Ejemplo n.º 1
0
        public MessageProcessorTestBase()
        {
            this.startTime = DateTimeOffset.UtcNow.Ticks;

            this.macAddress          = Utility.GetMacAddress();
            this.ServerConfiguration = new NetworkServerConfiguration
            {
                GatewayID    = ServerGatewayID,
                LogToConsole = true,
                LogLevel     = ((int)LogLevel.Debug).ToString(),
            };

            Logger.Init(new LoggerConfiguration()
            {
                LogLevel     = LogLevel.Debug,
                LogToConsole = true,
            });

            this.PayloadDecoder  = new TestLoRaPayloadDecoder(new LoRaPayloadDecoder());
            this.PacketForwarder = new TestPacketForwarder();
            this.LoRaDeviceApi   = new Mock <LoRaDeviceAPIServiceBase>(MockBehavior.Strict);
            this.FrameCounterUpdateStrategyProvider = new LoRaDeviceFrameCounterUpdateStrategyProvider(ServerGatewayID, this.LoRaDeviceApi.Object);
            var deduplicationFactory    = new DeduplicationStrategyFactory(this.LoRaDeviceApi.Object);
            var adrStrategyProvider     = new LoRaADRStrategyProvider();
            var adrManagerFactory       = new LoRAADRManagerFactory(this.LoRaDeviceApi.Object);
            var functionBundlerProvider = new FunctionBundlerProvider(this.LoRaDeviceApi.Object);

            this.RequestHandlerImplementation = new DefaultLoRaDataRequestHandler(this.ServerConfiguration, this.FrameCounterUpdateStrategyProvider, this.PayloadDecoder, deduplicationFactory, adrStrategyProvider, adrManagerFactory, functionBundlerProvider);
            this.LoRaDeviceClient             = new Mock <ILoRaDeviceClient>(MockBehavior.Strict);
            this.ConnectionManager            = new LoRaDeviceClientConnectionManager(new MemoryCache(new MemoryCacheOptions()
            {
                ExpirationScanFrequency = TimeSpan.FromSeconds(5)
            }));
            this.LoRaDeviceFactory = new TestLoRaDeviceFactory(this.ServerConfiguration, this.FrameCounterUpdateStrategyProvider, this.LoRaDeviceClient.Object, deduplicationFactory, adrStrategyProvider, adrManagerFactory, functionBundlerProvider, this.ConnectionManager);
        }
        // Creates a new instance of UdpServer
        public static UdpServer Create()
        {
            var configuration = NetworkServerConfiguration.CreateFromEnviromentVariables();

            var loRaDeviceAPIService         = new LoRaDeviceAPIService(configuration, new ServiceFacadeHttpClientProvider(configuration, ApiVersion.LatestVersion));
            var frameCounterStrategyProvider = new LoRaDeviceFrameCounterUpdateStrategyProvider(configuration.GatewayID, loRaDeviceAPIService);
            var deduplicationStrategyFactory = new DeduplicationStrategyFactory(loRaDeviceAPIService);
            var adrStrategyProvider          = new LoRaADRStrategyProvider();
            var cache = new MemoryCache(new MemoryCacheOptions());
            var dataHandlerImplementation = new DefaultLoRaDataRequestHandler(configuration, frameCounterStrategyProvider, new LoRaPayloadDecoder(), deduplicationStrategyFactory, adrStrategyProvider, new LoRAADRManagerFactory(loRaDeviceAPIService), new FunctionBundlerProvider(loRaDeviceAPIService));
            var connectionManager         = new LoRaDeviceClientConnectionManager(cache);
            var loRaDeviceFactory         = new LoRaDeviceFactory(configuration, dataHandlerImplementation, connectionManager);
            var loRaDeviceRegistry        = new LoRaDeviceRegistry(configuration, cache, loRaDeviceAPIService, loRaDeviceFactory);

            var messageDispatcher = new MessageDispatcher(configuration, loRaDeviceRegistry, frameCounterStrategyProvider);
            var udpServer         = new UdpServer(configuration, messageDispatcher, loRaDeviceAPIService, loRaDeviceRegistry);

            // TODO: review dependencies
            var classCMessageSender = new DefaultClassCDevicesMessageSender(configuration, loRaDeviceRegistry, udpServer, frameCounterStrategyProvider);

            dataHandlerImplementation.SetClassCMessageSender(classCMessageSender);

            udpServer.SetClassCMessageSender(classCMessageSender);
            return(udpServer);
        }
