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

Keeps track of the status of network node (up, down, etc.) for other modules, and also displays it as a small overlay icon on this module and on the module of the network node. More...

#include <NodeStatus.h>

Inheritance diagram for inet::NodeStatus:
inet::ILifecycle

Public Types

enum  State { UP, DOWN, GOING_UP, GOING_DOWN }
 

Public Member Functions

virtual State getState () const
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 

Static Public Attributes

static simsignal_t nodeStatusChangedSignal = registerSignal("nodeStatusChanged")
 

Protected Member Functions

virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
virtual void handleMessage (cMessage *msg) override
 
virtual bool handleOperationStage (LifecycleOperation *operation, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 
virtual void setState (State state)
 
virtual void refreshDisplay () const override
 

Static Protected Member Functions

static State getStateByName (const char *name)
 

Private Attributes

State state
 

Detailed Description

Keeps track of the status of network node (up, down, etc.) for other modules, and also displays it as a small overlay icon on this module and on the module of the network node.

Other modules can obtain the network node's status by calling the getState() method.

See NED file for more information.

Member Enumeration Documentation

◆ State

Enumerator
UP 
DOWN 
GOING_UP 
GOING_DOWN 
28 { UP, DOWN, GOING_UP, GOING_DOWN };

Member Function Documentation

◆ getState()

◆ getStateByName()

NodeStatus::State inet::NodeStatus::getStateByName ( const char *  name)
staticprotected
33 {
34  std::string temp = name;
35  std::transform(temp.begin(), temp.end(), temp.begin(), ::toupper);
36  cEnum *e = cEnum::get("inet::NodeStatus");
37  int state = e->lookup(temp.c_str(), -1);
38  if (state == -1)
39  throw cRuntimeError("Invalid state name '%s'", name);
40  return static_cast<State>(state);
41 }

Referenced by initialize().

◆ handleMessage()

virtual void inet::NodeStatus::handleMessage ( cMessage *  msg)
inlineoverrideprotectedvirtual
40 { throw cRuntimeError("This module doesn't handle messages"); }

◆ handleOperationStage()

bool inet::NodeStatus::handleOperationStage ( LifecycleOperation operation,
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.

44 {
45  Enter_Method("handleOperationStage");
46  int opStage = operation->getCurrentStage();
47  cModule *node = getContainingNode(this);
48  if (dynamic_cast<ModuleStartOperation *>(operation)) {
49  if (opStage == 0) {
50  EV << node->getFullPath() << " starting up" << endl;
51  if (getState() != DOWN)
52  throw cRuntimeError("Current node status is not 'down' at ModuleStartOperation");
54  }
55  // NOTE: this is not an 'else if' so that it works if there's only 1 stage
56  if (opStage == operation->getNumStages() - 1) {
57  ASSERT(getState() == GOING_UP);
58  setState(UP);
59  EV << node->getFullPath() << " started" << endl;
60  node->bubble("Node started");
61  }
62  }
63  else if (dynamic_cast<ModuleStopOperation *>(operation)) {
64  if (opStage == 0) {
65  EV << node->getFullPath() << " shutting down" << endl;
66  if (getState() != UP)
67  throw cRuntimeError("Current node status is not 'up' at ModuleStopOperation");
69  }
70  // NOTE: this is not an 'else if' so that it works if there's only 1 stage
71  if (opStage == operation->getNumStages() - 1) {
72  ASSERT(getState() == GOING_DOWN);
73  setState(DOWN);
74  EV << node->getFullPath() << " shut down" << endl;
75  node->bubble("Node shut down");
76  }
77  }
78  else if (dynamic_cast<ModuleCrashOperation *>(operation)) {
79  if (opStage == 0) {
80  EV << node->getFullPath() << " crashing" << endl;
81  if (getState() != UP)
82  throw cRuntimeError("Current node status is not 'up' at ModuleCrashOperation");
84  }
85  // NOTE: this is not an 'else if' so that it works if there's only 1 stage
86  if (opStage == operation->getNumStages() - 1) {
87  ASSERT(getState() == GOING_DOWN);
88  setState(DOWN);
89  EV << node->getFullPath() << " crashed" << endl;
90  node->bubble("Node crashed");
91  }
92  }
93  return true;
94 }

◆ initialize()

void inet::NodeStatus::initialize ( int  stage)
overrideprotectedvirtual
23 {
24  cSimpleModule::initialize(stage);
25 
26  if (stage == INITSTAGE_LOCAL) {
27  state = getStateByName(par("initialStatus"));
28  WATCH(state);
29  }
30 }

◆ numInitStages()

virtual int inet::NodeStatus::numInitStages ( ) const
inlineoverrideprotectedvirtual
38 { return NUM_INIT_STAGES; }

◆ refreshDisplay()

void inet::NodeStatus::refreshDisplay ( ) const
overrideprotectedvirtual
103 {
104  const char *icon;
105  const char *text;
106  switch (state) {
107  case UP:
108  icon = "";
109  text = "up";
110  break;
111  case DOWN:
112  icon = "status/cross";
113  text = "down";
114  break;
115  case GOING_UP:
116  icon = "status/execute";
117  text = "going up";
118  break;
119  case GOING_DOWN:
120  icon = "status/execute";
121  text = "going down";
122  break;
123  default:
124  throw cRuntimeError("Unknown status");
125  }
126  auto& displayString = getDisplayString();
127  displayString.setTagArg("t", 0, text);
128  cModule *node = getContainingNode(this);
129  if (*icon) {
130  displayString.setTagArg("i2", 0, icon);
131  node->getDisplayString().setTagArg("i2", 0, icon);
132  }
133  else {
134  displayString.removeTag("i2");
135  node->getDisplayString().removeTag("i2");
136  }
137 }

◆ setState()

void inet::NodeStatus::setState ( State  state)
protectedvirtual
97 {
98  state = s;
99  emit(nodeStatusChangedSignal, this);
100 }

Referenced by handleOperationStage().

Member Data Documentation

◆ nodeStatusChangedSignal

simsignal_t inet::NodeStatus::nodeStatusChangedSignal = registerSignal("nodeStatusChanged")
static

Referenced by setState().

◆ state

State inet::NodeStatus::state
private

The documentation for this class was generated from the following files:
inet::NodeStatus::setState
virtual void setState(State state)
Definition: NodeStatus.cc:96
inet::NodeStatus::GOING_DOWN
@ GOING_DOWN
Definition: NodeStatus.h:28
inet::NodeStatus::state
State state
Definition: NodeStatus.h:32
inet::getContainingNode
cModule * getContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:40
inet::units::constants::e
const value< double, units::C > e(1.602176487e-19)
inet::NodeStatus::DOWN
@ DOWN
Definition: NodeStatus.h:28
inet::units::values::s
value< double, units::s > s
Definition: Units.h:1235
inet::NodeStatus::GOING_UP
@ GOING_UP
Definition: NodeStatus.h:28
inet::NodeStatus::State
State
Definition: NodeStatus.h:28
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::NodeStatus::getStateByName
static State getStateByName(const char *name)
Definition: NodeStatus.cc:32
inet::NodeStatus::UP
@ UP
Definition: NodeStatus.h:28
Enter_Method
#define Enter_Method(...)
Definition: SelfDoc.h:71
inet::NodeStatus::nodeStatusChangedSignal
static simsignal_t nodeStatusChangedSignal
Definition: NodeStatus.h:29
inet::NodeStatus::getState
virtual State getState() const
Definition: NodeStatus.h:35