OverSim
CoordBasedRouting.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 //
18 
25 #ifndef __COORDBASEDROUTING_H_
26 #define __COORDBASEDROUTING_H_
27 
28 #include <omnetpp.h>
29 
30 #include <OverlayKey.h>
31 #include <TransportAddress.h>
32 #include <CoordinateSystem.h>
33 
34 class GlobalNodeList;
35 
41 class CBRArea
42 {
43 
44  public:
45  CBRArea(uint8_t dim);
46  CBRArea(const Coords& bottoms,
47  const Coords& tops,
48  const std::string& prefix)
49  : min(bottoms), max(tops), prefix(prefix) {};
50  ~CBRArea() {};
51 
52  Coords min;
54  std::string prefix;
55 
56  friend std::ostream& operator<<(std::ostream& os,
57  const CBRArea& area);
58 };
59 
60 
61 
62 
63 typedef std::vector<CBRArea> AP; //< {Global,Current} Area Partitioning
64 typedef std::vector<Coords> CD; //< {Global,Current} Coordinate Distribution
65 
66 class CoordBasedRouting : public cSimpleModule
67 {
68  private:
69  static const std::string NOPREFIX;
70 
71  const char* areaCoordinateSource;
72  uint8_t cbrStartAtDigit;
73  uint8_t cbrStopAtDigit;
74  uint8_t xmlDimensions;
75 
77  simtime_t cbrChangeIdStart;
78  simtime_t cbrChangeIdStop;
79 
80 
81  AP* gap; //< Global Area Partitioning for LM-CBR
82 
84 
89  void parseSource(const char* areaCoordinateSource);
90 
95  std::string getPrefix(const Coords& coords,
96  const AP* cap = NULL) const;
97 
103  bool checkDimensions(uint8_t dims) const;
104 
105  void splitNodes(CD& nodes,
106  const std::string& prefix,
107  const Coords& bottoms,
108  const Coords& tops,
109  uint8_t depth,
110  AP* cap);
111 
112  uint8_t ccdDim;
113  uint16_t maxPrefix;
114 
115  protected:
120  virtual void initialize();
121  void finish();
122 
123  public:
124  CoordBasedRouting() { gap = NULL; };
125  ~CoordBasedRouting() { delete gap; };
126 
133  OverlayKey getNodeId(const Coords& coords,
134  uint8_t bpd, uint8_t length,
135  const AP* cap = NULL) const;
136 
141  uint8_t getXmlDimensions() const { return xmlDimensions; }
142 
143  double getEuclidianDistanceByKeyAndCoords(const OverlayKey& destKey,
144  const std::vector<double>& nodeCoords,
145  uint8_t bpd,
146  const AP* cap = NULL) const;
147 
148  const AP* calculateCapFromCcd(const CD& ccd, uint8_t bpd);
149 
150  bool changeIdLater() const { return cbrChangeIdLater; };
151  simtime_t getChangeIdStart() const { return cbrChangeIdStart; };
152  simtime_t getChangeIdStop() const { return cbrChangeIdStop; };
153 };
154 
155 
156 class leqDim
157 {
158 private:
159  uint8_t dim;
160 
161 public:
162  leqDim(uint8_t dim) { this->dim = dim; };
163  int operator() (const Coords& left,
164  const Coords& right) { return left[dim] < right[dim]; };
165 };
166 
167 #endif