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

#include <Tun.h>

Inheritance diagram for inet::Tun:
inet::MacProtocolBase inet::LayeredProtocolBase inet::OperationalBase inet::OperationalMixin< cSimpleModule > inet::ILifecycle

Public Member Functions

virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
virtual void handleUpperMessage (cMessage *message) override
 
virtual void handleUpperPacket (Packet *packet) override
 
virtual void handleUpperCommand (cMessage *message) override
 
- Public Member Functions inherited from inet::OperationalMixin< cSimpleModule >
virtual ~OperationalMixin ()
 }@ More...
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 

Protected Member Functions

virtual void configureNetworkInterface () override
 
- Protected Member Functions inherited from inet::MacProtocolBase
 MacProtocolBase ()
 
virtual ~MacProtocolBase ()
 
virtual void registerInterface ()
 
virtual MacAddress parseMacAddressParameter (const char *addrstr)
 
virtual void deleteCurrentTxFrame ()
 
virtual void dropCurrentTxFrame (PacketDropDetails &details)
 
virtual void handleMessageWhenDown (cMessage *msg) override
 
virtual void sendUp (cMessage *message)
 
virtual void sendDown (cMessage *message)
 
virtual bool isUpperMessage (cMessage *message) const override
 
virtual bool isLowerMessage (cMessage *message) const override
 
virtual bool isInitializeStage (int stage) const override
 
virtual bool isModuleStartStage (int stage) const override
 
virtual bool isModuleStopStage (int stage) const override
 
virtual void flushQueue (PacketDropDetails &details)
 should clear queue and emit signal "packetDropped" with entire packets More...
 
virtual void clearQueue ()
 should clear queue silently More...
 
virtual void receiveSignal (cComponent *source, simsignal_t signalID, cObject *obj, cObject *details) override
 
virtual void handleStartOperation (LifecycleOperation *operation) override
 
virtual void handleStopOperation (LifecycleOperation *operation) override
 
virtual void handleCrashOperation (LifecycleOperation *operation) override
 
queueing::IPacketQueuegetQueue (cGate *gate) const
 
virtual bool canDequeuePacket () const
 
virtual PacketdequeuePacket ()
 
- Protected Member Functions inherited from inet::LayeredProtocolBase
virtual void handleMessageWhenUp (cMessage *message) override
 
virtual void handleSelfMessage (cMessage *message)
 
virtual void handleLowerMessage (cMessage *message)
 
virtual void handleLowerCommand (cMessage *message)
 
virtual void handleLowerPacket (Packet *packet)
 
- 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 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::vector< int > socketIds
 
- Protected Attributes inherited from inet::MacProtocolBase
int upperLayerInGateId = -1
 Gate ids. More...
 
int upperLayerOutGateId = -1
 
int lowerLayerInGateId = -1
 
int lowerLayerOutGateId = -1
 
opp_component_ptr< NetworkInterfacenetworkInterface
 
opp_component_ptr< cModule > hostModule
 
PacketcurrentTxFrame = nullptr
 Currently transmitted frame if any. More...
 
opp_component_ptr< queueing::IPacketQueuetxQueue
 Messages received from upper layer and to be transmitted later. More...
 
- Protected Attributes inherited from inet::OperationalMixin< cSimpleModule >
State operationalState
 
simtime_t lastChange
 
Operation activeOperation
 
cMessage * activeOperationTimeout
 
cMessage * activeOperationExtraTimer
 

Additional Inherited Members

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

Member Function Documentation

◆ configureNetworkInterface()

void inet::Tun::configureNetworkInterface ( )
overrideprotectedvirtual

Implements inet::MacProtocolBase.

35 {
36  networkInterface->setMtu(par("mtu"));
37 }

◆ handleUpperCommand()

void inet::Tun::handleUpperCommand ( cMessage *  message)
overridevirtual

Reimplemented from inet::LayeredProtocolBase.

82 {
83  cObject *controlInfo = message->getControlInfo();
84  int socketId = check_and_cast<Request *>(message)->getTag<SocketReq>()->getSocketId();
85  if (dynamic_cast<TunOpenCommand *>(controlInfo) != nullptr) {
86  if (contains(socketIds, socketId))
87  throw cRuntimeError("Socket is already open: %d", socketId);
88  socketIds.push_back(socketId);
89  delete message;
90  }
91  else if (dynamic_cast<TunCloseCommand *>(controlInfo) != nullptr) {
92  auto it = find(socketIds, socketId);
93  if (it != socketIds.end())
94  socketIds.erase(it);
95  delete message;
96  auto indication = new Indication("closed", TUN_I_CLOSED);
97  auto ctrl = new TunSocketClosedIndication();
98  indication->setControlInfo(ctrl);
99  indication->addTagIfAbsent<SocketInd>()->setSocketId(socketId);
100  send(indication, "upperLayerOut");
101  }
102  else if (dynamic_cast<TunDestroyCommand *>(controlInfo) != nullptr) {
103  auto it = find(socketIds, socketId);
104  if (it != socketIds.end())
105  socketIds.erase(it);
106  delete message;
107  }
108  else
109  throw cRuntimeError("Unknown command: %s", message->getName());
110 }