Ejemplo n.º 3
0
        public MessageProcessorMultipleGatewayTest()
        {
            this.SecondServerConfiguration = new NetworkServerConfiguration
            {
                GatewayID    = SecondServerGatewayID,
                LogToConsole = true,
                LogLevel     = ((int)LogLevel.Debug).ToString(),
            };

            this.SecondPacketForwarder = new TestPacketForwarder();
            this.SecondLoRaDeviceApi   = new Mock <LoRaDeviceAPIServiceBase>(MockBehavior.Strict);
            this.SecondFrameCounterUpdateStrategyProvider = new LoRaDeviceFrameCounterUpdateStrategyProvider(SecondServerGatewayID, this.SecondLoRaDeviceApi.Object);
            var deduplicationStrategyFactory = new DeduplicationStrategyFactory(this.SecondLoRaDeviceApi.Object);
            var loRaAdrManagerFactory        = new LoRAADRManagerFactory(this.SecondLoRaDeviceApi.Object);
            var adrStrategyProvider          = new LoRaADRStrategyProvider();
            var functionBundlerProvider      = new FunctionBundlerProvider(this.SecondLoRaDeviceApi.Object);

            this.secondRequestHandlerImplementation = new DefaultLoRaDataRequestHandler(this.SecondServerConfiguration, this.SecondFrameCounterUpdateStrategyProvider, new LoRaPayloadDecoder(), deduplicationStrategyFactory, adrStrategyProvider, loRaAdrManagerFactory, functionBundlerProvider);
            this.SecondLoRaDeviceClient             = new Mock <ILoRaDeviceClient>(MockBehavior.Strict);
            this.SecondConnectionManager            = new LoRaDeviceClientConnectionManager(new MemoryCache(new MemoryCacheOptions()
            {
                ExpirationScanFrequency = TimeSpan.FromSeconds(5)
            }));
            this.SecondLoRaDeviceFactory = new TestLoRaDeviceFactory(this.SecondServerConfiguration, this.SecondFrameCounterUpdateStrategyProvider, this.SecondLoRaDeviceClient.Object, deduplicationStrategyFactory, adrStrategyProvider, loRaAdrManagerFactory, functionBundlerProvider, this.SecondConnectionManager);
        }
        public MessageProcessorMultipleGatewayBase(ITestOutputHelper testOutputHelper) : base(testOutputHelper)
        {
            SecondServerConfiguration = new NetworkServerConfiguration
            {
                GatewayID    = SecondServerGatewayID,
                LogToConsole = true,
                LogLevel     = ((int)LogLevel.Debug).ToString(CultureInfo.InvariantCulture),
            };

            SecondDownstreamMessageSender            = new TestDownstreamMessageSender();
            SecondLoRaDeviceApi                      = new Mock <LoRaDeviceAPIServiceBase>(MockBehavior.Strict);
            SecondFrameCounterUpdateStrategyProvider = new LoRaDeviceFrameCounterUpdateStrategyProvider(SecondServerConfiguration, SecondLoRaDeviceApi.Object);
            this.cache = new MemoryCache(new MemoryCacheOptions()
            {
                ExpirationScanFrequency = TimeSpan.FromSeconds(5)
            });

            this.testOutputLoggerFactory = new TestOutputLoggerFactory(testOutputHelper);
            var deduplicationStrategyFactory = new DeduplicationStrategyFactory(this.testOutputLoggerFactory, this.testOutputLoggerFactory.CreateLogger <DeduplicationStrategyFactory>());
            var loRaAdrManagerFactory        = new LoRAADRManagerFactory(SecondLoRaDeviceApi.Object, this.testOutputLoggerFactory);
            var adrStrategyProvider          = new LoRaADRStrategyProvider(this.testOutputLoggerFactory);
            var functionBundlerProvider      = new FunctionBundlerProvider(SecondLoRaDeviceApi.Object, this.testOutputLoggerFactory, this.testOutputLoggerFactory.CreateLogger <FunctionBundlerProvider>());

            SecondConcentratorDeduplication = new ConcentratorDeduplication(this.cache, this.testOutputLoggerFactory.CreateLogger <IConcentratorDeduplication>());

            SecondRequestHandlerImplementation = new DefaultLoRaDataRequestHandler(SecondServerConfiguration,
                                                                                   SecondFrameCounterUpdateStrategyProvider,
                                                                                   SecondConcentratorDeduplication,
                                                                                   new LoRaPayloadDecoder(this.testOutputLoggerFactory.CreateLogger <LoRaPayloadDecoder>()),
                                                                                   deduplicationStrategyFactory,
                                                                                   adrStrategyProvider,
                                                                                   loRaAdrManagerFactory,
                                                                                   functionBundlerProvider,
                                                                                   this.testOutputLoggerFactory.CreateLogger <DefaultLoRaDataRequestHandler>(),
                                                                                   null);
            SecondLoRaDeviceClient = new Mock <ILoRaDeviceClient>(MockBehavior.Strict);
            this.cache             = new MemoryCache(new MemoryCacheOptions()
            {
                ExpirationScanFrequency = TimeSpan.FromSeconds(5)
            });

            var defaultRequestHandler = new DefaultLoRaDataRequestHandler(SecondServerConfiguration,
                                                                          SecondFrameCounterUpdateStrategyProvider,
                                                                          SecondConcentratorDeduplication,
                                                                          new LoRaPayloadDecoder(this.testOutputLoggerFactory.CreateLogger <LoRaPayloadDecoder>()),
                                                                          deduplicationStrategyFactory,
                                                                          adrStrategyProvider,
                                                                          loRaAdrManagerFactory,
                                                                          functionBundlerProvider,
                                                                          this.testOutputLoggerFactory.CreateLogger <DefaultLoRaDataRequestHandler>(),
                                                                          meter: null);

            SecondConnectionManager = new LoRaDeviceClientConnectionManager(this.cache, this.testOutputLoggerFactory.CreateLogger <LoRaDeviceClientConnectionManager>());
            SecondLoRaDeviceFactory = new TestLoRaDeviceFactory(SecondServerConfiguration, SecondLoRaDeviceClient.Object, SecondConnectionManager, DeviceCache, defaultRequestHandler);
        }
Ejemplo n.º 5
0
        public async System.Threading.Tasks.Task TestADRAsync(string testName, DevEui devEUI, IList <LoRaADRTableEntry> tableEntries, RadioMetadata radioMetadata, bool expectDefaultAnswer, LoRaADRResult expectedResult)
        {
            this.output.WriteLine($"Starting test {testName}");
            var region = TestUtils.TestRegion;
            ILoRaADRStrategyProvider provider = new LoRaADRStrategyProvider(NullLoggerFactory.Instance);

            using var inMemoryStore = new LoRaADRInMemoryStore();
            var loRaADRManager = new Mock <LoRaADRManagerBase>(MockBehavior.Loose, inMemoryStore, provider, NullLogger <LoRaADRManagerBase> .Instance)
            {
                CallBase = true
            };

            _ = loRaADRManager.Setup(x => x.NextFCntDown(It.IsAny <DevEui>(), It.IsAny <string>(), It.IsAny <uint>(), It.IsAny <uint>())).ReturnsAsync(1U);

            // If the test does not expect a default answer we trigger default reset before
            if (!expectDefaultAnswer)
            {
                _ = await loRaADRManager.Object.CalculateADRResultAndAddEntryAsync(devEUI, string.Empty, 1, 1, (float)region.RequiredSnr(radioMetadata.DataRate), radioMetadata.DataRate, region.TXPowertoMaxEIRP.Count - 1, region.MaxADRDataRate, new LoRaADRTableEntry()
                {
                    Snr          = 0,
                    FCnt         = 1,
                    DevEUI       = devEUI,
                    GatewayCount = 1,
                    GatewayId    = "gateway"
                });
            }

            for (var i = 0; i < tableEntries.Count; i++)
            {
                await loRaADRManager.Object.StoreADREntryAsync(tableEntries[i]);
            }

            var adrResult = await loRaADRManager.Object.CalculateADRResultAndAddEntryAsync(devEUI, string.Empty, 1, 1, (float)region.RequiredSnr(radioMetadata.DataRate), radioMetadata.DataRate, region.TXPowertoMaxEIRP.Count - 1, region.MaxADRDataRate);

            Assert.Equal(expectedResult.DataRate, adrResult.DataRate);
            Assert.Equal(expectedResult.NbRepetition, adrResult.NbRepetition);
            Assert.Equal(expectedResult.TxPower, adrResult.TxPower);
            Assert.Equal(expectedResult.FCntDown, adrResult.FCntDown);

            loRaADRManager.Verify(x => x.NextFCntDown(It.IsAny <DevEui>(), It.IsAny <string>(), It.IsAny <uint>(), It.IsAny <uint>()), Times.AtLeastOnce, "NextFCntDown");
            this.output.WriteLine($"Test {testName} finished");
        }
