|
INET Framework for OMNeT++/OMNEST
|
Performs Ethernet II encapsulation/decapsulation.
More...
#include <EthernetEncapsulation.h>
Performs Ethernet II encapsulation/decapsulation.
More info in the NED file.
◆ ~EthernetEncapsulation()
| inet::EthernetEncapsulation::~EthernetEncapsulation |
( |
| ) |
|
|
protectedvirtual |
◆ clearSockets()
| void inet::EthernetEncapsulation::clearSockets |
( |
| ) |
|
|
protectedvirtual |
◆ handleCrashOperation()
◆ handleMessageWhenUp()
| void inet::EthernetEncapsulation::handleMessageWhenUp |
( |
cMessage * |
message | ) |
|
|
overrideprotectedvirtual |
Implements inet::OperationalMixin< cSimpleModule >.
94 if (msg->arrivedOn(
"upperLayerIn")) {
96 EV_INFO <<
"Received " << msg <<
" from upper layer." << endl;
102 else if (msg->arrivedOn(
"lowerLayerIn")) {
103 EV_INFO <<
"Received " << msg <<
" from lower layer." << endl;
107 throw cRuntimeError(
"Unknown gate");
◆ handleRegisterAnyProtocol()
| void inet::EthernetEncapsulation::handleRegisterAnyProtocol |
( |
cGate * |
gate, |
|
|
ServicePrimitive |
servicePrimitive |
|
) |
| |
|
overrideprotectedvirtual |
◆ handleRegisterProtocol()
| void inet::EthernetEncapsulation::handleRegisterProtocol |
( |
const Protocol & |
protocol, |
|
|
cGate * |
gate, |
|
|
ServicePrimitive |
servicePrimitive |
|
) |
| |
|
overrideprotectedvirtual |
◆ handleRegisterService()
| void inet::EthernetEncapsulation::handleRegisterService |
( |
const Protocol & |
protocol, |
|
|
cGate * |
gate, |
|
|
ServicePrimitive |
servicePrimitive |
|
) |
| |
|
overrideprotectedvirtual |
◆ handleSendPause()
| void inet::EthernetEncapsulation::handleSendPause |
( |
cMessage * |
msg | ) |
|
|
protectedvirtual |
273 Ieee802PauseCommand *etherctrl =
dynamic_cast<Ieee802PauseCommand *
>(msg->getControlInfo());
275 throw cRuntimeError(
"PAUSE command `%s' from higher layer received without Ieee802PauseCommand controlinfo", msg->getName());
276 MacAddress dest = etherctrl->getDestinationAddress();
277 int pauseUnits = etherctrl->getPauseUnits();
280 EV_DETAIL <<
"Creating and sending PAUSE frame, with duration = " << pauseUnits <<
" units\n";
284 sprintf(framename,
"pause-%d-%d", getId(),
seqNum++);
285 auto packet =
new Packet(framename);
286 const auto& frame = makeShared<EthernetPauseFrame>();
287 const auto& hdr = makeShared<EthernetMacHeader>();
288 frame->setPauseTime(pauseUnits);
289 if (dest.isUnspecified())
292 packet->insertAtFront(frame);
294 packet->insertAtFront(hdr);
295 const auto& ethernetFcs = makeShared<EthernetFcs>();
296 ethernetFcs->setFcsMode(
fcsMode);
297 packet->insertAtBack(ethernetFcs);
300 EV_INFO <<
"Sending " << frame <<
" to lower layer.\n";
301 send(packet,
"lowerLayerOut");
Referenced by processCommandFromHigherLayer().
◆ handleStartOperation()
◆ handleStopOperation()
◆ initialize()
| void inet::EthernetEncapsulation::initialize |
( |
int |
stage | ) |
|
|
overrideprotectedvirtual |
◆ isInitializeStage()
| virtual bool inet::EthernetEncapsulation::isInitializeStage |
( |
int |
stage | ) |
const |
|
inlineoverrideprotectedvirtual |
◆ isModuleStartStage()
| virtual bool inet::EthernetEncapsulation::isModuleStartStage |
( |
int |
stage | ) |
const |
|
inlineoverrideprotectedvirtual |
◆ isModuleStopStage()
| virtual bool inet::EthernetEncapsulation::isModuleStopStage |
( |
int |
stage | ) |
const |
|
inlineoverrideprotectedvirtual |
◆ numInitStages()
| virtual int inet::EthernetEncapsulation::numInitStages |
( |
| ) |
const |
|
inlineoverrideprotectedvirtual |
◆ processCommandFromHigherLayer()
| void inet::EthernetEncapsulation::processCommandFromHigherLayer |
( |
Request * |
msg | ) |
|
|
protectedvirtual |
113 auto ctrl = msg->getControlInfo();
114 if (
dynamic_cast<Ieee802PauseCommand *
>(
ctrl) !=
nullptr)
116 else if (
auto bindCommand =
dynamic_cast<EthernetBindCommand *
>(
ctrl)) {
117 int socketId = check_and_cast<Request *>(msg)->getTag<SocketReq>()->getSocketId();
118 Socket *socket =
new Socket(socketId);
119 socket->interfaceId = msg->getTag<
InterfaceReq>()->getInterfaceId();
120 socket->localAddress = bindCommand->getLocalAddress();
121 socket->remoteAddress = bindCommand->getRemoteAddress();
122 socket->protocol = bindCommand->getProtocol();
123 socket->steal = bindCommand->getSteal();
127 else if (
dynamic_cast<SocketCloseCommand *
>(
ctrl) !=
nullptr) {
128 int socketId = check_and_cast<Request *>(msg)->getTag<SocketReq>()->getSocketId();
134 auto ctrl =
new SocketClosedIndication();
135 indication->setControlInfo(
ctrl);
136 indication->addTag<SocketInd>()->setSocketId(socketId);
137 send(indication,
"transportOut");
141 else if (
dynamic_cast<SocketDestroyCommand *
>(
ctrl) !=
nullptr) {
142 int socketId = check_and_cast<Request *>(msg)->getTag<SocketReq>()->getSocketId();
151 throw cRuntimeError(
"Unknown command: '%s' with %s", msg->getName(),
ctrl->getClassName());
Referenced by handleMessageWhenUp().
◆ processPacketFromHigherLayer()
| void inet::EthernetEncapsulation::processPacketFromHigherLayer |
( |
Packet * |
msg | ) |
|
|
protectedvirtual |
165 throw cRuntimeError(
"packet length from higher layer (%s) exceeds maximum Ethernet payload length (%s)", packet->getDataLength().str().c_str(),
MAX_ETHERNET_DATA_BYTES.
str().c_str());
174 EV_DETAIL <<
"Encapsulating higher layer packet `" << packet->getName() <<
"' for MAC\n";
176 int typeOrLength = -1;
178 const Protocol *
protocol = protocolTag->getProtocol();
182 typeOrLength = packet->getByteLength();
184 const auto& ethHeader = makeShared<EthernetMacHeader>();
185 auto macAddressReq = packet->getTag<MacAddressReq>();
186 auto srcAddr = macAddressReq->getSrcAddress();
189 ethHeader->setSrc(srcAddr);
190 ethHeader->setDest(macAddressReq->getDestAddress());
191 ethHeader->setTypeOrLength(typeOrLength);
192 packet->insertAtFront(ethHeader);
193 const auto& ethernetFcs = makeShared<EthernetFcs>();
194 ethernetFcs->setFcsMode(
fcsMode);
195 packet->insertAtBack(ethernetFcs);
198 EV_INFO <<
"Sending " << packet <<
" to lower layer.\n";
199 send(packet,
"lowerLayerOut");
Referenced by handleMessageWhenUp().
◆ processPacketFromMac()
| void inet::EthernetEncapsulation::processPacketFromMac |
( |
Packet * |
packet | ) |
|
|
protectedvirtual |
204 const Protocol *payloadProtocol =
nullptr;
206 int iface = packet->getTag<InterfaceInd>()->getInterfaceId();
207 auto ethHeader = packet->popAtFront<EthernetMacHeader>();
211 auto macAddressInd = packet->addTagIfAbsent<MacAddressInd>();
212 macAddressInd->setSrcAddress(ethHeader->getSrc());
213 macAddressInd->setDestAddress(ethHeader->getDest());
217 b payloadLength =
B(ethHeader->getTypeOrLength());
218 if (packet->getDataLength() < payloadLength)
219 throw cRuntimeError(
"incorrect payload length in ethernet frame");
220 packet->setBackOffset(packet->getFrontOffset() + payloadLength);
227 throw cRuntimeError(
"Unknown ethernet header");
229 if (payloadProtocol !=
nullptr) {
239 auto socket = it.second;
240 if (socket->matches(packet, iface, ethHeader)) {
241 auto packetCopy = packet->dup();
243 packetCopy->addTagIfAbsent<SocketInd>()->setSocketId(it.first);
244 EV_INFO <<
"Sending " << packetCopy <<
" to socket " << it.first <<
".\n";
245 send(packetCopy,
"upperLayerOut");
246 steal |= socket->steal;
252 EV_DETAIL <<
"Decapsulating frame `" << packet->getName() <<
"', passing up contained packet `"
253 << packet->getName() <<
"' to higher layer\n";
259 EV_INFO <<
"Sending " << packet <<
" to upper layer.\n";
260 send(packet,
"upperLayerOut");
263 EV_WARN <<
"Unknown protocol, dropping packet\n";
264 PacketDropDetails details;
Referenced by handleMessageWhenUp().
◆ refreshDisplay()
| void inet::EthernetEncapsulation::refreshDisplay |
( |
| ) |
const |
|
overrideprotectedvirtual |
159 getDisplayString().setTagArg(
"t", 0, buf);
◆ operator<<
| std::ostream& operator<< |
( |
std::ostream & |
o, |
|
|
const Socket & |
t |
|
) |
| |
|
friend |
38 o <<
"(id:" << t.socketId
39 <<
",interfaceId:" << t.interfaceId
40 <<
",local:" << t.localAddress
41 <<
",remote:" << t.remoteAddress
42 <<
",protocol" << (t.protocol ? t.protocol->getName() :
"<null>")
43 <<
",steal:" << (t.steal ?
"on" :
"off")
◆ anyUpperProtocols
| bool inet::EthernetEncapsulation::anyUpperProtocols = false |
|
protected |
◆ decapPkSignal
| simsignal_t inet::EthernetEncapsulation::decapPkSignal = registerSignal("decapPk") |
|
staticprotected |
◆ encapPkSignal
| simsignal_t inet::EthernetEncapsulation::encapPkSignal = registerSignal("encapPk") |
|
staticprotected |
◆ fcsMode
◆ networkInterface
◆ pauseSentSignal
| simsignal_t inet::EthernetEncapsulation::pauseSentSignal = registerSignal("pauseSent") |
|
staticprotected |
◆ seqNum
| int inet::EthernetEncapsulation::seqNum |
|
protected |
◆ socketIdToSocketMap
| std::map<int, Socket *> inet::EthernetEncapsulation::socketIdToSocketMap |
|
protected |
◆ totalFromHigherLayer
| long inet::EthernetEncapsulation::totalFromHigherLayer |
|
protected |
◆ totalFromMAC
| long inet::EthernetEncapsulation::totalFromMAC |
|
protected |
◆ totalPauseSent
| long inet::EthernetEncapsulation::totalPauseSent |
|
protected |
◆ upperProtocols
| std::set<const Protocol *> inet::EthernetEncapsulation::upperProtocols |
|
protected |
The documentation for this class was generated from the following files:
int getProtocolNumber(const Protocol *protocol) const
Definition: ProtocolGroup.cc:46
std::string str() const
Definition: Units.h:101
bool isEth2Header(const EthernetMacHeader &hdr)
Definition: EthernetMacHeader_m.h:228
static const MacAddress MULTICAST_PAUSE_ADDRESS
The special multicast PAUSE MAC address, 01:80:C2:00:00:01.
Definition: MacAddress.h:37
int seqNum
Definition: EthernetEncapsulation.h:32
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down protocol
Definition: IUdp-gates.txt:25
NetworkInterface * findContainingNicModule(const cModule *from)
Find the nic module (inside the networkNode) containing the given module.
Definition: NetworkInterface.cc:679
const MacAddress & getMacAddress() const
Definition: NetworkInterface.h:245
const B ETHER_FCS_BYTES
Definition: Ethernet.h:59
std::map< int, Socket * > socketIdToSocketMap
Definition: EthernetEncapsulation.h:56
virtual void initialize(int stage) override
Definition: OperationalMixinImpl.h:26
const Protocol * findProtocol(int protocolNumber) const
Definition: ProtocolGroup.cc:25
bool isIeee8023Header(const EthernetMacHeader &hdr)
Definition: EthernetMacHeader_m.h:229
removed InterfaceReq
Definition: IUdp-gates.txt:11
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down DispatchProtocolReq
Definition: IUdp-gates.txt:25
@ ETHERTYPE_FLOW_CONTROL
Definition: EtherType_m.h:92
bool anyUpperProtocols
Definition: EthernetEncapsulation.h:57
void registerService(const Protocol &protocol, cGate *gate, ServicePrimitive servicePrimitive)
Registers a service primitive (SDU processing) at the given gate.
Definition: IProtocolRegistrationListener.cc:14
simsignal_t packetDroppedSignal
Definition: Simsignals.cc:85
static const Protocol ieee8022llc
Definition: Protocol.h:88
virtual void clearSockets()
Definition: EthernetEncapsulation.cc:307
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down PacketProtocolTag
Definition: IUdp-gates.txt:25
virtual void handleSendPause(cMessage *msg)
Definition: EthernetEncapsulation.cc:271
removed ctrl
Definition: IUdp-gates.txt:7
long totalFromHigherLayer
Definition: EthernetEncapsulation.h:35
intscale< b, 1, 8 > B
Definition: Units.h:1168
bool contains(const std::vector< T > &v, const Tk &a)
Definition: stlutils.h:65
static const Protocol ethernetMac
Definition: Protocol.h:65
@ SOCKET_I_DATA
Definition: SocketCommand_m.h:85
@ STAGE_LINK_LAYER
Definition: ModuleOperations.h:54
virtual void processPacketFromMac(Packet *packet)
Definition: EthernetEncapsulation.cc:202
std::set< const Protocol * > upperProtocols
Definition: EthernetEncapsulation.h:28
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
value< int64_t, units::b > b
Definition: Units.h:1241
@ NO_PROTOCOL_FOUND
Definition: Simsignals_m.h:81
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
static simsignal_t encapPkSignal
Definition: EthernetEncapsulation.h:38
long totalPauseSent
Definition: EthernetEncapsulation.h:37
const B MAX_ETHERNET_DATA_BYTES
Definition: Ethernet.h:20
@ SOCKET_I_CLOSED
Definition: SocketCommand_m.h:86
virtual void processPacketFromHigherLayer(Packet *msg)
Definition: EthernetEncapsulation.cc:162
#define Enter_Method(...)
Definition: SelfDoc.h:71
static simsignal_t pauseSentSignal
Definition: EthernetEncapsulation.h:40
FcsMode parseFcsMode(const char *fcsModeString)
Definition: FcsMode.cc:14
virtual void processCommandFromHigherLayer(Request *msg)
Definition: EthernetEncapsulation.cc:110
FcsMode fcsMode
Definition: EthernetEncapsulation.h:31
NetworkInterface * networkInterface
Definition: EthernetEncapsulation.h:41
@ STAGE_LINK_LAYER
Definition: ModuleOperations.h:28
virtual void refreshDisplay() const override
Definition: OperationalMixinImpl.h:200
void registerProtocol(const Protocol &protocol, cGate *gate, ServicePrimitive servicePrimitive)
Registers a protocol primitive (PDU processing) at the given gate.
Definition: IProtocolRegistrationListener.cc:83
static simsignal_t decapPkSignal
Definition: EthernetEncapsulation.h:39
INET_API InitStage INITSTAGE_LINK_LAYER
Initialization of link-layer protocols.
long totalFromMAC
Definition: EthernetEncapsulation.h:36
static ProtocolGroup ethertype
Definition: ProtocolGroup.h:40