INET Framework for OMNeT++/OMNEST
inet::visualizer::LinkBreakVisualizerBase Class Referenceabstract

#include <LinkBreakVisualizerBase.h>

Inheritance diagram for inet::visualizer::LinkBreakVisualizerBase:
inet::visualizer::VisualizerBase inet::visualizer::LinkBreakCanvasVisualizer inet::visualizer::LinkBreakOsgVisualizer

Classes

class  LinkBreakVisualization
 

Public Member Functions

virtual ~LinkBreakVisualizerBase ()
 
virtual void receiveSignal (cComponent *source, simsignal_t signal, cObject *object, cObject *details) override
 

Protected Member Functions

virtual void initialize (int stage) override
 
virtual void handleParameterChange (const char *name) override
 
virtual void refreshDisplay () const override
 
virtual void subscribe ()
 
virtual void unsubscribe ()
 
virtual const LinkBreakVisualizationcreateLinkBreakVisualization (cModule *transmitter, cModule *receiver) const =0
 
virtual void addLinkBreakVisualization (const LinkBreakVisualization *linkBreakVisualization)
 
virtual void removeLinkBreakVisualization (const LinkBreakVisualization *linkBreakVisualization)
 
virtual void removeAllLinkBreakVisualizations ()
 
virtual void setAlpha (const LinkBreakVisualization *linkBreakVisualization, double alpha) const =0
 
virtual cModule * findNode (MACAddress address)
 
- Protected Member Functions inherited from inet::visualizer::VisualizerBase
virtual int numInitStages () const override
 
virtual Coord getPosition (const cModule *networkNode) const
 
virtual Coord getContactPosition (const cModule *networkNode, const Coord &fromPosition, const char *contactMode, double contactSpacing) const
 
virtual InterfaceEntrygetInterfaceEntry (cModule *networkNode, cModule *module) const
 

Protected Attributes

std::map< std::pair< int, int >, const LinkBreakVisualization * > linkBreakVisualizations
 
Parameters
bool displayLinkBreaks = false
 
NetworkNodeFilter nodeFilter
 
InterfaceFilter interfaceFilter
 
PacketFilter packetFilter
 
const char * icon = nullptr
 
double iconTintAmount = NaN
 
cFigure::Color iconTintColor
 
const char * fadeOutMode = nullptr
 
double fadeOutTime = NaN
 
double fadeOutAnimationSpeed = NaN
 
- Protected Attributes inherited from inet::visualizer::VisualizerBase
cModule * visualizerTargetModule = nullptr
 
const char * tags = nullptr
 

Constructor & Destructor Documentation

inet::visualizer::LinkBreakVisualizerBase::~LinkBreakVisualizerBase ( )
virtual
40 {
42  unsubscribe();
43 }

Member Function Documentation

void inet::visualizer::LinkBreakVisualizerBase::addLinkBreakVisualization ( const LinkBreakVisualization linkBreakVisualization)
protectedvirtual

Reimplemented in inet::visualizer::LinkBreakCanvasVisualizer.

Referenced by inet::visualizer::LinkBreakCanvasVisualizer::addLinkBreakVisualization(), and receiveSignal().

153 {
154  auto key = std::pair<int, int>(linkBreakVisualization->transmitterModuleId, linkBreakVisualization->receiverModuleId);
155  linkBreakVisualizations[key] = linkBreakVisualization;
156 }
virtual const LinkBreakVisualization* inet::visualizer::LinkBreakVisualizerBase::createLinkBreakVisualization ( cModule *  transmitter,
cModule *  receiver 
) const
protectedpure virtual
cModule * inet::visualizer::LinkBreakVisualizerBase::findNode ( MACAddress  address)
protectedvirtual

Referenced by receiveSignal().

167 {
168  L3AddressResolver addressResolver;
169  for (cModule::SubmoduleIterator it(getSystemModule()); !it.end(); it++) {
170  auto networkNode = *it;
171  if (isNetworkNode(networkNode)) {
172  auto interfaceTable = addressResolver.findInterfaceTableOf(networkNode);
173  for (int i = 0; i < interfaceTable->getNumInterfaces(); i++)
174  if (interfaceTable->getInterface(i)->getMacAddress() == address)
175  return networkNode;
176  }
177  }
178  return nullptr;
179 }
bool isNetworkNode(const cModule *mod)
Returns true if the given module is a network node, i.e.
Definition: ModuleAccess.cc:28
void inet::visualizer::LinkBreakVisualizerBase::handleParameterChange ( const char *  name)
overrideprotectedvirtual
67 {
68  if (name != nullptr) {
69  if (!strcmp(name, "nodeFilter"))
70  nodeFilter.setPattern(par("nodeFilter"));
71  else if (!strcmp(name, "interfaceFilter"))
72  interfaceFilter.setPattern(par("interfaceFilter"));
73  else if (!strcmp(name, "packetFilter"))
74  packetFilter.setPattern(par("packetFilter"));
76  }
77 }
void setPattern(const char *pattern)
Definition: NetworkNodeFilter.cc:24
void setPattern(const char *pattern)
Definition: InterfaceFilter.cc:24
void setPattern(const char *pattern)
Definition: PacketFilter.cc:24
void inet::visualizer::LinkBreakVisualizerBase::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::visualizer::VisualizerBase.

