Skip to content

​​​​​​​Implementing a 3D UWSN Localization Algorithm in ns-2-Aquasim

This article addresses some of the obstacles that one should pass before trying to implement a custom 3D version of any localization algorithm under ns-2-Aquasim.

Of course, this installation or patching procedure is based on the one provided by Anabel Pineda Briseño1, a former PhD. Student of Computer Science, Computer Research Center, Mexican National Polytechnic Institute, Mexico City, Mexico.

In fact, such patching procedures are nothing but a standard way of incorporating a routing protocol with ns-2. So if one understands how a routing protocol is integrated with ns-2, then it will be easy for them to successfully repeat this procedure.

Since we are going to implement a 3D version of DV-Hop algorithm under the Aquasim version of ns-2, this procedure is entirely different from all other previous procedures that you may see in previous research works.

As far as I know, this article is the very first attempt of using a ‘real’ localization algorithm under the ns-2 version of Aquasim UWSN simulation.

Important Note: This article is nothing but a log of my own experiments on Aquasim. Further, this article is not meant for those who are just viewing the public part of this article.

Some Technical Aspects that Should be Addressed:

  • The previous implementations of the localization algorithm (including dv-hop) are only implemented on standard wireless networking technology. So, they simply will not work under an acoustic underwater network.
  • Generally, the previous implementations of localization algorithms were made to work on a physical medium model such as  WirelessPhy of ns-2. But,  under UWSN, we need to make it work on the physical medium model  UnderwaterPhy of Aquasim.
  • Under a normal wireless scenario, a propagation model such as  TwoRayGround  or  Durkin’s propagation will be used. But, under UWSN, we need to use UnderwaterPropagation of Aquasim.
  • 802_11 Mac is generally used in all the previous examples of localization algorithms. But, we have to make a localization algorithm to work on BroadcastMac of Aquasim.
  • Since the previous implementations are implemented as a ‘dummy’ routing protocol, they handled the link layer and port demultiplexer in a different way.  To make the localization algorithm to work under a UWSN, we have to ‘handle’ the interfaces of LL and Port_Demux  as per the way in which Aquasim is handling them. In fact, it is the most important part of this new design. Otherwise, the packets transmitted by a localization node could not be actually transmitted or received by other nodes.

Note :

The main components and the logic of the dvhop3d localization protocol have been implemented in the following three files:

  • dvhop.cc,
  • dvhop.h,
  • dvhop_packet.h

As per the original procedure, we are going to modify the following files to incorporate dvhop3d as a dummy routing protocol module under ns-2.

  • $NS_ROOT/Makefile
  • $NS_ROOT/queue/priqueue.cc
  • $NS_ROOT/common/packet.h
  • $NS_ROOT/trace/cmu-trace.h
  • $NS_ROOT/trace/cmu-trace.cc
  • $NS_ROOT/tcl/lib/ns-packet.tcl
  • $NS_ROOT/tcl/lib/ns-lib.tcl
  • $NS_ROOT/tcl/lib/ns-agent.tcl
  • $NS_ROOT/tcl/lib/ns-mobilenode.tcl

For installing Aquasim under ns-2, one may see the following articles[2]:

Installing Aquasim & Aqua3D on an old Linux under VirtualBox

 

So, I assume that the reader already installed a working version of Aquasim as explained in the above procedure and having it ready for further experiments.

 

Step 1: Prepare a Folder for your new Routing Agent

 

Hidden Section! Contact Charles  

The key/passphrase will be given once you have been approved for getting paid research support/assistance from Charles. To get paid support, you may start a 'free' research discussion.  

WhatsApp chatDiscuss Through WhatsApp
 

Step 3: Edit priqueue.cc file

Add the following lines to /home/yourhome/aquasim/ns-2.30/queue/priqueue.cc (see line 94)

 

// DVHop patch
case PT_DVHOP:

Step 4: Edit packet.h file

 

Add the following lines to /home/yourhome/aquasim/ns-2.30/common/packet.h. (see line 204)

 

// 3DVHOP packet
PT_DVHOP,

Add the following lines in the same file /home/yourhome/aquasim/ns-2.30/common/packet.h.(see the line 332)

 

// 3D DVHop patch
name_[PT_DVHOP] = "DVHOP";

 

Step 5: Edit cmutrace.h and cmutrace.cc files

 

Add the following lines to /home/yourhome/aquasim/ns-2.30/trace/cmu-trace.h. (see line 138)

// 3DVHOP Patch
void format_dvhop(Packet *p, int offset);

Add the following lines to /home/yourhome/aquasim/ns-2.30//trace/cmu-trace.cc. (see line 929)

// DVHop patch
void
CMUTrace::format_dvhop(Packet *p, int offset)
{
       struct hdr_dvhop *wd = HDR_DVHOP(p);
       struct hdr_dvhop_beacon *bcn = HDR_DVHOP_BEACON(p);
       struct hdr_dvhop_hopsize *dhs = HDR_DVHOP_HOPSIZE(p);

   switch(wd->pkt_type) {
              case DVHOP_BEACON:
                     if (pt_->tagged()) {
                            sprintf(pt_->buffer() + offset,
                                              "-dvhop:t %x -dvhop:h %d -dvhop:b %d -
                     dvhop:s %d"
                                              "-dvhop:px %f -dvhop:py %f -dvhop:pz %f
                     -dvhop:ts %f "
                                              "-dvhop:c BEACON ",
                                              bcn->pkt_type,
                                              bcn->beacon_hops,
                                              bcn->beacon_id,
                                              bcn->beacon_anchor,
                                              bcn->beacon_posx,
                                              bcn->beacon_posy,
                                        bcn->beacon_posz,
                                              bcn->timestamp);
                          }  else if (newtrace_) {

                           sprintf(pt_->buffer() + offset,
                    "-P dvhop -Pt 0x%x -Ph %d -Pb %d -Ps %d -
                    Ppx %f -Ppy %f -Ppz %f -Pts %f -Pc BEACON ",
                                             bcn->pkt_type,
                                             bcn->beacon_hops,
                    bcn->beacon_id,
                    bcn->beacon_anchor,
                    bcn->beacon_posx,
                    bcn->beacon_posy,
                                     bcn->beacon_posz,
                    bcn->timestamp);
    
                       }else {

                        sprintf(pt_->buffer() + offset,
                     "[0x%x %d %d %d [%f %f %f] %f]] (BEACON)",
                                               bcn->pkt_type,
                                               bcn->beacon_hops,
                                               bcn->beacon_id,
                                               bcn->beacon_anchor,
                                               bcn->beacon_posx,
                                               bcn->beacon_posy,
                                        bcn->beacon_posz,
                     bcn->timestamp);
                       }
           break;
               case DVHOP_HOPSIZE:
                     sprintf(pt_->buffer() + offset,"-dvhop:t %x -dvhop:b %d
          -dvhop:s %d "
                                     "-dvhop:hs %f -dvhop:ts %f "
                                     "-dvhop:c HOPSIZE",
                                     dhs->pkt_type,
                                     dhs->hopsize_id,
                                     dhs->hopsize_anchor,
                                     dhs->hopsize_hs, 
                                     dhs->timestamp);
              }
                 else if (newtrace_) {

                     sprintf(pt_->buffer() + offset, "-P dvhop -Pt 0x%x -Pb 
          %d -Ps %d -Phs %f -Pts %f -Pc HOPSIZE ",
                                     dhs->pkt_type,
                                     dhs->hopsize_id,
                                     dhs->hopsize_anchor,
                                     dhs->hopsize_hs,
                                     dhs->timestamp);
              } else {

                    sprintf(pt_->buffer() + offset, "[0x%x %d %d %f %f] 
         (HOPSIZE)",
                                     dhs->hopsize_id,
                                     dhs->hopsize_anchor,
                                     dhs->hopsize_hs,
                                    dhs->timestamp);
               }
                break;
               default:
#ifdef WIN32
              fprintf(stderr, "CMUTrace::format_dvhop: invalid  
              DVHOP packet type\n");
#else
              fprintf(stderr,"%s: invalid DVHOP packet type\n",
              __FUNCTION__);
#endif
              abort();
   }
}

 

 

Step 6: Edit ns-packet.tcl file

Add the following lines to /home/yourhome/aquasim/ns-2.30/tcl/lib/ns-packet.tcl (see line 185)

 

# 3D DVHOP patch 
DVHOP

 

Step 7: Edit ns-lib.tcl file

Add the following lines to /home/yourhome/aquasim/ns-2.30/tcl/lib/ns-lib.tcl (see line 662)

 

