Dynamic node creation and deletion during simulation in ns3

2,517 views
Skip to first unread message

Dorice Diane Ngueguia

unread,
Nov 25, 2009, 11:24:25 AM11/25/09
to ns-3-...@googlegroups.com
Hi,

I am trying to write a simulation model for ns3 and I need your help please for the following issue :

At the begining of the simulation I have a node say N. I would like to dynamically create nodes and link them to N throught PointToPoint Channels. I want all my address to look like this : "192.168.1.X". Since I need only 2 addresses for a point to point network, I have chosen the subnet mask to be "255.255.255.252", thus enabling me to create 64 subnets, that is 64 new nodes,  and to assign Ipv4  addresses to them. (192.168.1.00000000 to 192.168.1.11111100)

To avoid address collision, I have a mecanism to detect wether there are available addresses or not. So after having created 64 nodes, I need to delete some nodes so as to recover their ipv4 addresses. Is there any way to :
      -given a certain node, to know wether the application installed on it is still running or not (note that the application installed on my node is a very small one, needing some       few seconds to end and get stopped)
      -"unassign" the ipv4addresses allocated to the corresponding NetDeviceContainer (in such a way to be able to "reassign" those addresses later
      -delete the node, and corresponding NodeContainer, NetDeviceContainer and Ipv4InterfaceContainer
  
Or any other way to solve that issue.

Thank you very much

Dorice

Antti Mäkelä

unread,
Nov 25, 2009, 4:47:39 PM11/25/09
to ns-3-users
On Nov 25, 6:24 pm, Dorice Diane Ngueguia <doricedi...@gmail.com>
wrote:

>       -given a certain node, to know wether the application installed on it
> is still running or not (note that the application installed on my node is a
> very small one, needing some       few seconds to end and get stopped)

If your application is inherited from the generic Application at
least, you could simply create some sort of IsRunning() method that
would return that information. Or the runtime is statically known then
just check if Now() > Starttime+Runtime.

>       -"unassign" the ipv4addresses allocated to the corresponding
> NetDeviceContainer (in such a way to be able to "reassign" those addresses
> later
>       -delete the node, and corresponding NodeContainer, NetDeviceContainer
> and Ipv4InterfaceContainer

I have asked this myself. You can't delete nodes, or what's more
problematic, links after they have been created. You can "switch them
off" and make it appear as if they are not present (set interfaces
down and so on), but not totally delete. I have this problem myself
with dynamically arriving and leaving nodes - no objects can be
deleted.

However, almost anything can be manipulated. So, set links down to
the node and it's effectively removed from the network. You *can*
reassign IP addresses at will. Just use Ipv4::RemoveAddress, and then
assign a new one. Use Node->GetObject<Ipv4>()->RemoveAddress(x,y).

Anyway, if you just want to assign IP addresses out-of-band (not
implement e.g. a full-scale DHCP client/server), I'm not sure why
can't you just do a std::map<Ipv4Address, Node> to store what's
assigned where, or use whatever data structure suits you to keep the
track.

Dorice Diane Ngueguia

unread,
Nov 27, 2009, 5:28:09 AM11/27/09
to ns-3-...@googlegroups.com
Tank you much for getting interest on my problem.

I think I have done what you suggested : this is a simple version of my source code (without checking instructions) : ra is a Ptr<Application> containing a smart pointer to the application installed on my central node. Here I remove all its addresses and set down it interfaces.

for(int i = 0; i < (int)ra->GetNode()->GetObject<Ipv4>()->GetNInterfaces()-2; i++)
         if(ra->GetNode()->GetObject<Ipv4>()->RemoveAddress(i+2,0))ra->GetNode()->GetObject<Ipv4>()->SetDown(i+2);

This runs well, but when I try to reassign the the removed addresses, I get an address collision error. I wonder what is wrong.

Please help.

Antti Mäkelä

unread,
Nov 27, 2009, 10:14:55 AM11/27/09
to ns-3-users
On Nov 27, 12:28 pm, Dorice Diane Ngueguia <doricedi...@gmail.com>
wrote:
> for(int i = 0; i <
> (int)ra->GetNode()->GetObject<Ipv4>()->GetNInterfaces()-2; i++)
>
> if(ra->GetNode()->GetObject<Ipv4>()->RemoveAddress(i+2,0))ra->GetNode()->GetObject<Ipv4>()->SetDown(i+2);
>
> This runs well, but when I try to reassign the the removed addresses, I get
> an address collision error. I wonder what is wrong.

Are you assigning them using helper or directly to the Ipv4 object?

cra...@ee.washington.edu

unread,
Nov 27, 2009, 2:07:29 PM11/27/09
to ns-3-...@googlegroups.com

> This runs well, but when I try to reassign the the removed addresses, I
> get an address collision error. I wonder what is wrong.
>
> Please help.

If the fatal error is, "Ipv4AddressGeneratorImpl::Add(): Address Collision"
then you are asking the system to automatically generate the same
combination of network number and address twice. This is considered a
programming error.

Reusing an existing address is different from trying to make the system
allocate the same address twice.

-- Craig



Dorice Diane Ngueguia

unread,
Nov 30, 2009, 4:08:29 AM11/30/09
to ns-3-...@googlegroups.com
I am using an Ipv4AddressHelper named address, these are the instructions :

 address.SetBase (Ipv4Address(buffer), "255.255.255.252");
 p2pinterfaces = address.Assign (p2pdevices);

where the buffer variable contains a string corrresponding to the network base address

 


--

You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To post to this group, send email to ns-3-...@googlegroups.com.
To unsubscribe from this group, send email to ns-3-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ns-3-users?hl=en.



Message has been deleted

Antti Mäkelä

unread,
Nov 30, 2009, 7:32:31 AM11/30/09
to ns-3-users
On Nov 30, 11:08 am, Dorice Diane Ngueguia <doricedi...@gmail.com>
wrote:
> I am using an Ipv4AddressHelper named address, these are the instructions :
>
>  address.SetBase (Ipv4Address(buffer), "255.255.255.252");
>  p2pinterfaces = address.Assign (p2pdevices);
>
> where the buffer variable contains a string corrresponding to the network
> base address

From the helper's perspective, the address has already been
assigned. Helper doesn't know that you have taken it away. You should
assign the address using ipv4::AddAddress method and only use the
helper with the initial assignment, if at all.

Dorice Diane Ngueguia

unread,
Dec 1, 2009, 5:22:09 AM12/1/09
to ns-3-...@googlegroups.com
Now, I not using the helper for address assignement, but still getting the same fatal error,

Ipv4AddressGeneratorImpl::Add(): Address Collision: 192.168.1.1

Craig, you were talked about reusing an existing address, different from trying to make the system
allocate the same address twice. How can I do it, please ?

Tank you




On Mon, Nov 30, 2009 at 1:31 PM, Antti Mäkelä <zar...@gmail.com> wrote:
On Nov 30, 11:08 am, Dorice Diane Ngueguia <doricedi...@gmail.com>

wrote:

 From the helper's perspective, the address has already been
assigned. Helper doesn't know that you have taken it away. You should
assign the address using ipv4::AddAddress method and only use the
helper with the initial assignment, if at all.

Peshal Nayak

unread,
Nov 26, 2014, 3:45:54 AM11/26/14
to ns-3-...@googlegroups.com, doric...@gmail.com
Hi Dorice,

I'm trying to turn off some nodes in my simulation during run time. Is it possible for you to send me a sample code so that I may know where in the code I need to make changes.

Peshal

On Monday, December 14, 2009 8:51:53 AM UTC-6, Dorice Diane Ngueguia wrote:
Hi, I have finally fixed my bug. I used low level instructions, rather than the Ipv4AddressHelper. I was using the following instruction "Ipv4AddressGenerator::AddAllocated (addr);" which causes the Ipv4AddressGenerator to check whether the specified address has already been created. I just had to remove it and perform myselff the required checking

Tank you very much for your help

Tommaso Pecorella

unread,
Nov 26, 2014, 12:18:34 PM11/26/14
to ns-3-...@googlegroups.com, doric...@gmail.com
2009 is 5 years ago.

Dorice Diane Ngueguia

unread,
Dec 14, 2009, 9:51:53 AM12/14/09
to ns-3-...@googlegroups.com

4917...@qq.com

unread,
Feb 17, 2019, 3:03:24 AM2/17/19
to ns-3-users
Hi, I also want to implement the dynamic creation and deletion of nodes, but I really don't know the method. 

Can you share your code?

Thank you!
Reply all
Reply to author
Forward
0 new messages