Reimplemented in inet::visualizer::LinkBreakOsgVisualizer, and inet::visualizer::LinkBreakCanvasVisualizer.

Referenced by inet::visualizer::LinkBreakCanvasVisualizer::initialize().

46 {
48  if (!hasGUI()) return;
49  if (stage == INITSTAGE_LOCAL) {
50  displayLinkBreaks = par("displayLinkBreaks");
51  nodeFilter.setPattern(par("nodeFilter"));
52  interfaceFilter.setPattern(par("interfaceFilter"));
53  packetFilter.setPattern(par("packetFilter"));
54  icon = par("icon");
55  iconTintAmount = par("iconTintAmount");
56  if (iconTintAmount != 0)
57  iconTintColor = cFigure::Color(par("iconTintColor"));
58  fadeOutMode = par("fadeOutMode");
59  fadeOutTime = par("fadeOutTime");
60  fadeOutAnimationSpeed = par("fadeOutAnimationSpeed");
62  subscribe();
63  }
64 }
void setPattern(const char *pattern)
Definition: NetworkNodeFilter.cc:24
void setPattern(const char *pattern)
Definition: InterfaceFilter.cc:24
virtual void initialize(int stage) override
Definition: VisualizerBase.cc:29
Local initializations.
Definition: InitStages.h:35
void setPattern(const char *pattern)
Definition: PacketFilter.cc:24
Color
Definition: DiffservUtil.h:30
void inet::visualizer::LinkBreakVisualizerBase::receiveSignal ( cComponent *  source,
simsignal_t  signal,
cObject *  object,
cObject *  details 
)
overridevirtual
120 {
121  Enter_Method_Silent();
122  if (signal == NF_LINK_BREAK) {
123  MACAddress transmitterAddress;
124  MACAddress receiverAddress;
125  if (auto frame = dynamic_cast<IMACFrame *>(object)) {
126  transmitterAddress = frame->getTransmitterAddress();
127  receiverAddress = frame->getReceiverAddress();
128  }
129 #ifdef WITH_IEEE80211
130  if (auto frame = dynamic_cast<ieee80211::Ieee80211TwoAddressFrame *>(object)) {
131  transmitterAddress = frame->getTransmitterAddress();
132  receiverAddress = frame->getReceiverAddress();
133  }
134 #endif // WITH_IEEE80211
135  auto transmitter = findNode(transmitterAddress);
136  auto receiver = findNode(receiverAddress);
137  if (nodeFilter.matches(transmitter) && nodeFilter.matches(receiver)) {
138  auto key = std::pair<int, int>(transmitter->getId(), receiver->getId());
139  auto it = linkBreakVisualizations.find(key);
140  if (it == linkBreakVisualizations.end())
142  else {
143  auto linkBreakVisualization = it->second;
144  linkBreakVisualization->linkBreakAnimationPosition = AnimationPosition();
145  }
146  }
147  }
148  else
149  throw cRuntimeError("Unknown signal");
150 }
bool matches(const cModule *module) const
Definition: NetworkNodeFilter.cc:29
simsignal_t NF_LINK_BREAK
Definition: NotifierConsts.cc:43
void inet::visualizer::LinkBreakVisualizerBase::refreshDisplay ( ) const
overrideprotectedvirtual

Reimplemented in inet::visualizer::LinkBreakCanvasVisualizer.

Referenced by inet::visualizer::LinkBreakCanvasVisualizer::refreshDisplay().

