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); }
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[]) { // 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; }
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; }
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[]) { uint32_t nWifis = 2; uint32_t nStas = 2; bool sendIp = true; bool writeMobility = false; CommandLine cmd; cmd.AddValue ("nWifis", "Number of wifi networks", nWifis); cmd.AddValue ("nStas", "Number of stations per wifi network", nStas); cmd.AddValue ("SendIp", "Send Ipv4 or raw packets", sendIp); cmd.AddValue ("writeMobility", "Write mobility trace", writeMobility); cmd.Parse (argc, argv); NodeContainer backboneNodes; NetDeviceContainer backboneDevices; Ipv4InterfaceContainer backboneInterfaces; std::vector<NodeContainer> staNodes; std::vector<NetDeviceContainer> staDevices; std::vector<NetDeviceContainer> apDevices; std::vector<Ipv4InterfaceContainer> staInterfaces; std::vector<Ipv4InterfaceContainer> apInterfaces; InternetStackHelper stack; CsmaHelper csma; Ipv4AddressHelper ip; ip.SetBase ("192.168.0.0", "255.255.255.0"); backboneNodes.Create (nWifis); stack.Install (backboneNodes); backboneDevices = csma.Install (backboneNodes); double wifiX = 0.0; YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO); for (uint32_t i = 0; i < nWifis; ++i) { // calculate ssid for wifi subnetwork std::ostringstream oss; oss << "wifi-default-" << i; Ssid ssid = Ssid (oss.str ()); NodeContainer sta; NetDeviceContainer staDev; NetDeviceContainer apDev; Ipv4InterfaceContainer staInterface; Ipv4InterfaceContainer apInterface; MobilityHelper mobility; BridgeHelper bridge; WifiHelper wifi = WifiHelper::Default (); NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default (); wifiPhy.SetChannel (wifiChannel.Create ()); sta.Create (nStas); mobility.SetPositionAllocator ("ns3::GridPositionAllocator", "MinX", DoubleValue (wifiX), "MinY", DoubleValue (0.0), "DeltaX", DoubleValue (5.0), "DeltaY", DoubleValue (5.0), "GridWidth", UintegerValue (1), "LayoutType", StringValue ("RowFirst")); // setup the AP. mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (backboneNodes.Get (i)); wifiMac.SetType ("ns3::ApWifiMac", "Ssid", SsidValue (ssid)); apDev = wifi.Install (wifiPhy, wifiMac, backboneNodes.Get (i)); NetDeviceContainer bridgeDev; bridgeDev = bridge.Install (backboneNodes.Get (i), NetDeviceContainer (apDev, backboneDevices.Get (i))); // assign AP IP address to bridge, not wifi apInterface = ip.Assign (bridgeDev); // setup the STAs stack.Install (sta); mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel", "Mode", StringValue ("Time"), "Time", StringValue ("2s"), "Speed", StringValue ("ns3::ConstantRandomVariable[Constant=1.0]"), "Bounds", RectangleValue (Rectangle (wifiX, wifiX+5.0,0.0, (nStas+1)*5.0))); mobility.Install (sta); wifiMac.SetType ("ns3::StaWifiMac", "Ssid", SsidValue (ssid), "ActiveProbing", BooleanValue (false)); staDev = wifi.Install (wifiPhy, wifiMac, sta); staInterface = ip.Assign (staDev); // save everything in containers. staNodes.push_back (sta); apDevices.push_back (apDev); apInterfaces.push_back (apInterface); staDevices.push_back (staDev); staInterfaces.push_back (staInterface); wifiX += 20.0; } Address dest; std::string protocol; if (sendIp) { dest = InetSocketAddress (staInterfaces[1].GetAddress (1), 1025); protocol = "ns3::UdpSocketFactory"; } else { PacketSocketAddress tmp; tmp.SetSingleDevice (staDevices[0].Get (0)->GetIfIndex ()); tmp.SetPhysicalAddress (staDevices[1].Get (0)->GetAddress ()); tmp.SetProtocol (0x807); dest = tmp; protocol = "ns3::PacketSocketFactory"; } OnOffHelper onoff = OnOffHelper (protocol, dest); onoff.SetConstantRate (DataRate ("500kb/s")); ApplicationContainer apps = onoff.Install (staNodes[0].Get (0)); apps.Start (Seconds (0.5)); apps.Stop (Seconds (3.0)); wifiPhy.EnablePcap ("wifi-wired-bridging", apDevices[0]); wifiPhy.EnablePcap ("wifi-wired-bridging", apDevices[1]); if (writeMobility) { AsciiTraceHelper ascii; MobilityHelper::EnableAsciiAll (ascii.CreateFileStream ("wifi-wired-bridging.mob")); } Simulator::Stop (Seconds (5.0)); Simulator::Run (); Simulator::Destroy (); }
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[]) { // // Users may find it convenient to turn on explicit debugging // for selected modules; the below lines suggest how to do this // // LogComponentEnable ("CsmaMulticastExample", LOG_LEVEL_INFO); // // Set up default values for the simulation. // // Select DIX/Ethernet II-style encapsulation (no LLC/Snap header) Config::SetDefault ("ns3::CsmaNetDevice::EncapsulationMode", StringValue ("Dix")); // Allow the user to override any of the defaults at // run-time, via command-line arguments CommandLine cmd; cmd.Parse (argc, argv); NS_LOG_INFO ("Create nodes."); NodeContainer c; c.Create (5); // We will later want two subcontainers of these nodes, for the two LANs NodeContainer c0 = NodeContainer (c.Get (0), c.Get (1), c.Get (2)); NodeContainer c1 = NodeContainer (c.Get (2), c.Get (3), c.Get (4)); NS_LOG_INFO ("Build Topology."); CsmaHelper csma; csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate (5000000))); csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2))); // We will use these NetDevice containers later, for IP addressing NetDeviceContainer nd0 = csma.Install (c0); // First LAN NetDeviceContainer nd1 = csma.Install (c1); // Second LAN NS_LOG_INFO ("Add IP Stack."); InternetStackHelper internet; internet.Install (c); NS_LOG_INFO ("Assign IP Addresses."); Ipv4AddressHelper ipv4Addr; ipv4Addr.SetBase ("10.1.1.0", "255.255.255.0"); ipv4Addr.Assign (nd0); ipv4Addr.SetBase ("10.1.2.0", "255.255.255.0"); ipv4Addr.Assign (nd1); NS_LOG_INFO ("Configure multicasting."); // // Now we can configure multicasting. As described above, the multicast // source is at node zero, which we assigned the IP address of 10.1.1.1 // earlier. We need to define a multicast group to send packets to. This // can be any multicast address from 224.0.0.0 through 239.255.255.255 // (avoiding the reserved routing protocol addresses). // Ipv4Address multicastSource ("10.1.1.1"); Ipv4Address multicastGroup ("225.1.2.4"); // Now, we will set up multicast routing. We need to do three things: // 1) Configure a (static) multicast route on node n2 // 2) Set up a default multicast route on the sender n0 // 3) Have node n4 join the multicast group // We have a helper that can help us with static multicast Ipv4StaticRoutingHelper multicast; // 1) Configure a (static) multicast route on node n2 (multicastRouter) Ptr<Node> multicastRouter = c.Get (2); // The node in question Ptr<NetDevice> inputIf = nd0.Get (2); // The input NetDevice NetDeviceContainer outputDevices; // A container of output NetDevices outputDevices.Add (nd1.Get (0)); // (we only need one NetDevice here) multicast.AddMulticastRoute (multicastRouter, multicastSource, multicastGroup, inputIf, outputDevices); // 2) Set up a default multicast route on the sender n0 Ptr<Node> sender = c.Get (0); Ptr<NetDevice> senderIf = nd0.Get (0); multicast.SetDefaultMulticastRoute (sender, senderIf); // // Create an OnOff application to send UDP datagrams from node zero to the // multicast group (node four will be listening). // NS_LOG_INFO ("Create Applications."); uint16_t multicastPort = 9; // Discard port (RFC 863) // Configure a multicast packet generator that generates a packet // every few seconds OnOffHelper onoff ("ns3::UdpSocketFactory", Address (InetSocketAddress (multicastGroup, multicastPort))); onoff.SetConstantRate (DataRate ("255b/s")); onoff.SetAttribute ("PacketSize", UintegerValue (128)); ApplicationContainer srcC = onoff.Install (c0.Get (0)); // // Tell the application when to start and stop. // srcC.Start (Seconds (1.)); srcC.Stop (Seconds (10.)); // Create an optional packet sink to receive these packets PacketSinkHelper sink ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), multicastPort)); ApplicationContainer sinkC = sink.Install (c1.Get (2)); // Node n4 // Start the sink sinkC.Start (Seconds (1.0)); sinkC.Stop (Seconds (10.0)); NS_LOG_INFO ("Configure Tracing."); // // Configure tracing of all enqueue, dequeue, and NetDevice receive events. // Ascii trace output will be sent to the file "csma-multicast.tr" // AsciiTraceHelper ascii; csma.EnableAsciiAll (ascii.CreateFileStream ("csma-multicast.tr")); // Also configure some tcpdump traces; each interface will be traced. // The output files will be named: // csma-multicast-<nodeId>-<interfaceId>.pcap // and can be read by the "tcpdump -r" command (use "-tt" option to // display timestamps correctly) csma.EnablePcapAll ("csma-multicast", 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[]) { // // Users may find it convenient to turn on explicit debugging // for selected modules; the below lines suggest how to do this // #if 0 LogComponentEnable ("CsmaBridgeOneHopExample", LOG_LEVEL_INFO); #endif // // Allow the user to override any of the defaults and the above Bind() at // run-time, via command-line arguments // CommandLine cmd; cmd.Parse (argc, argv); // // Explicitly create the nodes required by the topology (shown above). // NS_LOG_INFO ("Create nodes."); Ptr<Node> n0 = CreateObject<Node> (); Ptr<Node> n1 = CreateObject<Node> (); Ptr<Node> n2 = CreateObject<Node> (); Ptr<Node> n3 = CreateObject<Node> (); Ptr<Node> n4 = CreateObject<Node> (); Ptr<Node> bridge1 = CreateObject<Node> (); Ptr<Node> bridge2 = CreateObject<Node> (); NS_LOG_INFO ("Build Topology"); CsmaHelper csma; csma.SetChannelAttribute ("DataRate", DataRateValue (5000000)); csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2))); // Create the csma links, from each terminal to the bridge // This will create six network devices; we'll keep track separately // of the devices on and off the bridge respectively, for later configuration NetDeviceContainer topLanDevices; NetDeviceContainer topBridgeDevices; // It is easier to iterate the nodes in C++ if we put them into a container NodeContainer topLan (n2, n0, n1); for (int i = 0; i < 3; i++) { // install a csma channel between the ith toplan node and the bridge node NetDeviceContainer link = csma.Install (NodeContainer (topLan.Get (i), bridge1)); topLanDevices.Add (link.Get (0)); topBridgeDevices.Add (link.Get (1)); } // // Now, Create the bridge netdevice, which will do the packet switching. The // bridge lives on the node bridge1 and bridges together the topBridgeDevices // which are the three CSMA net devices on the node in the diagram above. // BridgeHelper bridge; bridge.Install (bridge1, topBridgeDevices); // Add internet stack to the router nodes NodeContainer routerNodes (n0, n1, n2, n3, n4); InternetStackHelper internet; internet.Install (routerNodes); // Repeat for bottom bridged LAN NetDeviceContainer bottomLanDevices; NetDeviceContainer bottomBridgeDevices; NodeContainer bottomLan (n2, n3, n4); for (int i = 0; i < 3; i++) { NetDeviceContainer link = csma.Install (NodeContainer (bottomLan.Get (i), bridge2)); bottomLanDevices.Add (link.Get (0)); bottomBridgeDevices.Add (link.Get (1)); } bridge.Install (bridge2, bottomBridgeDevices); // We've got the "hardware" in place. Now we need to add IP addresses. NS_LOG_INFO ("Assign IP Addresses."); Ipv4AddressHelper ipv4; ipv4.SetBase ("10.1.1.0", "255.255.255.0"); ipv4.Assign (topLanDevices); ipv4.SetBase ("10.1.2.0", "255.255.255.0"); ipv4.Assign (bottomLanDevices); // // Create router nodes, initialize routing database and set up the routing // tables in the nodes. We excuse the bridge nodes from having to serve as // routers, since they don't even have internet stacks on them. // Ipv4GlobalRoutingHelper::PopulateRoutingTables (); // // Create an OnOff application to send UDP datagrams from node zero to node 1. // NS_LOG_INFO ("Create Applications."); uint16_t port = 9; // Discard port (RFC 863) OnOffHelper onoff ("ns3::UdpSocketFactory", Address (InetSocketAddress (Ipv4Address ("10.1.1.3"), port))); onoff.SetConstantRate (DataRate ("500kb/s")); ApplicationContainer app = onoff.Install (n0); // 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))); ApplicationContainer sink1 = sink.Install (n1); sink1.Start (Seconds (1.0)); sink1.Stop (Seconds (10.0)); // // Create a similar flow from n3 to n0, starting at time 1.1 seconds // onoff.SetAttribute ("Remote", AddressValue (InetSocketAddress (Ipv4Address ("10.1.1.2"), port))); ApplicationContainer app2 = onoff.Install (n3); app2.Start (Seconds (1.1)); app2.Stop (Seconds (10.0)); ApplicationContainer sink2 = sink.Install (n0); sink2.Start (Seconds (1.1)); sink2.Stop (Seconds (10.0)); NS_LOG_INFO ("Configure Tracing."); // // Configure tracing of all enqueue, dequeue, and NetDevice receive events. // Trace output will be sent to the file "csma-bridge-one-hop.tr" // AsciiTraceHelper ascii; csma.EnableAsciiAll (ascii.CreateFileStream ("csma-bridge-one-hop.tr")); // // Also configure some tcpdump traces; each interface will be traced. // The output files will be named: // csma-bridge-one-hop-<nodeId>-<interfaceId>.pcap // and can be read by the "tcpdump -r" command (use "-tt" option to // display timestamps correctly) // csma.EnablePcapAll ("csma-bridge-one-hop", 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) { bool verbose = false; CommandLine cmd; cmd.AddValue ("verbose", "turn on log components", verbose); cmd.Parse (argc, argv); if (verbose) { LogComponentEnable ("Ipv6L3Protocol", LOG_LEVEL_ALL); LogComponentEnable ("Icmpv6L4Protocol", LOG_LEVEL_ALL); LogComponentEnable ("Ipv6StaticRouting", LOG_LEVEL_ALL); LogComponentEnable ("Ipv6Interface", LOG_LEVEL_ALL); LogComponentEnable ("Ping6Application", LOG_LEVEL_ALL); } NS_LOG_INFO ("Create nodes."); Ptr<Node> n0 = CreateObject<Node> (); Ptr<Node> r = CreateObject<Node> (); Ptr<Node> n1 = CreateObject<Node> (); NodeContainer net1 (n0, r); NodeContainer net2 (r, n1); NodeContainer all (n0, r, n1); NS_LOG_INFO ("Create IPv6 Internet Stack"); InternetStackHelper internetv6; internetv6.Install (all); NS_LOG_INFO ("Create channels."); CsmaHelper csma; csma.SetChannelAttribute ("DataRate", DataRateValue (5000000)); csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2))); NetDeviceContainer d1 = csma.Install (net1); NetDeviceContainer d2 = csma.Install (net2); NS_LOG_INFO ("Create networks and assign IPv6 Addresses."); Ipv6AddressHelper ipv6; ipv6.SetBase (Ipv6Address ("2001:1::"), Ipv6Prefix (64)); Ipv6InterfaceContainer i1 = ipv6.Assign (d1); i1.SetForwarding (1, true); i1.SetDefaultRouteInAllNodes (1); ipv6.SetBase (Ipv6Address ("2001:2::"), Ipv6Prefix (64)); Ipv6InterfaceContainer i2 = ipv6.Assign (d2); i2.SetForwarding (0, true); i2.SetDefaultRouteInAllNodes (0); Ipv6StaticRoutingHelper routingHelper; Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> (&std::cout); routingHelper.PrintRoutingTableAt (Seconds (0), n0, routingStream); /* Create a Ping6 application to send ICMPv6 echo request from n0 to n1 via r */ uint32_t packetSize = 4096; uint32_t maxPacketCount = 5; Time interPacketInterval = Seconds (1.0); Ping6Helper ping6; ping6.SetLocal (i1.GetAddress (0, 1)); ping6.SetRemote (i2.GetAddress (1, 1)); ping6.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount)); ping6.SetAttribute ("Interval", TimeValue (interPacketInterval)); ping6.SetAttribute ("PacketSize", UintegerValue (packetSize)); ApplicationContainer apps = ping6.Install (net1.Get (0)); apps.Start (Seconds (2.0)); apps.Stop (Seconds (20.0)); AsciiTraceHelper ascii; csma.EnableAsciiAll (ascii.CreateFileStream ("fragmentation-ipv6.tr")); csma.EnablePcapAll (std::string ("fragmentation-ipv6"), true); NS_LOG_INFO ("Run Simulation."); Simulator::Run (); Simulator::Destroy (); NS_LOG_INFO ("Done."); }