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

#include <Ieee8021qSocket.h>

Inheritance diagram for inet::Ieee8021qSocket:
inet::SocketBase inet::ISocket

Classes

class  ICallback
 

Public Member Functions

Opening and closing connections, sending data
void setCallback (ICallback *callback)
 Sets a callback object, to be used with processMessage(). More...
 
void setNetworkInterface (NetworkInterface *networkInterface)
 
void setProtocol (const Protocol *protocol)
 
void bind (const Protocol *protocol, int vlanId, bool steal)
 Binds the socket to the MAC address. More...
 
Handling of messages arriving from Ieee8021q
virtual void processMessage (cMessage *msg) override
 Returns true if the message belongs to this socket instance. 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

ICallbackcallback = nullptr
 
NetworkInterfacenetworkInterface = nullptr
 
const Protocolprotocol = nullptr
 
- Protected Attributes inherited from inet::SocketBase
cGate * outputGate = nullptr
 
int socketId = -1
 
bool isOpen_ = false
 
void * userData = nullptr
 

Member Function Documentation

◆ bind()

void inet::Ieee8021qSocket::bind ( const Protocol protocol,
int  vlanId,
bool  steal 
)

Binds the socket to the MAC address.

27 {
28  auto request = new Request("BIND", SOCKET_C_BIND);
29  Ieee8021qBindCommand *ctrl = new Ieee8021qBindCommand();
30  ctrl->setProtocol(protocol);
31  ctrl->setVlanId(vlanId);
32  ctrl->setSteal(steal);
33  request->setControlInfo(ctrl);
34  isOpen_ = true;
35  sendOut(request);
36 }

◆ processMessage()

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

Returns true if the message belongs to this socket instance.

Implements inet::ISocket.

39 {
40  ASSERT(belongsToSocket(msg));
41  switch (msg->getKind()) {
42  case SOCKET_I_DATA:
43  if (callback)
44  callback->socketDataArrived(this, check_and_cast<Packet *>(msg));
45  else
46  delete msg;
47  break;
48  case SOCKET_I_CLOSED:
49  isOpen_ = false;
50  if (callback)
51  callback->socketClosed(this);
52  delete msg;
53  break;
54  default:
55  throw cRuntimeError("Ieee8021qSocket: invalid msg kind %d, one of the ETHERNNET_I_xxx constants expected", msg->getKind());
56  break;
57  }
58 }

◆ sendOut()

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

Reimplemented from inet::SocketBase.

18 {
19  auto& tags = check_and_cast<ITaggedObject *>(msg)->getTags();
20  tags.addTagIfAbsent<InterfaceReq>()->setInterfaceId(networkInterface->getInterfaceId());
21  if (tags.findTag<DispatchProtocolReq>() == nullptr)
22  tags.addTag<DispatchProtocolReq>()->setProtocol(protocol);
24 }

Referenced by bind().

◆ setCallback()

void inet::Ieee8021qSocket::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 Ieee8021qSocket::ICallback

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

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

66 { this->callback = callback; }

◆ setNetworkInterface()

void inet::Ieee8021qSocket::setNetworkInterface ( NetworkInterface networkInterface)
inline

◆ setProtocol()

void inet::Ieee8021qSocket::setProtocol ( const Protocol protocol)
inline
68 { this->protocol = protocol; }

Member Data Documentation

◆ callback

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

Referenced by processMessage().

◆ networkInterface

NetworkInterface* inet::Ieee8021qSocket::networkInterface = nullptr
protected

Referenced by sendOut().

◆ protocol

const Protocol* inet::Ieee8021qSocket::protocol = nullptr
protected

Referenced by bind(), and sendOut().


The documentation for this class was generated from the following files:
inet::Ieee8021qSocket::callback
ICallback * callback
Definition: Ieee8021qSocket.h:42
inet::Ieee8021qSocket::protocol
const Protocol * protocol
Definition: Ieee8021qSocket.h:44
inet::Ieee8021qSocket::ICallback::socketClosed
virtual void socketClosed(Ieee8021qSocket *socket)=0
Notifies about the socket closed.
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::Ieee8021qSocket::sendOut
virtual void sendOut(cMessage *msg) override
Definition: Ieee8021qSocket.cc:17
ctrl
removed ctrl
Definition: IUdp-gates.txt:7
inet::NetworkInterface::getInterfaceId
int getInterfaceId() const
Definition: NetworkInterface.h:232
inet::SocketBase::isOpen_
bool isOpen_
Definition: SocketBase.h:20
inet::SOCKET_I_DATA
@ SOCKET_I_DATA
Definition: SocketCommand_m.h:85
inet::Ieee8021qSocket::networkInterface
NetworkInterface * networkInterface
Definition: Ieee8021qSocket.h:43
inet::Ieee8021qSocket::ICallback::socketDataArrived
virtual void socketDataArrived(Ieee8021qSocket *socket, Packet *packet)=0
Notifies about data arrival, packet ownership is transferred to the callee.
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::SOCKET_C_BIND
@ SOCKET_C_BIND
Definition: SocketCommand_m.h:65
inet::SocketBase::belongsToSocket
virtual bool belongsToSocket(cMessage *msg) const override
Returns true if the message belongs to this socket instance.
Definition: SocketBase.cc:61