Search code examples
initializationnodesns-3

In ns-3 simulator when to use p2p nodes, wifistanodes and csmanodes


I'm trying to use NS-3 simulator to do some tests between random waypoint model and some other models. While during the simulation I found that when need to run the simulation we need to initiate the model by using a class called

MobilityHelper

Code below is the part of the code that I am using. During the initialization, there are some nodes need to be created beforehand such as

p2pNodes

csmaNodes

So what do these nodes mean, and in which situation need to use them? Are they specify to some specific mobility models? If so please give some details, many thanks!

  NodeContainer p2pNodes;
  p2pNodes.Create (3);

  PointToPointHelper pointToPoint;
  pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
  pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));

  NetDeviceContainer p2pDevices;
  p2pDevices = pointToPoint.Install (p2pNodes);

  NodeContainer csmaNodes;
  csmaNodes.Add (p2pNodes.Get (1));
  csmaNodes.Create (nCsma);

  CsmaHelper csma;
  csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps"));
  csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (6560)));

  NetDeviceContainer csmaDevices;
  csmaDevices = csma.Install (csmaNodes);

Solution

  • p2pNodes and csmaNodes are simply variable names for the NodeContainer used in this particular example in order to keep track of nodes for the two networks (the Point-to-Point and the CSMA). The fact that you named them p2pNodes and csmaNodes is only for your own convenience. What matters are the types of NetDevices that end up being installed on these nodes.

    In any case, that has nothing to do with the MobilityModel that you install. Both P2P and CSMA are wired networks and I wouldn't think of adding a random mobility on those. It wouldn't make sense to move around with a wire attached to you..!

    Note that the above example code will crash, as you have created 3 p2pNodes, and a point-to-point link can only be instantiated between two nodes.

    I would recommend studying the ns-3 tutorial to get an understanding of the concepts of Node, NodeContainer (ie. vectors of Nodes), NetDevice (ie. the network card/type), MobilityModel etc.