cdataratechannel.h

00001 //==========================================================================
00002 //   CDATARATECHANNEL.H  -  header for
00003 //                     OMNeT++/OMNEST
00004 //            Discrete System Simulation in C++
00005 //
00006 //==========================================================================
00007 
00008 /*--------------------------------------------------------------*
00009   Copyright (C) 1992-2008 Andras Varga
00010   Copyright (C) 2006-2008 OpenSim Ltd.
00011 
00012   This file is distributed WITHOUT ANY WARRANTY. See the file
00013   `license' for details on this and other legal matters.
00014 *--------------------------------------------------------------*/
00015 
00016 #ifndef __CDATARATECHANNEL_H
00017 #define __CDATARATECHANNEL_H
00018 
00019 #include "cchannel.h"
00020 #include "csimulation.h"
00021 
00022 NAMESPACE_BEGIN
00023 
00024 
00030 class SIM_API cDatarateChannel : public cChannel //implies noncopyable
00031 {
00032   protected:
00033     static simsignal_t channelBusySignal;
00034     static simsignal_t messageSentSignal;
00035     static simsignal_t messageDiscardedSignal;
00036 
00037   private:
00038     enum {
00039       FL_ISDISABLED = 128,
00040       FL_DELAY_NONZERO = 256,
00041       FL_DATARATE_NONZERO = 512,
00042       FL_BER_NONZERO = 1024,
00043       FL_PER_NONZERO = 2048,
00044     };
00045 
00046     // cached values of parameters (note: parameters are non-volatile)
00047     simtime_t delay; // propagation delay
00048     double datarate; // data rate
00049     double ber;      // bit error rate
00050     double per;      // packet error rate
00051 
00052     // stores the end of the last transmission; used if there is a datarate
00053     simtime_t txfinishtime;
00054 
00055   private:
00056     // internal: checks whether parameters have been set up
00057     void checkState() const  {if (!parametersFinalized()) throw cRuntimeError(this, ePARAMSNOTREADY);}
00058 
00059   protected:
00060     // internal: update cached copies of parameters
00061     void rereadPars();
00062 
00066     virtual void handleParameterChange(const char *parname);
00067 
00068   public:
00071 
00077     explicit cDatarateChannel(const char *name=NULL);
00078 
00082     virtual ~cDatarateChannel();
00083 
00088     static cDatarateChannel *create(const char *name);
00090 
00097     virtual std::string info() const;
00099 
00105     virtual bool isTransmissionChannel() const {return true;}
00106 
00110     virtual void setDelay(double d);
00111 
00117     virtual void setDatarate(double d);
00118 
00124     virtual void setBitErrorRate(double d);
00125 
00131     virtual void setPacketErrorRate(double d);
00132 
00136     virtual void setDisabled(bool d);
00137 
00142     virtual simtime_t getDelay() const {checkState(); return delay;}
00143 
00150     virtual double getDatarate() const  {checkState(); return datarate;}
00151 
00158     virtual double getBitErrorRate() const  {checkState(); return ber;}
00159 
00166     virtual double getPacketErrorRate() const  {checkState(); return per;}
00167 
00173     virtual bool isDisabled() const  {checkState(); return flags & FL_ISDISABLED;}
00175 
00181     virtual double getNominalDatarate() const {return getDatarate();}
00182 
00190     virtual simtime_t calculateDuration(cMessage *msg) const;
00191 
00200     virtual simtime_t getTransmissionFinishTime() const {return txfinishtime;}
00201 
00206     virtual bool isBusy() const {return simTime() < txfinishtime;}
00207 
00214     virtual void forceTransmissionFinishTime(simtime_t t);
00216 
00222     virtual void initialize();
00223 
00227     virtual void processMessage(cMessage *msg, simtime_t t, result_t& result);
00229 };
00230 
00231 NAMESPACE_END
00232 
00233 #endif
00234 
00235 
Generated on Tue Dec 2 11:16:27 2014 for OMNeT++ Simulation Library by  doxygen 1.6.3