[ZZ]NS2的DSR源代码分析

深入了解NS2中的AODV路由协议 NS2(Network Simulator version 2)是一款开源的、面向对象的离散事件网络模拟器,广泛应用于计算机网络的研究和教学领域。它支持多种网络协议和场景,能够模拟有线和无线网络环境中的各种复杂行为。在上一节中,我们已经提到了一些核心文件,下面将对这些文件及其功能进行详细介绍。在评估AODV协议的性能时,有多个关键指标需要关注。其中包括:平均端到端延迟(Average End-to-End Delay):衡量从源节点到目的节点传输数据包所经历的平均时间。计算公式为。 阅读详情

 

原文链接:http://www.winlab.rutgers.edu/~zhibinwu/html/DSR_ns2.html#handlePacketReceipt

DSR in ns-2


[ Back to Network Simulator 2 for Wireless Home Page ]


Source code :

    Not all flies in ./dsr/ directory are used by the ns-2. the routing agent is implemented as Agent/DSRAgent.
    Thus, the source codes include:

  • dsragent.cc (h):  DSR agent class. major state machine handling routings. Important variables; net_id, mac_id in ID type. (IP and MAC address), both of them are initialzied by tcl commands to set the initla valie, the commads are "addr" amd "mac_addr"
  • hdr_sr.cc(h): define hdr_sr class.
  • request_table.cc(h)
  • Path.h(cc):  Path class. First, define struct  ID, it has an unsigned long addr a enum of ID_type, and a time stamp t. and then in Path class, ID[] is the key members of the path, and operator [] is defined to return an element of ID array. thus whenever the SRPacket.route[n] will return to the reference of ID[n]. Other member variables include cur_index, len,
  • srpacket.h:    Just define SRPacket class which enclose the hdr_sr as a full packet. The SRPacket construct has two parameters, a normal packet and a SR (Source Route) Header (a path variable). The constructor of "path" class makes a path from the bits of an NS source route header. And the other two variables of the SR packet are "dst" and "src" IP addresses.

Data Structure for Route

It is found that srh->addr and p.route are two different structures. srh() is always along with the packet. however, when DSR agent received a packet, it will

       SRPacket p(packet, srh);

 This generate a "p" which is frequently used by all other functions. remember p does not go along with the packet leaving dsr agent. Before the packet was sent out of the agent, another statement will be used to update "SRH" in   sendOutPacketwithRoute
   
	p.route.fillSR(srh);

Also, the tap() entry is also generate a p for its use. however, another entry point of agent "xmitFailed" use srh() directly.

Special tcl interface.

Unless other routing protocol, the ns-2.1b9a,has a special node type named as "SRNodeNew". From those routines in the ns-lib.tcl. We can see that speical. Also, there is a tcl file in mobiloty/dsr.tcl is also related.
Simulator instproc create-node-instance args {
$self instvar routingAgent_
# DSR is a special case
if {$routingAgent_ == "DSR"} {
set nodeclass [$self set-dsr-nodetype]
} else {
set nodeclass Node/MobileNode
}
return [eval new $nodeclass $args]
}

Simulator instproc set-dsr-nodetype {} {
$self instvar wiredRouting_
set nodetype SRNodeNew
# MIP mobilenode
if [Simulator set mobile_ip_] {
set nodetype SRNodeNew/MIPMH
}
# basestation dsr node
if { [info exists wiredRouting_] && $wiredRouting_ == "ON"} {
set nodetype Node/MobileNode/BaseStationNode
}
return $nodetype
}

