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

#include <EthernetSocket.h>

Inheritance diagram for inet::EthernetSocket:
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 bind (const MacAddress &localAddress, const MacAddress &remoteAddress, const Protocol *protocol, bool steal)
 Binds the socket to the MAC address. More...
 
Handling of messages arriving from Ethernet
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

ICallbackcallback = nullptr
 
NetworkInterfacenetworkInterface = 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::EthernetSocket::bind ( const MacAddress localAddress,
const MacAddress remoteAddress,
const Protocol protocol,
bool  steal 
)

Binds the socket to the MAC address.

28 {
29  auto request = new Request("BIND", SOCKET_C_BIND);
30  EthernetBindCommand *ctrl = new EthernetBindCommand();
31  ctrl->setLocalAddress(localAddress);
32  ctrl->setRemoteAddress(remoteAddress);
33  ctrl->setProtocol(protocol);
34  ctrl->setSteal(steal);
35  request->setControlInfo(ctrl);
36  isOpen_ = true;
37  sendOut(request);
38 }

◆ processMessage()

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

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

Implements inet::ISocket.

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

Referenced by inet::EthernetSocketIo::handleMessageWhenUp().

◆ sendOut()

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

Reimplemented from inet::SocketBase.

19 {
20  auto& tags = check_and_cast<ITaggedObject *>(msg)->getTags();
21  if (networkInterface != nullptr)
22  tags.addTagIfAbsent<InterfaceReq>()->setInterfaceId(networkInterface->getInterfaceId());
23  tags.addTag<DispatchProtocolReq>()->setProtocol(&Protocol::ethernetMac);
25 }

Referenced by bind().

◆ setCallback()

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

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

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

65 { this->callback = callback; }

Referenced by inet::EthernetSocketIo::setSocketOptions().

◆ setNetworkInterface()

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

Member Data Documentation

◆ callback

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

Referenced by processMessage().

◆ networkInterface

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

Referenced by sendOut().


The documentation for this class was generated from the following files:
inet::EthernetSocket::ICallback::socketClosed
virtual void socketClosed(EthernetSocket *socket)=0
Notifies about the socket closed.
protocol
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down protocol
Definition: IUdp-gates.txt:25
inet::EthernetSocket::callback
ICallback * callback
Definition: EthernetSocket.h:42
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
ctrl
removed ctrl
Definition: IUdp-gates.txt:7
inet::NetworkInterface::getInterfaceId
int getInterfaceId() const
Definition: NetworkInterface.h:232
inet::EthernetSocket::sendOut
virtual void sendOut(cMessage *msg) override
Definition: EthernetSocket.cc:18
inet::SocketBase::isOpen_
bool isOpen_
Definition: SocketBase.h:20
inet::Protocol::ethernetMac
static const Protocol ethernetMac
Definition: Protocol.h:65
inet::SOCKET_I_DATA
@ SOCKET_I_DATA
Definition: SocketCommand_m.h:85
inet::EthernetSocket::networkInterface
NetworkInterface * networkInterface
Definition: EthernetSocket.h:43
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
inet::EthernetSocket::ICallback::socketDataArrived
virtual void socketDataArrived(EthernetSocket *socket, Packet *packet)=0
Notifies about data arrival, packet ownership is transferred to the callee.