umts-wirelessch.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 "umts-wirelessch.h"
00032 #include "umts-headers.h"
00033 #include "umts-phy.h"
00034 
00035 static class UmtsWirelessChModuleClass : public TclClass {
00036 public:
00037         UmtsWirelessChModuleClass() : TclClass("Module/UmtsWirelessCh") {}
00038         TclObject* create(int, const char*const*) {
00039         return (new UmtsWirelessChModule());
00040 
00041 }
00042 } class_umtswirelesschmodule;
00043 
00044 UmtsWirelessChModule::UmtsWirelessChModule() : 
00045         ChannelModule(),
00046         BSchsap_(NULL)
00047 {
00048 
00049 }
00050 
00051 UmtsWirelessChModule::~UmtsWirelessChModule()
00052 {
00053 }
00054 
00055 
00056 
00057 int UmtsWirelessChModule::command(int argc, const char*const* argv)
00058 {
00059         Tcl& tcl = Tcl::instance();
00060         if (argc==3)
00061         {
00062                 if (strcasecmp(argv[1],"BSphymoduleId")==0)
00063                 {
00064                         int id = atoi(argv[2]);
00065                         if (id<0)
00066                                 return TCL_ERROR;
00067                         
00068                         return TCL_OK;
00069                         ChSAP *c;
00070                         BSchsap_ = NULL;
00071                         for (int i=0; i < getChSAPnum(); i++) 
00072                         {
00073                                 c = (ChSAP*)getChSAP(i);
00074                                 if (c->getModuleUpId()==id)
00075                                 {
00076                                         BSchsap_ = c;
00077                                         break;
00078                                 }
00079                         }
00080                         if (BSchsap_==NULL)
00081                         {
00082                                 fprintf(stderr,"Error UmtsWirelessChModule::command(%s), does not find the BS phy module, is yet attached?\n", argv[2]);
00083                                 return TCL_ERROR;
00084                         }
00085                 }
00086         }
00087 
00088 //      if (argc==3)
00089 //      {
00090 //              // Over-ride of a channel-module tcl command:
00091 //              // 1) and set up the array of the nodes used for reduce complexity in packet trasmission
00092 //              // 2) install a SAP to an above module (call channel-module tcl command)
00093 //              if (strcasecmp(argv[1],"addsap")==0)
00094 //              {
00095 //                      ChSAP *chsap = dynamic_cast<ChSAP*>(TclObject::lookup(argv[2]));
00096 //                      if (!chsap)
00097 //                              return TCL_ERROR;
00098 //                      addNode(chsap);
00099 //                      Module::command(argc, argv);
00100 //              }
00101 //              
00102 //      }
00103         return ChannelModule::command(argc, argv);
00104 }
00105 
00106 
00107 
00108 
00109 double UmtsWirelessChModule::getPropDelay(Position *source, Position* dest)
00110 {
00111   return        (sqrt( ((source->getX()-dest->getX())*(source->getX()-dest->getX())) + 
00112                        ((source->getY()-dest->getY())*(source->getY()-dest->getY())) ) 
00113                  / SPEED_OF_LIGHT);
00114 }
00115 
00116 void UmtsWirelessChModule::sendUpPhy(Packet *p,ChSAP *chsap)
00117 {
00118 
00119         
00120   Scheduler &s = Scheduler::instance();
00121   struct hdr_cmn *hdr = HDR_CMN(p);
00122   hdr_umtsphy* uh = HDR_UMTSPHY(p);
00123         
00124   hdr->direction() = hdr_cmn::UP;
00125   Position *sourcePos = chsap->getPosition();
00126   // check if it's an UPLINK transmission -> use the optimized mode
00127   if ((BSchsap_!=NULL)&&(uh->direction == DIRECTION_UPLINK))
00128   {
00129         // use the optimized mode -> transmit only to BS (transmission to the other MEs are useless)
00130         s.schedule(BSchsap_ ,p->copy(), getPropDelay(sourcePos, BSchsap_->getPosition()));
00131   }
00132   else
00133   {
00134                 // standard mode -> sent to all the ChSAP installed
00135                 //double Pt = p->txinfo_.getTxPr();
00136         
00137                 ChSAP *dest;
00138                 
00139                 
00140                 for (int i=0; i < getChSAPnum(); i++) {
00141                         
00142                 dest = (ChSAP*)getChSAP(i);
00143                 if (chsap == dest) // it's the source node -> skip it
00144                         continue;
00145                         
00146                 s.schedule(dest,
00147                                 p->copy(), 
00148                                 getPropDelay(sourcePos, dest->getPosition()));
00149                 }
00150         }
00151   Packet::free(p);
00152 }
00153 
00154 void UmtsWirelessChModule::recv(Packet *p, ChSAP* chsap)
00155 {
00156         sendUpPhy(p, chsap);
00157 }

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