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

MACRelayUnitPP Class Reference

#include <MACRelayUnitPP.h>

Inheritance diagram for MACRelayUnitPP:

MACRelayUnitBase List of all members.

Protected Methods

void handleIncomingFrame (EtherFrame *msg)
void processFrame (cMessage *msg)
Redefined cSimpleModule member functions.
virtual void initialize ()
virtual void handleMessage (cMessage *msg)
virtual void finish ()

Private Methods

 Module_Class_Members (MACRelayUnitPP, MACRelayUnitBase, 0) protected

Private Attributes

simtime_t processingTime
int bufferSize
long highWatermark
int pauseUnits
simtime_t pauseInterval
int bufferUsed
PortBuffer * buffer
simtime_t pauseLastSent
long numProcessedFrames
long numDroppedFrames
cOutVector bufferLevel

Detailed Description

An implementation of the MAC Relay Unit that assumes one processor assigned to each incoming port, with separate queues.

Definition at line 32 of file MACRelayUnitPP.h.


Member Function Documentation

void MACRelayUnitPP::finish   [protected, virtual]
 

Writes statistics.

Definition at line 195 of file MACRelayUnitPP.cc.

References numDroppedFrames, and numProcessedFrames.

00196 {
00197     if (par("writeScalars").boolValue())
00198     {
00199         recordScalar("processed frames", numProcessedFrames);
00200         recordScalar("dropped frames", numDroppedFrames);
00201     }
00202 }

void MACRelayUnitPP::handleIncomingFrame EtherFrame   msg [protected]
 

Handle incoming Ethernet frame: if buffer full discard it, otherwise, insert it into buffer and start processing if processor is free.

Definition at line 117 of file MACRelayUnitPP.cc.

References buffer, bufferLevel, bufferSize, bufferUsed, EV, highWatermark, numDroppedFrames, MACRelayUnitBase::numPorts, pauseInterval, pauseLastSent, pauseUnits, processingTime, and MACRelayUnitBase::sendPauseFrame().

Referenced by handleMessage().

00118 {
00119     // If buffer not full, insert payload frame into buffer and process the frame in parallel.
00120 
00121     long length = frame->length()/8;
00122     if (length + bufferUsed < bufferSize)
00123     {
00124         int inputport = frame->arrivalGate()->index();
00125         buffer[inputport].queue.insert(frame);
00126         buffer[inputport].port = inputport;
00127         bufferUsed += length;
00128 
00129         // send PAUSE if above watermark
00130         if (pauseUnits>0 && highWatermark>0 && bufferUsed>=highWatermark && pauseLastSent-simTime()>pauseInterval)
00131         {
00132             // send PAUSE on all ports
00133             for (int i=0; i<numPorts; i++)
00134                 sendPauseFrame(i, pauseUnits);
00135             pauseLastSent = simTime();
00136         }
00137 
00138         if (buffer[inputport].cpuBusy)
00139         {
00140             EV << "Port CPU " << inputport << " busy, incoming frame " << frame << " enqueued for later processing\n";
00141         }
00142         else
00143         {
00144             EV << "Port CPU " << inputport << " free, begin processing of incoming frame " << frame << endl;
00145             buffer[inputport].cpuBusy = true;
00146             cMessage *msg = new cMessage("endProcessing");
00147             msg->setContextPointer(&buffer[inputport]);
00148             scheduleAt(simTime() + processingTime, msg);
00149         }
00150     }
00151     // Drop the frame and record the number of dropped frames
00152     else
00153     {
00154         EV << "Buffer full, dropping frame " << frame << endl;
00155         delete frame;
00156         ++numDroppedFrames;
00157     }
00158 
00159     // Record statistics of buffer usage levels
00160     bufferLevel.record(bufferUsed);
00161 }

void MACRelayUnitPP::handleMessage cMessage *    msg [protected, virtual]
 

Calls handleIncomingFrame() for frames arrived from outside, and processFrame() for self messages.

Definition at line 100 of file MACRelayUnitPP.cc.

References ETH_FRAME, handleIncomingFrame(), and processFrame().

00101 {
00102     if (!msg->isSelfMessage())
00103     {
00104         // Frame received from MAC unit
00105         if (msg->kind()!=ETH_FRAME)
00106             error("Unknown incoming frame");
00107 
00108         handleIncomingFrame((EtherFrame *)msg);
00109     }
00110     else
00111     {
00112         // Self message signal used to indicate a frame has been finished processing
00113         processFrame(msg);
00114     }
00115 }

void MACRelayUnitPP::initialize   [protected, virtual]
 

Read parameters parameters.

Reimplemented from MACRelayUnitBase.

Definition at line 53 of file MACRelayUnitPP.cc.

References MACRelayUnitBase::addressTableSize, MACRelayUnitBase::agingTime, buffer, bufferLevel, bufferSize, bufferUsed, EV, highWatermark, MACRelayUnitBase::initialize(), numDroppedFrames, MACRelayUnitBase::numPorts, numProcessedFrames, pauseInterval, pauseLastSent, pauseUnits, and processingTime.

