Change UDP parameters at simulation runtime

159 views
Skip to first unread message

anas

unread,
Aug 7, 2019, 8:39:05 AM8/7/19
to ns-3-users
Hi,

I have a small and simple simulation where i have multiple nodes connected with wifi and lte at the same time. In simulation node 1 sends data from udp client helper to node 0 udp server via LTE.
Now after half simulation time e.g. 5 seconds, i want to change the destination ip address in udp client app (node1) to wifi ip address of node 0 so that data transfer will occur through wifi.

I am trying to do this with schedule() function and setAttributes() function but new ip address does not takes any effect.With this I have output the current ip address, in udp client whenever it sends a packet, with cout command. But the destination ip addres in udp client always remains the same i.e. the one with which it was configured initially.
Is there any way to modify such variables during runtime?

My basic applications configuration and changing of ip address is like following:

-----------------------------------------------------------------------------------------------------------------------------------
// changing ip address function
void reconfigureUdpClient(UdpClientHelper srcNode, Ptr<Node> dstNode, uint16_t dport)
{
  Ptr<Ipv4> ipv4 = dstNode->GetObject<Ipv4>();
  Ipv4Address ip = ipv4->GetAddress(1,0).GetLocal();

  srcNode.SetAttribute("RemotePort", UintegerValue(dport));
  srcNode.SetAttribute("RemoteAddress", AddressValue(ip));
}

// Simulation code
uint16_t dport =5001, dport1 = 6001;

UdpClientHelper dlClient ( ueIpIface.GetAddress(0), dport );  // udp source application

dlClient.SetAttributes ( "Interval", TimeValue( Milliseconds ( interPacketInterval ) ) );
dlClient.SetAttributes ( "MaxPackets", UIntegerValue ( 100000000 ) );
dlClient.SetAttributes ( "PacketSize" , UIntegerValue ( payloadSize ) );
dlClient.SetAttributes ( "StartTime", TimeValue( Milliseconds ( 1000 ) ) );
dlClient.SetAttributes ( "StopTime", TimeValue( Milliseconds ( 10000 ) ) );

clientApps.Add ( dlClient.Install ( ueNode.Get(1) ) );

UdpServerHelper dlPacketSinkHelper (dport);
serverApps.Add ( dlPacketSinkHelper.Install ( ueNode.Get(0) ) );

Simulator::Stop(Seconds(duration + 1));
Simulator::Schedule (Seconds (5), &reconfigureUdpClient, dlClient, ueNode.Get(0), dport1);
Simulator::Run ();
-----------------------------------------------------------------------------------------------------------------------------------

Regards,
Anas

Laura Michaella Ribeiro

unread,
Mar 17, 2020, 8:13:22 AM3/17/20
to ns-3-users
Hi, Anas

Sorry, I don't have your answer, but I'm also needing simular things that you. 

An advice about your problem: Have you been seen the ns3-lbt-dev? https://bitbucket.org/ns3lteu/lte-wifi-coexistence/src/master/

I'm using src/laa-wifi-coexistence like base to develop my solution, using https://bitbucket.org/ns3lteu/lte-wifi-coexistence/src/master/examples/lte-wifi-indoor.cc example. In there, they include https://bitbucket.org/ns3lteu/lte-wifi-coexistence/src/master/helper/scenario-helper.cc to define a coexistence scenario sending UDP, FTP or TCP employing changes at simulation runtime, I think it can be useful for you

Now, I'm working in an interface manager, where according to network performance metrics like throughput, RSSI, latency, and etc obtained from the last messages sended, the interface manager define the better network interface for nodes to send the next messages at simulation runtime.

So, I need to change network interfaces (LTE, Wave, Wifi ) at simulation runtime.  And, for the interface manager define which interface to apply I need to get these  network performance metrics dynamically. Could you help me, please? 

Regards, Laura

Jian Liu

unread,
Mar 17, 2022, 9:39:08 PM3/17/22
to ns-3-users
Do you have any progress on this question? I am also facing the same problem.

Soulimane Mammar

unread,
Mar 20, 2022, 1:12:00 PM3/20/22
to ns-3-users
Hi,
In function reconfigureUdpClient you are changing the attributes for the helper object,   this object is used once to create the client application, changing its attributes afterwords will not affect the application installed on the client.
Regards

Soulimane Mammar

unread,
Mar 20, 2022, 5:12:48 PM3/20/22
to ns-3-users
Hi,
Furthermore, once the application created you can change its attributes as long it has not yet started. But  once started, you can't change its remote address and port anymore as the StartApplication() member function will create a socket object corresponding to those parameters and changing them afterwards is not possible.
Your problem has nothing to do with udpclient/udpserver configuration. If I'm not mistaken you want to change the sending interface at some point in time.
For this, you just install two netdevices (wifi and lte) on node 1 (the client) and two ipv4/ipv6 interfaces with proper addresses (each address in a different subnet) and configure the routing properly.
Whenever you want to switch from lte to wifi (or vise versa) you simply disable the interface you don't want to use and enable the other one and let the routing do its job.
Regards

Reply all
Reply to author
Forward
0 new messages