Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

EtherMAC.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 
00020 #include <stdio.h>
00021 #include <string.h>
00022 #include <omnetpp.h>
00023 
00024 #include "Ethernet.h"
00025 #include "EtherFrame_m.h"
00026 
00027 // Self-message kind values
00028 #define ENDIFG             100
00029 #define ENDRECEPTION       101
00030 #define ENDBACKOFF         102
00031 #define ENDTRANSMISSION    103
00032 #define ENDJAMMING         104
00033 #define ENDPAUSE           105
00034 #define ENDAUTOCONFIG      106
00035 
00036 // MAC transmit state
00037 #define TX_IDLE_STATE      1
00038 #define WAIT_IFG_STATE     2
00039 #define TRANSMITTING_STATE 3
00040 #define JAMMING_STATE      4
00041 #define BACKOFF_STATE      5
00042 #define PAUSE_STATE        6
00043 
00044 // MAC receive states
00045 #define RX_IDLE_STATE      1
00046 #define RECEIVING_STATE    2
00047 #define RX_COLLISION_STATE 3
00048 
00049 // Length of autoconfig period: should be larger than delays
00050 #define AUTOCONFIG_PERIOD  0.001  /* well more than 4096 bit times at 10Mb */
00051 
00052 
00056 class EtherMAC : public cSimpleModule
00057 {
00058     Module_Class_Members(EtherMAC,cSimpleModule,0);
00059 
00060     virtual void initialize();
00061     virtual void handleMessage(cMessage *msg);
00062     virtual void finish();
00063 
00064   public:
00068     long queueLength() {return outputbuffer.length();}
00069 
00070   private:
00071     // counter for automatic address generation
00072     static unsigned int autoAddressCtr;
00073 
00074     // MAC operation modes and parameters
00075     bool disabled;          // true if not connected to a network
00076     MACAddress myaddress;   // own MAC address
00077     bool promiscuous;       // if true, passes up all received frames
00078     bool duplexMode;        // channel connecting to MAC is full duplex, i.e. like a switch with 2 half-duplex lines
00079     bool carrierExtension;  // carrier extension on/off (Gigabit Ethernet)
00080     bool frameBursting;     // frame bursting on/off (Gigabit Ethernet)
00081     int maxQueueSize;       // max queue length
00082 
00083     // MAC transmission characteristics
00084     double txrate;          // transmission rate of MAC, bit/s
00085     double bitTime;         // precalculated as 1/txrate
00086     double slotTime;        // slot time
00087     double interFrameGap;   // IFG
00088     double jamDuration;     // precalculated as 8*JAM_SIGNAL_BYTES*bitTime
00089     double shortestFrameDuration;  // precalculated from MIN_ETHERNET_FRAME or GIGABIT_MIN_FRAME_WITH_EXT
00090 
00091     // parameters for autoconfig
00092     bool autoconfigInProgress; // true if autoconfig is currently ongoing
00093     double lowestTxrateSuggested;
00094     bool duplexVetoed;
00095 
00096     // States
00097     int  transmitState;     // State of the MAC unit transmitting
00098     int  receiveState;      // State of the MAC unit receiving
00099     int  framesSentInBurst; // Number of frames send out in current frame burst
00100     int  bytesSentInBurst;  // Number of bytes transmitted in current frame burst
00101     int  backoffs;          // Value of backoff for exponential back-off algorithm
00102     int  numConcurrentTransmissions; // number of colliding frames -- we must receive this many jams
00103     int  pauseUnitsRequested; // requested pause duration, or zero -- examined at endTx
00104 
00105     // Other variables
00106     cQueue outputbuffer;    // Output queue
00107     EtherFrame *frameBeingReceived;
00108     cMessage *endTxMsg, *endRxMsg, *endIFGMsg, *endBackoffMsg, *endJammingMsg, *endPauseMsg;
00109 
00110     // Statistics:
00111     simtime_t totalCollisionTime;      // total duration of collisions on channel
00112     simtime_t totalSuccessfulRxTxTime; // total duration of successful transmissions on channel
00113     simtime_t channelBusySince;        // needed for computing totalCollisionTime/totalSuccessfulRxTxTime
00114     unsigned long numFramesSent;
00115     unsigned long numFramesReceivedOK;
00116     unsigned long numBytesSent;        // includes Ethernet frame bytes with preamble
00117     unsigned long numBytesReceivedOK;  // includes Ethernet frame bytes with preamble
00118     unsigned long numFramesFromHL;     // packets received from higer layer (LLC or MACRelayUnit)
00119     unsigned long numFramesFromHLDropped; // packets from higher layer dropped because queue was full
00120     unsigned long numDroppedBitError;  // frames dropped because of bit errors
00121     unsigned long numDroppedNotForUs;  // frames dropped because destination address didn't match
00122     unsigned long numFramesPassedToHL; // frames passed to higher layer
00123     unsigned long numPauseFramesRcvd;  // PAUSE frames received from network
00124     unsigned long numPauseFramesSent;  // PAUSE frames sent
00125     unsigned long numCollisions;       // collisions (NOT number of collided frames!) sensed
00126     unsigned long numBackoffs;         // number of retransmissions
00127     cOutVector numFramesSentVector;
00128     cOutVector numFramesReceivedOKVector;
00129     cOutVector numBytesSentVector;
00130     cOutVector numBytesReceivedOKVector;
00131     cOutVector numFramesFromHLDroppedVector;
00132     cOutVector numDroppedBitErrorVector;
00133     cOutVector numDroppedNotForUsVector;
00134     cOutVector numFramesPassedToHLVector;
00135     cOutVector numPauseFramesRcvdVector;
00136     cOutVector numPauseFramesSentVector;
00137     cOutVector numCollisionsVector;
00138     cOutVector numBackoffsVector;
00139 
00140     // event handlers
00141     void processFrameFromUpperLayer(EtherFrame *msg);
00142     void processMsgFromNetwork(cMessage *msg);
00143     void handleEndIFGPeriod();
00144     void handleEndTxPeriod();
00145     void handleEndRxPeriod();
00146     void handleEndBackoffPeriod();
00147     void handleEndJammingPeriod();
00148     void handleEndPausePeriod();
00149 
00150     // setup, autoconfig
00151     void startAutoconfig();
00152     void handleAutoconfigMessage(cMessage *msg);
00153     void printState();
00154     void printParameters();
00155     void calculateParameters();
00156 
00157     // helpers
00158     void scheduleEndIFGPeriod();
00159     void scheduleEndTxPeriod(cMessage*);
00160     void scheduleEndRxPeriod(cMessage*);
00161     void scheduleEndPausePeriod(int pauseUnits);
00162     void sendJamSignal();
00163     void handleRetransmission();
00164     void beginSendFrames();
00165     void frameReceptionComplete(EtherFrame *frame);
00166     void processReceivedDataFrame(EtherFrame *frame);
00167     void processPauseCommand(int pauseUnits);
00168     void startFrameTransmission();
00169 };
00170 
00171 

Generated on Sat May 15 20:30:43 2004 for Ethernet by doxygen1.2.17