INET Framework for OMNeT++/OMNEST
inet::OperationalMixin< T > Class Template Referenceabstract

#include <OperationalMixin.h>

Inheritance diagram for inet::OperationalMixin< T >:
inet::units::value< Value, Units > inet::ILifecycle

Classes

class  Operation
 

Protected Types

enum  State {
  STARTING_OPERATION, OPERATING, STOPPING_OPERATION, CRASHING_OPERATION,
  NOT_OPERATING
}
 

Protected Member Functions

virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
virtual void refreshDisplay () const override
 
virtual void handleMessage (cMessage *msg) override
 
virtual void handleMessageWhenDown (cMessage *msg)
 
virtual void handleMessageWhenUp (cMessage *msg)=0
 
virtual bool handleOperationStage (LifecycleOperation *operation, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 
virtual void handleStartOperation (LifecycleOperation *operation)=0
 
virtual void handleStopOperation (LifecycleOperation *operation)=0
 
virtual void handleCrashOperation (LifecycleOperation *operation)=0
 
virtual State getInitialOperationalState () const
 Returns initial operational state: OPERATING or NOT_OPERATING. More...
 
virtual bool isInitializeStage (int stage) const =0
 
virtual bool isModuleStartStage (int stage) const =0
 
virtual bool isModuleStopStage (int stage) const =0
 
virtual void handleActiveOperationTimeout (cMessage *message)
 

Protected Attributes

State operationalState = NOT_OPERATING
 
simtime_t lastChange
 
Operation activeOperation
 
cMessage * activeOperationTimeout = nullptr
 
cMessage * activeOperationExtraTimer = nullptr
 
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 ()
 
virtual ~OperationalMixin ()
 }@ More...
 

Additional Inherited Members

- Public Types inherited from inet::units::value< Value, Units >
typedef Value value_type
 
typedef Units unit
 
- Public Member Functions inherited from inet::units::value< Value, Units >
 value ()
 
 value (const value_type &v)
 
template<typename OtherValue , typename OtherUnits >
 value (const value< OtherValue, OtherUnits > &v)
 
std::string str () const
 
const value_typeget () const
 
void set (const value_type &v)
 
template<typename OtherValue , typename OtherUnits >
valueoperator= (const value< OtherValue, OtherUnits > &other)
 
template<typename OtherValue , typename OtherUnits , typename ResultValue = typename std::remove_cv<decltype(Value() + OtherValue())>::type>
value< ResultValue, Units > operator+ (const value< OtherValue, OtherUnits > &other) const
 
template<typename OtherValue , typename OtherUnits >
valueoperator+= (const value< OtherValue, OtherUnits > &other)
 
template<typename OtherValue , typename OtherUnits >
valueoperator-= (const value< OtherValue, OtherUnits > &other)
 
template<typename OtherValue , typename OtherUnits , typename ResultValue = typename std::remove_cv<decltype(Value() - OtherValue())>::type>
value< ResultValue, Units > operator- (const value< OtherValue, OtherUnits > &other) const
 
value operator- () const
 
template<typename OtherValue , typename OtherUnits , typename ResultValue = typename std::remove_cv<decltype(Value() * OtherValue())>::type>
value< ResultValue, compose< Units, OtherUnits > > operator* (const value< OtherValue, OtherUnits > &other) const
 
template<typename OtherValue >
value operator* (OtherValue v) const
 
valueoperator*= (const value_type &v)
 
template<typename OtherValue , typename OtherUnits , typename ResultValue = typename std::remove_cv<decltype(Value() / OtherValue())>::type>
value< ResultValue, compose< Units, pow< OtherUnits, -1 > > > operator/ (const value< OtherValue, OtherUnits > &other) const
 
value operator/ (const value_type &v) const
 
valueoperator/= (const value_type &v)
 
template<typename OtherValue , typename OtherUnits >
bool operator== (const value< OtherValue, OtherUnits > &other) const
 
template<typename OtherValue , typename OtherUnits >
bool operator!= (const value< OtherValue, OtherUnits > &other) const
 
template<typename OtherValue , typename OtherUnits >
bool operator< (const value< OtherValue, OtherUnits > &other) const
 
template<typename OtherValue , typename OtherUnits >
bool operator<= (const value< OtherValue, OtherUnits > &other) const
 
template<typename OtherValue , typename OtherUnits >
bool operator> (const value< OtherValue, OtherUnits > &other) const
 
template<typename OtherValue , typename OtherUnits >
bool operator>= (const value< OtherValue, OtherUnits > &other) const
 
