c++ns-3

How can i adding more nodes in first.cc in ns3?


I've just learned about first.cc and I want to change the number of nodes in first.cc from 2 to 3 or 4 5, but changing only nodes.Create(2) ==> nodes.Create(3) causes me some errors like this

assert failed.cond="c.GetN () ==2" , +0.00000000s -1 file=../src/point-to-point/helper/point-to-point-helper.cc, line=224 terminate called without an active exception

So I've to add some connection between them or else? Any help or suggestion will be appreciated!


Solution

  • I want to start by encouraging you to use gdb (or lldb) to debug the program. If you did this, you would have found that this line in first.cc is causing the error:

    devices = pointToPoint.Install (nodes);
    

    Why would this happen? Well, if we go to the definition of the function being called, we find:

    NetDeviceContainer 
    PointToPointHelper::Install (NodeContainer c)
    {
        NS_ASSERT (c.GetN () == 2);              // line 224
        return Install (c.Get (0), c.Get (1));
    }
    

    Looking at this code, it is clear that the PointToPointHelper::Install(NodeContainer) imposes the constraint that the NodeContainer can only contain two Nodes. This explains how the error you encountered occurred.

    But why?

    It's a (good) design choice. A PointToPointChannel can only be installed between exactly two PointToPointNetDevices, not more, not less. So, the implementation imposes the constraint that the NodeContainer can only contain two Nodes.