diff --git a/examples/wireless/mixed-wireless.cc b/examples/wireless/mixed-wireless.cc index a3e887c77..d5fe5711e 100644 --- a/examples/wireless/mixed-wireless.cc +++ b/examples/wireless/mixed-wireless.cc @@ -98,16 +98,15 @@ main (int argc, char *argv[]) uint32_t backboneNodes = 10; uint32_t infraNodes = 5; uint32_t lanNodes = 5; - uint32_t stopTime = 10; + uint32_t stopTime = 20; bool useCourseChangeCallback = false; - bool enableTracing = false; // // Simulation defaults are typically set next, before command line // arguments are parsed. // - Config::SetDefault ("ns3::OnOffApplication::PacketSize", StringValue ("210")); - Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("10kb/s")); + Config::SetDefault ("ns3::OnOffApplication::PacketSize", StringValue ("1472")); + Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("100kb/s")); // // For convenience, we add the local variables to the command line argument @@ -120,7 +119,6 @@ main (int argc, char *argv[]) cmd.AddValue ("lanNodes", "number of LAN nodes", lanNodes); cmd.AddValue ("stopTime", "simulation stop time (seconds)", stopTime); cmd.AddValue ("useCourseChangeCallback", "whether to enable course change tracing", useCourseChangeCallback); - cmd.AddValue ("enableTracing", "enable tracing", enableTracing); // // The system global variables and the local values added to the argument @@ -128,6 +126,11 @@ main (int argc, char *argv[]) // cmd.Parse (argc, argv); + if (stopTime < 10) + { + std::cout << "Use a simulation stop time >= 10 seconds" << std::endl; + exit (1); + } /////////////////////////////////////////////////////////////////////////// // // // Construct the backbone // @@ -165,9 +168,6 @@ main (int argc, char *argv[]) internet.SetRoutingHelper (olsr); // has effect on the next Install () internet.Install (backbone); - // re-initialize for non-olsr routing. - internet.Reset (); - // // Assign IPv4 addresses to the device drivers (actually to the associated // IPv4 interfaces) we just created. @@ -286,7 +286,9 @@ main (int argc, char *argv[]) NetDeviceContainer staDevices = wifiInfra.Install (wifiPhy, macInfra, stas); // setup ap. macInfra.SetType ("ns3::ApWifiMac", - "Ssid", SsidValue (ssid)); + "Ssid", SsidValue (ssid), + "BeaconGeneration", BooleanValue (true), + "BeaconInterval", TimeValue(Seconds(2.5))); NetDeviceContainer apDevices = wifiInfra.Install (wifiPhy, macInfra, backbone.Get (i)); // Collect all of these new devices NetDeviceContainer infraDevices (apDevices, staDevices); @@ -322,17 +324,6 @@ main (int argc, char *argv[]) "Pause", StringValue ("ns3::ConstantRandomVariable[Constant=0.4]")); mobility.Install (infra); } - /////////////////////////////////////////////////////////////////////////// - // // - // Routing configuration // - // // - /////////////////////////////////////////////////////////////////////////// - - // The below global routing does not take into account wireless effects. - // However, it is useful for setting default routes for all of the nodes - // such as the LAN nodes. - NS_LOG_INFO ("Enabling global routing on all nodes"); - Ipv4GlobalRoutingHelper::PopulateRoutingTables (); /////////////////////////////////////////////////////////////////////////// // // @@ -363,17 +354,16 @@ main (int argc, char *argv[]) OnOffHelper onoff ("ns3::UdpSocketFactory", Address (InetSocketAddress (remoteAddr, port))); - onoff.SetConstantRate (DataRate ("10kb/s")); ApplicationContainer apps = onoff.Install (appSource); - apps.Start (Seconds (3.0)); - apps.Stop (Seconds (20.0)); + apps.Start (Seconds (3)); + apps.Stop (Seconds (stopTime - 1)); // Create a packet sink to receive these packets PacketSinkHelper sink ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), port)); apps = sink.Install (appSink); - apps.Start (Seconds (3.0)); + apps.Start (Seconds (3)); /////////////////////////////////////////////////////////////////////////// // // @@ -382,30 +372,23 @@ main (int argc, char *argv[]) /////////////////////////////////////////////////////////////////////////// NS_LOG_INFO ("Configure Tracing."); - if (enableTracing == true) - { - CsmaHelper csma; + CsmaHelper csma; - // - // Let's set up some ns-2-like ascii traces, using another helper class - // - AsciiTraceHelper ascii; - Ptr stream = ascii.CreateFileStream ("mixed-wireless.tr"); - wifiPhy.EnableAsciiAll (stream); - csma.EnableAsciiAll (stream); - internet.EnableAsciiIpv4All (stream); + // + // Let's set up some ns-2-like ascii traces, using another helper class + // + AsciiTraceHelper ascii; + Ptr stream = ascii.CreateFileStream ("mixed-wireless.tr"); + wifiPhy.EnableAsciiAll (stream); + csma.EnableAsciiAll (stream); + internet.EnableAsciiIpv4All (stream); - // Let's do a pcap trace on the application source and sink, ifIndex 0 - // Csma captures in non-promiscuous mode -#if 0 - csma.EnablePcap ("mixed-wireless", appSource->GetId (), 0, false); -#else - csma.EnablePcapAll ("mixed-wireless", false); -#endif - wifiPhy.EnablePcap ("mixed-wireless", appSink->GetId (), 0); - wifiPhy.EnablePcap ("mixed-wireless", 9, 2); - wifiPhy.EnablePcap ("mixed-wireless", 9, 0); - } + // Csma captures in non-promiscuous mode + csma.EnablePcapAll ("mixed-wireless", false); + // pcap captures on the backbone wifi devices + wifiPhy.EnablePcap ("mixed-wireless", backboneDevices, false); + // pcap trace on the application data sink + wifiPhy.EnablePcap ("mixed-wireless", appSink->GetId (), 0); if (useCourseChangeCallback == true) { diff --git a/examples/wireless/mixed-wireless.py b/examples/wireless/mixed-wireless.py index e0772db2b..befc875a7 100644 --- a/examples/wireless/mixed-wireless.py +++ b/examples/wireless/mixed-wireless.py @@ -78,14 +78,14 @@ def main(argv): backboneNodes = 10 infraNodes = 5 lanNodes = 5 - stopTime = 10 + stopTime = 20 # # Simulation defaults are typically set next, before command line # arguments are parsed. # - ns.core.Config.SetDefault("ns3::OnOffApplication::PacketSize", ns.core.StringValue("210")) - ns.core.Config.SetDefault("ns3::OnOffApplication::DataRate", ns.core.StringValue("448kb/s")) + ns.core.Config.SetDefault("ns3::OnOffApplication::PacketSize", ns.core.StringValue("1472")) + ns.core.Config.SetDefault("ns3::OnOffApplication::DataRate", ns.core.StringValue("100kb/s")) # # For convenience, we add the local variables to the command line argument @@ -93,10 +93,10 @@ def main(argv): # "--backboneNodes=20" # cmd = ns.core.CommandLine() - #cmd.AddValue("backboneNodes", "number of backbone nodes", backboneNodes) - #cmd.AddValue("infraNodes", "number of leaf nodes", infraNodes) - #cmd.AddValue("lanNodes", "number of LAN nodes", lanNodes) - #cmd.AddValue("stopTime", "simulation stop time(seconds)", stopTime) + cmd.AddValue("backboneNodes", "number of backbone nodes", str(backboneNodes)) + cmd.AddValue("infraNodes", "number of leaf nodes", str(infraNodes)) + cmd.AddValue("lanNodes", "number of LAN nodes", str(lanNodes)) + cmd.AddValue("stopTime", "simulation stop time(seconds)", str(stopTime)) # # The system global variables and the local values added to the argument @@ -104,6 +104,9 @@ def main(argv): # cmd.Parse(argv) + if (stopTime < 10): + print "Use a simulation stop time >= 10 seconds" + exit(1) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # / # # # Construct the backbone # @@ -138,7 +141,7 @@ def main(argv): internet.SetRoutingHelper(olsr); # has effect on the next Install () internet.Install(backbone); # re-initialize for non-olsr routing. - internet.Reset() + # internet.Reset() # # Assign IPv4 addresses to the device drivers(actually to the associated # IPv4 interfaces) we just created. @@ -159,8 +162,8 @@ def main(argv): x += 5.0 mobility.SetPositionAllocator(positionAlloc) mobility.SetMobilityModel("ns3::RandomDirection2dMobilityModel", - "Bounds", ns.mobility.RectangleValue(ns.mobility.Rectangle(0, 1000, 0, 1000)), - "Speed", ns.core.StringValue ("ns3::ConstantRandomVariable[Constant=2000]"), + "Bounds", ns.mobility.RectangleValue(ns.mobility.Rectangle(0, 20, 0, 20)), + "Speed", ns.core.StringValue ("ns3::ConstantRandomVariable[Constant=2]"), "Pause", ns.core.StringValue ("ns3::ConstantRandomVariable[Constant=0.2]")) mobility.Install(backbone) @@ -276,8 +279,8 @@ def main(argv): mobility.PushReferenceMobilityModel(backbone.Get(i)) mobility.SetPositionAllocator(subnetAlloc) mobility.SetMobilityModel("ns3::RandomDirection2dMobilityModel", - "Bounds", ns.mobility.RectangleValue(ns.mobility.Rectangle(-25, 25, -25, 25)), - "Speed", ns.core.StringValue ("ns3::ConstantRandomVariable[Constant=30]"), + "Bounds", ns.mobility.RectangleValue(ns.mobility.Rectangle(-10, 10, -10, 10)), + "Speed", ns.core.StringValue ("ns3::ConstantRandomVariable[Constant=3]"), "Pause", ns.core.StringValue ("ns3::ConstantRandomVariable[Constant=0.4]")) mobility.Install(infra) @@ -295,22 +298,23 @@ def main(argv): # Let's make sure that the user does not define too few LAN nodes # to make this example work. We need lanNodes >= 5 assert(lanNodes >= 5) - appSource = ns.network.NodeList.GetNode(11) - appSink = ns.network.NodeList.GetNode(13) - remoteAddr = ns.network.Ipv4Address("172.16.0.5") + appSource = ns.network.NodeList.GetNode(backboneNodes) + lastNodeIndex = backboneNodes + backboneNodes*(lanNodes - 1) + backboneNodes*(infraNodes - 1) - 1 + appSink = ns.network.NodeList.GetNode(lastNodeIndex) + # Let's fetch the IP address of the last node, which is on Ipv4Interface 1 + remoteAddr = appSink.GetObject(ns.internet.Ipv4.GetTypeId()).GetAddress(1,0).GetLocal() onoff = ns.applications.OnOffHelper("ns3::UdpSocketFactory", ns.network.Address(ns.network.InetSocketAddress(remoteAddr, port))) - onoff.SetConstantRate (ns.network.DataRate ("10kb/s")) apps = onoff.Install(ns.network.NodeContainer(appSource)) - apps.Start(ns.core.Seconds(3.0)) - apps.Stop(ns.core.Seconds(20.0)) + apps.Start(ns.core.Seconds(3)) + apps.Stop(ns.core.Seconds(stopTime - 1)) # Create a packet sink to receive these packets sink = ns.applications.PacketSinkHelper("ns3::UdpSocketFactory", ns.network.InetSocketAddress(ns.network.Ipv4Address.GetAny(), port)) apps = sink.Install(ns.network.NodeContainer(appSink)) - apps.Start(ns.core.Seconds(3.0)) + apps.Start(ns.core.Seconds(3)) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # / # # @@ -319,24 +323,21 @@ def main(argv): # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # / print "Configure Tracing." + csma = ns.csma.CsmaHelper() # # Let's set up some ns-2-like ascii traces, using another helper class # - #std.ofstream ascii - #ascii = ns.core.AsciiTraceHelper(); - #stream = ascii.CreateFileStream("mixed-wireless.tr"); - #wifiPhy.EnableAsciiAll(stream); - #csma.EnableAsciiAll(stream); - print "(tracing not done for Python)" - # Look at nodes 11, 13 only - # WifiHelper.EnableAscii(ascii, 11, 0); - # WifiHelper.EnableAscii(ascii, 13, 0); + ascii = ns.network.AsciiTraceHelper(); + stream = ascii.CreateFileStream("mixed-wireless.tr"); + wifiPhy.EnableAsciiAll(stream); + csma.EnableAsciiAll(stream); + internet.EnableAsciiIpv4All(stream); + # Csma captures in non-promiscuous mode + csma.EnablePcapAll("mixed-wireless", False) # Let's do a pcap trace on the backbone devices wifiPhy.EnablePcap("mixed-wireless", backboneDevices) - # Let's additionally trace the application Sink, ifIndex 0 - csma = ns.csma.CsmaHelper() - csma.EnablePcapAll("mixed-wireless", False) + wifiPhy.EnablePcap("mixed-wireless", appSink.GetId(), 0) # #ifdef ENABLE_FOR_TRACING_EXAMPLE # Config.Connect("/NodeList/*/$MobilityModel/CourseChange",