计算机网络课程设计_第1页
计算机网络课程设计_第2页
计算机网络课程设计_第3页
计算机网络课程设计_第4页
计算机网络课程设计_第5页
已阅读5页,还剩21页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、中国地质大学(武汉)计算机学院计算机网络原理课程设计报告姓 名:学 号:联系方式:邮 件:指导老师:陈 喆二一二年七月目录一、 WireShark抓包分析TCP三次握手和四次握手实验1、实验思路.32、实验重点33、实验内容33.1、tcp第一次握手33.2、tcp第二次握手43.3、tcp第三次握手43.4、第一次请求数据.53.5、第一次回复数据.53.6、tcp断开连接第一次握手.63.7、tcp断开连接第二次握手.63.8、tcp断开连接第三次握手.73.9、tcp断开连接第四次握手.73.10、图形显示.8 二、 NS2仿真模拟真实网络场景实验1、有线场景下慢启动+滑动窗口实验1.1

2、、tcl文件.81.2、NAM动画显示.91.3、graph流量分析.122、有线节点与无线节点的混合仿真模拟实验2.1、tcl文件.122.2、NAM动画显示152.3、awk文件分析.152.4、graph流量分析.193、无线节点移动仿真模拟(自己的成果)3.1、tcl文件.203.2、NAM动画显示24三、 E to C Translation25四、总结.32一、WireShark抓包分析TCP三次握手实验1、实验思路:1.1启动WireShark抓包1.2、访问学校主页服务器,通过WireShark捕获通信内容1.3、分析TCP连接建立的三次握手和连接释放的四次握手过程2、实验重点

3、:2.1、浏览网页,抓取三次我输的包,并根据TCP包头格式记录各字段取值情况2.2、TCP包头格式如下:3、实验内容:3.1、第一次握手:找出第一次握手的数据包并截取对该数据包的展开图,根据截图填写相关内容,具体见下面的描述:Source IP: 09 Destination IP: 99Source port: 50915 Destination port:http(80)序号:0 确认号:0 URG: 0 ACK: 0 PSH: 0 RST: 0 SYN: 1 FIN: 0 窗口:81923.2、第二次握手Source IP: 74.125.71

4、.199 Destination IP: 09Source port: http(80) Destination port: 50912序号:0 确认号:1 URG: 0 ACK: 1 PSH: 0 RST: 0 SYN: 1 FIN: 0 窗口:1430033、第三次握手Source IP: 09 Destination IP: 99Source port: 50912 Destination port:http(80)序号:1 确认号:1 URG: 0 ACK: 1 PSH: 0 RST: 0 SYN: 0 FIN: 0 窗

5、口:166323.4、第一次请求数据Source port: 50901 Destination port:http(443)序号:101 确认号:1 要接收的下一个序号:1517URG: 0 ACK: 1 PSH: 0 RST: 0 SYN: 0 FIN: 0 窗口:40823.5、第一次回复数据Source port:http(443) Destination port: 50901序号:38 确认号:1517 URG: 0 ACK: 1 PSH: 0 RST: 0 SYN: 0 FIN: 0 窗口:13693.6、tcp断开连接第一次握手Source MAC:2001:a18:1:20:

6、42 Destination MAC:2001:250:4002:448:c Source port: http(80) Destination port:50927序号:1450 确认号:379 URG: 0 ACK: 1 PSH: 0 RST: 0 SYN: 0 FIN: 1 窗口:68483.7、tcp断开连接第二次握手Source MAC:2001:250:4002:448:c Destination MAC: 2001:a18:1:20:42Source port: 50927 Destination port:http(80)序号:379 确认号:1451 URG: 0 ACK:

7、1 PSH: 0 RST: 0 SYN: 0 FIN: 0 窗口:172323.8、tcp断开连接第三次握手Source MAC:2001:250:4002:448:c Destination MAC: 2001:a18:1:20:42Source port: 50927 Destination port:http(80)序号:379 确认号:1451 URG: 0 ACK: 1 PSH: 0 RST: 0 SYN: 0 FIN: 1 窗口:172323.9、tcp断开连接第四次握手Source IP: 09 Destination IP: 99So

8、urce port: 50915 Destination port:http(80)序号:1451 确认号:380 URG: 0 ACK: 1 PSH: 0 RST: 0 SYN: 0 FIN: 0 窗口:68483.10、图形显示如下:二、NS2仿真模拟网络场景实验1、有线场景下慢启动+滑动窗口实验11、tcl文件(cwnd-tcp.tcl)set ns new Simulator ;#建立一个模拟对象 set tracefd open cwnd-tcp.tr w ;#打开trace文件将全程模拟产生的数据写入$ns trace-all $tracefd ;#将ns模拟对象与trace文件的

