Jul 18, 2013

Add a new MAC protocol in NS2

I just install the NS2 in my machine. If you are not sure, please read:
http://itantenna.blogspot.com.au/2012/01/install-ns234-on-ubuntu-1004.html;
http://itantenna.blogspot.com.au/2011/11/install-ns21b9a-tens-in-ubuntu-1004.html;
http://itantenna.blogspot.com.au/2010/10/ns2macintosh.html;
Now let`s add a new MAC protocol.
1) Put your new MAC program files (newMAC.cc and newMAC.h) to ns-2.34/mac
2) Modify common/packet.h
#define HDR_NEWMAC(p) ((hdr_newmac *)hdr_mac::access(p)) // add newmac here
Find "enum packet_t{}" and add PT_NEWMAC. Notice that it must be added before PT_NTYPE.
Find "class p_info{}" and add name_[PT_NEWMAC] = "newmac". It must be before name_[PT_NTYPE] = "undefined".
3) Modify tcl/lib/ns-default.tcl
Add Mac/NEWMAC set syncFlag_ 1
Add Mac/NEWMAC set selfConfigFlag_ 1
Add Mac/NEWMAC set dutyCycle_ 10
……
In the later line,
Add Mac/NEWMAC set syncFlag_ 0
4) Modify tcl/lib/ns-packet.tcl
Find "foreach prot{}" and add NEWmac
5) Modify ns2.34/Makefile
Add mac/newmac.o \
6) Now a new MAC protocol has been added to NS2. We will modify some trace files in the next.
7) Modify trace/cmu-trace.h
Add void format_newmac(Packet *p, int offset);
8) Modify trace/cmu-trace.cc
Find "void CMUTrace::format_mac_common(Packet *p, const char *why, int offset)"
struct hdr_cmn *ch = HDR_CMN(p);
struct hdr_ip *ih = HDR_IP(p);
struct hdr_mac802_11 *mh;
struct hdr_smac *sh;
struct hdr_newmac *ph; // add newmac pointer
char mactype[SMALL_LEN];
strcpy(mactype, Simulator::instance().macType());
if (strcmp (mactype, "Mac/SMAC") == 0)
sh = HDR_SMAC(p);
else if (strcmp (mactype,"Mac/NEWMAC") == 0)
ph = HDR_LMAC(p);
else
mh = HDR_MAC802_11(p);
……
if (strcmp (mactype, "Mac/SMAC") == 0) {
format_smac(p, offset);
}
else if (strcmp (mactype, "Mac/NEWMAC") == 0) {
format_newmac(p, offset);
}
else {
format_mac(p, offset);
}
return;
Find "if(newtrace)"
offset = strlen(pt_->buffer());
if (strcmp(mactype, "Mac/SMAC") == 0) {
format_smac(p, offset);
}
else if (strcmp(mactype, "Mac/NEWMAC") == 0) {
format_newmac(p, offset);
}
else {
format_mac(p, offset);
}
……
(ch->ptype() == PT_SMAC) ? (
(sh->type == RTS_PKT) ? "RTS" :
(sh->type == CTS_PKT) ? "CTS" :
(sh->type == ACK_PKT) ? "ACK" :
(sh->type == SYNC_PKT) ? "SYNC" :
"UNKN") :
(ch->ptype() == PT_NEWMAC) ? (
(ph->type == RTS_PKT) ? "RTS" :
(ph->type == CTS_PKT) ? "CTS" :
(ph->type == ACK_PKT) ? "ACK" :
(ph->type == SYNC_PKT) ? "SYNC" :
"UNKN") :
packet_info.name(ch->ptype())),
ch->size());
……
if (strncmp (mactype, "Mac/SMAC", 8) == 0) {
format_smac(p, offset);
}
else if (strncmp (mactype, "Mac/NEWMAC", 8) == 0) {
format_newmac(p, offset);
}
else {
format_mac(p, offset);
}
……
Add a new function
void CMUTrace::format_newmac(Packet *p, int offset)
{
struct hdr_newmac *ph = HDR_NEWMAC(p);
sprintf(pt_->buffer() + offset,
" [%.2f %d %d] ",
ph->duration,
ph->dstAddr,
ph->srcAddr);
}
9) Find "void CMUTrace::format(Packet* p, const char *why)"
Add
switch(ch->ptype()) {
case PT_MAC:
case PT_SMAC:
case PT_NEWMAC:
break;
case PT_ARP:
format_arp(p, offset);
break;
10) Finally, add the header files #include

10 comments:

  1. hi,
    I think we need to write a tcl script to map(call) the apis of newmac.cc file, otherthan simulation tcl script. If it is not so, then how to call the functions in newmac.cc file

    Thanks

    ReplyDelete
    Replies
    1. right, the third step: Modify tcl/lib/ns-default.tcl and forth step: Modify tcl/lib/ns-packet.tcl are doing this mapping

      Delete
    2. Hey I have added new mac protocol as MMAC but getting below error while running

      invalid command name "Mac/MMAC"
      while executing
      "Mac/MMAC create _o48 "
      invoked from within
      "catch "$className create $o $args" msg"
      invoked from within
      "if [catch "$className create $o $args" msg] {
      if [string match "__FAILED_SHADOW_OBJECT_" $msg] {
      delete $o
      return ""
      }
      global errorInfo
      error "class $..."
      (procedure "new" line 3)
      invoked from within
      "new $mactype"
      (procedure "_o43" line 10)
      (Node/MobileNode add-interface line 10)
      invoked from within
      "$node add-interface $chan($i) $propInstance_ $llType_ $macType_ $ifqType_ $ifqlen_ $phyType_ $antType_ $topoInstance_ $inerrProc_ $outerrProc_ $FECP..."
      (procedure "_o22" line 87)
      (Simulator create-wireless-node line 87)
      invoked from within
      "_o22 create-wireless-node"
      ("eval" body line 1)
      invoked from within
      "eval $self create-wireless-node $args"
      (procedure "_o22" line 23)
      (Simulator node line 23)
      invoked from within
      "$ns node"

      Delete
    3. Sydney Cyber Army: Add A New Mac Protocol In Ns2 >>>>> Download Now

      >>>>> Download Full

      Sydney Cyber Army: Add A New Mac Protocol In Ns2 >>>>> Download LINK

      >>>>> Download Now

      Sydney Cyber Army: Add A New Mac Protocol In Ns2 >>>>> Download Full

      >>>>> Download LINK Ow

      Delete
  2. How cal we change mac address of the node. random with dynamic change in mac..

    ReplyDelete
  3. can you provide more detail approach to this.

    ReplyDelete
    Replies
    1. It's possible to changing mac address of nodes with periods of time. ie Dynamic MAC address allocation of nodes.

      Delete
    2. Yes, I think it could be possible. But you need to define a scheme to notify the other sender or receiver

      Delete
  4. this post is really helpful but when after I configure and make successfully when I run tcl script to evaluate the performance of newmac it will return the same value as mac802_11. it seems to me the new mac is using mac802_11 internally. could you please help me to fix this issue?

    ReplyDelete
  5. Sydney Cyber Army: Add A New Mac Protocol In Ns2 >>>>> Download Now

    >>>>> Download Full

    Sydney Cyber Army: Add A New Mac Protocol In Ns2 >>>>> Download LINK

    >>>>> Download Now

    Sydney Cyber Army: Add A New Mac Protocol In Ns2 >>>>> Download Full

    >>>>> Download LINK x0

    ReplyDelete