《计算机网络》课程报告

班级软件18-1学号181401013姓名张立辉

I课程报告基本要求

完成网络仿真环境的安装,并阐述安装过程中发生的问题与解决方案。使用NS2/NS3进行网络仿真,要求节点数量为自己序号后两位+5。对于所采用的协议进行代码级别的解析,阐述该层的工作原理。对于所解析的协议层,进行修改,给出仿真对比结果,并给出合理科学的结果分析。能对仿真全过程有自已的理解与认识,并总结全过程。

II报告内容

一、安装与仿真过程

成功安装NS2/NS3,并且修改脚本建立一个节点数量为自己序号后两位+5的仿真实验。其中节点间连接方式可以是有线也可以是无线。(40 分)
(1)有条理地阐述安装过程,并能清楚阐明安装过程中出现的问题以及其有效解决方案(500 字以上,电子,附有相关截屏图)。(10分)

安装过程:

出现问题:

VMware13.0安装后发现Ubuntu16.04,18.04,20.04安装时都出现黑屏现象

解决方案:

更换VMware15.0后问题解决。

出现问题:

VMware上的Ubuntu18.04安装后共享文件夹找不到。

解决方案:

安装tools插件。

出现问题:

虚拟机经常卡死,ns3安装时卡死,报错提示内存不足,提升虚拟机内存后问题仍无法解决,甚至会出现Windows跟着一起卡死的情况。(由于后期重做系统,虚拟机方面报错及解决方案都没有来得及截图)

解决方案:

安装双系统。
PS:双系统安装过程中坑巨多!!!
真有选这步的出现问题可以加联系方式私聊(同道中人啊)
用虚拟机的可以跳过双系统步骤,后续步骤相同

出现问题:

双系统Ubuntu安装后找不到启动项。

解决方案:

安装启动引导软件进行引导。

出现问题:

Ubuntu启动引导项无效,Windows启动引导项被删除

解决方案:

Ubuntu卸载,PE启动盘修复Windows启动项。

出现问题:

Windows启动项修复失败, BIOS里出现俩Windows安装磁盘标识。

解决方案:

office官网下载Windows安装iOS文件,UltraISO,exe制作Windows重装盘。

出现问题:

Windows无法正确引导Ubuntu启动项。

解决方案:

使用rufus-3.11p.exe制作Ubuntu启动盘,使用Ubuntu引导Windows启动项。

至此双系统安装完成,耗时一周。

出现问题:

ns3安装后编译不通过,出现报错。

解决方案:

安装ns3所需库

sudo apt-get install gcc g++ python python-dev  
sudo apt-get install mercurial  
sudo apt-get install bzr  
sudo apt-get install gdb valgrind  
sudo apt-get install flex bison libfl-dev 
sudo apt-get install tcpdump  
sudo apt-get install sqlite sqlite3 libsqlite3-dev  
sudo apt-get install libxml2 libxml2-dev  
sudo apt-get install libgtk2.0-0 libgtk2.0-dev  
sudo apt-get install vtun lxc  
sudo apt-get install uncrustify  
sudo apt-get install doxygen graphviz imagemagick  
sudo apt-get install python-sphinx dia      
sudo apt-get install python-pygraphviz python-kiwi python-pygoocanvas libgoocanvas-dev  
注意:
sudo apt-get install qt4-qmake   
sudo apt-get install qt4-dev-tools 
这里ns3最新版建议安装qt5
sudo apt-get install qt5*
sudo apt-get install libboost-signals-dev libboost-filesystem-dev
sudo apt-get install openmpi-bin openmpi-doc libopenmpi-dev

出现问题:

ns3可视化界面。

解决方案:

安装NetAnima:

hg clone  http://code.nsnam.org/jabraham3/netanim

(2)根据要求完成仿真实验,实现基本需求。能有条理的阐述实验全过程,重点突出。(1000字以上,电子,必须附有相关实验截图,该部分结尾附一张本人与仿真结果的清晰合影)。(30分)

实验过程:

首先安装Ubuntu18.04系统环境,之后在终端上安装ns3所需库

sudo apt-get install gcc g++ python python-dev  
sudo apt-get install mercurial  
sudo apt-get install bzr  
sudo apt-get install gdb valgrind  
sudo apt-get install flex bison libfl-dev 
sudo apt-get install tcpdump  
sudo apt-get install sqlite sqlite3 libsqlite3-dev  
sudo apt-get install libxml2 libxml2-dev  
sudo apt-get install libgtk2.0-0 libgtk2.0-dev  
sudo apt-get install vtun lxc  
sudo apt-get install uncrustify  
sudo apt-get install doxygen graphviz imagemagick  
sudo apt-get install python-sphinx dia      
sudo apt-get install python-pygraphviz python-kiwi python-pygoocanvas libgoocanvas-dev  
注意:
sudo apt-get install qt4-qmake   
sudo apt-get install qt4-dev-tools 
这里ns3最新版建议安装qt5
sudo apt-get install qt5*
sudo apt-get install libboost-signals-dev libboost-filesystem-devsudo apt-get install openmpi-bin openmpi-doc libopenmpi-dev

之后官网下载ns3.29的.bz2安装包,放到Ubuntu系统的软件文件夹(usr文件夹)里面,终端进入usr文件夹下

cd /usr

解压安装包

sudo tar -jxvf ns-allinone-3.29.tar.bz2

将解压后的安装包进行更名

sudo mv ns-allinone-3.29 ns3

进入ns3文件夹

cd ns3

使用build.py进行初次编译

sudo ./build.py --enable-examples --enable-tests
sudo ./build.py

进入新产生的ns-3.29文件夹下

cd ns-3.29

配置waf编译环境

sudo ./waf --build-profile=debug --enable-examples --enable-tests configure

使用waf进行编译

sudo ./waf

通过运行./test.py -c core脚本进行ns-3软件包的正确性测试

sudo ./test.py -c core

在屏幕显示hello查看ns3是否安装成功

sudo ./waf --run hello

安装成功后进行可视化界面的构建,安装NetAnim,
退回ns3文件夹下

cd ..

安装

sudo hg clone  http://code.nsnam.org/jabraham3/netanim

之前我20年安的时候是上面那个网址,但是21年安的时候不好使了
改为

sudo hg clone  http://code.nsnam.org/netanim

然后

cd netanim
sudo make clean
sudo qmake NetAnim.pro
sudo make

PS:这部我21年的时候报了特别多的错误,qmake生成的Makefile文件有bug
查看ns3自带的例子first.cc并对代码进行解析。

cd ns-3.29/scratch
sudo vi first.c

first.cc:

#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/netanim-module.h"
using namespace ns3;

NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");

int
main (int argc, char *argv[])
{
  CommandLine cmd;
  cmd.Parse (argc, argv);

  //确定时间精度
  Time::SetResolution (Time::NS);

  //打开日志功能
  LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
  LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
  /********************网络拓扑部分************************/
  //创建ns3节点对象,它们在仿真中代表计算机
  //先声明一个节点容器,然后创建两个节点。
  //这种节点是空节点,需要通过下面的配置加入网卡设备、协议栈等功能,实现数据传输。
  NodeContainer nodes;  //声明了一个名为”nodes”的NodeContainer
  nodes.Create (2); //调用了nodes对象的Create()方法创建了两个节点

  //创建一条点到点线路,PointToPointHelper类 可以很方便的配置链路属性
  PointToPointHelper pointToPoint;  //在栈中初始化了一个PointToPointHelper的对象
  //创建一个PointToPointNetDevice对象时使用“5Mbps"来作为数据速率
  pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
  //使用"2ms"(2毫秒)作为每一个被创建的点到点信道传输延时值
  pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));

  //完成设备和信道的配置(给节点加载网卡设备并接入网络)
  NetDeviceContainer devices;
  devices = pointToPoint.Install (nodes); 

  //安装协议栈(安装PointToPointHelper 对象和点到点网络设备的网络协议栈)
  InternetStackHelper stack;
  stack.Install (nodes);
  //配置ipv4地址域
  Ipv4AddressHelper address;  //声明了一个地址生成器对象
  address.SetBase ("10.1.1.0", "255.255.255.0");
  //将ipv4接口加载到网卡上
  Ipv4InterfaceContainer interfaces = address.Assign (devices);
  //给节点加载应用程序
  /********************网络拓扑部分结束*********************/

  /**********************应用程序部分*********************/
  //配置应用程序服务器端,并配置端口号9
  UdpEchoServerHelper echoServer (9); //服务器端口号
  //将该服务器功能加载到指定节点,并配置服务器开始和结束时间
  ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
  serverApps.Start (Seconds (1.0));
  serverApps.Stop (Seconds (10.0));

  //配置应用程序客户端,interfaces.GetAddress(1)获取服务器节点的ip地址,以及服务器端口号9
  UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);  //设定远程服务器的IP地址和端口号(创建了一个生成器并告诉它设置客户端的远端地址为服务器节点的IP地址。)
  //此外还需配置客户端属性,例如包的大小和长度以及发包间隔
  echoClient.SetAttribute ("MaxPackets", UintegerValue (1));    //告诉客户端我们所允许它在模拟期间所能发送的最大数据包个数
  echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));    //告诉客户端我们所允许它在模拟期间所能发送的最大数据包个数
  echoClient.SetAttribute ("PacketSize", UintegerValue (1024)); //告诉客户端它的数据包应该承载多少数据
  //将客户端功能加载到另一个节点上,同样需要配置客户端开始和结束时间
  ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
  clientApps.Start (Seconds (2.0));
  clientApps.Stop (Seconds (10.0));
  /**********************应用程序部分结束*********************/
  AnimationInterface anim("myfirst.xml");
  anim.SetConstantPosition(nodes.Get(0), 1.0, 2.0);
  anim.SetConstantPosition(nodes.Get(1), 2.0, 3.0);
  //开启仿真器运行
  Simulator::Run ();
  Simulator::Destroy ();
  return 0;
}

退回ns-3.29文件夹下

cd ..

使用waf进行编译

sudo ./waf

编译first.cc

sudo ./waf –run scratch/first

编译成功后退回ns3文件夹

cd ..

进入netanim-3.108文件夹

cd netanim-3.108

打开NEtAnim

sudo ./NetAnim

打开刚刚生成的myfirst.xml文件

可以看见节点连接结果:

之后自己新建一个first.cc文件,进行35个节点的代码书写,编译,调试,运行,步骤如first.cc所示(除了代码不一样其他大同小异)最后可以看见运行结果如下:
Waf编译:

test35.cc编译:

打开NetAnim:

打开(test.xml):

仿真结果:

二、协议解析与结果分析

对于所采用的协议进行代码级别的解析,说明该层的工作原理。对于所解析的协议层进行修改并进行仿真对比,给出合理科学的结果分析。(30分)
(1)对于所采用的协议如传输控制层,网络层,数据链路层进行代码级别的解析,说明该层的工作原理。(1000 字以上,附有相关截屏图)。(15分)

