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

This module provides the static configuration for the IPv4RoutingTable and the IPv4 network interfaces of a particular node in the network. More...

#include <IPv4NodeConfigurator.h>

Inheritance diagram for inet::IPv4NodeConfigurator:
inet::ILifecycle

Public Member Functions

 IPv4NodeConfigurator ()
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 

Protected Member Functions

virtual int numInitStages () const override
 
virtual void handleMessage (cMessage *msg) override
 
virtual void initialize (int stage) override
 
virtual bool handleOperationStage (LifecycleOperation *operation, int stage, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 
virtual void prepareNode ()
 
virtual void prepareInterface (InterfaceEntry *interfaceEntry)
 
virtual void configureInterface ()
 
virtual void configureRoutingTable ()
 

Protected Attributes

NodeStatusnodeStatus
 
IInterfaceTableinterfaceTable
 
IIPv4RoutingTableroutingTable
 
IPv4NetworkConfiguratornetworkConfigurator
 

Detailed Description

This module provides the static configuration for the IPv4RoutingTable and the IPv4 network interfaces of a particular node in the network.

For more info please see the NED file.

Constructor & Destructor Documentation

inet::IPv4NodeConfigurator::IPv4NodeConfigurator ( )
31 {
32  nodeStatus = nullptr;
33  interfaceTable = nullptr;
34  routingTable = nullptr;
35  networkConfigurator = nullptr;
36 }
IIPv4RoutingTable * routingTable
Definition: IPv4NodeConfigurator.h:44
IPv4NetworkConfigurator * networkConfigurator
Definition: IPv4NodeConfigurator.h:45
NodeStatus * nodeStatus
Definition: IPv4NodeConfigurator.h:42
IInterfaceTable * interfaceTable
Definition: IPv4NodeConfigurator.h:43

Member Function Documentation

void inet::IPv4NodeConfigurator::configureInterface ( )
protectedvirtual

Referenced by handleOperationStage(), and initialize().

125 {
126  ASSERT(networkConfigurator);
127  for (int i = 0; i < interfaceTable->getNumInterfaces(); i++)
129 }
IPv4NetworkConfigurator * networkConfigurator
Definition: IPv4NodeConfigurator.h:45
virtual void configureInterface(InterfaceEntry *interfaceEntry)
Configures the provided interface based on the current network configuration.
Definition: IPv4NetworkConfigurator.cc:153
IInterfaceTable * interfaceTable
Definition: IPv4NodeConfigurator.h:43
virtual int getNumInterfaces() const =0
Returns the number of interfaces.
virtual InterfaceEntry * getInterface(int pos) const =0
Returns the InterfaceEntry specified by an index 0..numInterfaces-1.
void inet::IPv4NodeConfigurator::configureRoutingTable ( )
protectedvirtual

Referenced by handleOperationStage(), and initialize().

132 {
133  ASSERT(networkConfigurator);
134  if (par("configureRoutingTable").boolValue())
136 }
IIPv4RoutingTable * routingTable
Definition: IPv4NodeConfigurator.h:44
virtual void configureRoutingTable(IIPv4RoutingTable *routingTable)
Configures the provided routing table based on the current network configuration. ...
Definition: IPv4NetworkConfigurator.cc:175
IPv4NetworkConfigurator * networkConfigurator
Definition: IPv4NodeConfigurator.h:45
virtual void inet::IPv4NodeConfigurator::handleMessage ( cMessage *  msg)
inlineoverrideprotectedvirtual
52 { throw cRuntimeError("this module doesn't handle messages, it runs only in initialize()"); }
bool inet::IPv4NodeConfigurator::handleOperationStage ( LifecycleOperation operation,
int  stage,
IDoneCallback doneCallback 
)
overrideprotectedvirtual

Perform one stage of a lifecycle operation.

Processing may be done entirely within this method, or may be a longer process that involves nonzero simulation time or several events, and is triggered by this method call.

Return value: true = "done"; false = "not yet done, will invoke doneCallback when done"

Implements inet::ILifecycle.

75 {
76  Enter_Method_Silent();
77  if (dynamic_cast<NodeStartOperation *>(operation)) {
79  prepareNode();
83  }
84  }
85  else if (dynamic_cast<NodeShutdownOperation *>(operation)) { /*nothing to do*/
86  ;
87  }
88  else if (dynamic_cast<NodeCrashOperation *>(operation)) { /*nothing to do*/
89  ;
90  }
91  else
92  throw cRuntimeError("Unsupported lifecycle operation '%s'", operation->getClassName());
93  return true;
94 }
virtual void prepareNode()
Definition: IPv4NodeConfigurator.cc:96
Definition: NodeOperations.h:50
Definition: NodeOperations.h:49
IPv4NetworkConfigurator * networkConfigurator
Definition: IPv4NodeConfigurator.h:45
Stage
Definition: NodeOperations.h:46
virtual void configureInterface()
Definition: IPv4NodeConfigurator.cc:124
virtual void configureRoutingTable()
Definition: IPv4NodeConfigurator.cc:131
void inet::IPv4NodeConfigurator::initialize ( int  stage)
overrideprotectedvirtual
39 {
40  cSimpleModule::initialize(stage);
41 
42  if (stage == INITSTAGE_LOCAL) {
43  cModule *node = getContainingNode(this);
44  if (!node)
45  throw cRuntimeError("The container @networkNode module not found");
46  const char *networkConfiguratorPath = par("networkConfiguratorModule");
47  nodeStatus = dynamic_cast<NodeStatus *>(node->getSubmodule("status"));
48  interfaceTable = getModuleFromPar<IInterfaceTable>(par("interfaceTableModule"), this);
49  routingTable = L3AddressResolver().findIPv4RoutingTableOf(node);
50 
51  if (!networkConfiguratorPath[0])
52  networkConfigurator = nullptr;
53  else {
54  cModule *module = getModuleByPath(networkConfiguratorPath);
55  if (!module)
56  throw cRuntimeError("Configurator module '%s' not found (check the 'networkConfiguratorModule' parameter)", networkConfiguratorPath);
57  networkConfigurator = check_and_cast<IPv4NetworkConfigurator *>(module);
58  }
59  }
60  else if (stage == INITSTAGE_NETWORK_LAYER) {
62  prepareNode();
63  }
64  else if (stage == INITSTAGE_NETWORK_LAYER_2) {
67  }
68  else if (stage == INITSTAGE_NETWORK_LAYER_3) {
71  }
72 }
virtual void prepareNode()
Definition: IPv4NodeConfigurator.cc:96
IIPv4RoutingTable * routingTable
Definition: IPv4NodeConfigurator.h:44
Initialization of network-layer protocols, stage 3.
Definition: InitStages.h:84
IPv4NetworkConfigurator * networkConfigurator
Definition: IPv4NodeConfigurator.h:45
Initialization of network-layer protocols, stage 1.
Definition: InitStages.h:72
NodeStatus * nodeStatus
Definition: IPv4NodeConfigurator.h:42
Local initializations.
Definition: InitStages.h:35
IInterfaceTable * interfaceTable
Definition: IPv4NodeConfigurator.h:43
cModule * getContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:65
Initialization of network-layer protocols, stage 2.
Definition: InitStages.h:78
virtual void configureInterface()
Definition: IPv4NodeConfigurator.cc:124
virtual void configureRoutingTable()
Definition: IPv4NodeConfigurator.cc:131
virtual State getState() const
Definition: NodeStatus.h:48
Definition: NodeStatus.h:40
virtual int inet::IPv4NodeConfigurator::numInitStages ( ) const
inlineoverrideprotectedvirtual
51 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::IPv4NodeConfigurator::prepareInterface ( InterfaceEntry interfaceEntry)
protectedvirtual