Ejemplo n.º 6
0
        public async System.Threading.Tasks.Task CheckADRReturnsDefaultValueIfCacheCrash()
        {
            var devEUI = TestEui.GenerateDevEui();
            var region = RegionManager.EU868;
            ILoRaADRStrategyProvider provider = new LoRaADRStrategyProvider(NullLoggerFactory.Instance);
            var datarate = DataRateIndex.DR5;

            using var inMemoryStore = new LoRaADRInMemoryStore();
            var loRaADRManager = new Mock <LoRaADRManagerBase>(MockBehavior.Loose, inMemoryStore, provider, NullLogger <LoRaADRManagerBase> .Instance)
            {
                CallBase = true
            };

            _ = loRaADRManager.Setup(x => x.NextFCntDown(It.IsAny <DevEui>(), It.IsAny <string>(), It.IsAny <uint>(), It.IsAny <uint>())).ReturnsAsync(1U);

            // setup table with default value
            _ = await loRaADRManager.Object.CalculateADRResultAndAddEntryAsync(devEUI, string.Empty, 1, 1, (float)region.RequiredSnr(datarate), region.GetDownstreamDataRate(datarate), region.TXPowertoMaxEIRP.Count - 1, region.MaxADRDataRate, new LoRaADRTableEntry()
            {
                Snr          = 0,
                FCnt         = 1,
                DevEUI       = devEUI,
                GatewayCount = 1,
                GatewayId    = "gateway"
            });

            // Add measurement and compute new ADR
            for (uint i = 0; i < 21; i++)
            {
                await loRaADRManager.Object.StoreADREntryAsync(
                    new LoRaADRTableEntry()
                {
                    DevEUI       = devEUI,
                    FCnt         = i,
                    GatewayCount = 1,
                    GatewayId    = "mygateway",
                    Snr          = 50
                });
            }

            var adrResult = await loRaADRManager.Object.CalculateADRResultAndAddEntryAsync(devEUI, string.Empty, 1, 1, (float)region.RequiredSnr(datarate), region.GetDownstreamDataRate(datarate), region.TXPowertoMaxEIRP.Count - 1, region.MaxADRDataRate);

            Assert.Equal(DR5, adrResult.DataRate);
            Assert.Equal(7, adrResult.TxPower);
            Assert.Equal(1, adrResult.NbRepetition);

            // reset cache and check we get default values
            _ = await loRaADRManager.Object.ResetAsync(devEUI);

            adrResult = await loRaADRManager.Object.CalculateADRResultAndAddEntryAsync(devEUI, string.Empty, 1, 1, (float)region.RequiredSnr(datarate), region.GetDownstreamDataRate(datarate), region.TXPowertoMaxEIRP.Count - 1, region.MaxADRDataRate, new LoRaADRTableEntry()
            {
                Snr          = 0,
                FCnt         = 1,
                DevEUI       = devEUI,
                GatewayCount = 1,
                GatewayId    = "gateway"
            });

            Assert.Equal(DR5, adrResult.DataRate);
            Assert.Equal(0, adrResult.TxPower);
            Assert.Equal(1, adrResult.NbRepetition);

            loRaADRManager.Verify(x => x.NextFCntDown(It.IsAny <DevEui>(), It.IsAny <string>(), It.IsAny <uint>(), It.IsAny <uint>()), Times.AtLeastOnce, "NextFCntDown");
        }
