802.11-module.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 #include "802.11-module.h"
00031 
00032 /* ======================================================================
00033    TCL Hooks for the simulator
00034    ====================================================================== */
00035 static class MacInterfaceClass : public TclClass {
00036 public:
00037         MacInterfaceClass() : TclClass("MacInterface") {}
00038         TclObject* create(int, const char*const*) {
00039         return (new MacInterface());
00040 
00041 }
00042 } class_macinterface;
00043 
00044 MacInterface::MacInterface() : NsObject()
00045 {
00046 }
00047 
00048 MacInterface::~MacInterface()
00049 {
00050 }
00051 
00052 void MacInterface::setModule(MacModule802_11 *m)
00053 {
00054         module_ = m;
00055 }
00056 
00057 void MacInterface::recv(Packet *p, const char *why)
00058 {
00059         module_->drop(p, 5, why);
00060 }
00061 
00062 void MacInterface::recv(Packet *p)
00063 {
00064         module_->drop(p, 5);
00065 }
00066 
00067 void MacInterface::recv(Packet *p, Handler *h)
00068 {
00069         module_->drop(p, 5);
00070 }
00071 
00072 /* ======================================================================
00073    TCL Hooks for the simulator
00074    ====================================================================== */
00075 static class LogInterfaceClass : public TclClass {
00076 public:
00077         LogInterfaceClass() : TclClass("LogInterface") {}
00078         TclObject* create(int, const char*const*) {
00079         return (new LogInterface());
00080 
00081 }
00082 } class_loginterface;
00083 
00084 LogInterface::LogInterface() : NsObject()
00085 {
00086 }
00087 
00088 LogInterface::~LogInterface()
00089 {
00090 }
00091 
00092 void LogInterface::setModule(MacModule802_11 *m)
00093 {
00094         module_ = m;
00095 }
00096 
00097 void LogInterface::recv(Packet *p, const char *why)
00098 {
00099         module_->drop(p, 10, why);
00100 }
00101 
00102 void LogInterface::recv(Packet *p)
00103 {
00104         module_->drop(p, 10);
00105 }
00106 
00107 void LogInterface::recv(Packet *p, Handler *h)
00108 {
00109         module_->drop(p, 10);
00110 }
00111 
00112 /* ======================================================================
00113    TCL Hooks for the simulator
00114    ====================================================================== */
00115 static class LLInterfaceClass : public TclClass {
00116 public:
00117         LLInterfaceClass() : TclClass("LLInterface") {}
00118         TclObject* create(int, const char*const*) {
00119         return (new LLInterface());
00120 
00121 }
00122 } class_llinterface;
00123 
00124 LLInterface::LLInterface() : NsObject()
00125 {
00126 }
00127 
00128 LLInterface::~LLInterface()
00129 {
00130 }
00131 
00132 void LLInterface::setModule(MacModule802_11 *m)
00133 {
00134         module_ = m;
00135 }
00136 
00137 void LLInterface::recv(Packet *p)
00138 {
00139         module_->sendUp(p);
00140 }
00141 
00142 void LLInterface::recv(Packet *p, Handler *h)
00143 {
00144         module_->sendUp(p);
00145 }
00146 
00147 /* ======================================================================
00148    TCL Hooks for the simulator
00149    ====================================================================== */
00150 static class Module802_11Class : public TclClass {
00151 public:
00152         Module802_11Class() : TclClass("Module/802_11") {}
00153         TclObject* create(int, const char*const*) {
00154         return (new MacModule802_11());
00155 
00156 }
00157 } class_module802_11;
00158 
00159 MacModule802_11::MacModule802_11() : Module(), mac_(0), queue_(0), logif_(0), macif_(0), llif_(0)
00160 {
00161 }
00162 
00163 MacModule802_11::~MacModule802_11()
00164 {
00165 }
00166 
00167 int MacModule802_11::command(int argc, const char*const* argv)
00168 {
00169         Tcl& tcl = Tcl::instance();
00170         if(argc == 2)
00171         {
00172                 if(strcasecmp(argv[1], "getMac")==0)
00173                 {
00174                         if(mac_)
00175                                 tcl.result(mac_->name());
00176                         else
00177                                 return TCL_ERROR;
00178                         return TCL_OK;
00179                 }
00180                 else if(strcasecmp(argv[1], "getQueue")==0)
00181                 {
00182                         if(queue_)
00183                                 tcl.result(queue_->name());
00184                         else
00185                                 return TCL_ERROR;
00186                         return TCL_OK;
00187                 }
00188         }
00189         else if(argc == 3)
00190         {
00191                 if(strcasecmp(argv[1], "setMac")==0)
00192                 {
00193                         mac_ = (Mac *)TclObject::lookup(argv[2]);
00194                         if(!mac_)
00195                                 return TCL_ERROR;
00196                         tcl.evalf("%s down-target %s",mac_->name(), name());
00197                         if(macif_)
00198                         {
00199                                 tcl.evalf("%s drop-target %s",mac_->name(), macif_->name());
00200                         }
00201                         if(logif_)
00202                         {
00203                                 tcl.evalf("%s log-target %s",mac_->name(), logif_->name());
00204                         }
00205                         return TCL_OK;
00206                 }
00207                 else if(strcasecmp(argv[1], "setIfq")==0)
00208                 {
00209                         queue_ = (Queue *)TclObject::lookup(argv[2]);
00210                         if(!queue_)
00211                                 return TCL_ERROR;
00212                         if(macif_)
00213                                 tcl.evalf("%s drop-target %s",queue_->name(), macif_->name());
00214                         return TCL_OK;
00215                 }
00216                 else if(strcasecmp(argv[1], "setLL")==0)
00217                 {
00218                         ll_ = (LL *)TclObject::lookup(argv[2]);
00219                         if(!ll_)
00220                                 return TCL_ERROR;
00221                         tcl.evalf("%s up-target %s",ll_->name(), name());
00222                         if(macif_)
00223                                 tcl.evalf("%s drop-target %s",ll_->name(), macif_->name());
00224                         if(llif_)
00225                                 tcl.evalf("%s up-target %s",ll_->name(), llif_->name());
00226                         return TCL_OK;
00227                 }
00228                 else if(strcasecmp(argv[1], "setMacInterface")==0)
00229                 {
00230                         macif_ = (MacInterface *)TclObject::lookup(argv[2]);
00231                         if(!macif_)
00232                                 return TCL_ERROR;
00233                         if(mac_)
00234                         {
00235                                 tcl.evalf("%s drop-target %s",mac_->name(), macif_->name());
00236                         }
00237                         if(queue_)
00238                                 tcl.evalf("%s drop-target %s",queue_->name(), macif_->name());
00239                         if(ll_)
00240                                 tcl.evalf("%s drop-target %s",ll_->name(), macif_->name());
00241                         macif_->setModule(this);
00242                         return TCL_OK;
00243                 }
00244                 else if(strcasecmp(argv[1], "setLogInterface")==0)
00245                 {
00246                         logif_ = (LogInterface *)TclObject::lookup(argv[2]);
00247                         if(!logif_)
00248                                 return TCL_ERROR;
00249                         if(mac_)
00250                         {
00251                                 tcl.evalf("%s log-target %s",mac_->name(), logif_->name());
00252                         }
00253                         logif_->setModule(this);
00254                         return TCL_OK;
00255                 }
00256                 else if(strcasecmp(argv[1], "setLLInterface")==0)
00257                 {
00258                         llif_ = (LLInterface *)TclObject::lookup(argv[2]);
00259                         if(!llif_)
00260                                 return TCL_ERROR;
00261                         if(ll_)
00262                                 tcl.evalf("%s up-target %s",ll_->name(), llif_->name());
00263                         llif_->setModule(this);
00264                         return TCL_OK;
00265                 }
00266         }
00267         return Module::command(argc, argv);
00268 }
00269 
00270 void MacModule802_11::recv(Packet *p)
00271 {
00272         hdr_cmn *ch = HDR_CMN(p);
00273         if(ch->direction() == hdr_cmn::DOWN)
00274         {
00275                 if(ll_)
00276                         ll_->recv(p, 0);
00277                 else
00278                 {
00279                         fprintf(stderr, "MacModule802_11: there is no ll connected!!");
00280                         exit(1);
00281                 }
00282         }
00283         else
00284         {
00285                 if(mac_){
00286                         mac_->recv(p, 0);
00287                 }
00288                 else
00289                 {
00290                         fprintf(stderr, "MacModule802_11: there is no mac connected!!");
00291                         exit(1);
00292                 }
00293         }
00294         
00295 }
00296 
00297 void MacModule802_11::recv(Packet *p, Handler *callback)
00298 {
00299         hdr_cmn *ch = HDR_CMN(p);
00300         if(ch->direction() == hdr_cmn::DOWN)
00301         {
00302                 sendDown(p);
00303         }
00304         else
00305         {
00306                 sendUp(p);
00307         }
00308 }
00309 

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