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

#include <Ieee8022Llc.h>

Inheritance diagram for inet::Ieee8022Llc:
inet::OperationalBase inet::DefaultProtocolRegistrationListener inet::OperationalMixin< cSimpleModule > inet::IProtocolRegistrationListener inet::ILifecycle inet::ieee80211::Ieee80211LlcLpd

Classes

struct  SocketDescriptor
 

Public Member Functions

virtual ~Ieee8022Llc ()
 
- Public Member Functions inherited from inet::OperationalMixin< cSimpleModule >
virtual ~OperationalMixin ()
 }@ More...
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 
- Public Member Functions inherited from inet::DefaultProtocolRegistrationListener
virtual void handleRegisterServiceGroup (const ProtocolGroup &protocolGroup, cGate *gate, ServicePrimitive servicePrimitive) override
 
virtual void handleRegisterProtocolGroup (const ProtocolGroup &protocolGroup, cGate *gate, ServicePrimitive servicePrimitive) override
 
virtual void handleRegisterAnyService (cGate *gate, ServicePrimitive servicePrimitive) override
 
virtual void handleRegisterAnyProtocol (cGate *gate, ServicePrimitive servicePrimitive) override
 

Static Public Member Functions

static const ProtocolgetProtocol (const Ptr< const Ieee8022LlcHeader > &header)
 

Protected Member Functions

void clearSockets ()
 
virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
virtual void handleMessageWhenUp (cMessage *message) override
 
virtual void encapsulate (Packet *frame)
 
virtual void decapsulate (Packet *frame)
 
virtual void processPacketFromHigherLayer (Packet *msg)
 
virtual bool deliverCopyToSockets (Packet *packet)
 
virtual bool isDeliverableToUpperLayer (Packet *packet)
 
virtual void processPacketFromMac (Packet *packet)
 
virtual void processCommandFromHigherLayer (Request *request)
 
virtual void registerMyProtocol ()
 
virtual void handleRegisterService (const Protocol &protocol, cGate *gate, ServicePrimitive servicePrimitive) override
 
virtual void handleRegisterProtocol (const Protocol &protocol, cGate *gate, ServicePrimitive servicePrimitive) override
 
virtual bool isInitializeStage (int stage) const override
 
virtual bool isModuleStartStage (int stage) const override
 
virtual bool isModuleStopStage (int stage) const override
 
virtual void handleStartOperation (LifecycleOperation *operation) override
 
virtual void handleStopOperation (LifecycleOperation *operation) override
 
virtual void handleCrashOperation (LifecycleOperation *operation) override
 
- Protected Member Functions inherited from inet::OperationalMixin< cSimpleModule >
virtual int numInitStages () const override
 
virtual void refreshDisplay () const override
 
virtual void handleMessage (cMessage *msg) override
 
virtual void handleMessageWhenDown (cMessage *msg)
 
virtual bool handleOperationStage (LifecycleOperation *operation, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 
virtual State getInitialOperationalState () const
 Returns initial operational state: OPERATING or NOT_OPERATING. More...
 
virtual void handleActiveOperationTimeout (cMessage *message)
 
virtual bool isUp () const
 utility functions More...
 
virtual bool isDown () const
 
virtual void setOperationalState (State newState)
 
virtual void scheduleOperationTimeout (simtime_t timeout)
 
virtual void setupActiveOperation (LifecycleOperation *operation, IDoneCallback *doneCallback, State)
 
virtual void delayActiveOperationFinish (simtime_t timeout)
 
virtual void startActiveOperationExtraTime (simtime_t delay=SIMTIME_ZERO)
 
virtual void startActiveOperationExtraTimeOrFinish (simtime_t extraTime)
 
virtual void finishActiveOperation ()
 

Protected Attributes

std::set< const Protocol * > upperProtocols
 
std::map< int, SocketDescriptor * > socketIdToSocketDescriptor
 
- Protected Attributes inherited from inet::OperationalMixin< cSimpleModule >
State operationalState
 
simtime_t lastChange
 
Operation activeOperation
 
cMessage * activeOperationTimeout
 
cMessage * activeOperationExtraTimer
 

Friends

std::ostream & operator<< (std::ostream &o, const SocketDescriptor &t)
 

Additional Inherited Members

- Protected Types inherited from inet::OperationalMixin< cSimpleModule >
enum  State
 

Constructor & Destructor Documentation

◆ ~Ieee8022Llc()

inet::Ieee8022Llc::~Ieee8022Llc ( )
virtual
26 {
27  clearSockets();
28 }

Member Function Documentation

◆ clearSockets()

void inet::Ieee8022Llc::clearSockets ( )
protected
272 {
273  for (auto& elem : socketIdToSocketDescriptor) {
274  delete elem.second;
275  elem.second = nullptr;
276  }
278 }

Referenced by handleCrashOperation(), handleStartOperation(), handleStopOperation(), and ~Ieee8022Llc().

◆ decapsulate()

void inet::Ieee8022Llc::decapsulate ( Packet frame)
protectedvirtual
209 {
210  const auto& llcHeader = frame->popAtFront<Ieee8022LlcHeader>();
211 
212  auto sapInd = frame->addTagIfAbsent<Ieee802SapInd>();
213  sapInd->setSsap(llcHeader->getSsap());
214  sapInd->setDsap(llcHeader->getDsap());
215  // TODO control?
216 
217  if (llcHeader->getSsap() == 0xAA && llcHeader->getDsap() == 0xAA && llcHeader->getControl() == 0x03) {
218  const auto& snapHeader = dynamicPtrCast<const Ieee8022LlcSnapHeader>(llcHeader);
219  if (snapHeader == nullptr)
220  throw cRuntimeError("LLC header indicates SNAP header, but SNAP header is missing");
221  }
222  auto payloadProtocol = getProtocol(llcHeader);
223  if (payloadProtocol) {
224  frame->addTagIfAbsent<DispatchProtocolReq>()->setProtocol(payloadProtocol);
225  frame->addTagIfAbsent<PacketProtocolTag>()->setProtocol(payloadProtocol);
226  }
227  else {
228  frame->removeTagIfPresent<DispatchProtocolReq>();
229  frame->removeTagIfPresent<PacketProtocolTag>();
230  }
231 }

Referenced by processPacketFromMac().

◆ deliverCopyToSockets()

bool inet::Ieee8022Llc::deliverCopyToSockets ( Packet packet)
protectedvirtual
117 {
118  bool isSent = false;
119  if (auto sap = packet->findTag<Ieee802SapInd>()) {
120  int localSap = sap->getDsap();
121  int remoteSap = sap->getSsap();
122  for (const auto& elem : socketIdToSocketDescriptor) {
123  if ((elem.second->localSap == localSap || elem.second->localSap == -1)
124  && (elem.second->remoteSap == remoteSap || elem.second->remoteSap == -1))
125  {
126  auto *packetCopy = packet->dup();
127  packetCopy->addTagIfAbsent<SocketInd>()->setSocketId(elem.second->socketId);
128  EV_INFO << "Passing up to socket " << elem.second->socketId << "\n";
129  packetCopy->setKind(SOCKET_I_DATA);
130  send(packetCopy, "upperLayerOut");
131  isSent = true;
132  }
133  }
134  }
135  return isSent;
136 }

Referenced by processPacketFromMac().

◆ encapsulate()

void inet::Ieee8022Llc::encapsulate ( Packet frame)
protectedvirtual

Reimplemented in inet::ieee80211::Ieee80211LlcLpd.

164 {
165  const auto& sapReq = frame->findTag<Ieee802SapReq>();
166  const auto& protocolTag = frame->findTag<PacketProtocolTag>();
167  const Protocol *protocol = protocolTag ? protocolTag->getProtocol() : nullptr;
168  int ethType = -1;
169  int snapOui = -1;
170  if (sapReq == nullptr && protocol != nullptr) {
172  if (ethType == -1)
174  }
175  if (ethType != -1 || snapOui != -1) {
176  const auto& snapHeader = makeShared<Ieee8022LlcSnapHeader>();
177  if (ethType != -1) {
178  snapHeader->setOui(0);
179  snapHeader->setProtocolId(ethType);
180  }
181  else {
182  snapHeader->setOui(snapOui);
183  snapHeader->setProtocolId(-1); // FIXME get value from a tag (e.g. protocolTag->getSubId() ???)
184  }
185  frame->insertAtFront(snapHeader);
186  }
187  else {
188  const auto& llcHeader = makeShared<Ieee8022LlcHeader>();
190  if (sapReq == nullptr && sapData != -1) {
191  llcHeader->setSsap((sapData >> 8) & 0xFF);
192  llcHeader->setDsap(sapData & 0xFF);
193  llcHeader->setControl(3);
194  }
195  else if (sapReq != nullptr) {
196  llcHeader->setSsap(sapReq->getSsap());
197  llcHeader->setDsap(sapReq->getDsap());
198  llcHeader->setControl(3); // TODO get from sapTag
199  }
200  else
201  throw cRuntimeError("Missing the required Ieee802SapReq for LLC header, or protocol number for SNAP header.");
202  frame->insertAtFront(llcHeader);
203  }
204  frame->addTagIfAbsent<PacketProtocolTag>()->setProtocol(&Protocol::ieee8022llc);
205  frame->addTagIfAbsent<DispatchProtocolReq>()->setProtocol(&Protocol::ethernetMac);
206 }

Referenced by inet::ieee80211::Ieee80211LlcLpd::encapsulate(), and processPacketFromHigherLayer().

◆ getProtocol()

const Protocol * inet::Ieee8022Llc::getProtocol ( const Ptr< const Ieee8022LlcHeader > &  header)
static
234 {
235  const Protocol *payloadProtocol = nullptr;
236  if (llcHeader->getSsap() == 0xAA && llcHeader->getDsap() == 0xAA && llcHeader->getControl() == 0x03) {
237  const auto& snapHeader = dynamicPtrCast<const Ieee8022LlcSnapHeader>(llcHeader);
238  if (snapHeader == nullptr)
239  throw cRuntimeError("LLC header indicates SNAP header, but SNAP header is missing");
240  if (snapHeader->getOui() == 0)
241  payloadProtocol = ProtocolGroup::ethertype.findProtocol(snapHeader->getProtocolId());
242  else
243  payloadProtocol = ProtocolGroup::snapOui.findProtocol(snapHeader->getOui());
244  }
245  else {
246  int32_t sapData = ((llcHeader->getSsap() & 0xFF) << 8) | (llcHeader->getDsap() & 0xFF);
247  payloadProtocol = ProtocolGroup::ieee8022protocol.findProtocol(sapData); // do not use getProtocol
248  }
249  return payloadProtocol;
250 }

Referenced by decapsulate(), and inet::Ieee802LlcDissector::dissect().

◆ handleCrashOperation()

void inet::Ieee8022Llc::handleCrashOperation ( LifecycleOperation operation)
overrideprotectedvirtual

Implements inet::OperationalMixin< cSimpleModule >.

291 {
292  clearSockets();
293 }

◆ handleMessageWhenUp()

void inet::Ieee8022Llc::handleMessageWhenUp ( cMessage *  message)
overrideprotectedvirtual

Implements inet::OperationalMixin< cSimpleModule >.

54 {
55  if (msg->arrivedOn("upperLayerIn")) {
56  // from upper layer
57  EV_INFO << "Received " << msg << " from upper layer." << endl;
58  if (msg->isPacket())
59  processPacketFromHigherLayer(check_and_cast<Packet *>(msg));
60  else
61  processCommandFromHigherLayer(check_and_cast<Request *>(msg));
62  }
63  else if (msg->arrivedOn("lowerLayerIn")) {
64  EV_INFO << "Received " << msg << " from lower layer." << endl;
65  processPacketFromMac(check_and_cast<Packet *>(msg));
66  }
67  else
68  throw cRuntimeError("Unknown gate");
69 }

◆ handleRegisterProtocol()

void inet::Ieee8022Llc::handleRegisterProtocol ( const Protocol protocol,
cGate *  gate,
ServicePrimitive  servicePrimitive 
)
overrideprotectedvirtual

Reimplemented from inet::DefaultProtocolRegistrationListener.

258 {
259  Enter_Method("handleRegisterProtocol");
260  // KLUDGE this should be here: if (!strcmp("upperLayerOut", gate->getBaseName()))
261  // but then the register protocol calls are lost, because they can't go through the traffic conditioner
262  upperProtocols.insert(&protocol);
263 }

◆ handleRegisterService()

void inet::Ieee8022Llc::handleRegisterService ( const Protocol protocol,
cGate *  gate,
ServicePrimitive  servicePrimitive 
)
overrideprotectedvirtual

Reimplemented from inet::DefaultProtocolRegistrationListener.

253 {
254  Enter_Method("handleRegisterService");
255 }

◆ handleStartOperation()

void inet::Ieee8022Llc::handleStartOperation ( LifecycleOperation operation)
overrideprotectedvirtual

Implements inet::OperationalMixin< cSimpleModule >.

281 {
282  clearSockets();
283 }

◆ handleStopOperation()

void inet::Ieee8022Llc::handleStopOperation ( LifecycleOperation operation)
overrideprotectedvirtual

Implements inet::OperationalMixin< cSimpleModule >.

286 {
287  clearSockets();
288 }

◆ initialize()

void inet::Ieee8022Llc::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::OperationalMixin< cSimpleModule >.

31 {
33  if (stage == INITSTAGE_LOCAL) {
34  // TODO parameterization for llc or snap?
35  }
36  else if (stage == INITSTAGE_LINK_LAYER) {
37  if (par("registerProtocol").boolValue()) { // FIXME //KUDGE should redesign place of EthernetEncapsulation and LLC modules
38  // register service and protocol
39  registerService(Protocol::ieee8022llc, gate("upperLayerIn"), gate("upperLayerOut"));
41  }
42 
43  WATCH_PTRMAP(socketIdToSocketDescriptor);
44  WATCH_PTRSET(upperProtocols);
45  }
46 }

◆ isDeliverableToUpperLayer()

bool inet::Ieee8022Llc::isDeliverableToUpperLayer ( Packet packet)
protectedvirtual
139 {
140  const auto& protocolTag = packet->findTag<PacketProtocolTag>();
141  return (protocolTag != nullptr && contains(upperProtocols, protocolTag->getProtocol()));
142 }

Referenced by processPacketFromMac().

◆ isInitializeStage()

virtual bool inet::Ieee8022Llc::isInitializeStage ( int  stage) const
inlineoverrideprotectedvirtual

Implements inet::OperationalMixin< cSimpleModule >.

58 { return stage == INITSTAGE_LINK_LAYER; }

◆ isModuleStartStage()

virtual bool inet::Ieee8022Llc::isModuleStartStage ( int  stage) const
inlineoverrideprotectedvirtual

◆ isModuleStopStage()

virtual bool inet::Ieee8022Llc::isModuleStopStage ( int  stage) const
inlineoverrideprotectedvirtual

◆ numInitStages()

virtual int inet::Ieee8022Llc::numInitStages ( ) const
inlineoverrideprotectedvirtual
41 { return NUM_INIT_STAGES; }

◆ processCommandFromHigherLayer()

void inet::Ieee8022Llc::processCommandFromHigherLayer ( Request request)
protectedvirtual
78 {
79  auto ctrl = request->getControlInfo();
80  if (ctrl == nullptr)
81  throw cRuntimeError("Request '%s' arrived without controlinfo", request->getName());
82  else if (auto command = dynamic_cast<Ieee8022LlcSocketOpenCommand *>(ctrl)) {
83  int socketId = request->getTag<SocketReq>()->getSocketId();
84  SocketDescriptor *descriptor = new SocketDescriptor(socketId, command->getLocalSap());
85  socketIdToSocketDescriptor[socketId] = descriptor;
86  delete request;
87  }
88  else if (dynamic_cast<SocketCloseCommand *>(ctrl) != nullptr) {
89  int socketId = request->getTag<SocketReq>()->getSocketId();
90  auto it = socketIdToSocketDescriptor.find(socketId);
91  if (it != socketIdToSocketDescriptor.end()) {
92  delete it->second;
94  }
95  delete request;
96  auto indication = new Indication("closed", SOCKET_I_CLOSED);
97  auto ctrl = new SocketClosedIndication();
98  indication->setControlInfo(ctrl);
99  indication->addTag<SocketInd>()->setSocketId(socketId);
100  send(indication, "upperLayerOut");
101 
102  }
103  else if (dynamic_cast<SocketDestroyCommand *>(ctrl) != nullptr) {
104  int socketId = request->getTag<SocketReq>()->getSocketId();
105  auto it = socketIdToSocketDescriptor.find(socketId);
106  if (it != socketIdToSocketDescriptor.end()) {
107  delete it->second;
108  socketIdToSocketDescriptor.erase(it);
109  }
110  delete request;
111  }
112  else
113  throw cRuntimeError("Unknown command: '%s' with %s", request->getName(), ctrl->getClassName());
114 }

Referenced by handleMessageWhenUp().

◆ processPacketFromHigherLayer()

void inet::Ieee8022Llc::processPacketFromHigherLayer ( Packet msg)
protectedvirtual
72 {
73  encapsulate(packet);
74  send(packet, "lowerLayerOut");
75 }

Referenced by handleMessageWhenUp().

◆ processPacketFromMac()

void inet::Ieee8022Llc::processPacketFromMac ( Packet packet)
protectedvirtual
145 {
146  decapsulate(packet);
147  bool isSent = deliverCopyToSockets(packet);
148 
149  if (isDeliverableToUpperLayer(packet)) {
150  send(packet, "upperLayerOut");
151  }
152  else {
153  if (!isSent) {
154  EV_WARN << "Unknown protocol, dropping packet\n";
155  PacketDropDetails details;
156  details.setReason(NO_PROTOCOL_FOUND);
157  emit(packetDroppedSignal, packet, &details);
158  }
159  delete packet;
160  }
161 }

Referenced by handleMessageWhenUp().

◆ registerMyProtocol()

void inet::Ieee8022Llc::registerMyProtocol ( )
protectedvirtual
49 {
50  registerProtocol(Protocol::ieee8022llc, gate("lowerLayerOut"), gate("lowerLayerIn"));
51 }

Referenced by initialize().

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  o,
const SocketDescriptor t 
)
friend
266 {
267  o << "(id:" << t.socketId << ",lsap:" << t.localSap << ",rsap" << t.remoteSap << ")";
268  return o;
269 }

