INET Framework for OMNeT++/OMNEST
inet::MACRelayUnit Class Reference

#include <MACRelayUnit.h>

Inheritance diagram for inet::MACRelayUnit:
inet::ILifecycle

Public Member Functions

virtual bool handleOperationStage (LifecycleOperation *operation, int stage, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 

Protected Member Functions

virtual void initialize (int stage) override
 
virtual int numInitStages () const override
 
virtual void handleAndDispatchFrame (EtherFrame *frame)
 Updates address table with source address, determines output port and sends out (or broadcasts) frame on ports. More...
 
virtual void broadcastFrame (EtherFrame *frame, int inputport)
 Utility function: sends the frame on all ports except inputport. More...
 
virtual void handleMessage (cMessage *msg) override
 Calls handleIncomingFrame() for frames arrived from outside, and processFrame() for self messages. More...
 
virtual void finish () override
 Writes statistics. More...
 
virtual void start ()
 
virtual void stop ()
 

Protected Attributes

IMACAddressTableaddressTable = nullptr
 
int numPorts = 0
 
long numProcessedFrames = 0
 
long numDiscardedFrames = 0
 
bool isOperational = false
 

Member Function Documentation

void inet::MACRelayUnit::broadcastFrame ( EtherFrame frame,
int  inputport 
)
protectedvirtual

Utility function: sends the frame on all ports except inputport.

The message pointer should not be referenced any more after this call.

Referenced by handleAndDispatchFrame().

103 {
104  for (int i = 0; i < numPorts; ++i) {
105  if (i != inputport) {
107  send(frame->dup(), "ifOut", i);
108  }
109  }
110 
111  delete frame;
112 }
static simsignal_t packetSentToLowerSignal
Definition: LayeredProtocolBase.h:32
int numPorts
Definition: MACRelayUnit.h:32
void inet::MACRelayUnit::finish ( )
overrideprotectedvirtual

Writes statistics.

153 {
154  recordScalar("processed frames", numProcessedFrames);
155  recordScalar("discarded frames", numDiscardedFrames);
156 }
long numDiscardedFrames
Definition: MACRelayUnit.h:36
long numProcessedFrames
Definition: MACRelayUnit.h:35
void inet::MACRelayUnit::handleAndDispatchFrame ( EtherFrame frame)
protectedvirtual

Updates address table with source address, determines output port and sends out (or broadcasts) frame on ports.

Includes calls to updateTableWithAddress() and getPortForAddress().

The message pointer should not be referenced any more after this call.

Referenced by handleMessage().

63 {
64  int inputport = frame->getArrivalGate()->getIndex();
65 
67 
68  // update address table
69  addressTable->updateTableWithAddress(inputport, frame->getSrc());
70 
71  // handle broadcast frames first
72  if (frame->getDest().isBroadcast()) {
73  EV << "Broadcasting broadcast frame " << frame << endl;
74  broadcastFrame(frame, inputport);
75  return;
76  }
77 
78  // Finds output port of destination address and sends to output port
79  // if not found then broadcasts to all other ports instead
80  int outputport = addressTable->getPortForAddress(frame->getDest());
81  // should not send out the same frame on the same ethernet port
82  // (although wireless ports are ok to receive the same message)
83  if (inputport == outputport) {
84  EV << "Output port is same as input port, " << frame->getFullName()
85  << " dest " << frame->getDest() << ", discarding frame\n";
87  delete frame;
88  return;
89  }
90 
91  if (outputport >= 0) {
92  EV << "Sending frame " << frame << " with dest address " << frame->getDest() << " to port " << outputport << endl;
94  send(frame, "ifOut", outputport);
95  }
96  else {
97  EV << "Dest address " << frame->getDest() << " unknown, broadcasting frame " << frame << endl;
98  broadcastFrame(frame, inputport);
99  }
100 }
virtual void broadcastFrame(EtherFrame *frame, int inputport)
Utility function: sends the frame on all ports except inputport.
Definition: MACRelayUnit.cc:102
static simsignal_t packetSentToLowerSignal
Definition: LayeredProtocolBase.h:32
long numDiscardedFrames
Definition: MACRelayUnit.h:36
long numProcessedFrames
Definition: MACRelayUnit.h:35
virtual int getPortForAddress(MACAddress &address, unsigned int vid=0)=0
For a known arriving port, V-TAG and destination MAC.
IMACAddressTable * addressTable
Definition: MACRelayUnit.h:31
virtual bool updateTableWithAddress(int portno, MACAddress &address, unsigned int vid=0)=0
Register a new MAC address at AddressTable.
void inet::MACRelayUnit::handleMessage ( cMessage *  msg)
overrideprotectedvirtual

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

50 {
51  if (!isOperational) {
52  EV << "Message '" << msg << "' arrived when module status is down, dropped it\n";
53  delete msg;
54  return;
55  }
56  EtherFrame *frame = check_and_cast<EtherFrame *>(msg);
57  // Frame received from MAC unit
60 }
virtual void handleAndDispatchFrame(EtherFrame *frame)
Updates address table with source address, determines output port and sends out (or broadcasts) frame...
Definition: MACRelayUnit.cc:62
bool isOperational
Definition: MACRelayUnit.h:38
static simsignal_t packetReceivedFromLowerSignal
Definition: LayeredProtocolBase.h:33
bool inet::MACRelayUnit::handleOperationStage ( LifecycleOperation operation,
int  stage,
IDoneCallback doneCallback 
)
overridevirtual

Perform one stage of a lifecycle operation.

Processing may be done entirely within this method, or may be a longer process that involves nonzero simulation time or several events, and is triggered by this method call.

Return value: true = "done"; false = "not yet done, will invoke doneCallback when done"

Implements inet::ILifecycle.

127 {
128  Enter_Method_Silent();
129 
130  if (dynamic_cast<NodeStartOperation *>(operation)) {
132  start();
133  }
134  }
135  else if (dynamic_cast<NodeShutdownOperation *>(operation)) {
137  stop();
138  }
139  }
140  else if (dynamic_cast<NodeCrashOperation *>(operation)) {
142  stop();
143  }
144  }
145  else {
146  throw cRuntimeError("Unsupported operation '%s'", operation->getClassName());
147  }
148 
149  return true;
150 }
Definition: NodeOperations.h:49
Stage
Definition: NodeOperations.h:71
Stage
Definition: NodeOperations.h:126
virtual void start()
Definition: MACRelayUnit.cc:114
virtual void stop()
Definition: MACRelayUnit.cc:120
Stage
Definition: NodeOperations.h:46
Definition: NodeOperations.h:127
Definition: NodeOperations.h:77
void inet::MACRelayUnit::initialize ( int  stage)
overrideprotectedvirtual
29 {
30  if (stage == INITSTAGE_LOCAL) {
31  // number of ports
32  numPorts = gate("ifOut", 0)->size();
33  if (gate("ifIn", 0)->size() != numPorts)
34  throw cRuntimeError("the sizes of the ifIn[] and ifOut[] gate vectors must be the same");
35 
37 
38  addressTable = check_and_cast<IMACAddressTable *>(getModuleByPath(par("macTablePath")));
39 
40  WATCH(numProcessedFrames);
41  WATCH(numDiscardedFrames);
42  }
43  else if (stage == INITSTAGE_LINK_LAYER) {
44  NodeStatus *nodeStatus = dynamic_cast<NodeStatus *>(findContainingNode(this)->getSubmodule("status"));
45  isOperational = (!nodeStatus) || nodeStatus->getState() == NodeStatus::UP;
46  }
47 }
bool isOperational
Definition: MACRelayUnit.h:38
cModule * findContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:56
Local initializations.
Definition: InitStages.h:35
Initialization of link-layer protocols.
Definition: InitStages.h:59
long numDiscardedFrames
Definition: MACRelayUnit.h:36
long numProcessedFrames
Definition: MACRelayUnit.h:35
int numPorts
Definition: MACRelayUnit.h:32
IMACAddressTable * addressTable
Definition: MACRelayUnit.h:31
Definition: NodeStatus.h:40
virtual int inet::MACRelayUnit::numInitStages ( ) const
inlineoverrideprotectedvirtual
42 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::MACRelayUnit::start ( )
protectedvirtual

Referenced by handleOperationStage().

115 {
117  isOperational = true;
118 }
virtual void clearTable()=0
For lifecycle: clears all entries from the vlanAddressTable.
bool isOperational
Definition: MACRelayUnit.h:38
IMACAddressTable * addressTable
Definition: MACRelayUnit.h:31
void inet::MACRelayUnit::stop ( )
protectedvirtual

Referenced by handleOperationStage().

121 {
123  isOperational = false;
124 }
virtual void clearTable()=0
For lifecycle: clears all entries from the vlanAddressTable.
bool isOperational
Definition: MACRelayUnit.h:38
IMACAddressTable * addressTable
Definition: MACRelayUnit.h:31

Member Data Documentation

IMACAddressTable* inet::MACRelayUnit::addressTable = nullptr
protected
bool inet::MACRelayUnit::isOperational = false
protected

Referenced by handleMessage(), initialize(), start(), and stop().

long inet::MACRelayUnit::numDiscardedFrames = 0
protected
int inet::MACRelayUnit::numPorts = 0
protected

Referenced by broadcastFrame(), and initialize().

long inet::MACRelayUnit::numProcessedFrames = 0
protected

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