《NS中的基本无线模型.ppt》由会员分享,可在线阅读,更多相关《NS中的基本无线模型.ppt(63页珍藏版)》请在三一办公上搜索。
1、NS Tutorial:mobile and wireless network simulation,Chuda LiuXJTUApril 10th,2004,Outlines,1.引言:NS中的基本无线模型 2.对CMU的无线模型的扩展3.应用举例,1.引言:NS中的基本无线模型,1.1 创建无线拓扑 1.2 创建MN的移动1.3 MN中的网络组件1.4 MAC协议1.5 Ad hoc 路由协议1.6 Trace支持1.7 对无线Trance格式的修改1.8 产生节点移动和业务连接的场景文件,1.引言:NS中的基本无线模型,引言无线模型MobileNode支持Adhoc&WLAN特征,基本节
2、点,无线/移动功能,在给定拓扑中移动;能从无线通道(Channel)接收发送信号MN不再通过链路相连,1.1 创建无线拓扑,MN从Node派生,其移动特征包括:节点移动 周期性位置更新 维护拓扑边缘MN中的网络组件 分类器 dmux LL MAC Channel,在C+实现mobilenode.cc,h,在OTcl实现ns-mobilenode.tcl,1.1 创建无线拓扑,创建MN前先要配置节点,经过以下API:#Define how a mobile node is configured$ns_ node-config-adhocRouting$opt(adhocRouting);#创建a
3、dhoc ragent-llType$opt(ll)-macType$opt(mac)-ifqType$opt(ifq)-ifqLen$opt(ifqlen)-antType$opt(ant)-propInstance new$opt(prop)-phyType$opt(netif)-channel new$opt(chan)-topoInstance$topo-wiredRouting OFF-agentTrace ON-routerTrace OFF-macTrace OFF,1.1 创建无线拓扑,创建MN:for set j 0$j$opt(nn)incr j set node_($j)
4、$ns_ node$node_($i)random-motion 0;#disable random motion,Node,ARP,Propagation and antenna models,MobileNode,LL,MAC,PHY,LL,CHANNEL,LL,MAC,PHY:,protocolAgent/src/sink,routingagent,addrclassifier,portclassifier,255,IFQ,IFQ,defaulttarget_,Radio propagation/antenna models,Prop/ant,Mobilenode示意图,Node,ARP
5、,Propagation and antenna models,MobileNode,LL,MAC,PHY,LL,CHANNEL,protocolagent,routingagent,addrclassifier,portclassifier,255,IFQ,defaulttarget_,Mobilenode示意图,物理层:1.无线电波模型表示:近处:Pant=1/r2 a free space prop.远处:Pant=1/r4 two-ray ground2.每个MN有一个或多个网络接口,相同的类型的接口接到一个通道 Pkt-Chan Obj 计算延时-调度 包到达事件-通告接收接口pkt
6、到达-比较pkt的能量级别t0:载波侦听阀值t1 和接收阀值t2:if t0t1 then discard pkt;else if t1t0t2 mark err;recv pkt并传至MAC层,Node,ARP,Propagation and antenna models,MobileNode,LL,MAC,PHY,LL,CHANNEL,protocolagent,routingagent,addrclassifier,portclassifier,255,IFQ,defaulttarget_,Mobilenode示意图,MAC层:实现了完整的IEEE 802.11 DCF,Node,ARP
7、,Propagation and antenna models,MobileNode,LL,MAC,PHY,LL,CHANNEL,protocolagent,routingagent,addrclassifier,portclassifier,255,IFQ,defaulttarget_,Mobilenode示意图,ARP 地址解析协议 MAC地址IP地址,SRNode不用 address demux or classifiers;节点接收到的所有包默认地 转发到DSR代理;DSR代理或者将pkt送到端口 dmux或者按源路路由转发pkt,1.2 创建MN的移动,MN被设计成在一个三维拓扑中移
8、动,但Z轴未用(Z0);MN的坐标随MN的移动而改变;有2种机制引入MN的移动:指定MN的起始和终点位置 随机移动模式创建MN前需要定义拓扑 set topo new Topography$topo load_flatgrid$opt(x)$opt(y),$node set X_$node set Y_$node set Z_$ns at time Snode setdest,1.3 MN中的网络组件,MN的网络栈有以下组件:LL ARP MAC IFQ netIF Channel 它们在MN中的add-interface()方法创建,#The following setups up link
9、 layer,mac layer,network#interface,physical layer structures for the mobile node.Node/MobileNode instproc add-interface channel pmodellltype mactype qtype qlen iftype anttype$self instvar arptable_ nifs_$self instvar netif_ mac_ ifq_ ll_global ns_ MacTrace optset t$nifs_incr nifs_set netif_($t)new$i
10、ftype;#net-interfaceset mac_($t)new$mactype;#mac layerset ifq_($t)new$qtype;#interface queueset ll_($t)new$lltype;#link layerset ant_($t)new$anttype#Local Variablesset nullAgent_$ns_ set nullAgent_ add-interface(1/8),set netif$netif_($t)set mac$mac_($t)set ifq$ifq_($t)set ll$ll_($t)#Initialize ARP t
11、able only once.#if$arptable_=set arptable_ new ARPTable$self$macset drpT cmu-trace Drop IFQ$self$arptable_ drop-target$drpT#Link Layer#$ll arptable$arptable_$ll mac$mac$ll up-target$self entry$ll down-target$ifq add-interface(2/8),#Interface Queue#$ifq target$mac$ifq set qlim_$qlenset drpT cmu-trace
12、 Drop IFQ$self$ifq drop-target$drpT#Mac Layer#$mac netif$netif$mac up-target$ll$mac down-target$netif$mac nodes$opt(nn)add-interface(3/8),#Network Interface#$netif channel$channel$netif up-target$mac$netif propagation$pmodel;#Propagation Model$netif node$self;#Bind node interface$netif antenna$ant_(
13、$t);#attach antenna#Physical Channel#$channel addif$netif;#add to list of interfaces#=#Setting up trace objects add-interface(4/8),#Network Interface#$netif channel$channel$netif up-target$mac$netif propagation$pmodel;#Propagation Model$netif node$self;#Bind node interface$netif antenna$ant_($t);#at
14、tach antenna#Physical Channel#$channel addif$netif;#add to list of interfaces#=#Setting up trace objects add-interface(5/8),#Network Interface#$netif channel$channel$netif up-target$mac$netif propagation$pmodel;#Propagation Model$netif node$self;#Bind node interface$netif antenna$ant_($t);#attach an
15、tenna#Physical Channel#$channel addif$netif;#add to list of interfaces#=#Setting up trace objects add-interface(6/8),if$MacTrace=ON#Trace RTS/CTS/ACK Packets#set rcvT cmu-trace Recv MAC$self$mac log-target$rcvT#Trace Sent Packets#set sndT cmu-trace Send MAC$self$sndT target$mac sendtarget$mac sendta
16、rget$sndT#Trace Received Packets#set rcvT cmu-trace Recv MAC$self$rcvT target$mac recvtarget$mac recvtarget$rcvT add-interface(7/8),#Trace Dropped Packets#set drpT cmu-trace Drop MAC$self$mac drop-target$drpT else$mac log-target$ns_ set nullAgent_$mac drop-target$ns_ set nullAgent_#=$self addif$neti
17、f add-interface(8/8),1.3.1 Link Layer(LL),仿真数据链路层协议,实现分组的分段、重组等;LL层负责设MAC目的地址在分组的MAC 头。,1.3.2 ARP,Address Resolution Protocol 接收从LL来的查询,如果ARP目的地址的硬件地址,它将其写入分组的MAC头;否则广播一个ARP查询,并临时缓存分组;对每个未知目的地址的硬件地址,有一个缓存为每个分组;对有相同目的地址的分组若发送到ARP,早先缓存的分组被丢弃;一旦分组下一跳的硬件地址知道,分组被插入到interface queue(Ifq);The ARPTable./ns-2
18、/arp.h 被实现在arp.cc,h和tcl/lib/ns-mobilenode.tcl.,1.3.3 Interface Queue,优先队列PriQueue./ns-2/priqueue.h对路由分组给较高优先级,将它们插入队列头;对对列中的所有分组有过虑作用并移除那些特定目的地址的分组;见priqueue.cc,h 为IFq 实现.,1.3.4 MAC Layer,IEEE 802.11 distributed coordination function(DCF)Mac 协议由CMU实现;对单播分组它使用RTS/CTS/DATA/ACK 模式;对广播分组只简单发送DATA;实现物理和虚
19、拟载波侦听;Mac802_11被实现在mac-802_11.cc,h.,1.3.5 Network Interfaces,Network Interface layer作为用于MN访问 channel 的硬件接口;无线共享媒体接口在Phy/WirelessPhy./ns-2/wireless-phy.h中实现,这种接口容易产生冲突并且由 radio propagation model 接收由其他节点接口发送到channel的分组;接口给每个发送的分组分发时间戳 以及给出发送接口的meta-data,如发送功率、波长等参数;meta-data在pkt头,propagation model用来在接
20、收netIF 确定是否分组有能被接收and/or captured and/or detected(carrier sense)by the receiving node的最小功率;模型用近似DSSS radio interface(Lucent WaveLan direct-sequence spread-spectrum),netIF实现见phy.cc.h 和wireless-phy.cc,h,1.3.6 Radio Propagation Model,近距离使用 Friss-space attenuation();远距离近似使用Two ray Ground();近似假设频谱在一个平面中反
21、射;实现见tworayground.cc,h,1.3.7 Antenna,MN使用有统一增益的全向天线omni-directional antenna.实现见antenna.cc,h。,1.5 路由代理,DSDV DSR TORA AODV,1.5.1 Destination-Sequenced Distance Vector(DSDV),DSDV需要节点周期性的广播路由更新,采用逐跳路由,与传统的DV比,不会产生环路;基本机制:每个节点维护一个路由表,为每个可达目的地址列出下一跳;DSDV给每个路径一个序列标记,若路径R比R好:要么序列号高,要么测度 值低;网络中的节点通告单调递增的序列号;
22、若节点B得知到目的D的路径断了,则以一个无穷大的测度和序列号比原来 值大1的通告到D的路径。,1.5.1 Destination-Sequenced Distance Vector(DSDV),实现细节;路由信息在MN间交换,当邻节点的路由信息在路由表中发生 变化,路由更新会被触发和转发;若分组到目的地的路径未知时会被缓存,同时发送路由查询,缓存至路径应答返回;缓存分组数目到达分组最大时,后来的分组会被丢弃.到MN的所有分组被地址dmux直接传至端口dmux.端口dmux 传送分组到分别的目的代理,端口255用来连接路由代理。MN也使用一个default-target 在分类器或地址demux
23、中。路由协议主要在C+中实现.DSDV实现的相关程序见dsdv 目录和tcl/mobility/dsdv.tcl,1.5.2 Dynamic Source Routing(DSR),DSR采用源路由而不是逐跳路由,其优点是中间节点不需要维护路由信息更新。基本机制有2个:路径发现 节点S需要发送一个分组到目的D以获得到目的D的源路径;*源节点S以泛洪方式广播一个ROUTE REQUEST到网络;*从目的节点或知道目的节点返回一个ROUTE REPLY到S。(为减少开销,每个节点维护一个它已经知道的源路径,以减少发送RREQ的频率和传输)路径维护 当网络拓扑改变后,需要更新源路径;实现细节:见ds
24、r 目录和 tcl/mobility/dsr.tcl,1.5.3 Temporally-Ordered Routing Algorithm(TORA),TORA是基于“反向链路”算法的分布式路由协议,按需发现路径,给一个目的提供多个路径,快速建立路径。基本机制:,1.5.4 Ad Hoc On-Demand Distance Vector(AODV),TORA是基于“反向链路”算法的分布式路由协议,按需发现路径,给一个目的提供多个路径,快速建立路径。基本机制:,1.6 Trace Support,无线仿真的Trace支持仍然用cmu-trace对象。cmu-trace对象有三类:CMUTrac
25、e/Drop,CMUTrace/Recv和CMUTrace/Send.这些用来在应用层agent、网络层router和链路层MAC跟踪分组的丢弃、接收和发送事件。用来实现无线跟踪支持的方法和程序可在trace.cc,h和tcl/lib/ns-cmutrace.tcl找到。,1.7 Revised format for wireless traces,1.8 产生节点移动和业务连接场景,2 对cmu无线模型的扩展,原来的CMU无线模型仅允许仿真 wireless LANs 和ad-hoc networks,为了用它仿真有线和无线节点必须对它扩展,称为wired-cum-wireless feat
26、ure。SUN公司集成MIP到无线模型允许MN允许MIP2.1 wired-cum-wireless 场景 2.2 MIP,2.1 wired-cum-wireless场景,当需要仿真一个由多个 WLAN通过有线节点相连的拓扑,或需要无线节点运行MIP 则需要扩展CMU模型;面临的主要问题是路由,因为在NS中路由信息产生基于拓扑的联通性,如节点怎样经过Link和其他节点相连;而MN无Link的概念,它们在无线拓扑范围内通过路由协议传送分组到其他,因此这2类节点如何交换分组?BaseStationNode被引入作为优先和无线域的网关,本质上基站节点是一个层次节点(HierNode)和Mobile
27、Node的混合节点。基站节点负责转发分组到和出无线域,这协议层次路由来实现它。每个无线域和基站应有一个唯一的域地址分配给他们,所有到无线节点的分组到达改无线节点域所属的基站,基站最终将其传到MN;MN发送分组到无线域外需先发送到基站,基站知道如何转分组到有线目的.在wired-cum-wireless中MN需要支持层次寻址/路由.,Figure 16.3:Schematic of a baseStationNode,2.1 Mobile IP,wired-cum-wireless 扩展无线模型为在NS中支持无线MIP奠定了基础MIP模型基于有线模型(由节点和链路组成)并且不用CMU的移动模型;
28、MIP由HA和FA组成,MH在HA和FAs间移动,HA和FA本质上为基站节点,而MHs为mobileNodes,MIP扩展的方法和程序在以下文件中:ns/mip.cc,h,ns/mip-reg.cc,ns/tcl/lib/ns-mip.tcl,ns/tcl/lib/ns-wireless-mip.tcl.。HA和FA节点 被定义为MobileNode/MIPBS,有注册代理(regagent_)发送信号到MN,建立了encapsulator和decapsulator。MH节点 被定义为MobileNode/MIPMH,也有regagent_ 接收和相应 信号,并发送请求到HA或FAs.。Mob
29、ileNode/MIPMH与MobileNode/MIPBS相似,除了它没有封装和解封装器。对 SRNode 版的MH,没有层次分类器 和由RA代理组成节点实体。,Figure 16.4:Schematic of a Wireless MobileIP BaseStation Node,2.1 Mobile IP,MobileNode/MIPBS节点广播信号或通告消息到MHs,一个来自MN的请求产生一个通告,该通告直接发送到请求MH。发送信号的基站的地址被MH听到,并用作 MH的COA(care-of-address).因此当MH从家网移到外部域,其COA会改变.当从MH接收到reg_requ
30、est(as reply to ads),基站会检查是否是MH的HA,若不是,它建立解封装并转发reg_request到MH的HA.In case the base-station is the HA for the requesting MH but the COA doesnot match its own,it sets up an encapsulator andsends reg-request-reply back to the COA(address of the FA)who has forwarded the reg_request to it.so now all pack
31、etsdestined to the MH reaching the HA would be tunneled through the encapsulator which encapsulates the IP pkthdr with aIPinIP hdr,now destined to the COA instead of MH.The FAs decapsulator recives this packet,removes the encapsulation,A simple wireless simulation(1),Scenariocontaining 3 mobile node
32、smoving within 670mX670m flat topologyusing DSDV ad hoc routing protocolRandom Waypoint mobility modelTCP and CBR trafficSee:ns-2/tcl/ex/wireless-demo-csci694.tcl,A simple wireless simulation(2),set ns_ new Simulator;create a ns simulator instance,#Define Global Variables,set topo new Topography;cre
33、ate a topology and$topo load_flatgrid 670 670;define it in 670 x670 area,A simple wireless simulation(3),#Define standard ns/nam trace,set tracefd open 694demo.tr w$ns_ trace-all$tracefd,set namtrace open 694demo.nam w$ns_ namtrace-all-wireless$namtrace 670 670,A simple wireless simulation(4),#Creat
34、e“God”,set god_ create-god 3 God is used to store an array of the shortest number of hops required to reach from one node to an other.For example:$ns_ at 899.00“$god_ setdist 2 3 1”,A simple wireless simulation(5),#Define how a mobile node should be created,$ns_ node-config-adhocRouting DSDV-llType
35、LL-macType Mac/802_11-ifqLen 50-ifqType Queue/DropTail/PriQueue-antType Antenna/OmniAntenna-propType Propagation/TwoRayGround-phyType Phy/WirelessPhy-channelType Channel/WirelessChannel-topoInstance$topo-agentTrace ON-routerTrace OFF-macTrace OFF,A simple wireless simulation(6),#Create a mobile node
36、 and attach it to the channel,set node$ns_ node$node random-motion 0;#disable random motion,Use“for loop”to create 3 nodes:for set i 0$i3 incr i set node_($i)$ns_ node,A simple wireless example(7),A simple wireless example(8),Wireless Scenario Generator(1),Mobile Movement Generatorsetdest-n-p pauset
37、ime-s-t-x-y See an exampleRandom movement$node startSource:See ns-2/indep-utils/cmu-scen-gen/setdest/,Wireless Scenario Generator(2),Generating traffic pattern filesCBR trafficns cbrgen.tcl-type cbf|tcp-nn nodes-seed seed-mc connections-rate rateTCP trafficns tcpgen.tcl-nn nodes-seed seedSee an exam
38、ple Source:See ns-2/indep-utils/cmu-scen-gen/,Sensor Node extension,Node is energy-awareDefine node by adding new options:$ns_ node-config-energyModel EnergyModel-initialEnergy100.0-txPower0.6-rxPower0.2,Summary of the API changes,OLD APIdsr/dsdv/tora-create-mobile-nodestrong global variable depende
39、ncyno nam supportno energy modelneed global chan and prop,New API$ns_ node-config$ns nodeno global variable dependency namtrace-all-wirelessEnergy model supportNo global definition of chan and prop,Visualize your simulation,Use nam to visualize:mobilenode positionmobilenode moving direction and spee
40、dcontrol the speed of playbackSee an example:,Feature summary(1),Mac Layer:IEEE 802.11Address Resolution Protocol(ARP)Ad hoc routing protocols:DSDV,DSR,TORARadio Propagation ModelFriss-space attenuation at near distancesTwo ray ground at far distancesAntenna:an omni-directional antenna having unity
41、gain,Feature summary(2),Scenario generator for traffic and node movementBase station node to bridge wired domain and wireless domainMobileIPSymmetric architecture with wired LAN(IEEE 802.3),Feature summary(3),Visualization of node movement and reachabilityGridkeeper optimizer for some scenariosEnerg
42、y consumption model for sensor networksValidation test-suites for dsdv,dsr,tora,base station,mobileIP,gridkeeper,Appendix A:Movement file,$node_(2)set Z_ 0.000000000000$node_(2)set Y_ 199.373306816804$node_(2)set X_ 591.256560093833$node_(1)set Z_ 0.000000000000$node_(1)set Y_ 345.357731779204$node_
43、(1)set X_ 257.046298323157$node_(0)set Z_ 0.000000000000$node_(0)set Y_ 239.438009831261$node_(0)set X_ 83.364418416244$ns_ at 50.000000000000$node_(2)setdest$ns_ at 51.000000000000$node_(1)setdest 221.826585497093 80.855495003839 14.909259208114$ns_ at 33.000000000000$node_(0)setdest,Appendix B:Tra
44、ffic Scenario,set udp_(0)new Agent/UDP$ns_ attach-agent$node_(0)$udp_(0)set null_(0)new Agent/Null$ns_ attach-agent$node_(2)$null_(0)set cbr_(0)new Application/Traffic/CBR$cbr_(0)set packetSize_ 512$cbr_(0)set interval_ 4.0$cbr_(0)set random_ 1$cbr_(0)set maxpkts_ 10000$cbr_(0)attach-agent$udp_(0)$ns_ connect$udp_(0)$null_(0)$ns_ at 127.93667922166023$cbr_(0)start.,Greedkeeper:an optimizer*,*optimization depends on your scenario,