r***@gmail.com
2018-12-07 06:40:55 UTC
int main(int argc, char *argv[])
{
CommandLine cmd;
cmd.Parse(argc, argv);
Time::SetResolution(Time::NS);
LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
NodeContainer nodes1,nodes2;
nodes1.Create(2);
nodes2.Create(2);
PointToPointHelper pointToPoint1,pointToPoint2;
pointToPoint1.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
pointToPoint1.SetChannelAttribute("Delay", StringValue("2ms"));
pointToPoint2.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
pointToPoint2.SetChannelAttribute("Delay", StringValue("2ms"));
NetDeviceContainer devices1,devices2;
devices1 = pointToPoint1.Install(nodes1);
devices2 = pointToPoint2.Install(nodes2);
InternetStackHelper stack1,stack2;
stack1.Install(nodes1);//
stack2.Install(nodes2);
Ipv4AddressHelper address1;
address1.SetBase("10.1.1.0", "255.255.255.0");
Ipv4AddressHelper address2;
address2.SetBase("10.5.4.0", "255.255.255.0");
Ipv4InterfaceContainer interfaces1 = address1.Assign(devices1);
Ipv4InterfaceContainer interfaces2 = address2.Assign(devices2);
UdpEchoServerHelper echoServer1(8889),echoServer2(8850);
ApplicationContainer serverApps1 = echoServer1.Install(nodes1.Get(0));
ApplicationContainer serverApps2 = echoServer2.Install(nodes2.Get(0));
serverApps1.Start(Seconds(1.0));
serverApps1.Stop(Seconds(10.0));
serverApps2.Start(Seconds(1.0));
serverApps2.Stop(Seconds(10.0));
UdpEchoClientHelper echoClient1(interfaces1.GetAddress(1), 8889),echoClient2(interfaces2.GetAddress(1), 8850);
echoClient1.SetAttribute("MaxPackets", UintegerValue(1));
echoClient1.SetAttribute("Interval", TimeValue(Seconds(1.0)));
echoClient1.SetAttribute("PacketSize", UintegerValue(1024));
echoClient2.SetAttribute("MaxPackets", UintegerValue(1));
echoClient2.SetAttribute("Interval", TimeValue(Seconds(1.0)));
echoClient2.SetAttribute("PacketSize", UintegerValue(1024));
ApplicationContainer clientApps1 = echoClient1.Install (nodes1.Get (1));
clientApps1.Start (Seconds (2.0));
clientApps1.Stop (Seconds (10.0));
ApplicationContainer clientApps2 = echoClient2.Install (nodes2.Get (1));
clientApps2.Start (Seconds (2.0));
clientApps2.Stop (Seconds (10.0));
FlowMonitorHelper flowmon ;
Ptr<FlowMonitor> monitor = flowmon.InstallAll( ) ;
pointToPoint1.EnablePcapAll("prog1");
pointToPoint2.EnablePcapAll("prog2");
Simulator::Stop(Seconds(50.0) ) ;
Simulator::Run();
monitor->CheckForLostPackets() ;
Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier> (flowmon.GetClassifier()) ;
std :: map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats ( ) ;
for (std ::map<FlowId,FlowMonitor::FlowStats >::const_iterator iter = stats.begin();iter!= stats.end( );++iter) //map iterator
{
Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow ( iter->first ) ;
if ((t.sourceAddress==Ipv4Address ("10.1.1.1") && t.destinationAddress==Ipv4Address("10.1.1.2")))
{
std:: cout<<"Flow ID : " <<iter->first<<"source address" << t.sourceAddress<<"destination address"<<t.destinationAddress<<"\n" ;
std :: cout<<"Transmitted Packets ="<<iter->second.txPackets<<"\n" ;
std :: cout<<"Received Packets = "<<iter->second.rxPackets<<"\n" ;
std :: cout<<"Throughput is :" <<iter->second.rxBytes*8.0/(iter->second.timeLastRxPacket.GetSeconds()-iter->second.timeFirstTxPacket.GetSeconds())/1024/1024<<"Mbps.\n" ;
}
}
Simulator::Destroy ();
return 0;
{
CommandLine cmd;
cmd.Parse(argc, argv);
Time::SetResolution(Time::NS);
LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
NodeContainer nodes1,nodes2;
nodes1.Create(2);
nodes2.Create(2);
PointToPointHelper pointToPoint1,pointToPoint2;
pointToPoint1.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
pointToPoint1.SetChannelAttribute("Delay", StringValue("2ms"));
pointToPoint2.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
pointToPoint2.SetChannelAttribute("Delay", StringValue("2ms"));
NetDeviceContainer devices1,devices2;
devices1 = pointToPoint1.Install(nodes1);
devices2 = pointToPoint2.Install(nodes2);
InternetStackHelper stack1,stack2;
stack1.Install(nodes1);//
stack2.Install(nodes2);
Ipv4AddressHelper address1;
address1.SetBase("10.1.1.0", "255.255.255.0");
Ipv4AddressHelper address2;
address2.SetBase("10.5.4.0", "255.255.255.0");
Ipv4InterfaceContainer interfaces1 = address1.Assign(devices1);
Ipv4InterfaceContainer interfaces2 = address2.Assign(devices2);
UdpEchoServerHelper echoServer1(8889),echoServer2(8850);
ApplicationContainer serverApps1 = echoServer1.Install(nodes1.Get(0));
ApplicationContainer serverApps2 = echoServer2.Install(nodes2.Get(0));
serverApps1.Start(Seconds(1.0));
serverApps1.Stop(Seconds(10.0));
serverApps2.Start(Seconds(1.0));
serverApps2.Stop(Seconds(10.0));
UdpEchoClientHelper echoClient1(interfaces1.GetAddress(1), 8889),echoClient2(interfaces2.GetAddress(1), 8850);
echoClient1.SetAttribute("MaxPackets", UintegerValue(1));
echoClient1.SetAttribute("Interval", TimeValue(Seconds(1.0)));
echoClient1.SetAttribute("PacketSize", UintegerValue(1024));
echoClient2.SetAttribute("MaxPackets", UintegerValue(1));
echoClient2.SetAttribute("Interval", TimeValue(Seconds(1.0)));
echoClient2.SetAttribute("PacketSize", UintegerValue(1024));
ApplicationContainer clientApps1 = echoClient1.Install (nodes1.Get (1));
clientApps1.Start (Seconds (2.0));
clientApps1.Stop (Seconds (10.0));
ApplicationContainer clientApps2 = echoClient2.Install (nodes2.Get (1));
clientApps2.Start (Seconds (2.0));
clientApps2.Stop (Seconds (10.0));
FlowMonitorHelper flowmon ;
Ptr<FlowMonitor> monitor = flowmon.InstallAll( ) ;
pointToPoint1.EnablePcapAll("prog1");
pointToPoint2.EnablePcapAll("prog2");
Simulator::Stop(Seconds(50.0) ) ;
Simulator::Run();
monitor->CheckForLostPackets() ;
Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier> (flowmon.GetClassifier()) ;
std :: map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats ( ) ;
for (std ::map<FlowId,FlowMonitor::FlowStats >::const_iterator iter = stats.begin();iter!= stats.end( );++iter) //map iterator
{
Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow ( iter->first ) ;
if ((t.sourceAddress==Ipv4Address ("10.1.1.1") && t.destinationAddress==Ipv4Address("10.1.1.2")))
{
std:: cout<<"Flow ID : " <<iter->first<<"source address" << t.sourceAddress<<"destination address"<<t.destinationAddress<<"\n" ;
std :: cout<<"Transmitted Packets ="<<iter->second.txPackets<<"\n" ;
std :: cout<<"Received Packets = "<<iter->second.rxPackets<<"\n" ;
std :: cout<<"Throughput is :" <<iter->second.rxBytes*8.0/(iter->second.timeLastRxPacket.GetSeconds()-iter->second.timeFirstTxPacket.GetSeconds())/1024/1024<<"Mbps.\n" ;
}
}
Simulator::Destroy ();
return 0;
--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+***@googlegroups.com.
To post to this group, send email to ns-3-***@googlegroups.com.
Visit this group at https://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/d/optout.
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+***@googlegroups.com.
To post to this group, send email to ns-3-***@googlegroups.com.
Visit this group at https://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/d/optout.