bool Ns3WimaxSimpleOFDMTestCase::DoRunOnce (double FrameDuration) { WimaxHelper::SchedulerType scheduler = WimaxHelper::SCHED_TYPE_SIMPLE; NodeContainer ssNodes; NodeContainer bsNodes; ssNodes.Create (3); bsNodes.Create (1); WimaxHelper wimax; NetDeviceContainer ssDevs, bsDevs; ssDevs = wimax.Install (ssNodes, WimaxHelper::DEVICE_TYPE_SUBSCRIBER_STATION, WimaxHelper::SIMPLE_PHY_TYPE_OFDM, scheduler, FrameDuration); bsDevs = wimax.Install (bsNodes, WimaxHelper::DEVICE_TYPE_BASE_STATION, WimaxHelper::SIMPLE_PHY_TYPE_OFDM, scheduler, FrameDuration); Simulator::Stop (Seconds (1)); Simulator::Run (); for (int i = 0; i < 3; i++) { if (ssDevs.Get (i)->GetObject<SubscriberStationNetDevice> ()->IsRegistered () == false) { NS_LOG_DEBUG ("SS[" << i << "] not registered"); return true; // Test fail because SS[i] is not registered } } Simulator::Destroy (); return (false); // Test was ok, all the SSs are registered }
int main (int argc, char *argv[]) { NodeContainer nodes; nodes.Create (2); PointToPointHelper pointToPoint; NetDeviceContainer devices; devices = pointToPoint.Install (nodes); InternetStackHelper stack; stack.Install (nodes); Ipv4AddressHelper address; address.SetBase ("10.1.1.0", "255.255.255.252"); Ipv4InterfaceContainer interfaces = address.Assign (devices); uint16_t sinkPort = 8080; Address sinkAddress (InetSocketAddress (interfaces.GetAddress (1), sinkPort)); Ptr<PacketSink> receiverApplication = CreateObject<PacketSink> (); receiverApplication->SetAttribute ("Local", AddressValue (InetSocketAddress (Ipv4Address::GetAny(), 8080))); receiverApplication->SetAttribute ("Protocol", TypeIdValue(TcpSocketFactory::GetTypeId())); receiverApplication->TraceConnectWithoutContext ("Rx", MakeCallback (&CountRx)); nodes.Get(1)->AddApplication(receiverApplication); Ptr<MyApp> app = CreateObject<MyApp> (nodes.Get (0), sinkAddress); nodes.Get (0)->AddApplication (app); Simulator::Stop (); Simulator::Run (); Simulator::Destroy (); return 0; }
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; }
int main (int argc, char *argv[]) { #ifdef NS3_CLICK NodeContainer csmaNodes; csmaNodes.Create (2); // Setup CSMA channel between the nodes CsmaHelper csma; csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate (5000000))); csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2))); NetDeviceContainer csmaDevices = csma.Install (csmaNodes); // Install normal internet stack on node B InternetStackHelper internet; internet.Install (csmaNodes.Get (1)); // Install Click on node A ClickInternetStackHelper clickinternet; clickinternet.SetClickFile (csmaNodes.Get (0), "src/click/examples/nsclick-lan-single-interface.click"); clickinternet.SetRoutingTableElement (csmaNodes.Get (0), "rt"); clickinternet.Install (csmaNodes.Get (0)); // Configure IP addresses for the nodes Ipv4AddressHelper ipv4; ipv4.SetBase ("172.16.1.0", "255.255.255.0"); ipv4.Assign (csmaDevices); // Configure traffic application and sockets Address LocalAddress (InetSocketAddress (Ipv4Address::GetAny (), 50000)); PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", LocalAddress); ApplicationContainer recvapp = packetSinkHelper.Install (csmaNodes.Get (1)); recvapp.Start (Seconds (5.0)); recvapp.Stop (Seconds (10.0)); OnOffHelper onOffHelper ("ns3::TcpSocketFactory", Address ()); onOffHelper.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]")); onOffHelper.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]")); ApplicationContainer appcont; AddressValue remoteAddress (InetSocketAddress (Ipv4Address ("172.16.1.2"), 50000)); onOffHelper.SetAttribute ("Remote", remoteAddress); appcont.Add (onOffHelper.Install (csmaNodes.Get (0))); appcont.Start (Seconds (5.0)); appcont.Stop (Seconds (10.0)); // For tracing csma.EnablePcap ("nsclick-simple-lan", csmaDevices, false); Simulator::Stop (Seconds (20.0)); Simulator::Run (); Simulator::Destroy (); return 0; #else NS_FATAL_ERROR ("Can't use ns-3-click without NSCLICK compiled in"); #endif }
// // Network topology // // n0 n1 n2 n3 // | | | | // ===================== // // - Packet socket flow from n0 to n1 and from node n3 to n0 // -- We will test reception at node n0 // - Default 512 byte packets generated by traffic generator // void CsmaPacketSocketTestCase::DoRun (void) { // Here, we will explicitly create four nodes. NodeContainer nodes; nodes.Create (4); PacketSocketHelper packetSocket; packetSocket.Install (nodes); // create the shared medium used by all csma devices. Ptr<CsmaChannel> channel = CreateObjectWithAttributes<CsmaChannel> ( "DataRate", DataRateValue (DataRate (5000000)), "Delay", TimeValue (MilliSeconds (2))); // use a helper function to connect our nodes to the shared channel. CsmaHelper csma; csma.SetDeviceAttribute ("EncapsulationMode", StringValue ("Llc")); NetDeviceContainer devs = csma.Install (nodes, channel); // Create the OnOff application to send raw datagrams // // Make packets be sent about every DefaultPacketSize / DataRate = // 4096 bits / (5000 bits/second) = 0.82 second. PacketSocketAddress socket; socket.SetSingleDevice (devs.Get (0)->GetIfIndex ()); socket.SetPhysicalAddress (devs.Get (1)->GetAddress ()); socket.SetProtocol (2); OnOffHelper onoff ("ns3::PacketSocketFactory", Address (socket)); onoff.SetConstantRate (DataRate (5000)); ApplicationContainer apps = onoff.Install (nodes.Get (0)); apps.Start (Seconds (1.0)); apps.Stop (Seconds (10.0)); socket.SetSingleDevice (devs.Get (3)->GetIfIndex ()); socket.SetPhysicalAddress (devs.Get (0)->GetAddress ()); socket.SetProtocol (3); onoff.SetAttribute ("Remote", AddressValue (socket)); apps = onoff.Install (nodes.Get (3)); apps.Start (Seconds (1.0)); apps.Stop (Seconds (10.0)); PacketSinkHelper sink = PacketSinkHelper ("ns3::PacketSocketFactory", socket); apps = sink.Install (nodes.Get (0)); apps.Start (Seconds (0.0)); apps.Stop (Seconds (20.0)); // Trace receptions Config::Connect ("/NodeList/0/ApplicationList/*/$ns3::PacketSink/Rx", MakeCallback (&CsmaPacketSocketTestCase::SinkRx, this)); Simulator::Run (); Simulator::Destroy (); // We should have received 10 packets on node 0 NS_TEST_ASSERT_MSG_EQ (m_count, 10, "Node 0 should have received 10 packets"); }
int main(int argc, char* argv[]) { // 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")); // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize CommandLine cmd; cmd.Parse(argc, argv); // Creating nodes NodeContainer nodes; nodes.Create(3); // Connecting nodes using two links PointToPointHelper p2p; p2p.Install(nodes.Get(0), nodes.Get(1)); p2p.Install(nodes.Get(1), nodes.Get(2)); // Install NDN stack on all nodes ndn::StackHelper ndnHelper; ndnHelper.SetDefaultRoutes(true); ndnHelper.SetOldContentStore( "ns3::ndn::cs::Freshness::Lru"); // don't set up max size here, will use default value = 100 ndnHelper.InstallAll(); // set up max sizes, after NDN stack is installed Config::Set("/NodeList/0/$ns3::ndn::ContentStore/MaxSize", UintegerValue( 1)); // number after nodeList is global ID of the node (= node->GetId ()) Config::Set("/NodeList/1/$ns3::ndn::ContentStore/MaxSize", UintegerValue(2)); Config::Set("/NodeList/2/$ns3::ndn::ContentStore/MaxSize", UintegerValue(200)); // Installing applications // Consumer ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr"); // Consumer will request /prefix/0, /prefix/1, ... consumerHelper.SetPrefix("/prefix"); consumerHelper.SetAttribute("Frequency", StringValue("10")); // 10 interests a second consumerHelper.Install(nodes.Get(0)); // first node // Producer ndn::AppHelper producerHelper("ns3::ndn::Producer"); // Producer will reply to all requests starting with /prefix producerHelper.SetPrefix("/prefix"); producerHelper.SetAttribute("PayloadSize", StringValue("1024")); producerHelper.Install(nodes.Get(2)); // last node Simulator::Stop(Seconds(20.0)); Simulator::Run(); Simulator::Destroy(); return 0; }
int main (int argc, char *argv[]) { CommandLine cmd; cmd.Parse (argc, argv); // // We are interacting with the outside, real, world. This means we have to // interact in real-time and therefore means we have to use the real-time // simulator and take the time to calculate checksums. // GlobalValue::Bind ("SimulatorImplementationType", StringValue ("ns3::RealtimeSimulatorImpl")); GlobalValue::Bind ("ChecksumEnabled", BooleanValue (true)); // // Create two ghost nodes. The first will represent the virtual machine host // on the left side of the network; and the second will represent the VM on // the right side. // NodeContainer nodes; nodes.Create (2); // // Use a CsmaHelper to get a CSMA channel created, and the needed net // devices installed on both of the nodes. The data rate and delay for the // channel can be set through the command-line parser. For example, // // ./waf --run "tap=csma-virtual-machine --ns3::CsmaChannel::DataRate=10000000" // CsmaHelper csma; NetDeviceContainer devices = csma.Install (nodes); // // Use the TapBridgeHelper to connect to the pre-configured tap devices for // the left side. We go with "UseBridge" mode since the CSMA devices support // promiscuous mode and can therefore make it appear that the bridge is // extended into ns-3. The install method essentially bridges the specified // tap to the specified CSMA device. // TapBridgeHelper tapBridge; tapBridge.SetAttribute ("Mode", StringValue ("UseBridge")); tapBridge.SetAttribute ("DeviceName", StringValue ("tap-left")); tapBridge.Install (nodes.Get (0), devices.Get (0)); // // Connect the right side tap to the right side CSMA device on the right-side // ghost node. // tapBridge.SetAttribute ("DeviceName", StringValue ("tap-right")); tapBridge.Install (nodes.Get (1), devices.Get (1)); // // Run the simulation for ten minutes to give the user time to play around // Simulator::Stop (Seconds (600.)); Simulator::Run (); Simulator::Destroy (); }
int main(int argc, char *argv[]) { // 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")); // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize CommandLine cmd; cmd.Parse(argc, argv); // Creating nodes NodeContainer nodes; nodes.Create(3); // Connecting nodes using two links PointToPointHelper p2p; p2p.Install(nodes.Get(0), nodes.Get(1)); p2p.Install(nodes.Get(1), nodes.Get(2)); // Install NDN stack on all nodes StackHelper ndnHelper; ndnHelper.InstallAll(); // Installing global routing interface on all nodes ndn::GlobalRoutingHelper ndnGlobalRoutingHelper; ndnGlobalRoutingHelper.InstallAll(); // Installing applications // Consumer ndn::AppHelper consumerHelper("PingClientApp"); consumerHelper.SetAttribute("Prefix", StringValue("/ping")); consumerHelper.SetAttribute("nPings", StringValue("3")); consumerHelper.Install(nodes.Get(0)).Start(Seconds(2)); // Producer ndn::AppHelper producerHelper("PingServerApp"); producerHelper.SetAttribute("Prefix", StringValue("/ping")); producerHelper.SetAttribute("nMaxPings", StringValue("3")); producerHelper.Install(nodes.Get(2)).Start(Seconds(0.1)); ndnGlobalRoutingHelper.AddOrigins("/ping", nodes.Get(2)); // Calculate and install FIBs ndn::GlobalRoutingHelper::CalculateRoutes(); Simulator::Stop(Seconds(20.0)); Simulator::Run(); Simulator::Destroy(); return 0; }
int main(int argc, char* argv[]) { // 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::QueueBase::MaxPackets", UintegerValue(20)); // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize CommandLine cmd; cmd.Parse(argc, argv); // Creating nodes NodeContainer nodes; nodes.Create(3); // Connecting nodes using two links PointToPointHelper p2p; p2p.Install(nodes.Get(0), nodes.Get(1)); p2p.Install(nodes.Get(1), nodes.Get(2)); // Install NDN stack on all nodes ndn::StackHelper ndnHelper; ndnHelper.SetDefaultRoutes(true); ndnHelper.InstallAll(); // Installing applications // Consumer ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr"); // Consumer will request /prefix/0, /prefix/1, ... consumerHelper.SetPrefix("/prefix"); consumerHelper.SetAttribute("Frequency", StringValue("10")); // 10 interests a second consumerHelper.Install(nodes.Get(0)); // first node // Producer ndn::AppHelper producerHelper("ns3::ndn::Producer"); // Producer will reply to all requests starting with /prefix producerHelper.SetPrefix("/prefix"); producerHelper.SetAttribute("PayloadSize", StringValue("1024")); producerHelper.SetAttribute("Signature", UintegerValue(100)); producerHelper.SetAttribute("KeyLocator", StringValue("/unique/key/locator")); producerHelper.Install(nodes.Get(2)); // last node PcapWriter trace("ndn-simple-trace.pcap"); Config::ConnectWithoutContext("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/MacTx", MakeCallback(&PcapWriter::TracePacket, &trace)); Simulator::Stop(Seconds(20.0)); Simulator::Run(); Simulator::Destroy(); return 0; }
int main(int argc, char* argv[]) { // 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")); // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize CommandLine cmd; cmd.Parse(argc, argv); // Creating nodes NodeContainer nodes; nodes.Create(3); // Connecting nodes using two links PointToPointHelper p2p; p2p.Install(nodes.Get(0), nodes.Get(1)); p2p.Install(nodes.Get(1), nodes.Get(2)); // Install NDN stack on all nodes ndn::StackHelper ndnHelper; ndnHelper.SetDefaultRoutes(true); ndnHelper.InstallAll(); // Choosing forwarding strategy ndn::StrategyChoiceHelper::InstallAll("/prefix", "/localhost/nfd/strategy/multicast"); // Installing applications // Consumer ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr"); // Consumer will request /prefix/0, /prefix/1, ... consumerHelper.SetPrefix("/prefix"); consumerHelper.SetAttribute("Frequency", StringValue("1")); // 10 interests a second consumerHelper.SetAttribute("MaxSeq",IntegerValue(5)); consumerHelper.Install(nodes.Get(0)); // first node // Producer ndn::AppHelper producerHelper("ns3::ndn::Producer"); // Producer will reply to all requests starting with /prefix producerHelper.SetPrefix("/prefix"); producerHelper.SetAttribute("PayloadSize", StringValue("1024")); producerHelper.Install(nodes.Get(2)); // last node Simulator::Stop(Seconds(20.0)); Simulator::Run(); Simulator::Destroy(); return 0; }
// // Network topology // (sender) (receiver) // n0 n1 n2 n3 // | | | | // ===================== // // Node n0 sends data to node n3 over a raw IP socket. The protocol // number used is 2. // void CsmaRawIpSocketTestCase::DoRun (void) { // Here, we will explicitly create four nodes. NodeContainer c; c.Create (4); // connect all our nodes to a shared channel. CsmaHelper csma; csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate (5000000))); csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2))); csma.SetDeviceAttribute ("EncapsulationMode", StringValue ("Llc")); NetDeviceContainer devs = csma.Install (c); // add an ip stack to all nodes. InternetStackHelper ipStack; ipStack.Install (c); // assign ip addresses Ipv4AddressHelper ip; ip.SetBase ("192.168.1.0", "255.255.255.0"); Ipv4InterfaceContainer addresses = ip.Assign (devs); // IP protocol configuration // // Make packets be sent about every DefaultPacketSize / DataRate = // 4096 bits / (5000 bits/second) = 0.82 second. Config::SetDefault ("ns3::Ipv4RawSocketImpl::Protocol", StringValue ("2")); InetSocketAddress dst = InetSocketAddress (addresses.GetAddress (3)); OnOffHelper onoff = OnOffHelper ("ns3::Ipv4RawSocketFactory", dst); onoff.SetConstantRate (DataRate (5000)); ApplicationContainer apps = onoff.Install (c.Get (0)); apps.Start (Seconds (1.0)); apps.Stop (Seconds (10.0)); PacketSinkHelper sink = PacketSinkHelper ("ns3::Ipv4RawSocketFactory", dst); apps = sink.Install (c.Get (3)); apps.Start (Seconds (0.0)); apps.Stop (Seconds (12.0)); // Trace receptions Config::ConnectWithoutContext ("/NodeList/3/ApplicationList/0/$ns3::PacketSink/Rx", MakeCallback (&CsmaRawIpSocketTestCase::SinkRx, this)); Simulator::Run (); Simulator::Destroy (); // We should have sent and received 10 packets NS_TEST_ASSERT_MSG_EQ (m_count, 10, "Node 3 should have received 10 packets"); }
int main (int argc, char *argv[]) { Time::SetResolution (Time::NS); LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO); LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO); NodeContainer nodes; nodes.Create (2); PointToPointHelper pointToPoint; pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms")); NetDeviceContainer devices; devices = pointToPoint.Install (nodes); InternetStackHelper stack; stack.Install (nodes); Ipv4AddressHelper address; address.SetBase ("10.1.1.0", "255.255.255.0"); Ipv4InterfaceContainer interfaces = address.Assign (devices); UdpEchoServerHelper echoServer (9); ApplicationContainer serverApps = echoServer.Install (nodes.Get (1)); serverApps.Start (Seconds (1.0)); serverApps.Stop (Seconds (10.0)); UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9); echoClient.SetAttribute ("MaxPackets", UintegerValue (1)); echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0))); echoClient.SetAttribute ("PacketSize", UintegerValue (1024)); ApplicationContainer clientApps = echoClient.Install (nodes.Get (0)); clientApps.Start (Seconds (2.0)); clientApps.Stop (Seconds (10.0)); Simulator::Run (); Simulator::Destroy (); return 0; }
int main(int argc, char *argv[]) { // 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")); // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize CommandLine cmd; cmd.Parse(argc, argv); // Creating nodes NodeContainer nodes; nodes.Create(3); // Connecting nodes using two links PointToPointHelper p2p; p2p.Install(nodes.Get(0), nodes.Get(1)); p2p.Install(nodes.Get(1), nodes.Get(2)); // Install NDN stack on all nodes StackHelper ndnHelper; ndnHelper.SetDefaultRoutes(true); ndnHelper.InstallAll(); // Installing applications // Consumer auto consumer = CreateObject<ApiApp<PingClient>>(); nodes.Get(0)->AddApplication(consumer); // consumer->SetStopTime(Seconds(15.0)); auto producer = CreateObject<ApiApp<PingServer>>(); nodes.Get(2)->AddApplication(producer); // producer->SetStartTime(Seconds(0.5)); Simulator::Stop(Seconds(20.0)); Simulator::Run(); Simulator::Destroy(); return 0; }
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[]) { 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; }
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[]) { #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; }
// Test derived from examples/routing/dynamic-global-routing.cc // // Network topology // // n0 // \ p-p // \ (shared csma/cd) // n2 -------------------------n3 // / | | // / p-p n4 n5 ---------- n6 // n1 p-p // | | // ---------------------------------------- // p-p // // Test that for node n6, the interface facing n5 receives packets at // times (1-2), (4-6), (8-10), (11-12), (14-16) and the interface // facing n1 receives packets at times (2-4), (6-8), (12-13) // void DynamicGlobalRoutingTestCase::DoRun (void) { // The below value configures the default behavior of global routing. // By default, it is disabled. To respond to interface events, set to true Config::SetDefault ("ns3::Ipv4GlobalRouting::RespondToInterfaceEvents", BooleanValue (true)); NodeContainer c; c.Create (7); NodeContainer n0n2 = NodeContainer (c.Get (0), c.Get (2)); NodeContainer n1n2 = NodeContainer (c.Get (1), c.Get (2)); NodeContainer n5n6 = NodeContainer (c.Get (5), c.Get (6)); NodeContainer n1n6 = NodeContainer (c.Get (1), c.Get (6)); NodeContainer n2345 = NodeContainer (c.Get (2), c.Get (3), c.Get (4), c.Get (5)); InternetStackHelper internet; internet.Install (c); // We create the channels first without any IP addressing information PointToPointHelper p2p; p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); p2p.SetChannelAttribute ("Delay", StringValue ("2ms")); NetDeviceContainer d0d2 = p2p.Install (n0n2); NetDeviceContainer d1d6 = p2p.Install (n1n6); NetDeviceContainer d1d2 = p2p.Install (n1n2); p2p.SetDeviceAttribute ("DataRate", StringValue ("1500kbps")); p2p.SetChannelAttribute ("Delay", StringValue ("10ms")); NetDeviceContainer d5d6 = p2p.Install (n5n6); // We create the channels first without any IP addressing information CsmaHelper csma; csma.SetChannelAttribute ("DataRate", StringValue ("5Mbps")); csma.SetChannelAttribute ("Delay", StringValue ("2ms")); NetDeviceContainer d2345 = csma.Install (n2345); // Later, we add IP addresses. Ipv4AddressHelper ipv4; ipv4.SetBase ("10.1.1.0", "255.255.255.0"); ipv4.Assign (d0d2); ipv4.SetBase ("10.1.2.0", "255.255.255.0"); ipv4.Assign (d1d2); ipv4.SetBase ("10.1.3.0", "255.255.255.0"); Ipv4InterfaceContainer i5i6 = ipv4.Assign (d5d6); ipv4.SetBase ("10.250.1.0", "255.255.255.0"); ipv4.Assign (d2345); ipv4.SetBase ("172.16.1.0", "255.255.255.0"); Ipv4InterfaceContainer i1i6 = ipv4.Assign (d1d6); // Create router nodes, initialize routing database and set up the routing // tables in the nodes. Ipv4GlobalRoutingHelper::PopulateRoutingTables (); // Create the OnOff application to send UDP datagrams of size // 210 bytes at a rate of 448 Kb/s uint16_t port = 9; // Discard port (RFC 863) OnOffHelper onoff ("ns3::UdpSocketFactory", InetSocketAddress (i5i6.GetAddress (1), port)); onoff.SetConstantRate (DataRate ("2kbps")); onoff.SetAttribute ("PacketSize", UintegerValue (50)); ApplicationContainer apps = onoff.Install (c.Get (1)); apps.Start (Seconds (1.0)); apps.Stop (Seconds (10.0)); // Create a second OnOff application to send UDP datagrams of size // 210 bytes at a rate of 448 Kb/s OnOffHelper onoff2 ("ns3::UdpSocketFactory", InetSocketAddress (i1i6.GetAddress (1), port)); onoff2.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]")); onoff2.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]")); onoff2.SetAttribute ("DataRate", StringValue ("2kbps")); onoff2.SetAttribute ("PacketSize", UintegerValue (50)); ApplicationContainer apps2 = onoff2.Install (c.Get (1)); apps2.Start (Seconds (11.0)); apps2.Stop (Seconds (16.0)); // Create an optional packet sink to receive these packets TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory"); Ptr<Socket> sink2 = Socket::CreateSocket (c.Get (6), tid); sink2->Bind (Address (InetSocketAddress (Ipv4Address::GetAny (), port))); sink2->Listen (); sink2->ShutdownSend (); sink2->SetRecvPktInfo (true); sink2->SetRecvCallback (MakeCallback (&DynamicGlobalRoutingTestCase::HandleRead, this)); Ptr<Node> n1 = c.Get (1); Ptr<Ipv4> ipv41 = n1->GetObject<Ipv4> (); // The first ifIndex is 0 for loopback, then the first p2p is numbered 1, // then the next p2p is numbered 2 uint32_t ipv4ifIndex1 = 2; // Trace receptions Config::Connect ("/NodeList/6/ApplicationList/*/$ns3::PacketSink/Rx", MakeCallback (&DynamicGlobalRoutingTestCase::SinkRx, this)); Simulator::Schedule (Seconds (2),&Ipv4::SetDown,ipv41, ipv4ifIndex1); Simulator::Schedule (Seconds (4),&Ipv4::SetUp,ipv41, ipv4ifIndex1); Ptr<Node> n6 = c.Get (6); Ptr<Ipv4> ipv46 = n6->GetObject<Ipv4> (); // The first ifIndex is 0 for loopback, then the first p2p is numbered 1, // then the next p2p is numbered 2 uint32_t ipv4ifIndex6 = 2; Simulator::Schedule (Seconds (6),&Ipv4::SetDown,ipv46, ipv4ifIndex6); Simulator::Schedule (Seconds (8),&Ipv4::SetUp,ipv46, ipv4ifIndex6); Simulator::Schedule (Seconds (12),&Ipv4::SetDown,ipv41, ipv4ifIndex1); Simulator::Schedule (Seconds (14),&Ipv4::SetUp,ipv41, ipv4ifIndex1); Simulator::Run (); NS_TEST_ASSERT_MSG_EQ (m_count, 68, "Dynamic global routing did not deliver all packets"); // Test that for node n6, the interface facing n5 receives packets at // times (1-2), (4-6), (8-10), (11-12), (14-16) and the interface // facing n1 receives packets at times (2-4), (6-8), (12-13) NS_TEST_ASSERT_MSG_EQ (m_firstInterface[1], 4, "Dynamic global routing did not deliver all packets"); NS_TEST_ASSERT_MSG_EQ (m_secondInterface[2], 5, "Dynamic global routing did not deliver all packets"); NS_TEST_ASSERT_MSG_EQ (m_secondInterface[3], 5, "Dynamic global routing did not deliver all packets"); NS_TEST_ASSERT_MSG_EQ (m_firstInterface[4], 5, "Dynamic global routing did not deliver all packets"); NS_TEST_ASSERT_MSG_EQ (m_firstInterface[5], 5, "Dynamic global routing did not deliver all packets"); NS_TEST_ASSERT_MSG_EQ (m_secondInterface[6], 5, "Dynamic global routing did not deliver all packets"); NS_TEST_ASSERT_MSG_EQ (m_secondInterface[7], 5, "Dynamic global routing did not deliver all packets"); NS_TEST_ASSERT_MSG_EQ (m_firstInterface[8], 5, "Dynamic global routing did not deliver all packets"); NS_TEST_ASSERT_MSG_EQ (m_firstInterface[9], 5, "Dynamic global routing did not deliver all packets"); NS_TEST_ASSERT_MSG_EQ (m_firstInterface[10], 0, "Dynamic global routing did not deliver all packets"); NS_TEST_ASSERT_MSG_EQ (m_firstInterface[11], 4, "Dynamic global routing did not deliver all packets"); NS_TEST_ASSERT_MSG_EQ (m_secondInterface[12], 5, "Dynamic global routing did not deliver all packets"); NS_TEST_ASSERT_MSG_EQ (m_secondInterface[13], 5, "Dynamic global routing did not deliver all packets"); NS_TEST_ASSERT_MSG_EQ (m_firstInterface[14], 5, "Dynamic global routing did not deliver all packets"); NS_TEST_ASSERT_MSG_EQ (m_firstInterface[15], 5, "Dynamic global routing did not deliver all packets"); Simulator::Destroy (); }
int main (int argc, char *argv[]) { GlobalValue::Bind ("ChecksumEnabled", BooleanValue (true)); uint16_t sinkPort = 8000; uint32_t packetSize = 10000; // bytes std::string dataRate("10Mb/s"); NS_LOG_INFO ("Create Node"); NodeContainer nodes; nodes.Create (2); NS_LOG_INFO ("Create Device"); FdNetDeviceHelper fd; NetDeviceContainer devices = fd.Install (nodes); int sv[2]; if (socketpair (AF_UNIX, SOCK_DGRAM, 0, sv) < 0) { NS_FATAL_ERROR ("Error creating pipe=" << strerror (errno)); } Ptr<NetDevice> d1 = devices.Get (0); Ptr<FdNetDevice> clientDevice = d1->GetObject<FdNetDevice> (); clientDevice->SetFileDescriptor (sv[0]); Ptr<NetDevice> d2 = devices.Get (1); Ptr<FdNetDevice> serverDevice = d2->GetObject<FdNetDevice> (); serverDevice->SetFileDescriptor (sv[1]); NS_LOG_INFO ("Add Internet Stack"); InternetStackHelper internetStackHelper; internetStackHelper.SetIpv4StackInstall(true); internetStackHelper.Install (nodes); NS_LOG_INFO ("Create IPv4 Interface"); Ipv4AddressHelper addresses; addresses.SetBase ("10.0.0.0", "255.255.255.0"); Ipv4InterfaceContainer interfaces = addresses.Assign (devices); Ptr<Node> clientNode = nodes.Get (0); Ipv4Address serverIp = interfaces.GetAddress (1); Ptr<Node> serverNode = nodes.Get (1); // server Address sinkLocalAddress (InetSocketAddress (serverIp, sinkPort)); PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory", sinkLocalAddress); ApplicationContainer sinkApp = sinkHelper.Install (serverNode); sinkApp.Start (Seconds (0.0)); sinkApp.Stop (Seconds (30.0)); fd.EnablePcap ("fd2fd-onoff-server", serverDevice); // client AddressValue serverAddress (InetSocketAddress (serverIp, sinkPort)); OnOffHelper onoff ("ns3::TcpSocketFactory", Address ()); onoff.SetAttribute ("Remote", serverAddress); onoff.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]")); onoff.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]")); onoff.SetAttribute ("DataRate", DataRateValue (dataRate)); onoff.SetAttribute ("PacketSize", UintegerValue (packetSize)); ApplicationContainer clientApps = onoff.Install (clientNode); clientApps.Start (Seconds (2.0)); clientApps.Stop (Seconds (29.0)); fd.EnablePcap ("fd2fd-onoff-client", clientDevice); Simulator::Stop (Seconds (30.0)); Simulator::Run (); Simulator::Destroy (); }
int main(int argc, char* argv[]) { // setting default parameters for PointToPoint links and channels Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("10Mbps")); Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("1ms")); Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("100")); uint64_t catalogCardinality = 0; // Estimated Content Catalog Cardinality. double cacheToCatalogRatio = 0.01; // Cache to Catalog Ratio per each node. uint32_t lambda = 1; // Request rate per each client. double alpha = 1; // Zipf's Exponent double plateau = 0; // q parameter for the ZipfMandelbrot distribution std::string simType = ""; // Simulation Type Description uint32_t simDuration = 100; uint32_t numReqTot = 10000; // Total number of requests inside the simulation. // Read optional command-line parameters CommandLine cmd; cmd.AddValue ("catalogCardinality", "Estimated Content Catalog Cardinality.", catalogCardinality); cmd.AddValue ("cacheToCatalogRatio", "Cache to Catalog Ratio per each node.", cacheToCatalogRatio); cmd.AddValue ("lambda", "Request rate per each client.", lambda); cmd.AddValue ("alpha", "Zipf's Exponent", alpha); cmd.AddValue ("plateau", "q parameter for the ZipfMandelbrot distribution", plateau); cmd.AddValue ("simType", "Simulation Type Description", simType); cmd.AddValue ("simDuration", "Length of the simulation, in seconds.", simDuration); cmd.AddValue ("numReqTot", "Total number of requests during the simulation", numReqTot); cmd.Parse (argc, argv); std::string catalogCardinalityStr, lambdaStr, alphaStr, plateauStr,reqStr; std::stringstream ss; ss << catalogCardinality; catalogCardinalityStr = ss.str(); ss.str(""); ss << lambda; lambdaStr = ss.str(); ss.str(""); ss << alpha; alphaStr = ss.str(); ss.str(""); ss << plateau; plateauStr = ss.str(); ss.str(""); ss << numReqTot; reqStr = ss.str(); ss.str(""); // ********** Getting the simulation run ********** uint64_t simRun = SeedManager::GetRun(); uint64_t simRunOut = simRun - 1; std::string simRunStr; ss << simRun; simRunStr = ss.str(); ss.str(""); //NS_LOG_UNCOND("M=" << catalogCardinality << "\nC=" << cacheToCatalogRatio << "\nL=" << lambda // << "\nT=" << simType << "\nA=" << alpha << "\nR=" << simRun); // ********** Calculate the Cache Size per each cache *********** uint32_t cacheSize = round((double)catalogCardinality * cacheToCatalogRatio); ss << cacheSize; std::string cacheSizeStr = ss.str(); ss.str(""); // Creating nodes NodeContainer nodes; //nodes.Create(3); nodes.Create(1); // Connecting nodes using two links //PointToPointHelper p2p; //p2p.Install(nodes.Get(0), nodes.Get(1)); //p2p.Install(nodes.Get(1), nodes.Get(2)); // Install NDN stack on all nodes ndn::StackHelper ndnHelper; ndnHelper.SetDefaultRoutes(true); //ndnHelper.InstallAll(); //ndnHelper.SetOldContentStore("ns3::ndn::cs::Nocache"); //ndnHelper.Install(nodes.Get(0)); // Consumer //ndnHelper.Install(nodes.Get(2)); // Producer ndnHelper.SetOldContentStore("ns3::ndn::cs::Lru", "MaxSize", cacheSizeStr); //ndnHelper.Install(nodes.Get(1)); // Router ndnHelper.Install(nodes.Get(0)); // Router // Choosing forwarding strategy ndn::StrategyChoiceHelper::InstallAll("/prefix", "/localhost/nfd/strategy/broadcast"); // Installing applications // Consumer ndn::AppHelper consumerHelper("ns3::ndn::ConsumerZipfMandelbrot"); // Consumer will request /prefix/0, /prefix/1, ... consumerHelper.SetPrefix("/prefix"); consumerHelper.SetAttribute ("Frequency", StringValue(lambdaStr)); // lambda Interest per second consumerHelper.SetAttribute ("NumberOfContents", StringValue (catalogCardinalityStr)); consumerHelper.SetAttribute ("Randomize", StringValue ("exponential")); consumerHelper.SetAttribute ("q", StringValue (plateauStr)); // q paremeter consumerHelper.SetAttribute ("s", StringValue (alphaStr)); // Zipf's exponent consumerHelper.Install(nodes.Get(0)); // first node // Producer ndn::AppHelper producerHelper("ns3::ndn::Producer"); // Producer will reply to all requests starting with /prefix producerHelper.SetPrefix("/prefix"); producerHelper.SetAttribute("PayloadSize", StringValue("1024")); //producerHelper.Install(nodes.Get(2)); // last node producerHelper.Install(nodes.Get(0)); // last node Simulator::Stop (Seconds (simDuration)); Simulator::Run(); Simulator::Destroy(); return 0; }
int run(int argc, char* argv[]) { delayFile.open(DELAY_OUTPUT_FILE_NAME); // setting default parameters for PointToPoint links and channels Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1000Mbps")); Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms")); Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("4294967295")); // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize CommandLine cmd; cmd.Parse(argc, argv); // Creating nodes NodeContainer nodes; nodes.Create(NUM_OF_CONSUMERS + NUM_OF_ROUTERS + NUM_OF_PRODUCER); // Connecting nodes using two links // Connecting nodes using two links PointToPointHelper p2p; // Connecting consumers to edge routers int g = 0; for (int i = 0; i < GROUP_SIZE; i++, g++) p2p.Install (nodes.Get (g), nodes.Get (0 + NUM_OF_CONSUMERS)); // C0 <--> R0 for (int i = 0; i < GROUP_SIZE; i++, g++) p2p.Install (nodes.Get (g), nodes.Get (1 + NUM_OF_CONSUMERS)); // C1 <--> R1 for (int i = 0; i < GROUP_SIZE; i++, g++) p2p.Install (nodes.Get (g), nodes.Get (3 + NUM_OF_CONSUMERS)); // C2 <--> R3 for (int i = 0; i < GROUP_SIZE; i++, g++) p2p.Install (nodes.Get (g), nodes.Get (5 + NUM_OF_CONSUMERS)); // C3 <--> R5 for (int i = 0; i < GROUP_SIZE; i++, g++) p2p.Install (nodes.Get (g), nodes.Get (6 + NUM_OF_CONSUMERS)); // C4 <--> R6 for (int i = 0; i < GROUP_SIZE; i++, g++) p2p.Install (nodes.Get (g), nodes.Get (10 + NUM_OF_CONSUMERS)); // C5 <--> R10 for (int i = 0; i < GROUP_SIZE; i++, g++) p2p.Install (nodes.Get (g), nodes.Get (8 + NUM_OF_CONSUMERS)); // C6 <--> R8 for (int i = 0; i < GROUP_SIZE; i++, g++) p2p.Install (nodes.Get (g), nodes.Get (11 + NUM_OF_CONSUMERS)); // C7 <--> R11 for (int i = 0; i < GROUP_SIZE; i++, g++) p2p.Install (nodes.Get (g), nodes.Get (12 + NUM_OF_CONSUMERS)); // C8 <--> R12 for (int i = 0; i < GROUP_SIZE; i++, g++) p2p.Install (nodes.Get (g), nodes.Get (18 + NUM_OF_CONSUMERS)); // C9 <--> R18 for (int i = 0; i < GROUP_SIZE; i++, g++) p2p.Install (nodes.Get (g), nodes.Get (17 + NUM_OF_CONSUMERS)); // C10 <--> R17 for (int i = 0; i < GROUP_SIZE; i++, g++) p2p.Install (nodes.Get (g), nodes.Get (20 + NUM_OF_CONSUMERS)); // C11 <--> R20 for (int i = 0; i < GROUP_SIZE; i++, g++) p2p.Install (nodes.Get (g), nodes.Get (24 + NUM_OF_CONSUMERS)); // C12 <--> R24 for (int i = 0; i < GROUP_SIZE; i++, g++) p2p.Install (nodes.Get (g), nodes.Get (29 + NUM_OF_CONSUMERS)); // C13 <--> R2 for (int i = 0; i < GROUP_SIZE; i++, g++) p2p.Install (nodes.Get (g), nodes.Get (28 + NUM_OF_CONSUMERS)); // C14 <--> R28 for (int i = 0; i < GROUP_SIZE; i++, g++) p2p.Install (nodes.Get (g), nodes.Get (21 + NUM_OF_CONSUMERS)); // C15 <--> R21 // Connect routers p2p.Install (nodes.Get (0 + NUM_OF_CONSUMERS), nodes.Get (9 + NUM_OF_CONSUMERS)); // R0 <--> R9 p2p.Install (nodes.Get (1 + NUM_OF_CONSUMERS), nodes.Get (15 + NUM_OF_CONSUMERS)); // R1 <--> R15 p2p.Install (nodes.Get (2 + NUM_OF_CONSUMERS), nodes.Get (9 + NUM_OF_CONSUMERS)); // R2 <--> R9 p2p.Install (nodes.Get (3 + NUM_OF_CONSUMERS), nodes.Get (4 + NUM_OF_CONSUMERS)); // R3 <--> R4 p2p.Install (nodes.Get (4 + NUM_OF_CONSUMERS), nodes.Get (7 + NUM_OF_CONSUMERS)); // R4 <--> R7 p2p.Install (nodes.Get (4 + NUM_OF_CONSUMERS), nodes.Get (14 + NUM_OF_CONSUMERS)); // R4 <--> R14 p2p.Install (nodes.Get (4 + NUM_OF_CONSUMERS), nodes.Get (9 + NUM_OF_CONSUMERS)); // R4 <--> R9 p2p.Install (nodes.Get (4 + NUM_OF_CONSUMERS), nodes.Get (16 + NUM_OF_CONSUMERS)); // R4 <--> R16 p2p.Install (nodes.Get (4 + NUM_OF_CONSUMERS), nodes.Get (25 + NUM_OF_CONSUMERS)); // R4 <--> R25 p2p.Install (nodes.Get (5 + NUM_OF_CONSUMERS), nodes.Get (13 + NUM_OF_CONSUMERS)); // R5 <--> R13 p2p.Install (nodes.Get (6 + NUM_OF_CONSUMERS), nodes.Get (7 + NUM_OF_CONSUMERS)); // R6 <--> R7 p2p.Install (nodes.Get (7 + NUM_OF_CONSUMERS), nodes.Get (9 + NUM_OF_CONSUMERS)); // R7 <--> R9 p2p.Install (nodes.Get (7 + NUM_OF_CONSUMERS), nodes.Get (14 + NUM_OF_CONSUMERS)); // R7 <--> R14 p2p.Install (nodes.Get (7 + NUM_OF_CONSUMERS), nodes.Get (22 + NUM_OF_CONSUMERS)); // R7 <--> R22 p2p.Install (nodes.Get (7 + NUM_OF_CONSUMERS), nodes.Get (23 + NUM_OF_CONSUMERS)); // R7 <--> R23 p2p.Install (nodes.Get (8 + NUM_OF_CONSUMERS), nodes.Get (9 + NUM_OF_CONSUMERS)); // R8 <--> R9 p2p.Install (nodes.Get (9 + NUM_OF_CONSUMERS), nodes.Get (13 + NUM_OF_CONSUMERS)); // R9 <--> R13 p2p.Install (nodes.Get (9 + NUM_OF_CONSUMERS), nodes.Get (14 + NUM_OF_CONSUMERS)); // R9 <--> R14 p2p.Install (nodes.Get (9 + NUM_OF_CONSUMERS), nodes.Get (22 + NUM_OF_CONSUMERS)); // R9 <--> R22 p2p.Install (nodes.Get (9 + NUM_OF_CONSUMERS), nodes.Get (25 + NUM_OF_CONSUMERS)); // R9 <--> R25 p2p.Install (nodes.Get (9 + NUM_OF_CONSUMERS), nodes.Get (27 + NUM_OF_CONSUMERS)); // R9 <--> R27 p2p.Install (nodes.Get (10 + NUM_OF_CONSUMERS), nodes.Get (14 + NUM_OF_CONSUMERS)); // R10 <--> R14 p2p.Install (nodes.Get (11 + NUM_OF_CONSUMERS), nodes.Get (13 + NUM_OF_CONSUMERS)); // R11 <--> R13 p2p.Install (nodes.Get (12 + NUM_OF_CONSUMERS), nodes.Get (13 + NUM_OF_CONSUMERS)); // R12 <--> R13 p2p.Install (nodes.Get (13 + NUM_OF_CONSUMERS), nodes.Get (14 + NUM_OF_CONSUMERS)); // R13 <--> R14 p2p.Install (nodes.Get (13 + NUM_OF_CONSUMERS), nodes.Get (22 + NUM_OF_CONSUMERS)); // R13 <--> R22 p2p.Install (nodes.Get (13 + NUM_OF_CONSUMERS), nodes.Get (25 + NUM_OF_CONSUMERS)); // R13 <--> R25 p2p.Install (nodes.Get (13 + NUM_OF_CONSUMERS), nodes.Get (27 + NUM_OF_CONSUMERS)); // R13 <--> R27 p2p.Install (nodes.Get (14 + NUM_OF_CONSUMERS), nodes.Get (15 + NUM_OF_CONSUMERS)); // R14 <--> R15 p2p.Install (nodes.Get (14 + NUM_OF_CONSUMERS), nodes.Get (18 + NUM_OF_CONSUMERS)); // R14 <--> R18 p2p.Install (nodes.Get (14 + NUM_OF_CONSUMERS), nodes.Get (19 + NUM_OF_CONSUMERS)); // R14 <--> R19 p2p.Install (nodes.Get (15 + NUM_OF_CONSUMERS), nodes.Get (16 + NUM_OF_CONSUMERS)); // R15 <--> R16 p2p.Install (nodes.Get (15 + NUM_OF_CONSUMERS), nodes.Get (19 + NUM_OF_CONSUMERS)); // R15 <--> R19 p2p.Install (nodes.Get (15 + NUM_OF_CONSUMERS), nodes.Get (21 + NUM_OF_CONSUMERS)); // R15 <--> R21 p2p.Install (nodes.Get (15 + NUM_OF_CONSUMERS), nodes.Get (22 + NUM_OF_CONSUMERS)); // R15 <--> R22 p2p.Install (nodes.Get (15 + NUM_OF_CONSUMERS), nodes.Get (23 + NUM_OF_CONSUMERS)); // R15 <--> R23 p2p.Install (nodes.Get (15 + NUM_OF_CONSUMERS), nodes.Get (25 + NUM_OF_CONSUMERS)); // R15 <--> R25 p2p.Install (nodes.Get (15 + NUM_OF_CONSUMERS), nodes.Get (27 + NUM_OF_CONSUMERS)); // R15 <--> R27 p2p.Install (nodes.Get (16 + NUM_OF_CONSUMERS), nodes.Get (23 + NUM_OF_CONSUMERS)); // R16 <--> R23 p2p.Install (nodes.Get (16 + NUM_OF_CONSUMERS), nodes.Get (27 + NUM_OF_CONSUMERS)); // R16 <--> R27 p2p.Install (nodes.Get (17 + NUM_OF_CONSUMERS), nodes.Get (23 + NUM_OF_CONSUMERS)); // R17 <--> R23 // 18 done p2p.Install (nodes.Get (19 + NUM_OF_CONSUMERS), nodes.Get (22 + NUM_OF_CONSUMERS)); // R19 <--> R22 p2p.Install (nodes.Get (20 + NUM_OF_CONSUMERS), nodes.Get (25 + NUM_OF_CONSUMERS)); // R20 <--> R25 p2p.Install (nodes.Get (21 + NUM_OF_CONSUMERS), nodes.Get (22 + NUM_OF_CONSUMERS)); // R21 <--> R22 p2p.Install (nodes.Get (21 + NUM_OF_CONSUMERS), nodes.Get (27 + NUM_OF_CONSUMERS)); // R21 <--> R27 p2p.Install (nodes.Get (22 + NUM_OF_CONSUMERS), nodes.Get (23 + NUM_OF_CONSUMERS)); // R22 <--> R23 p2p.Install (nodes.Get (22 + NUM_OF_CONSUMERS), nodes.Get (28 + NUM_OF_CONSUMERS)); // R22 <--> R28 p2p.Install (nodes.Get (22 + NUM_OF_CONSUMERS), nodes.Get (29 + NUM_OF_CONSUMERS)); // R22 <--> R29 p2p.Install (nodes.Get (23 + NUM_OF_CONSUMERS), nodes.Get (24 + NUM_OF_CONSUMERS)); // R23 <--> R24 p2p.Install (nodes.Get (23 + NUM_OF_CONSUMERS), nodes.Get (25 + NUM_OF_CONSUMERS)); // R23 <--> R25 p2p.Install (nodes.Get (23 + NUM_OF_CONSUMERS), nodes.Get (27 + NUM_OF_CONSUMERS)); // R23 <--> R27 // 24 done // 25 done p2p.Install (nodes.Get (26 + NUM_OF_CONSUMERS), nodes.Get (27 + NUM_OF_CONSUMERS)); // R26 <--> R27 // 27 done // 28 done // 29 done // Connecting producer(s) int producerId = 0 + NUM_OF_CONSUMERS + NUM_OF_ROUTERS; p2p.Install (nodes.Get (producerId), nodes.Get (0 + NUM_OF_CONSUMERS)); // P0 <--> R0 // Install NDN stack without cache ndn::StackHelper ndnHelperNoCache; // ndnHelperNoCache.SetDefaultRoutes(true); ndnHelperNoCache.SetOldContentStore("ns3::ndn::cs::Nocache"); // no cache // Install on consumers for (int i = 0; i < NUM_OF_CONSUMERS; i++) { ndnHelperNoCache.Install(nodes.Get(i)); } // Install on producer(s) ndnHelperNoCache.Install(nodes.Get(0 + NUM_OF_CONSUMERS + NUM_OF_ROUTERS)); // Install NDN stack with cache ndn::StackHelper ndnHelperWithCache; // ndnHelperWithCache.SetDefaultRoutes(true); ndnHelperWithCache.SetOldContentStore("ns3::ndn::cs::Freshness::Lru", "MaxSize", "0"); // Install on routers for (int i = NUM_OF_CONSUMERS; i < NUM_OF_CONSUMERS + NUM_OF_ROUTERS; i++) { ndnHelperWithCache.InstallWithCallback(nodes.Get(i), (size_t)&ForwardingDelay, i, USE_PINT); } // Consumers ndn::AppHelper consumerHelperHonest("ns3::ndn::AccountingEncrConsumer"); // Consumer will request /prefix/A/0, /prefix/A/1, ... consumerHelperHonest.SetAttribute("Frequency", StringValue("1")); // 10 interests a second consumerHelperHonest.SetAttribute("Randomize", StringValue("uniform")); consumerHelperHonest.SetAttribute("StartSeq", IntegerValue(0)); for(int i=0; i < NUM_OF_CONSUMERS; i++) { consumerHelperHonest.SetPrefix("/prefix/A/" + std::to_string(i)); ApplicationContainer consumer = consumerHelperHonest.Install(nodes.Get(i)); consumer.Start(Seconds(0)); std::ostringstream node_id; node_id << i; Config::ConnectWithoutContext("/NodeList/" + node_id.str() + "/ApplicationList/0/ReceivedMeaningfulContent", MakeCallback(ReceivedMeaningfulContent)); } // Producer ndn::AppHelper producerHelper("ns3::ndn::AccountingEncrProducer"); // Producer will reply to all requests starting with /prefix/A. For /prefix/B we expect NACK producerHelper.SetPrefix("/prefix/A"); producerHelper.SetAttribute("PayloadSize", StringValue("1024")); producerHelper.Install(nodes.Get(producerId)); ndn::GlobalRoutingHelper ndnGlobalRoutingHelper; ndnGlobalRoutingHelper.Install(nodes); std::string prefix = "/prefix/A"; ndnGlobalRoutingHelper.AddOrigins(prefix, nodes.Get(producerId)); ndn::GlobalRoutingHelper::CalculateRoutes(); // Traces ndn::L3RateTracer::InstallAll(RATE_OUTPUT_FILE_NAME, Seconds(1.0)); Simulator::Stop(Seconds(SIMULATION_DURATION)); Simulator::Run(); Simulator::Destroy(); delayFile.close(); return 0; }
int main (int argc, char *argv[]) { uint32_t packetSize = 1000; // Application bytes per packet double interval = 1.0; // Time between events uint32_t generationSize = 3; // RLNC generation size double errorRateEncoderRecoder = 0.4; // Error rate for encoder-recoder link double errorRateRecoderDecoder = 0.2; // Error rate for recoder-decoder link bool recodingFlag = true; // Flag to control recoding Time interPacketInterval = Seconds (interval); CommandLine cmd; cmd.AddValue ("packetSize", "Size of application packet sent", packetSize); cmd.AddValue ("interval", "Interval (seconds) between packets", interval); cmd.AddValue ("generationSize", "Set the generation size to use", generationSize); cmd.AddValue ("errorRateEncoderRecoder", "Packet erasure rate for the encoder-recoder link", errorRateEncoderRecoder); cmd.AddValue ("errorRateRecoderDecoder", "Packet erasure rate for the recoder-decoder link", errorRateRecoderDecoder); cmd.AddValue ("recodingFlag", "Enable packet recoding", recodingFlag); cmd.Parse (argc, argv); Time::SetResolution (Time::NS); // Set the basic helper for a single link PointToPointHelper pointToPoint; // Create node containers NodeContainer nodes; nodes.Create (3); NodeContainer encoderRecoder = NodeContainer (nodes.Get (0), nodes.Get (1)); NodeContainer recoderDecoder = NodeContainer (nodes.Get (1), nodes.Get (2)); // Internet stack for the nodes InternetStackHelper internet; internet.Install (nodes); // Create net device containers NetDeviceContainer encoderRecoderDevs = pointToPoint.Install (encoderRecoder); NetDeviceContainer recoderDecoderDevs = pointToPoint.Install (recoderDecoder); NetDeviceContainer devices = NetDeviceContainer (encoderRecoderDevs, recoderDecoderDevs); // Set IP addresses Ipv4AddressHelper ipv4("10.1.1.0", "255.255.255.0"); ipv4.Assign (devices); // Turn on global static routing so we can actually be routed across the hops Ipv4GlobalRoutingHelper::PopulateRoutingTables (); // Do pcap tracing on all point-to-point devices on all nodes. File naming // convention is: multihop-[NODE_NUMBER]-[DEVICE_NUMBER].pcap pointToPoint.EnablePcapAll ("multihop"); // Set error model for the net devices Config::SetDefault ("ns3::RateErrorModel::ErrorUnit", StringValue ("ERROR_UNIT_PACKET")); Ptr<RateErrorModel> errorEncoderRecoder = CreateObject<RateErrorModel> (); errorEncoderRecoder->SetAttribute ("ErrorRate", DoubleValue (errorRateEncoderRecoder)); devices.Get (1)->SetAttribute ("ReceiveErrorModel", PointerValue (errorEncoderRecoder)); Ptr<RateErrorModel> errorRecoderDecoder = CreateObject<RateErrorModel> (); errorRecoderDecoder->SetAttribute ("ErrorRate", DoubleValue (errorRateRecoderDecoder)); devices.Get (3)->SetAttribute ("ReceiveErrorModel", PointerValue (errorRecoderDecoder)); errorEncoderRecoder->Enable (); errorRecoderDecoder->Enable (); // Creation of RLNC encoder and decoder objects rlnc_encoder::factory encoder_factory(generationSize, packetSize); rlnc_decoder::factory decoder_factory(generationSize, packetSize); // The member build function creates differents instances of each object KodoSimulation kodoSimulator(encoder_factory.build(), decoder_factory.build(), decoder_factory.build(), recodingFlag); // Setting up application sockets for recoder and decoder uint16_t port = 80; TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory"); // Get node Ipv4 addresses Ipv4Address recoderAddress = nodes.Get (1)->GetObject<Ipv4>()-> GetAddress(1,0).GetLocal(); Ipv4Address decoderAddress = nodes.Get (2)->GetObject<Ipv4>()-> GetAddress(1,0).GetLocal(); // Socket connection addresses InetSocketAddress recoderSocketAddress = InetSocketAddress (recoderAddress, port); InetSocketAddress decoderSocketAddress = InetSocketAddress (decoderAddress, port); // Socket bind address InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny(), port); // Encoder Ptr<Socket> encoderSocket = Socket::CreateSocket (nodes.Get (0), tid); encoderSocket->Connect (recoderSocketAddress); // Recoder Ptr<Socket> recoderSocket = Socket::CreateSocket (nodes.Get (1), tid); recoderSocket->Bind(local); recoderSocket->Connect (decoderSocketAddress); recoderSocket-> SetRecvCallback (MakeCallback (&KodoSimulation::ReceivePacketRecoder, &kodoSimulator)); // Decoder Ptr<Socket> decoderSocket = Socket::CreateSocket (nodes.Get (2), tid); decoderSocket->Bind(local); decoderSocket-> SetRecvCallback (MakeCallback (&KodoSimulation::ReceivePacketDecoder, &kodoSimulator)); // Simulation setup // Schedule encoding process Simulator::ScheduleWithContext (encoderSocket->GetNode ()->GetId (), Seconds (1.0), &KodoSimulation::SendPacketEncoder, &kodoSimulator, encoderSocket, interPacketInterval); Simulator::ScheduleWithContext (recoderSocket->GetNode ()->GetId (), Seconds (1.5), &KodoSimulation::SendPacketRecoder, &kodoSimulator, recoderSocket, interPacketInterval); Simulator::Run (); Simulator::Destroy (); return 0; }
int main(int argc, char* argv[]) { AnnotatedTopologyReader topologyReader("", 1); topologyReader.SetFileName("src/ndnSIM/examples/topologies/Geant2012.txt"); topologyReader.Read(); // 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")); // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize CommandLine cmd; cmd.Parse(argc, argv); // Creating nodes NodeContainer nodes; size_t nNode=3; nodes.Create(nNode); // Connecting nodes using two links PointToPointHelper p2p; p2p.Install(nodes.Get(0), nodes.Get(1)); p2p.Install(nodes.Get(1), nodes.Get(2)); // Install NDN stack on all nodes ndn::StackHelper ndnHelper; //ndnHelper.SetDefaultRoutes(true); ndnHelper.disableRibManager(); //ndnHelper.disableFaceManager(); ndnHelper.InstallAll(); // Choosing forwarding strategy ndn::StrategyChoiceHelper::InstallAll("/cs-www.bu.edu/", "/localhost/nfd/strategy/multicast"); // Installing applications // Consumer ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr"); ifstream inFile("URLs.con2.cs18.800051214"); string line; if (inFile.is_open()) { //NS_LOG_UNCOND ("salam!"); while(getline (inFile,line)) { consumerHelper.SetPrefix(line); //NS_LOG_UNCOND ("file line = "<<line); consumerHelper.SetAttribute("Frequency", StringValue("1")); // 1 interests a second consumerHelper.Install(nodes.Get(0)).Start (Seconds(2)); } } inFile.close(); // Producer ndn::AppHelper producerHelper("ns3::ndn::Producer"); // Producer will reply to all requests starting with /videos/myvideos/video1 producerHelper.SetPrefix("/cs-www.bu.edu/"); producerHelper.SetAttribute("PayloadSize", StringValue("1024")); producerHelper.Install(nodes.Get(2)).Start (Seconds(0.0)); // last node // Choosing forwarding strategy for content adverts ndn::StrategyChoiceHelper::InstallAll("/ContentAdVert/", "/localhost/nfd/strategy/multicast"); //install advertiser app on the server consumerHelper.SetPrefix ("/ContentAdVert/cs-www.bu.edu/"); consumerHelper.SetAttribute("Frequency", StringValue("0.2")); // 1 advert per 5 second consumerHelper.Install(nodes.Get(2)).Start (Seconds(0.0)); Simulator::Stop(Seconds(10.0)); Simulator::Run(); Simulator::Destroy(); return 0; }
int main (int argc, char *argv[]) { // // Users may find it convenient to turn on explicit debugging // for selected modules; the below lines suggest how to do this // #if 0 LogComponentEnable ("UdpEchoExample", LOG_LEVEL_INFO); LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_ALL); LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_ALL); #endif // // Allow the user to override any of the defaults and the above Bind() at // run-time, via command-line arguments // bool useV6 = false; Address serverAddress; CommandLine cmd; cmd.AddValue ("useIpv6", "Use Ipv6", useV6); cmd.Parse (argc, argv); // // Explicitly create the nodes required by the topology (shown above). // NS_LOG_INFO ("Create nodes."); NodeContainer n; n.Create (4); InternetStackHelper internet; internet.Install (n); NS_LOG_INFO ("Create channels."); // // Explicitly create the channels required by the topology (shown above). // CsmaHelper csma; csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate (5000000))); csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2))); csma.SetDeviceAttribute ("Mtu", UintegerValue (1400)); NetDeviceContainer d = csma.Install (n); // // We've got the "hardware" in place. Now we need to add IP addresses. // NS_LOG_INFO ("Assign IP Addresses."); if (useV6 == false) { Ipv4AddressHelper ipv4; ipv4.SetBase ("10.1.1.0", "255.255.255.0"); Ipv4InterfaceContainer i = ipv4.Assign (d); serverAddress = Address(i.GetAddress (1)); } else { Ipv6AddressHelper ipv6; ipv6.SetBase ("2001:0000:f00d:cafe::", Ipv6Prefix (64)); Ipv6InterfaceContainer i6 = ipv6.Assign (d); serverAddress = Address(i6.GetAddress (1,1)); } NS_LOG_INFO ("Create Applications."); // // Create a UdpEchoServer application on node one. // uint16_t port = 9; // well-known echo port number UdpEchoServerHelper server (port); ApplicationContainer apps = server.Install (n.Get (1)); apps.Start (Seconds (1.0)); apps.Stop (Seconds (10.0)); // // Create a UdpEchoClient application to send UDP datagrams from node zero to // node one. // uint32_t packetSize = 1024; uint32_t maxPacketCount = 1; Time interPacketInterval = Seconds (1.); UdpEchoClientHelper client (serverAddress, port); client.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount)); client.SetAttribute ("Interval", TimeValue (interPacketInterval)); client.SetAttribute ("PacketSize", UintegerValue (packetSize)); apps = client.Install (n.Get (0)); apps.Start (Seconds (2.0)); apps.Stop (Seconds (10.0)); #if 0 // // Users may find it convenient to initialize echo packets with actual data; // the below lines suggest how to do this // client.SetFill (apps.Get (0), "Hello World"); client.SetFill (apps.Get (0), 0xa5, 1024); uint8_t fill[] = { 0, 1, 2, 3, 4, 5, 6}; client.SetFill (apps.Get (0), fill, sizeof(fill), 1024); #endif AsciiTraceHelper ascii; csma.EnableAsciiAll (ascii.CreateFileStream ("udp-echo.tr")); csma.EnablePcapAll ("udp-echo", false); // // Now, do the actual simulation. // NS_LOG_INFO ("Run Simulation."); Simulator::Run (); Simulator::Destroy (); NS_LOG_INFO ("Done."); }
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; }
int main(int argc, char* argv[]) { // setting default parameters for PointToPoint links and channels Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("10Mbps")); Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms")); Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("20")); // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize CommandLine cmd; cmd.Parse(argc, argv); // Creating nodes NodeContainer nodes; nodes.Create(3); // 3 nodes, connected: 0 <---> 1 <---> 2 // Connecting nodes using two links PointToPointHelper p2p; p2p.Install(nodes.Get(0), nodes.Get(1)); p2p.Install(nodes.Get(1), nodes.Get(2)); // Install NDN stack on all nodes ndn::StackHelper ndnHelper; ndnHelper.SetDefaultRoutes(true); ndnHelper.setCsSize(0); ndnHelper.SetOldContentStore("ns3::ndn::cs::Lru", "MaxSize", "100"); ndnHelper.InstallAll(); // Choosing forwarding strategy ndn::StrategyChoiceHelper::InstallAll("/myprefix", "/localhost/nfd/strategy/best-route"); ns3::ndn::AppHelper consumerHelper("ns3::ndn::FileConsumerCbr::MultimediaConsumer"); consumerHelper.SetAttribute("AllowUpscale", BooleanValue(true)); consumerHelper.SetAttribute("AllowDownscale", BooleanValue(false)); consumerHelper.SetAttribute("ScreenWidth", UintegerValue(1920)); consumerHelper.SetAttribute("ScreenHeight", UintegerValue(1080)); consumerHelper.SetAttribute("StartRepresentationId", StringValue("auto")); consumerHelper.SetAttribute("MaxBufferedSeconds", UintegerValue(30)); consumerHelper.SetAttribute("StartUpDelay", StringValue("0.1")); consumerHelper.SetAttribute("AdaptationLogic", StringValue("dash::player::RateAndBufferBasedAdaptationLogic")); consumerHelper.SetAttribute("MpdFileToRequest", StringValue(std::string("/myprefix/AVC/BBB-2s.mpd" ))); //consumerHelper.SetPrefix (std::string("/Server_" + boost::lexical_cast<std::string>(i%server.size ()) + "/layer0")); ApplicationContainer app1 = consumerHelper.Install (nodes.Get(2)); // Producer responsible for hosting the MPD file ndn::AppHelper mpdProducerHelper("ns3::ndn::FileServer"); // Producer will reply to all requests starting with /myprefix/AVC/ and hosts the mpd file there mpdProducerHelper.SetPrefix("/myprefix"); mpdProducerHelper.SetAttribute("ContentDirectory", StringValue("/home/someuser/multimediaData")); mpdProducerHelper.Install(nodes.Get(0)); // install to some node from nodelist // Producer responsible for hosting the virtual segments ndn::AppHelper fakeSegmentProducerHelper("ns3::ndn::FakeFileServer"); // Producer will reply to all requests starting with /myprefix/AVC/BBB/ and hosts the virtual segment files there fakeSegmentProducerHelper.SetPrefix("/myprefix/AVC/BBB"); fakeSegmentProducerHelper.SetAttribute("MetaDataFile", StringValue("dash_dataset_avc_bbb.csv")); fakeSegmentProducerHelper.Install(nodes.Get(0)); // install to some node from nodelist ndn::GlobalRoutingHelper ndnGlobalRoutingHelper; ndnGlobalRoutingHelper.InstallAll(); ndnGlobalRoutingHelper.AddOrigins("/myprefix", nodes.Get(0)); ndn::GlobalRoutingHelper::CalculateRoutes(); Simulator::Stop(Seconds(1000.0)); Simulator::Run(); Simulator::Destroy(); NS_LOG_UNCOND("Simulation Finished."); return 0; }
int main (int argc, char *argv[]) { // Users may find it convenient to turn on explicit debugging // for selected modules; the below lines suggest how to do this #if 0 LogComponentEnable ("SimpleGlobalRoutingExample", LOG_LEVEL_INFO); #endif // Set up some default values for the simulation. Use the Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210)); Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("448kb/s")); //DefaultValue::Bind ("DropTailQueue::m_maxPackets", 30); // Allow the user to override any of the defaults and the above // DefaultValue::Bind ()s at run-time, via command-line arguments CommandLine cmd; cmd.Parse (argc, argv); // Here, we will explicitly create four nodes. In more sophisticated // topologies, we could configure a node factory. NS_LOG_INFO ("Create nodes."); NodeContainer c; c.Create (5); NodeContainer n02 = NodeContainer (c.Get (0), c.Get (2)); NodeContainer n12 = NodeContainer (c.Get (1), c.Get (2)); NodeContainer n32 = NodeContainer (c.Get (3), c.Get (2)); NodeContainer n34 = NodeContainer (c.Get (3), c.Get (4)); // Enable OLSR NS_LOG_INFO ("Enabling OLSR Routing."); 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); // We create the channels first without any IP addressing information NS_LOG_INFO ("Create channels."); PointToPointHelper p2p; p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); p2p.SetChannelAttribute ("Delay", StringValue ("2ms")); NetDeviceContainer nd02 = p2p.Install (n02); NetDeviceContainer nd12 = p2p.Install (n12); p2p.SetDeviceAttribute ("DataRate", StringValue ("1500kbps")); p2p.SetChannelAttribute ("Delay", StringValue ("10ms")); NetDeviceContainer nd32 = p2p.Install (n32); NetDeviceContainer nd34 = p2p.Install (n34); // Later, we add IP addresses. NS_LOG_INFO ("Assign IP Addresses."); Ipv4AddressHelper ipv4; ipv4.SetBase ("10.1.1.0", "255.255.255.0"); Ipv4InterfaceContainer i02 = ipv4.Assign (nd02); ipv4.SetBase ("10.1.2.0", "255.255.255.0"); Ipv4InterfaceContainer i12 = ipv4.Assign (nd12); ipv4.SetBase ("10.1.3.0", "255.255.255.0"); Ipv4InterfaceContainer i32 = ipv4.Assign (nd32); ipv4.SetBase ("10.1.4.0", "255.255.255.0"); Ipv4InterfaceContainer i34 = ipv4.Assign (nd34); // Create the OnOff application to send UDP datagrams of size // 210 bytes at a rate of 448 Kb/s from n0 to n4 NS_LOG_INFO ("Create Applications."); uint16_t port = 9; // Discard port (RFC 863) OnOffHelper onoff ("ns3::UdpSocketFactory", InetSocketAddress (i34.GetAddress (1), port)); onoff.SetConstantRate (DataRate ("448kb/s")); ApplicationContainer apps = onoff.Install (c.Get (0)); apps.Start (Seconds (1.0)); apps.Stop (Seconds (10.0)); // Create a packet sink to receive these packets PacketSinkHelper sink ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), port)); apps = sink.Install (c.Get (3)); apps.Start (Seconds (1.0)); apps.Stop (Seconds (10.0)); // Create a similar flow from n3 to n1, starting at time 1.1 seconds onoff.SetAttribute ("Remote", AddressValue (InetSocketAddress (i12.GetAddress (0), port))); apps = onoff.Install (c.Get (3)); apps.Start (Seconds (1.1)); apps.Stop (Seconds (10.0)); // Create a packet sink to receive these packets apps = sink.Install (c.Get (1)); apps.Start (Seconds (1.1)); apps.Stop (Seconds (10.0)); AsciiTraceHelper ascii; p2p.EnableAsciiAll (ascii.CreateFileStream ("simple-point-to-point-olsr.tr")); p2p.EnablePcapAll ("simple-point-to-point-olsr"); Simulator::Stop (Seconds (30)); NS_LOG_INFO ("Run Simulation."); Simulator::Run (); Simulator::Destroy (); NS_LOG_INFO ("Done."); return 0; }