DSR Signaling Packets in Brief:

  • route-request. the packet itself is a layer 3 packet with a unique destination address, but MAC_Broadcast (labeled in common header's next_hop())
  • route-reply: unicasting in both layer 2 and 3.
  • route-error. unicasting in both layer 2 and 3. Generated when tx_failure in lower layer.


Entry Points for DSR agent:

  1. first, as normal, the recv() function which means a packet with a address destine to this node or from upper-target.
  2. xmitFailed(). This is the callback function when a MAC transmission failes. Based on this chance, route-error message generated
  3. tap(). This is a hidden entry when you turn promiscuous on. snooping the route and shorten the path.


Basic functions:

  • recv(), the entry for a receving packet. depends on the ip address of the packet and the SR (Source Route) header, call different functions to handle it. like the diagram below:
     
    The route-reply, route-request messages need special handling routines written in the handlePacketReceipt() funciton. Note that if the RRequest message reached the destination, the receiptent should send a RReply message, this is done by a function named  returnSrcRouteToRequestor(p) which is called in handlePacketReceipt(). Otherwise, if the route-request and route-err
  • or are not destined to us, for route-request, the function handleRouteRequest() is called
  • handlePacketReceipt(). A signaling reached its destination. There are two case:
    • if it is a route-request and "not processed",  sends back a route-reply, pkt "p" is forged in this function and returnSrcRouteToRequestor(p)
    • if it is a route-reply, call functiuon  acceptRouteReply(p);
  • handleRouteRequest(): From the version 2.27, we see some unused codes but probably under develop for future versions. It includes more close mac-routing cooperation, such as neighbor identity (is_neighnor()), and channel status (air_time_free()). 
     Basically, this function has three branches:
    1. already processed, checked by function ignoreRouteRequestp(p).
    2. has a cached route, done by replyFromRouteCache(p), and "cached route" is enabled by the flag dsragent_reply_from_cache_on_propagating.
    3. append myself in route with p.route.appendToPath(net_id); and sendOutPacketWithRoute(p, false);
  • handleForwarding. Forward packet on to next host in source route and  snooping as appropriate. So, a route-reply message is not treat as exceptional. It is a normal packet with sr header and be snooped by this node. The snooping is enabled by the flag "dsragent_snoop_source_routes" .
    handleForwarding is dcallin "handleDefaultforwarding" for doing some simple operations for DSR rules. At last, the packet will be sent by sendOutPacketWithRoute 
  • sendOutPacketWithRoute:  The function is used as  for send packets, Take packet and send it out, packet must a have a route in it. return value is not very meaningful. if fresh is true then reset the path before using it, if fresh is false then our caller wants us use a path with the index set as it currently is. Basically,
    • cmn header's failure callback functon and data are set
    • cmn header 's next hop is set to  addr of  next-hop in dsr header. address type are also set.
    • move the pointer in SR header to the next (increase 1).
    Actually, the third operation is not valid in real DSR implementations. To undo this effect in error-handing, we'd better find current Ip address first and locate the position of this address in SR header. The other two operations are also invalid, because there are no common headers in a real packet. For the "next_hop()" in common header, it is used by DSR only for those packets without valid SR header, refer to recv().
  • returnSrcRouteToRequestor(); this function 
  • xmitFailed(): when the common header->xmit_failure_ point to a callback function, thus, when the packet cannot be delivered, the callback function is used, and finally will generate a route-error messages. There is always a pointer in the SR header curr() . ( Refer to manet-ietf-dsr draft, there is no such a pointer in DSR Source Route Option, but has a "segments left" field to indicate how many nodes still to visit to reach the destination. ). Thus, an innovation needs to be done to re-interprete the "srh->cur_addr()" as a index number of the position in the path where fail happens.  So,  when not all nodes along the path handle the SR header, we need find the ip address of the node from srh. and set that index as cur_addr();
  • processBrokenRouteError(p); This should be another branch under the main recv() entry. It gives what to do when a Route Error message is receoived or heard (snooped). Snoop means the message was sent to another node but it passes myself, so i heard it.
  • tap(const Packet *packet): This is another entry point for DSR. When dsragent_use_tap flag is true. the mac is working in promiscuous mode and all overhearing packets will be processed if there is a SR header in it.

Other:
The longest route we can handle is defined in : define MAX_SR_LEN 16           // longest source route we can handle

Possible Reason for xmit_failure below IP layer:

  • arp failure
  • interface queue is full
  • mac transmission failure ( exceed the retry-limit)

DSR scheme options:
In the beginning of dsragent.cc, it define many bool selectors of some options like:


/*************** selectors ******************/
bool dsragent_snoop_forwarded_errors = true;
// give errors we forward to our cache?
bool dsragent_snoop_source_routes = true;
// should we snoop on any source routes we see?
bool dsragent_reply_only_to_first_rtreq = false;
// should we only respond to the first route request we receive from a host?
bool dsragent_propagate_last_error = true;
// should we take the data from the last route error msg sent to us
// and propagate it around on the next propagating route request we do?
// this is aka grat route error propagation
bool dsragent_send_grat_replies = true;
// should we send gratuitous replies to effect route shortening?
bool dsragent_salvage_with_cache = true;
// should we consult our cache for a route if we get a xmitfailure
// and salvage the packet using the route if possible
bool dsragent_use_tap = true;
// should we listen to a promiscuous tap?
bool dsragent_reply_from_cache_on_propagating = true;
// should we consult the route cache before propagating rt req's and
// answer if possible?
bool dsragent_ring_zero_search = true;
// should we send a non-propagating route request as the first action
// in each route discovery action?

// NOTE: to completely turn off replying from cache, you should
// set both dsragent_ring_zero_search and
// dsragent_reply_from_cache_on_propagating to false

bool dsragent_dont_salvage_bad_replies = true;
// if we have an xmit failure on a packet, and the packet contains a
// route reply, should we scan the reply to see if contains the dead link?
// if it does, we won't salvage the packet unless there's something aside
// from a reply in it (in which case we salvage, but cut out the rt reply)
bool dsragent_require_bi_routes = true;
// do we need to have bidirectional source routes?
// [XXX this flag doesn't control all the behaviors and code that assume
// bidirectional links -dam 5/14/98]

#if 0
bool lsnode_holdoff_rt_reply = true;
// if we have a cached route to reply to route_request with, should we
// hold off and not send it for a while?
bool lsnode_require_use = true;
// do we require ourselves to hear a route requestor use a route
// before we withold our route, or is merely hearing another (better)
// route reply enough?
#endif


About Flow State:

It is also desirable to disable the flow state stuff. it make the dsr code messy. flow state is not an orginal idea.

static const bool dsragent_enable_flowstate = false;
static const bool dsragent_prefer_default_flow = false;

 

About Packet Salvage

it's unknown how to complete disable the packet retransmission in layer 3. Even you change three expressions in dsragent.cc.

  1. salvage_with_cache = false (from true)
  2. salvage_max_request =0 (from 1)
  3. salvage_times = 0 (from 15)

The trace file still show that the routing agent send a undeliverable packet again. See xmitFail() function. I guess, it is necessary to disable "GOD" also.

 

Reference:
Bryan's NS-2 DSR FAQ


 

ns 2 中DSR协议代码 这个资源,对于网络模拟的科研人员很重要.DSR协议是非常经典的源路由协议,是研究的热点之一。 立即下载

相关推荐

DSR 源代码

c++ 实现的DSR源路由动态协议有兴趣的可以共同研究一下

ns2代码分析(一)-数据包指针进入队列

我发现一个现象,也就在中国,会有某某代码分析,某某代码走读。国外似乎就没有这种现象。    没有法子,想在ns2上做点自己东西,不添加C++代码估计是办不到的。之前我分析了quic中一个小仿真器的大致原理[1]。switch对象中的队列长度为什么增长?进的数据包多,而发送数据包少。就是交换机对象的发送队列在每次发包的之后会检测,上次发送数据包需要耗费的时间,就是网卡的处理能力(packet_le

u010643777的专栏 831

DSRSite

DSRSite

DSR源代码分析[转载]

DSR in ns-2Source code :    Not all flies in ./dsr/ directory are used by the ns-2. the routing agent is implemented as Agent/DSRAgent.    Thus, the source codes include:dsragent.cc (h):  DSR agent cl

Beyond Ideas 3233

opnet的dsr源代码.zip_DSR OPNET_仿真代码_协议 源码

基于opnet的动态源路由协议的仿真源码,可以拿去借鉴一下,

【农业生产系统模型】基于R语言APSIM模型进阶应用与参数优化、批量模拟实践技术

APSIM模型有Classic和Next Generation两个系列模型,能模拟几十种农作物、牧草和树木的土壤-植物-大气过程,被广泛应用于精细农业、水肥管理、气候变化、粮食安全、土壤碳周转、环境影响、农业可持续性、农业生态等诸多与农业生产和科研有关的领域。R语言是一门应用场景广泛、简单易学的程序语言,APSIM模型开发了许多R语言辅助包,在APSIM模型的气候、土壤、管理措施等数据准备,自动化模拟,参数优化和结果分析上都发挥着重要的作用。案例一:APSIM模型输入参数和土壤文件的制备。

2303_79243743的博客 1046

NS2中DSR模拟可运行版本 转载

ns2, dsr, multi hop, routing

一心两用 3745

【Matlab 六自由度机器人】基于改进型D-H参数的运动学建模与蒙特卡洛工作空间分析

本文详细介绍了如何使用改进型D-H参数法为六自由度机器人建立运动学模型,并利用Matlab Robotics Toolbox实现正运动学计算与可视化。通过蒙特卡洛法对机器人工作空间进行分析,生成三维点云图以直观展示其可达范围,为机器人选型与任务规划提供关键依据。

weixin_29040367的博客 439

经典源路由协议DSR在NS2中的源码分析

(1) 产生路由请求 当源节点需要与某目的节点进行通信时,它首先在本节点维护的路由缓存中查找是否有到达该目的节点的路由。若路由缓存中已包含了到达该目的节点的有效路由,则立即使用此路由发送数据分组,否则它将向所有邻居广播RREQ(Route Request)分组,以启动一个路由发现过程来找到一条到达该目的节点的可用路由。 由handlePktWithoutSR(SRPacket& p, b

1601

设计一个订单管理系统(OMS)系统100问?

一个完善的订单管理系统不仅仅是简单地记录和处理订单信息,更需要考虑到订单的全生命周期管理,包括订单的创建、支付、配送、售后等环节。这100个问题围绕订单管理系统(OMS)的各个方面展开,涵盖了系统的功能、架构、安全性、异常处理、订单处理流程、支付、库存管理、客户管理、报表与分析等多个方面。通过这些问题,可以全面考虑订单管理系统在设计与实现过程中需要考虑的各种因素,从而确保系统能够满足业务需求、具有良好的性能和稳定性,同时易于扩展、维护和管理。

nbsaas-boot基于Request-Response的企业级快速开发框架 1384

51单片机嵌入式开发:14、STC89C52RC 之HX1838红外解码NEC+数码管+串口打印+LED显示

对于C51单片机的设计思路,你可以使用类似的步骤来实现红外解码、数码管显示和LED显示的功能。下面是一个简单的设计思路:(1) 连接HX1838红外解码器、数码管和LED到C51单片机。将HX1838的信号引脚连接到C51单片机的外部中断引脚(例如INT0),数码管的CLK引脚连接到C51单片机的某个IO口引脚,数码管的DIO引脚连接到C51单片机的另一个IO口引脚,LED连接到C51单片机的某个IO口引脚。(2) 在C51的程序中,定义并初始化所需的IO口和外部中断。

sinat_30943509的博客 2977

DSR源代码分析

Source code :    Not all flies in ./dsr/ directory are used by the ns-2. the routing agent is implemented as Agent/DSRAgent.    Thus, the source codes include: dsragent.cc (h):  DSR agent class

yaoyaoruirui的专栏 1552

车载网络测试实操源码_使用CAPL脚本进行UDS刷写及其自动化测试

本文主要讲解如何使用CAPL脚本进行UDS刷写及其自动化测试,并结合了几个测试实例进行介绍,希望对大家有所帮助。

文章主要涉及嵌入式软件开发、测试、项目管理等,欢迎交流,共同进步。 1554

NS2中的DSR分析

Source code :     Not all flies in ./dsr/ directory are used by the ns-2. the routing agent is implemented as Agent/DSRAgent.     Thus, the source codes include: dsragent.cc (h):  DSR agent cla

norbert.jiang的专栏 1990

5.17华为OD机试真题 新系统 - 输出二叉树后序遍历结果 (Java/Py/C/C++/Js/Go)

5.17华为OD机试真题 新系统 - 输出二叉树后序遍历结果 (Java/Py/C/C++/Js/Go)

算法大师! 519

基于pytorch cnn ResNets卷积网络的模糊图像检测 完整代码数据直接运行

基于pytorch cnn ResNets卷积网络的模糊图像检测 完整代码数据直接运行

730

NS2学习之NS2简介

因为毕业设计要用NS2进行仿真,加上以后要研究的方向也决定了自己要学习NS2。现将自己的学习过程记录下来。NS2简介:NS2是指 Network Simulator version 2,NS(Network Simulator) 是一种针对网络技术的源代码公开的、免费的软件模拟平台,研究人员使用它可以很容易的进行网络技术的开发,而且发展到今天,它所包含的模块几乎涉及到了网络技术的所有方面。所以,N...

飞鱼的博客 5792

对角两对双差速轮AGV的平移、直行、转弯和原地旋转之PID控制

本示例将展示如何使用PID控制算法,控制具有对角线布置的两对双差速轮(左前和右后)的AGV,实现平移、直行、转弯和原地旋转等运动。通过对车辆的运动学和PID控制器的设计,我们可以精确地控制AGV的运动

xiaoc100200的博客 1511

NS2 Data Collections by mitkook

原发表在偶的Opera Blog: http://my.opera.com/mitkook/blog/show.dml/354188Collected by mitkook!NS2在Windows下的安装,参看该页面(最好Cygwin也在此页面上下载):http://140.116.72.80/~smallko/ns2/setup_en.htm有什么疑问多看看这个论坛上的帖子:http://w

MiTKooK's Tech Log 3399

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

[转]NS2 Data Collections by mitkook

原发表在偶的Opera Blog: http://my.opera.com/mitkook/blog/show.dml/354188 Collected by mitkook! NS2在Windows下的安装,参看该页面(最好Cygwin也在此页面上下载): http://140.116.72.80/~smallko/ns2/setup_en.htm 有什么疑问多看看这个论坛上的帖子: http://www.netforum.com.cn/default.asp 建议初学者先看这

jianwushuang的专栏 725

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

ns2的下载资源综合zz

 1、NS与网络模拟电子版 http://www.baisi.net/viewthread. ... %26amp%3Btypeid%3D22、NS软件包在Windows XP下的详细安装过程(多图,lynn友情提供) http://www.baisi.net/viewthread. ... %26amp%3Btypeid%3D23、一款强大的代码阅读器source insight http:

2796

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

ns3脚本first.cc的分析

转载博文:https://blog.youkuaiyun.com/tttabcgy/article/details/77295201 3.2 分析例子程序first.cc的源代码 进入ns-3.15/examples/tutorial目录。你会发现一个叫first.cc的文件。这一个脚本会在两个节点间创建一个简单的点到点的连接,并且在这两个节点之间传送一个数据包。为方便后续分许,先将first.cc的源代...

mniyinting的博客 507

ns2的下载资源

ns2的下载资源 1、NS与网络模拟电子版 http://www.baisi.net/viewthread. ... &typeid=2 2、NS软件包在Windows XP下的详细安装过程(多图,lynn友情提供) http://www.baisi.net/viewthread. ... &typeid=2 3、一款强大的代码阅读器source insight http

nuistlr的专栏 669

NS各种常用资料

<br />原文来自于: http://www.netforum.com.cn/forum_posts.asp?TID=9306&PN=1<br />(一). NS常用基本网站<br />  1. Maillist个人觉得是寻求问题答案最好的地方。<br />http://mailman.isi.edu/pipermail/ns-users/<br />  2. 柯老师的网站,包含很多非常实用资源:安装,trace文件分析,源代码分析,添加新协议的途径等<br />http://140.116.72.80/

jianwushuang的专栏 1422

ns2_相关资料大全

1、NS与网络模拟电子版 http://www.baisi.net/viewthread. ... %26amp%3Btypeid%3D2 2、NS软件包在Windows XP下的详细安装过程(多图,lynn友情提供) http://www.baisi.net/viewthread. ... %26amp%3Btypeid%3D2 3、一款强大的代码阅读器source insight

梦之境 1023
上一篇: [ZZ]NS代码架构分析
下一篇: [ZZ]NS编程与调试 - gdb调试工具
leonsc
博客等级 码龄18年 29粉丝 22原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值