Public Member Functions | Protected Member Functions | Protected Attributes

MACRelayUnitNP Class Reference

#include <MACRelayUnitNP.h>

Inheritance diagram for MACRelayUnitNP:
MACRelayUnitBase

List of all members.

Public Member Functions

 MACRelayUnitNP ()
virtual ~MACRelayUnitNP ()

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

cQueue queue
int numCPUs
simtime_t processingTime
int bufferSize
long highWatermark
int pauseUnits
simtime_t pauseInterval
int bufferUsed
cMessage ** endProcEvents
simtime_t pauseLastSent
long numProcessedFrames
long numDroppedFrames
cOutVector bufferLevel

Detailed Description

An implementation of the MAC Relay Unit that assumes a shared memory and N CPUs in the switch. The CPUs process frames from a single shared queue.

Definition at line 30 of file MACRelayUnitNP.h.


Constructor & Destructor Documentation

MACRelayUnitNP::MACRelayUnitNP (  ) 

Definition at line 35 of file MACRelayUnitNP.cc.

{
    endProcEvents = NULL;
    numCPUs = 0;
}

MACRelayUnitNP::~MACRelayUnitNP (  )  [virtual]

Definition at line 41 of file MACRelayUnitNP.cc.

{
    for (int i=0; i<numCPUs; i++)
    {
        cMessage *endProcEvent = endProcEvents[i];
        EtherFrame *etherFrame = (EtherFrame *)endProcEvent->getContextPointer();
        if (etherFrame)
        {
            endProcEvent->setContextPointer(NULL);
            delete etherFrame;
        }
        cancelAndDelete(endProcEvent);
    }
    delete [] endProcEvents;
}


Member Function Documentation

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

Writes statistics.

Definition at line 201 of file MACRelayUnitNP.cc.

{
    recordScalar("processed frames", numProcessedFrames);
    recordScalar("dropped frames", numDroppedFrames);
}

void MACRelayUnitNP::handleIncomingFrame ( EtherFrame *  msg  )  [protected, virtual]

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

Definition at line 119 of file MACRelayUnitNP.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)
    {
        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();
        }

        // assign frame to a free CPU (if there is one)
        int i;
        for (i=0; i<numCPUs; i++)
            if (!endProcEvents[i]->isScheduled())
                break;
        if (i==numCPUs)
        {
            EV << "All CPUs busy, enqueueing incoming frame " << frame << " for later processing\n";
            queue.insert(frame);
        }
        else
        {
            EV << "Idle CPU-" << i << " starting processing of incoming frame " << frame << endl;
            cMessage *msg = endProcEvents[i];
            ASSERT(msg->getContextPointer()==NULL);
            msg->setContextPointer(frame);
            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 MACRelayUnitNP::handleMessage ( cMessage *  msg  )  [protected, virtual]

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

Definition at line 105 of file MACRelayUnitNP.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 finished processing
        processFrame(msg);
    }
}

void MACRelayUnitNP::initialize (  )  [protected, virtual]

Read parameters parameters.

Reimplemented from MACRelayUnitBase.

Definition at line 57 of file MACRelayUnitNP.cc.

{
    MACRelayUnitBase::initialize();

    bufferLevel.setName("buffer level");
    queue.setName("queue");

    numProcessedFrames = numDroppedFrames = 0;
    WATCH(numProcessedFrames);
    WATCH(numDroppedFrames);

    numCPUs = par("numCPUs");

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

    endProcEvents = new cMessage *[numCPUs];
    for (int i=0; i<numCPUs; i++)
    {
        char msgname[20];
        sprintf(msgname, "endProcessing-cpu%d", i);
        endProcEvents[i] = new cMessage(msgname,i);
    }

    EV << "Parameters of (" << getClassName() << ") " << getFullPath() << "\n";
    EV << "number of processors: " << numCPUs << "\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 MACRelayUnitNP::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 168 of file MACRelayUnitNP.cc.

Referenced by handleMessage().

{
    int cpu = msg->getKind();
    EtherFrame *frame = (EtherFrame *) msg->getContextPointer();
    ASSERT(frame);
    msg->setContextPointer(NULL);
    long length = frame->getByteLength();
    int inputport = frame->getArrivalGate()->getIndex();

    EV << "CPU-" << cpu << " 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 (!queue.empty())
    {
        EtherFrame *newframe = (EtherFrame *) queue.pop();
        msg->setContextPointer(newframe);
        EV << "CPU-" << cpu << " starting processing of frame " << newframe << endl;
        scheduleAt(simTime()+processingTime, msg);
    }
    else
    {
        EV << "CPU-" << cpu << " idle\n";
    }
}


Member Data Documentation

cOutVector MACRelayUnitNP::bufferLevel [protected]

Definition at line 56 of file MACRelayUnitNP.h.

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

int MACRelayUnitNP::bufferSize [protected]

Definition at line 43 of file MACRelayUnitNP.h.

Referenced by handleIncomingFrame(), and initialize().

int MACRelayUnitNP::bufferUsed [protected]

Definition at line 49 of file MACRelayUnitNP.h.

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

cMessage** MACRelayUnitNP::endProcEvents [protected]

Definition at line 50 of file MACRelayUnitNP.h.

Referenced by handleIncomingFrame(), initialize(), MACRelayUnitNP(), and ~MACRelayUnitNP().

Definition at line 44 of file MACRelayUnitNP.h.

Referenced by handleIncomingFrame(), and initialize().

int MACRelayUnitNP::numCPUs [protected]

Definition at line 41 of file MACRelayUnitNP.h.

Referenced by handleIncomingFrame(), initialize(), MACRelayUnitNP(), and ~MACRelayUnitNP().

Definition at line 55 of file MACRelayUnitNP.h.

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

Definition at line 54 of file MACRelayUnitNP.h.

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

simtime_t MACRelayUnitNP::pauseInterval [protected]

Definition at line 46 of file MACRelayUnitNP.h.

Referenced by handleIncomingFrame(), and initialize().

simtime_t MACRelayUnitNP::pauseLastSent [protected]

Definition at line 51 of file MACRelayUnitNP.h.

Referenced by handleIncomingFrame(), and initialize().

int MACRelayUnitNP::pauseUnits [protected]

Definition at line 45 of file MACRelayUnitNP.h.

Referenced by handleIncomingFrame(), and initialize().

simtime_t MACRelayUnitNP::processingTime [protected]

Definition at line 42 of file MACRelayUnitNP.h.

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

cQueue MACRelayUnitNP::queue [protected]

Definition at line 38 of file MACRelayUnitNP.h.

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


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