80 {
81  AnimationPosition currentAnimationPosition;
82  std::vector<const LinkBreakVisualization *> removedLinkBreakVisualizations;
83  for (auto it : linkBreakVisualizations) {
84  auto linkBreakVisualization = it.second;
85  double delta;
86  if (!strcmp(fadeOutMode, "simulationTime"))
87  delta = (currentAnimationPosition.getSimulationTime() - linkBreakVisualization->linkBreakAnimationPosition.getSimulationTime()).dbl();
88  else if (!strcmp(fadeOutMode, "animationTime"))
89  delta = currentAnimationPosition.getAnimationTime() - linkBreakVisualization->linkBreakAnimationPosition.getAnimationTime();
90  else if (!strcmp(fadeOutMode, "realTime"))
91  delta = currentAnimationPosition.getRealTime() - linkBreakVisualization->linkBreakAnimationPosition.getRealTime();
92  else
93  throw cRuntimeError("Unknown fadeOutMode: %s", fadeOutMode);
94  if (delta > fadeOutTime)
95  removedLinkBreakVisualizations.push_back(linkBreakVisualization);
96  else
97  setAlpha(linkBreakVisualization, 1 - delta / fadeOutTime);
98  }
99  for (auto linkBreakVisualization : removedLinkBreakVisualizations) {
100  const_cast<LinkBreakVisualizerBase *>(this)->removeLinkBreakVisualization(linkBreakVisualization);
101  delete linkBreakVisualization;
102  }
103 }
void inet::visualizer::LinkBreakVisualizerBase::removeAllLinkBreakVisualizations ( )
protectedvirtual

Referenced by handleParameterChange().

182 {
183  std::vector<const LinkBreakVisualization *> removedLinkBreakVisualizations;
184  for (auto it : linkBreakVisualizations)
185  removedLinkBreakVisualizations.push_back(it.second);
186  for (auto it : removedLinkBreakVisualizations) {
188  delete it;
189  }
190 }
void inet::visualizer::LinkBreakVisualizerBase::removeLinkBreakVisualization ( const LinkBreakVisualization linkBreakVisualization)
protectedvirtual

Reimplemented in inet::visualizer::LinkBreakCanvasVisualizer.

Referenced by refreshDisplay(), removeAllLinkBreakVisualizations(), and inet::visualizer::LinkBreakCanvasVisualizer::removeLinkBreakVisualization().

159 {
160  auto key = std::pair<int, int>(linkBreakVisualization->transmitterModuleId, linkBreakVisualization->receiverModuleId);
161  auto it = linkBreakVisualizations.find(key);
162  linkBreakVisualizations.erase(it);
163 }
virtual void inet::visualizer::LinkBreakVisualizerBase::setAlpha ( const LinkBreakVisualization linkBreakVisualization,
double  alpha 
) const
protectedpure virtual
void inet::visualizer::LinkBreakVisualizerBase::subscribe ( )
protectedvirtual

Referenced by initialize().

106 {
107  auto subscriptionModule = getModuleFromPar<cModule>(par("subscriptionModule"), this);
108  subscriptionModule->subscribe(NF_LINK_BREAK, this);
109 }
simsignal_t NF_LINK_BREAK
Definition: NotifierConsts.cc:43
void inet::visualizer::LinkBreakVisualizerBase::unsubscribe ( )
protectedvirtual

Referenced by ~LinkBreakVisualizerBase().

112 {
113  // NOTE: lookup the module again because it may have been deleted first
114  auto subscriptionModule = getModuleFromPar<cModule>(par("subscriptionModule"), this, false);
115  if (subscriptionModule != nullptr)
116  subscriptionModule->unsubscribe(NF_LINK_BREAK, this);
117 }
simsignal_t NF_LINK_BREAK
Definition: NotifierConsts.cc:43

Member Data Documentation

bool inet::visualizer::LinkBreakVisualizerBase::displayLinkBreaks = false
protected
double inet::visualizer::LinkBreakVisualizerBase::fadeOutAnimationSpeed = NaN
protected
const char* inet::visualizer::LinkBreakVisualizerBase::fadeOutMode = nullptr
protected

Referenced by initialize(), and refreshDisplay().

double inet::visualizer::LinkBreakVisualizerBase::fadeOutTime = NaN
protected

Referenced by initialize(), and refreshDisplay().

const char* inet::visualizer::LinkBreakVisualizerBase::icon = nullptr
protected
double inet::visualizer::LinkBreakVisualizerBase::iconTintAmount = NaN
protected
cFigure::Color inet::visualizer::LinkBreakVisualizerBase::iconTintColor
protected
InterfaceFilter inet::visualizer::LinkBreakVisualizerBase::interfaceFilter
protected
std::map<std::pair<int, int>, const LinkBreakVisualization *> inet::visualizer::LinkBreakVisualizerBase::linkBreakVisualizations
protected
NetworkNodeFilter inet::visualizer::LinkBreakVisualizerBase::nodeFilter
protected
PacketFilter inet::visualizer::LinkBreakVisualizerBase::packetFilter
protected

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