Statistics
| Branch: | Revision:

root / include / cdataratechannel.h @ master

History | View | Annotate | Download (6.96 KB)

1
//==========================================================================
2
//   CDATARATECHANNEL.H  -  header for
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 __CDATARATECHANNEL_H
17
#define __CDATARATECHANNEL_H
18

    
19
#include "cchannel.h"
20
#include "csimulation.h"
21

    
22
NAMESPACE_BEGIN
23

    
24

    
25
/**
26
 * Channel that models delay, bit error rate and data rate.
27
 *
28
 * @ingroup SimCore
29
 */
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 = 128,
40
      FL_DELAY_NONZERO = 256,
41
      FL_DATARATE_NONZERO = 512,
42
      FL_BER_NONZERO = 1024,
43
      FL_PER_NONZERO = 2048,
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, ePARAMSNOTREADY);}
58

    
59
  protected:
60
    // internal: update cached copies of parameters
61
    void rereadPars();
62

    
63
    /**
64
     * Called back when a parameter changes. Redefined from cComponent.
65
     */
66
    virtual void handleParameterChange(const char *parname);
67

    
68
  public:
69
    /** @name Constructors, destructor */
70
    //@{
71

    
72
    /**
73
     * Constructor. This is only for internal purposes, and should not
74
     * be used when creating channels dynamically; use the create()
75
     * factory method instead.
76
     */
77
    explicit cDatarateChannel(const char *name=NULL);
78

    
79
    /**
80
     * Destructor.
81
     */
82
    virtual ~cDatarateChannel();
83

    
84
    /**
85
     * Utility function for dynamic channel creation. Equivalent to
86
     * <tt>cChannelType::getDatarateChannelType()->create(name)</tt>.
87
     */
88
    static cDatarateChannel *create(const char *name);
89
    //@}
90

    
91
    /** @name Redefined cObject member functions. */
92
    //@{
93
    /**
94
     * Produces a one-line description of the object's contents.
95
     * See cObject for more details.
96
     */
97
    virtual std::string info() const;
98
    //@}
99

    
100
    /** @name Setting and getting channel parameters. */
101
    //@{
102
    /**
103
     * Returns true.
104
     */
105
    virtual bool isTransmissionChannel() const {return true;}
106

    
107
    /**
108
     * Sets the propagation delay of the channel, in seconds.
109
     */
110
    virtual void setDelay(double d);
111

    
112
    /**
113
     * Sets the data rate of the channel, in bit/second.
114
     *
115
     * @see isBusy(), getTransmissionFinishTime()
116
     */
117
    virtual void setDatarate(double d);
118

    
119
    /**
120
     * Sets the bit error rate (BER) of the channel.
121
     *
122
     * @see cPacket::hasBitError()
123
     */
124
    virtual void setBitErrorRate(double d);
125

    
126
    /**
127
     * Sets the packet error rate (PER) of the channel.
128
     *
129
     * @see cPacket::hasBitError()
130
     */
131
    virtual void setPacketErrorRate(double d);
132

    
133
    /**
134
     * Disables or enables the channel.
135
     */
136
    virtual void setDisabled(bool d);
137

    
138
    /**
139
     * Returns the propagation delay of the channel, in seconds.
140
     * This method is equivalent to reading the "delay" parameter, via par("delay").
141
     */
142
    virtual simtime_t getDelay() const {checkState(); return delay;}
143

    
144
    /**
145
     * Returns the data rate of the channel, in bit/second.
146
     * This method is equivalent to reading the "datarate" parameter, via par("datarate").
147
     * This value affects the transmission time of messages sent through
148
     * the channel.
149
     */
150
    virtual double getDatarate() const  {checkState(); return datarate;}
151

    
152
    /**
153
     * Returns the bit error rate (BER) of the channel.
154
     * This method is equivalent to reading the "ber" parameter, via par("ber").
155
     * When a message sent through the channel suffers at least
156
     * one bit error, its bit error flag will be set.
157
     */
158
    virtual double getBitErrorRate() const  {checkState(); return ber;}
159

    
160
    /**
161
     * Returns the packet error rate (PER) of the channel.
162
     * This method is equivalent to reading the "per" parameter, via par("per").
163
     * When a message is sent through the channel, its bit error flag
164
     * will be set with this probability.
165
     */
166
    virtual double getPacketErrorRate() const  {checkState(); return per;}
167

    
168
    /**
169
     * Returns whether the channel is disabled.
170
     * This method is equivalent to reading the "disabled" parameter, via par("disabled").
171
     * A disabled channel discards all messages sent on it.
172
     */
173
    virtual bool isDisabled() const  {checkState(); return flags & FL_ISDISABLED;}
174
    //@}
175

    
176
    /** @name Transmission state. */
177
    //@{
178
    /**
179
     * Same as getDatarate().
180
     */
181
    virtual double getNominalDatarate() const {return getDatarate();}
182

    
183
    /**
184
     * Returns the message length in bits divided by the datarate.
185
     *
186
     * Note that processMessage() does NOT call this method, so in order to
187
     * change the duration computation algorithm via subclassing you need
188
     * to redefine both this and processMessage().
189
     */
190
    virtual simtime_t calculateDuration(cMessage *msg) const;
191

    
192
    /**
193
     * Returns the simulation time the sender gate will finish transmitting.
194
     * If the gate is not currently transmitting, the result is undefined but
195
     * less or equal the current simulation time.
196
     *
197
     * The transmission duration of a message depends on the message length
198
     * and the data rate assigned to the channel.
199
     */
200
    virtual simtime_t getTransmissionFinishTime() const {return txfinishtime;}
201

    
202
    /**
203
     * Returns whether the sender gate is currently transmitting, ie. whether
204
     * transmissionFinishTime() is greater than the current simulation time.
205
     */
206
    virtual bool isBusy() const {return simTime() < txfinishtime;}
207

    
208
    /**
209
     * Forcibly overwrites the finish time of the current transmission in the
210
     * channel (see getTransmissionFinishTime()). This method can be used for
211
     * implementing transmission abortion; see declaration in base class
212
     * (cChannel::forceTransmissionFinishTime()) for more information.
213
     */
214
    virtual void forceTransmissionFinishTime(simtime_t t);
215
    //@}
216

    
217
    /** @name Implementation methods */
218
    //@{
219
    /**
220
     * Initialization.
221
     */
222
    virtual void initialize();
223

    
224
    /**
225
     * Performs bit error rate, delay and transmission time modelling.
226
     */
227
    virtual void processMessage(cMessage *msg, simtime_t t, result_t& result);
228
    //@}
229
};
230

    
231
NAMESPACE_END
232

    
233
#endif
234

    
235