OMNeT++ API 6.1
Discrete Event Simulation Library
cfingerprint.h
1 //==========================================================================
2 // CFINGERPRINT.H - part of
3 // OMNeT++/OMNEST
4 // Discrete System Simulation in C++
5 //
6 //==========================================================================
7 
8 /*--------------------------------------------------------------*
9  Copyright (C) 1992-2008 Andras Varga
10  Copyright (C) 2006-2008 OpenSim Ltd.
11 
12  This file is distributed WITHOUT ANY WARRANTY. See the file
13  `license' for details on this and other legal matters.
14 *--------------------------------------------------------------*/
15 
16 #ifndef __CFINGERPRINT_H
17 #define __CFINGERPRINT_H
18 
19 #include <set>
20 #include <cstring>
21 #include "simkerneldefs.h"
22 #include "cevent.h"
23 #include "cmessage.h"
24 #include "chasher.h"
25 #include "cmatchexpression.h"
26 
27 namespace omnetpp {
28 
36 {
37  public:
40  virtual ~cFingerprintCalculator() {}
42 
46  virtual void initialize(const char *expectedFingerprints, cConfiguration *cfg, int index=-1) = 0;
47 
50  virtual void addEvent(cEvent *event) = 0;
51  virtual void addScalarResult(const cComponent *component, const char *name, double value) = 0;
52  virtual void addStatisticResult(const cComponent *component, const char *name, const cStatistic *value) = 0;
53  virtual void registerVectorResult(void *vechandle, const cComponent *component, const char *name) = 0;
54  virtual void addVectorResult(void *vechandle, const simtime_t& t, double value) = 0;
55  virtual void addVisuals() = 0;
56 
57  virtual void addExtraData(const char *data, size_t length) = 0;
58  virtual void addExtraData(char data) = 0;
59  virtual void addExtraData(short data) = 0;
60  virtual void addExtraData(int data) = 0;
61  virtual void addExtraData(long data) = 0;
62  virtual void addExtraData(long long data) = 0;
63  virtual void addExtraData(unsigned char data) = 0;
64  virtual void addExtraData(unsigned short data) = 0;
65  virtual void addExtraData(unsigned int data) = 0;
66  virtual void addExtraData(unsigned long data) = 0;
67  virtual void addExtraData(unsigned long long data) = 0;
68  virtual void addExtraData(double data) = 0;
69  virtual void addExtraData(const char *data) = 0;
71 
76  virtual bool checkFingerprint() const = 0;
77 };
78 
111 {
112  protected:
113  enum FingerprintIngredient {
114  EVENT_NUMBER = 'e',
115  SIMULATION_TIME = 't',
116  MESSAGE_FULL_NAME = 'n',
117  MESSAGE_CLASS_NAME = 'c',
118  MESSAGE_KIND = 'k',
119  MESSAGE_BIT_LENGTH = 'l',
120  MESSAGE_CONTROL_INFO_CLASS_NAME = 'o',
121  MESSAGE_DATA = 'd',
122  MODULE_ID = 'i',
123  MODULE_FULL_NAME = 'm',
124  MODULE_FULL_PATH = 'p',
125  MODULE_CLASS_NAME = 'a',
126  RANDOM_NUMBERS_DRAWN = 'r',
127  RESULT_SCALAR = 's',
128  RESULT_STATISTIC = 'z',
129  RESULT_VECTOR = 'v',
130  DISPLAY_STRINGS = 'y',
131  CANVAS_FIGURES = 'f',
132  EXTRA_DATA = 'x',
133  CLEAN_HASHER = '0'
134  };
135 
136  class MatchableObject : public cMatchExpression::Matchable
137  {
138  private:
139  const cObject *object;
140  mutable std::string attributeValue;
141 
142  public:
143  MatchableObject(const cObject *object) : object(object) {}
144 
145  virtual const char *getAsString() const;
146  virtual const char *getAsString(const char *attribute) const;
147  };
148 
149  protected:
150  std::string expectedFingerprints;
151  std::string ingredients;
152  cMatchExpression *eventMatcher = nullptr;
153  cMatchExpression *moduleMatcher = nullptr;
154  cMatchExpression *resultMatcher = nullptr;
155  cHasher hasher_;
156  [[deprecated]] cHasher *hasher = &hasher_;
157  bool addEvents = false;
158  bool addScalarResults = false;
159  bool addStatisticResults = false;
160  bool addVectorResults = false;
161  bool addExtraData_ = false;
162  std::set<void*> enabledVecHandles;
163 
164  protected:
165  virtual FingerprintIngredient validateIngredient(char ch);
166  virtual void parseIngredients(const char *s);
167  virtual void parseEventMatcher(const char *s);
168  virtual void parseModuleMatcher(const char *s);
169  virtual void parseResultMatcher(const char *s);
170  virtual bool addEventIngredient(cEvent *event, FingerprintIngredient ingredient);
171  virtual void addModuleVisuals(cModule *module, bool displayStrings, bool figures);
172 
173  public:
175  virtual ~cSingleFingerprintCalculator();
176 
177  virtual cSingleFingerprintCalculator *dup() const override { return new cSingleFingerprintCalculator(); }
178  virtual std::string str() const override;
179  virtual void initialize(const char *expectedFingerprints, cConfiguration *cfg, int index=-1) override;
180 
181  virtual void addEvent(cEvent *event) override;
182  virtual void addScalarResult(const cComponent *component, const char *name, double value) override;
183  virtual void addStatisticResult(const cComponent *component, const char *name, const cStatistic *value) override;
184  virtual void registerVectorResult(void *vechandle, const cComponent *component, const char *name) override;
185  virtual void addVectorResult(void *vechandle, const simtime_t& t, double value) override;
186  virtual void addVisuals() override;
187 
188  virtual void addExtraData(const char *buffer, size_t length) override { if (addExtraData_) hasher_.add(buffer, length); }
189  virtual void addExtraData(char data) override { if (addExtraData_) hasher_.add(data); }
190  virtual void addExtraData(short data) override { if (addExtraData_) hasher_.add(data); }
191  virtual void addExtraData(int data) override { if (addExtraData_) hasher_.add(data); }
192  virtual void addExtraData(long data) override { if (addExtraData_) hasher_.add(data); }
193  virtual void addExtraData(long long data) override { if (addExtraData_) hasher_.add(data); }
194  virtual void addExtraData(unsigned char data) override { if (addExtraData_) hasher_.add(data); }
195  virtual void addExtraData(unsigned short data) override { if (addExtraData_) hasher_.add(data); }
196  virtual void addExtraData(unsigned int data) override { if (addExtraData_) hasher_.add(data); }
197  virtual void addExtraData(unsigned long data) override { if (addExtraData_) hasher_.add(data); }
198  virtual void addExtraData(unsigned long long data) override { if (addExtraData_) hasher_.add(data); }
199  virtual void addExtraData(double data) override { if (addExtraData_) hasher_.add(data); }
200  virtual void addExtraData(const char *data) override { if (addExtraData_) hasher_.add(data); }
201 
202  virtual bool checkFingerprint() const override;
203 
204 };
205 
206 
216 {
217  protected:
218  cFingerprintCalculator *prototype;
219  std::vector<cFingerprintCalculator *> elements;
220 
221  public:
223  virtual ~cMultiFingerprintCalculator();
224 
225  virtual cMultiFingerprintCalculator *dup() const override { return new cMultiFingerprintCalculator(static_cast<cFingerprintCalculator *>(prototype->dup())); }
226  virtual std::string str() const override;
227  virtual void initialize(const char *expectedFingerprints, cConfiguration *cfg, int index=-1) override;
228 
229  virtual void addEvent(cEvent *event) override;
230  virtual void addScalarResult(const cComponent *component, const char *name, double value) override;
231  virtual void addStatisticResult(const cComponent *component, const char *name, const cStatistic *value) override;
232  virtual void registerVectorResult(void *vechandle, const cComponent *component, const char *name) override;
233  virtual void addVectorResult(void *vechandle, const simtime_t& t, double value) override;
234  virtual void addVisuals() override;
235 
236  virtual void addExtraData(const char *data, size_t length) override { for (auto element: elements) element->addExtraData(data, length); }
237  virtual void addExtraData(char data) override { for (auto element: elements) element->addExtraData(data); }
238  virtual void addExtraData(short data) override { for (auto element: elements) element->addExtraData(data); }
239  virtual void addExtraData(int data) override { for (auto element: elements) element->addExtraData(data); }
240  virtual void addExtraData(long data) override { for (auto element: elements) element->addExtraData(data); }
241  virtual void addExtraData(long long data) override { for (auto element: elements) element->addExtraData(data); }
242  virtual void addExtraData(unsigned char data) override { for (auto element: elements) element->addExtraData(data); }
243  virtual void addExtraData(unsigned short data) override { for (auto element: elements) element->addExtraData(data); }
244  virtual void addExtraData(unsigned int data) override { for (auto element: elements) element->addExtraData(data); }
245  virtual void addExtraData(unsigned long data) override { for (auto element: elements) element->addExtraData(data); }
246  virtual void addExtraData(unsigned long long data) override { for (auto element: elements) element->addExtraData(data); }
247  virtual void addExtraData(double data) override { for (auto element: elements) element->addExtraData(data); }
248  virtual void addExtraData(const char *data) override { for (auto element: elements) element->addExtraData(data); }
249 
250  virtual bool checkFingerprint() const override;
251 };
252 
253 } // namespace omnetpp
254 
255 #endif
256 
omnetpp::cMatchExpression::Matchable
Objects to be matched must implement this interface.
Definition: cmatchexpression.h:62
omnetpp::cModule
This class represents modules in the simulation.
Definition: cmodule.h:48
omnetpp::cObject
cObject is a lightweight class which serves as the root of the OMNeT++ class hierarchy....
Definition: cobject.h:92
omnetpp::cHasher
Utility class to calculate the hash of some data.
Definition: chasher.h:40
omnetpp::cConfiguration
Represents the configuration, as accessed by the simulation kernel.
Definition: cconfiguration.h:76
omnetpp::cFingerprintCalculator
This class defines the interface for fingerprint calculators.
Definition: cfingerprint.h:35
omnetpp::noncopyable
Utility class, to make it impossible to call the operator= and copy constructor of any class derived ...
Definition: cobject.h:415
omnetpp::cEvent
Represents an event in the discrete event simulator.
Definition: cevent.h:46
omnetpp::cMultiFingerprintCalculator
This class calculates multiple fingerprints simultaneously.
Definition: cfingerprint.h:215
omnetpp::SimTime
int64_t-based, base-10 fixed-point simulation time.
Definition: simtime.h:66
omnetpp::cObject::dup
virtual cObject * dup() const
omnetpp::cSingleFingerprintCalculator
This class calculates the "fingerprint" of a simulation.
Definition: cfingerprint.h:110
omnetpp::cMultiFingerprintCalculator::dup
virtual cMultiFingerprintCalculator * dup() const override
Definition: cfingerprint.h:225
omnetpp::cSingleFingerprintCalculator::dup
virtual cSingleFingerprintCalculator * dup() const override
Definition: cfingerprint.h:177
omnetpp::cComponent
Common base for module and channel classes.
Definition: ccomponent.h:49
omnetpp::cStatistic
cStatistic is an abstract class for computing statistical properties of a random variable.
Definition: cstatistic.h:34
omnetpp::cMatchExpression
Decides whether an object matches an expression.
Definition: cmatchexpression.h:55