日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

7、ns-3建立拓扑

發布時間:2025/7/14 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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建立拓扑的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 欧美日韩在线综合 | 超碰在线成人 | 日本精品视频 | 欧美色精品在线 | 久久久精品中文字幕 | 欧美日韩在线影院 | 手机在线一区二区三区 | 日韩久久一区二区三区 | 在线播放国产视频 | 欧美日韩一级二级三级 | 国产亚洲一区二区三区四区 | 亚洲av第一成肉网 | 国产精品99精品无码视亚 | 精品国产av无码一区二区三区 | 完美搭档在线观看 | 亚洲一区二区观看 | 日本久久免费 | 午夜老湿机 | 午夜影院h| 久久女同互慰一区二区三区 | 潘金莲性xxxxhd| 男女啪啪在线观看 | 一级片aaa| 在线观看成人一区 | 亚洲一区二区三区黄色 | 成年精品| 一级做a免费视频 | 不卡av一区 | www.久色| 久久久久久久国产精品毛片 | 在线国产三级 | 天堂一区二区三区四区 | 懂色av,蜜臀av粉嫩av | 中文字幕在线看片 | 亚洲精品乱码久久久久久麻豆不卡 | 亚洲青涩网| 免费观看污网站 | 成人网在线看 | 亚洲精品69 | 美女脱衣服一干二净 | 办公室荡乳欲伦交换bd电影 | 精品人妻大屁股白浆无码 | 精品96久久久久久中文字幕无 | 精品人妻一区二区三区三区四区 | av无码久久久久久不卡网站 | 欧美a v在线| 国产丝袜高跟 | 欧美性猛交xxxx免费看久久久 | www.激情.com| 吃瓜网今日吃瓜 热门大瓜 色婷在线 | 本道久久| 综合另类 | 久久伊人影视 | 中国黄色一级大片 | 8x8x国产精品一区二区 | 69精品久久久 | 成人羞羞国产免费游戏 | 日韩在线精品视频 | 97人人干| 亚洲欧美日韩综合一区二区 | 免费萌白酱国产一区二区三区 | 欧美在线视频网站 | 喷水了…太爽了高h | 婷婷资源网 | 久草观看视频 | 激情av网站 | 天天干天天玩 | 人人妻人人澡人人爽 | 国产精品黑人一区二区三区 | 日本成人性爱 | 成人av网址在线观看 | 国产黄a三级 | 91视频综合网 | 国产自偷自拍 | 青青草原av | 在线观看的av网址 | 综合网av| 风流少妇按摩来高潮 | 日韩高清免费av | 国产男男gay体育生网站 | 成年视频在线观看 | 深夜福利在线免费观看 | 亚洲第一av网 | 狠狠操导航 | 日本黄色视 | 国产精品无码免费在线观看 | 人妻av一区二区 | 国产精品影音先锋 | 久久无码性爱视频 | 三级男人添奶爽爽爽视频 | 波多野结衣中文字幕在线 | 乱子伦视频在线看 | 樱花电影最新免费观看国语版 | av在线网页 | 香蕉在线影院 | 神马伦理影视 | 日日爽视频 | 丝袜国产一区 | 国产高清一区在线观看 |