|
INET Framework for OMNeT++/OMNEST
|
00001 /* -*- mode:c++ -*- ******************************************************** 00002 * file: ChannelControl.h 00003 * 00004 * copyright: (C) 2006 Levente Meszaros, 2005 Andras Varga 00005 * 00006 * This program is free software; you can redistribute it 00007 * and/or modify it under the terms of the GNU General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2 of the License, or (at your option) any later 00010 * version. 00011 * For further information see file COPYING 00012 * in the top level directory 00013 *************************************************************************** 00014 * part of: framework implementation developed by tkn 00015 **************************************************************************/ 00016 00017 #ifndef CHANNELCONTROL_H 00018 #define CHANNELCONTROL_H 00019 00020 #include <vector> 00021 #include <list> 00022 #include <deque> 00023 #include <set> 00024 #include <omnetpp.h> 00025 #include "AirFrame_m.h" 00026 #include "Coord.h" 00027 00028 #define LIGHT_SPEED 3.0E+8 00029 #define TRANSMISSION_PURGE_INTERVAL 1.0 00030 00037 //TODO complete support multiple NICs per host 00038 class INET_API ChannelControl : public cSimpleModule 00039 { 00040 protected: 00041 struct HostEntry; 00042 typedef std::list<HostEntry> HostList; 00043 00044 public: 00045 typedef HostEntry *HostRef; // handle for ChannelControl's clients 00046 typedef std::vector<HostRef> HostRefVector; 00047 typedef std::list<AirFrame*> TransmissionList; 00048 00049 protected: 00055 struct HostEntry { 00056 cModule *host; 00057 cGate *radioInGate; 00058 int channel; 00059 Coord pos; // cached 00060 std::set<HostRef> neighbors; // cached neighbour list 00061 00062 // we cache neighbors set in an std::vector, because std::set iteration is slow; 00063 // std::vector is created and updated on demand 00064 bool isNeighborListValid; 00065 HostRefVector neighborList; 00066 }; 00067 HostList hosts; 00068 00073 typedef std::vector<TransmissionList> ChannelTransmissionLists; 00074 ChannelTransmissionLists transmissions; // indexed by channel number (size=numChannels) 00075 00077 simtime_t lastOngoingTransmissionsUpdate; 00078 00079 friend std::ostream& operator<<(std::ostream&, const HostEntry&); 00080 friend std::ostream& operator<<(std::ostream&, const TransmissionList&); 00081 00083 bool coreDebug; 00084 00086 Coord playgroundSize; 00087 00089 double maxInterferenceDistance; 00090 00092 int numChannels; 00093 00094 protected: 00095 virtual void updateConnections(HostRef h); 00096 00098 virtual double calcInterfDist(); 00099 00101 virtual void updateDisplayString(cModule *playgroundMod); 00102 00104 virtual void initialize(); 00105 00107 virtual void purgeOngoingTransmissions(); 00108 00110 virtual void checkChannel(const int channel); 00111 00112 public: 00113 ChannelControl(); 00114 virtual ~ChannelControl(); 00115 00117 static ChannelControl *get(); 00118 00120 virtual HostRef registerHost(cModule *host, const Coord& initialPos, cGate *radioInGate=NULL); 00121 00123 cModule *getHost(HostRef h) const {return h->host;} 00124 00126 cGate *getRadioGate(HostRef h) const {return h->radioInGate;} 00127 00129 int getHostChannel(HostRef h) const {return h->channel;} 00130 00132 virtual HostRef lookupHost(cModule *host); 00133 00135 virtual void updateHostPosition(HostRef h, const Coord& pos); 00136 00138 virtual void updateHostChannel(HostRef h, const int channel); 00139 00141 const TransmissionList& getOngoingTransmissions(const int channel); 00142 00144 virtual void addOngoingTransmission(HostRef h, AirFrame *frame); 00145 00147 const Coord& getHostPosition(HostRef h) {return h->pos;} 00148 00150 const HostRefVector& getNeighbors(HostRef h); 00151 00153 virtual void sendToChannel(cSimpleModule *srcRadioMod, HostRef srcHost, AirFrame *airFrame); 00154 00156 virtual double getCommunicationRange(HostRef h) { 00157 return maxInterferenceDistance; 00158 } 00159 00161 const Coord *getPgs() {return &playgroundSize;} 00162 00164 const int getNumChannels() {return numChannels;} 00165 }; 00166 00167 #endif 00168