OMNeT++ Simulation Library  6.0.3
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 
69 class SIM_API cDatarateChannel : public cChannel //implies noncopyable
70 {
71  protected:
72  static simsignal_t channelBusySignal;
73  static simsignal_t messageSentSignal;
74  static simsignal_t messageDiscardedSignal;
75 
76  public:
80  enum Mode {
85 
90 
98  UNCHECKED
99  };
100 
101  private:
102  enum {
103  FL_ISDISABLED = 1 << 10,
104  FL_DELAY_NONZERO = 1 << 11,
105  FL_DATARATE_PRESENT = 1 << 12,
106  FL_BER_NONZERO = 1 << 13,
107  FL_PER_NONZERO = 1 << 14,
108  };
109 
110  // cached values of parameters (note: parameters are non-volatile)
111  simtime_t delay = 0; // propagation delay
112  double datarate = 0; // data rate
113  double ber = 0; // bit error rate
114  double per = 0; // packet error rate
115 
116  Mode mode = SINGLE;
117 
118  // data of the last/ongoing transmission (only for mode=SINGLE)
119  struct Tx {
120  simtime_t startTime;
121  simtime_t finishTime;
122  txid_t transmissionId = -1;
123  };
124  Tx singleTx; // for SINGLE
125  std::vector<Tx> txList; // for MULTI
126  simtime_t channelFinishTime; // for both SINGLE and MULTI
127 
128  private:
129  // internal: checks whether parameters have been set up
130  void checkState() const {if (!parametersFinalized()) throw cRuntimeError(this, E_PARAMSNOTREADY);}
131 
132  protected:
133  // internal: update cached copies of parameters
134  void rereadPars();
135 
136  // internal: react to parameter changes
137  virtual void handleParameterChange(const char *parname) override;
138 
139  // internal: helper to processMessage()
140  virtual void processPacket(cPacket *pkt, const SendOptions& options, simtime_t t, Result& inoutResult);
141 
142  // internal: emits last busy signal
143  virtual void finish() override;
144 
145  public:
148 
154  explicit cDatarateChannel(const char *name=nullptr);
155 
159  virtual ~cDatarateChannel() {}
160 
165  static cDatarateChannel *create(const char *name);
167 
174  virtual std::string str() const override;
176 
182  virtual bool isTransmissionChannel() const override {return true;}
183 
188  virtual void setMode(Mode mode);
189 
193  virtual void setDelay(double d);
194 
200  virtual void setDatarate(double d);
201 
207  virtual void setBitErrorRate(double d);
208 
214  virtual void setPacketErrorRate(double d);
215 
219  virtual void setDisabled(bool d);
220 
224  virtual Mode getMode() const {return mode;}
225 
230  virtual simtime_t getDelay() const {checkState(); return delay;}
231 
238  virtual double getDatarate() const {checkState(); return datarate;}
239 
246  virtual double getBitErrorRate() const {checkState(); return ber;}
247 
254  virtual double getPacketErrorRate() const {checkState(); return per;}
255 
261  virtual bool isDisabled() const override {checkState(); return flags & FL_ISDISABLED;}
263 
269  virtual double getNominalDatarate() const override {return getDatarate();}
270 
278  virtual simtime_t calculateDuration(cMessage *msg) const override;
279 
287  virtual simtime_t getTransmissionFinishTime() const override;
288 
295  virtual bool isBusy() const override;
296 
308  [[deprecated]] virtual void forceTransmissionFinishTime(simtime_t t) override;
310 
316  virtual void initialize() override;
317 
321  virtual Result processMessage(cMessage *msg, const SendOptions& options, simtime_t t) override;
323 };
324 
325 } // namespace omnetpp
326 
327 #endif
328 
329 
omnetpp::simsignal_t
int simsignal_t
Signal handle.
Definition: clistener.h:27
omnetpp::cDatarateChannel::getPacketErrorRate
virtual double getPacketErrorRate() const
Definition: cdataratechannel.h:254
omnetpp::cDatarateChannel::~cDatarateChannel
virtual ~cDatarateChannel()
Definition: cdataratechannel.h:159
omnetpp::cDatarateChannel
A transmission channel model that supports propagation delay, transmission duration computed from a d...
Definition: cdataratechannel.h:69
omnetpp::cDatarateChannel::isDisabled
virtual bool isDisabled() const override
Definition: cdataratechannel.h:261
omnetpp::cDatarateChannel::getNominalDatarate
virtual double getNominalDatarate() const override
Definition: cdataratechannel.h:269
omnetpp::cChannel
Base class for channels.
Definition: cchannel.h:46
omnetpp::SimTime
int64_t-based, base-10 fixed-point simulation time.
Definition: simtime.h:66
omnetpp::SendOptions
Options for the cSimpleModule::send() and cSimpleModule::sendDirect() calls.
Definition: csimplemodule.h:82
omnetpp::cDatarateChannel::getBitErrorRate
virtual double getBitErrorRate() const
Definition: cdataratechannel.h:246
omnetpp::cDatarateChannel::getDelay
virtual simtime_t getDelay() const
Definition: cdataratechannel.h:230
omnetpp::cDatarateChannel::MULTI
@ MULTI
Definition: cdataratechannel.h:89
omnetpp::simtime_t
SimTime simtime_t
Represents simulation time.
Definition: simtime_t.h:40
omnetpp::cDatarateChannel::isTransmissionChannel
virtual bool isTransmissionChannel() const override
Definition: cdataratechannel.h:182
omnetpp::txid_t
int64_t txid_t
Transmission ID. See SendOptions::transmissionId(), cMessage::getTransmissionId().
Definition: simkerneldefs.h:92
omnetpp::cMessage
The message class in OMNeT++. cMessage objects may represent events, messages, jobs or other entities...
Definition: cmessage.h:95
omnetpp::cDatarateChannel::getDatarate
virtual double getDatarate() const
Definition: cdataratechannel.h:238
omnetpp::cDatarateChannel::getMode
virtual Mode getMode() const
Definition: cdataratechannel.h:224
omnetpp::cDatarateChannel::Mode
Mode
Definition: cdataratechannel.h:80
omnetpp::cDatarateChannel::SINGLE
@ SINGLE
Definition: cdataratechannel.h:84