I have below code. I am trying to iterate through my hosts and create UDP client and server application. My topology has a csma bridge that has many hosts. I am adding udp client and server application ever 60 seconds.
I know what the ip addresses of each host in const char type. but when going through each hosts in a loop, the ip address will also change. i want to assign that number to integer and pass it to ipv4Address class.
Can somebody help me with how i can convert the string value of ipv4 address to integer?
// We've got the "hardware" in place. Now we need to add IP addresses.
//
printf ("Assign IP Addresses.\n");
Ipv4AddressHelper ipv4;
ipv4.SetBase ("10.1.1.0", "255.255.255.0");
ipv4.Assign (terminalDevices);
....
....
......
for(int i = 0; i < 3600; i += 60)
{
randomClientNode = getRandomNumber(0,49);
printf("Random Client Node %d\n",randomClientNode);
randomServerNode = getRandomNumber(0,49);
printf("Random Server Node %d\n",randomServerNode);
if(randomClientNode != randomServerNode)
{
if( previousClientNode != randomClientNode)
{
// Traffic Generater
int trafficGenIpNumber = randomServerNode + 1;
OnOffHelper onoff("ns3::UdpSocketFactory", Address (InetSocketAddress (Ipv4Address ("10.1.1.randomServerNode"), port)));
onoff.SetAttribute("PacketSize", UintegerValue(1024));
app.Add(onoff.Install (terminals.Get (randomClientNode)));
// Start the application
app.Start (Seconds (i));
app.Stop (Seconds (3600 - i));
//Traffic receiver
// Create an optional packet sink to receive these packets
PacketSinkHelper sink("ns3::UdpSocketFactory",Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
sinkApps.Add(sink.Install (terminals.Get (randomServerNode)));
sinkApps.Start (Seconds (0.0));
}
}
previousClientNode = randomClientNode;
}