1、高级计算机网络实验报告 ns3模拟数据中心要点Project1-ns3模拟数据中心实验要求根据上面的数据中心拓扑图,完成以下要求:1.根据给定的数据中心的拓扑结构,利用ns3进行仿真2.模拟两种通信模式(traffic pattern)oall-to-all:每个服务器都发送消息给其他服务器消息,由拓扑结构可知,超过50%的消息传送将跨越两个簇(cluster)omany-to-one:每个服务器都发送消息给其中一个服务器3.测量两种模式下网络的仿真可以达到的吞吐量,找出网络瓶颈,并且说明如何改进注:拓扑中的网络都是Ethernet网实验内容数据中心模拟实现及主要代码解释a. 设置自定义的at
2、tribute为了做实验方便,设置如下自定义attribute:pattern:通信模式,all-to-all或many-to-one,默认为1defaultDst:多对一模式下,接收消息的默认服务器序号,默认为0verbose:enable或者disable PacketSink和OnOffApplication的日志,默认为falseDataRate1:定义数据中心拓扑第一层的数据传输速率(Mbps),默认为1.0DataRate2:定义数据中心拓扑第二层的数据传输速率(Mbps),默认为1.0DataRate3:定义数据中心拓扑第三层的数据传输速率(Mbps),默认为1.5实现代码如下:
3、 uint16_t pattern = 1; uint16_t nodesNum = 8; uint16_t defaultDst = 0; float DataRate1 = 1.0; float DataRate2 = 1.0; float DataRate3 = 1.5; uint16_t port = 50000; bool verbose = false; CommandLine cmd; cmd.AddValue(pattern, number of traffic pattern, pattern);/pattern1:all-to-all pattern2:many-to-on
4、e cmd.AddValue(defaultDst, default destination server node in pattern 2, defaultDst); cmd.AddValue(DataRate1, data rate of csma network at level 1, DataRate1); cmd.AddValue(DataRate2, data rate of csma network at level 2, DataRate2); cmd.AddValue(DataRate3, data rate of csma network at level 3, Data
5、Rate3); cmd.AddValue (verbose, Tell sink and onoff applications to log if true, verbose); cmd.Parse(argc, argv); LogComponentEnable (DataCenterSimulation, LOG_LEVEL_INFO); if (verbose) LogComponentEnable (PacketSink, LOG_LEVEL_INFO); LogComponentEnable (OnOffApplication, LOG_LEVEL_INFO); b. 创建结点根据实验
6、要求,总共需要创建15个结点,包括:8 servers4 ToR switches2 Aggregation switches1 Core switch实现代码如下: /create nodes NodeContainer n1_8; n1_8.Create(8); NodeContainer t1_4; t1_4.Create(4); NodeContainer a12; a12.Create(2); NodeContainer c1; c1.Create(1);c. 创建CSMA网络节点整个数据中心网络拓扑从下往上可以分为三层,即第一层:由服务器与ToR组成的ethernet网络,共有4个
7、,编号为CSMA11,CSMA12,CSMA13,CSMA14第二层:由ToR与Aggregation组成的ethernet网络,共有2个,编号为CSMA21,CSMA22第三层:由Aggregation与Core组成的ethernet网络,共有1个,编号为CSMA3将创建好的15个网络结点分配到这7个CSMA网络中,实现代码如下: /create csma nodes NodeContainer csmaNodes11 = NodeContainer(n1_8.Get(0),n1_8.Get(1),t1_4.Get(0); NodeContainer csmaNodes12 = NodeCo
8、ntainer(n1_8.Get(2),n1_8.Get(3),t1_4.Get(1); NodeContainer csmaNodes13 = NodeContainer(n1_8.Get(4),n1_8.Get(5),t1_4.Get(2); NodeContainer csmaNodes14 = NodeContainer(n1_8.Get(6),n1_8.Get(7),t1_4.Get(3); NodeContainer csmaNodes21 = NodeContainer(t1_4.Get(0),t1_4.Get(1),a12.Get(0); NodeContainer csmaN
9、odes22 = NodeContainer(t1_4.Get(2),t1_4.Get(3),a12.Get(1); NodeContainer csmaNodes3 = NodeContainer(a12.Get(0),a12.Get(1),c1.Get(0);d. 设置CSMA网络attribute,并将其安装到相应结点上根据实验要求中的网络拓扑,设置相应网络的属性所有直接相连的两个结点之间的延迟都为500ns第一层和第二层CSMA网络的数据传输速率都为1.0Mbps,第三层为1.5Mbps然后安装到相应的网络结点上,实现代码如下(DataRate可以通过命令行参数设置,默认值即为原实验要
10、求): /create the channels first without any IP addressing information CsmaHelper csma1; sprintf(buf,%1.1fMbps,DataRate1); csma1.SetChannelAttribute (DataRate, StringValue (buf); csma1.SetChannelAttribute (Delay, StringValue (500ns); NetDeviceContainer csmaDevices11 = csma1.Install (csmaNodes11); NetD
11、eviceContainer csmaDevices12 = csma1.Install (csmaNodes12); NetDeviceContainer csmaDevices13 = csma1.Install (csmaNodes13); NetDeviceContainer csmaDevices14 = csma1.Install (csmaNodes14); CsmaHelper csma2; sprintf(buf,%1.1fMbps,DataRate2); csma2.SetChannelAttribute (DataRate, StringValue (buf); csma
12、2.SetChannelAttribute (Delay, StringValue (500ns); NetDeviceContainer csmaDevices21 = csma2.Install (csmaNodes21); NetDeviceContainer csmaDevices22 = csma2.Install (csmaNodes22); CsmaHelper csma3; sprintf(buf,%1.1fMbps,DataRate3); csma3.SetChannelAttribute (DataRate, StringValue (buf); csma3.SetChan
13、nelAttribute (Delay, StringValue (500ns); NetDeviceContainer csmaDevices3 = csma3.Install (csmaNodes3);e. 分配网络IP根据实验要求,为每个结点安装协议栈,并为7个CSMA网络分配IP,实现代码如下 /assign IP address NS_LOG_INFO (Assign IP address.); InternetStackHelper stack; stack.Install (n1_8); stack.Install (t1_4); stack.Install (a12); sta
14、ck.Install (c1); Ipv4AddressHelper address; address.SetBase (10.0.1.0, 255.255.255.0); Ipv4InterfaceContainer csmaInterfaces11 = address.Assign (csmaDevices11); address.SetBase (10.0.2.0, 255.255.255.0); Ipv4InterfaceContainer csmaInterfaces12 = address.Assign (csmaDevices12); address.SetBase (10.0.
15、3.0, 255.255.255.0); Ipv4InterfaceContainer csmaInterfaces13 = address.Assign (csmaDevices13); address.SetBase (10.0.4.0, 255.255.255.0); Ipv4InterfaceContainer csmaInterfaces14 = address.Assign (csmaDevices14); address.SetBase (10.1.1.0, 255.255.255.0); Ipv4InterfaceContainer csmaInterfaces21 = add
16、ress.Assign (csmaDevices21); address.SetBase (10.2.1.0, 255.255.255.0); Ipv4InterfaceContainer csmaInterfaces22 = address.Assign (csmaDevices22); address.SetBase (192.168.1.0, 255.255.255.0); Ipv4InterfaceContainer csmaInterfaces3 = address.Assign (csmaDevices3);f. 初始化路由表这里直接调用了ns3自带的路由实现,实现代码如下 / C
17、reate router nodes, initialize routing database and set up the routing / tables in the nodes. Ipv4GlobalRoutingHelper:PopulateRoutingTables ();g. 创建和分配PacketSink和OnOffClient首先,创建sink和OnOff,实现代码如下 /Create sinkApp and OnOffClient ApplicationContainer clientAppnodesNum4; ApplicationContainer sinkAppnod
18、esNum;然后,分配sink到所有的server结点上,实现代码如下(其中nodesNum表示server个数): for(unsigned int i = 0;i nodesNum; i+) PacketSinkHelper packetSinkHelper (ns3:TcpSocketFactory, getAddress(i,port,csmaInterfaces11,csmaInterfaces12,csmaInterfaces13,csmaInterfaces14); sinkAppi = packetSinkHelper.Install (n1_8.Get (i); sinkAp
19、pi.Start(Seconds (1.0); sinkAppi.Stop(Seconds (60.0); 再然后,分配OnOffClient到server结点上,并且根据pattern不同,进行不同的配置pattern 1:每个服务器都发送消息给其他服务器消息,即发送消息给在另一个簇上面的4个服务器(每个服务器上建立4个OnOffClient)pattern 2:每个服务器都发送消息给同一个服务器,可以默认为n1(每个服务器(n1除外)上建立1个OnOffClient)实现代码如下 for(int i = 0; i nodesNum; i+) uint16_t dst = 0; if(pat
20、tern=1)/all-to-all pattern for(int j = 0 ;j 4; j+) if(iTCP Stream Graph-Throughput Graph来查看整个过程中该结点上的吞吐量变化情况使用statistics-Summary来查看当前结点上网络平均吞吐量,以此估计相应CSMA网络的吞吐量server n1上的测量结果如下Throughput GraphSummaryToR t1上的测量结果如下Throughput GraphSummaryAggregation a1上的测量结果如下Throughput GraphSummaryb. pattern 1 实验结果分
21、析首先对实验结果进行简单汇总网络结点带宽(Mbps)网络平均吞吐量(Mbps)CSMA11server n11.00.255CSMA21ToR t11.00.541CSMA3Aggregation a11.50.993从上面的结果可以看出第1层CSMA网络平均吞吐量是0.255Mbps,带宽利用率为25.5%;第2层CSMA网络平均吞吐量是0.541Mbps,带宽利用率为54.1%;第3层CSMA网络平均吞吐量是0.993Mbps,带宽利用率为66.2%。c. pattern 1 瓶颈及改进瓶颈根据以上的实验结果可以看出来,从网络的平均吞吐量来看:第3层CSMA第2层CSMA第1层CSMA2,从带宽利用率上看也是这样,所以作为core switch连接两个子网络但带宽过小的第三层网络成了整个网络的瓶颈。改进可以加大第3层网络的带宽,防止数据流量过大出现拥塞的情况发生。因此最后确定的网络带宽如下所示:oCSMA11-14:1.0MbpsoCSMA21-22:1.0MbpsoCSMA3 :2.0Mbps改进结果执行命令行./waf -run scratch/DC -DataRate1=1.0 -DataRate2=1.0 -DataRate3=2.0,以相同方式测量
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1