Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

EtherHub Class Reference

List of all members.

Private Methods

 Module_Class_Members (EtherHub, cSimpleModule, 0)
virtual void initialize ()
virtual void handleMessage (cMessage *)
virtual void finish ()

Private Attributes

int ports
long numMessages

Detailed Description

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

Definition at line 33 of file EtherHub.cc.


Member Function Documentation

void EtherHub::finish   [private, virtual]
 

Definition at line 99 of file EtherHub.cc.

References numMessages.

00100 {
00101     if (par("writeScalars").boolValue())
00102     {
00103         double t = simTime();
00104         recordScalar("simulated time", t);
00105         recordScalar("messages handled", numMessages);
00106         if (t>0)
00107             recordScalar("messages/sec", numMessages/t);
00108     }
00109 }

void EtherHub::handleMessage cMessage *    [private, virtual]
 

Definition at line 75 of file EtherHub.cc.

References EV, numMessages, and ports.

00076 {
00077     // Handle frame sent down from the network entity: send out on every other port
00078     int arrivalPort = msg->arrivalGate()->index();
00079     EV << "Frame " << msg << " arrived on port " << arrivalPort << ", broadcasting on all other ports\n";
00080 
00081     numMessages++;
00082 
00083     if (ports<=1)
00084     {
00085         delete msg;
00086         return;
00087     }
00088     for (int i=0; i<ports; i++)
00089     {
00090         if (i!=arrivalPort)
00091         {
00092             bool isLast = (arrivalPort==ports-1) ? (i==ports-2) : (i==ports-1);
00093             cMessage *msg2 = isLast ? msg : (cMessage*) msg->dup();
00094             send(msg2,"out",i);
00095         }
00096     }
00097 }

void EtherHub::initialize   [private, virtual]
 

Definition at line 55 of file EtherHub.cc.

References EV, numMessages, ports, and EtherAutoconfig::setHalfDuplex().

00056 {
00057     numMessages = 0;
00058     WATCH(numMessages);
00059 
00060     ports = gate("in",0)->size();
00061     if (gate("out",0)->size()!=ports)
00062         error("the sizes of the in[] and out[] gate vectors must be the same");
00063 
00064 
00065     // autoconfig: tell everyone that full duplex is not possible over shared media
00066     EV << "Autoconfig: advertising that we only support half-duplex operation\n";
00067     for (int i=0; i<ports; i++)
00068     {
00069         EtherAutoconfig *autoconf = new EtherAutoconfig("autoconf-halfduplex");
00070         autoconf->setHalfDuplex(true);
00071         send(autoconf,"out",i);
00072     }
00073 }

EtherHub::Module_Class_Members EtherHub   ,
cSimpleModule   ,
 
[private]
 


Member Data Documentation

long EtherHub::numMessages [private]
 

Definition at line 43 of file EtherHub.cc.

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

int EtherHub::ports [private]
 

Definition at line 42 of file EtherHub.cc.

Referenced by handleMessage(), and initialize().


The documentation for this class was generated from the following file:
Generated on Sat May 15 20:30:47 2004 for Ethernet by doxygen1.2.17