ns3::OnOffApplication
根據(jù)開關(guān)模式(onoff pattern)向一個(gè)目的地發(fā)送流量女责。
如果基礎(chǔ)插槽類型支持廣播宣鄙,這個(gè)應(yīng)用程序?qū)⒆詣?dòng)啟用SetAllowBroadcast(真)套接字選項(xiàng)趁舀。
它對(duì)應(yīng)有一個(gè)幫助類ns3::OnOffHelper,進(jìn)一步簡化了ns3::OnOffApplication的使用赠叼。
實(shí)例代碼如下:
OnOffHelper clientHelper1 ("ns3::TcpSocketFactory", Address ());
clientHelper1.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
clientHelper1.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
clientHelper1.SetAttribute ("PacketSize", UintegerValue (1000));
// Connection two
OnOffHelper clientHelper2 ("ns3::TcpSocketFactory", Address ());
clientHelper2.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
clientHelper2.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
clientHelper2.SetAttribute ("PacketSize", UintegerValue (1000));
clientHelper1.SetAttribute ("DataRate", DataRateValue (DataRate ("100Mb/s")));
clientHelper2.SetAttribute ("DataRate", DataRateValue (DataRate ("100Mb/s")));
ApplicationContainer clientApps1;
AddressValue remoteAddress (InetSocketAddress (i3i4.GetAddress (1), port));
clientHelper1.SetAttribute ("Remote", remoteAddress);
clientApps1.Add (clientHelper1.Install (n0n2.Get (0)));
clientApps1.Start (Seconds (client_start_time));
clientApps1.Stop (Seconds (client_stop_time));
ApplicationContainer clientApps2;
clientHelper2.SetAttribute ("Remote", remoteAddress);
clientApps2.Add (clientHelper2.Install (n1n2.Get (0)));
clientApps2.Start (Seconds (client_start_time));
clientApps2.Stop (Seconds (client_stop_time));
ns3::PacketSink
接收和消費(fèi)對(duì)應(yīng)IP地址和端口的流量洽胶。
它對(duì)應(yīng)有一個(gè)幫助類:ns3::PacketSinkHelper.
實(shí)例代碼如下:
PacketSinkHelper sinkHelper2 ("ns3::TcpSocketFactory", sinkLocalAddress2);
ApplicationContainer sinkApp2 = sinkHelper2.Install (serverCmts.Get (0));
ns3::BulkSendApplication
發(fā)送盡可能多的流量,試圖填補(bǔ)帶寬佳镜。
流量產(chǎn)生器盡量以maxbytes發(fā)送數(shù)據(jù)僚稿,或者止到應(yīng)用停止(如果maxbaytes=0).一旦底層發(fā)送緩存被填充滿,則等待釋放空間以發(fā)送更多的數(shù)據(jù)蟀伸,本質(zhì)上保證一個(gè)常數(shù)據(jù)流蚀同。只有SOCK_STREAM SOCK_SEQPACKET類型的sockets是支持的缅刽。例如,TCP socket可以使用蠢络,但是UDP sockets不能使用衰猛。
它對(duì)應(yīng)有一個(gè)幫助類:ns3::BulkSendHelper。
實(shí)例代碼如下:
BulkSendHelper sourceHelper ("ns3::TcpSocketFactory", Address ());
sourceHelper.SetAttribute ("Remote", remoteAddress);
sourceHelper.SetAttribute ("SendSize", UintegerValue (pktSize));
sourceHelper.SetAttribute ("MaxBytes", UintegerValue (0));
ApplicationContainer sourceApp = sourceHelper.Install (sender);
sourceApp.Start (Seconds (0));
sourceApp.Stop (Seconds (stopTime - 3));
ns3::UdpTraceClient
默認(rèn)跟蹤發(fā)送刹孔。
一個(gè)基于跟蹤流光啡省。
它對(duì)應(yīng)一個(gè)幫助類:ns3::UdpTraceClientHelper.
用法實(shí)例代碼如下:
UdpTraceClientHelper udpClient;
udpClient = UdpTraceClientHelper (multicastGroup, multicast_port, "");
clientApps = udpClient.Install (Streamer_Node.Get (0));
clientApps.Start (Seconds (6));
clientApps.Stop (Seconds (duration));
ns3::PacketLossCounter
計(jì)算丟失包數(shù)量的類
這個(gè)類記錄了在客戶端和服務(wù)器端以有序傳送的丟失的數(shù)據(jù)包。超定限定窗口的包都認(rèn)為是丟失的髓霞。
ns3::SeqTsHeader
為UDP 客戶端和服務(wù)器應(yīng)用所用的包頭卦睹。
該頭是跟在64位時(shí)間戳后的322位有序數(shù)
ns3::UdpEchoClien
一個(gè)UDP Echo客戶端
每一個(gè)發(fā)送的包都會(huì)被服務(wù)器返回并在該類中接收。
它對(duì)應(yīng)一個(gè)幫助類:ns3::UdpEchoClientHelper
ns3::UdpEchoServer
一個(gè)UDP server應(yīng)用
每個(gè)接收的包都將送回方库。
它對(duì)應(yīng)一個(gè)幫助類:ns3::UdpEchoServerHelper
實(shí)例代碼如下:
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (nodes34.Get (1));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
ApplicationContainer clientApps = echoClient.Install (nodes12.Get (0));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
ns3::UdpClient
一個(gè)Udp客戶端结序。
在其有效載荷中發(fā)送攜帶序列號(hào)和時(shí)間戳的UDP數(shù)據(jù)包
它對(duì)應(yīng)一個(gè)幫助類:ns3::UdpClientHelper
ns3::UdpServer
UDP服務(wù)器,從遠(yuǎn)程主機(jī)接收UDP數(shù)據(jù)包纵潦。
UDP數(shù)據(jù)包在其有效載荷中攜帶32位序列號(hào)徐鹤,后跟64位時(shí)間戳。 應(yīng)用程序使用序列號(hào)來確定數(shù)據(jù)包是否丟失邀层,以及計(jì)算延遲的時(shí)間戳返敬。
它對(duì)應(yīng)一個(gè)幫助類ns3::UdpServerHelper
用法實(shí)例代碼如下:
UdpServerHelper udpServer;
ApplicationContainer serverApps;
UdpClientHelper udpClient;
ApplicationContainer clientApps;
udpServer = UdpServerHelper (100);
serverApps = udpServer.Install (ssNodes.Get (0));
serverApps.Start (Seconds (6));
serverApps.Stop (Seconds (duration));
udpClient = UdpClientHelper (SSinterfaces.GetAddress (0), 100);
udpClient.SetAttribute ("MaxPackets", UintegerValue (1200));
udpClient.SetAttribute ("Interval", TimeValue (Seconds (0.5)));
udpClient.SetAttribute ("PacketSize", UintegerValue (1024));
clientApps = udpClient.Install (ssNodes.Get (1));
clientApps.Start (Seconds (6));
clientApps.Stop (Seconds (duration));
總的來說,application就是在socket上進(jìn)行進(jìn)一步的封裝寥院。依然利用的是socket類來完成一些功能的劲赠。
如果懂得socket通信的過程,可以完全不用利用application來完成應(yīng)用通信只磷,只不過可能application方便一點(diǎn)點(diǎn)而已经磅。