Ejemplo n.º 7
0
        public async System.Threading.Tasks.Task CheckADRReturnsDefaultValueIfCacheCrash()
        {
            string devEUI = "myloratest";
            var    region = RegionManager.EU868;
            ILoRaADRStrategyProvider provider = new LoRaADRStrategyProvider();
            Rxpk rxpk = new Rxpk();

            rxpk.Datr = "SF7BW125";
            var loRaADRManager = new Mock <LoRaADRManagerBase>(MockBehavior.Loose, new LoRaADRInMemoryStore(), provider);

            loRaADRManager.CallBase = true;
            loRaADRManager.Setup(x => x.NextFCntDown(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <uint>(), It.IsAny <uint>())).ReturnsAsync(1U);

            // setup table with default value
            _ = await loRaADRManager.Object.CalculateADRResultAndAddEntryAsync(devEUI, string.Empty, 1, 1, (float)rxpk.RequiredSnr, region.GetDRFromFreqAndChan(rxpk.Datr), region.TXPowertoMaxEIRP.Count - 1, region.MaxADRDataRate, new LoRaADRTableEntry()
            {
                Snr          = 0,
                FCnt         = 1,
                DevEUI       = devEUI,
                GatewayCount = 1,
                GatewayId    = "gateway"
            });

            // Add measurement and compute new ADR
            for (uint i = 0; i < 21; i++)
            {
                await loRaADRManager.Object.StoreADREntryAsync(
                    new LoRaADRTableEntry()
                {
                    DevEUI       = devEUI,
                    FCnt         = i,
                    GatewayCount = 1,
                    GatewayId    = "mygateway",
                    Snr          = 50
                });
            }

            var adrResult = await loRaADRManager.Object.CalculateADRResultAndAddEntryAsync(devEUI, string.Empty, 1, 1, (float)rxpk.RequiredSnr, region.GetDRFromFreqAndChan(rxpk.Datr), region.TXPowertoMaxEIRP.Count - 1, region.MaxADRDataRate);

            Assert.Equal(5, adrResult.DataRate);
            Assert.Equal(7, adrResult.TxPower);
            Assert.Equal(1, adrResult.NbRepetition);

            // reset cache and check we get default values
            await loRaADRManager.Object.ResetAsync(devEUI);

            adrResult = await loRaADRManager.Object.CalculateADRResultAndAddEntryAsync(devEUI, string.Empty, 1, 1, (float)rxpk.RequiredSnr, region.GetDRFromFreqAndChan(rxpk.Datr), region.TXPowertoMaxEIRP.Count - 1, region.MaxADRDataRate, new LoRaADRTableEntry()
            {
                Snr          = 0,
                FCnt         = 1,
                DevEUI       = devEUI,
                GatewayCount = 1,
                GatewayId    = "gateway"
            });

            Assert.Equal(5, adrResult.DataRate);
            Assert.Equal(0, adrResult.TxPower);
            Assert.Equal(1, adrResult.NbRepetition);

            loRaADRManager.Verify(x => x.NextFCntDown(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <uint>(), It.IsAny <uint>()), Times.AtLeastOnce, "NextFCntDown");
        }