EtherHub Class Reference

#include <EtherHub.h>

List of all members.


Detailed Description

Models a wiring hub. It simply broadcasts the received message on all other ports.

Protected Member Functions

virtual void initialize ()
virtual void handleMessage (cMessage *)
virtual void finish ()

Protected Attributes

int ports
long numMessages

Member Function Documentation

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

00032 {
00033     numMessages = 0;
00034     WATCH(numMessages);
00035 
00036     ports = gateSize("ethg");
00037 
00038     // autoconfig: tell everyone that full duplex is not possible over shared media
00039     EV << "Autoconfig: advertising that we only support half-duplex operation\n";
00040     for (int i=0; i<ports; i++)
00041     {
00042         EtherAutoconfig *autoconf = new EtherAutoconfig("autoconf-halfduplex");
00043         autoconf->setHalfDuplex(true);
00044         send(autoconf,"ethg$o",i);
00045     }
00046 }

void EtherHub::handleMessage ( cMessage *  msg  )  [protected, virtual]

00049 {
00050     // Handle frame sent down from the network entity: send out on every other port
00051     int arrivalPort = msg->getArrivalGate()->getIndex();
00052     EV << "Frame " << msg << " arrived on port " << arrivalPort << ", broadcasting on all other ports\n";
00053 
00054     numMessages++;
00055 
00056     if (ports<=1)
00057     {
00058         delete msg;
00059         return;
00060     }
00061     for (int i=0; i<ports; i++)
00062     {
00063         if (i!=arrivalPort)
00064         {
00065             bool isLast = (arrivalPort==ports-1) ? (i==ports-2) : (i==ports-1);
00066             cMessage *msg2 = isLast ? msg : (cMessage*) msg->dup();
00067             send(msg2,"ethg$o",i);
00068         }
00069     }
00070 }

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

00073 {
00074     simtime_t t = simTime();
00075     recordScalar("simulated time", t);
00076     recordScalar("messages handled", numMessages);
00077     if (t>0)
00078         recordScalar("messages/sec", numMessages/t);
00079 }


Member Data Documentation

int EtherHub::ports [protected]

Referenced by handleMessage(), and initialize().

long EtherHub::numMessages [protected]

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


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

Generated on Fri Mar 20 18:51:18 2009 for INET Framework for OMNeT++/OMNEST by  doxygen 1.5.5