7、ns-3建立拓扑
建立总线型拓扑。
/* -*- 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/csma-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/ipv4-global-routing-helper.h"
// Default Network Topology
//
// 10.1.1.0
// n0 -------------- n1 n2 n3 n4
// point-to-point | | | |
// ================
// LAN 10.1.2.0
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("SecondScriptExample");
int
main (int argc, char *argv[])
{
//定义变量,用于决定是否开启2个UdpApplication的Logging组件;默认true开启。
bool verbose = true;
uint32_t nCsma = 3;//LAN有3个node。
CommandLine cmd;
cmd.AddValue ("nCsma", "Number of \"extra\" CSMA nodes/devices", nCsma);
cmd.AddValue ("verbose", "Tell echo applications to log if true", verbose);
cmd.Parse (argc,argv);
if (verbose)
{
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
}
nCsma = nCsma == 0 ? 1 : nCsma;
/**************************网络拓扑部分****************************/
//创建使用P2P链路的2个node
NodeContainer p2pNodes;
p2pNodes.Create (2);
//创建另一个NodeContainer类对象,用于总线(CSMA)网络
NodeContainer csmaNodes;
csmaNodes.Add (p2pNodes.Get (1));
csmaNodes.Create (nCsma);//將之前P2P的NodeContainer的第二个节点(索引1)添加到CSMA的Nodeontainer,获得CSMA device;这个node将会有2个device
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
//安装P2P网卡设备到P2P网络节点,同first.cc
NetDeviceContainer p2pDevices;
p2pDevices = pointToPoint.Install (p2pNodes);
//类似于P2PHelper,CsmaHelper帮助创建和连接CSMA设备及信道
CsmaHelper csma;
csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps"));
//数据率由channel属性指定,而非Device属性,因为CSMA不允许同一信道有多个不同数据率的设备。
csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (6560)));
NetDeviceContainer csmaDevices;
csmaDevices = csma.Install (csmaNodes);
//安装网络协议
InternetStackHelper stack;
stack.Install (p2pNodes.Get (0));//P2P链路中的第一节点
stack.Install (csmaNodes);
//P2P链路中的第二节点包含在csmaNodes中。
Ipv4AddressHelper address;//2个网段的IP地址类对象
address.SetBase ("10.1.1.0", "255.255.255.0");//安排P2P网段的地址
Ipv4InterfaceContainer p2pInterfaces;
p2pInterfaces = address.Assign (p2pDevices);
address.SetBase ("10.1.2.0", "255.255.255.0");
Ipv4InterfaceContainer csmaInterfaces;
csmaInterfaces = address.Assign (csmaDevices);
/**************************网络拓扑部分结束****************************/
/**************************应用程序部分****************************/
UdpEchoServerHelper echoServer (9);
//將Server服务安装在CSMA网段的最后一个节点上,nCsma是可变的,所以不能用3.
ApplicationContainer serverApps = echoServer.Install (csmaNodes.Get (nCsma));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
UdpEchoClientHelper echoClient (csmaInterfaces.GetAddress (nCsma), 9);
echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
ApplicationContainer clientApps = echoClient.Install (p2pNodes.Get (0));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
/**************************应用程序部分结束****************************/
/********************调用全局路由Helper帮助建立网络路由*********************/
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
//全局路由管理器根据节点产生的链路通告为每个节点建立路由表
pointToPoint.EnablePcapAll ("second");//second是前缀名,不用担心命名问题
csma.EnablePcap ("second", csmaDevices.Get (1), true);//开启csmahelper类对象的pcap
//Netevice不用取得ID,可以直接使用,但是Node需要进一步查找ID
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
运行结果:
前面两个都是
后面一个是
由于要查找谁有该ip所以发送arp消息。
使用可视化:./waf --run second --vis
转载于:https://www.cnblogs.com/tempal/p/3798938.html
7、ns-3建立拓扑相关推荐
- arcgis伪节点检查_arcgis建立拓扑分析(检验矢量图)
目的:矢量图画好后,检查是否有伪节点,悬挂节点等,线要素和面要素都可以检查.伪节点,两条线应该相交但是画的没相交:悬挂节点,两条线看似相交了但是没有节点,因此路径不同(类似于高架桥和交叉口,悬挂节点就 ...
- arcgis建立拓扑分析(检验矢量图)
目的:矢量图画好后,检查是否有伪节点,悬挂节点等,线要素和面要素都可以检查.伪节点,两条线应该相交但是画的没相交:悬挂节点,两条线看似相交了但是没有节点,因此路径不同(类似于高架桥和交叉口,悬挂节点就 ...
- arcgis建立拓扑验证拓扑
建立拓扑和验证 1 ArcCatalog新建数据库 在ArcCatalog中,连接到文件夹后,右键→New→File Geodatabase,命名为test.gdb(后缀为mdb为个人数据库): 2 ...
- mininet下建立拓扑时关于远程控制器的一个小问题
我习惯在双系统下的ubuntu环境中,直接使用mininet,而不是在虚拟机中作仿真:最近重装了系统和mininet后,使用mininet时遇到了一点小问题,一开始忽视了细节,使得自己被这个问题困扰了 ...
- 视觉导航的神经拓扑SLAM
视觉导航的神经拓扑SLAM Neural Topological SLAM for Visual Navigation 论文地址: http://openaccess.thecvf.com/conte ...
- arcgis悬挂点修改_ArcGis拓扑的那些事儿(拓扑应用过程三)
(,,・∀・)ノ゛hello,小编又来啦(一不小心又拖更这么长时间),感觉大家都是催更小能手,天天定时定点的发消息催更,(其实很感谢大家的关注与催更,说明我写的这些对大家都有很大的用处!让我感到挺高兴 ...
- 【源码分析】storm拓扑运行全流程源码分析
[源码分析]storm拓扑运行全流程源码分析 @(STORM)[storm] 源码分析storm拓扑运行全流程源码分析 一拓扑提交流程 一stormpy 1storm jar 2def jar 3ex ...
- qgis折点打断_arcgis在折点处打断并建立网络分析(最短路径等问题)
目的:GIS网络分析用于对段路径等问题.这里仅仅讲述如何建立网络分析. 网络建立前必须满足以下条件 1.要素文件在节点处打断(本文下面会叙述) 2.要素文件在地理数据库里的数据集里(一般是这样) 3. ...
- ARCGIS 拓扑规则阐述
ARCGIS 拓扑规则阐述 [第一部分] Arcgis中topolopy说明: 在arcgis中有关topolopy操作,,有两个地方,一个是在arccatalog中,一个是在arcmap中.通常我们 ...
最新文章
- php负载均衡原理_Java开发大型互联网架构深入负载均衡原理之方案分析
- beyond compare 4 的30天试用期已过-解决方法
- 经典排序算法之直接选择排序
- python使用open打开文件时显示文件不存在-Python打开文件open()的注意事项
- MyBatisPlus条件构造器Condition的用法
- 计算机检索的pdf格式,win10系统实现全文搜索pdf文件的解决办法
- 图解丨在嵌入式设备上实现HTTP服务器
- 5脚耳机插座原理图_手机原理图的解读
- ADO.NET数据访问方式:SqlDataReader
- MATLAB简介与矩阵定义
- 计算机导航窗格有两个c盘,电脑怎么格式化所有盘只留系统
- Java的笔记开源软件_jnote
- Linux进程的创建
- Sharding-JDBC 基础
- Android Studio_day02 实际应用登录界面
- html制作图像画廊,创建 Web 照片画廊 (Photoshop)
- PS唯美清新花朵调色
- 怀念那些年我们每天使用的经典DOS程序
- Linux之条件变量
- Qt 自定义日历控件