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 "../model/satellite-mobility-model.h"
29 #include "../model/satellite-position-allocator.h"
30 #include "../utils/satellite-env-variables.h"
31 
32 #include "ns3/boolean.h"
33 #include "ns3/config.h"
34 #include "ns3/log.h"
35 #include "ns3/mobility-helper.h"
36 #include "ns3/simulator.h"
37 #include "ns3/singleton.h"
38 #include "ns3/string.h"
39 #include "ns3/test.h"
40 #include <ns3/cbr-application.h>
41 #include <ns3/cbr-helper.h>
42 #include <ns3/enum.h>
43 #include <ns3/lora-periodic-sender.h>
44 #include <ns3/lorawan-mac-header.h>
45 #include <ns3/packet-sink-helper.h>
46 #include <ns3/packet-sink.h>
47 #include <ns3/satellite-enums.h>
48 #include <ns3/satellite-helper.h>
49 #include <ns3/satellite-lora-conf.h>
50 #include <ns3/satellite-lorawan-net-device.h>
51 #include <ns3/uinteger.h>
52 
53 #include <iostream>
54 
55 using namespace ns3;
56 
66 class SatLoraFirstWindowTestCase : public TestCase
67 {
68  public:
70  virtual ~SatLoraFirstWindowTestCase();
71 
72  private:
73  virtual void DoRun(void);
74  void MacTraceCb(std::string context, Ptr<const Packet> packet, const Address& address);
75 
78 
79  Address m_gwAddress;
80  Address m_edAddress;
81 };
82 
84  : TestCase("Test satellite lorawan with acks sent in first window."),
85  m_gwReceiveDate(Seconds(0)),
86  m_edReceiveDate(Seconds(0))
87 {
88 }
89 
91 {
92 }
93 
94 void
96  Ptr<const Packet> packet,
97  const Address& address)
98 {
99  if (address == m_edAddress)
100  {
101  m_gwReceiveDate = Simulator::Now();
102  }
103 
104  if (address == m_gwAddress)
105  {
106  m_edReceiveDate = Simulator::Now();
107  }
108 }
109 
110 void
112 {
113  // Set simulation output details
114  Singleton<SatEnvVariables>::Get()->DoInitialize();
115  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-sat-lora", "first-window", true);
116 
117  // Enable Lora
118  Config::SetDefault("ns3::SatHelper::Standard", EnumValue(SatEnums::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::SatLorawanNetDevice::ForwardToUtUsers", BooleanValue(false));
123  Config::SetDefault("ns3::SatLoraConf::Standard", EnumValue(SatLoraConf::SATELLITE));
124 
125  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::FirstWindowDelay",
126  TimeValue(MilliSeconds(1500)));
127  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::SecondWindowDelay", TimeValue(Seconds(2)));
128  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::FirstWindowDuration",
129  TimeValue(MilliSeconds(400)));
130  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::SecondWindowDuration",
131  TimeValue(MilliSeconds(400)));
132  Config::SetDefault("ns3::LoraNetworkScheduler::FirstWindowAnswerDelay", TimeValue(Seconds(1)));
133  Config::SetDefault("ns3::LoraNetworkScheduler::SecondWindowAnswerDelay", TimeValue(Seconds(2)));
134 
135  // Superframe configuration
136  Config::SetDefault("ns3::SatConf::SuperFrameConfForSeq0",
137  EnumValue(SatSuperframeConf::SUPER_FRAME_CONFIG_4));
138  Config::SetDefault("ns3::SatSuperframeConf4::FrameConfigType",
139  EnumValue(SatSuperframeConf::CONFIG_TYPE_4));
140  Config::SetDefault("ns3::SatSuperframeConf4::Frame0_AllocatedBandwidthHz", DoubleValue(15000));
141  Config::SetDefault("ns3::SatSuperframeConf4::Frame0_CarrierAllocatedBandwidthHz",
142  DoubleValue(15000));
143 
144  // CRDSA only
145  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided",
146  BooleanValue(false));
147  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_RbdcAllowed",
148  BooleanValue(false));
149 
150  // Configure RA
151  Config::SetDefault("ns3::SatBeamHelper::RandomAccessModel", EnumValue(SatEnums::RA_MODEL_ESSA));
152  Config::SetDefault("ns3::SatBeamHelper::RaInterferenceEliminationModel",
153  EnumValue(SatPhyRxCarrierConf::SIC_RESIDUAL));
154  Config::SetDefault("ns3::SatBeamHelper::RaCollisionModel",
155  EnumValue(SatPhyRxCarrierConf::RA_COLLISION_CHECK_AGAINST_SINR));
156  Config::SetDefault("ns3::SatBeamHelper::ReturnLinkLinkResults", EnumValue(SatEnums::LR_LORA));
157  Config::SetDefault("ns3::SatWaveformConf::DefaultWfId", UintegerValue(2));
158  Config::SetDefault("ns3::SatHelper::RtnLinkWaveformConfFileName",
159  StringValue("loraWaveforms.txt"));
160 
161  // Configure E-SSA
162  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::WindowDuration", StringValue("600ms"));
163  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::WindowStep", StringValue("200ms"));
164  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::WindowSICIterations", UintegerValue(5));
165  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::EnableSIC", BooleanValue(false));
166 
167  Config::SetDefault("ns3::SatMac::EnableStatisticsTags", BooleanValue(true));
168 
169  // Creating the reference system.
170  Ptr<SatHelper> helper = CreateObject<SatHelper>();
171  helper->CreatePredefinedScenario(SatHelper::SIMPLE);
172 
173  // >>> Start of actual test using Simple scenario >>>
174  Ptr<Node> utNode = helper->UtNodes().Get(0);
175  Ptr<LoraPeriodicSender> app = Create<LoraPeriodicSender>();
176 
177  app->SetInterval(Seconds(10));
178 
179  app->SetStartTime(Seconds(1.0));
180  app->SetStopTime(Seconds(10.0));
181  app->SetPacketSize(24);
182 
183  app->SetNode(utNode);
184  utNode->AddApplication(app);
185 
186  m_gwAddress = helper->GwNodes().Get(0)->GetDevice(1)->GetAddress();
187  m_edAddress = helper->UtNodes().Get(0)->GetDevice(2)->GetAddress();
188 
189  Config::Connect("/NodeList/*/DeviceList/*/SatMac/Rx",
190  MakeCallback(&SatLoraFirstWindowTestCase::MacTraceCb, this));
191 
192  Simulator::Stop(Seconds(10));
193  Simulator::Run();
194 
195  Simulator::Destroy();
196 
197  Singleton<SatEnvVariables>::Get()->DoDispose();
198 
199  NS_TEST_ASSERT_MSG_NE(m_gwReceiveDate, Seconds(0), "Packet should be received by Gateway.");
200  NS_TEST_ASSERT_MSG_NE(m_edReceiveDate, Seconds(0), "Ack should be received by End Device.");
201  NS_TEST_ASSERT_MSG_GT(m_edReceiveDate, m_gwReceiveDate, "Ack should be received after packet.");
202 
203  Time difference = m_edReceiveDate - m_gwReceiveDate;
204  Time delay = MilliSeconds(130);
205 
206  NS_TEST_ASSERT_MSG_GT(difference, Seconds(1) + delay, "Ack arrived too early.");
207  NS_TEST_ASSERT_MSG_LT(difference + delay,
208  MilliSeconds(1900) + delay,
209  "Ack arrived too late. First window should be closed.");
210 }
211 
221 class SatLoraSecondWindowTestCase : public TestCase
222 {
223  public:
226 
227  private:
228  virtual void DoRun(void);
229  void MacTraceCb(std::string context, Ptr<const Packet> packet, const Address& address);
230 
233 
234  Address m_gwAddress;
235  Address m_edAddress;
236 };
237 
239  : TestCase("Test satellite lorawan with acks sent in second window."),
240  m_gwReceiveDate(Seconds(0)),
241  m_edReceiveDate(Seconds(0))
242 {
243 }
244 
246 {
247 }
248 
249 void
251  Ptr<const Packet> packet,
252  const Address& address)
253 {
254  if (address == m_edAddress)
255  {
256  m_gwReceiveDate = Simulator::Now();
257  }
258 
259  if (address == m_gwAddress)
260  {
261  m_edReceiveDate = Simulator::Now();
262  }
263 }
264 
265 void
267 {
268  // Set simulation output details
269  Singleton<SatEnvVariables>::Get()->DoInitialize();
270  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-sat-lora", "second-window", true);
271 
272  // Enable Lora
273  Config::SetDefault("ns3::SatHelper::Standard", EnumValue(SatEnums::LORA));
274  Config::SetDefault("ns3::LorawanMacEndDevice::DataRate", UintegerValue(5));
275  Config::SetDefault("ns3::LorawanMacEndDevice::MType",
276  EnumValue(LorawanMacHeader::CONFIRMED_DATA_UP));
277  Config::SetDefault("ns3::SatLorawanNetDevice::ForwardToUtUsers", BooleanValue(false));
278  Config::SetDefault("ns3::SatLoraConf::Standard", EnumValue(SatLoraConf::SATELLITE));
279 
280  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::FirstWindowDelay",
281  TimeValue(MilliSeconds(1500)));
282  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::SecondWindowDelay", TimeValue(Seconds(2)));
283  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::FirstWindowDuration",
284  TimeValue(MilliSeconds(400)));
285  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::SecondWindowDuration",
286  TimeValue(MilliSeconds(400)));
287  // Increase answer delay by 500ms compared to SatLoraSecondWindowTestCase to be in second window
288  // on End Device
289  Config::SetDefault("ns3::LoraNetworkScheduler::FirstWindowAnswerDelay",
290  TimeValue(Seconds(1) + MilliSeconds(500)));
291  Config::SetDefault("ns3::LoraNetworkScheduler::SecondWindowAnswerDelay", TimeValue(Seconds(2)));
292 
293  // Superframe configuration
294  Config::SetDefault("ns3::SatConf::SuperFrameConfForSeq0",
295  EnumValue(SatSuperframeConf::SUPER_FRAME_CONFIG_4));
296  Config::SetDefault("ns3::SatSuperframeConf4::FrameConfigType",
297  EnumValue(SatSuperframeConf::CONFIG_TYPE_4));
298  Config::SetDefault("ns3::SatSuperframeConf4::Frame0_AllocatedBandwidthHz", DoubleValue(15000));
299  Config::SetDefault("ns3::SatSuperframeConf4::Frame0_CarrierAllocatedBandwidthHz",
300  DoubleValue(15000));
301 
302  // CRDSA only
303  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided",
304  BooleanValue(false));
305  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_RbdcAllowed",
306  BooleanValue(false));
307 
308  // Configure RA
309  Config::SetDefault("ns3::SatBeamHelper::RandomAccessModel", EnumValue(SatEnums::RA_MODEL_ESSA));
310  Config::SetDefault("ns3::SatBeamHelper::RaInterferenceEliminationModel",
311  EnumValue(SatPhyRxCarrierConf::SIC_RESIDUAL));
312  Config::SetDefault("ns3::SatBeamHelper::RaCollisionModel",
313  EnumValue(SatPhyRxCarrierConf::RA_COLLISION_CHECK_AGAINST_SINR));
314  Config::SetDefault("ns3::SatBeamHelper::ReturnLinkLinkResults", EnumValue(SatEnums::LR_LORA));
315  Config::SetDefault("ns3::SatWaveformConf::DefaultWfId", UintegerValue(2));
316  Config::SetDefault("ns3::SatHelper::RtnLinkWaveformConfFileName",
317  StringValue("loraWaveforms.txt"));
318 
319  // Configure E-SSA
320  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::WindowDuration", StringValue("600ms"));
321  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::WindowStep", StringValue("200ms"));
322  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::WindowSICIterations", UintegerValue(5));
323  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::EnableSIC", BooleanValue(false));
324 
325  Config::SetDefault("ns3::SatMac::EnableStatisticsTags", BooleanValue(true));
326 
327  // Creating the reference system.
328  Ptr<SatHelper> helper = CreateObject<SatHelper>();
329  helper->CreatePredefinedScenario(SatHelper::SIMPLE);
330 
331  // >>> Start of actual test using Simple scenario >>>
332  Ptr<Node> utNode = helper->UtNodes().Get(0);
333  Ptr<LoraPeriodicSender> app = Create<LoraPeriodicSender>();
334 
335  app->SetInterval(Seconds(10));
336 
337  app->SetStartTime(Seconds(1.0));
338  app->SetStopTime(Seconds(10.0));
339  app->SetPacketSize(24);
340 
341  app->SetNode(utNode);
342  utNode->AddApplication(app);
343 
344  m_gwAddress = helper->GwNodes().Get(0)->GetDevice(1)->GetAddress();
345  m_edAddress = helper->UtNodes().Get(0)->GetDevice(2)->GetAddress();
346 
347  Config::Connect("/NodeList/*/DeviceList/*/SatMac/Rx",
348  MakeCallback(&SatLoraSecondWindowTestCase::MacTraceCb, this));
349 
350  Simulator::Stop(Seconds(10));
351  Simulator::Run();
352 
353  Simulator::Destroy();
354 
355  Singleton<SatEnvVariables>::Get()->DoDispose();
356  NS_TEST_ASSERT_MSG_NE(m_gwReceiveDate, Seconds(0), "Packet should be received by Gateway.");
357  NS_TEST_ASSERT_MSG_NE(m_edReceiveDate, Seconds(0), "Ack should be received by End Device.");
358  NS_TEST_ASSERT_MSG_GT(m_edReceiveDate, m_gwReceiveDate, "Ack should be received after packet.");
359 
360  Time difference = m_edReceiveDate - m_gwReceiveDate;
361  Time delay = MilliSeconds(130);
362 
363  NS_TEST_ASSERT_MSG_GT(difference, Seconds(1.5) + delay, "Ack arrived too early.");
364  NS_TEST_ASSERT_MSG_LT(difference + delay,
365  MilliSeconds(2400) + delay,
366  "Ack arrived too late. Second window should be closed.");
367 }
368 
377 class SatLoraOutOfWindowWindowTestCase : public TestCase
378 {
379  public:
382 
383  private:
384  virtual void DoRun(void);
385  void MacTraceCb(std::string context, Ptr<const Packet> packet, const Address& address);
386  void PhyTraceCb(std::string context, Ptr<const Packet> packet, const Address& address);
387 
388  std::vector<Time> m_gwReceiveDates;
390 
391  Address m_gwAddress;
392  Address m_edAddress;
393 
396 };
397 
399  : TestCase("Test satellite lorawan with acks sent in second window."),
400  m_edReceiveDate(Seconds(0)),
401  m_phyGwReceive(false),
402  m_phyEdReceive(false)
403 {
404 }
405 
407 {
408 }
409 
410 void
412  Ptr<const Packet> packet,
413  const Address& address)
414 {
415  if (address == m_edAddress)
416  {
417  m_gwReceiveDates.push_back(Simulator::Now());
418  }
419 
420  if (address == m_gwAddress)
421  {
422  m_edReceiveDate = Simulator::Now();
423  }
424 }
425 
426 void
428  Ptr<const Packet> packet,
429  const Address& address)
430 {
431  if (address == m_edAddress)
432  {
433  m_phyGwReceive = true;
434  }
435 
436  if (address == m_gwAddress)
437  {
438  m_phyEdReceive = true;
439  }
440 }
441 
442 void
444 {
445  // Set simulation output details
446  Singleton<SatEnvVariables>::Get()->DoInitialize();
447  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-sat-lora", "out-of-window", true);
448 
449  // Enable Lora
450  Config::SetDefault("ns3::SatHelper::Standard", EnumValue(SatEnums::LORA));
451  Config::SetDefault("ns3::LorawanMacEndDevice::DataRate", UintegerValue(5));
452  Config::SetDefault("ns3::LorawanMacEndDevice::MType",
453  EnumValue(LorawanMacHeader::CONFIRMED_DATA_UP));
454  Config::SetDefault("ns3::SatLorawanNetDevice::ForwardToUtUsers", BooleanValue(false));
455  Config::SetDefault("ns3::SatLoraConf::Standard", EnumValue(SatLoraConf::SATELLITE));
456 
457  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::FirstWindowDelay",
458  TimeValue(MilliSeconds(1500)));
459  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::SecondWindowDelay", TimeValue(Seconds(2)));
460  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::FirstWindowDuration",
461  TimeValue(MilliSeconds(400)));
462  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::SecondWindowDuration",
463  TimeValue(MilliSeconds(400)));
464  // Send answer too early
465  Config::SetDefault("ns3::LoraNetworkScheduler::FirstWindowAnswerDelay",
466  TimeValue(Seconds(0.1)));
467  Config::SetDefault("ns3::LoraNetworkScheduler::SecondWindowAnswerDelay", TimeValue(Seconds(2)));
468 
469  // Superframe configuration
470  Config::SetDefault("ns3::SatConf::SuperFrameConfForSeq0",
471  EnumValue(SatSuperframeConf::SUPER_FRAME_CONFIG_4));
472  Config::SetDefault("ns3::SatSuperframeConf4::FrameConfigType",
473  EnumValue(SatSuperframeConf::CONFIG_TYPE_4));
474  Config::SetDefault("ns3::SatSuperframeConf4::Frame0_AllocatedBandwidthHz", DoubleValue(15000));
475  Config::SetDefault("ns3::SatSuperframeConf4::Frame0_CarrierAllocatedBandwidthHz",
476  DoubleValue(15000));
477 
478  // CRDSA only
479  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided",
480  BooleanValue(false));
481  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_RbdcAllowed",
482  BooleanValue(false));
483 
484  // Configure RA
485  Config::SetDefault("ns3::SatBeamHelper::RandomAccessModel", EnumValue(SatEnums::RA_MODEL_ESSA));
486  Config::SetDefault("ns3::SatBeamHelper::RaInterferenceEliminationModel",
487  EnumValue(SatPhyRxCarrierConf::SIC_RESIDUAL));
488  Config::SetDefault("ns3::SatBeamHelper::RaCollisionModel",
489  EnumValue(SatPhyRxCarrierConf::RA_COLLISION_CHECK_AGAINST_SINR));
490  Config::SetDefault("ns3::SatBeamHelper::ReturnLinkLinkResults", EnumValue(SatEnums::LR_LORA));
491  Config::SetDefault("ns3::SatWaveformConf::DefaultWfId", UintegerValue(2));
492  Config::SetDefault("ns3::SatHelper::RtnLinkWaveformConfFileName",
493  StringValue("loraWaveforms.txt"));
494 
495  // Configure E-SSA
496  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::WindowDuration", StringValue("600ms"));
497  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::WindowStep", StringValue("200ms"));
498  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::WindowSICIterations", UintegerValue(5));
499  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::EnableSIC", BooleanValue(false));
500 
501  Config::SetDefault("ns3::SatMac::EnableStatisticsTags", BooleanValue(true));
502  Config::SetDefault("ns3::SatPhy::EnableStatisticsTags", BooleanValue(true));
503 
504  // Creating the reference system.
505  Ptr<SatHelper> helper = CreateObject<SatHelper>();
506  helper->CreatePredefinedScenario(SatHelper::SIMPLE);
507 
508  // >>> Start of actual test using Simple scenario >>>
509  Ptr<Node> utNode = helper->UtNodes().Get(0);
510  Ptr<LoraPeriodicSender> app = Create<LoraPeriodicSender>();
511 
512  app->SetInterval(Seconds(10));
513 
514  app->SetStartTime(Seconds(1.0));
515  app->SetStopTime(Seconds(10.0));
516  app->SetPacketSize(24);
517 
518  app->SetNode(utNode);
519  utNode->AddApplication(app);
520 
521  m_gwAddress = helper->GwNodes().Get(0)->GetDevice(1)->GetAddress();
522  m_edAddress = helper->UtNodes().Get(0)->GetDevice(2)->GetAddress();
523 
524  Config::Connect("/NodeList/*/DeviceList/*/SatMac/Rx",
525  MakeCallback(&SatLoraOutOfWindowWindowTestCase::MacTraceCb, this));
526  Config::Connect("/NodeList/*/DeviceList/*/SatPhy/Rx",
527  MakeCallback(&SatLoraOutOfWindowWindowTestCase::PhyTraceCb, this));
528 
529  Simulator::Stop(Seconds(10));
530  Simulator::Run();
531 
532  Simulator::Destroy();
533 
534  Singleton<SatEnvVariables>::Get()->DoDispose();
535 
536  NS_TEST_ASSERT_MSG_EQ(m_gwReceiveDates.size(),
537  2,
538  "GW should receive a packet and the first retransmission.");
539  NS_TEST_ASSERT_MSG_EQ(m_edReceiveDate, Seconds(0), "No ack should be received by End Device.");
540 
541  NS_TEST_ASSERT_MSG_EQ(m_phyGwReceive,
542  true,
543  "Phy layer should trace traffic from End Device to Gateway.");
544  NS_TEST_ASSERT_MSG_EQ(m_phyEdReceive,
545  false,
546  "Phy layer should not trace traffic from Gateway to End Device, as phy "
547  "layer is in SLEEP state.");
548 }
549 
560 {
561  public:
564 
565  private:
566  virtual void DoRun(void);
567  void MacTraceCb(std::string context, Ptr<const Packet> packet, const Address& address);
568  void PhyTraceCb(std::string context, Ptr<const Packet> packet, const Address& address);
569 
570  std::vector<Time> m_gwReceiveDates;
572 
573  Address m_gwAddress;
574  Address m_edAddress;
575 };
576 
578  : TestCase("Test satellite lorawan with acks sent in second window."),
579  m_edReceiveDate(Seconds(0))
580 {
581 }
582 
585 {
586 }
587 
588 void
590  Ptr<const Packet> packet,
591  const Address& address)
592 {
593  if (address == m_edAddress)
594  {
595  m_gwReceiveDates.push_back(Simulator::Now());
596  }
597 
598  if (address == m_gwAddress)
599  {
600  m_edReceiveDate = Simulator::Now();
601  }
602 }
603 
604 void
606 {
607  // Set simulation output details
608  Singleton<SatEnvVariables>::Get()->DoInitialize();
609  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-sat-lora", "out-of-window", true);
610 
611  // Enable Lora
612  Config::SetDefault("ns3::SatHelper::Standard", EnumValue(SatEnums::LORA));
613  Config::SetDefault("ns3::LorawanMacEndDevice::DataRate", UintegerValue(5));
614  Config::SetDefault("ns3::LorawanMacEndDevice::MType",
615  EnumValue(LorawanMacHeader::UNCONFIRMED_DATA_UP));
616  Config::SetDefault("ns3::SatLorawanNetDevice::ForwardToUtUsers", BooleanValue(false));
617  Config::SetDefault("ns3::SatLoraConf::Standard", EnumValue(SatLoraConf::SATELLITE));
618 
619  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::FirstWindowDelay",
620  TimeValue(MilliSeconds(1500)));
621  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::SecondWindowDelay", TimeValue(Seconds(2)));
622  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::FirstWindowDuration",
623  TimeValue(MilliSeconds(400)));
624  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::SecondWindowDuration",
625  TimeValue(MilliSeconds(400)));
626  // Send answer too early
627  Config::SetDefault("ns3::LoraNetworkScheduler::FirstWindowAnswerDelay",
628  TimeValue(Seconds(0.1)));
629  Config::SetDefault("ns3::LoraNetworkScheduler::SecondWindowAnswerDelay", TimeValue(Seconds(2)));
630 
631  // Superframe configuration
632  Config::SetDefault("ns3::SatConf::SuperFrameConfForSeq0",
633  EnumValue(SatSuperframeConf::SUPER_FRAME_CONFIG_4));
634  Config::SetDefault("ns3::SatSuperframeConf4::FrameConfigType",
635  EnumValue(SatSuperframeConf::CONFIG_TYPE_4));
636  Config::SetDefault("ns3::SatSuperframeConf4::Frame0_AllocatedBandwidthHz", DoubleValue(15000));
637  Config::SetDefault("ns3::SatSuperframeConf4::Frame0_CarrierAllocatedBandwidthHz",
638  DoubleValue(15000));
639 
640  // CRDSA only
641  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided",
642  BooleanValue(false));
643  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_RbdcAllowed",
644  BooleanValue(false));
645 
646  // Configure RA
647  Config::SetDefault("ns3::SatBeamHelper::RandomAccessModel", EnumValue(SatEnums::RA_MODEL_ESSA));
648  Config::SetDefault("ns3::SatBeamHelper::RaInterferenceEliminationModel",
649  EnumValue(SatPhyRxCarrierConf::SIC_RESIDUAL));
650  Config::SetDefault("ns3::SatBeamHelper::RaCollisionModel",
651  EnumValue(SatPhyRxCarrierConf::RA_COLLISION_CHECK_AGAINST_SINR));
652  Config::SetDefault("ns3::SatBeamHelper::ReturnLinkLinkResults", EnumValue(SatEnums::LR_LORA));
653  Config::SetDefault("ns3::SatWaveformConf::DefaultWfId", UintegerValue(2));
654  Config::SetDefault("ns3::SatHelper::RtnLinkWaveformConfFileName",
655  StringValue("loraWaveforms.txt"));
656 
657  // Configure E-SSA
658  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::WindowDuration", StringValue("600ms"));
659  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::WindowStep", StringValue("200ms"));
660  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::WindowSICIterations", UintegerValue(5));
661  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::EnableSIC", BooleanValue(false));
662 
663  Config::SetDefault("ns3::SatMac::EnableStatisticsTags", BooleanValue(true));
664  Config::SetDefault("ns3::SatPhy::EnableStatisticsTags", BooleanValue(true));
665 
666  // Creating the reference system.
667  Ptr<SatHelper> helper = CreateObject<SatHelper>();
668  helper->CreatePredefinedScenario(SatHelper::SIMPLE);
669 
670  // >>> Start of actual test using Simple scenario >>>
671  Ptr<Node> utNode = helper->UtNodes().Get(0);
672  Ptr<LoraPeriodicSender> app = Create<LoraPeriodicSender>();
673 
674  app->SetInterval(Seconds(10));
675 
676  app->SetStartTime(Seconds(1.0));
677  app->SetStopTime(Seconds(10.0));
678  app->SetPacketSize(24);
679 
680  app->SetNode(utNode);
681  utNode->AddApplication(app);
682 
683  m_gwAddress = helper->GwNodes().Get(0)->GetDevice(1)->GetAddress();
684  m_edAddress = helper->UtNodes().Get(0)->GetDevice(2)->GetAddress();
685 
686  Config::Connect(
687  "/NodeList/*/DeviceList/*/SatMac/Rx",
689 
690  Simulator::Stop(Seconds(10));
691  Simulator::Run();
692 
693  Simulator::Destroy();
694 
695  Singleton<SatEnvVariables>::Get()->DoDispose();
696 
697  NS_TEST_ASSERT_MSG_EQ(m_gwReceiveDates.size(),
698  1,
699  "GW should receive a packet but no retransmission.");
700  NS_TEST_ASSERT_MSG_EQ(m_edReceiveDate, Seconds(0), "No ack should be received by End Device.");
701 }
702 
711 class SatLoraCbrTestCase : public TestCase
712 {
713  public:
715  virtual ~SatLoraCbrTestCase();
716 
717  private:
718  virtual void DoRun(void);
719  void MacTraceCb(std::string context, Ptr<const Packet> packet, const Address& address);
720 
723 
724  Address m_gwAddress;
725  Address m_edAddress;
726 };
727 
729  : TestCase("Test satellite lorawan with acks sent in second window."),
730  m_edReceiveDate(Seconds(0))
731 {
732 }
733 
735 {
736 }
737 
738 void
739 SatLoraCbrTestCase::MacTraceCb(std::string context,
740  Ptr<const Packet> packet,
741  const Address& address)
742 {
743  if (address == m_edAddress)
744  {
745  m_gwReceiveDate = Simulator::Now();
746  }
747 
748  if (address == m_gwAddress)
749  {
750  m_edReceiveDate = Simulator::Now();
751  }
752 }
753 
754 void
756 {
757  // Set simulation output details
758  Singleton<SatEnvVariables>::Get()->DoInitialize();
759  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-sat-lora", "cbr", true);
760 
761  // Enable Lora
762  Config::SetDefault("ns3::SatHelper::Standard", EnumValue(SatEnums::LORA));
763  Config::SetDefault("ns3::LorawanMacEndDevice::DataRate", UintegerValue(5));
764  Config::SetDefault("ns3::LorawanMacEndDevice::MType",
765  EnumValue(LorawanMacHeader::CONFIRMED_DATA_UP));
766  Config::SetDefault("ns3::SatLorawanNetDevice::ForwardToUtUsers", BooleanValue(true));
767  Config::SetDefault("ns3::SatLoraConf::Standard", EnumValue(SatLoraConf::SATELLITE));
768 
769  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::FirstWindowDelay",
770  TimeValue(MilliSeconds(1500)));
771  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::SecondWindowDelay", TimeValue(Seconds(2)));
772  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::FirstWindowDuration",
773  TimeValue(MilliSeconds(400)));
774  Config::SetDefault("ns3::LorawanMacEndDeviceClassA::SecondWindowDuration",
775  TimeValue(MilliSeconds(400)));
776  Config::SetDefault("ns3::LoraNetworkScheduler::FirstWindowAnswerDelay", TimeValue(Seconds(1)));
777  Config::SetDefault("ns3::LoraNetworkScheduler::SecondWindowAnswerDelay", TimeValue(Seconds(2)));
778 
779  // Superframe configuration
780  Config::SetDefault("ns3::SatConf::SuperFrameConfForSeq0",
781  EnumValue(SatSuperframeConf::SUPER_FRAME_CONFIG_4));
782  Config::SetDefault("ns3::SatSuperframeConf4::FrameConfigType",
783  EnumValue(SatSuperframeConf::CONFIG_TYPE_4));
784  Config::SetDefault("ns3::SatSuperframeConf4::Frame0_AllocatedBandwidthHz", DoubleValue(15000));
785  Config::SetDefault("ns3::SatSuperframeConf4::Frame0_CarrierAllocatedBandwidthHz",
786  DoubleValue(15000));
787 
788  // CRDSA only
789  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided",
790  BooleanValue(false));
791  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_RbdcAllowed",
792  BooleanValue(false));
793 
794  // Configure RA
795  Config::SetDefault("ns3::SatBeamHelper::RandomAccessModel", EnumValue(SatEnums::RA_MODEL_ESSA));
796  Config::SetDefault("ns3::SatBeamHelper::RaInterferenceEliminationModel",
797  EnumValue(SatPhyRxCarrierConf::SIC_RESIDUAL));
798  Config::SetDefault("ns3::SatBeamHelper::RaCollisionModel",
799  EnumValue(SatPhyRxCarrierConf::RA_COLLISION_CHECK_AGAINST_SINR));
800  Config::SetDefault("ns3::SatBeamHelper::ReturnLinkLinkResults", EnumValue(SatEnums::LR_LORA));
801  Config::SetDefault("ns3::SatWaveformConf::DefaultWfId", UintegerValue(2));
802  Config::SetDefault("ns3::SatHelper::RtnLinkWaveformConfFileName",
803  StringValue("loraWaveforms.txt"));
804 
805  // Configure E-SSA
806  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::WindowDuration", StringValue("600ms"));
807  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::WindowStep", StringValue("200ms"));
808  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::WindowSICIterations", UintegerValue(5));
809  Config::SetDefault("ns3::SatPhyRxCarrierPerWindow::EnableSIC", BooleanValue(false));
810 
811  Config::SetDefault("ns3::CbrApplication::Interval", StringValue("10s"));
812  Config::SetDefault("ns3::CbrApplication::PacketSize", UintegerValue(24));
813 
814  Config::SetDefault("ns3::SatMac::EnableStatisticsTags", BooleanValue(true));
815  // Creating the reference system.
816  Ptr<SatHelper> helper = CreateObject<SatHelper>();
817  helper->CreatePredefinedScenario(SatHelper::SIMPLE);
818 
819  NodeContainer utUsers = helper->GetUtUsers();
820  NodeContainer gwUsers = helper->GetGwUsers();
821  InetSocketAddress gwUserAddr = InetSocketAddress(helper->GetUserAddress(gwUsers.Get(0)), 9);
822 
823  PacketSinkHelper sinkHelper("ns3::UdpSocketFactory", Address());
824  CbrHelper cbrHelper("ns3::UdpSocketFactory", Address());
825  ApplicationContainer sinkContainer;
826  ApplicationContainer cbrContainer;
827 
828  sinkHelper.SetAttribute("Local", AddressValue(Address(gwUserAddr)));
829  sinkContainer.Add(sinkHelper.Install(gwUsers.Get(0)));
830 
831  cbrHelper.SetAttribute("Remote", AddressValue(Address(gwUserAddr)));
832 
833  auto app = cbrHelper.Install(utUsers.Get(0)).Get(0);
834  app->SetStartTime(Seconds(1));
835  cbrContainer.Add(app);
836 
837  sinkContainer.Start(Seconds(1));
838  sinkContainer.Stop(Seconds(20));
839 
840  m_gwAddress = helper->GwNodes().Get(0)->GetDevice(1)->GetAddress();
841  m_edAddress = helper->UtNodes().Get(0)->GetDevice(2)->GetAddress();
842 
843  Ptr<PacketSink> receiver = DynamicCast<PacketSink>(sinkContainer.Get(0));
844 
845  Config::Connect("/NodeList/*/DeviceList/*/SatMac/Rx",
846  MakeCallback(&SatLoraCbrTestCase::MacTraceCb, this));
847 
848  Simulator::Stop(Seconds(20));
849  Simulator::Run();
850 
851  Simulator::Destroy();
852 
853  Singleton<SatEnvVariables>::Get()->DoDispose();
854 
855  NS_TEST_ASSERT_MSG_NE(m_gwReceiveDate, Seconds(0), "Packet should be received by Gateway.");
856  NS_TEST_ASSERT_MSG_NE(m_edReceiveDate, Seconds(0), "Ack should be received by End Device.");
857  NS_TEST_ASSERT_MSG_GT(m_edReceiveDate, m_gwReceiveDate, "Ack should be received after packet.");
858 
859  Time difference = m_edReceiveDate - m_gwReceiveDate;
860  Time delay = MilliSeconds(130);
861 
862  NS_TEST_ASSERT_MSG_GT(difference, Seconds(1) + delay, "Ack arrived too early.");
863  NS_TEST_ASSERT_MSG_LT(difference + delay,
864  MilliSeconds(1900) + delay,
865  "Ack arrived too late. First window should be closed.");
866 
867  NS_TEST_ASSERT_MSG_EQ(receiver->GetTotalRx(), 24, "Sink should receive one packet of 24 bytes");
868 }
869 
874 class SatLoraTestSuite : public TestSuite
875 {
876  public:
878 };
879 
881  : TestSuite("sat-lora-test", UNIT)
882 {
883  AddTestCase(new SatLoraFirstWindowTestCase, TestCase::QUICK);
884  AddTestCase(new SatLoraSecondWindowTestCase, TestCase::QUICK);
885  AddTestCase(new SatLoraOutOfWindowWindowTestCase, TestCase::QUICK);
886  AddTestCase(new SatLoraOutOfWindowWindowNoRetransmissionTestCase, TestCase::QUICK);
887  AddTestCase(new SatLoraCbrTestCase, TestCase::QUICK);
888 }
889 
890 // 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