#include <MACRelayUnitPP.h>
Classes | |
struct | PortBuffer |
Public Member Functions | |
MACRelayUnitPP () | |
virtual | ~MACRelayUnitPP () |
Protected Member Functions | |
virtual void | handleIncomingFrame (EtherFrame *msg) |
virtual void | processFrame (cMessage *msg) |
Redefined cSimpleModule member functions. | |
virtual void | initialize () |
virtual void | handleMessage (cMessage *msg) |
virtual void | finish () |
Protected 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 |
An implementation of the MAC Relay Unit that assumes one processor assigned to each incoming port, with separate queues.
Definition at line 31 of file MACRelayUnitPP.h.
MACRelayUnitPP::MACRelayUnitPP | ( | ) |
Definition at line 35 of file MACRelayUnitPP.cc.
{ buffer = NULL; }
MACRelayUnitPP::~MACRelayUnitPP | ( | ) | [virtual] |
Definition at line 40 of file MACRelayUnitPP.cc.
{ delete [] buffer; }
void MACRelayUnitPP::finish | ( | ) | [protected, virtual] |
Writes statistics.
Definition at line 184 of file MACRelayUnitPP.cc.
{ recordScalar("processed frames", numProcessedFrames); recordScalar("dropped frames", numDroppedFrames); }
void MACRelayUnitPP::handleIncomingFrame | ( | EtherFrame * | msg | ) | [protected, virtual] |
Handle incoming Ethernet frame: if buffer full discard it, otherwise, insert it into buffer and start processing if processor is free.
Definition at line 106 of file MACRelayUnitPP.cc.
Referenced by handleMessage().
{ // If buffer not full, insert payload frame into buffer and process the frame in parallel. long length = frame->getByteLength(); if (length + bufferUsed < bufferSize) { int inputport = frame->getArrivalGate()->getIndex(); buffer[inputport].queue.insert(frame); buffer[inputport].port = inputport; bufferUsed += length; // send PAUSE if above watermark if (pauseUnits>0 && highWatermark>0 && bufferUsed>=highWatermark && simTime()-pauseLastSent>pauseInterval) { // send PAUSE on all ports for (int i=0; i<numPorts; i++) sendPauseFrame(i, pauseUnits); pauseLastSent = simTime(); } if (buffer[inputport].cpuBusy) { EV << "Port CPU " << inputport << " busy, incoming frame " << frame << " enqueued for later processing\n"; } else { EV << "Port CPU " << inputport << " free, begin processing of incoming frame " << frame << endl; buffer[inputport].cpuBusy = true; cMessage *msg = new cMessage("endProcessing"); msg->setContextPointer(&buffer[inputport]); scheduleAt(simTime() + processingTime, msg); } } // Drop the frame and record the number of dropped frames else { EV << "Buffer full, dropping frame " << frame << endl; delete frame; ++numDroppedFrames; } // Record statistics of buffer usage levels bufferLevel.record(bufferUsed); }
void MACRelayUnitPP::handleMessage | ( | cMessage * | msg | ) | [protected, virtual] |
Calls handleIncomingFrame() for frames arrived from outside, and processFrame() for self messages.
Definition at line 92 of file MACRelayUnitPP.cc.
{ if (!msg->isSelfMessage()) { // Frame received from MAC unit handleIncomingFrame(check_and_cast<EtherFrame *>(msg)); } else { // Self message signal used to indicate a frame has been finished processing processFrame(msg); } }
void MACRelayUnitPP::initialize | ( | ) | [protected, virtual] |
Read parameters parameters.
Reimplemented from MACRelayUnitBase.
Definition at line 45 of file MACRelayUnitPP.cc.
{ MACRelayUnitBase::initialize(); bufferLevel.setName("buffer level"); numProcessedFrames = numDroppedFrames = 0; WATCH(numProcessedFrames); WATCH(numDroppedFrames); processingTime = par("processingTime"); bufferSize = par("bufferSize"); highWatermark = par("highWatermark"); pauseUnits = par("pauseUnits"); // 1 pause unit is 512 bit times; we assume 100Mb MACs here. // We send a pause again when previous one is about to expire. pauseInterval = pauseUnits*512.0/100000.0; pauseLastSent = 0; WATCH(pauseLastSent); bufferUsed = 0; WATCH(bufferUsed); buffer = new PortBuffer[numPorts]; for (int i = 0; i < numPorts; ++i) { buffer[i].port = i; buffer[i].cpuBusy = false; char qname[20]; sprintf(qname,"portQueue%d",i); buffer[i].queue.setName(qname); } EV << "Parameters of (" << getClassName() << ") " << getFullPath() << "\n"; EV << "processing time: " << processingTime << "\n"; EV << "ports: " << numPorts << "\n"; EV << "buffer size: " << bufferSize << "\n"; EV << "address table size: " << addressTableSize << "\n"; EV << "aging time: " << agingTime << "\n"; EV << "high watermark: " << highWatermark << "\n"; EV << "pause time: " << pauseUnits << "\n"; EV << "\n"; }
void MACRelayUnitPP::processFrame | ( | cMessage * | msg | ) | [protected, virtual] |
Triggered when a frame has completed processing, it routes the frame to the appropriate port, and starts processing the next frame.
Definition at line 152 of file MACRelayUnitPP.cc.
Referenced by handleMessage().
{ // Extract frame from the appropriate buffer; PortBuffer *pBuff = (PortBuffer*)msg->getContextPointer(); EtherFrame *frame = (EtherFrame*)pBuff->queue.pop(); long length = frame->getByteLength(); int inputport = pBuff->port; EV << "Port CPU " << inputport << " completed processing of frame " << frame << endl; handleAndDispatchFrame(frame, inputport); printAddressTable(); bufferUsed -= length; bufferLevel.record(bufferUsed); numProcessedFrames++; // Process next frame in queue if they are pending if (!pBuff->queue.empty()) { EV << "Begin processing of next frame\n"; scheduleAt(simTime()+processingTime, msg); } else { EV << "Port CPU idle\n"; pBuff->cpuBusy = false; delete msg; } }
PortBuffer* MACRelayUnitPP::buffer [protected] |
Definition at line 55 of file MACRelayUnitPP.h.
Referenced by handleIncomingFrame(), initialize(), MACRelayUnitPP(), and ~MACRelayUnitPP().
cOutVector MACRelayUnitPP::bufferLevel [protected] |
Definition at line 61 of file MACRelayUnitPP.h.
Referenced by handleIncomingFrame(), initialize(), and processFrame().
int MACRelayUnitPP::bufferSize [protected] |
Definition at line 48 of file MACRelayUnitPP.h.
Referenced by handleIncomingFrame(), and initialize().
int MACRelayUnitPP::bufferUsed [protected] |
Definition at line 54 of file MACRelayUnitPP.h.
Referenced by handleIncomingFrame(), initialize(), and processFrame().
long MACRelayUnitPP::highWatermark [protected] |
Definition at line 49 of file MACRelayUnitPP.h.
Referenced by handleIncomingFrame(), and initialize().
long MACRelayUnitPP::numDroppedFrames [protected] |
Definition at line 60 of file MACRelayUnitPP.h.
Referenced by finish(), handleIncomingFrame(), and initialize().
long MACRelayUnitPP::numProcessedFrames [protected] |
Definition at line 59 of file MACRelayUnitPP.h.
Referenced by finish(), initialize(), and processFrame().
simtime_t MACRelayUnitPP::pauseInterval [protected] |
Definition at line 51 of file MACRelayUnitPP.h.
Referenced by handleIncomingFrame(), and initialize().
simtime_t MACRelayUnitPP::pauseLastSent [protected] |
Definition at line 56 of file MACRelayUnitPP.h.
Referenced by handleIncomingFrame(), and initialize().
int MACRelayUnitPP::pauseUnits [protected] |
Definition at line 50 of file MACRelayUnitPP.h.
Referenced by handleIncomingFrame(), and initialize().
simtime_t MACRelayUnitPP::processingTime [protected] |
Definition at line 47 of file MACRelayUnitPP.h.
Referenced by handleIncomingFrame(), initialize(), and processFrame().