Project1-ns3模拟数据中心实验要求Datacenter network topology1根据上面的数据中心拓扑图,完成以下要求:1. 根据给定的数据中心的拓扑结构,利用ns3进行仿真2. 模拟两种通信模式(traffic pattern)o all-to-all :每个服务器都发送消息给其他服务器消息,由拓扑结构可知,超过50%的消息传送将跨越两个簇(cluster)o many-to-one :每个服务器都发送消息给其中一个服务器3. 测量两种模式下网络的仿真可以达到的吞吐量,找出网络瓶颈,并且说明如何改进注:拓扑中的网络都是Ethernet网实验内容数据中心模拟①实现及主要代码解释a.设置自定义的attribute为了做实验方便,设置如下自定义attribute :• pattern:通信模式,all-to-all 或 many-to-one,默认为 1• defaultDst:多对一模式下,接收消息的默认服务器序号,默认为0• verbose:enable 或者 disable PacketSink和 OnOffApplication 的日志,默认为 false• DataRatel:定义数据中心拓扑第一层的数据传输速率(Mbps),默认为1.0• DataRate2:定义数据中心拓扑第二层的数据传输速率(Mbps),默认为1.0• DataRate3:定义数据中心拓扑第三层的数据传输速率(Mbps),默认为1.5实现代码如下: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-onecmd.AddValue("defaultDst", "default destination server node in pattern 2", defaultDst);cmd.AddValue(〃DataRate1〃, "data rate of csma network at level 1", DataRatel);cmd.AddValue("DataRate2", "data rate of csma network at level 2", DataRate2);cmd.AddValue("DataRate3", "data rate of csma network at level 3", DataRate3);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.创建结点根据实验要求,总共需要创建15个结点,包括:• 8 servers• 4 ToR switches• 2 Aggregation switches• 1 Core switch实现代码如下://create nodesNodeContainer 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个,编号为CSMA11,CSMA12,CSMA13,CSMA14•第二层:由ToR与Aggregation组成的ethernet网络,共有2个,编号为CSMA21,CSMA22• 第三层:由Aggregation与Core组成的ethernet网络,共有1个,编号为CSMA3将创建好的15个网络结点分配到这7个CSMA网络中,实现代码如下://create csma nodesNodeContainer csmaNodes11 =NodeContainer(n1_8.Get(0),n1_8.Get(1),t1_4.Get(0));NodeContainer csmaNodes12 =NodeContainer(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 csmaNodes22 =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可以通过命令行参数设置,默 认值即为原实验要求)://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);NetDeviceContainer 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));csma2.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.SetChannelAttribute ("Delay", StringValue ("500ns"));NetDeviceContainer csmaDevices3 = csma3.Install (csmaNodes3);根据实验要求,为每个结点安装协议栈,并为7个CSMA网络分配IP,实现代码如下//assign IP addressNS_LOG_INFO ("Assign IP address.");InternetStackHelper stack;stack.Install (n1_8);stack.Install (t1_4);stack.Install (a12);stack.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.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 = address.Assign (csmaDevices21);address.SetBase ("10.2.1.0", "255.255.255.0");Ipv4InterfaceContainer csmaInterfaces22 = address.Assign (csmaDevices22);address.SetBase ("192.168.1.0", "255.2。