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; }
Ipv4InterfaceContainer Ipv4AddressHelper::Assign (const NetDeviceContainer &c) { NS_LOG_FUNCTION_NOARGS (); Ipv4InterfaceContainer retval; for (uint32_t i = 0; i < c.GetN (); ++i) { Ptr<NetDevice> device = c.Get (i); Ptr<Node> node = device->GetNode (); NS_ASSERT_MSG (node, "Ipv4AddressHelper::Assign(): NetDevice is not not associated " "with any node -> fail"); Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); NS_ASSERT_MSG (ipv4, "Ipv4AddressHelper::Assign(): NetDevice is associated" " with a node without IPv4 stack installed -> fail " "(maybe need to use InternetStackHelper?)"); int32_t interface = ipv4->GetInterfaceForDevice (device); if (interface == -1) { interface = ipv4->AddInterface (device); } NS_ASSERT_MSG (interface >= 0, "Ipv4AddressHelper::Assign(): " "Interface index not found"); Ipv4InterfaceAddress ipv4Addr = Ipv4InterfaceAddress (NewAddress (), m_mask); ipv4->AddAddress (interface, ipv4Addr); ipv4->SetMetric (interface, 1); ipv4->SetUp (interface); retval.Add (ipv4, interface); } return retval; }
// // 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; }
void AodvExample::InstallApplications () { V4PingHelper ping (interfaces.GetAddress (size - 1)); ping.SetAttribute ("Verbose", BooleanValue (true)); ApplicationContainer p = ping.Install (nodes.Get (0)); p.Start (Seconds (0)); p.Stop (Seconds (totalTime) - Seconds (0.001)); // move node away Ptr<Node> node = nodes.Get (size/2); Ptr<MobilityModel> mob = node->GetObject<MobilityModel> (); Simulator::Schedule (Seconds (totalTime/3), &MobilityModel::SetPosition, mob, Vector (1e5, 1e5, 1e5)); }
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 (); }
void Ns3TcpNoDelayTestCase::DoRun (void) { uint16_t sinkPort = 50000; double sinkStopTime = 8; // sec; will trigger Socket::Close double writerStopTime = 5; // sec; will trigger Socket::Close double simStopTime = 10; // sec Time sinkStopTimeObj = Seconds (sinkStopTime); Time writerStopTimeObj = Seconds (writerStopTime); Time simStopTimeObj= Seconds (simStopTime); Ptr<Node> n0 = CreateObject<Node> (); Ptr<Node> n1 = CreateObject<Node> (); PointToPointHelper pointToPoint; pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms")); NetDeviceContainer devices; devices = pointToPoint.Install (n0, n1); InternetStackHelper internet; internet.InstallAll (); Ipv4AddressHelper address; address.SetBase ("10.1.1.0", "255.255.255.252"); Ipv4InterfaceContainer ifContainer = address.Assign (devices); Ptr<SocketWriter> socketWriter = CreateObject<SocketWriter> (); Address sinkAddress (InetSocketAddress (ifContainer.GetAddress (1), sinkPort)); socketWriter->Setup (n0, sinkAddress); n0->AddApplication (socketWriter); socketWriter->SetStartTime (Seconds (0.)); socketWriter->SetStopTime (writerStopTimeObj); PacketSinkHelper sink ("ns3::TcpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), sinkPort)); ApplicationContainer apps = sink.Install (n1); // Start the sink application at time zero, and stop it at sinkStopTime apps.Start (Seconds (0.0)); apps.Stop (sinkStopTimeObj); Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::PacketSink/Rx", MakeCallback (&Ns3TcpNoDelayTestCase::SinkRx, this)); // Enable or disable TCP no delay option Config::SetDefault ("ns3::TcpSocket::TcpNoDelay", BooleanValue (m_noDelay)); // Connect the socket writer Simulator::Schedule (Seconds (1), &SocketWriter::Connect, socketWriter); // Write 5 packets to get some bytes in flight and some acks going Simulator::Schedule (Seconds (2), &SocketWriter::Write, socketWriter, 2680); m_inputs.Add (536); m_inputs.Add (536); m_inputs.Add (536); m_inputs.Add (536); m_inputs.Add (536); // Write one byte after 10 ms to ensure that some data is outstanding // and the window is big enough Simulator::Schedule (Seconds (2.010), &SocketWriter::Write, socketWriter, 1); // If Nagle is not enabled, i.e. no delay is on, add an input for a 1-byte // packet to be received if (m_noDelay) { m_inputs.Add (1); } // One ms later, write 535 bytes, i.e. one segment size - 1 Simulator::Schedule (Seconds (2.012), &SocketWriter::Write, socketWriter, 535); // If Nagle is not enabled, add an input for a 535 byte packet, // otherwise, we should get a single "full" packet of 536 bytes if (m_noDelay) { m_inputs.Add (535); } else { m_inputs.Add (536); } // Close down the socket Simulator::Schedule (writerStopTimeObj, &SocketWriter::Close, socketWriter); if (m_writeResults) { std::ostringstream oss; if (m_noDelay) { oss << "tcp-no-delay-on-test-case"; pointToPoint.EnablePcapAll (oss.str ()); } else { oss << "tcp-no-delay-off-test-case"; pointToPoint.EnablePcapAll (oss.str ()); } } Simulator::Stop (simStopTimeObj); Simulator::Run (); Simulator::Destroy (); // Compare inputs and outputs NS_TEST_ASSERT_MSG_EQ (m_inputs.GetN (), m_responses.GetN (), "Incorrect number of expected receive events"); for (uint32_t i = 0; i < m_responses.GetN (); i++) { uint32_t in = m_inputs.Get (i); uint32_t out = m_responses.Get (i); NS_TEST_ASSERT_MSG_EQ (in, out, "Mismatch: expected " << in << " bytes, got " << out << " bytes"); } }
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."); }
// Network topology // // n0 n1 n2 n3 // | | | | // ================= // LAN // // - CBR/UDP flows from n0 to n1 and from n3 to n0 // - DropTail queues // void CsmaOneSubnetTestCase::DoRun (void) { NodeContainer nodes; nodes.Create (4); CsmaHelper csma; csma.SetChannelAttribute ("DataRate", DataRateValue (5000000)); csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2))); // // Now fill out the topology by creating the net devices required to connect // the nodes to the channels and hooking them up. // NetDeviceContainer devices = csma.Install (nodes); InternetStackHelper internet; internet.Install (nodes); // We've got the "hardware" in place. Now we need to add IP addresses. // Ipv4AddressHelper ipv4; ipv4.SetBase ("10.1.1.0", "255.255.255.0"); Ipv4InterfaceContainer interfaces = ipv4.Assign (devices); uint16_t port = 9; // Discard port (RFC 863) // // Create an OnOff application to send UDP datagrams from node zero // to node 1. // // Make packets be sent about every defaultPacketSize / dataRate = // 4096 bits / (5000 bits/second) = 0.82 second. OnOffHelper onoff ("ns3::UdpSocketFactory", Address (InetSocketAddress (interfaces.GetAddress (1), port))); onoff.SetConstantRate (DataRate (5000)); ApplicationContainer app = onoff.Install (nodes.Get (0)); // Start the application app.Start (Seconds (1.0)); app.Stop (Seconds (10.0)); // Create an optional packet sink to receive these packets PacketSinkHelper sink ("ns3::UdpSocketFactory", Address (InetSocketAddress (Ipv4Address::GetAny (), port))); app = sink.Install (nodes.Get (1)); app.Start (Seconds (0.0)); // // Create a similar flow from n3 to n0, starting at time 1.1 seconds // onoff.SetAttribute ("Remote", AddressValue (InetSocketAddress (interfaces.GetAddress (0), port))); app = onoff.Install (nodes.Get (3)); app.Start (Seconds (1.1)); app.Stop (Seconds (10.0)); app = sink.Install (nodes.Get (0)); app.Start (Seconds (0.0)); // Trace receptions Config::ConnectWithoutContext ("/NodeList/0/ApplicationList/1/$ns3::PacketSink/Rx", MakeCallback (&CsmaOneSubnetTestCase::SinkRxNode0, this)); Config::ConnectWithoutContext ("/NodeList/1/ApplicationList/0/$ns3::PacketSink/Rx", MakeCallback (&CsmaOneSubnetTestCase::SinkRxNode1, this)); // // Now, do the actual simulation. // Simulator::Run (); Simulator::Destroy (); // We should have sent and received 10 packets NS_TEST_ASSERT_MSG_EQ (m_countNode0, 10, "Node 0 should have received 10 packets"); NS_TEST_ASSERT_MSG_EQ (m_countNode1, 10, "Node 1 should have received 10 packets"); }
void part2() { cout << "Seting up Part B with C" << endl; string rateHR = "100Mbps"; //data rate b/w hosts and routers string latencyHR = "20ms"; //latency b/w hosts and routers string rateRR = "10Mbps"; //data rate b/w routers string latencyRR = "50ms"; //latenc b/w routers uint32_t packetSize = 1.2*1024; //1.2KB uint32_t queueSizeHR = (100000*20)/packetSize; //100Mbps uint32_t queueSizeRR = (10000*50)/packetSize; //10Mbps uint32_t numSender = 3; double errorP = 0.000001; Config::SetDefault("ns3::DropTailQueue::Mode", StringValue("QUEUE_MODE_PACKETS")); //Creating channel without IP address PointToPointHelper p2pHR, p2pRR; p2pHR.SetDeviceAttribute("DataRate", StringValue(rateHR)); p2pHR.SetChannelAttribute("Delay", StringValue(latencyHR)); p2pHR.SetQueue("ns3::DropTailQueue", "MaxPackets", UintegerValue(queueSizeHR)); p2pRR.SetDeviceAttribute("DataRate", StringValue(rateRR)); p2pRR.SetChannelAttribute("Delay", StringValue(latencyRR)); p2pRR.SetQueue("ns3::DropTailQueue", "MaxPackets", UintegerValue(queueSizeRR)); //Adding some errorrate Ptr<RateErrorModel> em = CreateObjectWithAttributes<RateErrorModel> ("ErrorRate", DoubleValue (errorP)); //create nodes(routers, senders and recievers) NodeContainer routers, senders, recievers; routers.Create(2); senders.Create(numSender); recievers.Create(numSender); NetDeviceContainer routerDevices = p2pRR.Install(routers); NetDeviceContainer leftRouterDevices, rightRouterDevices, senderDevices, recieverDevices; //Adding links for(uint32_t i = 0; i < numSender; ++i) { NetDeviceContainer cleft = p2pHR.Install(routers.Get(0), senders.Get(i)); leftRouterDevices.Add(cleft.Get(0)); senderDevices.Add(cleft.Get(1)); cleft.Get(0)->SetAttribute("ReceiveErrorModel", PointerValue(em)); NetDeviceContainer cright = p2pHR.Install(routers.Get(1), recievers.Get(i)); rightRouterDevices.Add(cright.Get(0)); recieverDevices.Add(cright.Get(1)); cright.Get(0)->SetAttribute("ReceiveErrorModel", PointerValue(em)); } //Install Internet Stack InternetStackHelper stack; stack.Install(routers); stack.Install(senders); stack.Install(recievers); //Adding IP addresses Ipv4AddressHelper routerIP = Ipv4AddressHelper("10.3.0.0", "255.255.255.0"); Ipv4AddressHelper senderIP = Ipv4AddressHelper("10.1.0.0", "255.255.255.0"); Ipv4AddressHelper recieverIP = Ipv4AddressHelper("10.2.0.0", "255.255.255.0"); Ipv4InterfaceContainer routerIFC, senderIFCs, recieverIFCs, leftRouterIFCs, rightRouterIFCs; routerIFC = routerIP.Assign(routerDevices); for(uint32_t i = 0; i < numSender; ++i) { NetDeviceContainer senderDevice; senderDevice.Add(senderDevices.Get(i)); senderDevice.Add(leftRouterDevices.Get(i)); Ipv4InterfaceContainer senderIFC = senderIP.Assign(senderDevice); senderIFCs.Add(senderIFC.Get(0)); leftRouterIFCs.Add(senderIFC.Get(1)); senderIP.NewNetwork(); NetDeviceContainer recieverDevice; recieverDevice.Add(recieverDevices.Get(i)); recieverDevice.Add(rightRouterDevices.Get(i)); Ipv4InterfaceContainer recieverIFC = recieverIP.Assign(recieverDevice); recieverIFCs.Add(recieverIFC.Get(0)); rightRouterIFCs.Add(recieverIFC.Get(1)); recieverIP.NewNetwork(); } /******************************************************************** PART (2) start 2 other flows while one is progress -> measure throughput and CWND of each flow at steady state -> Also find the max throuhput per flow ********************************************************************/ cout << "Part B Starting" << endl; double durationGap = 100; double oneFlowStart = 0; double otherFlowStart = 20; uint32_t port = 9000; uint32_t numPackets = 10000000; string transferSpeed = "400Mbps"; //TCP Reno from H1 to H4 cout << "Flow from H1 -> H4 : TcpReno" << endl; cout << "Writing to app6_h1_h4_b.cwnd (congestion window) and app6_h1_h4_b.tp (throughput)" << endl; AsciiTraceHelper asciiTraceHelper; Ptr<OutputStreamWrapper> stream1CWND = asciiTraceHelper.CreateFileStream("app6_h1_h4_b.cwnd"); Ptr<OutputStreamWrapper> stream1PD = asciiTraceHelper.CreateFileStream("app6_h1_h4_b.congestion_loss"); Ptr<OutputStreamWrapper> stream1TP = asciiTraceHelper.CreateFileStream("app6_h1_h4_b.tp"); Ptr<OutputStreamWrapper> stream1GP = asciiTraceHelper.CreateFileStream("app6_h1_h4_b.gp"); Ptr<Socket> ns3TcpSocket1 = uniFlow(InetSocketAddress(recieverIFCs.GetAddress(0), port), port, "TcpReno", senders.Get(0), recievers.Get(0), oneFlowStart, oneFlowStart+durationGap, packetSize, numPackets, transferSpeed, oneFlowStart, oneFlowStart+durationGap); ns3TcpSocket1->TraceConnectWithoutContext("CongestionWindow", MakeBoundCallback (&CwndChange, stream1CWND, 0)); ns3TcpSocket1->TraceConnectWithoutContext("Drop", MakeBoundCallback (&packetDrop, stream1PD, 0, 1)); std::string sink_ = "/NodeList/5/ApplicationList/0/$ns3::PacketSink/Rx"; Config::Connect(sink_, MakeBoundCallback(&ReceivedPacket, stream1TP, oneFlowStart)); std::string sink = "/NodeList/5/ApplicationList/0/$ns3::PacketSink/Rx"; Config::Connect(sink, MakeBoundCallback(&ReceivedPacket, stream1GP, 0)); //TCP Tahoe from H2 to H5 cout << "Flow from H2 -> H5 : TcpTahoe" << endl; cout << "Writing to app6_h2_h5_b.cwnd (congestion window) and app6_h2_h5_b.tp (throughput)" << endl; Ptr<OutputStreamWrapper> stream2CWND = asciiTraceHelper.CreateFileStream("app6_h2_h5_b.cwnd"); Ptr<OutputStreamWrapper> stream2PD = asciiTraceHelper.CreateFileStream("app6_h2_h5_b.congestion_loss"); Ptr<OutputStreamWrapper> stream2TP = asciiTraceHelper.CreateFileStream("app6_h2_h5_b.tp"); Ptr<OutputStreamWrapper> stream2GP = asciiTraceHelper.CreateFileStream("app6_h2_h5_b.gp"); Ptr<Socket> ns3TcpSocket2 = uniFlow(InetSocketAddress(recieverIFCs.GetAddress(1), port), port, "TcpTahoe", senders.Get(1), recievers.Get(1), otherFlowStart, otherFlowStart+durationGap, packetSize, numPackets, transferSpeed, otherFlowStart, otherFlowStart+durationGap); ns3TcpSocket2->TraceConnectWithoutContext("CongestionWindow", MakeBoundCallback (&CwndChange, stream2CWND, 0)); ns3TcpSocket2->TraceConnectWithoutContext("Drop", MakeBoundCallback (&packetDrop, stream2PD, 0, 2)); sink_ = "/NodeList/6/ApplicationList/0/$ns3::PacketSink/Rx"; Config::Connect(sink_, MakeBoundCallback(&ReceivedPacket, stream2TP, otherFlowStart)); sink = "/NodeList/6/ApplicationList/0/$ns3::PacketSink/Rx"; Config::Connect(sink, MakeBoundCallback(&ReceivedPacket, stream2GP, 0)); //TCP WestWood from H3 to H6 cout << "Flow from H3 -> H6 : TcpWestwood" << endl; cout << "Writing to app6_h3_h6_b.cwnd (congestion window) and app6_h3_h6_b.tp (throughput)" << endl; Ptr<OutputStreamWrapper> stream3CWND = asciiTraceHelper.CreateFileStream("app6_h3_h6_b.cwnd"); Ptr<OutputStreamWrapper> stream3PD = asciiTraceHelper.CreateFileStream("app6_h3_h6_b.congestion_loss"); Ptr<OutputStreamWrapper> stream3TP = asciiTraceHelper.CreateFileStream("app6_h3_h6_b.tp"); Ptr<OutputStreamWrapper> stream3GP = asciiTraceHelper.CreateFileStream("app6_h3_h6_b.gp"); Ptr<Socket> ns3TcpSocket3 = uniFlow(InetSocketAddress(recieverIFCs.GetAddress(2), port), port, "TcpWestwood", senders.Get(2), recievers.Get(2), otherFlowStart, otherFlowStart+durationGap, packetSize, numPackets, transferSpeed, otherFlowStart, otherFlowStart+durationGap); ns3TcpSocket3->TraceConnectWithoutContext("CongestionWindow", MakeBoundCallback (&CwndChange, stream3CWND, 0)); ns3TcpSocket3->TraceConnectWithoutContext("Drop", MakeBoundCallback (&packetDrop, stream3PD, 0, 3)); sink = "/NodeList/7/ApplicationList/0/$ns3::PacketSink/Rx"; Config::Connect(sink, MakeBoundCallback(&ReceivedPacket, stream3GP, 0)); sink_ = "/NodeList/7/ApplicationList/0/$ns3::PacketSink/Rx"; Config::Connect(sink_, MakeBoundCallback(&ReceivedPacket, stream3TP, otherFlowStart)); //Turning on Static Global Routing Ipv4GlobalRoutingHelper::PopulateRoutingTables(); Ptr<FlowMonitor> flowmon; FlowMonitorHelper flowmonHelper; flowmon = flowmonHelper.InstallAll(); Simulator::Stop(Seconds(durationGap+otherFlowStart)); //animation("anim4.xml", routers, senders, recievers); //animation Simulator::Run(); flowmon->CheckForLostPackets(); cout << "Part b throughput into app6_b.tp" << endl; //Ptr<OutputStreamWrapper> streamTP = asciiTraceHelper.CreateFileStream("app6_b.tp"); Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier>(flowmonHelper.GetClassifier()); std::map<FlowId, FlowMonitor::FlowStats> stats = flowmon->GetFlowStats(); for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator i = stats.begin(); i != stats.end(); ++i) { Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow (i->first); if(t.sourceAddress == "10.1.0.1") { if(mapDrop.find(1)==mapDrop.end()) mapDrop[1] = 0; *stream1PD->GetStream() << "TcpReno Flow " << i->first << " (" << t.sourceAddress << " -> " << t.destinationAddress << ")\n"; *stream1PD->GetStream() << "Net Packet Lost: " << i->second.lostPackets << "\n"; *stream1PD->GetStream() << "Packet Lost due to buffer overflow: " << mapDrop[1] << "\n"; *stream1PD->GetStream() << "Packet Lost due to Congestion: " << i->second.lostPackets - mapDrop[1] << "\n"; *stream1PD->GetStream() << "Max throughput: " << mapMaxThroughput["/NodeList/5/$ns3::Ipv4L3Protocol/Rx"] << std::endl; } else if(t.sourceAddress == "10.1.1.1") { if(mapDrop.find(2)==mapDrop.end()) mapDrop[2] = 0; *stream2PD->GetStream() << "TcpTahoe Flow " << i->first << " (" << t.sourceAddress << " -> " << t.destinationAddress << ")\n"; *stream2PD->GetStream() << "Net Packet Lost: " << i->second.lostPackets << "\n"; *stream2PD->GetStream() << "Packet Lost due to buffer overflow: " << mapDrop[2] << "\n"; *stream2PD->GetStream() << "Packet Lost due to Congestion: " << i->second.lostPackets - mapDrop[2] << "\n"; *stream2PD->GetStream() << "Max throughput: " << mapMaxThroughput["/NodeList/6/$ns3::Ipv4L3Protocol/Rx"] << std::endl; } else if(t.sourceAddress == "10.1.2.1") { if(mapDrop.find(3)==mapDrop.end()) mapDrop[3] = 0; *stream3PD->GetStream() << "TcpWestWood Flow " << i->first << " (" << t.sourceAddress << " -> " << t.destinationAddress << ")\n"; *stream3PD->GetStream() << "Net Packet Lost: " << i->second.lostPackets << "\n"; *stream3PD->GetStream() << "Packet Lost due to buffer overflow: " << mapDrop[3] << "\n"; *stream3PD->GetStream() << "Packet Lost due to Congestion: " << i->second.lostPackets - mapDrop[3] << "\n"; *stream3PD->GetStream() << "Max throughput: " << mapMaxThroughput["/NodeList/7/$ns3::Ipv4L3Protocol/Rx"] << std::endl; } } //flowmon->SerializeToXmlFile("app6_b.flowmon", true, true); Simulator::Destroy(); }
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[]) { #ifdef NS3_MPI // Distributed simulation setup MpiInterface::Enable (&argc, &argv); GlobalValue::Bind ("SimulatorImplementationType", StringValue ("ns3::DistributedSimulatorImpl")); LogComponentEnable ("BriteMPITest", LOG_LEVEL_ALL); LogComponentEnable ("TcpSocketBase", LOG_LEVEL_INFO); uint32_t systemId = MpiInterface::GetSystemId (); uint32_t systemCount = MpiInterface::GetSize (); // Check for valid distributed parameters. // For just this particular example, must have 2 and only 2 Logical Processors (LPs) NS_ASSERT_MSG (systemCount == 2, "This demonstration requires 2 and only 2 logical processors."); // BRITE needs a configuration file to build its graph. By default, this // example will use the TD_ASBarabasi_RTWaxman.conf file. There are many others // which can be found in the BRITE/conf_files directory std::string confFile = "src/brite/examples/conf_files/TD_ASBarabasi_RTWaxman.conf"; bool tracing = false; bool nix = false; CommandLine cmd; cmd.AddValue ("confFile", "BRITE conf file", confFile); cmd.AddValue ("tracing", "Enable or disable ascii tracing", tracing); cmd.AddValue ("nix", "Enable or disable nix-vector routing", nix); cmd.Parse (argc,argv); // Invoke the BriteTopologyHelper and pass in a BRITE // configuration file and a seed file. This will use // BRITE to build a graph from which we can build the ns-3 topology BriteTopologyHelper bth (confFile); PointToPointHelper p2p; Ipv4StaticRoutingHelper staticRouting; Ipv4GlobalRoutingHelper globalRouting; Ipv4ListRoutingHelper listRouting; Ipv4NixVectorHelper nixRouting; InternetStackHelper stack; if (nix) { listRouting.Add (staticRouting, 0); listRouting.Add (nixRouting, 10); } else { listRouting.Add (staticRouting, 0); listRouting.Add (globalRouting, 10); } stack.SetRoutingHelper (listRouting); Ipv4AddressHelper address; address.SetBase ("10.0.0.0", "255.255.255.252"); //build topology as normal but also pass systemCount bth.BuildBriteTopology (stack, systemCount); bth.AssignIpv4Addresses (address); NS_LOG_LOGIC ("Number of AS created " << bth.GetNAs ()); uint16_t port = 5001; NodeContainer client; NodeContainer server; //For this example will use AS 0 and AS 1 which will be on seperate systems //due to the mod divide used to assign AS to system. //GetSystemNumberForAs (uint32_t) can be used to determine which system an //AS is assigned to NS_LOG_LOGIC ("AS 0 has been assigned to system " << bth.GetSystemNumberForAs (0)); NS_LOG_LOGIC ("As 1 has been assigned to system " << bth.GetSystemNumberForAs (1)); //install client node on last leaf node of AS 0 client.Add (CreateObject<Node> (0)); stack.Install (client); int numLeafNodesInAsZero = bth.GetNLeafNodesForAs (0); client.Add (bth.GetLeafNodeForAs (0, numLeafNodesInAsZero - 1)); //install server node on last leaf node on AS 1 server.Add (CreateObject<Node> (1)); stack.Install (server); int numLeafNodesInAsOne = bth.GetNLeafNodesForAs (1); server.Add (bth.GetLeafNodeForAs (1, numLeafNodesInAsOne - 1)); p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); p2p.SetChannelAttribute ("Delay", StringValue ("2ms")); NetDeviceContainer p2pClientDevices; NetDeviceContainer p2pServerDevices; p2pClientDevices = p2p.Install (client); p2pServerDevices = p2p.Install (server); address.SetBase ("10.1.0.0", "255.255.0.0"); Ipv4InterfaceContainer clientInterfaces; clientInterfaces = address.Assign (p2pClientDevices); address.SetBase ("10.2.0.0", "255.255.0.0"); Ipv4InterfaceContainer serverInterfaces; serverInterfaces = address.Assign (p2pServerDevices); if (!nix) { Ipv4GlobalRoutingHelper::PopulateRoutingTables (); } //only has two systems in this example. Install applications only on nodes in my system //Moved here to get totalRX at end ApplicationContainer sinkApps; if (systemId == 1) { Address sinkLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port)); PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", sinkLocalAddress); sinkApps.Add (packetSinkHelper.Install (server.Get (0))); sinkApps.Start (Seconds (0.0)); sinkApps.Stop (Seconds (10.0)); } if (systemId == 0) { OnOffHelper clientHelper ("ns3::TcpSocketFactory", Address ()); clientHelper.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]")); clientHelper.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]")); ApplicationContainer clientApps; AddressValue remoteAddress (InetSocketAddress (serverInterfaces.GetAddress (0), port)); clientHelper.SetAttribute ("Remote", remoteAddress); clientApps.Add (clientHelper.Install (client.Get (0))); clientApps.Start (Seconds (1.0)); // Start 1 second after sink clientApps.Stop (Seconds (9.0)); // Stop before the sink } if (!nix) { Ipv4GlobalRoutingHelper::PopulateRoutingTables (); } if (tracing) { AsciiTraceHelper ascii; p2p.EnableAsciiAll (ascii.CreateFileStream ("briteLeaves.tr")); } // Run the simulator Simulator::Stop (Seconds (200.0)); Simulator::Run (); Simulator::Destroy (); if (systemId == 1) { Ptr<PacketSink> sink1 = DynamicCast<PacketSink> (sinkApps.Get (0)); NS_LOG_DEBUG ("Total Bytes Received: " << sink1->GetTotalRx ()); } MpiInterface::Disable (); return 0; #else NS_FATAL_ERROR ("Can't use distributed simulator without MPI compiled in"); #endif }
int main (int argc, char *argv[]) { std::string mode = "ConfigureLocal"; std::string tapName = "thetap"; CommandLine cmd; cmd.AddValue ("mode", "Mode setting of TapBridge", mode); cmd.AddValue ("tapName", "Name of the OS tap device", tapName); cmd.Parse (argc, argv); GlobalValue::Bind ("SimulatorImplementationType", StringValue ("ns3::RealtimeSimulatorImpl")); GlobalValue::Bind ("ChecksumEnabled", BooleanValue (true)); // // The topology has a Wifi network of four nodes on the left side. We'll make // node zero the AP and have the other three will be the STAs. // NodeContainer nodesLeft; nodesLeft.Create (4); YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default (); wifiPhy.SetChannel (wifiChannel.Create ()); Ssid ssid = Ssid ("left"); WifiHelper wifi = WifiHelper::Default (); NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); wifi.SetRemoteStationManager ("ns3::ArfWifiManager"); wifiMac.SetType ("ns3::ApWifiMac", "Ssid", SsidValue (ssid)); NetDeviceContainer devicesLeft = wifi.Install (wifiPhy, wifiMac, nodesLeft.Get (0)); wifiMac.SetType ("ns3::StaWifiMac", "Ssid", SsidValue (ssid), "ActiveProbing", BooleanValue (false)); devicesLeft.Add (wifi.Install (wifiPhy, wifiMac, NodeContainer (nodesLeft.Get (1), nodesLeft.Get (2), nodesLeft.Get (3)))); MobilityHelper mobility; mobility.Install (nodesLeft); InternetStackHelper internetLeft; internetLeft.Install (nodesLeft); Ipv4AddressHelper ipv4Left; ipv4Left.SetBase ("10.1.1.0", "255.255.255.0"); Ipv4InterfaceContainer interfacesLeft = ipv4Left.Assign (devicesLeft); TapBridgeHelper tapBridge (interfacesLeft.GetAddress (1)); tapBridge.SetAttribute ("Mode", StringValue (mode)); tapBridge.SetAttribute ("DeviceName", StringValue (tapName)); tapBridge.Install (nodesLeft.Get (0), devicesLeft.Get (0)); // // Now, create the right side. // NodeContainer nodesRight; nodesRight.Create (4); CsmaHelper csmaRight; csmaRight.SetChannelAttribute ("DataRate", DataRateValue (5000000)); csmaRight.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2))); NetDeviceContainer devicesRight = csmaRight.Install (nodesRight); InternetStackHelper internetRight; internetRight.Install (nodesRight); Ipv4AddressHelper ipv4Right; ipv4Right.SetBase ("10.1.3.0", "255.255.255.0"); Ipv4InterfaceContainer interfacesRight = ipv4Right.Assign (devicesRight); // // Stick in the point-to-point line between the sides. // PointToPointHelper p2p; p2p.SetDeviceAttribute ("DataRate", StringValue ("512kbps")); p2p.SetChannelAttribute ("Delay", StringValue ("10ms")); NodeContainer nodes = NodeContainer (nodesLeft.Get (3), nodesRight.Get (0)); NetDeviceContainer devices = p2p.Install (nodes); Ipv4AddressHelper ipv4; ipv4.SetBase ("10.1.2.0", "255.255.255.192"); Ipv4InterfaceContainer interfaces = ipv4.Assign (devices); // // Simulate some CBR traffic over the point-to-point link // uint16_t port = 9; // Discard port (RFC 863) OnOffHelper onoff ("ns3::UdpSocketFactory", InetSocketAddress (interfaces.GetAddress (1), port)); onoff.SetConstantRate (DataRate ("500kb/s")); ApplicationContainer apps = onoff.Install (nodesLeft.Get (3)); apps.Start (Seconds (1.0)); // Create a packet sink to receive these packets PacketSinkHelper sink ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), port)); apps = sink.Install (nodesRight.Get (0)); apps.Start (Seconds (1.0)); wifiPhy.EnablePcapAll ("tap-wifi-dumbbell"); csmaRight.EnablePcapAll ("tap-wifi-dumbbell", false); Ipv4GlobalRoutingHelper::PopulateRoutingTables (); Simulator::Stop (Seconds (60.)); Simulator::Run (); Simulator::Destroy (); }
void EpcS1uDlTestCase::DoRun () { Ptr<PointToPointEpcHelper> epcHelper = CreateObject<PointToPointEpcHelper> (); Ptr<Node> pgw = epcHelper->GetPgwNode (); // allow jumbo packets Config::SetDefault ("ns3::CsmaNetDevice::Mtu", UintegerValue (30000)); Config::SetDefault ("ns3::PointToPointNetDevice::Mtu", UintegerValue (30000)); epcHelper->SetAttribute ("S1uLinkMtu", UintegerValue (30000)); // 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"))); NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost); Ipv4AddressHelper ipv4h; ipv4h.SetBase ("1.0.0.0", "255.0.0.0"); ipv4h.Assign (internetDevices); // setup default gateway for the remote hosts Ipv4StaticRoutingHelper ipv4RoutingHelper; Ptr<Ipv4StaticRouting> remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv4> ()); // hardcoded UE addresses for now remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask ("255.255.255.0"), 1); NodeContainer enbs; uint16_t cellIdCounter = 0; for (std::vector<EnbDlTestData>::iterator enbit = m_enbDlTestData.begin (); enbit < m_enbDlTestData.end (); ++enbit) { Ptr<Node> enb = CreateObject<Node> (); enbs.Add (enb); // we test EPC without LTE, hence we use: // 1) a CSMA network to simulate the cell // 2) a raw socket opened on the CSMA device to simulate the LTE socket uint16_t cellId = ++cellIdCounter; NodeContainer ues; ues.Create (enbit->ues.size ()); NodeContainer cell; cell.Add (ues); cell.Add (enb); CsmaHelper csmaCell; NetDeviceContainer cellDevices = csmaCell.Install (cell); // the eNB's CSMA NetDevice acting as an LTE NetDevice. Ptr<NetDevice> enbDevice = cellDevices.Get (cellDevices.GetN () - 1); // Note that the EpcEnbApplication won't care of the actual NetDevice type epcHelper->AddEnb (enb, enbDevice, cellId); // Plug test RRC entity Ptr<EpcEnbApplication> enbApp = enb->GetApplication (0)->GetObject<EpcEnbApplication> (); NS_ASSERT_MSG (enbApp != 0, "cannot retrieve EpcEnbApplication"); Ptr<EpcTestRrc> rrc = CreateObject<EpcTestRrc> (); rrc->SetS1SapProvider (enbApp->GetS1SapProvider ()); enbApp->SetS1SapUser (rrc->GetS1SapUser ()); // we install the IP stack on UEs only InternetStackHelper internet; internet.Install (ues); // assign IP address to UEs, and install applications for (uint32_t u = 0; u < ues.GetN (); ++u) { Ptr<NetDevice> ueLteDevice = cellDevices.Get (u); Ipv4InterfaceContainer ueIpIface = epcHelper->AssignUeIpv4Address (NetDeviceContainer (ueLteDevice)); Ptr<Node> ue = ues.Get (u); // disable IP Forwarding on the UE. This is because we use // CSMA broadcast MAC addresses for this test. The problem // won't happen with a LteUeNetDevice. ue->GetObject<Ipv4> ()->SetAttribute ("IpForward", BooleanValue (false)); uint16_t port = 1234; PacketSinkHelper packetSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), port)); ApplicationContainer apps = packetSinkHelper.Install (ue); apps.Start (Seconds (1.0)); apps.Stop (Seconds (10.0)); enbit->ues[u].serverApp = apps.Get (0)->GetObject<PacketSink> (); Time interPacketInterval = Seconds (0.01); UdpEchoClientHelper client (ueIpIface.GetAddress (0), port); client.SetAttribute ("MaxPackets", UintegerValue (enbit->ues[u].numPkts)); client.SetAttribute ("Interval", TimeValue (interPacketInterval)); client.SetAttribute ("PacketSize", UintegerValue (enbit->ues[u].pktSize)); apps = client.Install (remoteHost); apps.Start (Seconds (2.0)); apps.Stop (Seconds (10.0)); enbit->ues[u].clientApp = apps.Get (0); uint64_t imsi = u+1; epcHelper->AddUe (ueLteDevice, imsi); epcHelper->ActivateEpsBearer (ueLteDevice, imsi, EpcTft::Default (), EpsBearer (EpsBearer::NGBR_VIDEO_TCP_DEFAULT)); enbApp->GetS1SapProvider ()->InitialUeMessage (imsi, (uint16_t) imsi); } } Simulator::Run (); for (std::vector<EnbDlTestData>::iterator enbit = m_enbDlTestData.begin (); enbit < m_enbDlTestData.end (); ++enbit) { for (std::vector<UeDlTestData>::iterator ueit = enbit->ues.begin (); ueit < enbit->ues.end (); ++ueit) { NS_TEST_ASSERT_MSG_EQ (ueit->serverApp->GetTotalRx (), (ueit->numPkts) * (ueit->pktSize), "wrong total received bytes"); } } 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 }
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[]) { CommandLine cmd; cmd.Parse (argc, argv); // Here, we will explicitly create four nodes. NS_LOG_INFO ("Create nodes."); NodeContainer c; c.Create (4); // connect all our nodes to a shared channel. NS_LOG_INFO ("Build Topology."); 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. NS_LOG_INFO ("Add ip stack."); InternetStackHelper ipStack; ipStack.Install (c); // assign ip addresses NS_LOG_INFO ("Assign ip addresses."); Ipv4AddressHelper ip; ip.SetBase ("192.168.1.0", "255.255.255.0"); Ipv4InterfaceContainer addresses = ip.Assign (devs); NS_LOG_INFO ("Create Source"); Config::SetDefault ("ns3::Ipv4RawSocketImpl::Protocol", StringValue ("2")); InetSocketAddress dst = InetSocketAddress (addresses.GetAddress (3)); OnOffHelper onoff = OnOffHelper ("ns3::Ipv4RawSocketFactory", dst); onoff.SetConstantRate (DataRate (15000)); onoff.SetAttribute ("PacketSize", UintegerValue (1200)); ApplicationContainer apps = onoff.Install (c.Get (0)); apps.Start (Seconds (1.0)); apps.Stop (Seconds (10.0)); NS_LOG_INFO ("Create Sink."); PacketSinkHelper sink = PacketSinkHelper ("ns3::Ipv4RawSocketFactory", dst); apps = sink.Install (c.Get (3)); apps.Start (Seconds (0.0)); apps.Stop (Seconds (11.0)); NS_LOG_INFO ("Create pinger"); V4PingHelper ping = V4PingHelper (addresses.GetAddress (2)); NodeContainer pingers; pingers.Add (c.Get (0)); pingers.Add (c.Get (1)); pingers.Add (c.Get (3)); apps = ping.Install (pingers); apps.Start (Seconds (2.0)); apps.Stop (Seconds (5.0)); NS_LOG_INFO ("Configure Tracing."); // first, pcap tracing in non-promiscuous mode csma.EnablePcapAll ("csma-ping", false); // then, print what the packet sink receives. Config::ConnectWithoutContext ("/NodeList/3/ApplicationList/0/$ns3::PacketSink/Rx", MakeCallback (&SinkRx)); // finally, print the ping rtts. Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::V4Ping/Rtt", MakeCallback (&PingRtt)); Packet::EnablePrinting (); NS_LOG_INFO ("Run Simulation."); Simulator::Run (); Simulator::Destroy (); NS_LOG_INFO ("Done."); }