OMNeT++ Simulation Library  5.6.1
cdataratechannel.h
1 //==========================================================================
2 // CDATARATECHANNEL.H - header for
3 // OMNeT++/OMNEST
4 // Discrete System Simulation in C++
5 //
6 //==========================================================================
7 
8 /*--------------------------------------------------------------*
9  Copyright (C) 1992-2017 Andras Varga
10  Copyright (C) 2006-2017 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 __OMNETPP_CDATARATECHANNEL_H
17 #define __OMNETPP_CDATARATECHANNEL_H
18 
19 #include "cchannel.h"
20 #include "csimulation.h"
21 
22 namespace omnetpp {
23 
24 
30 class SIM_API cDatarateChannel : public cChannel //implies noncopyable
31 {
32  protected:
33  static simsignal_t channelBusySignal;
34  static simsignal_t messageSentSignal;
35  static simsignal_t messageDiscardedSignal;
36 
37  private:
38  enum {
39  FL_ISDISABLED = 1 << 10,
40  FL_DELAY_NONZERO = 1 << 11,
41  FL_DATARATE_NONZERO = 1 << 12,
42  FL_BER_NONZERO = 1 << 13,
43  FL_PER_NONZERO = 1 << 14,
44  };
45 
46  // cached values of parameters (note: parameters are non-volatile)
47  simtime_t delay; // propagation delay
48  double datarate; // data rate
49  double ber; // bit error rate
50  double per; // packet error rate
51 
52  // stores the end of the last transmission; used if there is a datarate
53  simtime_t txFinishTime;
54 
55  private:
56  // internal: checks whether parameters have been set up
57  void checkState() const {if (!parametersFinalized()) throw cRuntimeError(this, E_PARAMSNOTREADY);}
58 
59  protected:
60  // internal: update cached copies of parameters
61  void rereadPars();
62 
63  // internal: react to parameter changes
64  virtual void handleParameterChange(const char *parname) override;
65 
66  // internal: emits last busy signal
67  virtual void finish() override;
68 
69  public:
72 
78  explicit cDatarateChannel(const char *name=nullptr);
79 
83  virtual ~cDatarateChannel();
84 
89  static cDatarateChannel *create(const char *name);
91 
98  virtual std::string str() const override;
100 
106  virtual bool isTransmissionChannel() const override {return true;}
107 
111  virtual void setDelay(double d);
112 
118  virtual void setDatarate(double d);
119 
125  virtual void setBitErrorRate(double d);
126 
132  virtual void setPacketErrorRate(double d);
133 
137  virtual void setDisabled(bool d);
138 
143  virtual simtime_t getDelay() const {checkState(); return delay;}
144 
151  virtual double getDatarate() const {checkState(); return datarate;}
152 
159  virtual double getBitErrorRate() const {checkState(); return ber;}
160 
167  virtual double getPacketErrorRate() const {checkState(); return per;}
168 
174  virtual bool isDisabled() const {checkState(); return flags & FL_ISDISABLED;}
176 
182  virtual double getNominalDatarate() const override {return getDatarate();}
183 
191  virtual simtime_t calculateDuration(cMessage *msg) const override;
192 
201  virtual simtime_t getTransmissionFinishTime() const override {return txFinishTime;}
202 
207  virtual bool isBusy() const override {return simTime() < txFinishTime;}
208 
215  virtual void forceTransmissionFinishTime(simtime_t t) override;
217 
223  virtual void initialize() override;
224 
228  virtual void processMessage(cMessage *msg, simtime_t t, result_t& result) override;
230 };
231 
232 } // namespace omnetpp
233 
234 #endif
235 
236 
The message class in OMNeT++. cMessage objects may represent events, messages, jobs or other entities...
Definition: cmessage.h:95
Thrown when the simulation kernel or other components detect a runtime error.
Definition: cexception.h:283
int64_t-based, base-10 fixed-point simulation time.
Definition: simtime.h:66
virtual double getDatarate() const
Definition: cdataratechannel.h:151
Allows returning multiple values from the processMessage() method.
Definition: cchannel.h:64
virtual double getBitErrorRate() const
Definition: cdataratechannel.h:159
simtime_t simTime()
Returns the current simulation time.
Definition: csimulation.h:568
virtual bool isBusy() const override
Definition: cdataratechannel.h:207
virtual double getNominalDatarate() const override
Definition: cdataratechannel.h:182
virtual simtime_t getDelay() const
Definition: cdataratechannel.h:143
Definition: cabstracthistogram.h:21
virtual simtime_t getTransmissionFinishTime() const override
Definition: cdataratechannel.h:201
virtual bool isTransmissionChannel() const override
Definition: cdataratechannel.h:106
int simsignal_t
Signal handle.
Definition: clistener.h:24
Base class for channels.
Definition: cchannel.h:34
virtual double getPacketErrorRate() const
Definition: cdataratechannel.h:167
Channel that models delay, bit error rate and data rate.
Definition: cdataratechannel.h:30
virtual bool isDisabled() const
Definition: cdataratechannel.h:174