Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gs: Ignore Class B&C downlink when gateway time is not set #212

Merged
merged 5 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/gatewayserver/io/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,16 +307,21 @@ func (c *Connection) HandleUp(up *ttnpb.UplinkMessage, frontendSync *FrontendClo
"server_time", frontendSync.ServerTime,
"gateway_time", frontendSync.GatewayTime,
)).Debug("Gateway clocks have been synchronized by the frontend")

case gpsTime != nil:
gatewayTime := *ttnpb.StdTime(gpsTime)
// Bryan: up.Settings.Timestamp is tmst, check udp/translation.go v1Metadata and v2Metadata.
ct = c.scheduler.SyncWithGatewayAbsolute(up.Settings.Timestamp, receivedAt, gatewayTime)
log.FromContext(c.ctx).WithFields(log.Fields(
"timestamp", up.Settings.Timestamp,
"concentrator_time", ct,
"server_time", receivedAt,
"gateway_time", gatewayTime,
)).Debug("Synchronized server and gateway absolute time")

// Bryan: gpsTime will be nil when tmms is not provided, or tmms is invalid (check where gpsTimeDelta is used).
case gpsTime == nil:
// Bryan: up.Settings.Timestamp is tmst, check udp/translation.go v1Metadata and v2Metadata.
ct = c.scheduler.Sync(up.Settings.Timestamp, receivedAt)
log.FromContext(c.ctx).WithFields(log.Fields(
"timestamp", up.Settings.Timestamp,
Expand Down
2 changes: 2 additions & 0 deletions pkg/gatewayserver/scheduling/clock.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,15 @@ func (c *RolloverClock) Sync(timestamp uint32, server time.Time) ConcentratorTim
c.absolute = (ConcentratorTime(rollovers<<32) + ConcentratorTime(timestamp)) * ConcentratorTime(time.Microsecond)
c.relative = timestamp
c.server = &server
// Bryan: when gateway gps time is not set or invalid, this sync function will clear gateway gps time.
c.gateway = nil
c.synced = true
return c.absolute
}

// SyncWithGatewayAbsolute synchronizes the clock with the given concentrator timestamp, the server time and the
// absolute gateway time that corresponds to the given timestamp.
// Bryan: this function still syncs with tmst but caching gateway gps time.
func (c *RolloverClock) SyncWithGatewayAbsolute(timestamp uint32, server, gateway time.Time) ConcentratorTime {
ct := c.Sync(timestamp, server)
c.gateway = &gateway
Expand Down
13 changes: 5 additions & 8 deletions pkg/gatewayserver/scheduling/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,18 +316,14 @@ func (s *Scheduler) ScheduleAt(ctx context.Context, opts Options) (res Emission,
if !ok {
panic("clock is synced without server time")
}
// Bryan: opts.time is absolute time and only set for Class B and C, check gatewayserver/io ScheduleDown.
if opts.Time != nil {
var ok bool
starts, ok = s.clock.FromGatewayTime(*ttnpb.StdTime(opts.Time))
if !ok {
if medianRTT == nil {
return Emission{}, 0, errNoAbsoluteGatewayTime.New()
}
serverTime, ok := s.clock.FromServerTime(*ttnpb.StdTime(opts.Time))
if !ok {
return Emission{}, 0, errNoServerTime.New()
}
starts = serverTime - ConcentratorTime(*medianRTT/2)
// Bryan: we can simply fail here to block all Class B and C transmission
// when gateway gps time is nil in clock.go.
return Emission{}, 0, errNoAbsoluteGatewayTime.New()
}
} else {
starts = s.clock.FromTimestampTime(opts.Timestamp)
Expand Down Expand Up @@ -459,6 +455,7 @@ func (s *Scheduler) Sync(v uint32, server time.Time) ConcentratorTime {

// SyncWithGatewayAbsolute synchronizes the clock with the given concentrator timestamp, the server time and the
// absolute gateway time that corresponds to the given timestamp.
// Bryan: this function still syncs with tmst but caching gateway gps time.
func (s *Scheduler) SyncWithGatewayAbsolute(timestamp uint32, server, gateway time.Time) ConcentratorTime {
s.mu.Lock()
defer s.mu.Unlock()
Expand Down
20 changes: 0 additions & 20 deletions pkg/gatewayserver/scheduling/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,26 +166,6 @@ func TestScheduleAtWithBandDutyCycle(t *testing.T) {
// Exceeding dwell time of 2 seconds.
ExpectedError: scheduling.ErrDwellTime,
},
{
PayloadSize: 16,
Settings: &ttnpb.TxSettings{
DataRate: &ttnpb.DataRate{
Modulation: &ttnpb.DataRate_Lora{
Lora: &ttnpb.LoRaDataRate{
Bandwidth: 125000,
SpreadingFactor: 7,
CodingRate: band.Cr4_5,
},
},
},
Frequency: 868100000,
Time: timestamppb.New(time.Unix(0, int64(1*time.Second))),
},
Priority: ttnpb.TxSchedulePriority_HIGHEST,
MedianRTT: durationPtr(200 * time.Millisecond),
ExpectedToa: 51456 * time.Microsecond,
ExpectedStarts: 1000000000 - 200000000/2,
},
{
SyncWithGatewayAbsolute: true,
PayloadSize: 16,
Expand Down
Loading