INET Framework for OMNeT++/OMNEST
AnsaEtherMAC.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003 CTIE, Monash University
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU 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 General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 */
00018 
00019 #ifndef __INET_ETHERMAC_H
00020 #define __INET_ETHERMAC_H
00021 
00022 #include <stdio.h>
00023 #include <string.h>
00024 #include <omnetpp.h>
00025 #include "INETDefs.h"
00026 #include "Ethernet.h"
00027 #include "EtherFrame_m.h"
00028 #include "AnsaEtherMACBase.h"
00029 
00030 // Length of autoconfig period: should be larger than delays
00031 #define AUTOCONFIG_PERIOD  0.001  /* well more than 4096 bit times at 10Mb */
00032 
00033 class IPassiveQueue;
00034 
00038 class INET_API AnsaEtherMAC : public AnsaEtherMACBase
00039 {
00040   public:
00041     AnsaEtherMAC();
00042     virtual ~AnsaEtherMAC();
00043 
00044   protected:
00045     virtual void initialize();
00046     virtual void initializeTxrate();
00047     virtual void handleMessage(cMessage *msg);
00048     virtual void finish();
00049 
00050   protected:
00051     // parameters for autoconfig
00052     bool autoconfigInProgress; // true if autoconfig is currently ongoing
00053     double lowestTxrateSuggested;
00054     bool duplexVetoed;
00055 
00056     // states
00057     int  backoffs;          // Value of backoff for exponential back-off algorithm
00058     int  numConcurrentTransmissions; // number of colliding frames -- we must receive this many jams
00059 
00060     // other variables
00061     EtherFrame *frameBeingReceived;
00062     cMessage *endRxMsg, *endBackoffMsg, *endJammingMsg;
00063 
00064     // statistics
00065     simtime_t totalCollisionTime;      // total duration of collisions on channel
00066     simtime_t totalSuccessfulRxTxTime; // total duration of successful transmissions on channel
00067     simtime_t channelBusySince;        // needed for computing totalCollisionTime/totalSuccessfulRxTxTime
00068     unsigned long numCollisions;       // collisions (NOT number of collided frames!) sensed
00069     unsigned long numBackoffs;         // number of retransmissions
00070     cOutVector numCollisionsVector;
00071     cOutVector numBackoffsVector;
00072 
00073     // event handlers
00074     virtual void processFrameFromUpperLayer(EtherFrame *msg);
00075     virtual void processMsgFromNetwork(cPacket *msg);
00076     virtual void handleEndIFGPeriod();
00077     virtual void handleEndTxPeriod();
00078     virtual void handleEndRxPeriod();
00079     virtual void handleEndBackoffPeriod();
00080     virtual void handleEndJammingPeriod();
00081 
00082     // setup, autoconfig
00083     virtual void startAutoconfig();
00084     virtual void handleAutoconfigMessage(cMessage *msg);
00085     virtual void printState();
00086 
00087     // helpers
00088     virtual void scheduleEndRxPeriod(cPacket *);
00089     virtual void sendJamSignal();
00090     virtual void handleRetransmission();
00091     virtual void startFrameTransmission();
00092 
00093     // notifications
00094     virtual void updateHasSubcribers();
00095 };
00096 
00097 #endif
00098 
00099