OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * This script simulates a complex scenario with multiple gateways and end |
| 3 * devices. The metric of interest for this script is the throughput of the |
| 4 * network. |
| 5 */ |
| 6 |
| 7 #include "ns3/end-device-lora-phy.h" |
| 8 #include "ns3/gateway-lora-phy.h" |
| 9 #include "ns3/end-device-lora-mac.h" |
| 10 #include "ns3/gateway-lora-mac.h" |
| 11 #include "ns3/simulator.h" |
| 12 #include "ns3/log.h" |
| 13 #include "ns3/constant-position-mobility-model.h" |
| 14 #include "ns3/lora-helper.h" |
| 15 #include "ns3/mobility-helper.h" |
| 16 #include "ns3/node-container.h" |
| 17 #include "ns3/position-allocator.h" |
| 18 #include "ns3/one-shot-sender-helper.h" |
| 19 #include "ns3/command-line.h" |
| 20 #include <algorithm> |
| 21 #include <ctime> |
| 22 |
| 23 using namespace ns3; |
| 24 |
| 25 NS_LOG_COMPONENT_DEFINE ("SimpleLorawanNetworkExample"); |
| 26 |
| 27 int main (int argc, char *argv[]) |
| 28 { |
| 29 |
| 30 // Set up logging |
| 31 LogComponentEnable ("SimpleLorawanNetworkExample", LOG_LEVEL_ALL); |
| 32 LogComponentEnable ("LoraChannel", LOG_LEVEL_INFO); |
| 33 LogComponentEnable ("LoraPhy", LOG_LEVEL_ALL); |
| 34 LogComponentEnable ("EndDeviceLoraPhy", LOG_LEVEL_ALL); |
| 35 LogComponentEnable ("GatewayLoraPhy", LOG_LEVEL_ALL); |
| 36 LogComponentEnable ("LoraInterferenceHelper", LOG_LEVEL_ALL); |
| 37 LogComponentEnable ("LoraMac", LOG_LEVEL_ALL); |
| 38 LogComponentEnable ("EndDeviceLoraMac", LOG_LEVEL_ALL); |
| 39 LogComponentEnable ("GatewayLoraMac", LOG_LEVEL_ALL); |
| 40 LogComponentEnable ("LogicalLoraChannelHelper", LOG_LEVEL_ALL); |
| 41 LogComponentEnable ("LogicalLoraChannel", LOG_LEVEL_ALL); |
| 42 LogComponentEnable ("LoraHelper", LOG_LEVEL_ALL); |
| 43 LogComponentEnable ("LoraPhyHelper", LOG_LEVEL_ALL); |
| 44 LogComponentEnable ("LoraMacHelper", LOG_LEVEL_ALL); |
| 45 LogComponentEnable ("OneShotSenderHelper", LOG_LEVEL_ALL); |
| 46 LogComponentEnable ("OneShotSender", LOG_LEVEL_ALL); |
| 47 LogComponentEnable ("LoraMacHeader", LOG_LEVEL_ALL); |
| 48 LogComponentEnable ("LoraFrameHeader", LOG_LEVEL_ALL); |
| 49 LogComponentEnableAll (LOG_PREFIX_FUNC); |
| 50 LogComponentEnableAll (LOG_PREFIX_NODE); |
| 51 LogComponentEnableAll (LOG_PREFIX_TIME); |
| 52 |
| 53 /************************ |
| 54 * Create the channel * |
| 55 ************************/ |
| 56 |
| 57 NS_LOG_INFO ("Creating the channel..."); |
| 58 |
| 59 // Create the lora channel object |
| 60 Ptr<LogDistancePropagationLossModel> loss = CreateObject<LogDistancePropagatio
nLossModel> (); |
| 61 loss->SetPathLossExponent (3.76); |
| 62 loss->SetReference (1, 8.1); |
| 63 |
| 64 Ptr<PropagationDelayModel> delay = CreateObject<ConstantSpeedPropagationDelayM
odel> (); |
| 65 |
| 66 Ptr<LoraChannel> channel = CreateObject<LoraChannel> (loss, delay); |
| 67 |
| 68 /************************ |
| 69 * Create the helpers * |
| 70 ************************/ |
| 71 |
| 72 NS_LOG_INFO ("Setting up helpers..."); |
| 73 |
| 74 MobilityHelper mobility; |
| 75 Ptr<ListPositionAllocator> allocator = CreateObject<ListPositionAllocator> (); |
| 76 allocator->Add (Vector (1000,0,0)); |
| 77 allocator->Add (Vector (0,0,0)); |
| 78 mobility.SetPositionAllocator (allocator); |
| 79 mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); |
| 80 |
| 81 // Create the LoraPhyHelper |
| 82 LoraPhyHelper phyHelper = LoraPhyHelper (); |
| 83 phyHelper.SetChannel (channel); |
| 84 |
| 85 // Create the LoraMacHelper |
| 86 LoraMacHelper macHelper = LoraMacHelper (); |
| 87 |
| 88 // Create the LoraHelper |
| 89 LoraHelper helper = LoraHelper (); |
| 90 |
| 91 /************************ |
| 92 * Create End Devices * |
| 93 ************************/ |
| 94 |
| 95 NS_LOG_INFO ("Creating the end device..."); |
| 96 |
| 97 // Create a set of nodes |
| 98 NodeContainer endDevices; |
| 99 endDevices.Create (1); |
| 100 |
| 101 // Assign a mobility model to the node |
| 102 mobility.Install (endDevices); |
| 103 |
| 104 // Create the LoraNetDevices of the end devices |
| 105 phyHelper.SetDeviceType (LoraPhyHelper::ED); |
| 106 macHelper.SetDeviceType (LoraMacHelper::ED); |
| 107 helper.Install (phyHelper, macHelper, endDevices); |
| 108 |
| 109 /********************* |
| 110 * Create Gateways * |
| 111 *********************/ |
| 112 |
| 113 NS_LOG_INFO ("Creating the gateway..."); |
| 114 NodeContainer gateways; |
| 115 gateways.Create (1); |
| 116 |
| 117 mobility.SetPositionAllocator (allocator); |
| 118 mobility.Install (gateways); |
| 119 |
| 120 // Create a netdevice for each gateway |
| 121 phyHelper.SetDeviceType (LoraPhyHelper::GW); |
| 122 macHelper.SetDeviceType (LoraMacHelper::GW); |
| 123 helper.Install (phyHelper, macHelper, gateways); |
| 124 |
| 125 /********************************************* |
| 126 * Install applications on the end devices * |
| 127 *********************************************/ |
| 128 |
| 129 OneShotSenderHelper oneShotSenderHelper; |
| 130 oneShotSenderHelper.SetSendTime (Seconds (10)); |
| 131 |
| 132 oneShotSenderHelper.Install (endDevices); |
| 133 |
| 134 /**************** |
| 135 * Simulation * |
| 136 ****************/ |
| 137 |
| 138 Simulator::Stop (Hours (2)); |
| 139 |
| 140 Simulator::Run (); |
| 141 |
| 142 Simulator::Destroy (); |
| 143 |
| 144 return 0; |
| 145 } |
OLD | NEW |