Member Data Documentation

◆ socketIdToSocketDescriptor

std::map<int, SocketDescriptor *> inet::Ieee8022Llc::socketIdToSocketDescriptor
protected

◆ upperProtocols

std::set<const Protocol *> inet::Ieee8022Llc::upperProtocols
protected

The documentation for this class was generated from the following files:
inet::Ieee8022Llc::processCommandFromHigherLayer
virtual void processCommandFromHigherLayer(Request *request)
Definition: Ieee8022Llc.cc:77
protocol
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down protocol
Definition: IUdp-gates.txt:25
inet::Ieee8022Llc::decapsulate
virtual void decapsulate(Packet *frame)
Definition: Ieee8022Llc.cc:208
inet::ProtocolGroup::ieee8022protocol
static ProtocolGroup ieee8022protocol
Definition: ProtocolGroup.h:41
inet::OperationalMixin< cSimpleModule >::initialize
virtual void initialize(int stage) override
Definition: OperationalMixinImpl.h:26
inet::Ieee8022Llc::socketIdToSocketDescriptor
std::map< int, SocketDescriptor * > socketIdToSocketDescriptor
Definition: Ieee8022Llc.h:37
inet::ProtocolGroup::findProtocol
const Protocol * findProtocol(int protocolNumber) const
Definition: ProtocolGroup.cc:25
DispatchProtocolReq
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down DispatchProtocolReq
Definition: IUdp-gates.txt:25
inet::ProtocolGroup::snapOui
static ProtocolGroup snapOui
Definition: ProtocolGroup.h:44
inet::registerService
void registerService(const Protocol &protocol, cGate *gate, ServicePrimitive servicePrimitive)
Registers a service primitive (SDU processing) at the given gate.
Definition: IProtocolRegistrationListener.cc:14
inet::packetDroppedSignal
simsignal_t packetDroppedSignal
Definition: Simsignals.cc:85
inet::Protocol::ieee8022llc
static const Protocol ieee8022llc
Definition: Protocol.h:88
PacketProtocolTag
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down PacketProtocolTag
Definition: IUdp-gates.txt:25
ctrl
removed ctrl
Definition: IUdp-gates.txt:7
inet::Ieee8022Llc::processPacketFromMac
virtual void processPacketFromMac(Packet *packet)
Definition: Ieee8022Llc.cc:144
inet::Ieee8022Llc::processPacketFromHigherLayer
virtual void processPacketFromHigherLayer(Packet *msg)
Definition: Ieee8022Llc.cc:71
inet::contains
bool contains(const std::vector< T > &v, const Tk &a)
Definition: stlutils.h:65
inet::Ieee8022Llc::registerMyProtocol
virtual void registerMyProtocol()
Definition: Ieee8022Llc.cc:48
inet::Protocol::ethernetMac
static const Protocol ethernetMac
Definition: Protocol.h:65
inet::SOCKET_I_DATA
@ SOCKET_I_DATA
Definition: SocketCommand_m.h:85
inet::ModuleStopOperation::STAGE_LINK_LAYER
@ STAGE_LINK_LAYER
Definition: ModuleOperations.h:54
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
inet::ProtocolGroup::findProtocolNumber
int findProtocolNumber(const Protocol *protocol) const
Definition: ProtocolGroup.cc:40
inet::Ieee8022Llc::deliverCopyToSockets
virtual bool deliverCopyToSockets(Packet *packet)
Definition: Ieee8022Llc.cc:116
inet::NO_PROTOCOL_FOUND
@ NO_PROTOCOL_FOUND
Definition: Simsignals_m.h:81
NUM_INIT_STAGES
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
inet::SOCKET_I_CLOSED
@ SOCKET_I_CLOSED
Definition: SocketCommand_m.h:86
inet::Ieee8022Llc::upperProtocols
std::set< const Protocol * > upperProtocols
Definition: Ieee8022Llc.h:36
Enter_Method
#define Enter_Method(...)
Definition: SelfDoc.h:71
inet::Ieee8022Llc::clearSockets
void clearSockets()
Definition: Ieee8022Llc.cc:271
inet::Ieee8022Llc::getProtocol
static const Protocol * getProtocol(const Ptr< const Ieee8022LlcHeader > &header)
Definition: Ieee8022Llc.cc:233
inet::Ieee8022Llc::encapsulate
virtual void encapsulate(Packet *frame)
Definition: Ieee8022Llc.cc:163
inet::Ieee8022Llc::isDeliverableToUpperLayer
virtual bool isDeliverableToUpperLayer(Packet *packet)
Definition: Ieee8022Llc.cc:138
inet::ModuleStartOperation::STAGE_LINK_LAYER
@ STAGE_LINK_LAYER
Definition: ModuleOperations.h:28
inet::registerProtocol
void registerProtocol(const Protocol &protocol, cGate *gate, ServicePrimitive servicePrimitive)
Registers a protocol primitive (PDU processing) at the given gate.
Definition: IProtocolRegistrationListener.cc:83
inet::INITSTAGE_LINK_LAYER
INET_API InitStage INITSTAGE_LINK_LAYER
Initialization of link-layer protocols.
inet::ProtocolGroup::ethertype
static ProtocolGroup ethertype
Definition: ProtocolGroup.h:40