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