OMNeT++ Simulation Library  6.0.3
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 <string.h>
20 #include "simkerneldefs.h"
21 #include "cevent.h"
22 #include "cmessage.h"
23 #include "chasher.h"
24 #include "cmatchexpression.h"
25 
26 namespace omnetpp {
27 
35 {
36  public:
39  virtual ~cFingerprintCalculator() {}
41 
45  virtual void initialize(const char *expectedFingerprints, cConfiguration *cfg, int index=-1) = 0;
46 
49  virtual void addEvent(cEvent *event) = 0;
50  virtual void addScalarResult(const cComponent *component, const char *name, double value) = 0;
51  virtual void addStatisticResult(const cComponent *component, const char *name, const cStatistic *value) = 0;
52  virtual void addVectorResult(const cComponent *component, const char *name, const simtime_t& t, double value) = 0;
53  virtual void addVisuals() = 0;
54 
55  virtual void addExtraData(const char *data, size_t length) = 0;
56  virtual void addExtraData(char data) = 0;
57  virtual void addExtraData(short data) = 0;
58  virtual void addExtraData(int data) = 0;
59  virtual void addExtraData(long data) = 0;
60  virtual void addExtraData(long long data) = 0;
61  virtual void addExtraData(unsigned char data) = 0;
62  virtual void addExtraData(unsigned short data) = 0;
63  virtual void addExtraData(unsigned int data) = 0;
64  virtual void addExtraData(unsigned long data) = 0;
65  virtual void addExtraData(unsigned long long data) = 0;
66  virtual void addExtraData(double data) = 0;
67  virtual void addExtraData(const char *data) = 0;
69 
74  virtual bool checkFingerprint() const = 0;
75 };
76 
109 {
110  protected:
111  enum FingerprintIngredient {
112  EVENT_NUMBER = 'e',
113  SIMULATION_TIME = 't',
114  MESSAGE_FULL_NAME = 'n',
115  MESSAGE_CLASS_NAME = 'c',
116  MESSAGE_KIND = 'k',
117  MESSAGE_BIT_LENGTH = 'l',
118  MESSAGE_CONTROL_INFO_CLASS_NAME = 'o',
119  MESSAGE_DATA = 'd',
120  MODULE_ID = 'i',
121  MODULE_FULL_NAME = 'm',
122  MODULE_FULL_PATH = 'p',
123  MODULE_CLASS_NAME = 'a',
124  RANDOM_NUMBERS_DRAWN = 'r',
125  RESULT_SCALAR = 's',
126  RESULT_STATISTIC = 'z',
127  RESULT_VECTOR = 'v',
128  DISPLAY_STRINGS = 'y',
129  CANVAS_FIGURES = 'f',
130  EXTRA_DATA = 'x',
131  CLEAN_HASHER = '0'
132  };
133 
134  class MatchableObject : public cMatchExpression::Matchable
135  {
136  private:
137  const cObject *object;
138  mutable std::string attributeValue;
139 
140  public:
141  MatchableObject(const cObject *object) : object(object) {}
142 
143  virtual const char *getAsString() const;
144  virtual const char *getAsString(const char *attribute) const;
145  };
146 
147  protected:
148  std::string expectedFingerprints;
149  std::string ingredients;
150  cMatchExpression *eventMatcher = nullptr;
151  cMatchExpression *moduleMatcher = nullptr;
152  cMatchExpression *resultMatcher = nullptr;
153  cHasher hasher_;
154  [[deprecated]] cHasher *hasher = &hasher_;
155  bool addEvents = false;
156  bool addScalarResults = false;
157  bool addStatisticResults = false;
158  bool addVectorResults = false;
159  bool addExtraData_ = false;
160 
161  protected:
162  virtual FingerprintIngredient validateIngredient(char ch);
163  virtual void parseIngredients(const char *s);
164  virtual void parseEventMatcher(const char *s);
165  virtual void parseModuleMatcher(const char *s);
166  virtual void parseResultMatcher(const char *s);
167  virtual bool addEventIngredient(cEvent *event, FingerprintIngredient ingredient);
168  virtual void addModuleVisuals(cModule *module, bool displayStrings, bool figures);
169 
170  public:
172  virtual ~cSingleFingerprintCalculator();
173 
174  virtual cSingleFingerprintCalculator *dup() const override { return new cSingleFingerprintCalculator(); }
175  virtual std::string str() const override;
176  virtual void initialize(const char *expectedFingerprints, cConfiguration *cfg, int index=-1) override;
177 
178  virtual void addEvent(cEvent *event) override;
179  virtual void addScalarResult(const cComponent *component, const char *name, double value) override;
180  virtual void addStatisticResult(const cComponent *component, const char *name, const cStatistic *value) override;
181  virtual void addVectorResult(const cComponent *component, const char *name, const simtime_t& t, double value) override;
182  virtual void addVisuals() override;
183 
184  virtual void addExtraData(const char *buffer, size_t length) override { if (addExtraData_) hasher_.add(buffer, length); }
185  virtual void addExtraData(char data) override { if (addExtraData_) hasher_.add(data); }
186  virtual void addExtraData(short data) override { if (addExtraData_) hasher_.add(data); }
187  virtual void addExtraData(int data) override { if (addExtraData_) hasher_.add(data); }
188  virtual void addExtraData(long data) override { if (addExtraData_) hasher_.add(data); }
189  virtual void addExtraData(long long data) override { if (addExtraData_) hasher_.add(data); }
190  virtual void addExtraData(unsigned char data) override { if (addExtraData_) hasher_.add(data); }
191  virtual void addExtraData(unsigned short data) override { if (addExtraData_) hasher_.add(data); }
192  virtual void addExtraData(unsigned int data) override { if (addExtraData_) hasher_.add(data); }
193  virtual void addExtraData(unsigned long data) override { if (addExtraData_) hasher_.add(data); }
194  virtual void addExtraData(unsigned long long data) override { if (addExtraData_) hasher_.add(data); }
195  virtual void addExtraData(double data) override { if (addExtraData_) hasher_.add(data); }
196  virtual void addExtraData(const char *data) override { if (addExtraData_) hasher_.add(data); }
197 
198  virtual bool checkFingerprint() const override;
199 
200 };
201 
202 
212 {
213  protected:
214  cFingerprintCalculator *prototype;
215  std::vector<cFingerprintCalculator *> elements;
216 
217  public:
219  virtual ~cMultiFingerprintCalculator();
220 
221  virtual cMultiFingerprintCalculator *dup() const override { return new cMultiFingerprintCalculator(static_cast<cFingerprintCalculator *>(prototype->dup())); }
222  virtual std::string str() const override;
223  virtual void initialize(const char *expectedFingerprints, cConfiguration *cfg, int index=-1) override;
224 
225  virtual void addEvent(cEvent *event) override;
226  virtual void addScalarResult(const cComponent *component, const char *name, double value) override;
227  virtual void addStatisticResult(const cComponent *component, const char *name, const cStatistic *value) override;
228  virtual void addVectorResult(const cComponent *component, const char *name, const simtime_t& t, double value) override;
229  virtual void addVisuals() override;
230 
231  virtual void addExtraData(const char *data, size_t length) override { for (auto element: elements) element->addExtraData(data, length); }
232  virtual void addExtraData(char data) override { for (auto element: elements) element->addExtraData(data); }
233  virtual void addExtraData(short data) override { for (auto element: elements) element->addExtraData(data); }
234  virtual void addExtraData(int data) override { for (auto element: elements) element->addExtraData(data); }
235  virtual void addExtraData(long data) override { for (auto element: elements) element->addExtraData(data); }
236  virtual void addExtraData(long long data) override { for (auto element: elements) element->addExtraData(data); }
237  virtual void addExtraData(unsigned char data) override { for (auto element: elements) element->addExtraData(data); }
238  virtual void addExtraData(unsigned short data) override { for (auto element: elements) element->addExtraData(data); }
239  virtual void addExtraData(unsigned int data) override { for (auto element: elements) element->addExtraData(data); }
240  virtual void addExtraData(unsigned long data) override { for (auto element: elements) element->addExtraData(data); }
241  virtual void addExtraData(unsigned long long data) override { for (auto element: elements) element->addExtraData(data); }
242  virtual void addExtraData(double data) override { for (auto element: elements) element->addExtraData(data); }
243  virtual void addExtraData(const char *data) override { for (auto element: elements) element->addExtraData(data); }
244 
245  virtual bool checkFingerprint() const override;
246 };
247 
248 } // namespace omnetpp
249 
250 #endif
251 
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:39
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:34
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:211
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:108
omnetpp::cMultiFingerprintCalculator::dup
virtual cMultiFingerprintCalculator * dup() const override
Definition: cfingerprint.h:221
omnetpp::cSingleFingerprintCalculator::dup
virtual cSingleFingerprintCalculator * dup() const override
Definition: cfingerprint.h:174
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