9、对象进行绑定 set nf open ns-tcp.nam w ;#打开nam文件将模拟的实况写入$ns namtrace-all $nf ;#将ns对象与nam对象进行绑定proc finish ;#定义结束的过程,模拟结束时自动调用global ns tracefd nf ;#声明全局变量$ns flush-trace ;#清空跟踪缓冲区close $tracefd ;#关闭trace文件和nam显示文件close $nfexec nam cwnd-tcp.nam & ;#启动namexit 0#定义两个节点n0和n1,在两个节点间建立一条tcp连接set n0 $ns node set

10、n1 $ns node#定义有线链路节点的双向链路,带宽,时延,队列类型(允许队尾丢包)$ns duplex-link $n0 $n1 1Mb 100ms DropTail #指定节点间相对位置(节点的布局,nam动画显示时使用)$ns duplex-link-op $n0 $n1 orient left-right#再节点0与节点1之间建立连接,并在节点0上使用TCP/Reno协议,节点1上使#用TCPSink协议进行接收,使用 TCP/Reno协议获得文件 TCP_Reno.trset tcp $ns create-connection TCP/Reno $n0 TCPSink $n1 1

11、$tcp set Window_ 64 ;#将tcp窗口的默认大小设为64$tcp set ssthresh_ 60 ;#将慢启动的初始阈值设为60$tcp set packetSize_ 500 ;#将包的大小设为500set ftp new Application/FTP ;#在tcp连接上建立FTP应用程序$ftp attach-agent $tcp ;#将FTP应用绑定到tcp发送代理$ftp set type_ FTP ;#设定ftp的类型set f0 open cwndrec.tr w ;#打开trace文件进行跟踪写入proc Record ;#定义记录的过程global f0

12、tcp ns ;#定义全局变量set intval 0.1 ;#定义时间间隔set now $ns now ;#定义模拟启动时间set cwnd $tcp set cwnd_ ;#定义tcp窗口值puts $f0 $now $cwnd ;#在cwndrec.tr文件中输出模拟过程中变化的值$ns at expr $now + $intval Record ;#设定不同的时间间隔执行Record过程$ns at 0.1 Record ;#0.1s的时候开始记录过程 $ns at 0.5 $ftp start$ns at 5.0 finish ;#5.0s的时候完成$ns run ;#开始运行1.

13、2、NAM动画演示1.3、流量分析(曲线模拟)分析:从0.0s-1.8s执行的是慢启动过程,之后执行的拥塞控制过程。2、有线节点与无线节点的混合仿真模拟实验2.1、tcl文件(wired-wireless.tcl) # 定义选项,设定模拟需要的一些属性。set val(chan) Channel/WirelessChannel ;# 无线信道类型set val(prop) Propagation/TwoRayGround ;# 无限信号传输模型set val(netif) Phy/WirelessPhy ;# 物理层类型为无线物理层set val(mac) Mac/802_11 ;# MAC层

14、采用802.11协议set val(ifq) Queue/DropTail/PriQueue ;# 接口队列类型为IFQ队列set val(ll) LL 逻辑链路层类型LL层set val(ant) Antenna/OmniAntenna ;# 天线类型为全向天线set val(ifqlen) 50 ;# 队列长度set val(nn) 2 ;# 移动节点个数set val(rp) DSDV ;# 路由协议set val(x) 500 ;# 拓扑的X尺寸(单位m)set val(y) 500 ;# 拓扑的Y尺寸# 初始化全局变量#建立一个Simulator对象的实例并赋值给变量ns_set n

15、s_ new Simulator#打开一个名为simple.tr的文件(若不存在,则创建),设定文件可写,变量tracefd指向该文件Set tracefd open simple.tr w#调用Simulator类的trace-all方法将整个模拟过程写入simple.tr的Trace文件中$ns_ trace-all $tracefdset namtracefd open simple.nam w#在拓扑范围内建立无线nam跟踪$ns_ namtrace-all-wireless $namtracefd $val(x) $val(y)#建立一个Topography对象,该对象会保证节点在拓