Referenced by prepareNode().

103 {
104  ASSERT(!interfaceEntry->ipv4Data());
105  IPv4InterfaceData *interfaceData = new IPv4InterfaceData();
106  interfaceEntry->setIPv4Data(interfaceData);
107  if (interfaceEntry->isLoopback()) {
108  // we may reconfigure later it to be the routerId
109  interfaceData->setIPAddress(IPv4Address::LOOPBACK_ADDRESS);
110  interfaceData->setNetmask(IPv4Address::LOOPBACK_NETMASK);
111  interfaceData->setMetric(1);
112  }
113  else {
114  // metric: some hints: OSPF cost (2e9/bps value), MS KB article Q299540, ...
115  interfaceData->setMetric((int)ceil(2e9 / interfaceEntry->getDatarate())); // use OSPF cost as default
116  if (interfaceEntry->isMulticast()) {
117  interfaceData->joinMulticastGroup(IPv4Address::ALL_HOSTS_MCAST);
119  interfaceData->joinMulticastGroup(IPv4Address::ALL_ROUTERS_MCAST);
120  }
121  }
122 }
IIPv4RoutingTable * routingTable
Definition: IPv4NodeConfigurator.h:44
static const IPv4Address LOOPBACK_NETMASK
255.0.0.0
Definition: IPv4Address.h:104
static const IPv4Address ALL_HOSTS_MCAST
224.0.0.1 All hosts on a subnet
Definition: IPv4Address.h:107
virtual bool isForwardingEnabled() const =0
Forwarding on/off.
static const IPv4Address LOOPBACK_ADDRESS
127.0.0.1
Definition: IPv4Address.h:103
static const IPv4Address ALL_ROUTERS_MCAST
224.0.0.2 All routers on a subnet
Definition: IPv4Address.h:108
void inet::IPv4NodeConfigurator::prepareNode ( )
protectedvirtual

Referenced by handleOperationStage(), and initialize().

97 {
98  for (int i = 0; i < interfaceTable->getNumInterfaces(); i++)
100 }
virtual void prepareInterface(InterfaceEntry *interfaceEntry)
Definition: IPv4NodeConfigurator.cc:102
IInterfaceTable * interfaceTable
Definition: IPv4NodeConfigurator.h:43
virtual int getNumInterfaces() const =0
Returns the number of interfaces.
virtual InterfaceEntry * getInterface(int pos) const =0
Returns the InterfaceEntry specified by an index 0..numInterfaces-1.

Member Data Documentation

IInterfaceTable* inet::IPv4NodeConfigurator::interfaceTable
protected
IPv4NetworkConfigurator* inet::IPv4NodeConfigurator::networkConfigurator
protected
NodeStatus* inet::IPv4NodeConfigurator::nodeStatus
protected

Referenced by initialize(), and IPv4NodeConfigurator().

IIPv4RoutingTable* inet::IPv4NodeConfigurator::routingTable
protected

The documentation for this class was generated from the following files: