00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef CHANNELCONTROL_H
00023 #define CHANNELCONTROL_H
00024
00025 #include <omnetpp.h>
00026 #include <list>
00027 #include <vector>
00028
00029 #include "Coord.h"
00030 #include "NicEntry.h"
00031
00044 class ChannelControl : public cSimpleModule
00045 {
00046 protected:
00048 bool coreDebug;
00049
00050 typedef std::map<int, NicEntry*> NicEntries;
00051 typedef std::vector<NicEntries> RowVector;
00052 typedef std::vector<RowVector> NicMatrix;
00053
00059 NicMatrix nics;
00060
00062 bool sendDirect;
00063
00065 Coord playgroundSize;
00066
00068 double maxInterferenceDistance;
00069
00073 double maxDistSquared;
00074
00080 double findDistance;
00081
00085 unsigned maxX, maxY;
00086
00091 bool useTorus;
00092
00093 protected:
00102 bool increment(unsigned max, unsigned src, unsigned* target) {
00103 bool res = true;
00104 unsigned v = src + 1;
00105 if(src == max) {
00106 v = 0;
00107 if(!useTorus) res = false;
00108 }
00109 *target = v;
00110 return res;
00111 }
00112
00117 bool decrement(unsigned max, unsigned src, unsigned* target) {
00118 bool res = true;
00119 unsigned v = src - 1;
00120 if(src == 0) {
00121 v = max;
00122 if(!useTorus) res = false;
00123 }
00124 *target = v;
00125 return res;
00126 }
00127
00131 bool inRangeEuclid(const Coord& a, const Coord& b) {
00132 return a.sqrdist(b) < maxDistSquared;
00133 }
00134
00139 bool inRangeTorus(const Coord& a, const Coord& b);
00144 public:
00148 Module_Class_Members(ChannelControl, cSimpleModule, 0);
00149
00154 virtual void initialize();
00155
00157
00158
00160 bool registerNic( cModule*, const Coord* );
00161
00163 void updateNicPos(int, const Coord* oldPos, const Coord* newPos);
00164
00166 const Coord* getPgs(){
00167 return &playgroundSize;
00168 };
00169
00170 const NicEntry::GateList& getGateList( int, const Coord* );
00171
00172 const cGate* getOutGateTo(int, int, const Coord*);
00173
00175 static const double speedOfLight;
00176
00177 protected:
00179 void updateConnections(NicEntries& nmap, NicEntry* nic);
00180
00182 virtual double calcInterfDist();
00183
00187 void checkGrid(unsigned oldX, unsigned oldY,
00188 unsigned newX, unsigned newY,
00189 int id);
00190 };
00191
00192 #endif