Thursday, July 9, 2009

[AIT09] Addressing in NS2

This question is from our friend Hasanain.

The question is
  1. What is the address format in NS2?
  2. Where do we store (IP) address?
  3. How do we store the IP address? (using what function or instproc?)
Any comments?

13 comments:

Unknown said...

NS2 nodes have hirearchichal addressing scheme which is similar to IP adderss but it is not the same. When using trace-all in NS2, a trace string is created in a trace file.it also have source and destination addresses.

The structhdr_ip, IP packet header contains information about source and destination of a packet.NS2 utilizes data type ns_addr_t defined in file ˜ns/config.h to store node address. ns_addr_t is a struct data type, which contains two members: addr_ and port_. Both members are of type int32_t, which is simply an alias for int data type and file ˜ns/autoconf-win32.h. While addr_ specifies the node address, port_ identifies the attached port The variables src_ and dst_ of IP header are of class ns_addr_t. Hence, src_.addr_ and src_.port_ store the node address and the port of the sending agent, respectively. Similarly, the packet will be sent to a receiving agent attached to port dst_.port_ of a node with address dst_.addr_. function offset(off) and function access(p), which are essential to access IP header of a packet.

Tech News said...

Thein Tun Aung/ st108032
The MacClassifier class extends the Classifier class to implement a simple broadcasting mechanism. It modifies
the recv() method in the following way: since the replication of a packet is expensive, normally a unicast packet will
be classified by the MAC destination address macDA_ and delivered directly to the MAC object with such an address.
However, if the destination object cannot be found or if the MAC destination address is explicitly set to the broadcast address
BCAST_ADDR, the packet will be replicated and sent to allMACs on the lan excluding the one that is the source of the packet.
Finally, by setting the bound variable MacClassifier::bcast_ to a non–zero value, will cause MacClassifier
always to replicate packets.

When a Mac object receives a packet via its recv() method, it checks whether the packet is outgoing or incoming. For
an outgoing packet, it assumes that the link-layer of the sender has obtained the destination MAC address and filled in the
macDA_ field of theMAC header, hdr_mac. The Mac object fills in the rest of theMAC headerwith the sourceMAC address
and the frame type. It then passes the packet to its send() method, which carries out the medium access protocol.

Tech News said...

Thein Tun Aung / St108032

The address space consists of 2 parts, the node-id and the port-id. The higher bits are assigned as the node’s address or id_ and remaining lower bits are assigned to form port-id or the identification of the agent attached to the node. Of the higher bits, 1 bit is assigned for multicast. The address space consists of 32 bits and port id space consists of 32 bits as well. The
higher 32 bits for node-id, the MSB for multicast and the lower 32 bits for port-id.

These default and maximum address sizes are defined in ~ns//tcl/lib/ns-default.tcl.

Unknown said...

"NS2 nodes have hirearchichal addressing scheme which is similar to IP adderss but it is not the same." I need to do some work on standard IPv4 header, and I need these fields such as "Flags", " Fragment Offset", but they do not seem exist in NS2. How I have a standard IPv4 header?

Unknown said...

In NS 2.34, HDR_IP_LEN is defined as 20, and the size of struct hdr_ip is 24bytes see below. Why do they not match?
struct hdr_ip { /* common to IPv{4,6} */
ns_addr_t src_; -------------8
ns_addr_t dst_; -------------16
int ttl_; -------------18
/* IPv6 */
int fid_; - ------------20
/* flow id */
int prio_; -------------22
static int offset_; -------------24

z3d said...

@ Susan that is probably because the size specified in the cmn_hdr is not he actual size in bits for the sim header but is for calculation purposes only. i.e. to do calculations that conform with real world and has nothing to do with the sizeof(hdr_ip)

malshing said...

how to use the specific hierarchical address format.

from the manual it has this syntax:
$ns set-address-format hierarchical <#n hierarchy levels> <#bits for level1> <#bits for level 2> ....<#bits for nth level>

so i followed that and i wrote in my tcl script:
$ns_ set-address-format hierarchical 4 8 8 8 8

and when i created the nodes i have
set temp {0.0.0.0 0.0.0.1 0.0.0.2 }
for {set i 0} {$i < $val(nn) } {incr i} {
set node_($i) [$ns_ node [lindex $temp $i] ]
$node_($i) random-motion 0
}

however, the messages now are dropped once they reached the destination.
here is a part from the tracing file:

r 4.613981632 _2_ RTR --- 4 SIP_200 270 [13a 2 1 800] ------- [0.0.0.1:0 0.0.0.2:0 30 0.0.0.2]
D 4.613981632 _2_ RTR NRTE 4 SIP_200 270 [13a 2 1 800] ------- [0.0.0.1:0 0.0.0.2:0 29 0.0.0.2]


also when i do "cout" of the node address as following
iph->daddr() = shv->node_;

where node_ is of nsaddr_t i get 512 0r 256 instead of of 0.0.01 for example.

also i noticed that RTR is forwarding the messages instead of sending them .
what should i do to fix this problem? do I need to change any thing in the routing protocol?
basically what i am trying to achieve is given each node an ipv4 alike address format.

Anonymous said...

1.how can i configure IP address on ns2 node.
2.how can i configure IPSec on the channel between nodes using IPv4.
3.how can i configure IPSec on the channel between two nodes using IPv6

Teerawat Issariyakul said...

I have not used IP Address in NS2. But here is the addressing mechanism in NS2:

http://www.ns2ultimate.com/post/1196152906/address-and-ip-routing-in-ns2

Anonymous said...

In wired topology, how to node id for a certain node .

I have create an algorithm in c++ and I have put my code in droptail.cc.

Basically, I'm performing my code for any enqueue packet. part of my code to check the current node id. I have tried the following:
Node*nd=Node::get_node_by_address(2)
when I put :
int nodeNow=nd->address_ I got segmentatoin fault(core dump)
if comment the above line and print
nd value I'm getting high numbers
printf("node %d\n",nd)
I know you would say %d for integer but I tried every other way ...I couldn't... Any suggestions!!!!

Unknown said...

sir can you provide the detailed procedure to add a new MAC protocol to the NS2.

Unknown said...

How to print Wireless link sending and receiving nodes and bytes of data transfered ns2

Unknown said...

Please could you guide me on how to broadcast a packet over a wired-cum wireless network. What should I put as dst_addr()?
Thank you
regards