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

#include <Ieee8022LlcSocket.h>

Inheritance diagram for inet::Ieee8022LlcSocket:
inet::SocketBase inet::ISocket

Classes

class  ICallback
 

Public Member Functions

void setCallback (ICallback *callback)
 Sets a callback object, to be used with processMessage(). More...
 
virtual int getInterfaceId () const
 Returns the interface Id. More...
 
virtual int getLocalSap () const
 Returns the local SAP. More...
 
virtual int getRemoteSap () const
 Returns the remote SAP. More...
 
virtual void open (int interfaceId, int localSap, int remoteSap)
 
virtual void processMessage (cMessage *msg) override
 Examines the message, takes ownership, and updates socket state. More...
 
- Public Member Functions inherited from inet::SocketBase
 SocketBase ()
 
virtual ~SocketBase ()
 
void setOutputGate (cGate *gate)
 Sets the gate on which to send messages. More...
 
int getSocketId () const override
 Returns the internal socket Id. More...
 
virtual void send (Packet *packet) override
 Sends a data packet to the address and port specified previously in a connect() call. More...
 
virtual bool isOpen () const override
 Returns true if the socket is open. More...
 
virtual void close () override
 Unbinds the socket. More...
 
virtual void destroy () override
 Notify the protocol that the owner of ISocket has destroyed the socket. More...
 
virtual bool belongsToSocket (cMessage *msg) const override
 Returns true if the message belongs to this socket instance. More...
 
void * getUserData () const
 
void setUserData (void *userData)
 
- Public Member Functions inherited from inet::ISocket
virtual ~ISocket ()
 

Protected Member Functions

virtual void sendOut (cMessage *msg) override
 

Protected Attributes

int interfaceId = -1
 
int localSap = -1
 
int remoteSap = -1
 
ICallbackcallback = nullptr
 
- Protected Attributes inherited from inet::SocketBase
cGate * outputGate = nullptr
 
int socketId = -1
 
bool isOpen_ = false
 
void * userData = nullptr
 

Member Function Documentation

◆ getInterfaceId()

virtual int inet::Ieee8022LlcSocket::getInterfaceId ( ) const
inlinevirtual

Returns the interface Id.

54 { return interfaceId; }

◆ getLocalSap()

virtual int inet::Ieee8022LlcSocket::getLocalSap ( ) const
inlinevirtual

Returns the local SAP.

59 { return localSap; }

◆ getRemoteSap()

virtual int inet::Ieee8022LlcSocket::getRemoteSap ( ) const
inlinevirtual

Returns the remote SAP.

64 { return remoteSap; }

◆ open()

void inet::Ieee8022LlcSocket::open ( int  interfaceId,
int  localSap,
int  remoteSap 
)
virtual
41 {
42  if (localSap < -1 || localSap > 255)
43  throw cRuntimeError("Invalid localSap value: %d", localSap);
44  if (remoteSap < -1 || remoteSap > 255)
45  throw cRuntimeError("Invalid remoteSap value: %d", remoteSap);
46  this->interfaceId = interfaceId;
47  this->localSap = localSap;
48  this->remoteSap = remoteSap;
49  auto request = new Request("LLC_OPEN", SOCKET_C_OPEN);
50  Ieee8022LlcSocketOpenCommand *command = new Ieee8022LlcSocketOpenCommand();
51  command->setLocalSap(localSap);
52  request->setControlInfo(command);
53  isOpen_ = true;
54  sendOut(request);
55 }

Referenced by inet::EtherAppClient::handleMessageWhenUp(), inet::EtherTrafGen::handleMessageWhenUp(), inet::Ieee8022LlcSocketIo::handleStartOperation(), and inet::EtherAppServer::registerDsap().

◆ processMessage()

void inet::Ieee8022LlcSocket::processMessage ( cMessage *  msg)
overridevirtual

Examines the message, takes ownership, and updates socket state.

Implements inet::ISocket.

58 {
59  ASSERT(belongsToSocket(msg));
60  switch (msg->getKind()) {
61  case SOCKET_I_DATA:
62  if (callback)
63  callback->socketDataArrived(this, check_and_cast<Packet *>(msg));
64  else
65  delete msg;
66  break;
67  case SOCKET_I_CLOSED:
68  isOpen_ = false;
69  if (callback)
70  callback->socketClosed(this);
71  delete msg;
72  break;
73  default:
74  throw cRuntimeError("Ieee8022LlcSocket: invalid msg kind %d, one of the SOCKET_I_xxx constants expected", msg->getKind());
75  break;
76  }
77 }

