Trouble assigning loopback device address to two nodes using Linux stack

88 views
Skip to first unread message

D. B, R. S.

unread,
Feb 17, 2015, 6:13:46 PM2/17/15
to ns-3-...@googlegroups.com
Hello,
I have a network with two nodes. A "type" was assigned to each node through aggregation (the first node is of type A, and the second is of type B); moreover,  each node has several attached devices. I need the device 0 of each node to be the loopback; which is not a problem for a node working with the NS3 stack. When I assign the Linux stack to the nodes, I have to create the loopback, but I have problems assigning the address "127.0.0.1" to both of them. I have unsuccessfully tried the following approaches:


1. The first approach is using ipv4AddressHelper. Below you can see the definition of the loopback and its addressing:

/*  The following variables are defined in a .h file:
DceManagerHelper dceManagerHelper;  
LinuxStackHelper linuxStackHelper;
IpAddress loopbackIpAddress = IpAddress::GetLoopback ();
IpMask loopbackIpMask =  IpMask::GetLoopback ();
IpAddressHelper loopbackAddress;  */



dceManagerHelper
.SetNetworkStack ("ns3::LinuxSocketFdFactory","Library", StringValue ("liblinux.so"));
linuxStackHelper
.Install (node);
dceManagerHelper
.Install(node);

Ptr<LoopbackNetDevice> loopbackNetDev = 0;
for (uint32_t devCounter = 0; devCounter < node->GetNDevices (); devCounter++){
   
if ((loopbackNetDev = DynamicCast<LoopbackNetDevice> (node->GetDevice (devCounter)))){
       
break;
   
}
    PRINT_STDOUT
(<< " No loopback found");
}

if ( loopbackNetDev == 0 ){
    loopbackAddress
.SetBase(loopbackIpAddress, loopbackIpMask);
    loopbackNetDev
= CreateObject<LoopbackNetDevice> ();
   
NetDeviceContainer loopbackNetDevCont;
    loopbackNetDevCont
.Add(loopbackNetDev);
    node
->AddDevice (loopbackNetDev);
   
IpInterfaceContainer loopbackInterfaceContainer = loopbackAddress.Assign (loopbackNetDevCont);
    loopbackIpAddress
= loopbackAddress.NewAddress();
   
//loopbackIpAddress = loopbackAddress.NewNetwork();    //
    uint32_t nNodes
= loopbackInterfaceContainer.GetN ();
   
for (uint32_t i = 0; i < nNodes; ++i)
   
{
        std
::pair<Ptr<Ipv4>, uint32_t> pair = loopbackInterfaceContainer.Get (i);
   
     PRINT_STDOUT
( << " Node " << i << " in interface container has address " <<   pair.first << " stored at location " << pair.second);  // use the pair
   
}
}

Next you can see some information related to the network and nodes after running the code:


NS-3>TYPEANode 0 with 2 devices
<NS-3>
<NS-3>IP address/device address for interface 0: 127.0.0.1/02-06-00:00:00:00:00:00
<NS-3>device 1 has address 02-06-00:00:00:00:00:00
<NS-3>TYPEANode 1 with 0 devices
<NS-3> has no assigned address
<NS-3>0 Ns3InterfaceModule::printInventoryFor:
<NS-3>TYPEBNode 0 with 2 devices
<NS-3>
<NS-3>IP address/device address for interface 0: 127.0.0.1/02-06-00:00:00:00:00:00
<NS-3>device 1 has address 02-06-00:00:00:00:00:00
<NS-3>HOSTNode 1 with 0 devices
<NS-3> has no assigned address
<NS-3>Added NS3 Ipv4 class to node 1
 Address generator information: addr = 2130706433
examining entries: 2130706433 to 2130706434
 msg="Ipv4AddressGeneratorImpl::Add(): Address Collision: 127.0.0.1. Fatal: Address 127.0.0.1 falls in previously allocated block. Block: [127.0.0.1,127.0.0.2]", file=../model/ipv4-address-generator.cc, line=385
terminate called without an active exception


It does not matter how many times I run "loopbackAddress.NewAddress();" I always get a collision error message.
If instead of loopbackIpAddress = loopbackAddress.NewAddress();  I use "loopbackIpAddress = loopbackAddress.NewNetwork();",  I get


net:0, nodeiId=0, type=TYPEA, paired with [1]
    device 0: 127.0.0.1,255.0.0.0,00:00:00:00:00:00(0)
    device 1: 10.128.0.1,255.255.0.0,00:00:00:00:00:00(1)
    device 2: 10.64.0.1,255.255.255.0,00:00:00:00:00:01(2)
    device 3: ,,(0)
net 0 now has 1 nodes

net:0, nodeiId=1, type=TYPEB, paired with [0]
    device 0: 128.0.0.1,255.0.0.0,00:00:00:00:00:00(0)
    device 1: 10.64.0.2,255.255.255.0,00:00:00:00:00:02(1)
    device 2: ,,(0)
    device 3: ,,(0)
net 0 now has 2 nodes


2. The second approach is to try to follow the steps in Ipv4L3Protocol
dceManagerHelper.SetNetworkStack ("ns3::LinuxSocketFdFactory","Library", StringValue ("liblinux.so"));
linuxStackHelper
.Install (node);
dceManagerHelper
.Install(node);
Ptr<Ipv4Linux> ip4 = CreateObject<Ipv4Linux> ();
ip4
= node->GetObject<Ipv4Linux>();
Ptr<LoopbackNetDevice> loopbackNetDev = 0;
for (uint32_t devCounter = 0; devCounter < node->GetNDevices (); devCounter++){
   
if ((loopbackNetDev = DynamicCast<LoopbackNetDevice> (node->GetDevice (devCounter)))){
       
break;
   
}
    PRINT_STDOUT
(<< " No loopback found");
}

Ptr<Ipv4Interface> interface = CreateObject<Ipv4Interface> ();
//const uint16_t PROT_NUMBER = 0x0800;
if (loopbackNetDev == 0)
{
    loopbackNetDev
= CreateObject<LoopbackNetDevice> ();
    node
->AddDevice (loopbackNetDev);
   
interface->SetDevice (loopbackNetDev);
   
interface->SetNode (node);
   
//Ipv4InterfaceAddress ifaceAddr = Ipv4InterfaceAddress (Ipv4Address::GetLoopback (), Ipv4Mask::GetLoopback ());
   
//uint32_t index =ip4->Ipv4Linux::AddIpv4Interface(interface);
   
//node->RegisterProtocolHandler (MakeCallback (&Ipv4L3Protocol::Receive, this),PROT_NUMBER, loopbackNetDev);
   
//interface->SetUp ();
}


In this case, I did not find the way of implementing the equivalent of RegisterProtocolHandler for Ipv4Linux.



Thank you for your time to read my message. Any suggestion regarding this issue is welcome.
Best regards,

Dilia Rueda
Reply all
Reply to author
Forward
0 new messages