Unverified Commit 05175157 authored by conny-andersson-netmore's avatar conny-andersson-netmore Committed by GitHub
Browse files

Log fNS downlink frames for gateway (#569)

parent 153acc6c
......@@ -55,4 +55,4 @@ serve: build
./build/chirpstack-network-server
run-compose-test:
docker-compose run --rm networkserver make test
docker-compose run --rm chirpstack-network-server make test
......@@ -229,7 +229,7 @@ func forConfirmedDownlink(funcs ...func(*ackContext) error) func(*ackContext) er
func forMACOnlyPayload(funcs ...func(*ackContext) error) func(*ackContext) error {
return func(ctx *ackContext) error {
// for mac-only payload, the FPort must be nil or it must be set to 0.
if ctx.MACPayload == nil || !(ctx.MACPayload.FPort == nil || *ctx.MACPayload.FPort == 0) {
if len(ctx.DownlinkFrame.DevEui) == 0 || ctx.MACPayload == nil || !(ctx.MACPayload.FPort == nil || *ctx.MACPayload.FPort == 0) {
return nil
}
......
......@@ -2,6 +2,8 @@ package data
import (
"context"
"encoding/binary"
"github.com/brocaar/chirpstack-network-server/v3/internal/storage"
"sort"
"time"
......@@ -42,6 +44,7 @@ func HandleRoamingFNS(ctx context.Context, pl backend.XmitDataReqPayload) error
downlink := gw.DownlinkFrame{
GatewayId: rxInfo[0].GatewayId,
DownlinkId: downID[:],
Token: uint32(binary.BigEndian.Uint16(downID[0:2])),
Items: []*gw.DownlinkFrameItem{},
}
......@@ -97,6 +100,15 @@ func HandleRoamingFNS(ctx context.Context, pl backend.XmitDataReqPayload) error
downlink.Items = append(downlink.Items, &item)
}
df := storage.DownlinkFrame{
Token: downlink.Token,
DownlinkFrame: &downlink,
}
if err := storage.SaveDownlinkFrame(ctx, &df); err != nil {
return errors.Wrap(err, "save downlink-frame error")
}
if err := gateway.Backend().SendTXPacket(downlink); err != nil {
return errors.Wrap(err, "send downlink-frame to gateway error")
}
......
......@@ -2,6 +2,7 @@ package roaming
import (
"context"
"encoding/binary"
"sort"
"time"
......@@ -57,6 +58,7 @@ func EmitPRDownlink(ctx context.Context, rxPacket models.RXPacket, phy []byte, d
for _, f := range []func() error{
cctx.setDownlinkGateway,
cctx.setDownlinkFrame,
cctx.saveDownlinkFrame,
cctx.sendDownlinkFrame,
} {
if err := f(); err != nil {
......@@ -94,6 +96,7 @@ func (ctx *emitPRDownlinkContext) setDownlinkFrame() error {
ctx.downlinkFrame = gw.DownlinkFrame{
DownlinkId: id[:],
Token: uint32(binary.BigEndian.Uint16(id[0:2])),
GatewayId: ctx.downlinkGateway.GatewayID[:],
}
......@@ -148,6 +151,19 @@ func (ctx *emitPRDownlinkContext) setDownlinkFrame() error {
return nil
}
func (ctx *emitPRDownlinkContext) saveDownlinkFrame() error {
df := storage.DownlinkFrame{
Token: ctx.downlinkFrame.Token,
DownlinkFrame: &ctx.downlinkFrame,
}
if err := storage.SaveDownlinkFrame(ctx.ctx, &df); err != nil {
return errors.Wrap(err, "save downlink-frame error")
}
return nil
}
func (ctx *emitPRDownlinkContext) sendDownlinkFrame() error {
if len(ctx.downlinkFrame.Items) == 0 {
return nil
......
......@@ -2,6 +2,7 @@ package testsuite
import (
"context"
"encoding/binary"
"encoding/json"
"io/ioutil"
"net/http"
......@@ -295,7 +296,7 @@ func (ts *PassiveRoamingFNSTestSuite) TestJoinRequest() {
// validate published downlink
downlinkFrame := <-ts.GWBackend.TXPacketChan
assert.Equal(ts.Gateway.GatewayID[:], downlinkFrame.GetGatewayId())
assert.Equal(&gw.DownlinkFrameItem{
assert.True(proto.Equal(&gw.DownlinkFrameItem{
PhyPayload: []byte{1, 2, 3, 4},
TxInfo: &gw.DownlinkTXInfo{
Frequency: 868100000,
......@@ -317,8 +318,8 @@ func (ts *PassiveRoamingFNSTestSuite) TestJoinRequest() {
},
Context: []byte{1, 2, 3, 4},
},
}, downlinkFrame.Items[0])
assert.Equal(&gw.DownlinkFrameItem{
}, downlinkFrame.Items[0]))
assert.True(proto.Equal(&gw.DownlinkFrameItem{
PhyPayload: []byte{1, 2, 3, 4},
TxInfo: &gw.DownlinkTXInfo{
Frequency: 868200000,
......@@ -340,7 +341,7 @@ func (ts *PassiveRoamingFNSTestSuite) TestJoinRequest() {
},
Context: []byte{1, 2, 3, 4},
},
}, downlinkFrame.Items[1])
}, downlinkFrame.Items[1]))
})
}
......@@ -652,9 +653,11 @@ func (ts *PassiveRoamingFNSTestSuite) TestDownlink() {
// check that downlink was sent to the gateway
frame := <-ts.GWBackend.TXPacketChan
assert.Len(frame.DownlinkId, 16) // just check that the downlink id is set, we can't predict its value
token := uint32(binary.BigEndian.Uint16(frame.DownlinkId[0:2]))
frame.DownlinkId = nil
assert.Equal(gw.DownlinkFrame{
assert.True(proto.Equal(&gw.DownlinkFrame{
GatewayId: ts.Gateway.GatewayID[:],
Token: token,
Items: []*gw.DownlinkFrameItem{
{
PhyPayload: []byte{1, 2, 3},
......@@ -707,7 +710,7 @@ func (ts *PassiveRoamingFNSTestSuite) TestDownlink() {
},
},
},
}, frame)
}, &frame))
}
// PassiveRoamingSNSTestSuite contains the tests from the hNS POV.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment