INET Framework for OMNeT++/OMNEST
MACRelayUnitPP Class Reference

#include <MACRelayUnitPP.h>

Inheritance diagram for MACRelayUnitPP:
MACRelayUnitBase

List of all members.

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
PortBufferbuffer
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.


Constructor & Destructor Documentation

MACRelayUnitPP::MACRelayUnitPP ( )
{
    buffer = NULL;
}
MACRelayUnitPP::~MACRelayUnitPP ( ) [virtual]
{
    delete [] buffer;
}

Member Function Documentation

void MACRelayUnitPP::finish ( ) [protected, virtual]

Writes statistics.

{
    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.

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.

{
    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.

{
    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.

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;
    }
}

Member Data Documentation

int MACRelayUnitPP::bufferSize [protected]

Referenced by handleIncomingFrame(), and initialize().

simtime_t MACRelayUnitPP::pauseInterval [protected]

Referenced by handleIncomingFrame(), and initialize().

simtime_t MACRelayUnitPP::pauseLastSent [protected]

Referenced by handleIncomingFrame(), and initialize().

int MACRelayUnitPP::pauseUnits [protected]

Referenced by handleIncomingFrame(), and initialize().


The documentation for this class was generated from the following files: