EtherMACBase.h

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2006 Levente Meszaros
00003 // Copyright (C) 2004 Andras Varga
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public License
00016 // along with this program; if not, see <http://www.gnu.org/licenses/>.
00017 //
00018 
00019 #ifndef __INET_ETHER_MAC_BASE_H
00020 #define __INET_ETHER_MAC_BASE_H
00021 
00022 #include <omnetpp.h>
00023 #include "INETDefs.h"
00024 #include "Ethernet.h"
00025 #include "EtherFrame_m.h"
00026 #include "InterfaceEntry.h"
00027 #include "TxNotifDetails.h"
00028 #include "NotificationBoard.h"
00029 
00030 
00031 //FIXME change into inner enums!!!
00032 
00033 // Self-message kind values
00034 #define ENDIFG             100
00035 #define ENDRECEPTION       101
00036 #define ENDBACKOFF         102
00037 #define ENDTRANSMISSION    103
00038 #define ENDJAMMING         104
00039 #define ENDPAUSE           105
00040 #define ENDAUTOCONFIG      106
00041 
00042 // MAC transmit state
00043 #define TX_IDLE_STATE      1
00044 #define WAIT_IFG_STATE     2
00045 #define TRANSMITTING_STATE 3
00046 #define JAMMING_STATE      4
00047 #define BACKOFF_STATE      5
00048 #define PAUSE_STATE        6
00049 
00050 // MAC receive states
00051 #define RX_IDLE_STATE      1
00052 #define RECEIVING_STATE    2
00053 #define RX_COLLISION_STATE 3
00054 
00055 class IPassiveQueue;
00056 
00060 class INET_API EtherMACBase : public cSimpleModule, public INotifiable
00061 {
00062   protected:
00063     bool connected;                 // true if connected to a network, set automatically by exploring the network configuration
00064     bool disabled;                  // true if the MAC is disabled, defined by the user
00065     bool promiscuous;               // if true, passes up all received frames
00066     MACAddress address;             // own MAC address
00067     int txQueueLimit;               // max queue length
00068 
00069     // MAC operation modes and parameters
00070     bool duplexMode;                // channel connecting to MAC is full duplex, i.e. like a switch with 2 half-duplex lines
00071     bool carrierExtension;          // carrier extension on/off (Gigabit Ethernet)
00072     bool frameBursting;             // frame bursting on/off (Gigabit Ethernet)
00073 
00074     // MAC transmission characteristics
00075     double txrate;                  // transmission rate of MAC, bit/s
00076     simtime_t bitTime;              // precalculated as 1/txrate
00077     simtime_t slotTime;             // slot time
00078     simtime_t interFrameGap;        // IFG
00079     simtime_t jamDuration;          // precalculated as 8*JAM_SIGNAL_BYTES*bitTime
00080     simtime_t shortestFrameDuration;// precalculated from MIN_ETHERNET_FRAME or GIGABIT_MIN_FRAME_WITH_EXT
00081 
00082     // states
00083     int transmitState;              // State of the MAC unit transmitting
00084     int receiveState;               // State of the MAC unit receiving
00085     int pauseUnitsRequested;        // requested pause duration, or zero -- examined at endTx
00086 
00087     cQueue txQueue;                 // output queue
00088     IPassiveQueue *queueModule;     // optional module to receive messages from
00089 
00090     cGate *physOutGate;             // pointer to the "phys$o" gate
00091 
00092     // notification stuff
00093     InterfaceEntry *interfaceEntry;  // points into IInterfaceTable
00094     NotificationBoard *nb;
00095     TxNotifDetails notifDetails;
00096     bool hasSubscribers; // only notify if somebody is listening
00097 
00098     // self messages
00099     cMessage *endTxMsg, *endIFGMsg, *endPauseMsg;
00100 
00101     // statistics
00102     int  framesSentInBurst;            // Number of frames send out in current frame burst
00103     int  bytesSentInBurst;             // Number of bytes transmitted in current frame burst
00104     unsigned long numFramesSent;
00105     unsigned long numFramesReceivedOK;
00106     unsigned long numBytesSent;        // includes Ethernet frame bytes with preamble
00107     unsigned long numBytesReceivedOK;  // includes Ethernet frame bytes with preamble
00108     unsigned long numFramesFromHL;     // packets received from higer layer (LLC or MACRelayUnit)
00109     unsigned long numDroppedIfaceDown; // packets from higher layer dropped because interface down (TBD not impl yet)
00110     unsigned long numDroppedBitError;  // frames dropped because of bit errors
00111     unsigned long numDroppedNotForUs;  // frames dropped because destination address didn't match
00112     unsigned long numFramesPassedToHL; // frames passed to higher layer
00113     unsigned long numPauseFramesRcvd;  // PAUSE frames received from network
00114     unsigned long numPauseFramesSent;  // PAUSE frames sent
00115     cOutVector numFramesSentVector;
00116     cOutVector numFramesReceivedOKVector;
00117     cOutVector numBytesSentVector;
00118     cOutVector numBytesReceivedOKVector;
00119     cOutVector numDroppedIfaceDownVector;
00120     cOutVector numDroppedBitErrorVector;
00121     cOutVector numDroppedNotForUsVector;
00122     cOutVector numFramesPassedToHLVector;
00123     cOutVector numPauseFramesRcvdVector;
00124     cOutVector numPauseFramesSentVector;
00125 
00126   public:
00127     EtherMACBase();
00128     virtual ~EtherMACBase();
00129 
00130     virtual long getQueueLength() {return txQueue.length();}
00131     virtual MACAddress getMACAddress() {return address;}
00132 
00133   protected:
00134     //  initialization
00135     virtual void initialize();
00136     virtual void initializeTxrate() = 0;
00137     virtual void initializeFlags();
00138     virtual void initializeMACAddress();
00139     virtual void initializeQueueModule();
00140     virtual void initializeNotificationBoard();
00141     virtual void initializeStatistics();
00142     virtual void registerInterface(double txrate);
00143 
00144     // helpers
00145     virtual bool checkDestinationAddress(EtherFrame *frame);
00146     virtual void calculateParameters();
00147     virtual void printParameters();
00148 
00149     // finish
00150     virtual void finish();
00151 
00152     // event handlers
00153     virtual void processFrameFromUpperLayer(EtherFrame *msg);
00154     virtual void processMsgFromNetwork(cPacket *msg);
00155     virtual void processMessageWhenNotConnected(cMessage *msg);
00156     virtual void processMessageWhenDisabled(cMessage *msg);
00157     virtual void handleEndIFGPeriod();
00158     virtual void handleEndTxPeriod();
00159     virtual void handleEndPausePeriod();
00160     virtual void scheduleEndIFGPeriod();
00161     virtual void scheduleEndTxPeriod(cPacket *);
00162     virtual void scheduleEndPausePeriod(int pauseUnits);
00163 
00164     // helpers
00165     virtual bool checkAndScheduleEndPausePeriod();
00166     virtual void fireChangeNotification(int type, cPacket *msg);
00167     virtual void beginSendFrames();
00168     virtual void frameReceptionComplete(EtherFrame *frame);
00169     virtual void processReceivedDataFrame(EtherFrame *frame);
00170     virtual void processPauseCommand(int pauseUnits);
00171 
00172     // display
00173     virtual void updateDisplayString();
00174     virtual void updateConnectionColor(int txState);
00175 
00176     // notifications
00177     virtual void updateHasSubcribers() = 0;
00178     virtual void receiveChangeNotification(int category, const cPolymorphic *details);
00179 
00180 };
00181 
00182 #endif