valueoperator++ ()
 
value operator++ (int)
 
valueoperator-- ()
 
value operator-- (int)
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 

Member Enumeration Documentation

◆ State

template<typename T >
enum inet::OperationalMixin::State
protected
Enumerator
STARTING_OPERATION 
OPERATING 
STOPPING_OPERATION 
CRASHING_OPERATION 
NOT_OPERATING 
19  {
21  /*SUSPENDING_OPERATION, OPERATION_SUSPENDED, RESUMING_OPERATION */
22  };

Constructor & Destructor Documentation

◆ ~OperationalMixin()

template<typename T >
inet::OperationalMixin< T >::~OperationalMixin
virtual

}@

20 {
21  T::cancelAndDelete(activeOperationExtraTimer);
22  T::cancelAndDelete(activeOperationTimeout);
23 }

Member Function Documentation

◆ delayActiveOperationFinish()

template<typename T >
void inet::OperationalMixin< T >::delayActiveOperationFinish ( simtime_t  timeout)
protectedvirtual
162 {
163  ASSERT(activeOperation.operation != nullptr);
165  scheduleOperationTimeout(timeout);
166 }

◆ finishActiveOperation()

template<typename T >
void inet::OperationalMixin< T >::finishActiveOperation
protectedvirtual
189 {
192  T::cancelEvent(activeOperationExtraTimer);
193  T::cancelEvent(activeOperationTimeout);
195  }
197 }

◆ getInitialOperationalState()

template<typename T >
OperationalMixin< T >::State inet::OperationalMixin< T >::getInitialOperationalState
protectedvirtual

Returns initial operational state: OPERATING or NOT_OPERATING.

154 {
155  cModule *node = findContainingNode(this);
156  NodeStatus *nodeStatus = node ? check_and_cast_nullable<NodeStatus *>(node->getSubmodule("status")) : nullptr;
157  return (!nodeStatus || nodeStatus->getState() == NodeStatus::UP) ? OPERATING : NOT_OPERATING;
158 }

◆ handleActiveOperationTimeout()

template<typename T >
void inet::OperationalMixin< T >::handleActiveOperationTimeout ( cMessage *  message)
protectedvirtual

◆ handleCrashOperation()

template<typename T >
virtual void inet::OperationalMixin< T >::handleCrashOperation ( LifecycleOperation operation)
protectedpure virtual

◆ handleMessage()

template<typename T >
void inet::OperationalMixin< T >::handleMessage ( cMessage *  msg)
overrideprotectedvirtual

Reimplemented in inet::MacForwardingTable.

46 {
47  if (message == activeOperationExtraTimer)
49  else if (message == activeOperationTimeout) {
50  T::cancelEvent(activeOperationExtraTimer);
52  }
53  else {
54  switch (operationalState) {
55  case STARTING_OPERATION:
56  case OPERATING:
57  case STOPPING_OPERATION:
58  handleMessageWhenUp(message);
59  break;
60  case NOT_OPERATING:
61  handleMessageWhenDown(message);
62  break;
63  case CRASHING_OPERATION:
64  default:
65  throw cRuntimeError("Invalid operational state: %d", (int)operationalState);
66  }
67  }
68 }

◆ handleMessageWhenDown()

template<typename T >
void inet::OperationalMixin< T >::handleMessageWhenDown ( cMessage *  msg)
protectedvirtual

Reimplemented in inet::MacProtocolBase, inet::physicallayer::Radio, and inet::PacketReceiverBase.

72 {
73  if (message->isSelfMessage())
74  throw cRuntimeError("Self message '%s' received when %s is down", message->getName(), T::getComponentType()->getName());
75  else if (simTime() == lastChange)
76  EV_WARN << T::getComponentType()->getName() << " is down, dropping '" << message->getName() << "' message\n";
77  else
78  throw cRuntimeError("Message '%s' received when %s is down", message->getName(), T::getComponentType()->getName());
79  delete message;
80 }

Referenced by inet::PacketReceiverBase::handleMessageWhenDown().

◆ handleMessageWhenUp()

◆ handleOperationStage()

template<typename T >
bool inet::OperationalMixin< T >::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.

84 {
85  Enter_Method("handleOperationStage");
86  int stage = operation->getCurrentStage();
87  if (dynamic_cast<ModuleStartOperation *>(operation)) {
88  if (isModuleStartStage(stage)) {
90  setupActiveOperation(operation, doneCallback, OPERATING);
91  handleStartOperation(operation);
94  return activeOperation.operation == nullptr;
95  }
96  }
97  else if (dynamic_cast<ModuleStopOperation *>(operation)) {
98  if (isModuleStopStage(stage)) {
100  setupActiveOperation(operation, doneCallback, NOT_OPERATING);
101  handleStopOperation(operation);
104  return activeOperation.operation == nullptr;
105  }
106  }
107  else if (dynamic_cast<ModuleCrashOperation *>(operation)) {
108  if (stage == ModuleCrashOperation::STAGE_CRASH) {
110  setupActiveOperation(operation, doneCallback, NOT_OPERATING);
111  handleCrashOperation(operation);
113  return true;
114  }
115  }
116  else
117  throw cRuntimeError("unaccepted Lifecycle operation: (%s)%s", operation->getClassName(), operation->getName());
118  return true;
119 }

◆ handleStartOperation()

◆ handleStopOperation()

template<typename T >
virtual void inet::OperationalMixin< T >::handleStopOperation ( LifecycleOperation operation)
protectedpure virtual

◆ initialize()

template<typename T >
void inet::OperationalMixin< T >::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented in inet::Flooding, inet::LMac, inet::WiseRoute, inet::Ieee802154Mac, inet::XMac, inet::ieee80211::Ieee80211MgmtAp, inet::BMac, inet::ieee80211::Ieee80211Mac, inet::ProbabilisticBroadcast, inet::ieee80211::Ieee80211MgmtBase, inet::AdaptiveProbabilisticBroadcast, inet::ieee80211::Ieee80211MgmtApBase, inet::ieee80211::Ieee80211MgmtStaSimplified, inet::ieee80211::Ieee80211MgmtAdhoc, inet::RsvpTe, inet::PimDm, inet::Ipv4, inet::PimSm, inet::Udp, inet::Ldp, inet::PimBase, inet::EthernetMacBase, inet::NextHopForwarding, inet::physicallayer::Radio, inet::tcp::Tcp, inet::aodv::Aodv, inet::Rip, inet::CsmaCaMac, inet::ieee80211::Ieee80211MgmtSta, inet::InterfaceTable, inet::Arp, inet::dymo::Dymo, inet::PingApp, inet::UdpBasicBurst, inet::Dsdv, inet::AckingMac, inet::Stp, inet::Gpsr, inet::GlobalArp, inet::Ppp, inet::MacForwardingTable, inet::DhcpClient, inet::UdpVideoStreamServer, inet::EthernetEncapsulation, inet::Ted, inet::IpvxTrafGen, inet::ospfv2::Ospfv2, inet::DhcpServer, inet::StpBase, inet::EtherTrafGen, inet::EtherAppClient, inet::Ieee8021dRelay, inet::Rstp, inet::TcpSessionApp, inet::Pim, inet::UdpBasicApp, inet::MacProtocolBase, inet::NetworkProtocolBase, inet::PacketTransmitterBase, inet::UdpSink, inet::Ieee8022Llc, inet::TunnelApp, inet::TcpAppBase, inet::physicallayer::Ieee80211Radio, inet::PacketReceiverBase, inet::Loopback, inet::EtherAppServer, inet::UdpVideoStreamClient, inet::physicallayer::ShortcutRadio, inet::Ieee8022LlcSocketIo, inet::TcpBasicClientApp, inet::TcpEchoApp, inet::TcpServerHostApp, inet::EthernetCsmaMac, inet::ShortcutMac, inet::HostAutoConfigurator, inet::IpvxTrafSink, inet::MacRelayUnitBase, inet::EthernetMac, inet::StreamThroughTransmitter, inet::SimpleClockSynchronizer, inet::TelnetApp, inet::TcpSinkApp, inet::physicallayer::PhysicalLayerBase, inet::EthernetSocketIo, inet::UdpEchoApp, inet::UdpSocketIo, inet::Tun, inet::physicallayer::ApskRadio, inet::StreamingReceiverBase, inet::StreamingTransmitterBase, inet::DestreamingReceiver, and inet::StreamThroughReceiver.

27 {
28  T::initialize(stage);
29  if (stage == INITSTAGE_LOCAL) {
30  WATCH(operationalState);
31  activeOperationTimeout = new cMessage("ActiveOperationTimeout");
32  activeOperationExtraTimer = new cMessage("ActiveOperationExtraTimer");
34  }
35  if (isInitializeStage(stage)) {
36  auto state = getInitialOperationalState();
37  ASSERT(state == NOT_OPERATING || state == OPERATING);
38  setOperationalState(state);
40  handleStartOperation(nullptr); // TODO use an InitializeOperation with current stage value
41  }
42 }

