satellite-lora-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013 Magister Solutions Ltd
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Bastien Tauran <bastien.tauran@viveris.fr>
19  */
20 
27 // Include a header file from your module to test.
28 #include "ns3/boolean.h"
29 #include "ns3/config.h"
30 #include "ns3/log.h"
31 #include "ns3/mobility-helper.h"
32 #include "ns3/satellite-env-variables.h"
33 #include "ns3/satellite-mobility-model.h"
34 #include "ns3/satellite-position-allocator.h"
35 #include "ns3/simulator.h"
36 #include "ns3/singleton.h"
37 #include "ns3/string.h"
38 #include "ns3/test.h"
39 #include <ns3/cbr-application.h>
40 #include <ns3/cbr-helper.h>
41 #include <ns3/enum.h>
42 #include <ns3/lora-periodic-sender.h>
43 #include <ns3/lorawan-mac-header.h>
44 #include <ns3/packet-sink-helper.h>
45 #include <ns3/packet-sink.h>
46 #include <ns3/satellite-enums.h>
47 #include <ns3/satellite-helper.h>
48 #include <ns3/satellite-lora-conf.h>
49 #include <ns3/satellite-lorawan-net-device.h>
50 #include <ns3/satellite-topology.h>
51 #include <ns3/uinteger.h>
52 
53 #include <iostream>
54 #include <stdint.h>
55 
56 using namespace ns3;
57 
67 class SatLoraFirstWindowTestCase : public TestCase
68 {
69  public:
71  virtual ~SatLoraFirstWindowTestCase();
72 
73  private:
74  virtual void DoRun(void);
75  void MacTraceCb(std::string context, Ptr<const Packet> packet, const Address& address);
76 
79 
80  Address m_gwAddress;
81  Address m_edAddress;
82 };
83 
85  : TestCase("Test satellite lorawan with acks sent in first window."),
86  m_gwReceiveDate(Seconds(0)),
87  m_edReceiveDate(Seconds(0))
88 {
89 }
90 
92 {
93 }
94 
95 void
97  Ptr<const Packet> packet,
98  const Address& address)
99 {
100  if (address == m_edAddress)
101  {
102  m_gwReceiveDate = Simulator::Now();
103  }
104 
105  if (address == m_gwAddress)
106  {
107  m_edReceiveDate = Simulator::Now();
108  }
109 }
110 
111 void
113 {
114  // Set simulation output details
115  Singleton<SatEnvVariables>::Get()->DoInitialize();
116  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-sat-lora", "first-window", true);
117 
118  // Enable Lora
119  Config::SetDefault("ns3::LorawanMacEndDevice::DataRate", UintegerValue(5));
120  Config::SetDefault("ns3::LorawanMacEndDevice::MType",
121  EnumValue(LorawanMacHeader::CONFIRMED_DATA_UP));
122  Config::SetDefault("ns3::SatLoraConf::Standard", EnumValue(SatLoraConf::SATELLITE));
123 
124  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::FirstWindowDelay",
125  TimeValue(MilliSeconds(1500)));
126  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::SecondWindowDelay", TimeValue(Seconds(2)));
127  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::FirstWindowDuration",
128  TimeValue(MilliSeconds(400)));
129  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::SecondWindowDuration",
130  TimeValue(MilliSeconds(400)));
131  Config::SetDefault("ns3::LoraNetworkScheduler::FirstWindowAnswerDelay", TimeValue(Seconds(1)));
132  Config::SetDefault("ns3::LoraNetworkScheduler::SecondWindowAnswerDelay", TimeValue(Seconds(2)));
133 
134  // Superframe configuration
135  Config::SetDefault("ns3::SatConf::SuperFrameConfForSeq0",
136  EnumValue(SatSuperframeConf::SUPER_FRAME_CONFIG_4));
137  Config::SetDefault("ns3::SatSuperframeConf4::FrameConfigType",
138  EnumValue(SatSuperframeConf::CONFIG_TYPE_4));
139  Config::SetDefault("ns3::SatSuperframeConf4::Frame0_AllocatedBandwidthHz", DoubleValue(15000));
140  Config::SetDefault("ns3::SatSuperframeConf4::Frame0_CarrierAllocatedBandwidthHz",
141  DoubleValue(15000));
142 
143  // CRDSA only
144  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided",
145  BooleanValue(false));
146  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_RbdcAllowed",
147  BooleanValue(false));
148 
149  // Configure RA
150  Config::SetDefault("ns3::SatBeamHelper::RandomAccessModel", EnumValue(SatEnums::RA_MODEL_ESSA));
151  Config::SetDefault("ns3::SatBeamHelper::RaInterferenceEliminationModel",
152  EnumValue(SatPhyRxCarrierConf::SIC_RESIDUAL));
153  Config::SetDefault("ns3::SatBeamHelper::RaCollisionModel",
154  EnumValue(SatPhyRxCarrierConf::RA_COLLISION_CHECK_AGAINST_SINR));
155  Config::SetDefault("ns3::SatBeamHelper::ReturnLinkLinkResults", EnumValue(SatEnums::LR_LORA));
156 
157  // Configure E-SSA
158  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::WindowDuration", StringValue("600ms"));
159  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::WindowStep", StringValue("200ms"));
160  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::WindowSICIterations", UintegerValue(5));
161  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::EnableSIC", BooleanValue(false));
162 
163  Config::SetDefault("ns3::SatMac::EnableStatisticsTags", BooleanValue(true));
164  Config::SetDefault("ns3::SatHelper::PacketTraceEnabled", BooleanValue(true));
165 
166  // Creating the reference system.
167  Ptr<SatHelper> helper = CreateObject<SatHelper>(
168  Singleton<SatEnvVariables>::Get()->LocateDataDirectory() + "/scenarios/geo-33E-lora");
169  helper->CreatePredefinedScenario(SatHelper::SIMPLE);
170 
171  // >>> Start of actual test using Simple scenario >>>
172  Ptr<Node> utNode = Singleton<SatTopology>::Get()->GetUtNode(0);
173  Ptr<LoraPeriodicSender> app = Create<LoraPeriodicSender>();
174 
175  app->SetInterval(Seconds(10));
176 
177  app->SetStartTime(Seconds(1.0));
178  app->SetStopTime(Seconds(10.0));
179  app->SetPacketSize(24);
180 
181  app->SetNode(utNode);
182  utNode->AddApplication(app);
183 
184  m_gwAddress = Singleton<SatTopology>::Get()->GetGwNode(0)->GetDevice(1)->GetAddress();
185  m_edAddress = Singleton<SatTopology>::Get()->GetUtNode(0)->GetDevice(2)->GetAddress();
186 
187  Config::Connect("/NodeList/*/DeviceList/*/SatMac/Rx",
188  MakeCallback(&SatLoraFirstWindowTestCase::MacTraceCb, this));
189 
190  Simulator::Stop(Seconds(10));
191  Simulator::Run();
192 
193  Simulator::Destroy();
194 
195  Singleton<SatEnvVariables>::Get()->DoDispose();
196 
197  NS_TEST_ASSERT_MSG_NE(m_gwReceiveDate, Seconds(0), "Packet should be received by Gateway.");
198  NS_TEST_ASSERT_MSG_NE(m_edReceiveDate, Seconds(0), "Ack should be received by End Device.");
199  NS_TEST_ASSERT_MSG_GT(m_edReceiveDate, m_gwReceiveDate, "Ack should be received after packet.");
200 
201  Time difference = m_edReceiveDate - m_gwReceiveDate;
202  Time delay = MilliSeconds(130);
203 
204  NS_TEST_ASSERT_MSG_GT(difference, Seconds(1) + delay, "Ack arrived too early.");
205  NS_TEST_ASSERT_MSG_LT(difference + delay,
206  MilliSeconds(1900) + delay,
207  "Ack arrived too late. First window should be closed.");
208 }
209 
219 class SatLoraSecondWindowTestCase : public TestCase
220 {
221  public:
224 
225  private:
226  virtual void DoRun(void);
227  void MacTraceCb(std::string context, Ptr<const Packet> packet, const Address& address);
228 
231 
232  Address m_gwAddress;
233  Address m_edAddress;
234 };
235 
237  : TestCase("Test satellite lorawan with acks sent in second window."),
238  m_gwReceiveDate(Seconds(0)),
239  m_edReceiveDate(Seconds(0))
240 {
241 }
242 
244 {
245 }
246 
247 void
249  Ptr<const Packet> packet,
250  const Address& address)
251 {
252  if (address == m_edAddress)
253  {
254  m_gwReceiveDate = Simulator::Now();
255  }
256 
257  if (address == m_gwAddress)
258  {
259  m_edReceiveDate = Simulator::Now();
260  }
261 }
262 
263 void
265 {
266  // Set simulation output details
267  Singleton<SatEnvVariables>::Get()->DoInitialize();
268  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-sat-lora", "second-window", true);
269 
270  // Enable Lora
271  Config::SetDefault("ns3::LorawanMacEndDevice::DataRate", UintegerValue(5));
272  Config::SetDefault("ns3::LorawanMacEndDevice::MType",
273  EnumValue(LorawanMacHeader::CONFIRMED_DATA_UP));
274  Config::SetDefault("ns3::SatLoraConf::Standard", EnumValue(SatLoraConf::SATELLITE));
275 
276  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::FirstWindowDelay",
277  TimeValue(MilliSeconds(1500)));
278  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::SecondWindowDelay", TimeValue(Seconds(2)));
279  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::FirstWindowDuration",
280  TimeValue(MilliSeconds(400)));
281  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::SecondWindowDuration",
282  TimeValue(MilliSeconds(400)));
283  // Increase answer delay by 500ms compared to SatLoraSecondWindowTestCase to be in second window
284  // on End Device
285  Config::SetDefault("ns3::LoraNetworkScheduler::FirstWindowAnswerDelay",
286  TimeValue(Seconds(1) + MilliSeconds(500)));
287  Config::SetDefault("ns3::LoraNetworkScheduler::SecondWindowAnswerDelay", TimeValue(Seconds(2)));
288 
289  // Superframe configuration
290  Config::SetDefault("ns3::SatConf::SuperFrameConfForSeq0",
291  EnumValue(SatSuperframeConf::SUPER_FRAME_CONFIG_4));
292  Config::SetDefault("ns3::SatSuperframeConf4::FrameConfigType",
293  EnumValue(SatSuperframeConf::CONFIG_TYPE_4));
294  Config::SetDefault("ns3::SatSuperframeConf4::Frame0_AllocatedBandwidthHz", DoubleValue(15000));
295  Config::SetDefault("ns3::SatSuperframeConf4::Frame0_CarrierAllocatedBandwidthHz",
296  DoubleValue(15000));
297 
298  // CRDSA only
299  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided",
300  BooleanValue(false));
301  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_RbdcAllowed",
302  BooleanValue(false));
303 
304  // Configure RA
305  Config::SetDefault("ns3::SatBeamHelper::RandomAccessModel", EnumValue(SatEnums::RA_MODEL_ESSA));
306  Config::SetDefault("ns3::SatBeamHelper::RaInterferenceEliminationModel",
307  EnumValue(SatPhyRxCarrierConf::SIC_RESIDUAL));
308  Config::SetDefault("ns3::SatBeamHelper::RaCollisionModel",
309  EnumValue(SatPhyRxCarrierConf::RA_COLLISION_CHECK_AGAINST_SINR));
310  Config::SetDefault("ns3::SatBeamHelper::ReturnLinkLinkResults", EnumValue(SatEnums::LR_LORA));
311 
312  // Configure E-SSA
313  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::WindowDuration", StringValue("600ms"));
314  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::WindowStep", StringValue("200ms"));
315  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::WindowSICIterations", UintegerValue(5));
316  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::EnableSIC", BooleanValue(false));
317 
318  Config::SetDefault("ns3::SatMac::EnableStatisticsTags", BooleanValue(true));
319  Config::SetDefault("ns3::SatHelper::PacketTraceEnabled", BooleanValue(true));
320 
321  // Creating the reference system.
322  Ptr<SatHelper> helper = CreateObject<SatHelper>(
323  Singleton<SatEnvVariables>::Get()->LocateDataDirectory() + "/scenarios/geo-33E-lora");
324  helper->CreatePredefinedScenario(SatHelper::SIMPLE);
325 
326  // >>> Start of actual test using Simple scenario >>>
327  Ptr<Node> utNode = Singleton<SatTopology>::Get()->GetUtNode(0);
328  Ptr<LoraPeriodicSender> app = Create<LoraPeriodicSender>();
329 
330  app->SetInterval(Seconds(10));
331 
332  app->SetStartTime(Seconds(1.0));
333  app->SetStopTime(Seconds(10.0));
334  app->SetPacketSize(24);
335 
336  app->SetNode(utNode);
337  utNode->AddApplication(app);
338 
339  m_gwAddress = Singleton<SatTopology>::Get()->GetGwNode(0)->GetDevice(1)->GetAddress();
340  m_edAddress = Singleton<SatTopology>::Get()->GetUtNode(0)->GetDevice(2)->GetAddress();
341 
342  Config::Connect("/NodeList/*/DeviceList/*/SatMac/Rx",
343  MakeCallback(&SatLoraSecondWindowTestCase::MacTraceCb, this));
344 
345  Simulator::Stop(Seconds(10));
346  Simulator::Run();
347 
348  Simulator::Destroy();
349 
350  Singleton<SatEnvVariables>::Get()->DoDispose();
351  NS_TEST_ASSERT_MSG_NE(m_gwReceiveDate, Seconds(0), "Packet should be received by Gateway.");
352  NS_TEST_ASSERT_MSG_NE(m_edReceiveDate, Seconds(0), "Ack should be received by End Device.");
353  NS_TEST_ASSERT_MSG_GT(m_edReceiveDate, m_gwReceiveDate, "Ack should be received after packet.");
354 
355  Time difference = m_edReceiveDate - m_gwReceiveDate;
356  Time delay = MilliSeconds(130);
357 
358  NS_TEST_ASSERT_MSG_GT(difference, Seconds(1.5) + delay, "Ack arrived too early.");
359  NS_TEST_ASSERT_MSG_LT(difference + delay,
360  MilliSeconds(2400) + delay,
361  "Ack arrived too late. Second window should be closed.");
362 }
363 
372 class SatLoraOutOfWindowWindowTestCase : public TestCase
373 {
374  public:
377 
378  private:
379  virtual void DoRun(void);
380  void MacTraceCb(std::string context, Ptr<const Packet> packet, const Address& address);
381  void PhyTraceCb(std::string context, Ptr<const Packet> packet, const Address& address);
382 
383  std::vector<Time> m_gwReceiveDates;
385 
386  Address m_gwAddress;
387  Address m_edAddress;
388 
391 };
392 
394  : TestCase("Test satellite lorawan with acks sent out of reception windows."),
395  m_edReceiveDate(Seconds(0)),
396  m_phyGwReceive(false),
397  m_phyEdReceive(false)
398 {
399 }
400 
402 {
403 }
404 
405 void
407  Ptr<const Packet> packet,
408  const Address& address)
409 {
410  if (address == m_edAddress)
411  {
412  m_gwReceiveDates.push_back(Simulator::Now());
413  }
414 
415  if (address == m_gwAddress)
416  {
417  m_edReceiveDate = Simulator::Now();
418  }
419 }
420 
421 void
423  Ptr<const Packet> packet,
424  const Address& address)
425 {
426  if (address == m_edAddress)
427  {
428  m_phyGwReceive = true;
429  }
430 
431  if (address == m_gwAddress)
432  {
433  m_phyEdReceive = true;
434  }
435 }
436 
437 void
439 {
440  // Set simulation output details
441  Singleton<SatEnvVariables>::Get()->DoInitialize();
442  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-sat-lora", "out-of-window", true);
443 
444  // Enable Lora
445  Config::SetDefault("ns3::LorawanMacEndDevice::DataRate", UintegerValue(5));
446  Config::SetDefault("ns3::LorawanMacEndDevice::MType",
447  EnumValue(LorawanMacHeader::CONFIRMED_DATA_UP));
448  Config::SetDefault("ns3::SatLoraConf::Standard", EnumValue(SatLoraConf::SATELLITE));
449 
450  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::FirstWindowDelay",
451  TimeValue(MilliSeconds(1500)));
452  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::SecondWindowDelay", TimeValue(Seconds(2)));
453  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::FirstWindowDuration",
454  TimeValue(MilliSeconds(400)));
455  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::SecondWindowDuration",
456  TimeValue(MilliSeconds(400)));
457  // Send answer too early
458  Config::SetDefault("ns3::LoraNetworkScheduler::FirstWindowAnswerDelay",
459  TimeValue(Seconds(0.1)));
460  Config::SetDefault("ns3::LoraNetworkScheduler::SecondWindowAnswerDelay", TimeValue(Seconds(2)));
461 
462  // Superframe configuration
463  Config::SetDefault("ns3::SatConf::SuperFrameConfForSeq0",
464  EnumValue(SatSuperframeConf::SUPER_FRAME_CONFIG_4));
465  Config::SetDefault("ns3::SatSuperframeConf4::FrameConfigType",
466  EnumValue(SatSuperframeConf::CONFIG_TYPE_4));
467  Config::SetDefault("ns3::SatSuperframeConf4::Frame0_AllocatedBandwidthHz", DoubleValue(15000));
468  Config::SetDefault("ns3::SatSuperframeConf4::Frame0_CarrierAllocatedBandwidthHz",
469  DoubleValue(15000));
470 
471  // CRDSA only
472  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided",
473  BooleanValue(false));
474  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_RbdcAllowed",
475  BooleanValue(false));
476 
477  // Configure RA
478  Config::SetDefault("ns3::SatBeamHelper::RandomAccessModel", EnumValue(SatEnums::RA_MODEL_ESSA));
479  Config::SetDefault("ns3::SatBeamHelper::RaInterferenceEliminationModel",
480  EnumValue(SatPhyRxCarrierConf::SIC_RESIDUAL));
481  Config::SetDefault("ns3::SatBeamHelper::RaCollisionModel",
482  EnumValue(SatPhyRxCarrierConf::RA_COLLISION_CHECK_AGAINST_SINR));
483  Config::SetDefault("ns3::SatBeamHelper::ReturnLinkLinkResults", EnumValue(SatEnums::LR_LORA));
484 
485  // Configure E-SSA
486  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::WindowDuration", StringValue("600ms"));
487  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::WindowStep", StringValue("200ms"));
488  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::WindowSICIterations", UintegerValue(5));
489  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::EnableSIC", BooleanValue(false));
490 
491  Config::SetDefault("ns3::SatMac::EnableStatisticsTags", BooleanValue(true));
492  Config::SetDefault("ns3::SatPhy::EnableStatisticsTags", BooleanValue(true));
493  Config::SetDefault("ns3::SatHelper::PacketTraceEnabled", BooleanValue(true));
494 
495  // Creating the reference system.
496  Ptr<SatHelper> helper = CreateObject<SatHelper>(
497  Singleton<SatEnvVariables>::Get()->LocateDataDirectory() + "/scenarios/geo-33E-lora");
498  helper->CreatePredefinedScenario(SatHelper::SIMPLE);
499 
500  // >>> Start of actual test using Simple scenario >>>
501  Ptr<Node> utNode = Singleton<SatTopology>::Get()->GetUtNode(0);
502  Ptr<LoraPeriodicSender> app = Create<LoraPeriodicSender>();
503 
504  app->SetInterval(Seconds(10));
505 
506  app->SetStartTime(Seconds(1.0));
507  app->SetStopTime(Seconds(10.0));
508  app->SetPacketSize(24);
509 
510  app->SetNode(utNode);
511  utNode->AddApplication(app);
512 
513  m_gwAddress = Singleton<SatTopology>::Get()->GetGwNode(0)->GetDevice(1)->GetAddress();
514  m_edAddress = utNode->GetDevice(2)->GetAddress();
515 
516  Config::Connect("/NodeList/*/DeviceList/*/SatMac/Rx",
517  MakeCallback(&SatLoraOutOfWindowWindowTestCase::MacTraceCb, this));
518  Config::Connect("/NodeList/*/DeviceList/*/SatPhy/Rx",
519  MakeCallback(&SatLoraOutOfWindowWindowTestCase::PhyTraceCb, this));
520 
521  Simulator::Stop(Seconds(10));
522  Simulator::Run();
523 
524  Simulator::Destroy();
525 
526  Singleton<SatEnvVariables>::Get()->DoDispose();
527 
528  NS_TEST_ASSERT_MSG_EQ(m_gwReceiveDates.size(),
529  2,
530  "GW should receive a packet and the first retransmission.");
531  NS_TEST_ASSERT_MSG_EQ(m_edReceiveDate, Seconds(0), "No ack should be received by End Device.");
532 
533  NS_TEST_ASSERT_MSG_EQ(m_phyGwReceive,
534  true,
535  "Phy layer should trace traffic from End Device to Gateway.");
536  NS_TEST_ASSERT_MSG_EQ(m_phyEdReceive,
537  false,
538  "Phy layer should not trace traffic from Gateway to End Device, as phy "
539  "layer is in SLEEP state.");
540 }
541 
552 {
553  public:
556 
557  private:
558  virtual void DoRun(void);
559  void MacTraceCb(std::string context, Ptr<const Packet> packet, const Address& address);
560  void PhyTraceCb(std::string context, Ptr<const Packet> packet, const Address& address);
561 
562  std::vector<Time> m_gwReceiveDates;
564 
565  Address m_gwAddress;
566  Address m_edAddress;
567 };
568 
570  : TestCase("Test satellite lorawan with acks sent out of reception windows and no "
571  "retransmission needed."),
572  m_edReceiveDate(Seconds(0))
573 {
574 }
575 
578 {
579 }
580 
581 void
583  Ptr<const Packet> packet,
584  const Address& address)
585 {
586  if (address == m_edAddress)
587  {
588  m_gwReceiveDates.push_back(Simulator::Now());
589  }
590 
591  if (address == m_gwAddress)
592  {
593  m_edReceiveDate = Simulator::Now();
594  }
595 }
596 
597 void
599 {
600  // Set simulation output details
601  Singleton<SatEnvVariables>::Get()->DoInitialize();
602  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-sat-lora", "out-of-window", true);
603 
604  // Enable Lora
605  Config::SetDefault("ns3::LorawanMacEndDevice::DataRate", UintegerValue(5));
606  Config::SetDefault("ns3::LorawanMacEndDevice::MType",
607  EnumValue(LorawanMacHeader::UNCONFIRMED_DATA_UP));
608  Config::SetDefault("ns3::SatLoraConf::Standard", EnumValue(SatLoraConf::SATELLITE));
609 
610  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::FirstWindowDelay",
611  TimeValue(MilliSeconds(1500)));
612  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::SecondWindowDelay", TimeValue(Seconds(2)));
613  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::FirstWindowDuration",
614  TimeValue(MilliSeconds(400)));
615  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::SecondWindowDuration",
616  TimeValue(MilliSeconds(400)));
617  // Send answer too early
618  Config::SetDefault("ns3::LoraNetworkScheduler::FirstWindowAnswerDelay",
619  TimeValue(Seconds(0.1)));
620  Config::SetDefault("ns3::LoraNetworkScheduler::SecondWindowAnswerDelay", TimeValue(Seconds(2)));
621 
622  // Superframe configuration
623  Config::SetDefault("ns3::SatConf::SuperFrameConfForSeq0",
624  EnumValue(SatSuperframeConf::SUPER_FRAME_CONFIG_4));
625  Config::SetDefault("ns3::SatSuperframeConf4::FrameConfigType",
626  EnumValue(SatSuperframeConf::CONFIG_TYPE_4));
627  Config::SetDefault("ns3::SatSuperframeConf4::Frame0_AllocatedBandwidthHz", DoubleValue(15000));
628  Config::SetDefault("ns3::SatSuperframeConf4::Frame0_CarrierAllocatedBandwidthHz",
629  DoubleValue(15000));
630 
631  // CRDSA only
632  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided",
633  BooleanValue(false));
634  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_RbdcAllowed",
635  BooleanValue(false));
636 
637  // Configure RA
638  Config::SetDefault("ns3::SatBeamHelper::RandomAccessModel", EnumValue(SatEnums::RA_MODEL_ESSA));
639  Config::SetDefault("ns3::SatBeamHelper::RaInterferenceEliminationModel",
640  EnumValue(SatPhyRxCarrierConf::SIC_RESIDUAL));
641  Config::SetDefault("ns3::SatBeamHelper::RaCollisionModel",
642  EnumValue(SatPhyRxCarrierConf::RA_COLLISION_CHECK_AGAINST_SINR));
643  Config::SetDefault("ns3::SatBeamHelper::ReturnLinkLinkResults", EnumValue(SatEnums::LR_LORA));
644 
645  // Configure E-SSA
646  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::WindowDuration", StringValue("600ms"));
647  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::WindowStep", StringValue("200ms"));
648  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::WindowSICIterations", UintegerValue(5));
649  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::EnableSIC", BooleanValue(false));
650 
651  Config::SetDefault("ns3::SatMac::EnableStatisticsTags", BooleanValue(true));
652  Config::SetDefault("ns3::SatPhy::EnableStatisticsTags", BooleanValue(true));
653  Config::SetDefault("ns3::SatHelper::PacketTraceEnabled", BooleanValue(true));
654 
655  // Creating the reference system.
656  Ptr<SatHelper> helper = CreateObject<SatHelper>(
657  Singleton<SatEnvVariables>::Get()->LocateDataDirectory() + "/scenarios/geo-33E-lora");
658  helper->CreatePredefinedScenario(SatHelper::SIMPLE);
659 
660  // >>> Start of actual test using Simple scenario >>>
661  Ptr<Node> utNode = Singleton<SatTopology>::Get()->GetUtNode(0);
662  Ptr<LoraPeriodicSender> app = Create<LoraPeriodicSender>();
663 
664  app->SetInterval(Seconds(10));
665 
666  app->SetStartTime(Seconds(1.0));
667  app->SetStopTime(Seconds(10.0));
668  app->SetPacketSize(24);
669 
670  app->SetNode(utNode);
671  utNode->AddApplication(app);
672 
673  m_gwAddress = Singleton<SatTopology>::Get()->GetGwNode(0)->GetDevice(1)->GetAddress();
674  m_edAddress = utNode->GetDevice(2)->GetAddress();
675 
676  Config::Connect(
677  "/NodeList/*/DeviceList/*/SatMac/Rx",
679 
680  Simulator::Stop(Seconds(10));
681  Simulator::Run();
682 
683  Simulator::Destroy();
684 
685  Singleton<SatEnvVariables>::Get()->DoDispose();
686 
687  NS_TEST_ASSERT_MSG_EQ(m_gwReceiveDates.size(),
688  1,
689  "GW should receive a packet but no retransmission.");
690  NS_TEST_ASSERT_MSG_EQ(m_edReceiveDate, Seconds(0), "No ack should be received by End Device.");
691 }
692 
701 class SatLoraCbrTestCase : public TestCase
702 {
703  public:
705  virtual ~SatLoraCbrTestCase();
706 
707  private:
708  virtual void DoRun(void);
709  void MacTraceCb(std::string context, Ptr<const Packet> packet, const Address& address);
710 
713 
714  Address m_gwAddress;
715  Address m_edAddress;
716 };
717 
719  : TestCase("Test satellite lorawan with acks sent in second window."),
720  m_edReceiveDate(Seconds(0))
721 {
722 }
723 
725 {
726 }
727 
728 void
729 SatLoraCbrTestCase::MacTraceCb(std::string context,
730  Ptr<const Packet> packet,
731  const Address& address)
732 {
733  if (address == m_edAddress)
734  {
735  m_gwReceiveDate = Simulator::Now();
736  }
737 
738  if (address == m_gwAddress)
739  {
740  m_edReceiveDate = Simulator::Now();
741  }
742 }
743 
744 void
746 {
747  // Set simulation output details
748  Singleton<SatEnvVariables>::Get()->DoInitialize();
749  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-sat-lora", "cbr", true);
750 
751  // Enable Lora
752  Config::SetDefault("ns3::LorawanMacEndDevice::DataRate", UintegerValue(5));
753  Config::SetDefault("ns3::LorawanMacEndDevice::MType",
754  EnumValue(LorawanMacHeader::CONFIRMED_DATA_UP));
755  Config::SetDefault("ns3::SatLoraConf::Standard", EnumValue(SatLoraConf::SATELLITE));
756 
757  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::FirstWindowDelay",
758  TimeValue(MilliSeconds(1500)));
759  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::SecondWindowDelay", TimeValue(Seconds(2)));
760  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::FirstWindowDuration",
761  TimeValue(MilliSeconds(400)));
762  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::SecondWindowDuration",
763  TimeValue(MilliSeconds(400)));
764  Config::SetDefault("ns3::LoraNetworkScheduler::FirstWindowAnswerDelay", TimeValue(Seconds(1)));
765  Config::SetDefault("ns3::LoraNetworkScheduler::SecondWindowAnswerDelay", TimeValue(Seconds(2)));
766 
767  // Superframe configuration
768  Config::SetDefault("ns3::SatConf::SuperFrameConfForSeq0",
769  EnumValue(SatSuperframeConf::SUPER_FRAME_CONFIG_4));
770  Config::SetDefault("ns3::SatSuperframeConf4::FrameConfigType",
771  EnumValue(SatSuperframeConf::CONFIG_TYPE_4));
772  Config::SetDefault("ns3::SatSuperframeConf4::Frame0_AllocatedBandwidthHz", DoubleValue(15000));
773  Config::SetDefault("ns3::SatSuperframeConf4::Frame0_CarrierAllocatedBandwidthHz",
774  DoubleValue(15000));
775 
776  // CRDSA only
777  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided",
778  BooleanValue(false));
779  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_RbdcAllowed",
780  BooleanValue(false));
781 
782  // Configure RA
783  Config::SetDefault("ns3::SatBeamHelper::RandomAccessModel", EnumValue(SatEnums::RA_MODEL_ESSA));
784  Config::SetDefault("ns3::SatBeamHelper::RaInterferenceEliminationModel",
785  EnumValue(SatPhyRxCarrierConf::SIC_RESIDUAL));
786  Config::SetDefault("ns3::SatBeamHelper::RaCollisionModel",
787  EnumValue(SatPhyRxCarrierConf::RA_COLLISION_CHECK_AGAINST_SINR));
788  Config::SetDefault("ns3::SatBeamHelper::ReturnLinkLinkResults", EnumValue(SatEnums::LR_LORA));
789 
790  // Configure E-SSA
791  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::WindowDuration", StringValue("600ms"));
792  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::WindowStep", StringValue("200ms"));
793  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::WindowSICIterations", UintegerValue(5));
794  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::EnableSIC", BooleanValue(false));
795 
796  Config::SetDefault("ns3::CbrApplication::Interval", StringValue("10s"));
797  Config::SetDefault("ns3::CbrApplication::PacketSize", UintegerValue(24));
798 
799  Config::SetDefault("ns3::SatMac::EnableStatisticsTags", BooleanValue(true));
800  Config::SetDefault("ns3::SatHelper::PacketTraceEnabled", BooleanValue(true));
801 
802  // Creating the reference system.
803  Ptr<SatHelper> helper = CreateObject<SatHelper>(
804  Singleton<SatEnvVariables>::Get()->LocateDataDirectory() + "/scenarios/geo-33E-lora");
805  helper->CreatePredefinedScenario(SatHelper::SIMPLE);
806 
807  NodeContainer utUsers = Singleton<SatTopology>::Get()->GetUtUserNodes();
808  NodeContainer gwUsers = Singleton<SatTopology>::Get()->GetGwUserNodes();
809  InetSocketAddress gwUserAddr = InetSocketAddress(helper->GetUserAddress(gwUsers.Get(0)), 9);
810 
811  PacketSinkHelper sinkHelper("ns3::UdpSocketFactory", Address());
812  CbrHelper cbrHelper("ns3::UdpSocketFactory", Address());
813  ApplicationContainer sinkContainer;
814  ApplicationContainer cbrContainer;
815 
816  sinkHelper.SetAttribute("Local", AddressValue(Address(gwUserAddr)));
817  sinkContainer.Add(sinkHelper.Install(gwUsers.Get(0)));
818 
819  cbrHelper.SetAttribute("Remote", AddressValue(Address(gwUserAddr)));
820 
821  auto app = cbrHelper.Install(utUsers.Get(0)).Get(0);
822  app->SetStartTime(Seconds(1));
823  cbrContainer.Add(app);
824 
825  sinkContainer.Start(Seconds(1));
826  sinkContainer.Stop(Seconds(20));
827 
828  m_gwAddress = Singleton<SatTopology>::Get()->GetGwNode(0)->GetDevice(1)->GetAddress();
829  m_edAddress = Singleton<SatTopology>::Get()->GetUtNode(0)->GetDevice(2)->GetAddress();
830 
831  Ptr<PacketSink> receiver = DynamicCast<PacketSink>(sinkContainer.Get(0));
832 
833  Config::Connect("/NodeList/*/DeviceList/*/SatMac/Rx",
834  MakeCallback(&SatLoraCbrTestCase::MacTraceCb, this));
835 
836  Simulator::Stop(Seconds(20));
837  Simulator::Run();
838 
839  Simulator::Destroy();
840 
841  Singleton<SatEnvVariables>::Get()->DoDispose();
842 
843  NS_TEST_ASSERT_MSG_NE(m_gwReceiveDate, Seconds(0), "Packet should be received by Gateway.");
844  NS_TEST_ASSERT_MSG_NE(m_edReceiveDate, Seconds(0), "Ack should be received by End Device.");
845  NS_TEST_ASSERT_MSG_GT(m_edReceiveDate, m_gwReceiveDate, "Ack should be received after packet.");
846 
847  Time difference = m_edReceiveDate - m_gwReceiveDate;
848  Time delay = MilliSeconds(130);
849 
850  NS_TEST_ASSERT_MSG_GT(difference, Seconds(1) + delay, "Ack arrived too early.");
851  NS_TEST_ASSERT_MSG_LT(difference + delay,
852  MilliSeconds(1900) + delay,
853  "Ack arrived too late. First window should be closed.");
854 
855  NS_TEST_ASSERT_MSG_EQ(receiver->GetTotalRx(), 24, "Sink should receive one packet of 24 bytes");
856 }
857 
862 class SatLoraTestSuite : public TestSuite
863 {
864  public:
866 };
867 
869  : TestSuite("sat-lora-test", Type::SYSTEM)
870 {
871  AddTestCase(new SatLoraFirstWindowTestCase, TestCase::Duration::QUICK);
872  AddTestCase(new SatLoraSecondWindowTestCase, TestCase::Duration::QUICK);
873  AddTestCase(new SatLoraOutOfWindowWindowTestCase, TestCase::Duration::QUICK);
874  AddTestCase(new SatLoraOutOfWindowWindowNoRetransmissionTestCase, TestCase::Duration::QUICK);
875  AddTestCase(new SatLoraCbrTestCase, TestCase::Duration::QUICK);
876 }
877 
878 // Do allocate an instance of this TestSuite
Test case to check if packet is received on App layer.
void MacTraceCb(std::string context, Ptr< const Packet > packet, const Address &address)
virtual void DoRun(void)
Test case to check if Lora ack arrives in first reception window.
void MacTraceCb(std::string context, Ptr< const Packet > packet, const Address &address)
Test case to check that packet is not retransmitted if ack outside of both windows but no retransmiss...
void MacTraceCb(std::string context, Ptr< const Packet > packet, const Address &address)
void PhyTraceCb(std::string context, Ptr< const Packet > packet, const Address &address)
Test case to check if packet retransmitted if ack outside of both windows.
void MacTraceCb(std::string context, Ptr< const Packet > packet, const Address &address)
void PhyTraceCb(std::string context, Ptr< const Packet > packet, const Address &address)
Test case to check if Lora ack arrives in second reception window.
void MacTraceCb(std::string context, Ptr< const Packet > packet, const Address &address)
Test suite for Satellite mobility unit test cases.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
static SatLoraTestSuite satLoraTestSuite