#include <EtherHub.h>
Protected Member Functions | |
| virtual void | initialize () |
| virtual void | handleMessage (cMessage *) |
| virtual void | finish () |
Protected Attributes | |
| int | ports |
| long | numMessages |
Models a wiring hub. It simply broadcasts the received message on all other ports.
Definition at line 27 of file EtherHub.h.
| void EtherHub::finish | ( | ) | [protected, virtual] |
Definition at line 72 of file EtherHub.cc.
{
simtime_t t = simTime();
recordScalar("simulated time", t);
recordScalar("messages handled", numMessages);
if (t>0)
recordScalar("messages/sec", numMessages/t);
}
| void EtherHub::handleMessage | ( | cMessage * | msg | ) | [protected, virtual] |
Definition at line 48 of file EtherHub.cc.
{
// Handle frame sent down from the network entity: send out on every other port
int arrivalPort = msg->getArrivalGate()->getIndex();
EV << "Frame " << msg << " arrived on port " << arrivalPort << ", broadcasting on all other ports\n";
numMessages++;
if (ports<=1)
{
delete msg;
return;
}
for (int i=0; i<ports; i++)
{
if (i!=arrivalPort)
{
bool isLast = (arrivalPort==ports-1) ? (i==ports-2) : (i==ports-1);
cMessage *msg2 = isLast ? msg : (cMessage*) msg->dup();
send(msg2,"ethg$o",i);
}
}
}
| void EtherHub::initialize | ( | ) | [protected, virtual] |
Definition at line 31 of file EtherHub.cc.
{
numMessages = 0;
WATCH(numMessages);
ports = gateSize("ethg");
// autoconfig: tell everyone that full duplex is not possible over shared media
EV << "Autoconfig: advertising that we only support half-duplex operation\n";
for (int i=0; i<ports; i++)
{
EtherAutoconfig *autoconf = new EtherAutoconfig("autoconf-halfduplex");
autoconf->setHalfDuplex(true);
send(autoconf,"ethg$o",i);
}
}
long EtherHub::numMessages [protected] |
Definition at line 31 of file EtherHub.h.
Referenced by finish(), handleMessage(), and initialize().
int EtherHub::ports [protected] |
Definition at line 30 of file EtherHub.h.
Referenced by handleMessage(), and initialize().
1.7.1