Referenced by inet::PacketReceiverBase::initialize().

◆ isDown()

template<typename T >
virtual bool inet::OperationalMixin< T >::isDown ( ) const
inlineprotectedvirtual
67 { return operationalState == NOT_OPERATING /* || operationalState == OPERATION_SUSPENDED */; }

◆ isInitializeStage()

◆ isModuleStartStage()

◆ isModuleStopStage()

◆ isUp()

template<typename T >
virtual bool inet::OperationalMixin< T >::isUp ( ) const
inlineprotectedvirtual

utility functions

66 { return operationalState != NOT_OPERATING /* && operationalState != OPERATION_SUSPENDED */; }

◆ numInitStages()

template<typename T >
virtual int inet::OperationalMixin< T >::numInitStages ( ) const
inlineoverrideprotectedvirtual
41 { return NUM_INIT_STAGES; }

◆ refreshDisplay()

template<typename T >
void inet::OperationalMixin< T >::refreshDisplay
overrideprotectedvirtual
201 {
202  auto& displayString = T::getDisplayString();
203  switch (operationalState) {
204  case STARTING_OPERATION:
205  displayString.setTagArg("i2", 0, "status/up");
206  break;
207  case OPERATING:
208  displayString.removeTag("i2");
209  break;
210  case STOPPING_OPERATION:
211  case CRASHING_OPERATION:
212  displayString.setTagArg("i2", 0, "status/down");
213  break;
214  case NOT_OPERATING:
215  displayString.setTagArg("i2", 0, "status/cross");
216  break;
217  default:
218  break;
219  }
220 }

◆ scheduleOperationTimeout()

template<typename T >
void inet::OperationalMixin< T >::scheduleOperationTimeout ( simtime_t  timeout)
protectedvirtual
123 {
125  ASSERT(!activeOperationTimeout->isScheduled());
127  T::scheduleAt(simTime() + timeout, activeOperationTimeout);
128  // TODO schedule timer and use module parameter
129 }

◆ setOperationalState()

template<typename T >
void inet::OperationalMixin< T >::setOperationalState ( State  newState)
protectedvirtual
147 {
148  operationalState = newState;
149  lastChange = simTime();
150 }

◆ setupActiveOperation()

template<typename T >
void inet::OperationalMixin< T >::setupActiveOperation ( LifecycleOperation operation,
IDoneCallback doneCallback,
State  endState 
)
protectedvirtual
140 {
141  ASSERT(activeOperation.operation == nullptr);
142  activeOperation.set(operation, doneCallback, endState);
143 }

◆ startActiveOperationExtraTime()

template<typename T >
void inet::OperationalMixin< T >::startActiveOperationExtraTime ( simtime_t  delay = SIMTIME_ZERO)
protectedvirtual
170 {
171  ASSERT(extraTime >= SIMTIME_ZERO);
172  ASSERT(!activeOperationExtraTimer->isScheduled());
175  T::scheduleAt(simTime() + extraTime, activeOperationExtraTimer);
176 }

◆ startActiveOperationExtraTimeOrFinish()

template<typename T >
void inet::OperationalMixin< T >::startActiveOperationExtraTimeOrFinish ( simtime_t  extraTime)
protectedvirtual
180 {
181  if (extraTime >= SIMTIME_ZERO)
183  else
185 }

Member Data Documentation

◆ activeOperation

template<typename T >
Operation inet::OperationalMixin< T >::activeOperation
protected

◆ activeOperationExtraTimer

template<typename T >
cMessage* inet::OperationalMixin< T >::activeOperationExtraTimer = nullptr
protected

◆ activeOperationTimeout

template<typename T >
cMessage* inet::OperationalMixin< T >::activeOperationTimeout = nullptr
protected

◆ lastChange

template<typename T >
simtime_t inet::OperationalMixin< T >::lastChange
protected

◆ operationalState

template<typename T >
State inet::OperationalMixin< T >::operationalState = NOT_OPERATING
protected