16、扑边界范围内运动set topo new Topography#设定模拟所采用的场景的长宽尺寸$topo load_flatgrid $val(x) $val(y)# 建立一个God对象。God对象主要用来对路由协议做性能评价,它存储了节点总数,节点间最短路径等信息。节点的MAC对象会调用God对象,因此即使不使用也仍然要建立此对象。create-god $val(nn)# 建立指定数目$val(nn)的移动节点并将它们连接至信道。# 这里建立了两个节点: node(0),node(1)# 配置节点 $ns_ node-config -adhocRouting $val(rp) -llType

17、 $val(ll) -macType $val(mac) -ifqType $val(ifq) -ifqLen $val(ifqlen) -antType $val(ant) -propType $val(prop) -phyType $val(netif) -channelType $val(chan) -topoInstance $topo -agentTrace ON -routerTrace ON -macTrace OFF -movementTrace OFF #建立两个节点,关闭节点的随机运动功能,即节点的运动完全有程序指定 for set i 0 $i $val(nn) incr

18、 i set node_($i) $ns_ node $node_($i) random-motion 0 ;# 为移动节点指定初始的X,Y坐标,此处Z坐标为0$node_(0) set X_ 5.0$node_(0) set Y_ 2.0$node_(0) set Z_ 0.0$node_(1) set X_ 390.0$node_(1) set Y_ 385.0$node_(1) set Z_ 0.0# 下面产生一些简单的运动# Node_(1)在50.0s,以15.0m/s的速度向坐标(25.0,20.0)运动$ns_ at 50.0 $node_(1) setdest 25.0 20.

19、0 15.0# Node_(0)在10.0s,以1.0m/s的速度向坐标(20.0,18.0)运动$ns_ at 10.0 $node_(0) setdest 20.0 18.0 1.0# Node_(1)在100.0s,以15.0m/s的速度向坐标(490.0,480.0)运动$ns_ at 100.0 $node_(1) setdest 490.0 480.0 15.0#设置节点间的流量#创建一个TCP源代理对象tcpset tcp new Agent/TCP#class_是agent类中定义的整型变量,用于分类,之后可用于着色。此程序无用。$tcp set class_ 2#创建分组的接

20、收代理对象sinkset sink new Agent/TCPSink#将源代理对象tcp绑定到节点0$ns_ attach-agent $node_(0) $tcp#将接收代理对象sink绑定到节点1$ns_ attach-agent $node_(1) $sink#在源代理对象tcp和接收代理对象sink之间建立连接$ns_ connect $tcp $sink#在TCP连接上创建一个FTP流量模拟器,因为TCP不会产生自己的流量set ftp new Application/FTP$ftp attach-agent $tcp#在10.0s启动ftp流量模拟器$ns_ at 10.0 $f

21、tp start#模拟结束时告知节点for set i 0 $i $val(nn) incr i #在模拟结束前(150.0s)重置节点中的所有对象 $ns_ at 150.0 $node_($i) reset;#告知Simulator对象在150.0s时调用stop过程$ns_ at 150.0 stop#在150.01s时输出提示语句并终止调度器$ns_ at 150.01 puts NS EXITING. ; $ns_ halt#stop过程proc stop global ns_ tracefd namtracefd ;#声明全局变量 $ns_ flush-trace ;#清空跟踪的缓

22、冲区 close $tracefd ;#关闭文件 close $namtracefd exec nam simple.nam & ;#启动nam exit 0puts Starting Simulation.#启动调度器$ns_ run22、NAM动画显示2.3、awk文件分析2.3.1、delay.awk 文件BEGIN highest_uid=0; #highest_uid 会保存一处理过的分组中最大的uid event=$1; #第一个字段$1标识事件的类型 time=$2; #第二个字段$2标识事件发生的时间 node=$3; #第三个字段$3标识事件发生所在的地点 len=lengt

23、h(node) #有线trace和无线trace格式不同,通过判断node的字段唱得知是哪一种格式if(len=3) #无线trace格式$3如“_x_”,字段长len=3node_ =substr(node,2,1); #获取节点号trace_type=$4; #无线trace第四个字段$4为事件发生所在的网络层面flag=$5; uid=$6; #无线trace第6个字段$6为分组的uidpkt_type=$7; #无线trace第7个字段$7为分组的类型pkt_size=$8; #无线trace第8个字段$8为分组的大小Else #有线trace格式$3如“x”,字段长len=1from

24、_node =$3; #有线trace第3个字段$3为分组的源节点to_node=$4; #有线trace第4个字段$4为分组的目的节点pkt_type=$5; #有线trace第5个字段$5为分组的类型pkt_size=$6; #有线trace第6个字段$6为分组的大小flag=$7;uid=$12; #有线trace第12个字段$12为分组的uidif(len=3) #如果分析的是无线trace记录if(event=s & node_=2 & pkt_type=cbr & highest_uid=uid) start_timeuid=time; #源节点是无线节点2,保存源节点发送分组的时

