for (double s=0; s<100000; s++){
Simulator::Schedule(MicroSeconds (s*100), &read_pkt1, echoClient1, clientApps1, echoClient2, clientApps2);
Simulator::Schedule(MicroSeconds (s*100), &read_pkt2, echoClient3, clientApps3);
}
Is
this the right way to schedule events? I need to call the functions
read_pkt1 and read_pkt2 every 100 us for 100000 times ie for 10 secs. I
also pass echoClient1 etc. as parameters to the function. read_pkt1 and
read_pkt2 are almost the same, its just that I can't seem to pass more
than 4 parameters to a function in the scheduler without it throwing an
error.
2) // set the packet size
echoClient1.SetAttribute ("PacketSize", UintegerValue (msg1.str().length()));
// set the data
echoClient1.SetFill (clientApps1.Get (0), (uint8_t*) msg1.str().c_str(), msg1.str().length(), msg1.str().length());
Is this the right way to send a packet of my own data in ns3? msg1 is a std::ostringstream string for ex "hello world"
3)
Ptr<Socket> source1 = Socket::CreateSocket (terminals.Get (0), tid);
InetSocketAddress remote1 = InetSocketAddress (Ipv4Address::GetAny (), 40);
source1->Connect (remote1);
///////Repeat above 5 times for 5 nodes. Full code in file attached.
Ptr<Socket> recvSink1 = Socket::CreateSocket (terminals.Get (5), tid);
InetSocketAddress local1 = InetSocketAddress (Ipv4Address::GetAny (), 9);
recvSink1->Bind (local1);
recvSink1->SetRecvCallback (MakeBoundCallback (&Send_pkt,2));
///////Repeat above 3 times for 3 nodes. Full code in file attached.
UdpEchoClientHelper echoClient1 (interfaces.GetAddress (5), 9);
echoClient1.SetAttribute ("Interval", TimeValue (MilliSeconds (1)));
echoClient1.SetAttribute ("MaxPackets", UintegerValue (100000000));
ApplicationContainer clientApps1 = echoClient1.Install (terminals.Get (0));
UdpEchoClientHelper echoClient2 (interfaces.GetAddress (6), 10);
echoClient2.SetAttribute ("Interval", TimeValue (MilliSeconds (1)));
echoClient2.SetAttribute ("MaxPackets", UintegerValue (100000000));
ApplicationContainer clientApps2 = echoClient2.Install (terminals.Get (0));
UdpEchoClientHelper echoClient3 (interfaces.GetAddress (7), 11);
echoClient3.SetAttribute ("Interval", TimeValue (MilliSeconds (1)));
echoClient3.SetAttribute ("MaxPackets", UintegerValue (100000000));
ApplicationContainer clientApps3 = echoClient3.Install (terminals.Get (0));
Finally and this is the part I'm sure I've got wrong.
I
want to use nodes 0,1,2,3,4 as a source of packets. They must rx
packets from the external app and send them through the switch to the
other nodes.
Likewise nodes 5,6,7 are sinks and as soon as the
receive a packet (through ns3), they make a callback to the Send_pkt fn
which then sends the packets to the external app
I'm not sure
whether to put nodes 0,1,2,3,4 or 5,6,7 as the terminals for
udpechoclient. I assume its 0,1,2,3,4 because these are the nodes I send
packets through? Also where do I install the udpechoclienthelper
object?
Basically what do I write here?
UdpEchoClientHelper echoClient1 (interfaces.GetAddress (5), 9);
and here?
ApplicationContainer clientApps2 = echoClient2.Install (terminals.Get (0));
Can
I use UdpEchoClientHelper without a server? My main goal was to just
use the setfill function of udpechoclient. I don't want the packets to
echo back, just to be sent every 1 ms and every time the data depends on
whats put in using setfill.
Thanks
> 1) Yes, it't the right way.
It's *a* way, but arguably not the best way, because it uses a lot of memory, and slows down the execution to have so many events in the Scheduler. Instead, schedule just the first read_pktx call, then have those functions Schedule the next call. Kind of like tail recursion.
Peter
UdpEchoClientHelper echoClient1 (interfaces.GetAddress (sink node), 9);
echoClient1.SetAttribute ("Interval", TimeValue (MilliSeconds (1)));
echoClient1.SetAttribute ("MaxPackets", UintegerValue (100000000));
ApplicationContainer clientApps1 = echoClient1.Install (terminals.Get (source node));
Could you elaborate more on where I messed up in 2? It seems to work as I can see the data in the pcap files.
Simulator::Schedule(MicroSeconds (0), &read_pkt1, echoClient1, clientApps1, echoClient2, clientApps2);
Simulator::Schedule(MicroSeconds (0), &read_pkt2, echoClient3, clientApps3, echoClient4, clientApps4);
Simulator::Schedule(MicroSeconds (0), &read_pkt3, echoClient5, clientApps5, echoClient6, clientApps6);
probably declare a global variable or pass a parameter say "count"
void read_pktx(UdpEchoClientHelper echoClientx, ApplicationContainer clientAppsx, UdpEchoClientHelper echoClientx, ApplicationContainer clientAppsx){
// do stuff
if(count <
100000){
Simulator::Schedule(MicroSeconds (count * 100), &read_pktx, echoClientx, clientAppsx, echoClientx, clientAppsx);
count++;
}
}
I cant seem to edit my previous post so here goes,
What do you mean by "
For your case you'll need your own application to receive and re-send the packets."can we use the echoclient without an echoserver.
Simulator::Schedule(MicroSeconds (0), &read_pkt1, echoClient1, clientApps1, echoClient2, clientApps2);
Simulator::Schedule(MicroSeconds (0), &read_pkt2, echoClient3, clientApps3, echoClient4, clientApps4);
Simulator::Schedule(MicroSeconds (0), &read_pkt3, echoClient5, clientApps5, echoClient6, clientApps6);
in the main function and within each sub function read_pktx:
probably declare a global variable or pass a parameter say "count"
void read_pktx(UdpEchoClientHelper echoClientx, ApplicationContainer clientAppsx, UdpEchoClientHelper echoClientx, ApplicationContainer clientAppsx){
// do stuffif(count <
Simulator::Schedule(MicroSeconds (count * 100), &read_pktx, echoClientx, clientAppsx, echoClientx, clientAppsx);
100000){
count++;
}
}
Won't this use more memory since it's recursive and I don't need recursive? I mean the previous function calls will still have their variables on stack right? Or does waf optimize for this?
To synchronize ns3 with the external app, i use a clock signal from the app and run ns3 to that. I've modified the wall clock synchronizer files for that. It works, but i guess that's why it slow. If you or Tom have any suggestions on how to make it faster, I would appreciate it.
I know ns3 receives the clock signals in tandem with that being sent (i just printed it on the terminal from wall clock sync), but after that it slows down dramatically while executing my code. If I don't use the real time clock, it self synchronizes but there is a random amount of delay involved, so I'm not sure where to look for this delay.
Can you use the unmodified real-time scheduler? And throttle your external app to something reasonable? Is ns-3 able to keep up with real time?