The documentation for this class was generated from the following files:
inet::OperationalMixin::getInitialOperationalState
virtual State getInitialOperationalState() const
Returns initial operational state: OPERATING or NOT_OPERATING.
Definition: OperationalMixinImpl.h:153
inet::findContainingNode
cModule * findContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:31
inet::OperationalMixin::CRASHING_OPERATION
@ CRASHING_OPERATION
Definition: OperationalMixin.h:20
inet::OperationalMixin::STOPPING_OPERATION
@ STOPPING_OPERATION
Definition: OperationalMixin.h:20
inet::OperationalMixin::operationalState
State operationalState
Definition: OperationalMixin.h:23
inet::OperationalMixin::startActiveOperationExtraTime
virtual void startActiveOperationExtraTime(simtime_t delay=SIMTIME_ZERO)
Definition: OperationalMixinImpl.h:169
inet::OperationalMixin::setupActiveOperation
virtual void setupActiveOperation(LifecycleOperation *operation, IDoneCallback *doneCallback, State)
Definition: OperationalMixinImpl.h:139
inet::OperationalMixin::Operation::delayFinish
void delayFinish()
Definition: OperationalMixin.h:34
inet::OperationalMixin::activeOperationExtraTimer
cMessage * activeOperationExtraTimer
Definition: OperationalMixin.h:38
inet::OperationalMixin::activeOperation
Operation activeOperation
Definition: OperationalMixin.h:36
inet::IDoneCallback::invoke
virtual void invoke()=0
inet::OperationalMixin::isModuleStartStage
virtual bool isModuleStartStage(int stage) const =0
inet::OperationalMixin::Operation::doneCallback
IDoneCallback * doneCallback
Definition: OperationalMixin.h:29
inet::OperationalMixin::handleMessageWhenUp
virtual void handleMessageWhenUp(cMessage *msg)=0
inet::OperationalMixin::handleCrashOperation
virtual void handleCrashOperation(LifecycleOperation *operation)=0
inet::OperationalMixin::handleStartOperation
virtual void handleStartOperation(LifecycleOperation *operation)=0
inet::OperationalMixin::handleActiveOperationTimeout
virtual void handleActiveOperationTimeout(cMessage *message)
Definition: OperationalMixinImpl.h:132
inet::OperationalMixin::Operation::endState
State endState
Definition: OperationalMixin.h:30
inet::OperationalMixin::isInitializeStage
virtual bool isInitializeStage(int stage) const =0
inet::OperationalMixin::Operation::isDelayedFinish
bool isDelayedFinish
Definition: OperationalMixin.h:31
inet::OperationalMixin::isModuleStopStage
virtual bool isModuleStopStage(int stage) const =0
inet::OperationalMixin::STARTING_OPERATION
@ STARTING_OPERATION
Definition: OperationalMixin.h:20
inet::OperationalMixin::Operation::clear
void clear()
Definition: OperationalMixin.h:33
inet::OperationalMixin::lastChange
simtime_t lastChange
Definition: OperationalMixin.h:24
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
inet::OperationalMixin::OPERATING
@ OPERATING
Definition: OperationalMixin.h:20
NUM_INIT_STAGES
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
inet::sctp::max
double max(const double a, const double b)
Returns the maximum of a and b.
Definition: SctpAssociation.h:266
inet::OperationalMixin::NOT_OPERATING
@ NOT_OPERATING
Definition: OperationalMixin.h:20
inet::ModuleCrashOperation::STAGE_CRASH
@ STAGE_CRASH
Definition: ModuleOperations.h:76
inet::NodeStatus::UP
@ UP
Definition: NodeStatus.h:28
Enter_Method
#define Enter_Method(...)
Definition: SelfDoc.h:71
inet::OperationalMixin::handleStopOperation
virtual void handleStopOperation(LifecycleOperation *operation)=0
inet::OperationalMixin::Operation::set
void set(LifecycleOperation *operation_, IDoneCallback *doneCallback_, State endState_)
Definition: OperationalMixin.h:32
inet::OperationalMixin::finishActiveOperation
virtual void finishActiveOperation()
Definition: OperationalMixinImpl.h:188
inet::OperationalMixin::activeOperationTimeout
cMessage * activeOperationTimeout
Definition: OperationalMixin.h:37
inet::OperationalMixin::handleMessageWhenDown
virtual void handleMessageWhenDown(cMessage *msg)
Definition: OperationalMixinImpl.h:71
inet::OperationalMixin::setOperationalState
virtual void setOperationalState(State newState)
Definition: OperationalMixinImpl.h:146
inet::OperationalMixin::Operation::operation
LifecycleOperation * operation
Definition: OperationalMixin.h:28
inet::OperationalMixin::scheduleOperationTimeout
virtual void scheduleOperationTimeout(simtime_t timeout)
Definition: OperationalMixinImpl.h:122