00001 #ifndef BASEPHYLAYER_
00002 #define BASEPHYLAYER_
00003
00004 #include "ChannelAccess.h"
00005 #include "DeciderToPhyInterface.h"
00006 #include "MacToPhyInterface.h"
00007
00008 #include "AnalogueModel.h"
00009
00010 #include "Decider.h"
00011 #include "ChannelInfo.h"
00012 #include "BaseWorldUtility.h"
00013
00014 #include "MacPkt_m.h"
00015
00016 #include <cxmlelement.h>
00017 #include <map>
00018 #include <vector>
00019 #include <iostream>
00020
00021
00068 class BasePhyLayer: public ChannelAccess,
00069 public DeciderToPhyInterface,
00070 public MacToPhyInterface {
00071
00072 protected:
00073
00074 enum ProtocolIds {
00075 GENERIC = 0,
00076 };
00077
00078 int protocolId;
00079
00091 static short airFramePriority;
00092
00094 ConstantSimpleConstMapping* thermalNoise;
00095
00097 double maxTXPower;
00098
00100 double sensitivity;
00101
00103 bool recordStats;
00104
00109 ChannelInfo channelInfo;
00110
00112 Radio* radio;
00113
00115 Decider* decider;
00116
00118 typedef std::vector<AnalogueModel*> AnalogueModelList;
00119
00121 AnalogueModelList analogueModels;
00122
00127 typedef std::map<std::string, cMsgPar> ParameterMap;
00128
00130 int upperGateIn;
00132 int upperGateOut;
00134 int upperControlOut;
00136 int upperControlIn;
00137
00142 cMessage* radioSwitchingOverTimer;
00143
00148 cMessage* txOverTimer;
00149
00151 enum AirFrameStates {
00153 START_RECEIVE = 1,
00155 RECEIVING,
00157 END_RECEIVE
00158 };
00159
00161 int headerLength;
00162
00164 BaseWorldUtility* world;
00165
00166 public:
00167
00168
00169 private:
00170
00175 void getParametersFromXML(cXMLElement* xmlData, ParameterMap& outputMap);
00176
00181 void initializeAnalogueModels(cXMLElement* xmlConfig);
00182
00187 void initializeDecider(cXMLElement* xmlConfig);
00188
00189
00190
00191 protected:
00192
00203 template<class T> T readPar(const char* parName, const T defaultValue);
00204
00212 virtual void initialize(int stage);
00213
00224 virtual void handleMessage(cMessage* msg);
00225
00232 virtual Radio* initializeRadio();
00233
00249 virtual AnalogueModel* getAnalogueModelFromName(std::string name, ParameterMap& params);
00250
00266 virtual Decider* getDeciderFromName(std::string name, ParameterMap& params);
00267
00271
00275 virtual void handleAirFrame(cMessage* msg);
00276
00281 virtual void handleUpperMessage(cMessage* msg);
00282
00287 virtual void handleUpperControlMessage(cMessage* msg);
00288
00292 virtual void handleSelfMessage(cMessage* msg);
00293
00299 virtual void handleChannelSenseRequest(cMessage* msg);
00300
00304 void handleAirFrameFirstReceive(AirFrame* msg);
00305
00309 virtual void handleAirFrameStartReceive(AirFrame* msg);
00310
00314 virtual void handleAirFrameReceiving(AirFrame* msg);
00315
00319 virtual void handleAirFrameEndReceive(AirFrame* msg);
00320
00326
00331 void sendControlMessageUp(cMessage* msg);
00332
00336 void sendMacPktUp(cMessage* pkt);
00337
00341 void sendMessageDown(AirFrame* pkt);
00342
00346 void sendSelfMessage(cMessage* msg, simtime_t time);
00347
00354 virtual AirFrame *encapsMsg(cPacket *msg);
00355
00359 virtual void filterSignal(Signal& s);
00360
00367 virtual void finishRadioSwitching();
00368
00375 virtual int myProtocolId() { return protocolId; }
00376
00392 virtual bool isKnownProtocolId(int id) { return id == myProtocolId(); }
00393
00394 public:
00395 BasePhyLayer();
00396
00400 virtual ~BasePhyLayer();
00401
00403 virtual void finish();
00404
00405
00410
00419 virtual int getRadioState();
00420
00431 virtual simtime_t setRadioState(int rs);
00432
00438 virtual ChannelState getChannelState();
00439
00448 virtual int getPhyHeaderLength();
00449
00451 virtual void setCurrentRadioChannel(int newRadioChannel);
00452
00454 virtual int getCurrentRadioChannel();
00455
00457 virtual int getNbRadioChannels();
00458
00461
00466
00472 virtual void getChannelInfo(simtime_t from, simtime_t to, AirFrameVector& out);
00473
00487 virtual ConstMapping* getThermalNoise(simtime_t from, simtime_t to);
00488
00495 virtual void sendControlMsg(cMessage* msg);
00496
00505 virtual void sendUp(AirFrame* packet, DeciderResult* result);
00506
00510 virtual simtime_t getSimTime();
00511
00519 virtual void cancelScheduledMessage(cMessage* msg);
00520
00529 virtual void rescheduleMessage(cMessage* msg, simtime_t t);
00530
00535 virtual void drawCurrent(double amount, int activity);
00536
00540 virtual BaseUtility* getUtility();
00541
00545 virtual BaseWorldUtility* getWorldUtility();
00546
00553 void recordScalar(const char *name, double value, const char *unit=NULL);
00554
00557 };
00558
00559 #endif