25、间else #如果分析的是有线trace记录 if(event=r & to_node=0 & pkt_type=cbr & highest_uid=uid) end_timeuid=time; #目的节点是无线节点0,保存目的节点发送分组的时间if(event=s & node_=2 & pkt_type=cbr & highest_uiduid) highest_uid=uid; #更新highest_uid的值END id=1; delay=0.0; for(i=0;i=highest_uid;i+) start=start_timei; end=end_timei; delay=end

26、 -start; #计算分组的延迟时间 if( startend) printf(%d %.9fn,rate,delay); #打印节点 delay=delay+(end -start); #节点之间发送的分组机分组的延迟时间 2.3.2、throughput.awk文件BEGIN init=0; i=0; event = $1; time = $2; node = $3; len = length(node); if(len = 3) node_ = substr(node,2,1); trace_type = $4; flag = $5; uid = $6; pkt_type = $7;

27、pkt_size = $8; else from_node = $3; to_node = $4; pkt_type = $5; pkt_size = $6; flag =$7; uid = $12; if(len=1) #如果目的节点接收到分组 if(event=r & to_node=0 & pkt_type=cbr) pkt_byte_sumi+1=pkt_byte_sumi+(pkt_size-20); #计算已接收的数据字节 if(init=0) start_time=time; #保存接收到的第一个分组的时间 init=1; end_timei=time; 更新接收到的最新一个分组

28、的时间 i+; END th =8*pkt_byte_sumi-1/(end_timei-1-start_time)/1000; #计算吞吐量 printf(%d %.2fn,rate, th); #打印吞吐量信息 2.3.3、jitter.awk文件BEGIN highest_uid=0;event = $1;time = $2;node = $3;len = length(node);if(len = 3) node_ = substr(node,2,1);trace_type = $4;flag = $5;uid = $6;pkt_type = $7;pkt_size = $8; els

29、e from_node = $3;to_node =$4;pkt_type = $5;pkt_size = $6;flag = $7;uid = $12;if(len=3) if(event=d & node_=2 & trace_type=AGT & pkt_type=cbr)start_timeuid = time; else if(event=r & to_node=0 & pkt_type=cbr)end_timeuid = time;if(highest_uid uid) highest_uid = uid; #更新highes_uid的值END id=1;for(i=0; i=hi

30、ghest_uid; i+ )start = start_timei;end = end_timei;if(start end) delayi=end-start; #用一个数组保存每个分组的延迟时间last_delay=0; #last_delay用于保存上一分组的延迟时间last_seqno=0;for(i=0; i=highest_uid; i+)if(delayi!=0) if(last_delay=0) jitter=0; #第一个抖动为0 else jitter=(delayi-last_delay)/(i-last_seqno); #从第二个分组开始 #计算抖动printf(%d

31、 %.8fn,i,jitter); #打印延迟抖动信息last_delay=delayi;last_seqno=i;2.4、流量分析(主要是分析时延、带宽和抖动率)三、E to C TranslationA Day in the Life of a Web Page Request网页请求的流程1、前言:本章我们主要讨论链路层,我们的网络之路从协议栈起步。Getting Started : DHCP ,UDP, IP,and Ethernet让我们来假设Bob启动他的笔记本然后连上以太网连接到学校的以太网交换机,这些交换机轮流连到学校的路由器,像上图显示的一样学校的路由器连到ISP,如电信,电

32、信为学校提供DNS服务,因此,DNS服务器存在于电信联盟的网络上而不是学校网络。我们假设DHCP服务器运行在路由器,经常都是这样 。当Bob第一次联网时,他不能做任何事假如没有IP地址,因此,第一次网络关联的举动就是运行DHCP来获得IP地址,也包括其他的一些信息。2、正文:如上图所示:数字和下面的翻译对应:1. The operating system on Bobs laptop creates a DHCP request message and puts this message within a UDP segment with destination port 67 (DHCP s

33、erver) and source port 68 (DHCP client). The UDP segment is then placed within an IP datagram with a broadcast IP destination address (55) and a source IP address of , since Bobs laptop doesnt yet have an IP address. Bob的笔记本电脑上的操作系统创建一个DHCP请求消息并且把这个消息放在包含目标端口67(DHCP服务器)和源端口68(DHC

34、P客户端)UDP段内。UDP报文封装在IP数据报内以源IP地址(),全网广播出去,现在Bob的电脑依然上不了网。 2. The IP datagram containing the DHCP request message is then placed within an Ethernet frame. The Ethernet frame has a destination MAC addresses of FF:FF:FF:FF:FF:FF so that the frame will be broadcast to all devices connected to the

