NS2 结点地址映射关系

/**OTCL操作

/**

在Ns2中创建节点后,会依照其创建关系为其分配一个ID号

Node set nn_ 0
Node proc getid {} {
 set id [Node set nn_]
 Node set nn_ [expr $id + 1] ;#递增
 return $id
}

地址则要区分为分层地址以及非分层地址进行处理

if {[llength $args] != 0} {
  set address_ [lindex $args 0] ;#the hierarchical address
 } else {
  set address_ $id_
 }
 $self cmd addr $address_; # Propagate address_ into C++ space

 

 /**C++操作

/**

//节点mac地址。Mac.cc

static int MacIndex = 0;

index_ = MacIndex++;(mac)

 

//节点地址

if {[llength $args] != 0} {

set address_ [lindex $args 0] ;#the hierarchical address

} else {

set address_ $id_

}

$self cmd addr $address_; # Propagate address_ into C++ space

 

//节点agent地址(当在节点上attach了一个agent后,就会将node的address_赋值给该agent的here_地址,agent在实际的帧传输时再将其封装到ip头中)

Node instproc attach { agent { port "" } } {

$self instvar agents_ address_ dmux_

#

# Assign port number (i.e., this agent receives

# traffic addressed to this host and port)

#

lappend agents_ $agent

#

# Attach agents to this node (i.e., the classifier inside).

# We call the entry method on ourself to find the front door

# (e.g., for multicast the first object is not the unicast classifier)

#

# Also, stash the node in the agent and set the local addr of

# this agent.

#

$agent set node_ $self

$agent set agent_addr_ [AddrParams addr2id $address_]

#

# If a port demuxer doesn't exist, create it.

#

if { $dmux_ == "" } {

# Use the default mask_ and port_ values

set dmux_ [new Classifier/Port]

# point the node's routing entry to itself

# at the port demuxer (if there is one)

$self add-route $address_ $dmux_

}

if { $port == "" } {

set port [$dmux_ alloc-port [[Simulator instance] nullagent]]

}

$agent set agent_port_ $port

 

$self add-target $agent $port

}

 

//节点agent向ip地址映射转换

hdr_ip* iph = hdr_ip::access(p);

iph->saddr() = here_.addr_;

iph->sport() = here_.port_;

iph->daddr() = dst_.addr_;

iph->dport() = dst_.port_;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值