mmac-aloha.cc

Go to the documentation of this file.
00001 /* -*- Mode:C++ -*- */
00002 
00003 /*
00004  * Copyright (c) 2007 Regents of the SIGNET lab, University of Padova.
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions
00009  * are met:
00010  * 1. Redistributions of source code must retain the above copyright
00011  *    notice, this list of conditions and the following disclaimer.
00012  * 2. Redistributions in binary form must reproduce the above copyright
00013  *    notice, this list of conditions and the following disclaimer in the
00014  *    documentation and/or other materials provided with the distribution.
00015  * 3. Neither the name of the University of Padova (SIGNET lab) nor the 
00016  *    names of its contributors may be used to endorse or promote products 
00017  *    derived from this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00020  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 
00021  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
00022  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
00023  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00024  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00025  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
00026  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
00027  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
00028  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
00029  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030  */
00031 
00043 #include"mmac-aloha.h"
00044 
00045 #include<iostream>
00046 
00047 
00048 
00049 static class MMacAlohaClass : public TclClass {
00050 public:
00051   MMacAlohaClass() : TclClass("Module/MMac/ALOHA") {}
00052   TclObject* create(int, const char*const*) {
00053     return (new MMacAloha);
00054   }
00055 } class_MMacAloha;
00056 
00057 
00058 
00059 
00060 
00061 MMacAloha::MMacAloha()
00062   : TxActive(false)
00063 {
00064   
00065 }
00066 
00067 void MMacAloha::recvFromUpperLayers(Packet* p)
00068 {  
00069 
00070   if (TxActive)
00071     {
00072       Q.push(p);
00073       if (debug_) 
00074         cerr << showpoint << NOW << " " <<  __PRETTY_FUNCTION__ 
00075              << " TxActive => enqueueing packet" << endl;
00076     }
00077   else
00078     {
00079       Mac2PhyStartTx(p); 
00080       TxActive = true;
00081       if (debug_) 
00082         cerr << showpoint << NOW << " " <<  __PRETTY_FUNCTION__ 
00083              << " transmitting packet" << endl;
00084       
00085     }
00086 }
00087 
00088 void MMacAloha::Phy2MacEndTx(const Packet* p)
00089 {
00090 
00091   TxActive = false;
00092 
00093   // we can send something else if we have it
00094   if (! Q.empty())
00095     {
00096       if (debug_) 
00097         cerr << showpoint << NOW << " " <<  __PRETTY_FUNCTION__ 
00098              << "Q.size()=" << Q.size() << ", transmitting packet"  << endl;
00099       
00100       Packet* p2;
00101       p2 = Q.front();
00102       Q.pop();
00103       Mac2PhyStartTx(p2);
00104       TxActive = true;
00105     }
00106   else
00107     {
00108       if (debug_) 
00109         cerr << showpoint << NOW << " " <<  __PRETTY_FUNCTION__ 
00110              << "Q.size()= 0" << endl;
00111     }
00112 }
00113 
00114 void MMacAloha::Phy2MacStartRx(const Packet* p)
00115 {
00116   if (debug_) 
00117     cerr << showpoint << NOW << " " <<  __PRETTY_FUNCTION__ << endl;
00118 }
00119 
00120 
00121 void MMacAloha::Phy2MacEndRx(Packet* p)
00122 {
00123   if (debug_) 
00124     cerr << showpoint << NOW << " " <<  __PRETTY_FUNCTION__ << endl;
00125   hdr_cmn* ch = HDR_CMN(p);
00126 
00127   if (ch->error())
00128     drop(p, 1, "ERR");
00129   else
00130     sendUp(p);
00131 }

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