mmac.cc

Go to the documentation of this file.
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 
00040 #include <phymac-clmsg.h>
00041 #include "mmac.h"
00042 #include "mmac-clmsg.h"
00043 #include "clmsg-phy-on-off-switch.h"
00044 
00045 static int mmac_addr_counter = 0;
00046 
00047 
00048 MMac::MMac()
00049   : mac2phy_delay_(1e-9),
00050     addr(mmac_addr_counter++)
00051 {
00052 
00053 }
00054 
00055 MMac::~MMac()
00056 {
00057 }
00058 
00059 
00060 int MMac::command(int argc, const char*const* argv)
00061 {
00062   Tcl& tcl = Tcl::instance();
00063   if (argc == 2)
00064     {
00065       if (strcasecmp(argv[1], "addr") == 0) 
00066         {
00067           tcl.resultf("%d", addr);
00068           return TCL_OK;
00069         }
00070     } 
00071   return Module::command(argc, argv);
00072 }
00073 
00074 
00075 int MMac::recvSyncClMsg(ClMessage* m)
00076 {
00077   if (m->type() == CLMSG_PHY2MAC_ENDTX)
00078     {
00079       Phy2MacEndTx(((ClMsgPhy2MacEndTx*)m)->pkt);
00080       return 0;
00081     }
00082   else if (m->type() == CLMSG_PHY2MAC_STARTRX)
00083     {
00084       Phy2MacStartRx(((ClMsgPhy2MacEndTx*)m)->pkt);
00085       return 0;
00086     }
00087   else if (m->type() == CLMSG_PHY2MAC_CCA)
00088     {
00089       Phy2MacCCA(((ClMsgPhy2MacCCA*)m)->CCA);
00090       return 0;
00091     }
00092   else if (m->type() == MAC_CLMSG_GET_ADDR)
00093     {
00094       ((MacClMsgGetAddr *)m)->setAddr(addr);
00095       return 0;
00096     }
00097   else return Module::recvSyncClMsg(m);
00098 }
00099 
00100 
00101 void MMac::recv(Packet* p)
00102 {
00103   hdr_cmn *ch = HDR_CMN(p);
00104   if(ch->direction() == hdr_cmn::UP)
00105     {
00106       Phy2MacEndRx(p);
00107     }
00108   else
00109     {
00110       //direction DOWN: packet is coming from upper layers
00111       recvFromUpperLayers(p);
00112     }
00113 }
00114 
00115 
00116 void MMac::Mac2PhyStartTx(Packet* p)
00117 {
00118   sendDown(p, mac2phy_delay_);
00119 }
00120 
00121 void MMac::Mac2PhyStartTx(int moduleId, Packet* p)
00122 {
00123   sendDown(moduleId, p, mac2phy_delay_);
00124 }
00125 
00126 
00127 void MMac::Phy2MacEndTx(const Packet* p)
00128 {
00129 }
00130 
00131 void MMac::Phy2MacStartRx(const Packet* p)
00132 {
00133 }
00134 
00135 void MMac::Phy2MacEndRx(Packet* p)
00136 {
00137 }
00138 
00139 void MMac::recvFromUpperLayers(Packet* p)
00140 {
00141 }
00142 
00143 void MMac::Phy2MacCCA(bool cca)
00144 {
00145 }
00146 
00147 double MMac::Mac2PhyTxDuration(Packet* pkt)
00148 {
00149   ClMsgMac2PhyGetTxDuration m(pkt);
00150   sendSyncClMsgDown(&m);
00151   return(m.getDuration());
00152 }
00153 
00154 double MMac::Mac2PhyTxDuration(int moduleId, Packet* pkt)
00155 {
00156   ClMsgMac2PhyGetTxDuration m(moduleId, pkt);
00157   sendSyncClMsgDown(&m);
00158   return(m.getDuration());
00159 }
00160 
00161 void MMac::Mac2PhyTurnOn()
00162 {
00163   ClMsgPhyOnOffSwitch m;
00164   m.setOn();
00165   sendSyncClMsgDown(&m);
00166 }
00167 
00168 void MMac::Mac2PhyTurnOn(int moduleId)
00169 {
00170   ClMsgPhyOnOffSwitch m(moduleId);
00171   m.setOn();
00172   sendSyncClMsgDown(&m);
00173 }
00174 
00175 void MMac::Mac2PhyTurnOff()
00176 {
00177   ClMsgPhyOnOffSwitch m;
00178   m.setOff();
00179   sendSyncClMsgDown(&m);
00180 }  
00181 
00182 void MMac::Mac2PhyTurnOff(int moduleId)
00183 {
00184   ClMsgPhyOnOffSwitch m(moduleId);
00185   m.setOff();
00186   sendSyncClMsgDown(&m);
00187 }
00188 
00189 bool MMac::Mac2PhyOnOffSwitchStatus()
00190 {
00191   ClMsgPhyOnOffSwitchStatus m;
00192   sendSyncClMsgDown(&m);
00193   return(m.getStatus());
00194 }
00195 
00196 bool MMac::Mac2PhyOnOffSwitchStatus(int moduleId)
00197 {
00198   ClMsgPhyOnOffSwitchStatus m(moduleId);
00199   sendSyncClMsgDown(&m);
00200   return(m.getStatus());
00201 }
00202 
00203 

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