//test35.cc
 #include <iostream>
 #include <fstream>
 #include <string>
 #include <cassert>
 #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"
 #include "ns3/netanim-module.h"
 using namespace ns3;
 
 NS_LOG_COMPONENT_DEFINE ("DynamicGlobalRoutingExample");
 
 int 
 main (int argc, char *argv[])
 {
    //确定时间精度
    Time::SetResolution (Time::NS);
    // 配置全局路由算法的参数。The below value configures the default behavior of global routing.
    // 默认情况下是禁用的,相应借口事件时候,设为true
    Config::SetDefault ("ns3::Ipv4GlobalRouting::RespondToInterfaceEvents", BooleanValue (true));

    CommandLine cmd;
    cmd.Parse (argc, argv);
/********************网络拓扑部分************************/
//创建ns3节点对象,它们在仿真中代表计算机
    NS_LOG_INFO ("Create nodes.");
    NodeContainer c;//声明了一个名为”c”的NodeContainer
    c.Create (35);//调用了nodes对象的Create()方法创建了35个节点
    //位于ns3命名空间下。它提供了管理、创建、访问Node对象的方法。程序中涉及的Create()即为创建节点的方法。

    NodeContainer n0n1 = NodeContainer (c.Get (0), c.Get (1));
    NodeContainer n0n2 = NodeContainer (c.Get (0), c.Get (2));
    NodeContainer n0n3 = NodeContainer (c.Get (0), c.Get (3));
    NodeContainer n0n4 = NodeContainer (c.Get (0), c.Get (4));
    NodeContainer n0n5 = NodeContainer (c.Get (0), c.Get (5));
    NodeContainer n0n6 = NodeContainer (c.Get (0), c.Get (6));
    NodeContainer n0n7 = NodeContainer (c.Get (0), c.Get (7));
    NodeContainer n0n8 = NodeContainer (c.Get (0), c.Get (8));

    NodeContainer n1n10 = NodeContainer (c.Get (1), c.Get (10));

    NodeContainer n2n11 = NodeContainer (c.Get (2), c.Get (11));
    NodeContainer n2n12 = NodeContainer (c.Get (2), c.Get (12));
    NodeContainer n2n13 = NodeContainer (c.Get (2), c.Get (13));

    NodeContainer n3n14 = NodeContainer (c.Get (3), c.Get (14));

    NodeContainer n4n15 = NodeContainer (c.Get (4), c.Get (15));
    NodeContainer n4n16 = NodeContainer (c.Get (4), c.Get (16));
    NodeContainer n4n17 = NodeContainer (c.Get (4), c.Get (17));

    NodeContainer n5n18 = NodeContainer (c.Get (5), c.Get (18));

    NodeContainer n6n19 = NodeContainer (c.Get (6), c.Get (19));
    NodeContainer n6n20 = NodeContainer (c.Get (6), c.Get (20));
    NodeContainer n6n21 = NodeContainer (c.Get (6), c.Get (21));

    NodeContainer n7n22 = NodeContainer (c.Get (7), c.Get (22));

    NodeContainer n8n23 = NodeContainer (c.Get (8), c.Get (23));
    NodeContainer n8n24 = NodeContainer (c.Get (8), c.Get (24));
    NodeContainer n8n9 = NodeContainer (c.Get (8), c.Get (9));

    NodeContainer n2345 = NodeContainer (c.Get (2), c.Get (3), c.Get (4), c.Get (5));
    NodeContainer n6789 = NodeContainer (c.Get (6), c.Get (7), c.Get (8), c.Get (9));
    NodeContainer n10111213 = NodeContainer (c.Get (10), c.Get (11), c.Get (12), c.Get (13));
    NodeContainer n14151617 = NodeContainer (c.Get (14), c.Get (15), c.Get (16), c.Get (17));
    NodeContainer n18192021 = NodeContainer (c.Get (18), c.Get (19), c.Get (20), c.Get (21));
    NodeContainer n22232425 = NodeContainer (c.Get (22), c.Get (23), c.Get (24), c.Get (25));
    NodeContainer n26272829 = NodeContainer (c.Get (26), c.Get (27), c.Get (28), c.Get (29));
    NodeContainer n30313233 = NodeContainer (c.Get (30), c.Get (31), c.Get (32), c.Get (33));

    InternetStackHelper internet;
    //网络协议部署器,属于Topology Helper,在设置完整体拓扑结构之后,需要在节点中部署互联网协议(TCP、UDP、IP等)
    internet.Install (c);
 
    // 创建第一次没有任何ip寻址信息的信道
    NS_LOG_INFO ("Create channels.");
    //创建一条点到点线路,PointToPointHelper类 可以很方便的配置链路属性
    PointToPointHelper p2p;//在栈中初始化了一个PointToPointHelper的对象p2p
    //在该脚本中构造一个点对点的链路,连接PointToPointNetDevice和PointToPointChannel
    p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));//创建一个PointToPointNetDevice对象时使用“5Mbps"来作为数据速率
    p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));//使用"2ms"(2毫秒)作为每一个被创建的点到点信道传输延时值
    NetDeviceContainer d0d1 = p2p.Install (n0n1);//完成设备和信道的配置(给节点加载网卡设备并接入网络)
    NetDeviceContainer d0d2 = p2p.Install (n0n2);
    NetDeviceContainer d0d3 = p2p.Install (n0n3);
    NetDeviceContainer d0d4 = p2p.Install (n0n4);
    NetDeviceContainer d0d5 = p2p.Install (n0n5);
    NetDeviceContainer d0d6 = p2p.Install (n0n6);
    NetDeviceContainer d0d7 = p2p.Install (n0n7);
    NetDeviceContainer d0d8 = p2p.Install (n0n8);
    //网络设备容器,类似于NodeContainer,是网络设备的容器。
    //但是它并非像NetContainer那样创造对象。而是通过将Channel和Node连接起来这样的一个过程构造网络设备卡,并将其附在节点和信道之间
    p2p.SetDeviceAttribute ("DataRate", StringValue ("1500kbps"));
    p2p.SetChannelAttribute ("Delay", StringValue ("10ms"));
    NetDeviceContainer d1d10 = p2p.Install (n1n10);

    NetDeviceContainer d2d11 = p2p.Install (n2n11);
    NetDeviceContainer d2d12 = p2p.Install (n2n12);
    NetDeviceContainer d2d13 = p2p.Install (n2n13);

    NetDeviceContainer d3d14 = p2p.Install (n3n14);

    NetDeviceContainer d4d15 = p2p.Install (n4n15);
    NetDeviceContainer d4d16 = p2p.Install (n4n16);
    NetDeviceContainer d4d17 = p2p.Install (n4n17);

    NetDeviceContainer d5d18 = p2p.Install (n5n18);

    NetDeviceContainer d6d19 = p2p.Install (n6n19);
    NetDeviceContainer d6d20 = p2p.Install (n6n20);
    NetDeviceContainer d6d21 = p2p.Install (n6n21);

    NetDeviceContainer d7d22 = p2p.Install (n7n22);

    NetDeviceContainer d8d9 = p2p.Install (n8n9);
    NetDeviceContainer d8d23 = p2p.Install (n8n23);
    NetDeviceContainer d8d24 = p2p.Install (n8n24);
 
    // 创建第一次没有任何ip寻址信息的信道
    CsmaHelper csma;
    csma.SetChannelAttribute ("DataRate", StringValue ("5Mbps"));
    csma.SetChannelAttribute ("Delay", StringValue ("2ms"));
    NetDeviceContainer d2345 = csma.Install (n2345);
    NetDeviceContainer d6789 = csma.Install (n6789);
    NetDeviceContainer d10111213 = csma.Install (n10111213);
    NetDeviceContainer d14151617 = csma.Install (n14151617);
    NetDeviceContainer d18192021 = csma.Install (n18192021);
    NetDeviceContainer d22232425 = csma.Install (n22232425);
    NetDeviceContainer d26272829 = csma.Install (n26272829);
    NetDeviceContainer d30313233 = csma.Install (n30313233);
 
 
    // 添加ip地址
    NS_LOG_INFO ("Assign IP Addresses.");
    Ipv4AddressHelper ipv4;//声明了一个地址生成器对象
    //负责ip地址的分配,同样为了方便,可以直接以节点容器为对象进行地址分配。目前该类对外只提供基础IP地址和子网掩码的设置功能,函数为SetBase()。
    ipv4.SetBase ("10.1.1.0", "255.255.255.0");
    ipv4.Assign (d0d1);
    ipv4.SetBase ("10.1.2.0", "255.255.255.0");
    ipv4.Assign (d0d2);
    ipv4.SetBase ("10.1.3.0", "255.255.255.0");
    ipv4.Assign (d0d3);
    ipv4.SetBase ("10.1.4.0", "255.255.255.0");
    ipv4.Assign (d0d4);
    ipv4.SetBase ("10.1.5.0", "255.255.255.0");
    ipv4.Assign (d0d5);
    ipv4.SetBase ("10.1.6.0", "255.255.255.0");
    ipv4.Assign (d0d6);
    ipv4.SetBase ("10.1.7.0", "255.255.255.0");
    ipv4.Assign (d0d7);
    ipv4.SetBase ("10.1.8.0", "255.255.255.0");
    ipv4.Assign (d0d8);
    //具体分配是由Assign()方法完成的,以容器为对象,按顺序分配ip
    ipv4.SetBase ("10.1.10.0", "255.255.255.0");
    ipv4.Assign (d1d10);

    ipv4.SetBase ("10.1.11.0", "255.255.255.0");
    ipv4.Assign (d2d11);
    ipv4.SetBase ("10.1.12.0", "255.255.255.0");
    ipv4.Assign (d2d12);
    ipv4.SetBase ("10.1.13.0", "255.255.255.0");
    ipv4.Assign (d2d13);

    ipv4.SetBase ("10.1.14.0", "255.255.255.0");
    ipv4.Assign (d3d14);

    ipv4.SetBase ("10.1.15.0", "255.255.255.0");
    ipv4.Assign (d4d15);
    ipv4.SetBase ("10.1.16.0", "255.255.255.0");
    ipv4.Assign (d4d16);
    ipv4.SetBase ("10.1.17.0", "255.255.255.0");
    ipv4.Assign (d4d17);

    ipv4.SetBase ("10.1.18.0", "255.255.255.0");
    ipv4.Assign (d5d18);

    ipv4.SetBase ("10.1.19.0", "255.255.255.0");
    ipv4.Assign (d6d19);
    ipv4.SetBase ("10.1.20.0", "255.255.255.0");
    ipv4.Assign (d6d20);
    ipv4.SetBase ("10.1.21.0", "255.255.255.0");
    ipv4.Assign (d6d21);

    ipv4.SetBase ("10.1.22.0", "255.255.255.0");
    ipv4.Assign (d7d22);

    ipv4.SetBase ("10.1.29.0", "255.255.255.0");
    ipv4.Assign (d8d9);
    ipv4.SetBase ("10.1.23.0", "255.255.255.0");
    ipv4.Assign (d8d23);
    ipv4.SetBase ("10.1.24.0", "255.255.255.0");
    ipv4.Assign (d8d24);
 
    ipv4.SetBase ("10.1.30.0", "255.255.255.0");
    Ipv4InterfaceContainer i5i6 = ipv4.Assign (d5d18);
 
    ipv4.SetBase ("10.250.1.0", "255.255.255.0");
    ipv4.Assign (d2345);
    ipv4.SetBase ("10.250.2.0", "255.255.255.0");
    //ipv4.Assign (d6789);
    //ipv4.SetBase ("10.250.3.0", "255.255.255.0");
    //ipv4.Assign (d10111213);
    //ipv4.SetBase ("10.250.4.0", "255.255.255.0");
    //ipv4.Assign (d14151617);
    //ipv4.SetBase ("10.250.5.0", "255.255.255.0");
    //ipv4.Assign (d18192021);
    //ipv4.SetBase ("10.250.6.0", "255.255.255.0");
    //ipv4.Assign (d22232425);
    //ipv4.SetBase ("10.250.7.0", "255.255.255.0");
    //ipv4.Assign (d26272829);
    //ipv4.SetBase ("10.250.8.0", "255.255.255.0");
    //ipv4.Assign (d30313233);

    ipv4.SetBase ("172.16.1.0", "255.255.255.0");
    Ipv4InterfaceContainer i1i6 = ipv4.Assign (d1d10);

    // 创建路由器节点,初始化路由选择数据库,设置路由表节点。
    Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
    //给节点加载应用程序
    /********************网络拓扑部分结束*********************/
    // 创建时断时续的发送数据报应用。
    NS_LOG_INFO ("Create Applications.");
    uint16_t port = 9;    // Discard port (RFC 863)
    OnOffHelper onoff ("ns3::UdpSocketFactory",InetSocketAddress (i5i6.GetAddress (1), port));
    onoff.SetConstantRate (DataRate ("2kbps"));
    onoff.SetAttribute ("PacketSize", UintegerValue (50));
 
    ApplicationContainer apps = onoff.Install (c.Get (1));
    //应用程序-Application
    apps.Start (Seconds (1.0));
    apps.Stop (Seconds (10.0));
    //通过OnOffHelper来设置属性值
    OnOffHelper onoff2 ("ns3::UdpSocketFactory",InetSocketAddress (i1i6.GetAddress (1), port));
    onoff2.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
    onoff2.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
    onoff2.SetAttribute ("DataRate", StringValue ("2kbps"));
    onoff2.SetAttribute ("PacketSize", UintegerValue (50));
    //将该服务器功能加载到指定节点,并配置服务器开始和结束时间
    ApplicationContainer apps2 = onoff2.Install (c.Get (1));
    apps2.Start (Seconds (11.0));
    apps2.Stop (Seconds (16.0));
 
    // 接收数据包
    //创建PacketSinkHelper以使其更容易使用PacketSinkApplications。
    PacketSinkHelper sink ("ns3::UdpSocketFactory",Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
    apps = sink.Install (c.Get (6));
    apps.Start (Seconds (1.0));
    apps.Stop (Seconds (10.0));
 
    PacketSinkHelper sink2 ("ns3::UdpSocketFactory",Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
    apps2 = sink2.Install (c.Get (6));
    apps2.Start (Seconds (11.0));
    apps2.Stop (Seconds (16.0));
 
 
    AsciiTraceHelper ascii;
    Ptr<OutputStreamWrapper> stream = ascii.CreateFileStream ("dynamic-global-routing.tr");
    p2p.EnableAsciiAll (stream);
    csma.EnableAsciiAll (stream);
    internet.EnableAsciiIpv4All (stream);
 
    p2p.EnablePcapAll ("dynamic-global-routing");
    csma.EnablePcapAll ("dynamic-global-routing", false);
  
    Ptr<Node> n1 = c.Get (1);
    Ptr<Ipv4> ipv41 = n1->GetObject<Ipv4> ();

    uint32_t ipv4ifIndex1 = 2;
 
    Simulator::Schedule (Seconds (2),&Ipv4::SetDown,ipv41, ipv4ifIndex1);
    Simulator::Schedule (Seconds (4),&Ipv4::SetUp,ipv41, ipv4ifIndex1);
    //仿真-Simulator
    Ptr<Node> n6 = c.Get (6);
    Ptr<Ipv4> ipv46 = n6->GetObject<Ipv4> ();

    uint32_t ipv4ifIndex6 = 2;
    Simulator::Schedule (Seconds (6),&Ipv4::SetDown,ipv46, ipv4ifIndex6);
    Simulator::Schedule (Seconds (8),&Ipv4::SetUp,ipv46, ipv4ifIndex6);
 
    Simulator::Schedule (Seconds (12),&Ipv4::SetDown,ipv41, ipv4ifIndex1);
    Simulator::Schedule (Seconds (14),&Ipv4::SetUp,ipv41, ipv4ifIndex1);
 
    // 查探路由表
    Ipv4GlobalRoutingHelper g;
    Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("dynamic-global-routing.routes", std::ios::out);
    g.PrintRoutingTableAllAt (Seconds (12), routingStream);

    //设置生成xml文件,并确定各个节点的位置(为了好看我设置的位置四四方方的,而非无序随机产生)
    AnimationInterface animsd("test.xml");
    animsd.SetConstantPosition(c.Get(0),40,40);
    animsd.SetConstantPosition(c.Get(1),40,60);
    animsd.SetConstantPosition(c.Get(2),60,60);
    animsd.SetConstantPosition(c.Get(3),60,40);
    animsd.SetConstantPosition(c.Get(4),60,20);
    animsd.SetConstantPosition(c.Get(5),40,20);
    animsd.SetConstantPosition(c.Get(6),20,20);
    animsd.SetConstantPosition(c.Get(7),20,40);
    animsd.SetConstantPosition(c.Get(8),20,60);
    animsd.SetConstantPosition(c.Get(9),20,80);
    animsd.SetConstantPosition(c.Get(10),40,80);
    animsd.SetConstantPosition(c.Get(11),60,80);
    animsd.SetConstantPosition(c.Get(12),80,80);
    animsd.SetConstantPosition(c.Get(13),80,60);
    animsd.SetConstantPosition(c.Get(14),80,40);
    animsd.SetConstantPosition(c.Get(15),80,20);
    animsd.SetConstantPosition(c.Get(16),80,0);
    animsd.SetConstantPosition(c.Get(17),60,0);
    animsd.SetConstantPosition(c.Get(18),40,0);
    animsd.SetConstantPosition(c.Get(19),20,0);
    animsd.SetConstantPosition(c.Get(20),0,0);
    animsd.SetConstantPosition(c.Get(21),0,20);
    animsd.SetConstantPosition(c.Get(22),0,40);
    animsd.SetConstantPosition(c.Get(23),0,60);
    animsd.SetConstantPosition(c.Get(24),0,80);
    animsd.SetConstantPosition(c.Get(25),0,100);
    animsd.SetConstantPosition(c.Get(26),20,100);
    animsd.SetConstantPosition(c.Get(27),40,100);
    animsd.SetConstantPosition(c.Get(28),60,100);
    animsd.SetConstantPosition(c.Get(29),80,100);
    animsd::SetConstantPosition(c.Get(30),100,100);
    animsd::SetConstantPosition(c.Get(31),100,80);
    animsd::SetConstantPosition(c.Get(32),100,60);
    animsd::SetConstantPosition(c.Get(33),100,40);
    AnimationInterface::SetConstantPosition(c.Get(34),100,20);

//开始仿真
    NS_LOG_INFO ("Run Simulation.");
    Simulator::Run ();
    Simulator::Destroy ();
    NS_LOG_INFO ("Done.");
 }

(2)对于所解析的协议层,进行修改(包括工作机制和参数的修改),对比原有协议给出仿真对比结果(可以包括多个指标的,如延迟,丢包率等),也可以是负面的结果,但是要求给出合理科学的结果分析。(1000字以上,附有相关截屏图)。(15分)
创建5Mbps,2ms的信道,链接节点0和1,2,3,4,5,6,7,8

创建1500kbps,10ms的信道,链接节点1和10,2和11,12,13,3和14,4和15,16,17,5和18,6和19.20.21,7和22,8和9,23,24

创建第一次没有任何ip寻址信息的信道

分别给分配ip地址:

配置服务器开始和结束时间:

规定每一个节点的位置:

仿真结果对比:
原仿真结果:

更改后仿真结果:

三、总结与认识

根据仿真实验过程,总结对计算机网络的基本概念、原理、协议栈及Internet为实例的协议栈的理解认识以及收获,及仿真实验中所遇到的困难和解决方案。(2000字以上,A4纸手写)(30分)
字丑(捂脸)

最后修改:2021 年 06 月 21 日
如果觉得我的文章对你有用,请随意赞赏