# 3D DVHOP patch 
DVHOP {
set ragent [$self create-dvhop-agent $node]
}

 

 

Add the following lines to  the same file /home/yourhome/aquasim/ns-2.30/tcl/lib/ns-lib.tcl (see line 918)

 

# 3D DVHOP patch 
Simulator instproc create-dvhop-agent { node } {
# Create 3D DVHOP routing agent
set ragent [new Agent/DVHOP [$node node-addr]]
$self at 0.0 "$ragent start"
$node set ragent_ $ragent
return $ragent
}

 

 

Step 8: Edit ns-agent.tcl file

Add the following lines to /home/yourhome/aquasim/ns-2.30/tcl/lib/ns-agent.tcl see line 204)

 

# 3D DVHOP patch 
Agent/DVHOP instproc init args {
   $self next $args 
}

 

 

Step 9: Edit ns-mobilenode.tcl file

Add the following lines to /home/yourhome/aquasim/ns-2.30/tcl/lib/ns-mobilenode.tcl see line 204)

 

//Special processing for DVHOP  
set dvhoponly [string first "DVHOP" [$agent info class]]
if {$dvhoponly != -1 } {
   $agent if-queue [$self set ifq_(0)] ;# ifq between LL and MAC
}

Change

//Special processing for DVHOP

as

#Special processing for DVHOP

Step 10: Recompile ns-2

$ cd /home/yourhome/aquasim/ns-2.30/
$ make clean
$ make
Propably it will endup with the following error:
Correct the error as follows:

Hidden Section! Contact Charles  

The key/passphrase will be given once you have been approved for getting paid research support/assistance from Charles. To get paid support, you may start a 'free' research discussion.  

WhatsApp chatDiscuss Through WhatsApp
 

If we compile it again, probably it will end with the following errors:
We have to correct this error as follows:

Hidden Section! Contact Charles  

The key/passphrase will be given once you have been approved for getting paid research support/assistance from Charles. To get paid support, you may start a 'free' research discussion.  

WhatsApp chatDiscuss Through WhatsApp
 

// DVHop patch
void
CMUTrace::format_dvhop(Packet *p, int offset)
{
       struct hdr_dvhop *wd = HDR_DVHOP(p);
       struct hdr_dvhop_beacon *bcn = HDR_DVHOP_BEACON(p);
       struct hdr_dvhop_hopsize *dhs = HDR_DVHOP_HOPSIZE(p);

   switch(wd->pkt_type) {
              case DVHOP_BEACON:
                     if (pt_->tagged()) {
                            sprintf(pt_->buffer() + offset,
                                              "-dvhop:t %x -dvhop:h %d -dvhop:b %d - dvhop:s %d"
                                              "-dvhop:px %f -dvhop:py %f -dvhop:pz %f -dvhop:ts %f "
                                              "-dvhop:c BEACON ",
                                              bcn->pkt_type,
                                              bcn->beacon_hops,
                                              bcn->beacon_id,
                                              bcn->beacon_anchor,
                                              bcn->beacon_posx,
                                              bcn->beacon_posy,
                                        bcn->beacon_posz,
                                              bcn->timestamp);
                          }  else if (newtrace_) {

                           sprintf(pt_->buffer() + offset,
                    "-P dvhop -Pt 0x%x -Ph %d -Pb %d -Ps %d - Ppx %f -Ppy %f -Ppz %f -Pts %f -Pc BEACON ",
                                             bcn->pkt_type,
                                             bcn->beacon_hops,
                    bcn->beacon_id,
                    bcn->beacon_anchor,
                    bcn->beacon_posx,
                    bcn->beacon_posy,
                                     bcn->beacon_posz,
                    bcn->timestamp);
    
                       }else {

                        sprintf(pt_->buffer() + offset,
                     "[0x%x %d %d %d [%f %f %f] %f]] (BEACON)",
                                               bcn->pkt_type,
                                               bcn->beacon_hops,
                                               bcn->beacon_id,
                                               bcn->beacon_anchor,
                                               bcn->beacon_posx,
                                               bcn->beacon_posy,
                                        bcn->beacon_posz,
                     bcn->timestamp);
                       }
           break;
               case DVHOP_HOPSIZE:
                     else if (newtrace_) {
                     sprintf(pt_->buffer() + offset,"-dvhop:t %x -dvhop:b %d -dvhop:s %d "
                                     "-dvhop:hs %f -dvhop:ts %f "
                                     "-dvhop:c HOPSIZE",
                                     dhs->pkt_type,
                                     dhs->hopsize_id,
                                     dhs->hopsize_anchor,
                                     dhs->hopsize_hs, 
                                     dhs->timestamp);
              }
                 else if (newtrace_) {

                     sprintf(pt_->buffer() + offset, "-P dvhop -Pt 0x%x -Pb %d -Ps %d -Phs %f -Pts %f -Pc HOPSIZE ",
                                     dhs->pkt_type,
                                     dhs->hopsize_id,
                                     dhs->hopsize_anchor,
                                     dhs->hopsize_hs,
                                     dhs->timestamp);
              } else {

                    sprintf(pt_->buffer() + offset, "[0x%x %d %d %f %f] (HOPSIZE)",
                                     dhs->hopsize_id,
                                     dhs->hopsize_anchor,
                                     dhs->hopsize_hs,
                                    dhs->timestamp);
               }
                break;
               default:
#ifdef WIN32
              fprintf(stderr, "CMUTrace::format_dvhop: invalid DVHOP packet type\n");
#else
              fprintf(stderr,"%s: invalid DVHOP packet type\n",
              __FUNCTION__);
#endif
              abort();
   }
}

 

