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

HostAutoConfigurator automatically assigns IP addresses and sets up the routing table for the host it is part of. More...

#include <HostAutoConfigurator.h>

Inheritance diagram for inet::HostAutoConfigurator:
inet::OperationalBase inet::OperationalMixin< cSimpleModule > inet::ILifecycle

Public Member Functions

virtual void initialize (int stage) override
 
virtual void finish () override
 
virtual int numInitStages () const override
 
virtual void handleMessageWhenUp (cMessage *msg) 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 handleStartOperation (LifecycleOperation *operation) override
 
virtual void handleStopOperation (LifecycleOperation *operation) override
 
virtual void handleCrashOperation (LifecycleOperation *operation) override
 
virtual bool isInitializeStage (int stage) const override
 
virtual bool isModuleStartStage (int stage) const override
 
virtual bool isModuleStopStage (int stage) const override
 
virtual void setupNetworkLayer ()
 
- 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

ModuleRefByPar< IInterfaceTableinterfaceTable
 
- 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
 

Detailed Description

HostAutoConfigurator automatically assigns IP addresses and sets up the routing table for the host it is part of.

For more info please see the NED file.

Author
Christoph Sommer

Member Function Documentation

◆ finish()

void inet::HostAutoConfigurator::finish ( )
overridevirtual
33 {
34 }

◆ handleCrashOperation()

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

Implements inet::OperationalMixin< cSimpleModule >.

117 {
118 }

◆ handleMessageWhenUp()

void inet::HostAutoConfigurator::handleMessageWhenUp ( cMessage *  msg)
overridevirtual

Implements inet::OperationalMixin< cSimpleModule >.

37 {
38 }

◆ handleStartOperation()

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

Implements inet::OperationalMixin< cSimpleModule >.

103 {
104  if (operation == nullptr) {
105  // in initialize:
106  for (int i = 0; i < interfaceTable->getNumInterfaces(); i++)
107  interfaceTable->getInterface(i)->addProtocolData<Ipv4InterfaceData>();
108  }
110 }

◆ handleStopOperation()

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

Implements inet::OperationalMixin< cSimpleModule >.

113 {
114 }

◆ initialize()

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

Reimplemented from inet::OperationalMixin< cSimpleModule >.

25 {
27  if (stage == INITSTAGE_LOCAL) {
28  interfaceTable.reference(this, "interfaceTableModule", true);
29  }
30 }

◆ isInitializeStage()

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

◆ isModuleStartStage()

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

◆ isModuleStopStage()

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

◆ numInitStages()

virtual int inet::HostAutoConfigurator::numInitStages ( ) const
inlineoverridevirtual
34 { return NUM_INIT_STAGES; }

◆ setupNetworkLayer()