35、switch (hopefully a DHCP server); the frames source MAC address is that of Bobs laptop, 00:16:D3:23:68:8A. IP数据报包含DHCP的发送请求报文,然后封装在以太网帧中。以太网帧的默认目的MAC地址为FF:FF:FF:FF:FF:FF,以至于以太网帧能广播到连接在交换机(准确的说应该是DHCP服务器)的全部设备上,然后帧的源MAC地址是Bob的电脑:00:16:D3:23:68:8A.3. The broadcast Ethernet frame containing the DHCP re

36、quest is the first frame sent by Bobs laptop to the Ethernet switch. The switch broadcasts the incoming frame on all outgoing ports, including the port connected to the router. Bob的电脑发到以太网交换机的第一帧是包括DHCP请求报文的广播帧。交换机广播所有来自输出端口的传入帧,包括连接到路由器的端口上的。4. The router receives the broadcast Ethernet frame conta

37、ining the DHCP request on its interface with MAC address 00:22:6B:45:1F:1B and the IP datagram is extracted from the Ethernet frame. The datagrams broadcast IP destination address indicates that this IP datagram should be processed by upper layer protocols at this node, so the datagrams payload (a U

38、DP segment) is thus demultiplexed up to UDP, and the DHCP request message is extracted from the UDP segment. The DHCP server now has the DHCP request message.路由器用接口MAC地址为00:22:6B:45:1F:1B接收包含DHCP请求报文的广播以太网帧,然后从以太网帧中提取IP报文。该报文的广播的IP目的地址表明本IP数据报应该由上层协议在这个节点上进行处理,所以该数据报的有效载荷(一个UDP报文)向上分用给UDP,然后DHCP请求报文

39、从UDP报文中提取。此时DHCP服务器拥有了DHCP请求报文。5. Lets suppose that the DHCP server running within the router can allocate IP addresses in the CIDR block /24. In this example, all IP addresses used within the school are thus within Comcasts address block. Lets suppose the DHCP server allocates address 68.8

40、5.2.101 to Bobs laptop. The DHCP server creates a DHCP ACK message containing this IP address, as well as the IP address of the DNS server (26), the IP address for the default gateway router (), and the subnet block (/24) (equivalently, the “network mask”). The DHCP messa

41、ge is put inside a UDP segment, which is put inside an IP datagram, which is put inside an Ethernet frame. The Ethernet frame has a source MAC address of the routers interface to the home network (00:22:6B:45:1F:1B) and a destination MAC address of Bobs laptop (00:16:D3:23:68:8A). 我们假设在路由器上运行的DHCP服务

42、器能用/24这个地址块分配IP地址。在这个例子中学校里面使用的IP的地址也是电线公司分配的地址块当中的地址。 我们假设DHCP服务器分配给Bob的电脑的IP是01。DHCP服务器产生一个ACK报文其中包含这个IP地址,也包含DNS服务器的IP((26),默认网关的IP()和子网掩码/24。DHCP报文封装在UDP数据报中,UDP数据报又封装在IP报文中,IP报文封装在以太网帧中进行传输。以太网帧有一个连接在路由器接口源MAC地址00:22:6B:45:1F:1B和Bob电脑的目的MAC地址00:16:D

43、3:23:68:8A。6. The Ethernet frame containing the DHCP ACK is sent (unicast) by the router to the switch. Because the switch is self-learning and previously received an Ethernet (containing the DHCP request) from Bobs laptop, the switch knows to forward a frame addressed to 00:16:D3:23:68:8A only to t

44、he output port leading to Bobs laptop. 包含DHCP ACK的以太网帧从路由器发送到交换机。因为交换机有自我学习的功能,所以在之前接收到从Bob发来的DHCP请求帧,交换机就知道转发帧从接收请求帧的那个端口发送DHCP ACK 到MAC地址为00:16:D3:23:68:8A。7. Bobs laptop receives the Ethernet frame containing the DHCP ACK, extracts the IP datagram from the Ethernet frame, extracts the UDP segment from the IP datagram, and extracts the DHCP ACK message from the UDP segment. Bobs DHCP client then records its IP address and the IP address of its DNS server. It also installs the address of th

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论