wirelessch-dumb.cc

00001 /*
00002  * Copyright (c) 2007 Regents of the SIGNET lab, University of Padova.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the University of Padova (SIGNET lab) nor the 
00014  *    names of its contributors may be used to endorse or promote products 
00015  *    derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00018  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 
00019  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
00020  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
00021  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00022  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00023  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
00024  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
00025  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
00026  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
00027  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 
00031 #include "wirelessch-dumb.h"
00032 
00033 static class DumbWirelessChModuleClass : public TclClass {
00034 public:
00035         DumbWirelessChModuleClass() : TclClass("Module/DumbWirelessCh") {}
00036         TclObject* create(int, const char*const*) {
00037         return (new DumbWirelessChModule());
00038 
00039 }
00040 } class_wirelesschdumbmodule;
00041 
00042 DumbWirelessChModule::DumbWirelessChModule() : ChannelModule()
00043 {
00044         bind_bool("usePropagationDelay_", &usePropagationDelay_);
00045 }
00046 
00047 DumbWirelessChModule::~DumbWirelessChModule()
00048 {
00049 }
00050 
00051 
00052 
00053 int DumbWirelessChModule::command(int argc, const char*const* argv)
00054 {
00055         //Tcl& tcl = Tcl::instance();
00056         
00057 //      if (argc==3)
00058 //      {
00059 //              // Over-ride of a channel-module tcl command:
00060 //              // 1) and set up the array of the nodes used for reduce complexity in packet trasmission
00061 //              // 2) install a SAP to an above module (call channel-module tcl command)
00062 //              if (strcasecmp(argv[1],"addsap")==0)
00063 //              {
00064 //                      ChSAP *chsap = dynamic_cast<ChSAP*>(TclObject::lookup(argv[2]));
00065 //                      if (!chsap)
00066 //                              return TCL_ERROR;
00067 //                      addNode(chsap);
00068 //                      Module::command(argc, argv);
00069 //              }
00070 //              
00071 //      }
00072         return ChannelModule::command(argc, argv);
00073 }
00074 
00075 
00076 
00077 
00078 double DumbWirelessChModule::getPropDelay(Position *source, Position* dest)
00079 {
00080         if(usePropagationDelay_)
00081                 return  (sqrt( ((source->getX()-dest->getX())*(source->getX()-dest->getX())) + 
00082                         ((source->getY()-dest->getY())*(source->getY()-dest->getY())) ) 
00083                         / SPEED_OF_LIGHT);
00084         else
00085                 return 0;
00086 }
00087 
00088 void DumbWirelessChModule::sendUpPhy(Packet *p,ChSAP *chsap)
00089 {
00090 
00091         
00092   Scheduler &s = Scheduler::instance();
00093   struct hdr_cmn *hdr = HDR_CMN(p);
00094         
00095   hdr->direction() = hdr_cmn::UP;
00096         
00097   //double Pt = p->txinfo_.getTxPr();
00098         
00099   Position *sourcePos = chsap->getPosition();
00100   ChSAP *dest;
00101         
00102         
00103   for (int i=0; i < getChSAPnum(); i++) {
00104                 
00105     dest = (ChSAP*)getChSAP(i);
00106     if (chsap == dest) // it's the source node -> skip it
00107       continue;
00108                 
00109     s.schedule(dest,
00110                p->copy(), 
00111                getPropDelay(sourcePos, dest->getPosition()));
00112   }
00113 
00114   Packet::free(p);
00115 }
00116 
00117 void DumbWirelessChModule::recv(Packet *p, ChSAP* chsap)
00118 {
00119         sendUpPhy(p, chsap);
00120 }

Generated on Wed Nov 26 15:47:29 2008 for NS-MIRACLE library by  doxygen 1.5.2