/**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 on
$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_;