Now compile again
$ make
At last, the ns-2 has been successfully compiled with aquasim extension and the dvhop3d localization extension. The following screen shows the sign of success :

 

Step 11: Running a Localization Example Scenario

The default example simulations (dvhop_802_11.tcl) provided by the authors of dvhop will not at all work here. The reasons are:  here we need to use an underwater mac protocol. Further, the we need to use the underwater propagation model of aquasim. The following is the simple, modified simulation example that will work in this underwater network scenario.

Hidden Section! Contact Charles  

The key/passphrase will be given once you have been approved for getting paid research support/assistance from Charles. To get paid support, you may start a 'free' research discussion.  

WhatsApp chatDiscuss Through WhatsApp
 

If we try to run any example simulation that is given, then we may end with the following error:

 

Try to correct it as follows:

Hidden Section! Contact Charles  

The key/passphrase will be given once you have been approved for getting paid research support/assistance from Charles. To get paid support, you may start a 'free' research discussion.  

WhatsApp chatDiscuss Through WhatsApp
 

Now if we try to run the example, then it will run; but will end with a ‘core dumped‘ error as follows :

 

The reason for this error is: the implemented localization algorithm is unable to transmit even a single packet.

As I mentioned earlier, the previous implementations of the localization algorithm is implemented as a ‘dummy’ routing protocol. They handled the link layer and port demultiplexer in a different way.  To make the localization algorithm work under a UWSN, we have to ‘handle’ the interfaces of LL and Port_Demux  as per the way in which Aquasim is handling them.

So, to make it work, we have to implement something inside the previous code framework. In fact, it is the most important part of this new design. Otherwise, the packets transmitted by a localization node could not be actually transmitted or received by other nodes.

Further, if we wish to incorporate routing logic inside this ‘dummy’ routing agent code and wish to make it as a working routing protocol, then without the following modifications, it will not be possible:

Hidden Section! Contact Charles  

The key/passphrase will be given once you have been approved for getting paid research support/assistance from Charles. To get paid support, you may start a 'free' research discussion.  

WhatsApp chatDiscuss Through WhatsApp
 

 

After all the above modifications and inclusions, the dvhop localization example successfully run and end without any error.

 

 

Conclusion

At last, after a lot of effort and understanding, we have successfully implemented a localization algorithm under UWSN using the Aquasim extension. The simple example scenario that we used here is not sufficient to explore the capability of the localization algorithm further. So, to really test its good working and to evaluate the localization performance, we will need a more suitable underwater network scenario.

Further, if we wish to incorporate routing logic inside this ‘dummy’ routing agent code and wish to make it a working routing protocol, then we have to do a lot of additional things inside this code. Then only it will become a full-fledged, localization-based, acoustic, underwater routing protocol.  We may address those issues in another article.

References

Hidden Section! Contact Charles  

The key/passphrase will be given once you have been approved for getting paid research support/assistance from Charles. To get paid support, you may start a 'free' research discussion.  

WhatsApp chatDiscuss Through WhatsApp
 

WhatsApp Discuss Through WhatsApp