diff --git a/examples/tutorial/third.cc b/examples/tutorial/third.cc old mode 100644 new mode 100755 index ef07a1bda..e6360c4ae --- a/examples/tutorial/third.cc +++ b/examples/tutorial/third.cc @@ -44,19 +44,23 @@ main (int argc, char *argv[]) bool verbose = true; uint32_t nCsma = 3; uint32_t nWifi = 3; + bool tracing = false; CommandLine cmd; cmd.AddValue ("nCsma", "Number of \"extra\" CSMA nodes/devices", nCsma); cmd.AddValue ("nWifi", "Number of wifi STA devices", nWifi); cmd.AddValue ("verbose", "Tell echo applications to log if true", verbose); + cmd.AddValue ("tracing", "Enable pcap tracing", tracing); cmd.Parse (argc,argv); - if (nWifi > 18) + // Check for valid number of csma or wifi nodes + // 250 should be enough, otherwise IP addresses + // soon become an issue + if (nWifi > 250 || nCsma > 250) { - std::cout << "Number of wifi nodes " << nWifi << - " specified exceeds the mobility bounding box" << std::endl; - exit (1); + std::cout << "Too many wifi or csma nodes, no more than 250 each." << std::endl; + return 1; } if (verbose) @@ -169,9 +173,16 @@ main (int argc, char *argv[]) Simulator::Stop (Seconds (10.0)); - pointToPoint.EnablePcapAll ("third"); - phy.EnablePcap ("third", apDevices.Get (0)); - csma.EnablePcap ("third", csmaDevices.Get (0), true); + if (tracing == true) + { + pointToPoint.EnablePcapAll ("third-distributed-wifi"); + phy.EnablePcap ("third-distributed-wifi", apDevices.Get (0)); + csma.EnablePcap ("third-distributed-wifi", csmaDevices.Get (0), true); + + pointToPoint.EnablePcapAll ("third-distributed-csma"); + phy.EnablePcap ("third-distributed-csma", apDevices.Get (0)); + csma.EnablePcap ("third-distributed-csma", csmaDevices.Get (0), true); + } Simulator::Run (); Simulator::Destroy (); diff --git a/src/mpi/examples/third-distributed.cc b/src/mpi/examples/third-distributed.cc old mode 100644 new mode 100755 index 07b6fb5e4..40624f9b0 --- a/src/mpi/examples/third-distributed.cc +++ b/src/mpi/examples/third-distributed.cc @@ -15,26 +15,23 @@ */ #include "ns3/core-module.h" +#include "ns3/point-to-point-module.h" #include "ns3/network-module.h" +#include "ns3/applications-module.h" #include "ns3/wifi-module.h" #include "ns3/mobility-module.h" -#include "ns3/mpi-interface.h" -#include "ns3/ipv4-global-routing-helper.h" -#include "ns3/udp-echo-helper.h" -#include "ns3/point-to-point-helper.h" -#include "ns3/csma-helper.h" -#include "ns3/internet-stack-helper.h" -#include "ns3/ipv4-address-helper.h" -#include "ns3/ipv4-interface-container.h" +#include "ns3/csma-module.h" +#include "ns3/internet-module.h" -#ifdef NS3_MPI -#include -#endif +#include "ns3/mpi-module.h" -// Default Network Topology (same as third.cc from tutorial) +// Default Network Topology +// (same as third.cc from tutorial) // Distributed simulation, split along the p2p link // Number of wifi or csma nodes can be increased up to 250 -// +// | +// Rank 0 | Rank 1 +// -------------------------|---------------------------- // Wifi 10.1.3.0 // AP // * * * * @@ -42,10 +39,7 @@ // n5 n6 n7 n0 -------------- n1 n2 n3 n4 // point-to-point | | | | // ================ -// | LAN 10.1.2.0 -// | -// Rank 0 | Rank 1 -// -------------------------|---------------------------- +// LAN 10.1.2.0 using namespace ns3; @@ -54,20 +48,19 @@ NS_LOG_COMPONENT_DEFINE ("ThirdExampleDistributed"); int main (int argc, char *argv[]) { -#ifdef NS3_MPI - bool verbose = true; uint32_t nCsma = 3; uint32_t nWifi = 3; - bool nullmsg = false; bool tracing = false; + bool nullmsg = false; CommandLine cmd; cmd.AddValue ("nCsma", "Number of \"extra\" CSMA nodes/devices", nCsma); cmd.AddValue ("nWifi", "Number of wifi STA devices", nWifi); cmd.AddValue ("verbose", "Tell echo applications to log if true", verbose); - cmd.AddValue ("nullmsg", "Enable the use of null-message synchronization", nullmsg); cmd.AddValue ("tracing", "Enable pcap tracing", tracing); + cmd.AddValue ("nullmsg", "Enable the use of null-message synchronization", nullmsg); + cmd.Parse (argc,argv); // Check for valid number of csma or wifi nodes @@ -75,7 +68,7 @@ main (int argc, char *argv[]) // soon become an issue if (nWifi > 250 || nCsma > 250) { - std::cout << "Too many wifi or csma nodes, max 200 each." << std::endl; + std::cout << "Too many wifi or csma nodes, no more than 250 each." << std::endl; return 1; } @@ -85,6 +78,12 @@ main (int argc, char *argv[]) LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO); } + // Sequential fallback values + uint32_t systemId = 0; + uint32_t systemCount = 1; + +#ifdef NS3_MPI + // Distributed simulation setup; by default use granted time window algorithm. if(nullmsg) { @@ -99,8 +98,8 @@ main (int argc, char *argv[]) MpiInterface::Enable (&argc, &argv); - uint32_t systemId = MpiInterface::GetSystemId (); - uint32_t systemCount = MpiInterface::GetSize (); + systemId = MpiInterface::GetSystemId (); + systemCount = MpiInterface::GetSize (); // Check for valid distributed parameters. // Must have 2 and only 2 Logical Processors (LPs) @@ -110,10 +109,17 @@ main (int argc, char *argv[]) return 1; } +#endif // NS3_MPI + // System id of Wifi side + uint32_t systemWifi = 0; + + // System id of CSMA side + uint32_t systemCsma = systemCount - 1; + NodeContainer p2pNodes; - Ptr p2pNode1 = CreateObject (0); // Create node with rank 0 - Ptr p2pNode2 = CreateObject (1); // Create node with rank 1 + Ptr p2pNode1 = CreateObject (systemWifi); // Create node with rank 0 + Ptr p2pNode2 = CreateObject (systemCsma); // Create node with rank 1 p2pNodes.Add (p2pNode1); p2pNodes.Add (p2pNode2); @@ -126,7 +132,7 @@ main (int argc, char *argv[]) NodeContainer csmaNodes; csmaNodes.Add (p2pNodes.Get (1)); - csmaNodes.Create (nCsma, 1); // Create csma nodes with rank 1 + csmaNodes.Create (nCsma, systemCsma); // Create csma nodes with rank 1 CsmaHelper csma; csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps")); @@ -136,7 +142,7 @@ main (int argc, char *argv[]) csmaDevices = csma.Install (csmaNodes); NodeContainer wifiStaNodes; - wifiStaNodes.Create (nWifi, 0); // Create wifi nodes with rank 0 + wifiStaNodes.Create (nWifi, systemWifi); // Create wifi nodes with rank 0 NodeContainer wifiApNode = p2pNodes.Get (0); YansWifiChannelHelper channel = YansWifiChannelHelper::Default (); @@ -168,12 +174,12 @@ main (int argc, char *argv[]) "MinX", DoubleValue (0.0), "MinY", DoubleValue (0.0), "DeltaX", DoubleValue (5.0), - "DeltaY", DoubleValue (5.0), - "GridWidth", UintegerValue (10), + "DeltaY", DoubleValue (10.0), + "GridWidth", UintegerValue (3), "LayoutType", StringValue ("RowFirst")); mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel", - "Bounds", RectangleValue (Rectangle (-250, 250, -250, 250))); + "Bounds", RectangleValue (Rectangle (-50, 50, -50, 50))); mobility.Install (wifiStaNodes); mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); @@ -198,25 +204,26 @@ main (int argc, char *argv[]) address.Assign (staDevices); address.Assign (apDevices); - // If this simulator has system id 1, then + // If this rank is systemCsma, // it should contain the server application, // since it is on one of the csma nodes - if (systemId == 1) + if (systemId == systemCsma) { UdpEchoServerHelper echoServer (9); + ApplicationContainer serverApps = echoServer.Install (csmaNodes.Get (nCsma)); serverApps.Start (Seconds (1.0)); serverApps.Stop (Seconds (10.0)); } - // If the simulator has system id 0, then + // If this rank is systemWifi // it should contain the client application, // since it is on one of the wifi nodes - if (systemId == 0) + if (systemId == systemWifi) { UdpEchoClientHelper echoClient (csmaInterfaces.GetAddress (nCsma), 9); echoClient.SetAttribute ("MaxPackets", UintegerValue (1)); - echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.))); + echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0))); echoClient.SetAttribute ("PacketSize", UintegerValue (1024)); ApplicationContainer clientApps = @@ -235,28 +242,28 @@ main (int argc, char *argv[]) // traced will be different. For example, the ethernet pcap // will be empty for rank0, since these nodes are placed on // on rank 1. All ethernet traffic will take place on rank 1. - // Similar differences are seen in the p2p and wirless pcaps. - if (systemId == 0) + // Similar differences are seen in the p2p and wireless pcaps. + if (systemId == systemWifi) { - pointToPoint.EnablePcapAll ("third-distributed-rank0"); - phy.EnablePcap ("third-distributed-rank0", apDevices.Get (0)); - csma.EnablePcap ("third-distributed-rank0", csmaDevices.Get (0), true); + pointToPoint.EnablePcapAll ("third-distributed-wifi"); + phy.EnablePcap ("third-distributed-wifi", apDevices.Get (0)); + csma.EnablePcap ("third-distributed-wifi", csmaDevices.Get (0), true); } - else + else // systemCsma { - pointToPoint.EnablePcapAll ("third-distributed-rank1"); - phy.EnablePcap ("third-distributed-rank1", apDevices.Get (0)); - csma.EnablePcap ("third-distributed-rank1", csmaDevices.Get (0), true); + pointToPoint.EnablePcapAll ("third-distributed-csma"); + phy.EnablePcap ("third-distributed-csma", apDevices.Get (0)); + csma.EnablePcap ("third-distributed-csma", csmaDevices.Get (0), true); } } Simulator::Run (); Simulator::Destroy (); + +#ifdef NS3_MPI // Exit the MPI execution environment MpiInterface::Disable (); - return 0; - -#else - NS_FATAL_ERROR ("Can't use distributed simulator without MPI compiled in"); #endif + + return 0; }