diff --git a/core/router/downlink.go b/core/router/downlink.go index 6a6463b75..1fbbe59a2 100644 --- a/core/router/downlink.go +++ b/core/router/downlink.go @@ -34,9 +34,7 @@ func (r *router) SubscribeDownlink(gatewayID string, subscriptionID string) (<-c go func() { ctx.Debug("Activate downlink") for message := range fromSchedule { - gateway.Utilization.AddTx(message) ctx.Debug("Send downlink") - message.Trace = message.Trace.WithEvent(trace.SendEvent) toGateway <- message } ctx.Debug("Deactivate downlink") diff --git a/core/router/gateway/gateway.go b/core/router/gateway/gateway.go index 60d3f9ce2..17b217999 100644 --- a/core/router/gateway/gateway.go +++ b/core/router/gateway/gateway.go @@ -16,13 +16,15 @@ import ( // NewGateway creates a new in-memory Gateway structure func NewGateway(ctx log.Interface, id string) *Gateway { ctx = ctx.WithField("GatewayID", id) - return &Gateway{ + gtw := &Gateway{ ID: id, Status: NewStatusStore(), Utilization: NewUtilization(), Schedule: NewSchedule(ctx), Ctx: ctx, } + gtw.Schedule.(*schedule).gateway = gtw // FIXME: Issue #420 + return gtw } // Gateway contains the state of a gateway diff --git a/core/router/gateway/schedule.go b/core/router/gateway/schedule.go index 5167c7a13..e5493c266 100644 --- a/core/router/gateway/schedule.go +++ b/core/router/gateway/schedule.go @@ -11,6 +11,7 @@ import ( pb_lorawan "github.com/TheThingsNetwork/ttn/api/protocol/lorawan" router_pb "github.com/TheThingsNetwork/ttn/api/router" + "github.com/TheThingsNetwork/ttn/api/trace" "github.com/TheThingsNetwork/ttn/utils/errors" "github.com/TheThingsNetwork/ttn/utils/random" "github.com/TheThingsNetwork/ttn/utils/toa" @@ -79,6 +80,7 @@ type schedule struct { downlink chan *router_pb.DownlinkMessage downlinkSubscriptionsLock sync.RWMutex downlinkSubscriptions map[string]chan *router_pb.DownlinkMessage + gateway *Gateway } func (s *schedule) GoString() (str string) { @@ -245,6 +247,10 @@ func (s *schedule) Subscribe(subscriptionID string) <-chan *router_pb.DownlinkMe s.downlink = make(chan *router_pb.DownlinkMessage) go func() { for downlink := range s.downlink { + if s.gateway != nil && s.gateway.Utilization != nil { + s.gateway.Utilization.AddTx(downlink) // FIXME: Issue #420 + } + downlink.Trace = downlink.Trace.WithEvent(trace.SendEvent) s.downlinkSubscriptionsLock.RLock() for _, ch := range s.downlinkSubscriptions { select {