{"id":69499,"date":"2026-01-31T19:16:55","date_gmt":"2026-01-31T11:16:55","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/69499.html"},"modified":"2026-01-31T19:16:55","modified_gmt":"2026-01-31T11:16:55","slug":"ns-3%e4%bb%bf%e7%9c%9f%e4%b9%8b%e5%ba%94%e7%94%a8%e5%b1%82%ef%bc%88%e4%b8%80%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/69499.html","title":{"rendered":"ns-3\u4eff\u771f\u4e4b\u5e94\u7528\u5c42\uff08\u4e00\uff09"},"content":{"rendered":"<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"%E4%B8%80%E3%80%81%E6%9E%B6%E6%9E%84%E4%B8%8E%E8%84%9A%E6%9C%AC-toc\" style=\"margin-left:0px\">\u4e00\u3001\u67b6\u6784\u4e0e\u811a\u672c<\/p>\n<p id=\"1.1%20%E6%A6%82%E5%86%B5-toc\" style=\"margin-left:40px\">1.1 \u6982\u51b5<\/p>\n<p id=\"1.2%20%E5%BB%BA%E7%AB%8B%E4%B8%80%E4%B8%AAUDP%E8%BF%9E%E6%8E%A5-toc\" style=\"margin-left:40px\">1.2 \u5efa\u7acb\u4e00\u4e2aUDP\u8fde\u63a5<\/p>\n<p id=\"%E4%BA%8C%E3%80%81%E5%86%85%E7%BD%AE%E5%BA%94%E7%94%A8%EF%BC%9AApplication-toc\" style=\"margin-left:0px\">\u4e8c\u3001\u5185\u7f6e\u5e94\u7528&#xff1a;Application<\/p>\n<p id=\"2.1%E5%86%85%E7%BD%AE%E5%BA%94%E7%94%A8-toc\" style=\"margin-left:40px\">2.1\u5185\u7f6e\u5e94\u7528<\/p>\n<p id=\"2.2%20%E5%BA%94%E7%94%A8%E5%B1%82%E5%8D%8F%E8%AE%AE%E5%8A%A9%E6%89%8B%E7%B1%BB%E4%BD%BF%E7%94%A8%E7%9A%84%E5%9F%BA%E6%9C%AC%E6%AD%A5%E9%AA%A4%EF%BC%9A-toc\" style=\"margin-left:40px\">2.2 \u5e94\u7528\u5c42\u534f\u8bae\u52a9\u624b\u7c7b\u4f7f\u7528\u7684\u57fa\u672c\u6b65\u9aa4&#xff1a;<\/p>\n<p id=\"%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A01.%20%E5%88%9B%E5%BB%BA%E5%8A%A9%E6%89%8B%E7%B1%BB%E5%AF%B9%E8%B1%A1%EF%BC%9A%E6%8C%87%E5%AE%9A%E4%B8%A4%E4%B8%AA%E5%BD%A2%E5%8F%82-toc\" style=\"margin-left:80px\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a01. \u521b\u5efa\u52a9\u624b\u7c7b\u5bf9\u8c61&#xff1a;\u6307\u5b9a\u4e24\u4e2a\u5f62\u53c2<\/p>\n<p id=\"%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%202.%20%E9%85%8D%E7%BD%AE%E4%B8%93%E5%B1%9E%E5%B1%9E%E6%80%A7%EF%BC%88%E5%8F%AF%E9%80%89%EF%BC%89-toc\" style=\"margin-left:80px\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 2. \u914d\u7f6e\u4e13\u5c5e\u5c5e\u6027&#xff08;\u53ef\u9009&#xff09;<\/p>\n<p id=\"%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%203.%20%E5%9C%A8%E6%8C%87%E5%AE%9A%E7%BB%93%E7%82%B9%E4%B8%8A%E5%AE%89%E8%A3%85%E5%BA%94%E7%94%A8%E5%B1%82%E5%8D%8F%E8%AE%AE-toc\" style=\"margin-left:80px\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 3. \u5728\u6307\u5b9a\u7ed3\u70b9\u4e0a\u5b89\u88c5\u5e94\u7528\u5c42\u534f\u8bae<\/p>\n<p id=\"%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A04.%20%E8%AE%BE%E7%BD%AE%E5%BA%94%E7%94%A8%E5%B1%82%E5%8D%8F%E8%AE%AE%E7%9A%84%E5%90%AF%E5%8A%A8%E5%92%8C%E5%81%9C%E6%AD%A2%E6%97%B6%E9%97%B4-toc\" style=\"margin-left:80px\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a04. \u8bbe\u7f6e\u5e94\u7528\u5c42\u534f\u8bae\u7684\u542f\u52a8\u548c\u505c\u6b62\u65f6\u95f4<\/p>\n<p id=\"%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%205.%20%E9%85%8D%E7%BD%AEtrace%E5%8F%98%E9%87%8F%EF%BC%88%E5%8F%AF%E9%80%89%EF%BC%89-toc\" style=\"margin-left:80px\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 5. \u914d\u7f6etrace\u53d8\u91cf&#xff08;\u53ef\u9009&#xff09;<\/p>\n<p id=\"2.3%20%E5%88%86%E7%BB%84%E4%BA%A7%E7%94%9F%E5%99%A8-toc\" style=\"margin-left:40px\">2.3 \u5206\u7ec4\u4ea7\u751f\u5668<\/p>\n<p id=\"2.3.1.%20%E5%88%86%E7%BB%84%E6%8E%A5%E6%94%B6%E5%99%A8%EF%BC%9APacketSink-toc\" style=\"margin-left:80px\">2.3.1. \u5206\u7ec4\u63a5\u6536\u5668&#xff1a;PacketSink<\/p>\n<p id=\"%EF%BD%9Eexamples%2Ftcp%2Ftcp-bulk-send.cc-toc\" style=\"margin-left:120px\">&#xff5e;examples\/tcp\/tcp-bulk-send.cc<\/p>\n<p id=\"%E7%A8%8B%E5%BA%8F%E5%8A%9F%E8%83%BD%E5%92%8C%E6%89%A7%E8%A1%8C%E9%80%BB%E8%BE%91-toc\" style=\"margin-left:160px\">\u7a0b\u5e8f\u529f\u80fd\u548c\u6267\u884c\u903b\u8f91<\/p>\n<p id=\"%EF%BD%9Eexamples%2Frouting%2Fsimple-global-routing.cc-toc\" style=\"margin-left:120px\">&#xff5e;examples\/routing\/simple-global-routing.cc<\/p>\n<p id=\"%E7%A8%8B%E5%BA%8F%E5%8A%9F%E8%83%BD%E4%B8%8E%E6%89%A7%E8%A1%8C%E9%80%BB%E8%BE%91-toc\" style=\"margin-left:160px\">\u7a0b\u5e8f\u529f\u80fd\u4e0e\u6267\u884c\u903b\u8f91<\/p>\n<p id=\"%EF%BD%9Esrc%2Fcsma%2Fexamples%2Fcsma-packet-socket.cc-toc\" style=\"margin-left:120px\">&#xff5e;src\/csma\/examples\/csma-packet-socket.cc<\/p>\n<p id=\"%E7%A8%8B%E5%BA%8F%E5%8A%9F%E8%83%BD%E4%B8%8E%E6%89%A7%E8%A1%8C%E9%80%BB%E8%BE%91-toc\" style=\"margin-left:160px\">\u7a0b\u5e8f\u529f\u80fd\u4e0e\u6267\u884c\u903b\u8f91<\/p>\n<hr id=\"hr-toc\" \/>\n<\/p>\n<p>\u5728\u811a\u672c\u4e2d\u521b\u5efa\u5e94\u7528\u5c42\u534f\u8bae\u5b9e\u9645\u4e0a\u5b8c\u6210\u7684\u662f\u5236\u5b9a\u5206\u7ec4\u6536\u53d1\u89c4\u5219\u548c\u8c03\u7528\u5957\u63a5\u5b57&#xff08;API&#xff09;\u8fd9\u4e24\u90e8\u5206\u64cd\u4f5c\u3002<\/p>\n<h2 id=\"%E4%B8%80%E3%80%81%E6%9E%B6%E6%9E%84%E4%B8%8E%E8%84%9A%E6%9C%AC\">\u4e00\u3001\u67b6\u6784\u4e0e\u811a\u672c<\/h2>\n<h3 id=\"1.1%20%E6%A6%82%E5%86%B5\">1.1 \u6982\u51b5<\/h3>\n<p>ns-3\u5e94\u7528\u5c42\u534f\u8bae\u4e3b\u8981\u8d1f\u8d23\u6570\u636e\u5206\u7ec4\u7684\u53d1\u9001\u3001\u5904\u7406\u548c\u63a5\u6536&#xff0c;\u53ef\u4ee5\u628a\u5176\u770b\u6210\u7269\u7406\u7f51\u7edc\u4e2d\u5e94\u7528\u7a0b\u5e8f\u7684\u7f51\u7edc\u4f20\u8f93\u90e8\u5206<\/p>\n<p>\u5728\u5e94\u7528\u5c42\u534f\u8bae\u4e2d&#xff0c;\u5206\u7ec4\u751f\u6210\u90e8\u5206\u8d1f\u8d23\u6309\u7167\u4e00\u5b9a\u7684\u7edf\u8ba1\u89c4\u5219\u53d1\u9001\u5206\u7ec4&#xff1b;\u5206\u7ec4\u5904\u7406\u90e8\u5206\u8d1f\u8d23\u63a5\u6536\u6765\u81ea\u4e0b\u5c42\u534f\u8bae\u7684\u5206\u7ec4\u5e76\u5bf9\u5206\u7ec4\u76f8\u5173\u4fe1\u606f\u8fdb\u884c\u8bb0\u5f55\u3002<\/p>\n<p>\u5728ns-3\u4e2d&#xff0c;\u7f51\u7edc\u5957\u63a5\u5b57&#xff08;network socket&#xff09;\u3010\u53ef\u770b\u4f5c\u4e00\u79cd\u5e94\u7528\u7a0b\u5e8f\u63a5\u53e3\u3011\u53ef\u88ab\u5206\u4e3a\u4e24\u5927\u7c7b&#xff1a;<\/p>\n<li>\u57fa\u4e8ePOSIX\u5957\u63a5\u5b57\u7684\u539f\u8bed\u51fd\u6570&#xff0c;\u4e3b\u8981\u7528\u4e8e\u5efa\u7acb\u4e0b\u5c42\u534f\u8bae\u8fde\u63a5\u3001\u53d1\u9001\u548c\u63a5\u53d7\u5206\u7ec4&#xff1b;<\/li>\n<li>\u56de\u8c03\u51fd\u6570&#xff0c;\u4e3b\u8981\u7528\u4e8e\u63a5\u6536\u6765\u81ea\u4e0b\u5c42\u534f\u8bae\u7684\u4e8b\u4ef6\u901a\u77e5<\/li>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"256\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260131111654-697de4a651de9.png\" width=\"209\" \/><\/p>\n<p style=\"text-align:center\">\u56fe1-1 ns-3\u5e94\u7528\u5c42\u8f6f\u4ef6\u67b6\u6784<\/p>\n<p>ns-3\u652f\u6301\u76844\u79cd\u5957\u63a5\u5b57\u7c7b\u578b&#xff1a;\u4e0e\u4f20\u8f93\u5c42\u534f\u8bae\u4ea4\u4e92\u7684\u6d41\u5957\u63a5\u5b57&#xff08;stream packet&#xff09;\u3001\u6570\u636e\u62a5\u6587\u5957\u63a5\u5b57&#xff08;datagram socket&#xff09;\u3001\u4e0e\u7f51\u7edc\u5c42\u534f\u8bae\u4ea4\u4e92\u7684\u539f\u59cb\u5957\u63a5\u5b57&#xff08;raw socket&#xff09;\u3001\u4e0e\u94fe\u8def\u5c42\u4ea4\u4e92\u7684Packet\u5957\u63a5\u5b57&#xff08;packet socket&#xff09;\u3002<\/p>\n<h3 id=\"1.2%20%E5%BB%BA%E7%AB%8B%E4%B8%80%E4%B8%AAUDP%E8%BF%9E%E6%8E%A5\">1.2 \u5efa\u7acb\u4e00\u4e2aUDP\u8fde\u63a5<\/h3>\n<li>\n<h4>\u5229\u7528UdpClient\u548cUdpServer\u5e94\u7528\u534f\u8bae\u7684\u52a9\u624b\u7c7b\u6765\u5efa\u7acb<\/h4>\n<\/li>\n<p>\/\/\u521b\u5efa\u5ba2\u6237\u7aef<br \/>\nUdpClientHelper client(<br \/>\n    serverIpv4Address,serverPort);<br \/>\nclient.Install(clientNode);<\/p>\n<p>\/\/\u521b\u5efa\u670d\u52a1\u5668\u7aef<br \/>\nUdpServerHelper server(serverPort);<br \/>\nserver.Install(serverNode); <\/p>\n<h4>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 2.\u4e0d\u4f7f\u7528\u52a9\u624b\u7c7b\u7684\u60c5\u51b5\u4e0b\u5b9e\u73b0\u4e0eUdpClient\u548cUdpServer\u76f8\u7c7b\u4f3c\u7684\u529f\u80fd<\/h4>\n<p>\/\/\u521b\u5efa\u5ba2\u6237\u7aef<br \/>\nclient&#061;Socket::CreateSocket(<br \/>\n        clientNode,<br \/>\n        &#034;ns3::UdpSocketFactory&#034;);<br \/>\nclient-&gt;Bind();<br \/>\nclient-&gt;Connect(serverSocketAddress);<br \/>\nclient-&gt;Send(pakcet);<\/p>\n<p>\/\/\u521b\u5efa\u670d\u52a1\u5668\u7aef<br \/>\nserver&#061;Socket::CreateSocket(<br \/>\n        serverNode,<br \/>\n        &#034;ns3::UdpSocketFactory&#034;);<br \/>\nserver-&gt;Bind(serverSocketAddress);<br \/>\nserver-&gt;SetRecvCallback(MakeCallback(&amp;ReceivePacket)); <\/p>\n<h2 id=\"%E4%BA%8C%E3%80%81%E5%86%85%E7%BD%AE%E5%BA%94%E7%94%A8%EF%BC%9AApplication\">\u4e8c\u3001\u5185\u7f6e\u5e94\u7528&#xff1a;Application<\/h2>\n<h3 id=\"2.1%E5%86%85%E7%BD%AE%E5%BA%94%E7%94%A8\">2.1\u5185\u7f6e\u5e94\u7528<\/h3>\n<p>\u5185\u7f6e\u5e94\u7528\u53ef\u4ee5\u5206\u4e3a\u4e24\u7c7b&#xff1a;<\/p>\n<ul>\n<li>\u5206\u7ec4\u4ea7\u751f\u5668&#xff08;packet generator&#xff09;&#xff1a;\u6839\u636e\u4e0d\u540c\u7684\u7edf\u8ba1\u6a21\u578b\u4ea7\u751f\u6570\u636e\u5206\u7ec4&#xff0c;\u5e76\u4e0d\u5177\u6709\u4fe1\u4ee4\u4ea4\u4e92\u7b49\u884c\u4e3a<\/li>\n<li>\u5177\u6709\u4fe1\u4ee4\u4ea4\u4e92\u884c\u4e3a\u7684\u5185\u7f6e\u5e94\u7528<\/li>\n<\/ul>\n<p style=\"text-align:center\">\u88682-1 \u5185\u7f6e\u5e94\u7528\u5c42\u534f\u8bae<\/p>\n<table align=\"center\" border=\"1\" cellpadding=\"1\" cellspacing=\"1\" style=\"width:650px\">\n<tbody>\n<tr>\n<td style=\"text-align:center\">\u5e94\u7528\u5c42\u534f\u8bae<\/td>\n<td style=\"text-align:center\">\u652f\u6301\u7684\u4e0b\u5c42\u534f\u8bae\u79cd\u7c7b<\/td>\n<td style=\"text-align:center\">C<\/td>\n<td style=\"text-align:center\">S<\/td>\n<td style=\"text-align:center\">\u652f\u6301\u7684\u5bf9\u7aef\u534f\u8bae<\/td>\n<\/tr>\n<tr>\n<td colspan=\"5\" style=\"text-align:center\">application\u6a21\u5757<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">PacketSink<\/td>\n<td style=\"text-align:center\">\u6240\u6709<\/td>\n<td style=\"text-align:center\"><\/td>\n<td style=\"text-align:center\">\u221a<\/td>\n<td>\n<p style=\"text-align:center\">OnOffApplication<\/p>\n<p style=\"text-align:center\">BulkSendAppliction<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">OnOffApplication<\/td>\n<td style=\"text-align:center\">\u6240\u6709<\/td>\n<td style=\"text-align:center\">\u221a<\/td>\n<td style=\"text-align:center\"><\/td>\n<td colspan=\"1\" rowspan=\"2\" style=\"text-align:center\">PacketSlink<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">BUlkSendApplication<\/td>\n<td style=\"text-align:center\">TCP<\/td>\n<td style=\"text-align:center\">\u221a<\/td>\n<td style=\"text-align:center\"><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">UdpServer<\/td>\n<td colspan=\"1\" rowspan=\"5\" style=\"text-align:center\">UDP<\/td>\n<td style=\"text-align:center\"><\/td>\n<td style=\"text-align:center\">\u221a<\/td>\n<td style=\"text-align:center\">UdpClient<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">UdpClient<\/td>\n<td style=\"text-align:center\">\u221a<\/td>\n<td style=\"text-align:center\"><\/td>\n<td colspan=\"1\" rowspan=\"2\" style=\"text-align:center\">UdpServer<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">UdpTraceClient<\/td>\n<td style=\"text-align:center\">\u221a<\/td>\n<td style=\"text-align:center\"><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">UdpEchoServer<\/td>\n<td style=\"text-align:center\"><\/td>\n<td style=\"text-align:center\">\u221a<\/td>\n<td style=\"text-align:center\">UdpEchoClient<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">UdpEchoClient<\/td>\n<td style=\"text-align:center\">\u221a<\/td>\n<td style=\"text-align:center\"><\/td>\n<td style=\"text-align:center\">UdpEchoServer<\/td>\n<\/tr>\n<tr>\n<td colspan=\"5\" style=\"text-align:center\">network\u6a21\u5757<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">PacketSocketServer<\/td>\n<td colspan=\"1\" rowspan=\"2\" style=\"text-align:center\">NetDevice<\/td>\n<td style=\"text-align:center\"><\/td>\n<td style=\"text-align:center\">\u221a<\/td>\n<td style=\"text-align:center\">PacketSocketClient<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">PacketSocketClient<\/td>\n<td style=\"text-align:center\">\u221a<\/td>\n<td style=\"text-align:center\"><\/td>\n<td style=\"text-align:center\">PacketSocketServer<\/td>\n<\/tr>\n<tr>\n<td colspan=\"5\" style=\"text-align:center\">internet-app\u6a21\u5757<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">DhcpServer<\/td>\n<td colspan=\"1\" rowspan=\"3\" style=\"text-align:center\">IPv4<\/td>\n<td style=\"text-align:center\"><\/td>\n<td style=\"text-align:center\">\u221a<\/td>\n<td style=\"text-align:center\">DhcpClient<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">DhcpClient<\/td>\n<td style=\"text-align:center\">\u221a<\/td>\n<td style=\"text-align:center\"><\/td>\n<td style=\"text-align:center\">DhcpServer<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">V4Ping<\/td>\n<td style=\"text-align:center\">\u221a<\/td>\n<td style=\"text-align:center\">\u221a<\/td>\n<td style=\"text-align:center\">V4Ping<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">Ping6<\/td>\n<td colspan=\"1\" rowspan=\"2\" style=\"text-align:center\">IPv6<\/td>\n<td style=\"text-align:center\">\u221a<\/td>\n<td style=\"text-align:center\">\u221a<\/td>\n<td style=\"text-align:center\">Ping6<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:center\">Radvd<\/td>\n<td style=\"text-align:center\">\u221a<\/td>\n<td style=\"text-align:center\">\u221a<\/td>\n<td style=\"text-align:center\">\n<p style=\"text-align:center\">Radvd<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3 id=\"2.2%20%E5%BA%94%E7%94%A8%E5%B1%82%E5%8D%8F%E8%AE%AE%E5%8A%A9%E6%89%8B%E7%B1%BB%E4%BD%BF%E7%94%A8%E7%9A%84%E5%9F%BA%E6%9C%AC%E6%AD%A5%E9%AA%A4%EF%BC%9A\">2.2 \u5e94\u7528\u5c42\u534f\u8bae\u52a9\u624b\u7c7b\u4f7f\u7528\u7684\u57fa\u672c\u6b65\u9aa4&#xff1a;<\/h3>\n<p>\u4ee5PacketSink\u548cBulkSendApplication\u4e3a\u4f8b&#xff1a;\u5728\u7ed3\u70b91&#xff08;nodes.Get(1),nodes\u662f\u4e00\u4e2a\u7ed3\u70b9\u5bb9\u5668&#xff09;\u4e2d\u521b\u5efa\u4e86\u4e00\u4e2aBulkSendApplication\u5e94\u7528&#xff08;\u5ba2\u6237\u7aef&#xff09;\u3002\u8fd9\u4e2a\u5e94\u7528\u5411\u4f4d\u4e8e\u7ed3\u70b90\u7684PacketSink\u5e94\u7528&#xff08;\u670d\u52a1\u5668\u7aef&#xff09;\u53d1\u9001TCP\u5206\u7ec4<\/p>\n<p>\/\/\u670d\u52a1\u5668\u7aef<\/p>\n<p>\/\/\u521b\u5efa\u52a9\u624b\u7c7b\u5bf9\u8c61\u5e76\u914d\u7f6e\u5fc5\u5907\u5c5e\u6027<br \/>\nPacketSinkHelper sin(<br \/>\n    \/\/\u4e0b\u5c42\u534f\u8bae\u79cd\u7c7b&#xff08;TCP\u534f\u8bae&#xff09;<br \/>\n    &#034;ns3::TcpSocketFactory&#034;,<br \/>\n    \/\/\u672c\u5730\u76d1\u542cIP\u5730\u5740&#xff08;\u5168\u96f6\u5730\u5740&#xff09;\u53ca\u7aef\u53e3\u5c5e\u6027<br \/>\n    InetSocketAddress(Ipv4Address::GetAny(),9));<br \/>\n\/\/\u5728\u7ed3\u70b9\u4e2d\u5b89\u88c5\u670d\u52a1\u5668\u7aef\u5e94\u7528\u5c42\u534f\u8bae<br \/>\nApplicationContainer sinkApps&#061;<br \/>\nsink.Install(nodes.Get(0));<br \/>\n\/\/\u8bbe\u7f6e\u542f\u52a8\u548c\u505c\u6b62\u65f6\u95f4\u5c5e\u6027&#xff08;\u6279\u91cf\u8bbe\u7f6e&#xff09;<br \/>\nsinkApps.Start(Seconds(0.0));<br \/>\nsinkApps.Stop(Seconds(10.0));<\/p>\n<p>\/\/\u5ba2\u6237\u7aef<\/p>\n<p>\/\/\u521b\u5efa\u52a9\u624b\u7c7b\u5bf9\u8c61\u5e76\u914d\u7f6e\u5fc5\u5907\u5c5e\u6027<br \/>\nBulkSendHelper source(<br \/>\n    \/\/\u4e0b\u5c42\u534f\u8bae\u79cd\u7c7b<br \/>\n    &#034;ns3::TcpSocketFactory&#034;,<br \/>\n    \/\/\u670d\u52a1\u5668IP\u5730\u5740\u53ca\u7aef\u53e3\u5c5e\u6027<br \/>\n    InetSocketAddress(&#034;10.0.0.1&#034;,9));<br \/>\n\/\/\u8bbe\u7f6e\u5176\u4ed6\u5c5e\u6027&#xff08;\u5206\u7ec4\u5927\u5c0fSendSize\u5c5e\u6027&#xff09;<br \/>\nsource.SetAttribute(<br \/>\n    &#034;SendSize&#034;,<br \/>\n    UintegerValue(1024);<br \/>\n\/\/\u5728\u7ed3\u70b9\u4e2d\u5b89\u88c5\u5ba2\u6237\u7aef\u5e94\u7528\u5c42\u534f\u8bae<br \/>\nApplicationContainer sourceApps&#061;<br \/>\nsorce.Install(nodes.Get(1));<br \/>\n\/\/\u8bbe\u7f6e\u542f\u52a8\u548c\u505c\u6b62\u65f6\u95f4&#xff08;\u6279\u91cf\u8bbe\u7f6e&#xff09;<br \/>\nsourceApps.Start(Seconds(1.0));<br \/>\nsourceApps.Stop(Seconds(10.0)); <\/p>\n<h4 id=\"%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A01.%20%E5%88%9B%E5%BB%BA%E5%8A%A9%E6%89%8B%E7%B1%BB%E5%AF%B9%E8%B1%A1%EF%BC%9A%E6%8C%87%E5%AE%9A%E4%B8%A4%E4%B8%AA%E5%BD%A2%E5%8F%82\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a01. \u521b\u5efa\u52a9\u624b\u7c7b\u5bf9\u8c61&#xff1a;\u6307\u5b9a\u4e24\u4e2a\u5f62\u53c2<\/h4>\n<ul>\n<li>\u4e0b\u5c42\u534f\u8bae&#xff08;\u5957\u63a5\u5b57&#xff09;\u79cd\u7c7b&#xff1a;ns3::TcpSocketFactory(TCP)\u3001ns3::UdpSocketFactory(UDP)\u3001ns3::Ipv4RawSocketFactory(IPv4)\u3001ns3::Ipv6RawSocketFactory(IPv6)\u3001ns3::PacketSocketFactory(\u94fe\u8def\u5c42\u534f\u8bae)&#xff1b;<\/li>\n<li>\u5957\u63a5\u5b57\u5730\u5740&#xff1a;\u5bf9\u4e8e\u5ba2\u6237\u7aef\u5e94\u7528&#xff0c;\u5957\u63a5\u5b57\u5730\u5740\u4e3a\u53d1\u9001\u5206\u7ec4\u7684\u76ee\u6807\u5730\u5740&#xff0c;\u5373\u670d\u52a1\u5668\u7aef\u5730\u5740&#xff1b;\u5bf9\u4e8e\u670d\u52a1\u5668\u7aef\u5e94\u7528&#xff0c;\u8be5\u5730\u5740\u4e3a\u672c\u5730\u7684\u76d1\u542c\u5730\u5740\u3002\u4e25\u683c\u5730\u8bf4&#xff0c;\u8fd9\u4e24\u4e2a\u5957\u63a5\u5b57\u5730\u5740\u5fc5\u987b\u662f\u76f8\u540c\u7684&#xff0c;\u4f46\u5728\u5b9e\u9645\u4e2d&#xff0c;\u670d\u52a1\u5668\u7aef\u76d1\u542c\u5957\u63a5\u5b57\u4e2d\u7684IP\u5730\u5740\u5e38\u5e38\u91c7\u7528\u5168\u96f6IP\u5730\u5740&#xff0c;\u8fd9\u6837\u670d\u52a1\u5668\u7aef\u53ef\u4ee5\u63a5\u6536\u6240\u6709\u53d1\u5f80\u6307\u5b9a\u7aef\u53e3\u7684\u5206\u7ec4&#xff0c;\u800c\u65e0\u8bba\u5176\u76ee\u7684\u7684\u5730\u5740\u662f\u4ec0\u4e48\u3002\u5168\u96f6\u5730\u5740\u53ef\u4ee5\u901a\u8fc7Ipv4Address::GetAny()\u548cIpv6Address::GetAny()\u51fd\u6570\u83b7\u53d6\u3002<\/li>\n<\/ul>\n<h4 id=\"%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%202.%20%E9%85%8D%E7%BD%AE%E4%B8%93%E5%B1%9E%E5%B1%9E%E6%80%A7%EF%BC%88%E5%8F%AF%E9%80%89%EF%BC%89\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 2. \u914d\u7f6e\u4e13\u5c5e\u5c5e\u6027&#xff08;\u53ef\u9009&#xff09;<\/h4>\n<ul>\n<li>\u914d\u7f6eApplication\u5b50\u7c7b\u4e2d\u7684\u5c5e\u6027<\/li>\n<\/ul>\n<h4 id=\"%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%203.%20%E5%9C%A8%E6%8C%87%E5%AE%9A%E7%BB%93%E7%82%B9%E4%B8%8A%E5%AE%89%E8%A3%85%E5%BA%94%E7%94%A8%E5%B1%82%E5%8D%8F%E8%AE%AE\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 3. \u5728\u6307\u5b9a\u7ed3\u70b9\u4e0a\u5b89\u88c5\u5e94\u7528\u5c42\u534f\u8bae<\/h4>\n<ul>\n<li>ns-3\u4e2d&#xff0c;\u534f\u8bae\u7684\u5b89\u88c5\u64cd\u4f5c\u901a\u8fc7\u52a9\u624b\u7c7b\u4e2d\u7684 Install&#xff08;&#xff09;\u51fd\u6570 \u5b8c\u6210&#xff1b;<\/li>\n<li>Install&#xff08;&#xff09;\u51fd\u6570\u7684\u5f62\u53c2\u53ef\u4ee5\u662f\u4e00\u4e2a\u7ed3\u70b9\u6307\u9488&#xff08;Ptr&lt;Node&gt; node)&#xff0c;\u4e5f\u53ef\u4ee5\u662f\u5305\u542b\u591a\u4e2a\u7ed3\u70b9\u6307\u9488\u7684\u7ed3\u70b9\u5bb9\u5668&#xff08;NodeContainer&#xff09;&#xff1b;<\/li>\n<li>\u521b\u5efa\u597d\u7684\u5e94\u7528\u5c42\u534f\u8bae\u5bf9\u8c61\u88ab\u653e\u5728\u5e94\u7528\u5c42\u5bb9\u5668 ApplicationContainer \u4e2d\u8fd4\u56de<\/li>\n<\/ul>\n<h4 id=\"%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A04.%20%E8%AE%BE%E7%BD%AE%E5%BA%94%E7%94%A8%E5%B1%82%E5%8D%8F%E8%AE%AE%E7%9A%84%E5%90%AF%E5%8A%A8%E5%92%8C%E5%81%9C%E6%AD%A2%E6%97%B6%E9%97%B4\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a04. \u8bbe\u7f6e\u5e94\u7528\u5c42\u534f\u8bae\u7684\u542f\u52a8\u548c\u505c\u6b62\u65f6\u95f4<\/h4>\n<ul>\n<li>\u5728\u8bbe\u7f6e\u542f\u52a8\u548c\u505c\u6b62\u65f6\u95f4\u65f6&#xff0c;\u4e00\u822c\u79c9\u627f\u201c\u670d\u52a1\u5668\u7aef\u5148\u542f\u52a8&#xff0c;\u540e\u505c\u6b62\u201d\u7684\u89c4\u5219<\/li>\n<li>ns-3\u811a\u672c\u65e2\u53ef\u4ee5\u4f7f\u7528\u5e94\u7528\u5bb9\u5668\u6279\u91cf\u8bbe\u7f6e\u542f\u52a8\u548c\u505c\u6b62\u65f6\u95f4&#xff0c;\u4e5f\u53ef\u4ee5\u4e3a\u6bcf\u4e00\u4e2a\u5e94\u7528\u5c42\u534f\u8bae\u5206\u522b\u8bbe\u7f6e\u65f6\u95f4<\/li>\n<\/ul>\n<p>\/\/\u6279\u91cf\u8bbe\u7f6e<br \/>\nsinkApps.Start(Seconds(0.0));<br \/>\nsinkApps.Stop(Seconds(10.0));<br \/>\n\/\/\u5355\u72ec\u8bbe\u7f6e<br \/>\nsinkApp[0].Start(Seconds(0.0));<br \/>\nsinkApp[0].Stop(Seconds(10.0)); <\/p>\n<h4 id=\"%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%C2%A0%205.%20%E9%85%8D%E7%BD%AEtrace%E5%8F%98%E9%87%8F%EF%BC%88%E5%8F%AF%E9%80%89%EF%BC%89\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 5. \u914d\u7f6etrace\u53d8\u91cf&#xff08;\u53ef\u9009&#xff09;<\/h4>\n<ul>\n<li>BulkSendApplication\u548cPacketSink\u5206\u522b\u63d0\u4f9b\u4e86\u53d1\u9001&#xff08;Tx&#xff09;\u548c\u63a5\u6536&#xff08;Rx&#xff09;\u7684trace\u53d8\u91cf<\/li>\n<\/ul>\n<p>\/************\u914d\u7f6etrace\u56de\u8c03\u51fd\u6570\u793a\u4f8b***************\/<\/p>\n<p>\/\/\u5206\u7ec4\u63a5\u6536\u56de\u8c03\u51fd\u6570<br \/>\nvoid recvPackets(<br \/>\n    std::string path,<br \/>\n    Ptr&lt;const Packet&gt;packet,<br \/>\n    const Address&amp;from);<\/p>\n<p>\/\/\u5206\u7ec4\u53d1\u9001\u56de\u8c03\u51fd\u6570<br \/>\nvoid sendPackets(<br \/>\n    std::string path,<br \/>\n    Ptr&lt;const Packet&gt;packet);<\/p>\n<p>\/\/\u914d\u7f6etrace\u53d8\u91cf<br \/>\nConfig::Connect(<br \/>\n    &#034;\/NodeList\/0\/ApplicationList\/*\/\\\\<br \/>\n    $ns3::BulkSendApplication\/Tx&#034;,<br \/>\n    MakeCallback(&amp;sendPackets));<br \/>\nConfig::Connect(&#034;NodeList\/*\/\\\\<br \/>\n    ApplicationList\/*\/$ns3::PacketSink\/Rx&#034;,<br \/>\n    MakeCallback(&amp;recvPackets)); <\/p>\n<p>\u6240\u6709\u5185\u7f6e\u534f\u8bae\u52a9\u624b\u7c7b\u7684\u4f7f\u7528\u65b9\u6cd5\u548c\u987a\u5e8f\u90fd\u662f\u76f8\u540c\u7684<\/p>\n<h3 id=\"2.3%20%E5%88%86%E7%BB%84%E4%BA%A7%E7%94%9F%E5%99%A8\">2.3 \u5206\u7ec4\u4ea7\u751f\u5668<\/h3>\n<h4 id=\"2.3.1.%20%E5%88%86%E7%BB%84%E6%8E%A5%E6%94%B6%E5%99%A8%EF%BC%9APacketSink\">2.3.1. \u5206\u7ec4\u63a5\u6536\u5668&#xff1a;PacketSink<\/h4>\n<p>\u4e13\u95e8\u90e8\u7f72\u5728\u670d\u52a1\u5668\u7aef\u7684\u5e94\u7528\u5c42\u534f\u8bae&#xff0c;\u53ef\u4ee5\u63a5\u6536\u6765\u81eaTCP\u3001UDP\u3001IPv4\u3001IPv6\u548cNetDevice\u534f\u8bae\u7684\u5206\u7ec4\u3002\u52a9\u624b\u7c7b\u662fPacketSinkHelper\u3002<\/p>\n<p>\u5de5\u4f5c\u539f\u7406&#xff1a;\u5bf9\u4e8e\u63a5\u6536\u5230\u7684\u6bcf\u4e00\u4e2a\u5206\u7ec4&#xff0c;\u6253\u5370\u5176\u57fa\u672c\u4fe1\u606f\u5e76\u8bb0\u5f55&#xff08;\u901a\u8fc7Rx trace\u53d8\u91cf&#xff09;&#xff0c;\u5e38\u5e38\u4e0eOnOffApplication\u3001BulkSendApplication\u4e00\u8d77\u4f7f\u7528<\/p>\n<ul>\n<li>\n<h5 id=\"%EF%BD%9Eexamples%2Ftcp%2Ftcp-bulk-send.cc\">&#xff5e;examples\/tcp\/tcp-bulk-send.cc<\/h5>\n<\/li>\n<\/ul>\n<p>\/* -*- Mode:C&#043;&#043;; c-file-style:&#034;gnu&#034;; indent-tabs-mode:nil; -*- *\/<br \/>\n\/*<br \/>\n * \u4f7f\u7528 ns-3 \u7f51\u7edc\u6a21\u62df\u5668\u521b\u5efa\u7684\u7b80\u5355\u70b9\u5bf9\u70b9\u7f51\u7edc\u62d3\u6251&#xff0c;\u6f14\u793a\u4e86 TCP \u5927\u6587\u4ef6\u4f20\u8f93&#xff08;BulkSend&#xff09;\u573a\u666f<br \/>\n *<br \/>\n * This program is distributed in the hope that it will be useful,<br \/>\n * but WITHOUT ANY WARRANTY; without even the implied warranty of<br \/>\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br \/>\n * GNU General Public License for more details.<br \/>\n *<br \/>\n * You should have received a copy of the GNU General Public License<br \/>\n * along with this program; if not, write to the Free Software<br \/>\n * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA<br \/>\n *\/<\/p>\n<p>\/\/ \u62d3\u6251\u7ed3\u6784&#xff1a;\u4e24\u4e2a\u8282\u70b9\u901a\u8fc7\u70b9\u5bf9\u70b9\u94fe\u8def\u8fde\u63a5&#xff0c;\u5e26\u5bbd 500 Kbps&#xff0c;\u5ef6\u8fdf 5ms<br \/>\n\/\/<br \/>\n\/\/       n0 &#8212;&#8212;&#8212;&#8211; n1<br \/>\n\/\/            500 Kbps<br \/>\n\/\/             5 ms<br \/>\n\/\/<br \/>\n\/\/ &#8211; Flow from n0 to n1 using BulkSendApplication.<br \/>\n\/\/ &#8211; Tracing of queues and packet receptions to file &#034;tcp-bulk-send.tr&#034;<br \/>\n\/\/   and pcap tracing available when tracing is turned on.<\/p>\n<p>#include &lt;string&gt;<br \/>\n#include &lt;fstream&gt;<br \/>\n#include &#034;ns3\/core-module.h&#034;<br \/>\n#include &#034;ns3\/point-to-point-module.h&#034;<br \/>\n#include &#034;ns3\/internet-module.h&#034;<br \/>\n#include &#034;ns3\/applications-module.h&#034;<br \/>\n#include &#034;ns3\/network-module.h&#034;<br \/>\n#include &#034;ns3\/packet-sink.h&#034;\/\/ \u6570\u636e\u5305\u63a5\u6536\u5668\u7c7b<\/p>\n<p>using namespace ns3;<\/p>\n<p>NS_LOG_COMPONENT_DEFINE (&#034;TcpBulkSendExample&#034;);<\/p>\n<p>int<br \/>\nmain (int argc, char *argv[])<br \/>\n{<\/p>\n<p>  bool tracing &#061; false;<br \/>\n  uint32_t maxBytes &#061; 0;<\/p>\n<p>\/\/<br \/>\n\/\/ Allow the user to override any of the defaults at<br \/>\n\/\/ run-time, via command-line arguments<br \/>\n\/\/<br \/>\n  CommandLine cmd (__FILE__);<br \/>\n  cmd.AddValue (&#034;tracing&#034;, &#034;Flag to enable\/disable tracing&#034;, tracing);\/\/tracing: \u63a7\u5236\u662f\u5426\u542f\u7528\u8ddf\u8e2a<br \/>\n  cmd.AddValue (&#034;maxBytes&#034;,<br \/>\n                &#034;Total number of bytes for application to send&#034;, maxBytes);\/\/maxBytes: \u5e94\u7528\u7a0b\u5e8f\u8981\u53d1\u9001\u7684\u603b\u5b57\u8282\u6570&#xff08;0\u8868\u793a\u65e0\u9650\u5236&#xff09;<br \/>\n  cmd.Parse (argc, argv);<\/p>\n<p>\/\/<br \/>\n\/\/ Explicitly create the nodes required by the topology (shown above).<br \/>\n\/\/<br \/>\n  NS_LOG_INFO (&#034;Create nodes.&#034;);<br \/>\n  NodeContainer nodes;<br \/>\n  nodes.Create (2);\/\/ \u521b\u5efa 2 \u4e2a\u8282\u70b9<\/p>\n<p>  NS_LOG_INFO (&#034;Create channels.&#034;);<\/p>\n<p>\/\/<br \/>\n\/\/ Explicitly create the point-to-point link required by the topology (shown above).<\/p>\n<p>\/\/\u521b\u5efa\u5e26\u5bbd\u4e3a 500 Kbps&#xff0c;\u5ef6\u8fdf\u4e3a 5ms \u7684\u70b9\u5bf9\u70b9\u94fe\u8def<br \/>\n  PointToPointHelper pointToPoint;<br \/>\n  pointToPoint.SetDeviceAttribute (&#034;DataRate&#034;, StringValue (&#034;500Kbps&#034;));<br \/>\n  pointToPoint.SetChannelAttribute (&#034;Delay&#034;, StringValue (&#034;5ms&#034;));<\/p>\n<p>  NetDeviceContainer devices;<br \/>\n  devices &#061; pointToPoint.Install (nodes);<\/p>\n<p>\/\/<br \/>\n\/\/ Install the internet stack on the nodes<br \/>\n\/\/<br \/>\n  InternetStackHelper internet;<br \/>\n  internet.Install (nodes);\/\/ \u5728\u4e24\u4e2a\u8282\u70b9\u4e0a\u5b89\u88c5 TCP\/IP \u534f\u8bae\u6808<\/p>\n<p>\/\/<br \/>\n\/\/ We&#039;ve got the &#034;hardware&#034; in place.  Now we need to add IP addresses.<br \/>\n\/\/<br \/>\n  NS_LOG_INFO (&#034;Assign IP Addresses.&#034;);<br \/>\n  Ipv4AddressHelper ipv4;<br \/>\n  ipv4.SetBase (&#034;10.1.1.0&#034;, &#034;255.255.255.0&#034;);\/\/\u5206\u914d IP \u5730\u5740&#xff1a;n0 \u5f97\u5230 10.1.1.1&#xff0c;n1 \u5f97\u5230 10.1.1.2<br \/>\n  Ipv4InterfaceContainer i &#061; ipv4.Assign (devices);<\/p>\n<p>  NS_LOG_INFO (&#034;Create Applications.&#034;);<\/p>\n<p>\/\/<br \/>\n\/\/ \u521b\u5efa BulkSend \u53d1\u9001\u5e94\u7528&#xff08;\u5728 n0 \u4e0a&#xff09;<br \/>\n\/\/<br \/>\n  uint16_t port &#061; 9;  \/\/ well-known echo port number<\/p>\n<p>  BulkSendHelper source (&#034;ns3::TcpSocketFactory&#034;,<br \/>\n                         InetSocketAddress (i.GetAddress (1), port));<br \/>\n  \/\/ \u521b\u5efa\u4e00\u4e2a\u6301\u7eed\u53d1\u9001\u6570\u636e\u7684 TCP \u5e94\u7528&#xff0c;maxBytes&#061;0 \u8868\u793a\u65e0\u9650\u5236\u53d1\u9001&#xff0c;\u76f4\u5230\u6a21\u62df\u7ed3\u675f<br \/>\n  source.SetAttribute (&#034;MaxBytes&#034;, UintegerValue (maxBytes));<br \/>\n  ApplicationContainer sourceApps &#061; source.Install (nodes.Get (0));<br \/>\n  sourceApps.Start (Seconds (0.0));<br \/>\n  sourceApps.Stop (Seconds (10.0));<\/p>\n<p>\/\/<br \/>\n\/\/ \u521b\u5efa PacketSink \u63a5\u6536\u5e94\u7528&#xff08;\u5728 n1 \u4e0a&#xff09;<br \/>\n\/\/<br \/>\n  PacketSinkHelper sink (&#034;ns3::TcpSocketFactory&#034;,<br \/>\n                         InetSocketAddress (Ipv4Address::GetAny (), port));<br \/>\n  ApplicationContainer sinkApps &#061; sink.Install (nodes.Get (1));<br \/>\n  sinkApps.Start (Seconds (0.0));<br \/>\n  sinkApps.Stop (Seconds (10.0));<\/p>\n<p>\/\/<br \/>\n\/\/  \u914d\u7f6e\u8ddf\u8e2a&#xff08;\u53ef\u9009&#xff09;<br \/>\n\/\/<br \/>\n  if (tracing)<br \/>\n    {<br \/>\n      AsciiTraceHelper ascii;<br \/>\n      pointToPoint.EnableAsciiAll (ascii.CreateFileStream (&#034;tcp-bulk-send.tr&#034;));<br \/>\n      pointToPoint.EnablePcapAll (&#034;tcp-bulk-send&#034;, false);<br \/>\n    }<\/p>\n<p>\/\/\u751f\u6210 ASCII \u683c\u5f0f\u8ddf\u8e2a\u6587\u4ef6 &#034;tcp-bulk-send.tr&#034;<br \/>\n\/\/\u751f\u6210 PCAP \u683c\u5f0f\u8ddf\u8e2a\u6587\u4ef6&#xff0c;\u53ef\u7528\u4e8e Wireshark \u5206\u6790<br \/>\n\/\/<br \/>\n\/\/ Now, do the actual simulation.<br \/>\n\/\/<br \/>\n  NS_LOG_INFO (&#034;Run Simulation.&#034;);<br \/>\n  Simulator::Stop (Seconds (10.0));\/\/ \u8bbe\u7f6e\u6a21\u62df\u505c\u6b62\u65f6\u95f4<br \/>\n  Simulator::Run ();<br \/>\n  Simulator::Destroy ();<br \/>\n  NS_LOG_INFO (&#034;Done.&#034;);<\/p>\n<p>  \/\/ \u83b7\u53d6\u5e76\u8f93\u51fa\u7edf\u8ba1\u4fe1\u606f<br \/>\n  Ptr&lt;PacketSink&gt; sink1 &#061; DynamicCast&lt;PacketSink&gt; (sinkApps.Get (0));<br \/>\n  std::cout &lt;&lt; &#034;Total Bytes Received: &#034; &lt;&lt; sink1-&gt;GetTotalRx () &lt;&lt; std::endl;<br \/>\n} <\/p>\n<h6 id=\"%E7%A8%8B%E5%BA%8F%E5%8A%9F%E8%83%BD%E5%92%8C%E6%89%A7%E8%A1%8C%E9%80%BB%E8%BE%91\">\u7a0b\u5e8f\u529f\u80fd\u548c\u6267\u884c\u903b\u8f91<\/h6>\n<p>1\u3001\u7f51\u7edc\u62d3\u6251&#xff1a;n0&#xff08;10.1.1.1&#xff09;&#8212;&#8211;[500kbps,5ms]&#8212;&#8211;n1(10.1.1.2)<\/p>\n<p>2\u3001TCP\u8fde\u63a5\u5efa\u7acb\u8fc7\u7a0b&#xff08;\u4e09\u6b21\u63e1\u624b&#xff09;&#xff1a;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0.0s&#xff1a;n0\u542f\u52a8BulkSend \u5e94\u7528&#xff0c;n1 \u542f\u52a8 PacketSink \u5e94\u7528<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 n0 \u5411 n1 \u53d1\u8d77 TCP \u8fde\u63a5&#xff08;SYN&#xff09;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0n1 \u56de\u590d SYN-ACK<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0n0 \u53d1\u9001 ACK&#xff0c;\u8fde\u63a5\u5efa\u7acb<\/p>\n<p>3\u3001\u6570\u636e\u4f20\u8f93\u8fc7\u7a0b&#xff1a;<\/p>\n<ul>\n<li>\n<p>TCP \u6d41\u63a7\u5236&#xff1a;ns-3 \u4e2d\u7684 TCP \u5b9e\u73b0\u4f1a\u81ea\u52a8\u8fdb\u884c\u62e5\u585e\u63a7\u5236<\/p>\n<\/li>\n<li>\n<p>\u6570\u636e\u4f20\u8f93&#xff1a;n0 \u6301\u7eed\u53d1\u9001\u6570\u636e&#xff0c;\u76f4\u5230&#xff1a;\u8fbe\u5230 maxBytes \u9650\u5236\u6216\u5230\u8fbe\u505c\u6b62\u65f6\u95f4<\/p>\n<\/li>\n<li>\n<p>\u63a5\u6536\u786e\u8ba4&#xff1a;n1 \u63a5\u6536\u6570\u636e\u5e76\u53d1\u9001 ACK<\/p>\n<\/li>\n<\/ul>\n<p>4\u3001\u6267\u884c\u65f6\u95f4\u7ebf&#xff1a;<\/p>\n<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\" style=\"width:500px\">\n<tbody>\n<tr>\n<td>\u65f6\u95f4&#xff08;\u79d2&#xff09;<\/td>\n<td style=\"text-align:center\">\u4e8b\u4ef6<\/td>\n<\/tr>\n<tr>\n<td>0.0<\/td>\n<td>TCP\u8fde\u63a5\u5efa\u7acb\u5f00\u59cb&#xff0c;\u6570\u636e\u4f20\u8f93\u5f00\u59cb<\/td>\n<\/tr>\n<tr>\n<td>\u2026<\/td>\n<td>\u6570\u636e\u4f20\u8f93\u8fdb\u884c\u4e2d<\/td>\n<\/tr>\n<tr>\n<td>9.999&#043;<\/td>\n<td>n0\u53d1\u9001\u6700\u540e\u4e00\u4e2a\u6570\u636e\u5305<\/td>\n<\/tr>\n<tr>\n<td>10.0<\/td>\n<td>\n<p>\u5e94\u7528\u7a0b\u5e8f\u505c\u6b62&#xff0c;TCP\u53efianjie\u6b63\u5e38\u5173\u95ed<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>10.0&#043;<\/td>\n<td>\u6a21\u62df\u7ed3\u675f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>5\u3001\u5173\u952e\u7279\u70b9&#xff1a;<\/p>\n<p id=\"BulkSendApplication%20%E7%89%B9%E6%80%A7\">BulkSendApplication \u7279\u6027<\/p>\n<ul>\n<li>\n<p>\u6301\u7eed\u751f\u6210\u6570\u636e\u5e76\u5c3d\u53ef\u80fd\u5feb\u5730\u53d1\u9001<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528 TCP \u534f\u8bae&#xff0c;\u786e\u4fdd\u53ef\u9760\u4f20\u8f93<\/p>\n<\/li>\n<li>\n<p>\u81ea\u52a8\u5904\u7406 TCP \u7684\u6d41\u63a7\u5236\u548c\u62e5\u585e\u63a7\u5236<\/p>\n<\/li>\n<\/ul>\n<p id=\"TCP%20%E5%8D%8F%E8%AE%AE%E6%A0%88%E9%85%8D%E7%BD%AE\">TCP \u534f\u8bae\u6808\u914d\u7f6e<\/p>\n<p>\u7a0b\u5e8f\u4f7f\u7528\u4e86 ns-3 \u7684\u9ed8\u8ba4 TCP \u5b9e\u73b0&#xff08;\u901a\u5e38\u662f TcpNewReno&#xff09;&#xff0c;\u5305\u62ec&#xff1a;<\/p>\n<li>\n<p>\u6162\u542f\u52a8&#xff1a;\u8fde\u63a5\u5f00\u59cb\u65f6\u6307\u6570\u589e\u957f\u62e5\u585e\u7a97\u53e3<\/p>\n<\/li>\n<li>\n<p>\u62e5\u585e\u907f\u514d&#xff1a;\u62e5\u585e\u7a97\u53e3\u7ebf\u6027\u589e\u957f<\/p>\n<\/li>\n<li>\n<p>\u5feb\u901f\u91cd\u4f20\/\u5feb\u901f\u6062\u590d&#xff1a;\u5904\u7406\u4e22\u5305\u60c5\u51b5<\/p>\n<\/li>\n<p id=\"%E9%93%BE%E8%B7%AF%E5%AE%B9%E9%87%8F%E4%B8%8E%E7%90%86%E8%AE%BA%E6%9C%80%E5%A4%A7%E4%BC%A0%E8%BE%93%E9%87%8F\">\u94fe\u8def\u5bb9\u91cf\u4e0e\u7406\u8bba\u6700\u5927\u4f20\u8f93\u91cf<\/p>\n<ul>\n<li>\n<p>\u94fe\u8def\u5e26\u5bbd&#xff1a;500 Kbps &#061; 62.5 KB\/s<\/p>\n<\/li>\n<li>\n<p>\u6a21\u62df\u65f6\u95f4&#xff1a;10 \u79d2<\/p>\n<\/li>\n<li>\n<p>\u7406\u8bba\u6700\u5927\u4f20\u8f93\u91cf&#xff1a;62.5 KB\/s \u00d7 10s &#061; 625 KB<\/p>\n<\/li>\n<li>\n<p>\u8003\u8651 TCP \u5efa\u7acb\/\u5173\u95ed\u5f00\u9500\u548c\u62e5\u585e\u63a7\u5236&#xff0c;\u5b9e\u9645\u4f20\u8f93\u91cf\u4f1a\u7565\u4f4e\u4e8e\u6b64\u503c<\/p>\n<\/li>\n<\/ul>\n<p>6\u3001\u8f93\u51fa\u7ed3\u679c\u5206\u6790<\/p>\n<p>\u7a0b\u5e8f\u6700\u540e\u8f93\u51fa\u7684 &#034;Total Bytes Received&#034; \u53ef\u4ee5\u7528\u4e8e&#xff1a;<\/p>\n<ul>\n<li>\u8ba1\u7b97\u541e\u5410\u91cf&#xff1a;\u603b\u5b57\u8282\u6570\/\u4f20\u8f93\u65f6\u95f4<\/li>\n<li>\u8bc4\u4f30TCP\u6027\u80fd&#xff1a;\u6bd4\u8f83\u4e16\u7eaa\u541e\u5410\u91cf\u4e0e\u7406\u8bba\u6700\u5927\u503c<\/li>\n<li>\u5206\u6790\u6548\u7387&#xff1a;\u8003\u8651TCP\u5f00\u9500\u540e\u7684\u5b9e\u9645\u6548\u7387<\/li>\n<\/ul>\n<ul>\n<li>\n<h5 id=\"%EF%BD%9Eexamples%2Frouting%2Fsimple-global-routing.cc\">&#xff5e;examples\/routing\/simple-global-routing.cc<\/h5>\n<\/li>\n<\/ul>\n<p>\/* -*- Mode:C&#043;&#043;; c-file-style:&#034;gnu&#034;; indent-tabs-mode:nil; -*- *\/<br \/>\n\/*<br \/>\n * \u4f7f\u7528 ns-3 \u7f51\u7edc\u6a21\u62df\u5668\u521b\u5efa\u7684\u661f\u578b\u7f51\u7edc\u62d3\u6251\u793a\u4f8b&#xff0c;\u6f14\u793a\u4e86\u5168\u5c40\u8def\u7531\u548c\u591a\u4e2a\u6570\u636e\u6d41&#xff08;UDP&#xff09;\u7684\u573a\u666f<br \/>\n *<br \/>\n *<br \/>\n *\/<\/p>\n<p>\/\/\u62d3\u6251\u7ed3\u6784&#xff1a;\u8282\u70b9 n2 \u4f5c\u4e3a\u4e2d\u5fc3\u8282\u70b9&#xff0c;\u8fde\u63a5 n0\u3001n1 \u548c n3<br \/>\n\/\/ Network topology<br \/>\n\/\/<br \/>\n\/\/  n0<br \/>\n\/\/     \\\\ 5 Mb\/s, 2ms<br \/>\n\/\/      \\\\          1.5Mb\/s, 10ms<br \/>\n\/\/       n2 &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-n3<br \/>\n\/\/      \/<br \/>\n\/\/     \/ 5 Mb\/s, 2ms<br \/>\n\/\/   n1<br \/>\n\/\/<br \/>\n\/\/ &#8211; all links are point-to-point links with indicated one-way BW\/delay<br \/>\n\/\/ &#8211; CBR\/UDP flows from n0 to n3, and from n3 to n1<br \/>\n\/\/ &#8211; FTP\/TCP flow from n0 to n3, starting at time 1.2 to time 1.35 sec.<br \/>\n\/\/ &#8211; UDP packet size of 210 bytes, with per-packet interval 0.00375 sec.<br \/>\n\/\/   (i.e., DataRate of 448,000 bps)<br \/>\n\/\/ &#8211; DropTail queues<br \/>\n\/\/ &#8211; Tracing of queues and packet receptions to file &#034;simple-global-routing.tr&#034;<\/p>\n<p>#include &lt;iostream&gt;<br \/>\n#include &lt;fstream&gt;<br \/>\n#include &lt;string&gt;<br \/>\n#include &lt;cassert&gt;<\/p>\n<p>#include &#034;ns3\/core-module.h&#034;<br \/>\n#include &#034;ns3\/network-module.h&#034;<br \/>\n#include &#034;ns3\/internet-module.h&#034;<br \/>\n#include &#034;ns3\/point-to-point-module.h&#034;<br \/>\n#include &#034;ns3\/applications-module.h&#034;<br \/>\n#include &#034;ns3\/flow-monitor-helper.h&#034;\/\/\u6d41\u91cf\u76d1\u63a7\u52a9\u624b<br \/>\n#include &#034;ns3\/ipv4-global-routing-helper.h&#034;\/\/\u5168\u5c40\u8def\u7531\u52a9\u624b<\/p>\n<p>using namespace ns3;<\/p>\n<p>NS_LOG_COMPONENT_DEFINE (&#034;SimpleGlobalRoutingExample&#034;);<\/p>\n<p>int<br \/>\nmain (int argc, char *argv[])<br \/>\n{<br \/>\n  \/\/ Users may find it convenient to turn on explicit debugging<br \/>\n  \/\/ for selected modules; the below lines suggest how to do this<br \/>\n#if 0<br \/>\n  LogComponentEnable (&#034;SimpleGlobalRoutingExample&#034;, LOG_LEVEL_INFO);<br \/>\n#endif<\/p>\n<p>  \/\/\u914d\u7f6e\u9ed8\u8ba4\u53c2\u6570&#xff1a; \u8bbe\u7f6e OnOff \u5e94\u7528\u7684\u9ed8\u8ba4\u6570\u636e\u5305\u5927\u5c0f&#xff08;210\u5b57\u8282&#xff09;\u548c\u6570\u636e\u901f\u7387&#xff08;448 kbps&#xff09;<br \/>\n  Config::SetDefault (&#034;ns3::OnOffApplication::PacketSize&#034;, UintegerValue (210));<br \/>\n  Config::SetDefault (&#034;ns3::OnOffApplication::DataRate&#034;, StringValue (&#034;448kb\/s&#034;));<\/p>\n<p>  \/\/DefaultValue::Bind (&#034;DropTailQueue::m_maxPackets&#034;, 30);\/\/\u961f\u5217\u957f\u5ea6\u8bbe\u7f6e\u4e3a30<\/p>\n<p>  \/\/ \u547d\u4ee4\u884c\u53c2\u6570\u5904\u7406&#xff1a; &#8211;EnableMonitor \u6765\u63a7\u5236\u662f\u5426\u542f\u7528\u6d41\u91cf\u76d1\u63a7<br \/>\n  \/\/ DefaultValue::Bind ()s at run-time, via command-line arguments<br \/>\n  CommandLine cmd (__FILE__);<br \/>\n  bool enableFlowMonitor &#061; false;<br \/>\n  cmd.AddValue (&#034;EnableMonitor&#034;, &#034;Enable Flow Monitor&#034;, enableFlowMonitor);<br \/>\n  cmd.Parse (argc, argv);<\/p>\n<p>  \/\/ Here, we will explicitly create four nodes.  In more sophisticated<br \/>\n  \/\/ topologies, we could configure a node factory.<br \/>\n  NS_LOG_INFO (&#034;Create nodes.&#034;);<br \/>\n  NodeContainer c;<br \/>\n  c.Create (4);\/\/\u521b\u5efa4\u4e2a\u8282\u70b9&#xff0c;\u5b9a\u4e49\u4e09\u4e2a\u70b9\u5bf9\u70b9\u8fde\u63a5<br \/>\n  NodeContainer n0n2 &#061; NodeContainer (c.Get (0), c.Get (2));<br \/>\n  NodeContainer n1n2 &#061; NodeContainer (c.Get (1), c.Get (2));<br \/>\n  NodeContainer n3n2 &#061; NodeContainer (c.Get (3), c.Get (2));<\/p>\n<p>  InternetStackHelper internet;<br \/>\n  internet.Install (c);\/\/\u5728\u6240\u6709\u8282\u70b9\u4e0a\u5b89\u88c5TCP\/IP\u534f\u8bae\u6808<\/p>\n<p>  \/\/ \u521b\u5efa\u70b9\u5bf9\u70b9\u94fe\u8def\u548c\u8bbe\u5907<br \/>\n  NS_LOG_INFO (&#034;Create channels.&#034;);<br \/>\n  PointToPointHelper p2p;<br \/>\n  p2p.SetDeviceAttribute (&#034;DataRate&#034;, StringValue (&#034;5Mbps&#034;));<br \/>\n  p2p.SetChannelAttribute (&#034;Delay&#034;, StringValue (&#034;2ms&#034;));<br \/>\n  NetDeviceContainer d0d2 &#061; p2p.Install (n0n2);\/\/n0-n2\u94fe\u8def&#xff1a;5Mbps&#xff0c;2ms<\/p>\n<p>  NetDeviceContainer d1d2 &#061; p2p.Install (n1n2);\/\/n1-n2\u94fe\u8def&#xff1a;5Mbps&#xff0c;2ms<\/p>\n<p>  p2p.SetDeviceAttribute (&#034;DataRate&#034;, StringValue (&#034;1500kbps&#034;));<br \/>\n  p2p.SetChannelAttribute (&#034;Delay&#034;, StringValue (&#034;10ms&#034;));<br \/>\n  NetDeviceContainer d3d2 &#061; p2p.Install (n3n2);\/\/n3-n2\u94fe\u8def&#xff1a;1.5Mbps&#xff0c;10ms<\/p>\n<p>  \/\/ \u5206\u914dIP\u5730\u5740<br \/>\n  NS_LOG_INFO (&#034;Assign IP Addresses.&#034;);<br \/>\n  Ipv4AddressHelper ipv4;<br \/>\n  ipv4.SetBase (&#034;10.1.1.0&#034;, &#034;255.255.255.0&#034;);<br \/>\n  Ipv4InterfaceContainer i0i2 &#061; ipv4.Assign (d0d2);\/\/n0-n2&#xff1a;10.1.1.0\/24<\/p>\n<p>  ipv4.SetBase (&#034;10.1.2.0&#034;, &#034;255.255.255.0&#034;);<br \/>\n  Ipv4InterfaceContainer i1i2 &#061; ipv4.Assign (d1d2);\/\/n1-n2&#xff1a;10.1.2.0\/24<\/p>\n<p>  ipv4.SetBase (&#034;10.1.3.0&#034;, &#034;255.255.255.0&#034;);<br \/>\n  Ipv4InterfaceContainer i3i2 &#061; ipv4.Assign (d3d2);\/\/n3-n2&#xff1a;10.1.3.0\/24<\/p>\n<p>  \/\/ \u914d\u7f6e\u5168\u5c40\u8def\u7531&#xff1a;\u8ba1\u7b97\u5e76\u5b89\u88c5\u5168\u5c40\u8def\u7531\u8868&#xff0c;\u8ba9\u6240\u6709\u8282\u70b9\u77e5\u9053\u5982\u4f55\u5230\u8fbe\u7f51\u7edc\u4e2d\u7684\u6240\u6709\u5176\u4ed6\u8282\u70b9<br \/>\n  Ipv4GlobalRoutingHelper::PopulateRoutingTables ();<\/p>\n<p>  \/\/ \u521b\u5efa\u5e94\u7528\u7a0b\u5e8f<br \/>\n  \/\/ 210 bytes at a rate of 448 Kb\/s<br \/>\n  NS_LOG_INFO (&#034;Create Applications.&#034;);<br \/>\n  \/\/\u7b2c\u4e00\u4e2a UDP \u6d41&#xff08;n0 \u2192 n3&#xff09;<br \/>\n  uint16_t port &#061; 9;   \/\/ Discard port (RFC 863)<br \/>\n  OnOffHelper onoff (&#034;ns3::UdpSocketFactory&#034;,<br \/>\n                     Address (InetSocketAddress (i3i2.GetAddress (0), port)));<br \/>\n  onoff.SetConstantRate (DataRate (&#034;448kb\/s&#034;));<br \/>\n  ApplicationContainer apps &#061; onoff.Install (c.Get (0));\/\/\u5b89\u88c5\u5728n0<br \/>\n  apps.Start (Seconds (1.0));<br \/>\n  apps.Stop (Seconds (10.0));<\/p>\n<p>  \/\/\u521b\u5efa\u7b2c\u4e00\u4e2a\u6570\u636e\u5305\u63a5\u6536\u5668&#xff08;\u5728 n3&#xff09;<br \/>\n  PacketSinkHelper sink (&#034;ns3::UdpSocketFactory&#034;,<br \/>\n                         Address (InetSocketAddress (Ipv4Address::GetAny (), port)));<br \/>\n  apps &#061; sink.Install (c.Get (3));\/\/ \u5728 n3 \u4e0a\u5b89\u88c5\u63a5\u6536\u5668<br \/>\n  apps.Start (Seconds (1.0));<br \/>\n  apps.Stop (Seconds (10.0));<\/p>\n<p>  \/\/  \u521b\u5efa\u7b2c\u4e8c\u4e2a UDP \u6d41&#xff08;n3 \u2192 n1&#xff09;<br \/>\n  onoff.SetAttribute (&#034;Remote&#034;,<br \/>\n                      AddressValue (InetSocketAddress (i1i2.GetAddress (0), port)));<br \/>\n  apps &#061; onoff.Install (c.Get (3));\/\/ \u5b89\u88c5\u5728 n3<br \/>\n  apps.Start (Seconds (1.1)); \/\/ \u6bd4\u7b2c\u4e00\u4e2a\u6d41\u665a 0.1 \u79d2\u5f00\u59cb<br \/>\n  apps.Stop (Seconds (10.0));<\/p>\n<p>  \/\/ \u521b\u5efa\u7b2c\u4e8c\u4e2a\u6570\u636e\u5305\u63a5\u6536\u5668&#xff08;\u5728 n1<br \/>\n  apps &#061; sink.Install (c.Get (1));\/\/ \u5728 n1 \u4e0a\u5b89\u88c5\u63a5\u6536\u5668<br \/>\n  apps.Start (Seconds (1.1));<br \/>\n  apps.Stop (Seconds (10.0));<\/p>\n<p>  \/\/\u914d\u7f6e\u8ddf\u8e2a&#xff1a;\u542f\u7528 ASCII \u8ddf\u8e2a\u548c PCAP \u8ddf\u8e2a&#xff0c;\u7528\u4e8e\u540e\u7eed\u5206\u6790<br \/>\n  AsciiTraceHelper ascii;<br \/>\n  p2p.EnableAsciiAll (ascii.CreateFileStream (&#034;simple-global-routing.tr&#034;));<br \/>\n  p2p.EnablePcapAll (&#034;simple-global-routing&#034;);<\/p>\n<p>  \/\/ \u6d41\u91cf\u76d1\u63a7&#xff08;\u53ef\u9009&#xff09;&#xff1a;\u5982\u679c\u547d\u4ee4\u884c\u53c2\u6570\u542f\u7528\u4e86\u6d41\u91cf\u76d1\u63a7&#xff0c;\u5219\u5b89\u88c5\u6d41\u91cf\u76d1\u63a7\u5668<br \/>\n  FlowMonitorHelper flowmonHelper;<br \/>\n  if (enableFlowMonitor)<br \/>\n    {<br \/>\n      flowmonHelper.InstallAll ();<br \/>\n    }<\/p>\n<p>  \/\/\u8fd0\u884c\u6a21\u62df<br \/>\n  NS_LOG_INFO (&#034;Run Simulation.&#034;);<br \/>\n  Simulator::Stop (Seconds (11)); \/\/ \u505c\u6b62\u65f6\u95f4\u6bd4\u5e94\u7528\u505c\u6b62\u65f6\u95f4\u665a1\u79d2<br \/>\n  Simulator::Run ();<br \/>\n  NS_LOG_INFO (&#034;Done.&#034;);<\/p>\n<p>  if (enableFlowMonitor)<br \/>\n    {<br \/>\n      flowmonHelper.SerializeToXmlFile (&#034;simple-global-routing.flowmon&#034;, false, false);<br \/>\n    }<\/p>\n<p>  Simulator::Destroy ();<br \/>\n  return 0;<br \/>\n} <\/p>\n<h6 id=\"%E7%A8%8B%E5%BA%8F%E5%8A%9F%E8%83%BD%E4%B8%8E%E6%89%A7%E8%A1%8C%E9%80%BB%E8%BE%91\">\u7a0b\u5e8f\u529f\u80fd\u4e0e\u6267\u884c\u903b\u8f91<\/h6>\n<p>1\u3001\u7f51\u7edc\u62d3\u6251\u8be6\u60c5&#xff1a;<\/p>\n<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\" style=\"width:500px\">\n<tbody>\n<tr>\n<td colspan=\"2\">\u8282\u70b9\u8fde\u63a5&#xff1a;<\/td>\n<\/tr>\n<tr>\n<td>n0-n2<\/td>\n<td>5Mbps,2ms\u5ef6\u8fdf<\/td>\n<\/tr>\n<tr>\n<td>n1-n2<\/td>\n<td>5Mbps,2ms\u5ef6\u8fdf<\/td>\n<\/tr>\n<tr>\n<td>n3-n2<\/td>\n<td>1.5Mbps,10ms\u5ef6\u8fdf<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\" style=\"width:500px\">\n<tbody>\n<tr>\n<td>IP\u5730\u5740\u5206\u914d&#xff1a;<\/td>\n<\/tr>\n<tr>\n<td>-n0:10.1.1.1(\u63a5\u53e3\u8fde\u63a5\u5230n2)<\/td>\n<\/tr>\n<tr>\n<td>-n1:10.1.2.1(\u63a5\u53e3\u8fde\u63a5\u5230n2)<\/td>\n<\/tr>\n<tr>\n<td>-n2:10.1.1.2,10.1.2.2,10.1.3.1(\u4e09\u4e2a\u63a5\u53e3)<\/td>\n<\/tr>\n<tr>\n<td>-n3:10.1.3.2(\u63a5\u53e3\u8fde\u63a5\u5230n2)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>2\u3001\u6570\u636e\u6d41\u8be6\u60c5&#xff1a;<\/p>\n<ul>\n<li>\u6d411&#xff1a;n0-n3&#xff08;UDP&#xff09;<\/li>\n<\/ul>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u5f00\u59cb\u65f6\u95f4&#xff1a;1.0s<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u7ed3\u675f\u65f6\u95f4&#xff1a;10.0s<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u6570\u636e\u901f\u7387&#xff1a;448kbps<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u6570\u636e\u5305\u5927\u5c0f&#xff1a;210\u5b57\u8282<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u8def\u5f84&#xff1a;n0-n2-n3<\/p>\n<ul>\n<li>\u6d412&#xff1a;n3-n1&#xff08;UDP&#xff09;<\/li>\n<\/ul>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u5f00\u59cb\u65f6\u95f4&#xff1a;1.1s<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u7ed3\u675f\u65f6\u95f4&#xff1a;10.0s<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u6570\u636e\u901f\u7387&#xff1a;448kbps<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u6570\u636e\u5305\u5927\u5c0f&#xff1a;210\u5b57\u8282<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u8def\u5f84&#xff1a;n3-n2-n1<\/p>\n<p>3\u3001\u6267\u884c\u65f6\u95f4&#xff1a;<\/p>\n<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\" style=\"width:500px\">\n<tbody>\n<tr>\n<td style=\"text-align:center;width:96px\">\u65f6\u95f4&#xff08;\u79d2&#xff09;<\/td>\n<td style=\"text-align:center;width:402px\">\u4e8b\u4ef6<\/td>\n<\/tr>\n<tr>\n<td style=\"width:96px\">0.0<\/td>\n<td style=\"width:402px\">\u6a21\u62df\u5f00\u59cb&#xff0c;\u8def\u7531\u8868\u5efa\u7acb<\/td>\n<\/tr>\n<tr>\n<td style=\"width:96px\">1.0<\/td>\n<td style=\"width:402px\">n0\u5f00\u59cb\u5411n3\u53d1\u9001UDP\u6570\u636e&#xff0c;n3\u5f00\u59cb\u63a5\u6536<\/td>\n<\/tr>\n<tr>\n<td style=\"width:96px\">1.1<\/td>\n<td style=\"width:402px\">n3\u5f00\u59cb\u5411n1\u53d1\u9001UDP\u6570\u636e&#xff0c;n1\u5f00\u59cb\u63a5\u6536<\/td>\n<\/tr>\n<tr>\n<td style=\"width:96px\">10.0<\/td>\n<td style=\"width:402px\">\u6240\u6709\u53d1\u9001\u5e94\u7528\u505c\u6b62<\/td>\n<\/tr>\n<tr>\n<td style=\"width:96px\">10.0<\/td>\n<td style=\"width:402px\">\u6240\u6709\u63a5\u6536\u5e94\u7528\u505c\u6b62&#xff08;\u5b9e\u9645\u4e0a\u63a5\u53d7\u5668\u4f1a\u7ee7\u7eed\u63a5\u6536\u5df2\u7ecf\u5728\u9014\u7684\u6570\u636e\u5305&#xff09;<\/td>\n<\/tr>\n<tr>\n<td style=\"width:96px\">11.0<\/td>\n<td style=\"width:402px\">\u6a21\u62df\u7ed3\u675f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>4\u3001\u8def\u7531\u673a\u5236&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u4f7f\u7528 Ipv4GlobalRoutingHelper::PopulateRoutingTables() \u81ea\u52a8\u8ba1\u7b97\u6700\u4f73\u8def\u7531<\/p>\n<\/li>\n<li>\n<p>n2 \u4f5c\u4e3a\u8def\u7531\u5668&#xff0c;\u8d1f\u8d23\u8f6c\u53d1 n0-n3 \u548c n3-n1 \u4e4b\u95f4\u7684\u6570\u636e\u5305<\/p>\n<\/li>\n<li>\n<p>\u8def\u7531\u8868\u57fa\u4e8e\u94fe\u8def\u6210\u672c&#xff08;\u5e26\u5bbd\u548c\u5ef6\u8fdf&#xff09;\u81ea\u52a8\u8ba1\u7b97<\/p>\n<\/li>\n<\/ul>\n<p>5\u3001\u5173\u952e\u7279\u70b9&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u4e0d\u5bf9\u79f0\u94fe\u8def\u5e26\u5bbd&#xff1a;n2-n3 \u94fe\u8def&#xff08;1.5 Mbps&#xff09;\u6bd4\u5176\u4ed6\u94fe\u8def&#xff08;5 Mbps&#xff09;\u6162&#xff0c;\u53ef\u80fd\u6210\u4e3a\u74f6\u9888<\/p>\n<\/li>\n<li>\n<p>\u591a\u8df3\u901a\u4fe1&#xff1a;n0 \u548c n3 \u4e4b\u95f4\u7684\u901a\u4fe1\u9700\u8981\u7ecf\u8fc7 n2 \u8f6c\u53d1<\/p>\n<\/li>\n<li>\n<p>\u5168\u5c40\u8def\u7531&#xff1a;\u81ea\u52a8\u8ba1\u7b97\u548c\u914d\u7f6e\u6240\u6709\u8282\u70b9\u7684\u8def\u7531\u8868<\/p>\n<\/li>\n<li>\n<p>\u5e76\u53d1 UDP \u6d41&#xff1a;\u4e24\u4e2a\u65b9\u5411\u76f8\u53cd\u7684 UDP \u6570\u636e\u6d41\u540c\u65f6\u8fd0\u884c<\/p>\n<\/li>\n<li>\n<p>\u5b8c\u6574\u7684\u534f\u8bae\u6808&#xff1a;\u4f7f\u7528 TCP\/IP \u534f\u8bae\u6808&#xff0c;\u800c\u4e0d\u4ec5\u4ec5\u662f\u539f\u59cb\u6570\u636e\u5305<\/p>\n<\/li>\n<\/ul>\n<p>6\u3001\u8f93\u51fa\u6587\u4ef6&#xff1a;<\/p>\n<ul>\n<li>\n<p>simple-global-routing.tr&#xff1a;ASCII \u683c\u5f0f\u7684\u7f51\u7edc\u4e8b\u4ef6\u8ddf\u8e2a<\/p>\n<\/li>\n<li>\n<p>simple-global-routing-0-1.pcap \u7b49&#xff1a;\u6bcf\u4e2a\u8282\u70b9\u7684 PCAP \u6587\u4ef6&#xff0c;\u53ef\u7528 Wireshark \u5206\u6790<\/p>\n<\/li>\n<li>\n<p>simple-global-routing.flowmon&#xff08;\u53ef\u9009&#xff09;&#xff1a;\u5982\u679c\u542f\u7528\u6d41\u91cf\u76d1\u63a7&#xff0c;\u751f\u6210 XML \u683c\u5f0f\u7684\u6d41\u91cf\u7edf\u8ba1<\/p>\n<\/li>\n<\/ul>\n<ul>\n<li>\n<h5 id=\"%EF%BD%9Esrc%2Fcsma%2Fexamples%2Fcsma-packet-socket.cc\">&#xff5e;src\/csma\/examples\/csma-packet-socket.cc<\/h5>\n<\/li>\n<\/ul>\n<p>\/* -*- Mode:C&#043;&#043;; c-file-style:&#034;gnu&#034;; indent-tabs-mode:nil; -*- *\/<br \/>\n\/*<br \/>\n\u4f7f\u7528 ns-3 \u7f51\u7edc\u6a21\u62df\u5668\u521b\u5efa\u7684 CSMA&#xff08;\u8f7d\u6ce2\u4fa6\u542c\u591a\u8def\u8bbf\u95ee&#xff09;\u7f51\u7edc\u793a\u4f8b<br \/>\n\u6f14\u793a\u4e86\u539f\u59cb\u6570\u636e\u5305\u5957\u63a5\u5b57&#xff08;Packet Socket&#xff09;\u901a\u4fe1<br \/>\n *\/<\/p>\n<p>\/\/\u7f51\u7edc\u62d3\u6251\u8bf4\u660e&#xff1a;4\u4e2a\u8282\u70b9\u901a\u8fc7\u4e00\u4e2a\u5171\u4eab\u7684 CSMA \u603b\u7ebf\u8fde\u63a5<br \/>\n\/\/<br \/>\n\/\/<br \/>\n\/\/       n0    n1   n2   n3<br \/>\n\/\/       |     |    |    |<br \/>\n\/\/     &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n\/\/<br \/>\n\/\/ &#8211; Two packet socket flows:  from n0 to n1 and from n3 to n0<br \/>\n\/\/ &#8211; Default 512 byte packets generated by traffic generator<br \/>\n\/\/ &#8211; Output from the PacketSink trace source will be sent to the<br \/>\n\/\/      csma-packet-socket-sink.tr file<br \/>\n\/\/   ASCII trace output will be sent to the csma-packet-socket.tr file<\/p>\n<p>#include &lt;iostream&gt;<br \/>\n#include &lt;fstream&gt;<br \/>\n#include &lt;string&gt;<br \/>\n#include &lt;cassert&gt;<\/p>\n<p>#include &#034;ns3\/core-module.h&#034;\/\/ns3\u6838\u5fc3\u6a21\u5757<br \/>\n#include &#034;ns3\/network-module.h&#034;\/\/\u7f51\u7edc\u6a21\u5757<br \/>\n#include &#034;ns3\/csma-module.h&#034;\/\/CSMA\u6a21\u5757<br \/>\n#include &#034;ns3\/applications-module.h&#034;\/\/\u5e94\u7528\u5c42\u6a21\u5757<\/p>\n<p>using namespace ns3;<\/p>\n<p>NS_LOG_COMPONENT_DEFINE (&#034;CsmaPacketSocketExample&#034;);<\/p>\n<p>std::ofstream g_os;\/\/\u5168\u5c40\u53d8\u91cf&#xff1a;\u5168\u5c40\u8f93\u51fa\u6587\u4ef6\u6d41<\/p>\n<p>\/\/\u56de\u8c03\u51fd\u6570&#xff1a;\u8be5\u56de\u8c03\u51fd\u6570\u5728PacketSink\u63a5\u6536\u5230\u6570\u636e\u5305\u65f6\u88ab\u8c03\u7528&#xff0c;\u5c06\u6570\u636e\u5305\u5927\u5c0f\u5199\u5165\u6587\u4ef6<br \/>\nstatic void<br \/>\nSinkRx (std::string path, Ptr&lt;const Packet&gt; p, const Address &amp;address)<br \/>\n{<br \/>\n  g_os &lt;&lt; p-&gt;GetSize () &lt;&lt; std::endl;\/\/\u8bb0\u5f55\u63a5\u6536\u5230\u7684\u6570\u636e\u5305\u5927\u5c0f<br \/>\n}<\/p>\n<p>\/\/\u4e3b\u51fd\u6570<br \/>\nint<br \/>\nmain (int argc, char *argv[])<br \/>\n{<br \/>\n#if 0<br \/>\n  LogComponentEnable (&#034;CsmaPacketSocketExample&#034;, LOG_LEVEL_INFO);<br \/>\n#endif<\/p>\n<p>\/\/\u6253\u5f00\u8f93\u51fa\u6587\u4ef6&#xff0c;\u7528\u4e8e\u8bb0\u5f55\u63a5\u6536\u5230\u7684\u6570\u636e\u5305\u4fe1\u606f<br \/>\n  CommandLine cmd (__FILE__);<br \/>\n  cmd.Parse (argc, argv);<\/p>\n<p>  g_os.open (&#034;csma-packet-socket-sink.tr&#034;,std::ios_base::binary | std::ios_base::out);<\/p>\n<p>  \/\/ \u521b\u5efa\u7f51\u7edc\u7ed3\u70b9<br \/>\n  NS_LOG_INFO (&#034;Create nodes.&#034;);<br \/>\n  NodeContainer nodes;<br \/>\n  nodes.Create (4);<\/p>\n<p>  \/\/\u5b89\u88c5PacketSocket<br \/>\n  PacketSocketHelper packetSocket;<br \/>\n  packetSocket.Install (nodes);\/\/\u5728\u6240\u6709\u7ed3\u70b9\u4e0a\u5b89\u88c5\u539f\u59cb\u6570\u636e\u5305\u5957\u63a5\u5b57<\/p>\n<p>  \/\/ \u521b\u5efaCSMA\u4fe1\u9053\u548c\u8bbe\u5907<br \/>\n  NS_LOG_INFO (&#034;Create channels.&#034;);<br \/>\n  Ptr&lt;CsmaChannel&gt; channel &#061; CreateObjectWithAttributes&lt;CsmaChannel&gt; (<br \/>\n      &#034;DataRate&#034;, DataRateValue (DataRate (5000000)),\/\/5Mbps<br \/>\n      &#034;Delay&#034;, TimeValue (MilliSeconds (2)));\/\/2ms \u8fdf\u5ef6<\/p>\n<p>  \/\/ use a helper function to connect our nodes to the shared channel.<br \/>\n  NS_LOG_INFO (&#034;Build Topology.&#034;);<br \/>\n  CsmaHelper csma;<br \/>\n  csma.SetDeviceAttribute (&#034;EncapsulationMode&#034;, StringValue (&#034;Llc&#034;));\/\/LLC\u5c01\u88c5<br \/>\n  NetDeviceContainer devs &#061; csma.Install (nodes, channel);\/\/\u5b89\u88c5CSMA\u8bbe\u5907<\/p>\n<p>  NS_LOG_INFO (&#034;Create Applications.&#034;);<br \/>\n  \/\/\u521b\u5efa\u5e94\u7528\u7a0b\u5e8f-\u4e24\u4e2a\u6570\u636e\u6d41<\/p>\n<p>  \/\/\u7b2c\u4e00\u4e2a\u6570\u636e\u6d41&#xff1a;\u4ece\u8282\u70b90\u5230\u8282\u70b91<br \/>\n  PacketSocketAddress socket;<br \/>\n  socket.SetSingleDevice (devs.Get (0)-&gt;GetIfIndex ());\/\/\u4f7f\u7528\u8282\u70b90\u7684\u8bbe\u5907<br \/>\n  socket.SetPhysicalAddress (devs.Get (1)-&gt;GetAddress ());\/\/\u76ee\u6807&#xff1a;\u8282\u70b91\u7684MAC\u5730\u5740<br \/>\n  socket.SetProtocol (2);\/\/\u534f\u8bae\u53f72<br \/>\n  OnOffHelper onoff (&#034;ns3::PacketSocketFactory&#034;, Address (socket));<br \/>\n  onoff.SetConstantRate (DataRate (&#034;500kb\/s&#034;));\/\/500 Kbps\u6052\u5b9a\u901f\u7387<br \/>\n  ApplicationContainer apps &#061; onoff.Install (nodes.Get (0));\/\/\u5b89\u88c5\u5728\u8282\u70b90<br \/>\n  apps.Start (Seconds (1.0));<br \/>\n  apps.Stop (Seconds (10.0));<\/p>\n<p>  \/\/\u7b2c\u4e8c\u4e2a\u6570\u636e\u6d41&#xff1a;\u4ece\u8282\u70b93\u5230\u8282\u70b90<br \/>\n  socket.SetSingleDevice (devs.Get (3)-&gt;GetIfIndex ());\/\/\u4f7f\u7528\u8282\u70b93\u7684\u8bbe\u5907<br \/>\n  socket.SetPhysicalAddress (devs.Get (0)-&gt;GetAddress ());\/\/\u76ee\u6807&#xff1a;\u8282\u70b90\u7684MAC\u5730\u5740<br \/>\n  socket.SetProtocol (3);\/\/\u534f\u8bae\u53f73<br \/>\n  onoff.SetAttribute (&#034;Remote&#034;, AddressValue (socket));<br \/>\n  apps &#061; onoff.Install (nodes.Get (3));\/\/\u5b89\u88c5\u5728\u8282\u70b93<br \/>\n  apps.Start (Seconds (1.0));<br \/>\n  apps.Stop (Seconds (10.0));<\/p>\n<p>  \/\/ \u521b\u5efa\u6570\u636e\u5305\u63a5\u6536\u5668&#xff08;Packet Sink&#xff09;<br \/>\n  PacketSinkHelper sink &#061; PacketSinkHelper (&#034;ns3::PacketSocketFactory&#034;,<br \/>\n                                            socket);<br \/>\n  apps &#061; sink.Install (nodes.Get (0));\/\/\u5728\u8282\u70b90\u4e0a\u5b89\u88c5\u63a5\u53d7\u5176<br \/>\n  apps.Start (Seconds (0.0));<br \/>\n  apps.Stop (Seconds (20.0));<\/p>\n<p>  \/\/ While the below trace sink is hooked to all nodes (the wildcard &#034;*&#034;)<br \/>\n  \/\/ only one packet sink (on node 0) is actually added above, so<br \/>\n  \/\/ only the receive events on node 0 will be traced<br \/>\n  \/\/\u8fde\u63a5\u8ddf\u8e2a\u56de\u8c03&#xff1a;\u5c06\u6240\u6709\u7684 PacketSink \u63a5\u6536\u4e8b\u4ef6\u8fde\u63a5\u5230 SinkRx \u56de\u8c03\u51fd\u6570<br \/>\n  Config::Connect (&#034;\/NodeList\/*\/ApplicationList\/*\/$ns3::PacketSink\/Rx&#034;,<br \/>\n                   MakeCallback (&amp;SinkRx));<\/p>\n<p>  \/\/ Configure tracing of all enqueue, dequeue, and NetDevice receive events<br \/>\n  \/\/ Trace output will be sent to the csma-packet-socket.tr file<br \/>\n  NS_LOG_INFO (&#034;Configure Tracing.&#034;);<\/p>\n<p>  \/\/\u542f\u7528ASCII\u8ddf\u8e2a&#xff1a;\u8bb0\u5f55\u6240\u6709\u8282\u70b9\u7684\u7f51\u7edc\u4e8b\u4ef6\u5230 ASCII \u6587\u4ef6<br \/>\n  AsciiTraceHelper ascii;<br \/>\n  csma.EnableAsciiAll (ascii.CreateFileStream (&#034;csma-packet-socket.tr&#034;));<\/p>\n<p>  \/\/\u8fd0\u884c\u6a21\u62df\u548c\u6e05\u7406<br \/>\n  NS_LOG_INFO (&#034;Run Simulation.&#034;);<br \/>\n  Simulator::Run ();\/\/\u8fd0\u884c\u6a21\u62df<br \/>\n  Simulator::Destroy ();\/\/\u6e05\u7406\u6a21\u62df\u5668<br \/>\n  NS_LOG_INFO (&#034;Done.&#034;);\/\/\u5173\u95ed\u8f93\u51fa\u6587\u4ef6<\/p>\n<p>  g_os.close ();<\/p>\n<p>  return 0;<br \/>\n} <\/p>\n<h6 id=\"%E7%A8%8B%E5%BA%8F%E5%8A%9F%E8%83%BD%E4%B8%8E%E6%89%A7%E8%A1%8C%E9%80%BB%E8%BE%91\" style=\"background-color:transparent\">\u7a0b\u5e8f\u529f\u80fd\u4e0e\u6267\u884c\u903b\u8f91<\/h6>\n<p>1\u3001\u4e3b\u8981\u529f\u80fd&#xff1a;<\/p>\n<ul>\n<li>\u00a0\u521b\u5efa\u7f51\u7edc\u62d3\u6251&#xff1a;4\u4e2a\u8282\u70b9\u901a\u8fc7\u5171\u4eabCSMA\u603b\u7ebf\u8fde\u63a5<\/li>\n<li>\u521b\u5efa\u4e24\u4e2a\u539f\u59cb\u6570\u636e\u5305\u6d41&#xff1a;<\/li>\n<\/ul>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u6d411&#xff1a;\u8282\u70b90&#8211;&gt;\u8282\u70b91.\u4f7f\u7528\u534f\u8bae\u53f72&#xff0c;500kbps<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u6d412&#xff1a;\u8282\u70b93 \u2192 \u8282\u70b90&#xff0c;\u4f7f\u7528\u534f\u8bae\u53f73&#xff0c;500 kbps<\/p>\n<ul>\n<li>\u6570\u636e\u5305\u63a5\u6536&#xff1a;\u5728\u8282\u70b90\u4e0a\u5b89\u88c5 PacketSink&#xff0c;\u63a5\u6536\u6765\u81ea\u8282\u70b93\u7684\u6570\u636e\u5305<\/li>\n<li>\u6570\u636e\u5305\u6536\u96c6&#xff1a;<\/li>\n<\/ul>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5c06\u63a5\u6536\u5230\u7684\u6570\u636e\u5305\u5927\u5c0f\u8bb0\u5f55\u5230 csma-packet-socket-sink.tr<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u5c06\u7f51\u7edc\u4e8b\u4ef6\u8bb0\u5f55\u5230 csma-packet-socket.tr<\/p>\n<p>2\u3001\u6267\u884c\u65f6\u95f4\u7ebf&#xff1a;<\/p>\n<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\" style=\"width:500px\">\n<tbody>\n<tr>\n<td>\u65f6\u95f4&#xff08;\u79d2&#xff09;<\/td>\n<td style=\"text-align:center\">\u4e8b\u4ef6<\/td>\n<\/tr>\n<tr>\n<td>0.0<\/td>\n<td>\u8282\u70b90\u7684PacketSink\u5f00\u59cb\u76d1\u542c<\/td>\n<\/tr>\n<tr>\n<td>1.0<\/td>\n<td>\u8282\u70b90\u548c\u8282\u70b93\u5f00\u59cb\u53d1\u9001\u6570\u636e<\/td>\n<\/tr>\n<tr>\n<td>10.0<\/td>\n<td>\u8282\u70b90\u548c\u8282\u70b93\u505c\u6b62\u53d1\u9001\u6570\u636e<\/td>\n<\/tr>\n<tr>\n<td>20.0<\/td>\n<td>\u8282\u70b90\u7684PacketSink\u505c\u6b62\u76d1\u542c&#xff0c;\u6a21\u62df\u7ed3\u675f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>3\u3001\u5173\u952e\u7279\u70b9&#xff1a;<\/p>\n<ul>\n<li>\u00a0\u4f7f\u7528\u539f\u59cb\u6570\u636e\u5305\u5957\u63a5\u5b57&#xff1a;\u4e0d\u4f9d\u8d56IP\u534f\u8bae\u6808&#xff0c;\u76f4\u63a5\u5728\u6570\u636e\u94fe\u8def\u5c42\u901a\u4fe1<\/li>\n<li>CSMA\/CD\u534f\u8bae&#xff1a;\u6a21\u62df\u4ee5\u592a\u7f51\u7684\u591a\u8def\u8bbf\u95ee\u7279\u6027<\/li>\n<li>\u4e24\u4e2a\u72ec\u7acb\u7684\u6570\u636e\u6d41&#xff1a;\u4f7f\u7528\u4e0d\u540c\u7684\u534f\u8bae\u53f7\u8fdb\u884c\u533a\u5206<\/li>\n<li>\u975e\u5bf9\u79f0\u901a\u4fe1&#xff1a;\u8282\u70b90\u65e2\u53d1\u9001\u53c8\u63a5\u6536\u3001\u8282\u70b91\u53ea\u63a5\u6536\u3001\u8282\u70b93\u53ea\u53d1\u9001\u3001\u8282\u70b92\u662f\u7a7a\u95f2\u8282\u70b9<\/li>\n<\/ul>\n<p>4\u3001\u8f93\u51fa\u6587\u4ef6&#xff1a;<\/p>\n<ul>\n<li>\n<p>csma-packet-socket-sink.tr&#xff1a;\u5305\u542b\u6240\u6709\u63a5\u6536\u5230\u7684\u6570\u636e\u5305\u5927\u5c0f<\/p>\n<\/li>\n<li>\n<p>csma-packet-socket.tr&#xff1a;\u5305\u542b\u8be6\u7ec6\u7684\u7f51\u7edc\u4e8b\u4ef6&#xff08;\u6392\u961f\u3001\u53d1\u9001\u3001\u63a5\u6536\u7b49&#xff09;<\/p>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u5f55<br \/>\n\u4e00\u3001\u67b6\u6784\u4e0e\u811a\u672c<br \/>\n1.1 \u6982\u51b5<br \/>\n1.2 \u5efa\u7acb\u4e00\u4e2aUDP\u8fde\u63a5<br \/>\n\u4e8c\u3001\u5185\u7f6e\u5e94\u7528&#xff1a;Application<br \/>\n2.1\u5185\u7f6e\u5e94\u7528<br \/>\n2.2 \u5e94\u7528\u5c42\u534f\u8bae\u52a9\u624b\u7c7b\u4f7f\u7528\u7684\u57fa\u672c\u6b65\u9aa4&#xff1a; 1. \u521b\u5efa\u52a9\u624b\u7c7b\u5bf9\u8c61&#xff1a;\u6307\u5b9a\u4e24\u4e2a\u5f62\u53c2 2. \u914d\u7f6e\u4e13\u5c5e\u5c5e\u6027&#xff08;\u53ef\u9009&#xff09; 3. \u5728\u6307\u5b9a\u7ed3\u70b9\u4e0a\u5b89\u88c5\u5e94\u7528\u5c42\u534f\u8bae 4. \u8bbe\u7f6e\u5e94\u7528\u5c42\u534f\u8bae\u7684\u542f\u52a8\u548c\u505c\u6b62\u65f6\u95f4 5. \u914d\u7f6etrace\u53d8\u91cf&#xff08;\u53ef\u9009&#xff09;<br \/>\n2.3 \u5206\u7ec4\u4ea7\u751f\u5668<br \/>\n2.3.1. \u5206<\/p>\n","protected":false},"author":2,"featured_media":69498,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[7315,78],"topic":[],"class_list":["post-69499","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-ns3","tag-78"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>ns-3\u4eff\u771f\u4e4b\u5e94\u7528\u5c42\uff08\u4e00\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/69499.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"ns-3\u4eff\u771f\u4e4b\u5e94\u7528\u5c42\uff08\u4e00\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u76ee\u5f55 \u4e00\u3001\u67b6\u6784\u4e0e\u811a\u672c 1.1 \u6982\u51b5 1.2 \u5efa\u7acb\u4e00\u4e2aUDP\u8fde\u63a5 \u4e8c\u3001\u5185\u7f6e\u5e94\u7528&#xff1a;Application 2.1\u5185\u7f6e\u5e94\u7528 2.2 \u5e94\u7528\u5c42\u534f\u8bae\u52a9\u624b\u7c7b\u4f7f\u7528\u7684\u57fa\u672c\u6b65\u9aa4&#xff1a; 1. \u521b\u5efa\u52a9\u624b\u7c7b\u5bf9\u8c61&#xff1a;\u6307\u5b9a\u4e24\u4e2a\u5f62\u53c2 2. \u914d\u7f6e\u4e13\u5c5e\u5c5e\u6027&#xff08;\u53ef\u9009&#xff09; 3. \u5728\u6307\u5b9a\u7ed3\u70b9\u4e0a\u5b89\u88c5\u5e94\u7528\u5c42\u534f\u8bae 4. \u8bbe\u7f6e\u5e94\u7528\u5c42\u534f\u8bae\u7684\u542f\u52a8\u548c\u505c\u6b62\u65f6\u95f4 5. \u914d\u7f6etrace\u53d8\u91cf&#xff08;\u53ef\u9009&#xff09; 2.3 \u5206\u7ec4\u4ea7\u751f\u5668 2.3.1. \u5206\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/69499.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-31T11:16:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260131111654-697de4a651de9.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/69499.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/69499.html\",\"name\":\"ns-3\u4eff\u771f\u4e4b\u5e94\u7528\u5c42\uff08\u4e00\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-31T11:16:55+00:00\",\"dateModified\":\"2026-01-31T11:16:55+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/69499.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/69499.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/69499.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"ns-3\u4eff\u771f\u4e4b\u5e94\u7528\u5c42\uff08\u4e00\uff09\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"ns-3\u4eff\u771f\u4e4b\u5e94\u7528\u5c42\uff08\u4e00\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/69499.html","og_locale":"zh_CN","og_type":"article","og_title":"ns-3\u4eff\u771f\u4e4b\u5e94\u7528\u5c42\uff08\u4e00\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u76ee\u5f55 \u4e00\u3001\u67b6\u6784\u4e0e\u811a\u672c 1.1 \u6982\u51b5 1.2 \u5efa\u7acb\u4e00\u4e2aUDP\u8fde\u63a5 \u4e8c\u3001\u5185\u7f6e\u5e94\u7528&#xff1a;Application 2.1\u5185\u7f6e\u5e94\u7528 2.2 \u5e94\u7528\u5c42\u534f\u8bae\u52a9\u624b\u7c7b\u4f7f\u7528\u7684\u57fa\u672c\u6b65\u9aa4&#xff1a; 1. \u521b\u5efa\u52a9\u624b\u7c7b\u5bf9\u8c61&#xff1a;\u6307\u5b9a\u4e24\u4e2a\u5f62\u53c2 2. \u914d\u7f6e\u4e13\u5c5e\u5c5e\u6027&#xff08;\u53ef\u9009&#xff09; 3. \u5728\u6307\u5b9a\u7ed3\u70b9\u4e0a\u5b89\u88c5\u5e94\u7528\u5c42\u534f\u8bae 4. \u8bbe\u7f6e\u5e94\u7528\u5c42\u534f\u8bae\u7684\u542f\u52a8\u548c\u505c\u6b62\u65f6\u95f4 5. \u914d\u7f6etrace\u53d8\u91cf&#xff08;\u53ef\u9009&#xff09; 2.3 \u5206\u7ec4\u4ea7\u751f\u5668 2.3.1. \u5206","og_url":"https:\/\/www.wsisp.com\/helps\/69499.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-31T11:16:55+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260131111654-697de4a651de9.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"12 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/69499.html","url":"https:\/\/www.wsisp.com\/helps\/69499.html","name":"ns-3\u4eff\u771f\u4e4b\u5e94\u7528\u5c42\uff08\u4e00\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-31T11:16:55+00:00","dateModified":"2026-01-31T11:16:55+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/69499.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/69499.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/69499.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"ns-3\u4eff\u771f\u4e4b\u5e94\u7528\u5c42\uff08\u4e00\uff09"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/69499","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=69499"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/69499\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/69498"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=69499"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=69499"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=69499"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=69499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}