Referenced by inet::Ieee8022LlcSocketIo::handleMessageWhenUp(), inet::EtherAppServer::handleMessageWhenUp(), and inet::EtherAppClient::handleMessageWhenUp().

◆ sendOut()

void inet::Ieee8022LlcSocket::sendOut ( cMessage *  msg)
overrideprotectedvirtual

Reimplemented from inet::SocketBase.

19 {
20  auto& tags = check_and_cast<ITaggedObject *>(msg)->getTags();
21  tags.addTagIfAbsent<DispatchProtocolReq>()->setProtocol(&Protocol::ieee8022llc);
22  if (localSap != -1) {
23  auto& sapReq = tags.addTagIfAbsent<Ieee802SapReq>();
24  if (sapReq->getSsap() == -1)
25  sapReq->setSsap(localSap);
26  }
27  if (remoteSap != -1) {
28  auto& sapReq = tags.addTagIfAbsent<Ieee802SapReq>();
29  if (sapReq->getDsap() == -1)
30  sapReq->setDsap(remoteSap);
31  }
32  if (interfaceId != -1) {
33  auto& interfaceReq = tags.addTagIfAbsent<InterfaceReq>();
34  if (interfaceReq->getInterfaceId() == -1)
35  interfaceReq->setInterfaceId(interfaceId);
36  }
38 }

Referenced by open().

◆ setCallback()

void inet::Ieee8022LlcSocket::setCallback ( ICallback callback)
inline

Sets a callback object, to be used with processMessage().

This callback object may be your simple module itself (if it multiply inherits from ICallback too, that is you declared it as

class MyAppModule : public cSimpleModule, public LlcSocket::ICallback

and redefined the necessary virtual functions; or you may use dedicated class (and objects) for this purpose.

LlcSocket doesn't delete the callback object in the destructor or on any other occasion.

49 { this->callback = callback; }

Referenced by inet::EtherAppServer::initialize(), inet::EtherAppClient::initialize(), and inet::Ieee8022LlcSocketIo::setSocketOptions().

Member Data Documentation

◆ callback

ICallback* inet::Ieee8022LlcSocket::callback = nullptr
protected

Referenced by processMessage().

◆ interfaceId

int inet::Ieee8022LlcSocket::interfaceId = -1
protected

Referenced by open(), and sendOut().

◆ localSap

int inet::Ieee8022LlcSocket::localSap = -1
protected

Referenced by open(), and sendOut().

◆ remoteSap

int inet::Ieee8022LlcSocket::remoteSap = -1
protected

Referenced by open(), and sendOut().


The documentation for this class was generated from the following files:
inet::Ieee8022LlcSocket::remoteSap
int remoteSap
Definition: Ieee8022LlcSocket.h:28
inet::SOCKET_C_OPEN
@ SOCKET_C_OPEN
Definition: SocketCommand_m.h:66
InterfaceReq
removed InterfaceReq
Definition: IUdp-gates.txt:11
DispatchProtocolReq
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down DispatchProtocolReq
Definition: IUdp-gates.txt:25
inet::Ieee8022LlcSocket::ICallback::socketClosed
virtual void socketClosed(Ieee8022LlcSocket *socket)=0
inet::Protocol::ieee8022llc
static const Protocol ieee8022llc
Definition: Protocol.h:88
inet::SocketBase::isOpen_
bool isOpen_
Definition: SocketBase.h:20
inet::SOCKET_I_DATA
@ SOCKET_I_DATA
Definition: SocketCommand_m.h:85
inet::Ieee8022LlcSocket::ICallback::socketDataArrived
virtual void socketDataArrived(Ieee8022LlcSocket *socket, Packet *packet)=0
inet::Ieee8022LlcSocket::interfaceId
int interfaceId
Definition: Ieee8022LlcSocket.h:26
inet::SOCKET_I_CLOSED
@ SOCKET_I_CLOSED
Definition: SocketCommand_m.h:86
tags
* tags
Definition: IUdp-gates.txt:3
inet::SocketBase::sendOut
virtual void sendOut(cMessage *msg)
Definition: SocketBase.cc:24
inet::Ieee8022LlcSocket::callback
ICallback * callback
Definition: Ieee8022LlcSocket.h:29
inet::Ieee8022LlcSocket::sendOut
virtual void sendOut(cMessage *msg) override
Definition: Ieee8022LlcSocket.cc:18
inet::Ieee8022LlcSocket::localSap
int localSap
Definition: Ieee8022LlcSocket.h:27
inet::SocketBase::belongsToSocket
virtual bool belongsToSocket(cMessage *msg) const override
Returns true if the message belongs to this socket instance.
Definition: SocketBase.cc:61