int main (int argc, char *argv[]) { CommandLine cmd; cmd.Parse (argc, argv); NodeContainer c; c.Create (10000); MobilityHelper mobility; mobility.SetPositionAllocator ("ns3::RandomDiscPositionAllocator", "X", StringValue ("100.0"), "Y", StringValue ("100.0"), "Rho", StringValue ("ns3::UniformRandomVariable[Min=0|Max=30]")); mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (c); Config::Connect ("/NodeList/*/$ns3::MobilityModel/CourseChange", MakeCallback (&CourseChange)); Simulator::Stop (Seconds (100.0)); Simulator::Run (); Simulator::Destroy (); return 0; }
void FlameRegressionTest::CreateNodes () { m_nodes = new NodeContainer; m_nodes->Create (3); MobilityHelper mobility; mobility.SetPositionAllocator ("ns3::GridPositionAllocator", "MinX", DoubleValue (0.0), "MinY", DoubleValue (0.0), "DeltaX", DoubleValue (150), "DeltaY", DoubleValue (0), "GridWidth", UintegerValue (3), "LayoutType", StringValue ("RowFirst")); mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (*m_nodes); }
void HwmpReactiveRegressionTest::CreateNodes () { m_nodes = new NodeContainer; m_nodes->Create (6); MobilityHelper mobility; Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>(); positionAlloc->Add (Vector ( 0, 0, 0)); positionAlloc->Add (Vector ( 0, 150, 0)); positionAlloc->Add (Vector ( 0, 300, 0)); positionAlloc->Add (Vector ( 0, 450, 0)); positionAlloc->Add (Vector ( 0, 600, 0)); positionAlloc->Add (Vector ( 0, 750, 0)); mobility.SetPositionAllocator (positionAlloc); mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (*m_nodes); Simulator::Schedule (Seconds (5.0), &HwmpReactiveRegressionTest::ResetPosition, this); }
void MobilityTraceTestCase::DoRun (void) { //*************************************************************************** // Create the new mobility trace. //*************************************************************************** NodeContainer sta; sta.Create (4); MobilityHelper mobility; mobility.SetPositionAllocator ("ns3::GridPositionAllocator", "MinX", DoubleValue (1.0), "MinY", DoubleValue (1.0), "DeltaX", DoubleValue (5.0), "DeltaY", DoubleValue (5.0), "GridWidth", UintegerValue (3), "LayoutType", StringValue ("RowFirst")); mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel", "Mode", StringValue ("Time"), "Time", StringValue ("2s"), "Speed", StringValue ("ns3::ConstantRandomVariable[Constant=1.0]"), "Bounds", RectangleValue (Rectangle (0.0, 20.0, 0.0, 20.0))); mobility.Install (sta); // Set mobility random number streams to fixed values mobility.AssignStreams (sta, 0); SetDataDir (NS_TEST_SOURCEDIR); std::string referenceMobilityFilePath = CreateDataDirFilename ("mobility-trace-example.mob"); std::string testMobilityFilePath = CreateTempDirFilename ("mobility-trace-test.mob"); AsciiTraceHelper ascii; MobilityHelper::EnableAsciiAll (ascii.CreateFileStream (testMobilityFilePath)); Simulator::Stop (Seconds (5.0)); Simulator::Run (); Simulator::Destroy (); //*************************************************************************** // Test the new mobility trace against the reference mobility trace. //*************************************************************************** NS_ASCII_TEST_EXPECT_EQ (testMobilityFilePath, referenceMobilityFilePath); }
void AodvExample::CreateNodes () { std::cout << "Creating " << (unsigned)size << " nodes " << step << " m apart.\n"; nodes.Create (size); // Name nodes for (uint32_t i = 0; i < size; ++i) { std::ostringstream os; os << "node-" << i; Names::Add (os.str (), nodes.Get (i)); } // Create static grid MobilityHelper mobility; mobility.SetPositionAllocator ("ns3::GridPositionAllocator", "MinX", DoubleValue (0.0), "MinY", DoubleValue (0.0), "DeltaX", DoubleValue (step), "DeltaY", DoubleValue (0), "GridWidth", UintegerValue (size), "LayoutType", StringValue ("RowFirst")); mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (nodes); }
int main (int argc, char *argv[]) { #ifdef NS3_CLICK // // Enable logging // LogComponentEnable ("NsclickUdpClientServerWifi", LOG_LEVEL_INFO); // // Explicitly create the nodes required by the topology (shown above). // NS_LOG_INFO ("Create nodes."); NodeContainer n; n.Create (4); NS_LOG_INFO ("Create channels."); // // Explicitly create the channels required by the topology (shown above). // std::string phyMode ("DsssRate1Mbps"); // disable fragmentation for frames below 2200 bytes Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200")); // turn off RTS/CTS for frames below 2200 bytes Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200")); // Fix non-unicast data rate to be the same as that of unicast Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue (phyMode)); WifiHelper wifi; wifi.SetStandard (WIFI_PHY_STANDARD_80211b); YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); // This is one parameter that matters when using FixedRssLossModel // set it to zero; otherwise, gain will be added wifiPhy.Set ("RxGain", DoubleValue (0) ); // ns-3 supports RadioTap and Prism tracing extensions for 802.11b wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO); YansWifiChannelHelper wifiChannel; wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel"); // The below FixedRssLossModel will cause the rss to be fixed regardless // of the distance between the two stations, and the transmit power wifiChannel.AddPropagationLoss ("ns3::FixedRssLossModel","Rss",DoubleValue (-80)); wifiPhy.SetChannel (wifiChannel.Create ()); // Add a non-QoS upper mac, and disable rate control NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode",StringValue (phyMode), "ControlMode",StringValue (phyMode)); // Set it to adhoc mode wifiMac.SetType ("ns3::AdhocWifiMac"); NetDeviceContainer d = wifi.Install (wifiPhy, wifiMac, n); MobilityHelper mobility; Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> (); positionAlloc->Add (Vector (0.0, 0.0, 0.0)); positionAlloc->Add (Vector (10.0, 0.0, 0.0)); positionAlloc->Add (Vector (20.0, 0.0, 0.0)); positionAlloc->Add (Vector (0.0, 10.0, 0.0)); mobility.SetPositionAllocator (positionAlloc); mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (n); // // Install Click on the nodes // ClickInternetStackHelper clickinternet; clickinternet.SetClickFile (n.Get (0), "src/click/examples/nsclick-wifi-single-interface.click"); clickinternet.SetClickFile (n.Get (1), "src/click/examples/nsclick-wifi-single-interface.click"); clickinternet.SetClickFile (n.Get (2), "src/click/examples/nsclick-wifi-single-interface.click"); // Node 4 is to run in promiscuous mode. This can be verified // from the pcap trace Node4_in_eth0.pcap generated after running // this script. clickinternet.SetClickFile (n.Get (3), "src/click/examples/nsclick-wifi-single-interface-promisc.click"); clickinternet.SetRoutingTableElement (n, "rt"); clickinternet.Install (n); Ipv4AddressHelper ipv4; // // We've got the "hardware" in place. Now we need to add IP addresses. // NS_LOG_INFO ("Assign IP Addresses."); ipv4.SetBase ("172.16.1.0", "255.255.255.0"); Ipv4InterfaceContainer i = ipv4.Assign (d); NS_LOG_INFO ("Create Applications."); // // Create one udpServer applications on node one. // uint16_t port = 4000; UdpServerHelper server (port); ApplicationContainer apps = server.Install (n.Get (1)); apps.Start (Seconds (1.0)); apps.Stop (Seconds (10.0)); // // Create one UdpClient application to send UDP datagrams from node zero to // node one. // uint32_t MaxPacketSize = 1024; Time interPacketInterval = Seconds (0.5); uint32_t maxPacketCount = 320; UdpClientHelper client (i.GetAddress (1), port); client.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount)); client.SetAttribute ("Interval", TimeValue (interPacketInterval)); client.SetAttribute ("PacketSize", UintegerValue (MaxPacketSize)); apps = client.Install (NodeContainer (n.Get (0), n.Get (2))); apps.Start (Seconds (2.0)); apps.Stop (Seconds (10.0)); wifiPhy.EnablePcap ("nsclick-udp-client-server-wifi", d); // Force the MAC address of the second node: The current ARP // implementation of Click sends only one ARP request per incoming // packet for an unknown destination and does not retransmit if no // response is received. With the scenario of this example, all ARP // requests of node 3 are lost due to interference from node // 1. Hence, we fill in the ARP table of node 2 before at the // beginning of the simulation Simulator::Schedule (Seconds (0.5), &ReadArp, n.Get (2)->GetObject<Ipv4ClickRouting> ()); Simulator::Schedule (Seconds (0.6), &WriteArp, n.Get (2)->GetObject<Ipv4ClickRouting> ()); Simulator::Schedule (Seconds (0.7), &ReadArp, n.Get (2)->GetObject<Ipv4ClickRouting> ()); // // Now, do the actual simulation. // NS_LOG_INFO ("Run Simulation."); Simulator::Stop (Seconds (20.0)); Simulator::Run (); Simulator::Destroy (); NS_LOG_INFO ("Done."); #else NS_FATAL_ERROR ("Can't use ns-3-click without NSCLICK compiled in"); #endif }
int main (int argc, char *argv[]) { std::string phyMode ("DsssRate1Mbps"); double rss = -80; // -dBm uint32_t packetSize = 1000; // bytes uint32_t numPackets = 1; double interval = 1.0; // seconds bool verbose = false; CommandLine cmd; cmd.AddValue ("phyMode", "Wifi Phy mode", phyMode); cmd.AddValue ("rss", "received signal strength", rss); cmd.AddValue ("packetSize", "size of application packet sent", packetSize); cmd.AddValue ("numPackets", "number of packets generated", numPackets); cmd.AddValue ("interval", "interval (seconds) between packets", interval); cmd.AddValue ("verbose", "turn on all WifiNetDevice log components", verbose); cmd.Parse (argc, argv); // Convert to time object Time interPacketInterval = Seconds (interval); // disable fragmentation for frames below 2200 bytes Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200")); // turn off RTS/CTS for frames below 2200 bytes Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200")); // Fix non-unicast data rate to be the same as that of unicast Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue (phyMode)); NodeContainer c; c.Create (2); // The below set of helpers will help us to put together the wifi NICs we want WifiHelper wifi; if (verbose) { wifi.EnableLogComponents (); // Turn on all Wifi logging } wifi.SetStandard (WIFI_PHY_STANDARD_80211b); YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); // This is one parameter that matters when using FixedRssLossModel // set it to zero; otherwise, gain will be added wifiPhy.Set ("RxGain", DoubleValue (0) ); // ns-3 supports RadioTap and Prism tracing extensions for 802.11b wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO); YansWifiChannelHelper wifiChannel; wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel"); // The below FixedRssLossModel will cause the rss to be fixed regardless // of the distance between the two stations, and the transmit power wifiChannel.AddPropagationLoss ("ns3::FixedRssLossModel","Rss",DoubleValue (rss)); wifiPhy.SetChannel (wifiChannel.Create ()); // Add a non-QoS upper mac, and disable rate control NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode",StringValue (phyMode), "ControlMode",StringValue (phyMode)); // Set it to adhoc mode wifiMac.SetType ("ns3::AdhocWifiMac"); NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c); // Note that with FixedRssLossModel, the positions below are not // used for received signal strength. MobilityHelper mobility; Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> (); positionAlloc->Add (Vector (0.0, 0.0, 0.0)); positionAlloc->Add (Vector (5.0, 0.0, 0.0)); mobility.SetPositionAllocator (positionAlloc); mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (c); InternetStackHelper internet; internet.Install (c); Ipv4AddressHelper ipv4; NS_LOG_INFO ("Assign IP Addresses."); ipv4.SetBase ("10.1.1.0", "255.255.255.0"); Ipv4InterfaceContainer i = ipv4.Assign (devices); TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory"); Ptr<Socket> recvSink = Socket::CreateSocket (c.Get (0), tid); InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80); recvSink->Bind (local); recvSink->SetRecvCallback (MakeCallback (&ReceivePacket)); Ptr<Socket> source = Socket::CreateSocket (c.Get (1), tid); InetSocketAddress remote = InetSocketAddress (Ipv4Address ("255.255.255.255"), 80); source->SetAllowBroadcast (true); source->Connect (remote); // Tracing wifiPhy.EnablePcap ("wifi-simple-adhoc", devices); // Output what we are doing NS_LOG_UNCOND ("Testing " << numPackets << " packets sent with receiver rss " << rss ); Simulator::ScheduleWithContext (source->GetNode ()->GetId (), Seconds (1.0), &GenerateTraffic, source, packetSize, numPackets, interPacketInterval); Simulator::Run (); Simulator::Destroy (); return 0; }
int main (int argc, char *argv[]) { CommandLine cmd; cmd.Parse (argc, argv); // to save a template default attribute file run it like this: // ./waf --command-template="%s --ns3::ConfigStore::Filename=input-defaults.txt --ns3::ConfigStore::Mode=Save --ns3::ConfigStore::FileFormat=RawText" --run src/lte/examples/lena-first-sim // // to load a previously created default attribute file // ./waf --command-template="%s --ns3::ConfigStore::Filename=input-defaults.txt --ns3::ConfigStore::Mode=Load --ns3::ConfigStore::FileFormat=RawText" --run src/lte/examples/lena-first-sim ConfigStore inputConfig; inputConfig.ConfigureDefaults (); // parse again so you can override default values from the command line cmd.Parse (argc, argv); Ptr<LteHelper> lteHelper = CreateObject<LteHelper> (); lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::FriisSpectrumPropagationLossModel")); // Uncomment to enable logging //lteHelper->EnableLogComponents (); // Create Nodes: eNodeB and UE NodeContainer enbNodes; NodeContainer ueNodes; enbNodes.Create (1); ueNodes.Create (1); // Install Mobility Model MobilityHelper mobility; mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (enbNodes); BuildingsHelper::Install (enbNodes); mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (ueNodes); BuildingsHelper::Install (ueNodes); // Create Devices and install them in the Nodes (eNB and UE) NetDeviceContainer enbDevs; NetDeviceContainer ueDevs; // lteHelper->SetSchedulerType ("ns3::RrFfMacScheduler"); lteHelper->SetSchedulerType ("ns3::PfFfMacScheduler"); lteHelper->SetSchedulerAttribute ("CqiTimerThreshold", UintegerValue (3)); enbDevs = lteHelper->InstallEnbDevice (enbNodes); ueDevs = lteHelper->InstallUeDevice (ueNodes); lteHelper->EnableRlcTraces(); lteHelper->EnableMacTraces(); // Attach a UE to a eNB lteHelper->Attach (ueDevs, enbDevs.Get (0)); Simulator::Schedule (Seconds (0.010), &ChangePosition, ueNodes.Get (0)); Simulator::Schedule (Seconds (0.020), &ChangePosition, ueNodes.Get (0)); // Activate a data radio bearer enum EpsBearer::Qci q = EpsBearer::GBR_CONV_VOICE; EpsBearer bearer (q); lteHelper->ActivateDataRadioBearer (ueDevs, bearer); Simulator::Stop (Seconds (0.030)); Simulator::Run (); //GtkConfigStore config; //config.ConfigureAttributes (); Simulator::Destroy (); return 0; }
int main (int argc, char *argv[]) { CommandLine cmd; cmd.Parse (argc, argv); // to save a template default attribute file run it like this: // ./waf --command-template="%s --ns3::ConfigStore::Filename=input-defaults.txt --ns3::ConfigStore::Mode=Save --ns3::ConfigStore::FileFormat=RawText" --run src/lte/examples/lena-first-sim // // to load a previously created default attribute file // ./waf --command-template="%s --ns3::ConfigStore::Filename=input-defaults.txt --ns3::ConfigStore::Mode=Load --ns3::ConfigStore::FileFormat=RawText" --run src/lte/examples/lena-first-sim ConfigStore inputConfig; inputConfig.ConfigureDefaults (); // Parse again so you can override default values from the command line cmd.Parse (argc, argv); Ptr<LteHelper> lteHelper = CreateObject<LteHelper> (); // Uncomment to enable logging //lteHelper->EnableLogComponents (); // Create Nodes: eNodeB and UE NodeContainer enbNodes; NodeContainer ueNodes; enbNodes.Create (1); ueNodes.Create (1); // Install Mobility Model MobilityHelper mobility; mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (enbNodes); BuildingsHelper::Install (enbNodes); mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (ueNodes); BuildingsHelper::Install (ueNodes); // Create Devices and install them in the Nodes (eNB and UE) NetDeviceContainer enbDevs; NetDeviceContainer ueDevs; // Default scheduler is PF, uncomment to use RR //lteHelper->SetSchedulerType ("ns3::RrFfMacScheduler"); enbDevs = lteHelper->InstallEnbDevice (enbNodes); ueDevs = lteHelper->InstallUeDevice (ueNodes); // Attach a UE to a eNB lteHelper->Attach (ueDevs, enbDevs.Get (0)); // Activate an EPS bearer enum EpsBearer::Qci q = EpsBearer::GBR_CONV_VOICE; EpsBearer bearer (q); lteHelper->ActivateDataRadioBearer (ueDevs, bearer); // Configure Radio Environment Map (REM) output // for LTE-only simulations always use /ChannelList/0 which is the downlink channel Ptr<RadioEnvironmentMapHelper> remHelper = CreateObject<RadioEnvironmentMapHelper> (); remHelper->SetAttribute ("ChannelPath", StringValue ("/ChannelList/0")); remHelper->SetAttribute ("OutputFile", StringValue ("rem.out")); remHelper->SetAttribute ("XMin", DoubleValue (-400.0)); remHelper->SetAttribute ("XMax", DoubleValue (400.0)); remHelper->SetAttribute ("YMin", DoubleValue (-300.0)); remHelper->SetAttribute ("YMax", DoubleValue (300.0)); remHelper->SetAttribute ("Z", DoubleValue (0.0)); remHelper->Install (); // here's a minimal gnuplot script that will plot the above: // // set view map; // set term x11; // set xlabel "X" // set ylabel "Y" // set cblabel "SINR (dB)" // plot "rem.out" using ($1):($2):(10*log10($4)) with image BuildingsHelper::MakeMobilityModelConsistent (); Simulator::Run (); //GtkConfigStore config; //config.ConfigureAttributes (); Simulator::Destroy (); return 0; }
int main(int argc, char* argv[]) { // setting default parameters for Wifi // enable rts cts all the time. Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("0")); // disable fragmentation Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200")); Config::SetDefault("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue("OfdmRate24Mbps")); // setting default parameters for PointToPoint links and channels Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps")); Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms")); Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("20")); std::uint32_t max_routers = 1; std::string cSize = "100"; std::string cSplit = "75"; // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize CommandLine cmd; cmd.AddValue("cSize", "Cache Size", cSize); cmd.AddValue("cSplit", "Cache Split", cSplit); cmd.AddValue("routers", "number of routers", max_routers); cmd.Parse(argc, argv); Packet::EnablePrinting (); // Wifi config WifiHelper wifi = WifiHelper::Default (); // Nodes NodeContainer sta_consumers; NodeContainer sta_mobile_consumers; NodeContainer ap; NodeContainer routers; NodeContainer producers; // ?? NetDeviceContainer staDevs; PacketSocketHelper packetSocket; // 5 stationary consumers, 5 mobile, 4 APs and 1 router sta_consumers.Create(3*max_routers); sta_mobile_consumers.Create(7*max_routers); ap.Create (5*max_routers); routers.Create(max_routers); producers.Create(1); // give packet socket powers to nodes. packetSocket.Install(sta_mobile_consumers); packetSocket.Install(sta_consumers); packetSocket.Install (ap); // Wifi Config NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default (); wifiPhy.SetChannel (wifiChannel.Create ()); wifiPhy.Set("TxPowerStart", DoubleValue(5)); wifiPhy.Set("TxPowerEnd", DoubleValue(5)); Ssid ssid = Ssid ("wifi-default"); wifi.SetRemoteStationManager ("ns3::ArfWifiManager"); // setup stas. wifiMac.SetType ("ns3::StaWifiMac", "Ssid", SsidValue (ssid), "ActiveProbing", BooleanValue (false)); // install wifi wifi.Install(wifiPhy, wifiMac, sta_mobile_consumers); wifi.Install(wifiPhy, wifiMac, sta_consumers); // setup ap. wifiMac.SetType ("ns3::ApWifiMac", "Ssid", SsidValue (ssid)); wifi.Install (wifiPhy, wifiMac, ap); // Mobility config -- Change max_routers value to change size of sim int number_rows = sqrt(max_routers); int x = 0; int y = 0; int pos_counter = 0; Ptr<UniformRandomVariable> randomizerX = CreateObject<UniformRandomVariable>(); Ptr<UniformRandomVariable> randomizerY = CreateObject<UniformRandomVariable>(); MobilityHelper stationary_mobility; stationary_mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel"); MobilityHelper mobility; mobility.SetMobilityModel("ns3::GaussMarkovMobilityModel", "Bounds", BoxValue(Box (0, number_rows*10, 0, number_rows*10, 0, 0)), "TimeStep", TimeValue(Seconds(1))); // Place router in center of box randomizerX->SetAttribute("Min", DoubleValue(5)); randomizerX->SetAttribute("Max", DoubleValue(5)); randomizerY->SetAttribute("Min", DoubleValue(5)); randomizerY->SetAttribute("Max", DoubleValue(5)); stationary_mobility.SetPositionAllocator("ns3::RandomBoxPositionAllocator", "X", PointerValue(randomizerX), "Y", PointerValue(randomizerY)); // Install on routers stationary_mobility.Install(producers.Get(0)); // p2p helper PointToPointHelper p2p; // for each row for (int i=0; i < number_rows; i++) { x = i * 10 + 5; // for each column for (int j=0; j < number_rows; j++) { y = j * 10 + 5; // Place router in center of box randomizerX->SetAttribute("Min", DoubleValue(x)); randomizerX->SetAttribute("Max", DoubleValue(x)); randomizerY->SetAttribute("Min", DoubleValue(y)); randomizerY->SetAttribute("Max", DoubleValue(y)); stationary_mobility.SetPositionAllocator("ns3::RandomBoxPositionAllocator", "X", PointerValue(randomizerX), "Y", PointerValue(randomizerY)); // Install on routers stationary_mobility.Install(routers.Get(pos_counter)); // Set box (center +/-5) randomizerX->SetAttribute("Min", DoubleValue(x-5)); randomizerX->SetAttribute("Max", DoubleValue(x+5)); randomizerY->SetAttribute("Min", DoubleValue(y-5)); randomizerY->SetAttribute("Max", DoubleValue(y+5)); // Connect router to previous if not 1 if (pos_counter == 0) { p2p.Install(routers.Get(0), producers.Get(0)); } else // Otherwise connect to router behind you { p2p.Install(routers.Get(pos_counter), routers.Get(pos_counter-1)); } // APs for (int k=0; k < 5; k++) { stationary_mobility.SetPositionAllocator("ns3::RandomBoxPositionAllocator", "X", PointerValue(randomizerX), "Y", PointerValue(randomizerY)); stationary_mobility.Install(ap.Get(pos_counter * 5 + k)); p2p.Install(routers.Get(pos_counter), ap.Get(pos_counter * 5 + k)); } // Consumers (stationary) for (int l=0; l < 3; l++) { stationary_mobility.SetPositionAllocator("ns3::RandomBoxPositionAllocator", "X", PointerValue(randomizerX), "Y", PointerValue(randomizerY)); stationary_mobility.Install(sta_consumers.Get(pos_counter * 3 + l)); } // Consumers (Mobile) for (int m=0; m < 7; m++) { mobility.SetPositionAllocator("ns3::RandomBoxPositionAllocator", "X", PointerValue(randomizerX), "Y", PointerValue(randomizerY)); mobility.Install(sta_mobile_consumers.Get(pos_counter * 7 + m)); } // Keep track of overall position pos_counter++; } } // Install NDN stack on all nodes ndn::StackHelper ndnHelper; ndnHelper.SetDefaultRoutes(true); ndnHelper.SetOldContentStore("ns3::ndn::cs::Splitcache", "NormalPolicy", "ns3::ndn::cs::Lru", "SpecialPolicy", "ns3::ndn::cs::Lfu", "TotalCacheSize", cSize, "Configure", cSplit); // Percentage Special^ //ndnHelper.SetOldContentStore("ns3::ndn::cs::Lru"); ndnHelper.Install(ap); ndnHelper.Install(routers); ndnHelper.SetOldContentStore("ns3::ndn::cs::Nocache"); ndnHelper.Install(sta_consumers); ndnHelper.Install(sta_mobile_consumers); ndnHelper.Install(producers); // Choosing forwarding strategy ndn::StrategyChoiceHelper::Install(sta_consumers, "/", "/localhost/nfd/strategy/best-route"); ndn::StrategyChoiceHelper::Install(sta_mobile_consumers, "/", "/localhost/nfd/strategy/best-route"); ndn::StrategyChoiceHelper::Install(ap, "/", "/localhost/nfd/strategy/best-route"); ndn::StrategyChoiceHelper::Install(routers, "/", "/localhost/nfd/strategy/best-route"); ndn::StrategyChoiceHelper::Install(producers, "/", "/localhost/nfd/strategy/best-route"); // Installing applications // Consumer (basic and special data) ndn::AppHelper consumerHelper("ns3::ndn::ConsumerZipfMandelbrot"); consumerHelper.SetAttribute("NumberOfContents", StringValue("100")); // 10 different contents // Consumer will request /prefix/0, /prefix/1, ... // Basic consumers request basic data (and pumpkin spice coffee) consumerHelper.SetPrefix("data/basic"); consumerHelper.SetAttribute("Frequency", StringValue("10")); // 1 interests a second consumerHelper.Install(sta_consumers); // Mobile consumers request special data only consumerHelper.SetPrefix("data/special"); consumerHelper.SetAttribute("Frequency", StringValue("10")); // 2 interests a second consumerHelper.Install(sta_mobile_consumers); // Producer ndn::AppHelper producerHelper("ns3::ndn::Producer"); // Producer will reply to all requests starting with /prefix producerHelper.SetPrefix("/data"); producerHelper.SetAttribute("PayloadSize", StringValue("1024")); producerHelper.SetAttribute("Freshness", TimeValue(Seconds(-1.0))); // unlimited freshness producerHelper.Install(producers); // Tracers 'n stuff //AthstatsHelper athstats; //athstats.EnableAthstats("athstats-sta", sta_mobile_consumers); //athstats.EnableAthstats("athstats-sta", sta_consumers); //athstats.EnableAthstats ("athstats-ap", ap); ndn::AppDelayTracer::Install(sta_consumers, "app-delays-trace-stationary-03.txt"); ndn::AppDelayTracer::Install(sta_mobile_consumers, "app-delays-trace-mobile-03.txt"); ndn::CsTracer::Install(ap, "cs-trace-ap-03.txt", Seconds(1)); ndn::CsTracer::Install(routers, "cs-trace-routers-03.txt", Seconds(1)); // 10 min Simulator::Stop(Seconds(600.0)); Simulator::Run(); Simulator::Destroy(); return 0; }
void LenaMimoTestCase::DoRun (void) { NS_LOG_FUNCTION (this << GetName ()); Config::SetDefault ("ns3::LteSpectrumPhy::DataErrorModelEnabled", BooleanValue (false)); Config::SetDefault ("ns3::LteAmc::AmcModel", EnumValue (LteAmc::PiroEW2010)); Config::SetDefault ("ns3::LteHelper::UseIdealRrc", BooleanValue (m_useIdealRrc)); /** * Initialize Simulation Scenario: 1 eNB and m_nUser UEs */ Ptr<LteHelper> lteHelper = CreateObject<LteHelper> (); Config::SetDefault ("ns3::RrFfMacScheduler::HarqEnabled", BooleanValue (false)); Config::SetDefault ("ns3::PfFfMacScheduler::HarqEnabled", BooleanValue (false)); // lteHelper->SetSchedulerAttribute ("HarqEnabled", BooleanValue (false)); lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::HybridBuildingsPropagationLossModel")); lteHelper->SetPathlossModelAttribute ("ShadowSigmaOutdoor", DoubleValue (0.0)); lteHelper->SetPathlossModelAttribute ("ShadowSigmaIndoor", DoubleValue (0.0)); lteHelper->SetPathlossModelAttribute ("ShadowSigmaExtWalls", DoubleValue (0.0)); // lteHelper->EnableLogComponents (); // Create Nodes: eNodeB and UE NodeContainer enbNodes; NodeContainer ueNodes; enbNodes.Create (1); ueNodes.Create (1); // Install Mobility Model MobilityHelper mobility; mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (enbNodes); BuildingsHelper::Install (enbNodes); mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (ueNodes); BuildingsHelper::Install (ueNodes); // Create Devices and install them in the Nodes (eNB and UE) NetDeviceContainer enbDevs; NetDeviceContainer ueDevs; lteHelper->SetSchedulerType (m_schedulerType); enbDevs = lteHelper->InstallEnbDevice (enbNodes); ueDevs = lteHelper->InstallUeDevice (ueNodes); // Attach a UE to a eNB lteHelper->Attach (ueDevs, enbDevs.Get (0)); // Activate an EPS bearer enum EpsBearer::Qci q = EpsBearer::GBR_CONV_VOICE; EpsBearer bearer (q); lteHelper->ActivateDataRadioBearer (ueDevs, bearer); Ptr<LteEnbNetDevice> lteEnbDev = enbDevs.Get (0)->GetObject<LteEnbNetDevice> (); Ptr<LteEnbPhy> enbPhy = lteEnbDev->GetPhy (); enbPhy->SetAttribute ("TxPower", DoubleValue (46.0)); enbPhy->SetAttribute ("NoiseFigure", DoubleValue (5.0)); Ptr<MobilityModel> mmenb = enbNodes.Get (0)->GetObject<MobilityModel> (); mmenb->SetPosition (Vector (0.0, 0.0, 30.0)); // Set UE's position and power Ptr<MobilityModel> mmue = ueNodes.Get (0)->GetObject<MobilityModel> (); mmue->SetPosition (Vector (m_dist, 0.0, 1.0)); Ptr<LteUeNetDevice> lteUeDev = ueDevs.Get (0)->GetObject<LteUeNetDevice> (); Ptr<LteUePhy> uePhy = lteUeDev->GetPhy (); uePhy->SetAttribute ("TxPower", DoubleValue (23.0)); uePhy->SetAttribute ("NoiseFigure", DoubleValue (9.0)); // need to allow for RRC connection establishment + SRS before enabling traces lteHelper->EnableRlcTraces (); lteHelper->EnableMacTraces (); double simulationTime = 0.6; double tolerance = 0.1; uint8_t rnti = 1; Ptr<LteEnbNetDevice> enbNetDev = enbDevs.Get (0)->GetObject<LteEnbNetDevice> (); PointerValue ptrval; enbNetDev->GetAttribute ("FfMacScheduler", ptrval); Ptr<PfFfMacScheduler> pfsched; Ptr<RrFfMacScheduler> rrsched; if (m_schedulerType.compare ("ns3::RrFfMacScheduler") == 0) { rrsched = ptrval.Get<RrFfMacScheduler> (); if (rrsched == 0) { NS_FATAL_ERROR ("No RR Scheduler available"); } Simulator::Schedule (Seconds (0.2), &RrFfMacScheduler::TransmissionModeConfigurationUpdate, rrsched, rnti, 1); Simulator::Schedule (Seconds (0.4), &RrFfMacScheduler::TransmissionModeConfigurationUpdate, rrsched, rnti, 2); } else if (m_schedulerType.compare ("ns3::PfFfMacScheduler") == 0) { pfsched = ptrval.Get<PfFfMacScheduler> (); if (pfsched == 0) { NS_FATAL_ERROR ("No Pf Scheduler available"); } Simulator::Schedule (Seconds (0.2), &PfFfMacScheduler::TransmissionModeConfigurationUpdate, pfsched, rnti, 1); Simulator::Schedule (Seconds (0.4), &PfFfMacScheduler::TransmissionModeConfigurationUpdate, pfsched, rnti, 2); } else { NS_FATAL_ERROR ("Scheduler not supported by this test"); } Ptr<RadioBearerStatsCalculator> rlcStats = lteHelper->GetRlcStats (); rlcStats->SetAttribute ("EpochDuration", TimeValue (Seconds (0.1))); NS_LOG_INFO (m_schedulerType << " MIMO test:"); double sampleTime = 0.199999; // at 0.2 RlcStats are reset for (uint8_t j = 0; j < m_estThrDl.size (); j ++) { NS_LOG_INFO ("\t test with user at distance " << m_dist << " time " << sampleTime); // get the imsi uint64_t imsi = ueDevs.Get (0)->GetObject<LteUeNetDevice> ()->GetImsi (); uint8_t lcId = 3; Time t = Seconds (sampleTime); Simulator::Schedule(t, &LenaMimoTestCase::GetRlcBufferSample, this, rlcStats, imsi, lcId); sampleTime += 0.2; } Simulator::Stop (Seconds (simulationTime)); Simulator::Run (); Simulator::Destroy (); NS_LOG_INFO ("Check consistency"); for (uint8_t i = 0; i < m_estThrDl.size (); i++) { NS_LOG_INFO ("interval " << i + 1 << ": bytes rxed " << (double)m_dlDataRxed.at (i) << " ref " << m_estThrDl.at (i)); NS_TEST_ASSERT_MSG_EQ_TOL ((double)m_dlDataRxed.at (i) , m_estThrDl.at (i), m_estThrDl.at (i) * tolerance, " Unfair Throughput!"); } }
LteFadingTestSuite::LteFadingTestSuite () : TestSuite ("lte-fading-model", SYSTEM) { // -------------- COMPOUND TESTS ---------------------------------- LogComponentEnable ("LteFadingTest", LOG_LEVEL_ALL); // NS_LOG_INFO ("Creating LteDownlinkSinrTestSuite"); Ptr<LteHelper> lteHelper = CreateObject<LteHelper> (); lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::BuildingsPropagationLossModel")); // Create Nodes: eNodeB, home eNB, UE and home UE (UE attached to HeNB) NodeContainer enbNodes; NodeContainer henbNodes; NodeContainer ueNodes; NodeContainer hueNodes; enbNodes.Create (1); henbNodes.Create (2); ueNodes.Create (5); hueNodes.Create (3); // Install Mobility Model MobilityHelper mobility; mobility.SetMobilityModel ("ns3::BuildingsMobilityModel"); mobility.Install (enbNodes); mobility.Install (henbNodes); mobility.Install (ueNodes); mobility.Install (hueNodes); NetDeviceContainer enbDevs; NetDeviceContainer henbDevs; NetDeviceContainer ueDevs; NetDeviceContainer hueDevs; enbDevs = lteHelper->InstallEnbDevice (enbNodes); ueDevs = lteHelper->InstallUeDevice (ueNodes); henbDevs = lteHelper->InstallEnbDevice (henbNodes); hueDevs = lteHelper->InstallUeDevice (hueNodes); lteHelper->Attach (ueDevs, enbDevs.Get (0)); lteHelper->Attach (hueDevs, henbDevs.Get (0)); // Test #1 Okumura Hata Model (150 < freq < 1500 MHz) (Macro<->UE) double distance = 2000; double hm = 1; double hb = 30; // double freq = 869e6; // E_UTRA BAND #5 see table 5.5-1 of 36.101 Ptr<BuildingsMobilityModel> mm1 = enbNodes.Get (0)->GetObject<BuildingsMobilityModel> (); mm1->SetPosition (Vector (0.0, 0.0, hb)); Ptr<BuildingsMobilityModel> mm2 = ueNodes.Get (0)->GetObject<BuildingsMobilityModel> (); mm2->SetPosition (Vector (distance, 0.0, hm)); AddTestCase (new LteFadingTestCase (mm1, mm2, 137.93, "OH Urban Large city"), TestCase::QUICK); }
int main (int argc, char *argv[]) { std::string phyMode ("DsssRate1Mbps"); double distance = 500; // m uint32_t packetSize = 1000; // bytes uint32_t numPackets = 1; uint32_t numNodes = 25; // by default, 5x5 uint32_t sinkNode = 0; uint32_t sourceNode = 24; double interval = 1.0; // seconds bool verbose = false; bool tracing = false; CommandLine cmd; cmd.AddValue ("phyMode", "Wifi Phy mode", phyMode); cmd.AddValue ("distance", "distance (m)", distance); cmd.AddValue ("packetSize", "size of application packet sent", packetSize); cmd.AddValue ("numPackets", "number of packets generated", numPackets); cmd.AddValue ("interval", "interval (seconds) between packets", interval); cmd.AddValue ("verbose", "turn on all WifiNetDevice log components", verbose); cmd.AddValue ("tracing", "turn on ascii and pcap tracing", tracing); cmd.AddValue ("numNodes", "number of nodes", numNodes); cmd.AddValue ("sinkNode", "Receiver node number", sinkNode); cmd.AddValue ("sourceNode", "Sender node number", sourceNode); cmd.Parse (argc, argv); // Convert to time object Time interPacketInterval = Seconds (interval); // disable fragmentation for frames below 2200 bytes Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200")); // turn off RTS/CTS for frames below 2200 bytes Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200")); // Fix non-unicast data rate to be the same as that of unicast Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue (phyMode)); NodeContainer c; c.Create (numNodes); // The below set of helpers will help us to put together the wifi NICs we want WifiHelper wifi; if (verbose) { wifi.EnableLogComponents (); // Turn on all Wifi logging } YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); // set it to zero; otherwise, gain will be added wifiPhy.Set ("RxGain", DoubleValue (-10) ); // ns-3 supports RadioTap and Prism tracing extensions for 802.11b wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO); YansWifiChannelHelper wifiChannel; wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel"); wifiChannel.AddPropagationLoss ("ns3::FriisPropagationLossModel"); wifiPhy.SetChannel (wifiChannel.Create ()); // Add a non-QoS upper mac, and disable rate control NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); wifi.SetStandard (WIFI_PHY_STANDARD_80211b); wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode",StringValue (phyMode), "ControlMode",StringValue (phyMode)); // Set it to adhoc mode wifiMac.SetType ("ns3::AdhocWifiMac"); NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c); MobilityHelper mobility; mobility.SetPositionAllocator ("ns3::GridPositionAllocator", "MinX", DoubleValue (0.0), "MinY", DoubleValue (0.0), "DeltaX", DoubleValue (distance), "DeltaY", DoubleValue (distance), "GridWidth", UintegerValue (5), "LayoutType", StringValue ("RowFirst")); mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (c); // Enable OLSR OlsrHelper olsr; Ipv4StaticRoutingHelper staticRouting; Ipv4ListRoutingHelper list; list.Add (staticRouting, 0); list.Add (olsr, 10); InternetStackHelper internet; internet.SetRoutingHelper (list); // has effect on the next Install () internet.Install (c); Ipv4AddressHelper ipv4; NS_LOG_INFO ("Assign IP Addresses."); ipv4.SetBase ("10.1.1.0", "255.255.255.0"); Ipv4InterfaceContainer i = ipv4.Assign (devices); TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory"); Ptr<Socket> recvSink = Socket::CreateSocket (c.Get (sinkNode), tid); InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80); recvSink->Bind (local); recvSink->SetRecvCallback (MakeCallback (&ReceivePacket)); Ptr<Socket> source = Socket::CreateSocket (c.Get (sourceNode), tid); InetSocketAddress remote = InetSocketAddress (i.GetAddress (sinkNode, 0), 80); source->Connect (remote); if (tracing == true) { AsciiTraceHelper ascii; wifiPhy.EnableAsciiAll (ascii.CreateFileStream ("wifi-simple-adhoc-grid.tr")); wifiPhy.EnablePcap ("wifi-simple-adhoc-grid", devices); // Trace routing tables Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("wifi-simple-adhoc-grid.routes", std::ios::out); olsr.PrintRoutingTableAllEvery (Seconds (2), routingStream); // To do-- enable an IP-level trace that shows forwarding events only } // Give OLSR time to converge-- 30 seconds perhaps Simulator::Schedule (Seconds (30.0), &GenerateTraffic, source, packetSize, numPackets, interPacketInterval); // Output what we are doing NS_LOG_UNCOND ("Testing from node " << sourceNode << " to " << sinkNode << " with grid distance " << distance); Simulator::Stop (Seconds (32.0)); Simulator::Run (); Simulator::Destroy (); return 0; }
int main (int argc, char *argv[]) { uint32_t nWifis = 2; uint32_t nStas = 2; bool sendIp = true; bool writeMobility = false; CommandLine cmd; cmd.AddValue ("nWifis", "Number of wifi networks", nWifis); cmd.AddValue ("nStas", "Number of stations per wifi network", nStas); cmd.AddValue ("SendIp", "Send Ipv4 or raw packets", sendIp); cmd.AddValue ("writeMobility", "Write mobility trace", writeMobility); cmd.Parse (argc, argv); NodeContainer backboneNodes; NetDeviceContainer backboneDevices; Ipv4InterfaceContainer backboneInterfaces; std::vector<NodeContainer> staNodes; std::vector<NetDeviceContainer> staDevices; std::vector<NetDeviceContainer> apDevices; std::vector<Ipv4InterfaceContainer> staInterfaces; std::vector<Ipv4InterfaceContainer> apInterfaces; InternetStackHelper stack; CsmaHelper csma; Ipv4AddressHelper ip; ip.SetBase ("192.168.0.0", "255.255.255.0"); backboneNodes.Create (nWifis); stack.Install (backboneNodes); backboneDevices = csma.Install (backboneNodes); double wifiX = 0.0; YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO); for (uint32_t i = 0; i < nWifis; ++i) { // calculate ssid for wifi subnetwork std::ostringstream oss; oss << "wifi-default-" << i; Ssid ssid = Ssid (oss.str ()); NodeContainer sta; NetDeviceContainer staDev; NetDeviceContainer apDev; Ipv4InterfaceContainer staInterface; Ipv4InterfaceContainer apInterface; MobilityHelper mobility; BridgeHelper bridge; WifiHelper wifi = WifiHelper::Default (); NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default (); wifiPhy.SetChannel (wifiChannel.Create ()); sta.Create (nStas); mobility.SetPositionAllocator ("ns3::GridPositionAllocator", "MinX", DoubleValue (wifiX), "MinY", DoubleValue (0.0), "DeltaX", DoubleValue (5.0), "DeltaY", DoubleValue (5.0), "GridWidth", UintegerValue (1), "LayoutType", StringValue ("RowFirst")); // setup the AP. mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (backboneNodes.Get (i)); wifiMac.SetType ("ns3::ApWifiMac", "Ssid", SsidValue (ssid)); apDev = wifi.Install (wifiPhy, wifiMac, backboneNodes.Get (i)); NetDeviceContainer bridgeDev; bridgeDev = bridge.Install (backboneNodes.Get (i), NetDeviceContainer (apDev, backboneDevices.Get (i))); // assign AP IP address to bridge, not wifi apInterface = ip.Assign (bridgeDev); // setup the STAs stack.Install (sta); mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel", "Mode", StringValue ("Time"), "Time", StringValue ("2s"), "Speed", StringValue ("ns3::ConstantRandomVariable[Constant=1.0]"), "Bounds", RectangleValue (Rectangle (wifiX, wifiX+5.0,0.0, (nStas+1)*5.0))); mobility.Install (sta); wifiMac.SetType ("ns3::StaWifiMac", "Ssid", SsidValue (ssid), "ActiveProbing", BooleanValue (false)); staDev = wifi.Install (wifiPhy, wifiMac, sta); staInterface = ip.Assign (staDev); // save everything in containers. staNodes.push_back (sta); apDevices.push_back (apDev); apInterfaces.push_back (apInterface); staDevices.push_back (staDev); staInterfaces.push_back (staInterface); wifiX += 20.0; } Address dest; std::string protocol; if (sendIp) { dest = InetSocketAddress (staInterfaces[1].GetAddress (1), 1025); protocol = "ns3::UdpSocketFactory"; } else { PacketSocketAddress tmp; tmp.SetSingleDevice (staDevices[0].Get (0)->GetIfIndex ()); tmp.SetPhysicalAddress (staDevices[1].Get (0)->GetAddress ()); tmp.SetProtocol (0x807); dest = tmp; protocol = "ns3::PacketSocketFactory"; } OnOffHelper onoff = OnOffHelper (protocol, dest); onoff.SetConstantRate (DataRate ("500kb/s")); ApplicationContainer apps = onoff.Install (staNodes[0].Get (0)); apps.Start (Seconds (0.5)); apps.Stop (Seconds (3.0)); wifiPhy.EnablePcap ("wifi-wired-bridging", apDevices[0]); wifiPhy.EnablePcap ("wifi-wired-bridging", apDevices[1]); if (writeMobility) { AsciiTraceHelper ascii; MobilityHelper::EnableAsciiAll (ascii.CreateFileStream ("wifi-wired-bridging.mob")); } Simulator::Stop (Seconds (5.0)); Simulator::Run (); Simulator::Destroy (); }
void LenaPssFfMacSchedulerTestCase2::DoRun (void) { if (!m_errorModelEnabled) { Config::SetDefault ("ns3::LteSpectrumPhy::CtrlErrorModelEnabled", BooleanValue (false)); Config::SetDefault ("ns3::LteSpectrumPhy::DataErrorModelEnabled", BooleanValue (false)); } Config::SetDefault ("ns3::LteHelper::UseIdealRrc", BooleanValue (true)); Ptr<LteHelper> lteHelper = CreateObject<LteHelper> (); Ptr<PointToPointEpcHelper> epcHelper = CreateObject<PointToPointEpcHelper> (); lteHelper->SetEpcHelper (epcHelper); Ptr<Node> pgw = epcHelper->GetPgwNode (); // Create a single RemoteHost NodeContainer remoteHostContainer; remoteHostContainer.Create (1); Ptr<Node> remoteHost = remoteHostContainer.Get (0); InternetStackHelper internet; internet.Install (remoteHostContainer); // Create the Internet PointToPointHelper p2ph; p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s"))); p2ph.SetDeviceAttribute ("Mtu", UintegerValue (1500)); p2ph.SetChannelAttribute ("Delay", TimeValue (Seconds (0.001))); NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost); Ipv4AddressHelper ipv4h; ipv4h.SetBase ("1.0.0.0", "255.0.0.0"); Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign (internetDevices); // interface 0 is localhost, 1 is the p2p device Ipv4Address remoteHostAddr = internetIpIfaces.GetAddress (1); Ipv4StaticRoutingHelper ipv4RoutingHelper; Ptr<Ipv4StaticRouting> remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv4> ()); remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask ("255.0.0.0"), 1); // LogComponentDisableAll (LOG_LEVEL_ALL); //LogComponentEnable ("LenaTestPssFfMacCheduler", LOG_LEVEL_ALL); lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::FriisSpectrumPropagationLossModel")); // Create Nodes: eNodeB and UE NodeContainer enbNodes; NodeContainer ueNodes; enbNodes.Create (1); ueNodes.Create (m_nUser); // Install Mobility Model MobilityHelper mobility; mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (enbNodes); mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (ueNodes); // Create Devices and install them in the Nodes (eNB and UE) NetDeviceContainer enbDevs; NetDeviceContainer ueDevs; lteHelper->SetSchedulerType ("ns3::PssFfMacScheduler"); enbDevs = lteHelper->InstallEnbDevice (enbNodes); ueDevs = lteHelper->InstallUeDevice (ueNodes); Ptr<LteEnbNetDevice> lteEnbDev = enbDevs.Get (0)->GetObject<LteEnbNetDevice> (); Ptr<LteEnbPhy> enbPhy = lteEnbDev->GetPhy (); enbPhy->SetAttribute ("TxPower", DoubleValue (30.0)); enbPhy->SetAttribute ("NoiseFigure", DoubleValue (5.0)); // Set UEs' position and power for (int i = 0; i < m_nUser; i++) { Ptr<ConstantPositionMobilityModel> mm = ueNodes.Get (i)->GetObject<ConstantPositionMobilityModel> (); mm->SetPosition (Vector (m_dist.at (i), 0.0, 0.0)); Ptr<LteUeNetDevice> lteUeDev = ueDevs.Get (i)->GetObject<LteUeNetDevice> (); Ptr<LteUePhy> uePhy = lteUeDev->GetPhy (); uePhy->SetAttribute ("TxPower", DoubleValue (23.0)); uePhy->SetAttribute ("NoiseFigure", DoubleValue (9.0)); } // Install the IP stack on the UEs internet.Install (ueNodes); Ipv4InterfaceContainer ueIpIface; ueIpIface = epcHelper->AssignUeIpv4Address (NetDeviceContainer (ueDevs)); // Assign IP address to UEs for (uint32_t u = 0; u < ueNodes.GetN (); ++u) { Ptr<Node> ueNode = ueNodes.Get (u); // Set the default gateway for the UE Ptr<Ipv4StaticRouting> ueStaticRouting = ipv4RoutingHelper.GetStaticRouting (ueNode->GetObject<Ipv4> ()); ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress (), 1); } // Attach a UE to a eNB lteHelper->Attach (ueDevs, enbDevs.Get (0)); // Activate an EPS bearer on all UEs for (uint32_t u = 0; u < ueNodes.GetN (); ++u) { Ptr<NetDevice> ueDevice = ueDevs.Get (u); GbrQosInformation qos; qos.gbrDl = (m_packetSize.at (u) + 32) * (1000 / m_interval) * 8; // bit/s, considering IP, UDP, RLC, PDCP header size qos.gbrUl = (m_packetSize.at (u) + 32) * (1000 / m_interval) * 8; qos.mbrDl = qos.gbrDl; qos.mbrUl = qos.gbrUl; enum EpsBearer::Qci q = EpsBearer::GBR_CONV_VOICE; EpsBearer bearer (q, qos); lteHelper->ActivateDedicatedEpsBearer (ueDevice, bearer, EpcTft::Default ()); } // Install downlind and uplink applications uint16_t dlPort = 1234; uint16_t ulPort = 2000; PacketSinkHelper dlPacketSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), dlPort)); PacketSinkHelper ulPacketSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), ulPort)); ApplicationContainer clientApps; ApplicationContainer serverApps; for (uint32_t u = 0; u < ueNodes.GetN (); ++u) { ++ulPort; serverApps.Add (dlPacketSinkHelper.Install (ueNodes.Get (u))); // receive packets from remotehost serverApps.Add (ulPacketSinkHelper.Install (remoteHost)); // receive packets from UEs UdpClientHelper dlClient (ueIpIface.GetAddress (u), dlPort); // uplink packets generator dlClient.SetAttribute ("Interval", TimeValue (MilliSeconds (m_interval))); dlClient.SetAttribute ("MaxPackets", UintegerValue (1000000)); dlClient.SetAttribute ("PacketSize", UintegerValue (m_packetSize.at (u))); UdpClientHelper ulClient (remoteHostAddr, ulPort); // downlink packets generator ulClient.SetAttribute ("Interval", TimeValue (MilliSeconds (m_interval))); ulClient.SetAttribute ("MaxPackets", UintegerValue (1000000)); ulClient.SetAttribute ("PacketSize", UintegerValue (m_packetSize.at (u))); clientApps.Add (dlClient.Install (remoteHost)); clientApps.Add (ulClient.Install (ueNodes.Get (u))); } serverApps.Start (Seconds (0.030)); clientApps.Start (Seconds (0.030)); double statsStartTime = 0.04; // need to allow for RRC connection establishment + SRS double statsDuration = 0.5; double tolerance = 0.1; Simulator::Stop (Seconds (statsStartTime + statsDuration - 0.0001)); lteHelper->EnableRlcTraces (); Ptr<RadioBearerStatsCalculator> rlcStats = lteHelper->GetRlcStats (); rlcStats->SetAttribute ("StartTime", TimeValue (Seconds (statsStartTime))); rlcStats->SetAttribute ("EpochDuration", TimeValue (Seconds (statsDuration))); Simulator::Run (); /** * Check that the downlink assignation is done in a "token bank fair queue" manner */ NS_LOG_INFO ("DL - Test with " << m_nUser << " user(s)"); std::vector <uint64_t> dlDataRxed; for (int i = 0; i < m_nUser; i++) { // get the imsi uint64_t imsi = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetImsi (); // get the lcId uint8_t lcId = 4; dlDataRxed.push_back (rlcStats->GetDlRxData (imsi, lcId)); NS_LOG_INFO ("\tUser " << i << " dist " << m_dist.at (i) << " imsi " << imsi << " bytes rxed " << (double)dlDataRxed.at (i) << " thr " << (double)dlDataRxed.at (i) / statsDuration << " ref " << m_estThrPssDl.at (i)); } for (int i = 0; i < m_nUser; i++) { NS_TEST_ASSERT_MSG_EQ_TOL ((double)dlDataRxed.at (i) / statsDuration, m_estThrPssDl.at (i), m_estThrPssDl.at (i) * tolerance, " Unfair Throughput!"); } Simulator::Destroy (); }
int main (int argc, char *argv[]) { uint32_t nEnbPerFloor = 1; uint32_t nUe = 1; uint32_t nFloors = 0; double simTime = 1.0; CommandLine cmd; cmd.AddValue ("nEnb", "Number of eNodeBs per floor", nEnbPerFloor); cmd.AddValue ("nUe", "Number of UEs", nUe); cmd.AddValue ("nFloors", "Number of floors, 0 for Friis propagation model", nFloors); cmd.AddValue ("simTime", "Total duration of the simulation (in seconds)", simTime); cmd.Parse (argc, argv); ConfigStore inputConfig; inputConfig.ConfigureDefaults (); // parse again so you can override default values from the command line cmd.Parse (argc, argv); // Geometry of the scenario (in meters) // Assume squared building double nodeHeight = 1.5; double roomHeight = 3; double roomLength = 8; uint32_t nRooms = std::ceil (std::sqrt (nEnbPerFloor)); uint32_t nEnb; Ptr<LteHelper> lteHelper = CreateObject<LteHelper> (); //lteHelper->EnableLogComponents (); //LogComponentEnable ("BuildingsPropagationLossModel", LOG_LEVEL_ALL); if (nFloors == 0) { lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::FriisPropagationLossModel")); nEnb = nEnbPerFloor; } else { lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::HybridBuildingsPropagationLossModel")); nEnb = nFloors * nEnbPerFloor; } // Create Nodes: eNodeB and UE NodeContainer enbNodes; std::vector<NodeContainer> ueNodes; enbNodes.Create (nEnb); for (uint32_t i = 0; i < nEnb; i++) { NodeContainer ueNode; ueNode.Create (nUe); ueNodes.push_back (ueNode); } MobilityHelper mobility; mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); std::vector<Vector> enbPosition; Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> (); Ptr<Building> building; if (nFloors == 0) { // Position of eNBs uint32_t plantedEnb = 0; for (uint32_t row = 0; row < nRooms; row++) { for (uint32_t column = 0; column < nRooms && plantedEnb < nEnbPerFloor; column++, plantedEnb++) { Vector v (roomLength * (column + 0.5), roomLength * (row + 0.5), nodeHeight); positionAlloc->Add (v); enbPosition.push_back (v); mobility.Install (ueNodes.at(plantedEnb)); } } mobility.SetPositionAllocator (positionAlloc); mobility.Install (enbNodes); BuildingsHelper::Install (enbNodes); // Position of UEs attached to eNB for (uint32_t i = 0; i < nEnb; i++) { Ptr<UniformRandomVariable> posX = CreateObject<UniformRandomVariable> (); posX->SetAttribute ("Min", DoubleValue (enbPosition.at(i).x - roomLength * 0.5)); posX->SetAttribute ("Max", DoubleValue (enbPosition.at(i).x + roomLength * 0.5)); Ptr<UniformRandomVariable> posY = CreateObject<UniformRandomVariable> (); posY->SetAttribute ("Min", DoubleValue (enbPosition.at(i).y - roomLength * 0.5)); posY->SetAttribute ("Max", DoubleValue (enbPosition.at(i).y + roomLength * 0.5)); positionAlloc = CreateObject<ListPositionAllocator> (); for (uint32_t j = 0; j < nUe; j++) { positionAlloc->Add (Vector (posX->GetValue (), posY->GetValue (), nodeHeight)); mobility.SetPositionAllocator (positionAlloc); } mobility.Install (ueNodes.at(i)); BuildingsHelper::Install (ueNodes.at(i)); } } else { building = CreateObject<Building> (); building->SetBoundaries (Box (0.0, nRooms * roomLength, 0.0, nRooms * roomLength, 0.0, nFloors* roomHeight)); building->SetBuildingType (Building::Residential); building->SetExtWallsType (Building::ConcreteWithWindows); building->SetNFloors (nFloors); building->SetNRoomsX (nRooms); building->SetNRoomsY (nRooms); mobility.Install (enbNodes); BuildingsHelper::Install (enbNodes); uint32_t plantedEnb = 0; for (uint32_t floor = 0; floor < nFloors; floor++) { uint32_t plantedEnbPerFloor = 0; for (uint32_t row = 0; row < nRooms; row++) { for (uint32_t column = 0; column < nRooms && plantedEnbPerFloor < nEnbPerFloor; column++, plantedEnb++, plantedEnbPerFloor++) { Vector v (roomLength * (column + 0.5), roomLength * (row + 0.5), nodeHeight + roomHeight * floor); positionAlloc->Add (v); enbPosition.push_back (v); Ptr<MobilityModel> mmEnb = enbNodes.Get (plantedEnb)->GetObject<MobilityModel> (); mmEnb->SetPosition (v); // Positioning UEs attached to eNB mobility.Install (ueNodes.at(plantedEnb)); BuildingsHelper::Install (ueNodes.at(plantedEnb)); for (uint32_t ue = 0; ue < nUe; ue++) { Ptr<MobilityModel> mmUe = ueNodes.at(plantedEnb).Get (ue)->GetObject<MobilityModel> (); Vector vUe (v.x, v.y, v.z); mmUe->SetPosition (vUe); } } } } } // Create Devices and install them in the Nodes (eNB and UE) NetDeviceContainer enbDevs; std::vector<NetDeviceContainer> ueDevs; enbDevs = lteHelper->InstallEnbDevice (enbNodes); for (uint32_t i = 0; i < nEnb; i++) { NetDeviceContainer ueDev = lteHelper->InstallUeDevice (ueNodes.at(i)); ueDevs.push_back (ueDev); lteHelper->Attach (ueDev, enbDevs.Get (i)); enum EpsBearer::Qci q = EpsBearer::GBR_CONV_VOICE; EpsBearer bearer (q); lteHelper->ActivateDataRadioBearer (ueDev, bearer); } BuildingsHelper::MakeMobilityModelConsistent (); Simulator::Stop (Seconds (simTime)); lteHelper->EnableTraces (); Simulator::Run (); /*GtkConfigStore config; config.ConfigureAttributes ();*/ Simulator::Destroy (); return 0; }
void LenaDlCtrlPhyErrorModelTestCase::DoRun (void) { double ber = 0.03; Config::SetDefault ("ns3::LteAmc::Ber", DoubleValue (ber)); Config::SetDefault ("ns3::LteAmc::AmcModel", EnumValue (LteAmc::PiroEW2010)); Config::SetDefault ("ns3::LteSpectrumPhy::CtrlErrorModelEnabled", BooleanValue (true)); Config::SetDefault ("ns3::LteSpectrumPhy::DataErrorModelEnabled", BooleanValue (false)); Config::SetDefault ("ns3::RrFfMacScheduler::HarqEnabled", BooleanValue (false)); Config::SetGlobal ("RngRun", IntegerValue (m_rngRun)); /* * Initialize Simulation Scenario: 1 eNB and m_nUser UEs */ int64_t stream = 1; Ptr<LteHelper> lena = CreateObject<LteHelper> (); // Create Nodes: eNodeB and UE NodeContainer enbNodes; NodeContainer ueNodes; enbNodes.Create (m_nEnb); ueNodes.Create (1); // Install Mobility Model MobilityHelper mobility; mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (enbNodes); BuildingsHelper::Install (enbNodes); mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (ueNodes); BuildingsHelper::Install (ueNodes); // remove random shadowing component lena->SetAttribute ("PathlossModel", StringValue ("ns3::HybridBuildingsPropagationLossModel")); lena->SetPathlossModelAttribute ("ShadowSigmaOutdoor", DoubleValue (0.0)); lena->SetPathlossModelAttribute ("ShadowSigmaIndoor", DoubleValue (0.0)); lena->SetPathlossModelAttribute ("ShadowSigmaExtWalls", DoubleValue (0.0)); // Create Devices and install them in the Nodes (eNB and UE) NetDeviceContainer enbDevs; NetDeviceContainer ueDevs; lena->SetSchedulerType ("ns3::RrFfMacScheduler"); lena->SetSchedulerAttribute ("UlCqiFilter", EnumValue (FfMacScheduler::PUSCH_UL_CQI)); enbDevs = lena->InstallEnbDevice (enbNodes); stream += lena->AssignStreams (enbDevs, stream); ueDevs = lena->InstallUeDevice (ueNodes); stream += lena->AssignStreams (ueDevs, stream); // Attach a UE to one eNB (the others are interfering ones) lena->Attach (ueDevs, enbDevs.Get (0)); // Activate an EPS bearer enum EpsBearer::Qci q = EpsBearer::GBR_CONV_VOICE; EpsBearer bearer (q); lena->ActivateDataRadioBearer (ueDevs, bearer); // Set UEs' position and power for (int i = 0; i < m_nEnb; i++) { // place the HeNB over the default rooftop level (20 mt.) Ptr<MobilityModel> mm = enbNodes.Get (i)->GetObject<MobilityModel> (); mm->SetPosition (Vector (0.0, 0.0, 30.0)); Ptr<LteEnbNetDevice> lteEnbDev = enbDevs.Get (i)->GetObject<LteEnbNetDevice> (); Ptr<LteEnbPhy> enbPhy = lteEnbDev->GetPhy (); enbPhy->SetAttribute ("TxPower", DoubleValue (43.0)); enbPhy->SetAttribute ("NoiseFigure", DoubleValue (5.0)); } // Set UEs' position and power Ptr<MobilityModel> mm = ueNodes.Get (0)->GetObject<MobilityModel> (); mm->SetPosition (Vector (m_dist, 0.0, 1.0)); Ptr<LteUeNetDevice> lteUeDev = ueDevs.Get (0)->GetObject<LteUeNetDevice> (); Ptr<LteUePhy> uePhy = lteUeDev->GetPhy (); uePhy->SetAttribute ("TxPower", DoubleValue (23.0)); uePhy->SetAttribute ("NoiseFigure", DoubleValue (9.0)); Time statsDuration = Seconds (1.0); Simulator::Stop (m_statsStartTime + statsDuration - Seconds (0.0001)); lena->EnableRlcTraces (); Ptr<RadioBearerStatsCalculator> rlcStats = lena->GetRlcStats (); rlcStats->SetAttribute ("StartTime", TimeValue (m_statsStartTime)); rlcStats->SetAttribute ("EpochDuration", TimeValue (statsDuration)); Simulator::Run (); NS_LOG_INFO ("\tTest downlink control channels (PCFICH+PDCCH)"); NS_LOG_INFO ("Test with " << m_nEnb << " eNB(s) at distance " << m_dist << " expected BLER " << m_blerRef); int nUser = 1; for (int i = 0; i < nUser; i++) { // get the imsi uint64_t imsi = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetImsi (); uint8_t lcId = 3; double dlRxPackets = rlcStats->GetDlRxPackets (imsi, lcId); double dlTxPackets = rlcStats->GetDlTxPackets (imsi, lcId); double dlBler = 1.0 - (dlRxPackets/dlTxPackets); double expectedDlRxPackets = dlTxPackets -dlTxPackets*m_blerRef; NS_LOG_INFO ("\tUser " << i << " imsi " << imsi << " DOWNLINK" << " pkts rx " << dlRxPackets << " tx " << dlTxPackets << " BLER " << dlBler << " Err " << std::fabs (m_blerRef - dlBler) << " expected rx " << expectedDlRxPackets << " difference " << std::abs (expectedDlRxPackets - dlRxPackets) << " tolerance " << m_toleranceRxPackets); NS_UNUSED (dlBler); // sanity check for whether the tx packets reported by the stats are correct // we expect one packet per TTI double expectedDlTxPackets = statsDuration.GetMilliSeconds (); NS_TEST_ASSERT_MSG_EQ_TOL (dlTxPackets, expectedDlTxPackets, expectedDlTxPackets * 0.005, " too different DL TX packets reported"); // this is the main test condition: check that the RX packets are within the expected range NS_TEST_ASSERT_MSG_EQ_TOL (dlRxPackets, expectedDlRxPackets, m_toleranceRxPackets, "too different DL RX packets reported"); } Simulator::Destroy (); }