00054 {
00055     MACRelayUnitBase::initialize();
00056 
00057     bufferLevel.setName("buffer level");
00058 
00059     numProcessedFrames = numDroppedFrames = 0;
00060     WATCH(numProcessedFrames);
00061     WATCH(numDroppedFrames);
00062 
00063     processingTime = par("processingTime");
00064     bufferSize = par("bufferSize");
00065     highWatermark = par("highWatermark");
00066     pauseUnits = par("pauseUnits");
00067 
00068     // 1 pause unit is 512 bit times; we assume 100Mb MACs here.
00069     // We send a pause again when previous one is about to expire.
00070     pauseInterval = pauseUnits*512.0/100000.0;
00071 
00072     pauseLastSent = 0;
00073     WATCH(pauseLastSent);
00074 
00075     bufferUsed = 0;
00076     WATCH(bufferUsed);
00077 
00078     buffer = new PortBuffer[numPorts];
00079     for (int i = 0; i < numPorts; ++i)
00080     {
00081         buffer[i].port = i;
00082         buffer[i].cpuBusy = false;
00083 
00084         char qname[20];
00085         sprintf(qname,"portQueue%d",i);
00086         buffer[i].queue.setName(qname);
00087     }
00088 
00089     EV << "Parameters of (" << className() << ") " << fullPath() << "\n";
00090     EV << "processing time: " << processingTime << "\n";
00091     EV << "ports: " << numPorts << "\n";
00092     EV << "buffer size: " << bufferSize << "\n";
00093     EV << "address table size: " << addressTableSize << "\n";
00094     EV << "aging time: " << agingTime << "\n";
00095     EV << "high watermark: " << highWatermark << "\n";
00096     EV << "pause time: " << pauseUnits << "\n";
00097     EV << "\n";
00098 }

MACRelayUnitPP::Module_Class_Members MACRelayUnitPP   ,
MACRelayUnitBase   ,
 
[inline, private]
 

Definition at line 34 of file MACRelayUnitPP.h.

00036            :
00037     // Stores frame buffer, one for each port
00038     struct PortBuffer
00039     {
00040         int port;
00041         bool cpuBusy;
00042         cQueue queue;
00043     };

void MACRelayUnitPP::processFrame cMessage *    msg [protected]
 

Triggered when a frame has completed processing, it routes the frame to the appropriate port, and starts processing the next frame.

Definition at line 163 of file MACRelayUnitPP.cc.

References bufferLevel, bufferUsed, EV, MACRelayUnitBase::handleAndDispatchFrame(), numProcessedFrames, MACRelayUnitBase::printAddressTable(), and processingTime.

Referenced by handleMessage().

00164 {
00165     // Extract frame from the appropriate buffer;
00166     PortBuffer *pBuff = (PortBuffer*)msg->contextPointer();
00167     EtherFrame *frame = (EtherFrame*)pBuff->queue.pop();
00168     long length = frame->length()/8;
00169     int inputport = pBuff->port;
00170 
00171     EV << "Port CPU " << inputport << " completed processing of frame " << frame << endl;
00172 
00173     handleAndDispatchFrame(frame, inputport);
00174     printAddressTable();
00175 
00176     bufferUsed -= length;
00177     bufferLevel.record(bufferUsed);
00178 
00179     numProcessedFrames++;
00180 
00181     // Process next frame in queue if they are pending
00182     if (!pBuff->queue.empty())
00183     {
00184         EV << "Begin processing of next frame\n";
00185         scheduleAt(simTime()+processingTime, msg);
00186     }
00187     else
00188     {
00189         EV << "Port CPU idle\n";
00190         pBuff->cpuBusy = false;
00191         delete msg;
00192     }
00193 }


Member Data Documentation

PortBuffer* MACRelayUnitPP::buffer [private]
 

Definition at line 54 of file MACRelayUnitPP.h.

Referenced by handleIncomingFrame(), and initialize().

cOutVector MACRelayUnitPP::bufferLevel [private]
 

Definition at line 60 of file MACRelayUnitPP.h.

Referenced by handleIncomingFrame(), initialize(), and processFrame().

int MACRelayUnitPP::bufferSize [private]
 

Definition at line 47 of file MACRelayUnitPP.h.

Referenced by handleIncomingFrame(), and initialize().

int MACRelayUnitPP::bufferUsed [private]
 

Definition at line 53 of file MACRelayUnitPP.h.

Referenced by handleIncomingFrame(), initialize(), and processFrame().

long MACRelayUnitPP::highWatermark [private]
 

Definition at line 48 of file MACRelayUnitPP.h.

Referenced by handleIncomingFrame(), and initialize().

long MACRelayUnitPP::numDroppedFrames [private]
 

Definition at line 59 of file MACRelayUnitPP.h.

Referenced by finish(), handleIncomingFrame(), and initialize().

long MACRelayUnitPP::numProcessedFrames [private]
 

Definition at line 58 of file MACRelayUnitPP.h.

Referenced by finish(), initialize(), and processFrame().

simtime_t MACRelayUnitPP::pauseInterval [private]
 

Definition at line 50 of file MACRelayUnitPP.h.

Referenced by handleIncomingFrame(), and initialize().

simtime_t MACRelayUnitPP::pauseLastSent [private]
 

Definition at line 55 of file MACRelayUnitPP.h.

Referenced by handleIncomingFrame(), and initialize().

int MACRelayUnitPP::pauseUnits [private]
 

Definition at line 49 of file MACRelayUnitPP.h.

Referenced by handleIncomingFrame(), and initialize().

simtime_t MACRelayUnitPP::processingTime [private]
 

Definition at line 46 of file MACRelayUnitPP.h.

Referenced by handleIncomingFrame(), initialize(), and processFrame().


The documentation for this class was generated from the following files:
Generated on Sat May 15 20:30:48 2004 for Ethernet by doxygen1.2.17