Ns3 构建哑铃型拓扑,并实现两个点的TCP连接(详细请戳全文)
如图所示要实现n0到n5的TCP通信
每个链路之间的带宽都是100Mbps
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /** This program is free software; you can redistribute it and/or modify* it under the terms of the GNU General Public License version 2 as* published by the Free Software Foundation;** This program is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the* GNU General Public License for more details.** You should have received a copy of the GNU General Public License* along with this program; if not, write to the Free Software* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/#include "ns3/core-module.h" #include "ns3/network-module.h" #include "ns3/internet-module.h" #include "ns3/point-to-point-module.h" #include "ns3/applications-module.h"using namespace ns3;NS_LOG_COMPONENT_DEFINE ("BottleNeckTcpScriptExample");int main (int argc, char *argv[]) {Time::SetResolution (Time::NS);LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);LogComponentEnable ("BottleNeckTcpScriptExample", LOG_LEVEL_INFO);// LogComponentEnable ("TcpL4Protocol", LOG_LEVEL_INFO);LogComponentEnable ("PacketSink", LOG_LEVEL_ALL);//LogComponentEnable ("OnOff", LOG_LEVEL_ALL); NodeContainer nodes;nodes.Create (6);NodeContainer n0n1 = NodeContainer(nodes.Get(0),nodes.Get(1));NodeContainer n1n2 = NodeContainer(nodes.Get(1),nodes.Get(2));NodeContainer n1n3 = NodeContainer(nodes.Get(1),nodes.Get(3));NodeContainer n3n4 = NodeContainer(nodes.Get(3),nodes.Get(4));NodeContainer n3n5 = NodeContainer(nodes.Get(3),nodes.Get(5));InternetStackHelper internet;internet.Install(nodes);PointToPointHelper p2p;p2p.SetDeviceAttribute("DataRate",StringValue("100Mbps"));p2p.SetChannelAttribute("Delay",StringValue("2ms"));NetDeviceContainer nets;NetDeviceContainer d0d1 =p2p.Install(n0n1);NetDeviceContainer d1d2 =p2p.Install(n1n2);NetDeviceContainer d1d3 =p2p.Install(n1n3);NetDeviceContainer d3d4 =p2p.Install(n3n4);NetDeviceContainer d3d5 =p2p.Install(n3n5);Ipv4AddressHelper ipv4;ipv4.SetBase("10.1.1.0","255.255.255.0");Ipv4InterfaceContainer i0i1 = ipv4.Assign(d0d1);ipv4.SetBase("10.1.2.0","255.255.255.0");ipv4.Assign(d1d2);ipv4.SetBase("10.1.3.0","255.255.255.0");ipv4.Assign(d1d3);ipv4.SetBase("10.1.4.0","255.255.255.0");ipv4.Assign(d3d4);ipv4.SetBase("10.1.5.0","255.255.255.0");ipv4.Assign(d3d5);Ipv4InterfaceContainer i3i5 = ipv4.Assign(d3d5);uint16_t port = 50000;ApplicationContainer sinkApp;Address sinkLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port));PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory", sinkLocalAddress);sinkApp.Add(sinkHelper.Install(nodes.Get(0)));sinkApp.Start (Seconds (0.0));sinkApp.Stop (Seconds (10.0));OnOffHelper clientHelper ("ns3::TcpSocketFactory", Address ());clientHelper.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));clientHelper.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));ApplicationContainer clientApps;AddressValue remoteAddress(InetSocketAddress (i0i1.GetAddress (0), port));clientHelper.SetAttribute("Remote",remoteAddress);clientApps.Add(clientHelper.Install(nodes.Get(5)));clientApps.Start(Seconds(1.0));clientApps.Stop (Seconds (10.0));Ipv4GlobalRoutingHelper::PopulateRoutingTables ();//嗅探,记录所有节点相关的数据包 Simulator::Run ();Simulator::Destroy ();return 0; }
1.首先针对拓扑的构造,对于这个拓扑构造个人觉得还是相对比较容易,通过对网上一些例子的理解,以及对上次myfirst.cc的理解
可参考 简单ns-3点对点网络的构造
NodeContainer nodes;nodes.Create (6);NodeContainer n0n1 = NodeContainer(nodes.Get(0),nodes.Get(1));NodeContainer n1n2 = NodeContainer(nodes.Get(1),nodes.Get(2));NodeContainer n1n3 = NodeContainer(nodes.Get(1),nodes.Get(3));NodeContainer n3n4 = NodeContainer(nodes.Get(3),nodes.Get(4));NodeContainer n3n5 = NodeContainer(nodes.Get(3),nodes.Get(5));InternetStackHelper internet;internet.Install(nodes);PointToPointHelper p2p;p2p.SetDeviceAttribute("DataRate",StringValue("100Mbps"));p2p.SetChannelAttribute("Delay",StringValue("2ms"));NetDeviceContainer nets;NetDeviceContainer d0d1 =p2p.Install(n0n1);NetDeviceContainer d1d2 =p2p.Install(n1n2);NetDeviceContainer d1d3 =p2p.Install(n1n3);NetDeviceContainer d3d4 =p2p.Install(n3n4);NetDeviceContainer d3d5 =p2p.Install(n3n5);Ipv4AddressHelper ipv4;ipv4.SetBase("10.1.1.0","255.255.255.0");Ipv4InterfaceContainer i0i1 = ipv4.Assign(d0d1);ipv4.SetBase("10.1.2.0","255.255.255.0");ipv4.Assign(d1d2);ipv4.SetBase("10.1.3.0","255.255.255.0");ipv4.Assign(d1d3);ipv4.SetBase("10.1.4.0","255.255.255.0");ipv4.Assign(d3d4);ipv4.SetBase("10.1.5.0","255.255.255.0");ipv4.Assign(d3d5);Ipv4InterfaceContainer i3i5 = ipv4.Assign(d3d5);
我的拓扑构建如上面所示,每两个点之间建立点对点链路,数据率100Mbps,信道传输延迟为2ms,然后对每一个网卡(设备),分配IP地址。
这个时候就有一个疑惑,网卡能分配两个以上的IP地址吗,就如上面的节点d1他被分配了10.1.1.2,又被分配了10.1.2.1的IP地址,这时候就想一个网卡能被分配两个以上的IP地址吗,(网络没学好。。) 答案是可以的。
然后再通过Ipv4InterfaceContainer获得等下我们所需的0号节点和5号节点的IP地址,进行TCP连接。
2.接下来是为0号节点装入TCP的sever,为5号节点安装tcp的client的application
uint16_t port = 50000;ApplicationContainer sinkApp;Address sinkLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port)); //获得节点1的IP的地址以及端口号PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory", sinkLocalAddress); //设置为TCP连接sinkApp.Add(sinkHelper.Install(nodes.Get(0))); //把应用程序装入节点0sinkApp.Start (Seconds (0.0));sinkApp.Stop (Seconds (10.0));OnOffHelper clientHelper ("ns3::TcpSocketFactory", Address ());clientHelper.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));clientHelper.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));ApplicationContainer clientApps;AddressValue remoteAddress(InetSocketAddress (i0i1.GetAddress (0), port)); //设置远端IP以及端口,即服务器应用的IP和端口clientHelper.SetAttribute("Remote",remoteAddress);clientApps.Add(clientHelper.Install(nodes.Get(5))); //把应用程序装入节点5clientApps.Start(Seconds(1.0));clientApps.Stop (Seconds (10.0));
这是输出结果:
对于输出结果我存在很大的疑惑,为什么有时候传的是512字节,有时候是536字节,又或是112字节,当然绝大部分以512字节为主。
对于这个问题主要还是自己对TCP连接的原因理解的不够透彻,以及对一些模拟可视化的界面,还没办法弄出来加强理解。
在阅读相关文档后,还是安装TCP应用的地方存在疑惑。 接下来应该学习一些如何操作输出结果,看到可视化的一些东西,以加强对各种数据传输的理解。
转载于:https://www.cnblogs.com/wpqwpq/p/5676284.html
Ns3 构建哑铃型拓扑,并实现两个点的TCP连接(详细请戳全文)相关推荐
- 《CCNP ROUTE 300-101学习指南》——2.2节构建EIGRP拓扑表
本节书摘来自异步社区<CCNP ROUTE 300-101学习指南>一书中的第2章,第2.2节构建EIGRP拓扑表,作者 [美]戴安娜 蒂尔(Diane Teare) , 鲍勃 瓦尚(Bo ...
- 利用NS3部署不同拓扑无线网络
利用NS3部署不同拓扑无线网络 实验题目 利用NS2/NS3部署一个星型无线网络(一个AP,不少于5个接入点).一个多跳无线网络(不少于6个网络节点).并测量两种网络拓扑下的网络链路吞吐量,用图表表示 ...
- 4.19构建一个类book,含有两个私有成员qu和price
构建一个类book,含有两个私有成员qu和price,建立一个有5个元素的suzuki对象,将qu初始化为1~5,将price初始化为qu的10倍.显示每个对象的qu*price. 4.19 #inc ...
- 两个字符串之间的连接函数,不使用strcat()函数
#include <stdio.h>// 获得字符串的长度 int getLength(char* src) {int len;for(len = 0; src[len] != '\0'; ...
- 不要在同一客户端同时使用超过两个的 HTTP 长连接
们使用 IE 下载文件时会有这样的体验,从同一个 Web 服务器下载文件,最多只能有两个文件同时被下载.第三个文件的下载会被阻塞,直到前面下载的文件下载完毕.这是因为 HTTP 1.1 规范中规定,客 ...
- mac插网线不能上网_实现两个无线路由器之间的连接,最稳定的方式是使用网线连接...
实现两个无线路由器之间的连接,最稳定的方式是使用网线连接:在满足条件的情况下,可以考虑电力猫方式:如果使用无线中继方式,可以考虑使用mesh路由器组网,稳定性有很大程度的提高. 两个无线路由器之间的连 ...
- 主机甲和主机乙之间已建立一个TCP连接,TCP最大段长为1000B。若主机甲的当前拥塞窗口为4000B,在主机甲向主机乙连续发送两个最大段后,成功收到主机乙发送的第一个段的确认段,确认段中通告的接收窗
主机甲和主机乙之间已建立一个TCP连接,TCP最大段长为1000B.若主机甲的当前拥塞窗口为4000B,在主机甲向主机乙连续发送两个最大段后,成功收到主机乙发送的第一个段的确认段,确认段中通告的接收窗 ...
- sql INNER JOIN 取得两个表中存在连接匹配关系的记录(mysql)
首先:JOIN 通常与 ON 关键字搭配使用 其次我们来看我们的两个表格: table1: table2: 在这里,INNER JOIN(内连接,或等值连接):取得两个表中存在连接匹配关系的记录. 例 ...
- 传输层两大协议:TCP与UDP详解(两者的联系与区别)
一.TCP协议 1.TCP协议报文格式 TCP协议报文格式详解 2.TCP"三次握手"建立连接 位码即tcp标志位,有6种标示: SYN(synchronous建立联机) ACK( ...
- Java 网络编程(二) 两类传输协议:TCP UDP
两类传输协议:TCP,UDP TCP TCP是Transfer Control Protocol(传输控制协议)的简称,是一种面向连接的保证可靠传输的协议. 在TCP/IP协议中, IP层主要负责网络 ...
最新文章
- vs2019装了WDK后,编译其他vc工程,提示无法打开文件msvcprtd.lib
- Lua table笔记
- 电信业务分类目录2019_2019年1月国内增值电信业务许可情况分析报告,市场区域发展不均衡...
- 给缺少Python项目实战经验的人
- 技术分享|前端性能 关键性能指标以及测量工具介绍
- 轻量级 HTTP(s) 代理 TinyProxy
- php 返回script,从PHP脚本返回JSON
- 用“混序”替代鲍尔默
- 编写代码注释的最佳实践
- 42. 确保lessT与operator小于具有相同的语义
- Java面试八股文(素材来自网络)
- 通过python获取浏览器cookie
- setBackground()和setImageBitmap()看完就哦了
- 2021考研——浙江大学控制科学与工程专业考研经验贴(845自动控制原理)
- java中小数后加f_在 Java 中,小数默认为 ,如果要指定 类型请在小数后加 F/f 。_学小易找答案...
- 计算机颜色偏蓝,电脑整个屏幕颜色不正常偏蓝怎么调回正常颜色?
- 二级联动 三级联动 多级联动 无限级联动下拉列表或菜单专题
- python多线程破解压缩包_我用 Python 破解了同事的加密压缩包!
- 数据的正态分布验证和方差齐性检验
- 2022-2028全球与中国颈带式耳机市场现状及未来发展趋势