Skip to content

Commit

Permalink
Merge pull request #5737 from TheThingsNetwork/fix/class-b-fixes
Browse files Browse the repository at this point in the history
Synchronize gateway time only with GPS timestamps
  • Loading branch information
adriansmares authored Aug 29, 2022
2 parents fd5a893 + b8e1480 commit 0bd5b7a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
22 changes: 18 additions & 4 deletions pkg/gatewayserver/io/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"sync/atomic"
"time"

"github.com/gogo/protobuf/types"
"go.thethings.network/lorawan-stack/v3/pkg/band"
"go.thethings.network/lorawan-stack/v3/pkg/config"
"go.thethings.network/lorawan-stack/v3/pkg/errorcontext"
Expand Down Expand Up @@ -241,27 +242,40 @@ func (c *Connection) HandleUp(up *ttnpb.UplinkMessage, frontendSync *FrontendClo
}

receivedAt := *ttnpb.StdTime(up.ReceivedAt)
gpsTime := func(mds []*ttnpb.RxMetadata) *types.Timestamp {
for _, md := range mds {
if gpsTime := md.GpsTime; gpsTime != nil {
return gpsTime
}
}
return nil
}(up.RxMetadata)

var ct scheduling.ConcentratorTime
switch {
case frontendSync != nil:
ct = c.scheduler.SyncWithGatewayConcentrator(frontendSync.Timestamp, frontendSync.ServerTime, frontendSync.GatewayTime, frontendSync.ConcentratorTime)
ct = c.scheduler.SyncWithGatewayConcentrator(
frontendSync.Timestamp,
frontendSync.ServerTime,
frontendSync.GatewayTime,
frontendSync.ConcentratorTime,
)
log.FromContext(c.ctx).WithFields(log.Fields(
"timestamp", frontendSync.Timestamp,
"concentrator_time", frontendSync.ConcentratorTime,
"server_time", frontendSync.ServerTime,
"gateway_time", frontendSync.GatewayTime,
)).Debug("Gateway clocks have been synchronized by the frontend")
case up.Settings.Time != nil:
gatewayTime := *ttnpb.StdTime(up.Settings.Time)
case gpsTime != nil:
gatewayTime := *ttnpb.StdTime(gpsTime)
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")
case up.Settings.Time == nil:
case gpsTime == nil:
ct = c.scheduler.Sync(up.Settings.Timestamp, receivedAt)
log.FromContext(c.ctx).WithFields(log.Fields(
"timestamp", up.Settings.Timestamp,
Expand Down
4 changes: 3 additions & 1 deletion pkg/gatewayserver/io/mock/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ func ConnectFrontend(ctx context.Context, ids *ttnpb.GatewayIdentifiers, server
case up := <-f.Up:
gatewayTime := time.Unix(0, 0).Add(time.Since(started))
up.ReceivedAt = ttnpb.ProtoTimePtr(time.Now())
up.Settings.Time = ttnpb.ProtoTimePtr(gatewayTime)
for _, md := range up.RxMetadata {
md.GpsTime = ttnpb.ProtoTimePtr(gatewayTime)
}
conn.HandleUp(up, nil)
case status := <-f.Status:
conn.HandleStatus(status)
Expand Down
4 changes: 2 additions & 2 deletions pkg/networkserver/downlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -2096,14 +2096,14 @@ func (ns *NetworkServer) processDownlinkTask(ctx context.Context, consumerID str
case !slot.IsApplicationTime && slot.Class == ttnpb.Class_CLASS_C && time.Until(slot.Time) > 0:
logger.WithFields(log.Fields(
"slot_start", slot.Time,
)).Info("Class C downlink scheduling attempt performed too soon, retry attempt")
)).Debug("Class C downlink scheduling attempt performed too soon, retry attempt")
taskUpdateStrategy = nextDownlinkTask
return dev, nil, nil

case time.Until(slot.Time) > absoluteTimeSchedulingDelay+2*nsScheduleWindow():
logger.WithFields(log.Fields(
"slot_start", slot.Time,
)).Info("Class B/C downlink scheduling attempt performed too soon, retry attempt")
)).Debug("Class B/C downlink scheduling attempt performed too soon, retry attempt")
taskUpdateStrategy = nextDownlinkTask
return dev, nil, nil

Expand Down

0 comments on commit 0bd5b7a

Please sign in to comment.