Referenced by handleUpperMessage().

◆ handleUpperMessage()

void inet::Tun::handleUpperMessage ( cMessage *  message)
overridevirtual

Reimplemented from inet::LayeredProtocolBase.

40 {
41  if (!message->isPacket())
42  handleUpperCommand(message);
43  else {
44  handleUpperPacket(check_and_cast<Packet *>(message));
45  }
46 }

◆ handleUpperPacket()

void inet::Tun::handleUpperPacket ( Packet packet)
overridevirtual

Reimplemented from inet::LayeredProtocolBase.

49 {
50  const auto& socketReq = packet->findTag<SocketReq>();
51  // check if packet is from app by finding SocketReq with sockedId that is in socketIds
52  auto sId = socketReq != nullptr ? socketReq->getSocketId() : -1;
53  ASSERT(packet->getControlInfo() == nullptr);
54  if (socketReq != nullptr && contains(socketIds, sId)) {
55  // TODO should we determine the network protocol by looking at the packet?!
56  packet->clearTags();
57  packet->addTag<InterfaceInd>()->setInterfaceId(networkInterface->getInterfaceId());
58  packet->addTag<DispatchProtocolReq>()->setProtocol(&Protocol::ipv4);
59  packet->addTag<PacketProtocolTag>()->setProtocol(&Protocol::ipv4);
60  emit(packetSentToUpperSignal, packet);
61  send(packet, "upperLayerOut");
62  }
63  else {
64  emit(packetReceivedFromUpperSignal, packet);
65  for (int socketId : socketIds) {
66  Packet *copy = packet->dup();
67  copy->setKind(TUN_I_DATA);
68  copy->clearTags();
69  copy->addTag<SocketInd>()->setSocketId(socketId);
70  copy->addTag<InterfaceInd>()->setInterfaceId(networkInterface->getInterfaceId());
71  copy->addTag<PacketProtocolTag>()->setProtocol(packet->getTag<PacketProtocolTag>()->getProtocol());
72  auto npTag = packet->getTag<NetworkProtocolInd>();
73  auto newnpTag = copy->addTag<NetworkProtocolInd>();
74  *newnpTag = *npTag;
75  send(copy, "upperLayerOut");
76  }
77  delete packet;
78  }
79 }

Referenced by handleUpperMessage().

◆ initialize()

void inet::Tun::initialize ( int  stage)
overridevirtual

Reimplemented from inet::MacProtocolBase.

26 {
28  if (stage == INITSTAGE_LOCAL) {
29  lowerLayerInGateId = findGate("phys$i");
30  lowerLayerOutGateId = findGate("phys$o");
31  }
32 }

◆ numInitStages()

virtual int inet::Tun::numInitStages ( ) const
inlineoverridevirtual
25 { return NUM_INIT_STAGES; }

Member Data Documentation

◆ socketIds

std::vector<int> inet::Tun::socketIds
protected

The documentation for this class was generated from the following files:
inet::MacProtocolBase::networkInterface
opp_component_ptr< NetworkInterface > networkInterface
Definition: MacProtocolBase.h:30
inet::TUN_I_CLOSED
@ TUN_I_CLOSED
Definition: TunControlInfo_m.h:79
inet::Tun::socketIds
std::vector< int > socketIds
Definition: Tun.h:19
inet::Protocol::ipv4
static const Protocol ipv4
Definition: Protocol.h:93
inet::packetReceivedFromUpperSignal
simsignal_t packetReceivedFromUpperSignal
Definition: Simsignals.cc:88
DispatchProtocolReq
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down DispatchProtocolReq
Definition: IUdp-gates.txt:25
inet::find
std::vector< T >::iterator find(std::vector< T > &v, const Tk &a)
Definition: stlutils.h:44
inet::Tun::handleUpperCommand
virtual void handleUpperCommand(cMessage *message) override
Definition: Tun.cc:81
PacketProtocolTag
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down PacketProtocolTag
Definition: IUdp-gates.txt:25
inet::MacProtocolBase::lowerLayerInGateId
int lowerLayerInGateId
Definition: MacProtocolBase.h:26
ctrl
removed ctrl
Definition: IUdp-gates.txt:7
inet::Tun::handleUpperPacket
virtual void handleUpperPacket(Packet *packet) override
Definition: Tun.cc:48
inet::contains
bool contains(const std::vector< T > &v, const Tk &a)
Definition: stlutils.h:65
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
inet::TUN_I_DATA
@ TUN_I_DATA
Definition: TunControlInfo_m.h:80
NUM_INIT_STAGES
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
inet::MacProtocolBase::initialize
virtual void initialize(int stage) override
Definition: MacProtocolBase.cc:37
inet::MacProtocolBase::lowerLayerOutGateId
int lowerLayerOutGateId
Definition: MacProtocolBase.h:27
inet::packetSentToUpperSignal
simsignal_t packetSentToUpperSignal
Definition: Simsignals.cc:87
copy
MIT License free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to copy
Definition: LICENSE.txt:8