EtherMAC.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003 Andras Varga; CTIE, Monash University, Australia
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public License
00015  * along with this program; if not, see <http://www.gnu.org/licenses/>.
00016 */
00017 
00018 #ifndef __INET_ETHERMAC_H
00019 #define __INET_ETHERMAC_H
00020 
00021 #include <stdio.h>
00022 #include <string.h>
00023 #include <omnetpp.h>
00024 #include "INETDefs.h"
00025 #include "Ethernet.h"
00026 #include "EtherFrame_m.h"
00027 #include "EtherMACBase.h"
00028 
00029 // Length of autoconfig period: should be larger than delays
00030 #define AUTOCONFIG_PERIOD  0.001  /* well more than 4096 bit times at 10Mb */
00031 
00032 class IPassiveQueue;
00033 
00037 class INET_API EtherMAC : public EtherMACBase
00038 {
00039   public:
00040     EtherMAC();
00041     virtual ~EtherMAC();
00042 
00043   protected:
00044     virtual void initialize();
00045     virtual void initializeTxrate();
00046     virtual void handleMessage(cMessage *msg);
00047     virtual void finish();
00048 
00049   protected:
00050     // parameters for autoconfig
00051     bool autoconfigInProgress; // true if autoconfig is currently ongoing
00052     double lowestTxrateSuggested;
00053     bool duplexVetoed;
00054 
00055     // states
00056     int  backoffs;          // Value of backoff for exponential back-off algorithm
00057     int  numConcurrentTransmissions; // number of colliding frames -- we must receive this many jams
00058 
00059     // other variables
00060     EtherFrame *frameBeingReceived;
00061     cMessage *endRxMsg, *endBackoffMsg, *endJammingMsg;
00062 
00063     // statistics
00064     simtime_t totalCollisionTime;      // total duration of collisions on channel
00065     simtime_t totalSuccessfulRxTxTime; // total duration of successful transmissions on channel
00066     simtime_t channelBusySince;        // needed for computing totalCollisionTime/totalSuccessfulRxTxTime
00067     unsigned long numCollisions;       // collisions (NOT number of collided frames!) sensed
00068     unsigned long numBackoffs;         // number of retransmissions
00069     cOutVector numCollisionsVector;
00070     cOutVector numBackoffsVector;
00071 
00072     // event handlers
00073     virtual void processFrameFromUpperLayer(EtherFrame *msg);
00074     virtual void processMsgFromNetwork(cPacket *msg);
00075     virtual void handleEndIFGPeriod();
00076     virtual void handleEndTxPeriod();
00077     virtual void handleEndRxPeriod();
00078     virtual void handleEndBackoffPeriod();
00079     virtual void handleEndJammingPeriod();
00080 
00081     // setup, autoconfig
00082     virtual void startAutoconfig();
00083     virtual void handleAutoconfigMessage(cMessage *msg);
00084     virtual void printState();
00085 
00086     // helpers
00087     virtual void scheduleEndRxPeriod(cPacket *);
00088     virtual void sendJamSignal();
00089     virtual void handleRetransmission();
00090     virtual void startFrameTransmission();
00091 
00092     // notifications
00093     virtual void updateHasSubcribers();
00094 };
00095 
00096 #endif
00097 
00098