void inet::HostAutoConfigurator::setupNetworkLayer ( )
protectedvirtual
41 {
42  EV_INFO << "host auto configuration started" << std::endl;
43 
44  std::string interfaces = par("interfaces");
45  Ipv4Address addressBase = Ipv4Address(par("addressBase").stringValue());
46  Ipv4Address netmask = Ipv4Address(par("netmask").stringValue());
47  std::string mcastGroups = par("mcastGroups").stdstringValue();
48 
49  // get our host module
50  cModule *host = getContainingNode(this);
51 
52  Ipv4Address myAddress = Ipv4Address(addressBase.getInt() + uint32_t(host->getId()));
53 
54  // address test
55  if (!Ipv4Address::maskedAddrAreEqual(myAddress, addressBase, netmask))
56  throw cRuntimeError("Generated IP address is out of specified address range");
57 
58  // get our routing table
59  IIpv4RoutingTable *routingTable = L3AddressResolver().getIpv4RoutingTableOf(host);
60  if (!routingTable)
61  throw cRuntimeError("No routing table found");
62 
63  // look at all interface table entries
64  cStringTokenizer interfaceTokenizer(interfaces.c_str());
65  const char *ifname;
66  uint32_t loopbackAddr = Ipv4Address::LOOPBACK_ADDRESS.getInt();
67  while ((ifname = interfaceTokenizer.nextToken()) != nullptr) {
68  NetworkInterface *ie = interfaceTable->findInterfaceByName(ifname);
69  if (!ie)
70  throw cRuntimeError("No such interface '%s'", ifname);
71 
72  auto ipv4Data = ie->getProtocolDataForUpdate<Ipv4InterfaceData>();
73  // assign IP Address to all connected interfaces
74  if (ie->isLoopback()) {
75  ipv4Data->setIPAddress(Ipv4Address(loopbackAddr++));
76  ipv4Data->setNetmask(Ipv4Address::LOOPBACK_NETMASK);
77  ipv4Data->setMetric(1);
78  EV_INFO << "loopback interface " << ifname << " gets " << ipv4Data->getIPAddress() << "/" << ipv4Data->getNetmask() << std::endl;
79  continue;
80  }
81 
82  EV_INFO << "interface " << ifname << " gets " << myAddress.str() << "/" << netmask.str() << std::endl;
83 
84  ipv4Data->setIPAddress(myAddress);
85  ipv4Data->setNetmask(netmask);
86  ie->setBroadcast(true);
87 
88  // associate interface with default multicast groups
89  ipv4Data->joinMulticastGroup(Ipv4Address::ALL_HOSTS_MCAST);
90  ipv4Data->joinMulticastGroup(Ipv4Address::ALL_ROUTERS_MCAST);
91 
92  // associate interface with specified multicast groups
93  cStringTokenizer interfaceTokenizer(mcastGroups.c_str());
94  const char *mcastGroup_s;
95  while ((mcastGroup_s = interfaceTokenizer.nextToken()) != nullptr) {
96  Ipv4Address mcastGroup(mcastGroup_s);
97  ipv4Data->joinMulticastGroup(mcastGroup);
98  }
99  }
100 }

Referenced by handleStartOperation().

Member Data Documentation

◆ interfaceTable

ModuleRefByPar<IInterfaceTable> inet::HostAutoConfigurator::interfaceTable
protected

The documentation for this class was generated from the following files:
inet::INITSTAGE_NETWORK_CONFIGURATION
INET_API InitStage INITSTAGE_NETWORK_CONFIGURATION
Initialization of network configuration (e.g.
inet::HostAutoConfigurator::setupNetworkLayer
virtual void setupNetworkLayer()
Definition: HostAutoConfigurator.cc:40
inet::Ipv4Address::getInt
uint32_t getInt() const
Returns the address as an uint32_t in host byte order (e.g.
Definition: Ipv4Address.h:186
inet::ModuleStopOperation::STAGE_NETWORK_LAYER
@ STAGE_NETWORK_LAYER
Definition: ModuleOperations.h:53
inet::getContainingNode
cModule * getContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:40
inet::OperationalMixin< cSimpleModule >::initialize
virtual void initialize(int stage) override
Definition: OperationalMixinImpl.h:26
inet::ModuleStartOperation::STAGE_NETWORK_LAYER
@ STAGE_NETWORK_LAYER
Definition: ModuleOperations.h:29
inet::Ipv4Address::ALL_ROUTERS_MCAST
static const Ipv4Address ALL_ROUTERS_MCAST
224.0.0.2 All routers on a subnet
Definition: Ipv4Address.h:97
inet::Ipv4Address::maskedAddrAreEqual
static bool maskedAddrAreEqual(const Ipv4Address &addr1, const Ipv4Address &addr2, const Ipv4Address &netmask)
Test if the masked addresses (ie the mask is applied to addr1 and addr2) are equal.
Definition: Ipv4Address.cc:249
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
NUM_INIT_STAGES
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
inet::HostAutoConfigurator::interfaceTable
ModuleRefByPar< IInterfaceTable > interfaceTable
Definition: HostAutoConfigurator.h:29
inet::Ipv4Address::LOOPBACK_ADDRESS
static const Ipv4Address LOOPBACK_ADDRESS
127.0.0.1
Definition: Ipv4Address.h:92
inet::Ipv4Address::ALL_HOSTS_MCAST
static const Ipv4Address ALL_HOSTS_MCAST
224.0.0.1 All hosts on a subnet
Definition: Ipv4Address.h:96
inet::Ipv4Address::LOOPBACK_NETMASK
static const Ipv4Address LOOPBACK_NETMASK
255.0.0.0
Definition: Ipv4Address.h:93