Bug 267

Summary: overload helpers that take NodeContainers to also take Ptr<Node>
Product: ns-3 Reporter: evensky
Component: helpersAssignee: ns-bugs <ns-bugs>
Status: RESOLVED INVALID    
Severity: minor    
Priority: P3    
Version: pre-release   
Hardware: All   
OS: All   

Description evensky 2008-07-30 18:38:22 UTC
I have a large set of overlapping NodeContainers that make up a network. I need to do things like InternetStackHelper::Install on these. It would be nice if methods that take a NodeContainer and operate on a Node at a time, would have versions that could also operate on a Ptr<Node>. This is related to 265, but not the same. I think these sorts of overloaded methods should exist, but they are much more necessary given the current state of the containers. I do have a work around, in that I can create potentially large temporaries and then nuke them, but that seems like bad c++ practice.
Comment 1 Mathieu Lacage 2008-07-30 18:50:54 UTC
I think that this bug is invalid. I wanted to point you to the relevant tutorial entry but it looks like this specific entry has disappeared from it.

So, there is magic involved but the following works already:

Ptr<Node> node = ;
NodeContainer c;
c.Install (node);

Comment 2 evensky 2008-07-30 19:29:20 UTC
I'm looking for InternetStackHelper::Install(Ptr<Node>), I can certainly use (and destroy the temporaries) InternetStackHelper::Install(NodeContainer), but it's a drag. I don't understand your response, so I can't comment on the resolved invalid.

Comment 3 Mathieu Lacage 2008-07-30 19:39:25 UTC
(In reply to comment #2)
> I'm looking for InternetStackHelper::Install(Ptr<Node>), I can certainly use
> (and destroy the temporaries) InternetStackHelper::Install(NodeContainer), but
> it's a drag. I don't understand your response, so I can't comment on the
> resolved invalid.

I don't understand what you want to do: maybe you could paste below the code you want to write and outline why the current codebase makes that hard/impossible/inappropriate.
Comment 4 Rajib Bhattacharjea 2008-07-30 22:38:45 UTC
David, Mathieu is saying that InternetStackHelper::Install WILL work with a Ptr<Node> as a parameter.  I think he meant "InternetStackHelper c" instead of "NodeContainer c" in his code example.  That is, the following will compile and do what you expect:

InternetStackHelper internet;
Ptr<Node> oneNode = CreateObject<Node> ();
internet.Install(oneNode);

The InternetStackHelper::Install(Ptr<Node>) API you are looking for however doesn't exist in the code, but the case is handled implicitly via the magic Mathieu speaks of: an implicit conversion from Ptr<Node> to a NodeContainer with exactly one entry, via the constructor NodeContainer::NodeContainer(Ptr<Node>).
Comment 5 Craig Dowell 2008-08-01 11:56:23 UTC
The section of the tutorial referring to this idiom follows.  The detailed explanation was removed and will end up in an appendix.

----------

The following lines of code in our example script, first.cc, are used to set up a UDP echo server application on one of the nodes we have previously created. 

    UdpEchoServerHelper echoServer (9);

    ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
    serverApps.Start (Seconds (1.0));
    serverApps.Stop (Seconds (10.0));

The first line of code in the above snippet declares the UdpEchoServerHelper. As usual, this isn't the application itself, it is an object used to help us create the actual applications. One of our conventions is to place required attributes in the helper constructor. In this case, the helper can't do anything useful unless it is provided with a port number that the client also knows about. Rather than just picking one and hoping it all works out, we require the port number as a parameter to the constructor. The constructor, in turn, simply does a SetAttribute with the passed value. You can, if desired, set the "Port" attribute to another value later. 

Similar to many other helper objects, the UdpEchoServerHelper object has an Install method. It is the execution of this method that actually causes the underlying echo server application to be instantiated and attached to a node. Interestingly, the Install method takes a NodeContainter as a parameter just as the other Install methods we have seen. This is actually what is passed to the method even though it doesn't look so in this case. There is a C++ implicit conversion at work here.