中科大高网实验报告
- 格式:doc
- 大小:3.32 MB
- 文档页数:17
运用ns-3模拟数据中心(datacenter)实验报告一.实验工具
Ubuntu、Vmware虚拟机、ns-3仿真器、Wireshark抓包工具
二.实验步骤
1.编写程序模拟网络拓扑及网络消息传输状态(多对一和多对多)
2.利用Wireshark抓包工具对输出的.pcap文件进行分析
3.实验总结
三.网络拓扑
图(1)
四.重要代码解释
//备注:以下是实现主机间多对一通信的代码,其中多指的为主机h2—h8,一为主机//h1.
//库函数调用
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/csma-module.h"
#include "ns3/internet-module.h"
#include "ns3/applications-module.h"
#include "ns3/ipv4-global-routing-helper.h"
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("SecondScriptExample");
int
main (int argc, char *argv[])
{
bool verbose = true;
uint32_t nCsma = 3;
uint32_t nFlows = 7;
uint16_t port = 5000;
//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)//为真
{////定义两个LOG模块,用于收到和发出数据包时输出LOG消息
LogComponentEnable ("PacketSink", LOG_LEVEL_INFO);
LogComponentEnable ("OnOffApplication", LOG_LEVEL_INFO);
}
nCsma = nCsma == 0 ? 1 : nCsma;
//创建底层的4个小csma网络
NodeContainer csmaNodes1;
csmaNodes1.Create (3);
NodeContainer csmaNodes2;
csmaNodes2.Create (3);
NodeContainer csmaNodes3;
csmaNodes3.Create (3);
NodeContainer csmaNodes4;
csmaNodes4.Create (3);
//创建中层的csma中左侧网络
NodeContainer csmaNodes5;
csmaNodes5.Create (1);
csmaNodes5.Add (csmaNodes1.Get (0));
csmaNodes5.Add (csmaNodes2.Get (0));
//创建中层的csma中右侧网络
NodeContainer csmaNodes6;
csmaNodes6.Create (1);
csmaNodes6.Add (csmaNodes3.Get (0));
csmaNodes6.Add (csmaNodes4.Get (0));
//创建总的csma大csma网络
NodeContainer csmaNodes7;
csmaNodes7.Create (1);
csmaNodes7.Add (csmaNodes5.Get (0));
csmaNodes7.Add (csmaNodes6.Get (0));
//CMSA1网络拓扑
CsmaHelper csma1;
csma1.SetChannelAttribute ("DataRate", StringValue ("1.0Mbps"));
csma1.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (500)));
NetDeviceContainer csmaDevices1;
csmaDevices1 = csma1.Install (csmaNodes1);
//CMSA2网络拓扑
csma2.SetChannelAttribute ("DataRate", StringValue ("1.0Mbps"));
csma2.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (500)));
NetDeviceContainer csmaDevices2;
csmaDevices2 = csma2.Install (csmaNodes2);
//CMSA3网络拓扑
CsmaHelper csma3;
csma3.SetChannelAttribute ("DataRate", StringValue ("1.0Mbps"));
csma3.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (500)));
NetDeviceContainer csmaDevices3;
csmaDevices3 = csma3.Install (csmaNodes3);
//CMSA4网络拓扑
CsmaHelper csma4;
csma4.SetChannelAttribute ("DataRate", StringValue ("1.0Mbps"));
csma4.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (500)));
NetDeviceContainer csmaDevices4;
csmaDevices4 = csma4.Install (csmaNodes4);
//CMSA5网络拓扑
CsmaHelper csma5;
csma5.SetChannelAttribute ("DataRate", StringValue ("1.0Mbps"));
csma5.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (500))); NetDeviceContainer csmaDevices5;
csmaDevices5 = csma5.Install (csmaNodes5);
//CMSA6网络拓扑
CsmaHelper csma6;
csma6.SetChannelAttribute ("DataRate", StringValue ("1.0Mbps"));
csma6.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (500))); NetDeviceContainer csmaDevices6;
csmaDevices6 = csma6.Install (csmaNodes6);
//CMSA7网络拓扑
CsmaHelper csma7;
csma7.SetChannelAttribute ("DataRate", StringValue ("1.5Mbps"));
csma7.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (500))); NetDeviceContainer csmaDevices7;
csmaDevices7 = csma7.Install (csmaNodes7);
//安装协议栈(每个node只有一个stack)
InternetStackHelper stack;
stack.Install (csmaNodes1);
stack.Install (csmaNodes2);
stack.Install (csmaNodes3);
stack.Install (csmaNodes4);