OverSim
RUNetworkConfigurator.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2010 Institut fuer Telematik, Karlsruher Institut fuer Technologie (KIT)
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 
26 #ifndef RUNetworkConfigurator_H_
27 #define RUNetworkConfigurator_H_
28 
29 #include <omnetpp.h>
30 #include <cctype>
31 #include <vector>
32 #include <map>
33 #include <ctopology.h>
34 #include <string>
35 #include <iostream>
36 #include "INETDefs.h"
37 #include "IPAddress.h"
38 #include "RoutingTable.h"
39 #include "InterfaceTable.h"
40 #include "IPAddressResolver.h"
41 #include "NetworkConfigurator.h"
42 #include "IPv4InterfaceData.h"
43 #include "InterfaceEntry.h"
44 
45 using std::vector;
46 using std::map;
47 using std::string;
48 using std::cerr;
49 using std::cout;
50 using std::endl;
51 
52 const int INIT_STAGES = 3;
53 // unique hex values for different router- and AS-level node types
54 const int TRANSIT_AS = 1;
55 const int STUB_AS = 2;
56 const int UNSPECIFIED = -1;
57 const int CORE = 1;
58 const int GW = 2;
59 const int EDGE = 3;
60 const int ENDSYS = 4;
61 
62 typedef vector<string> StringVector;
63 
72 struct nodeInfoRL
73 {
74  bool isIPNode;
75  IInterfaceTable *ift;
76  InterfaceEntry *defaultRouteIE;
78  IRoutingTable *rt;
79  IPAddress addr;
81  cModule *module;
82  cTopology::Node *node;
83 
84  nodeInfoRL() {};
85  nodeInfoRL(cTopology::Node *node)
86  {
87  this->node = node;
88  module = node->getModule();
89  moduleId = module->getId();
90  ift = IPAddressResolver().findInterfaceTableOf(module);
91  rt = IPAddressResolver().findRoutingTableOf(module);
92  isIPNode = (rt != NULL);
93  int index = 0;
94  string fullPath = module->getFullPath();
95 
96  // check if stubstring "sas" (StubAS) or "tas" (TransitAS)
97  // is contained in fullPath
98  if ( (index = fullPath.find("sas")) != -1 )
99  asType = STUB_AS;
100  else if ( (index = fullPath.find("tas")) != -1 )
101  asType = TRANSIT_AS;
102  else if ( (index = fullPath.find("ReaSEUnderlayNetwork")) != -1)
104  else {
105  cerr << "found module that doesn't belong to Transit AS (tas) or Stub AS (sas): "<< fullPath<<endl;
106  opp_error("found module that doesn't belong to Transit AS (tas) or Stub AS (sas)");
107  }
108 
109  // set index to char position after substring "sas/tas"
110  if (asType == STUB_AS || asType == TRANSIT_AS) {
111  index += 3;
112  string currentId;
113  while (isdigit(fullPath[index]) && (index < (int) fullPath.length()))
114  currentId += fullPath[index++];
115  asId = atoi(currentId.data());
116  }
117 
118  if (module->getProperties()->get("CoreRouter"))
119  routerType = CORE;
120  else if (module->getProperties()->get("GatewayRouter"))
121  routerType = GW;
122  else if (module->getProperties()->get("EdgeRouter"))
123  routerType = EDGE;
124  else if (module->getProperties()->get("Host"))
125  routerType = ENDSYS;
126  else {
127  cerr<<"found module without valid type: "<<fullPath<<endl;
128  opp_error("found module without valid type");
129  }
130  //
131  // determine default interface
132  //
133  if (routerType == CORE) {
134  // find last interface that is not loopback
135  for (int i=0; i<ift->getNumInterfaces(); i++)
136  if (!ift->getInterface(i)->isLoopback())
137  addr = ift->getInterface(i)->ipv4Data()->getIPAddress();
138  defaultRouteIE = NULL;
139  }
140  else {
141  for (int i=0; i<ift->getNumInterfaces(); i++) {
142  if (!ift->getInterface(i)->isLoopback()) {
143  // find first interface that is not loopback and is connected to
144  // a higher level node. Then, create default route
145  addr = ift->getInterface(i)->ipv4Data()->getIPAddress();
146  if (routerType == GW) {
147  if (module->gate(ift->getInterface(i)->getNodeOutputGateId())\
148  ->getNextGate()->getOwnerModule()->getProperties()->get("CoreRouter")) {
149  defaultRouteIE = ift->getInterface(i);
150  break;
151  }
152  }
153  else if (routerType == EDGE) {
154  if (module->gate(ift->getInterface(i)->getNodeOutputGateId())\
155  ->getNextGate()->getOwnerModule()->getProperties()->get("GatewayRouter")) {
156  defaultRouteIE = ift->getInterface(i);
157  break;
158  }
159  }else if (routerType == ENDSYS) {
160  if (module->gate(ift->getInterface(i)->getNodeOutputGateId())\
161  ->getNextGate()->getOwnerModule()->getProperties()->get("EdgeRouter")) {
162  defaultRouteIE = ift->getInterface(i);
163  break;
164  }
165  }
166  }
167  }
168  }
169  };
170 
171 };
172 
174 {
175  unsigned int edgeIP;
176  int usedIPs;
177  cModule *module;
178 };
179 
180 typedef std::vector<nodeInfoRL> NODE_INFO_RL_VEC;
181 typedef std::map<int, nodeInfoRL> NODE_MAP;
182 typedef std::pair<int, nodeInfoRL> NODE_MAP_PAIR;
183 typedef std::vector<edgeRouter> EDGE_ROUTER_VEC;
184 
192 {
193  int id;
194  int asType;
195  cTopology::Node *node;
196  cModule *module;
199  IPAddress addr;
200  IPAddress netmask;
201  IPAddress subnetmask;
203 
204  nodeInfoAS(cTopology::Node *node, IPAddress a, IPAddress m) {
205  this->node = node;
206  this->module = node->getModule();
207  addr = a;
208  netmask = m;
209  int index = 0;
210  string fullPath = node->getModule()->getFullPath();
211 
212  // check if stubstring "sas" (StubAS) or "tas" (TransitAS)
213  // is contained in fullPath
214  if ( (index = fullPath.find(".sas")) != -1 )
215  asType = STUB_AS;
216  else if ( (index = fullPath.find(".tas")) != -1 )
217  asType = TRANSIT_AS;
218  else if ( (index = fullPath.find("ReaSEUnderlayNetwork")) != -1 )
220  else
221  {
222  cerr << "found module that doesn't belong to TAS or SAS: "<< fullPath<<endl;
223  opp_error("found module that doesn't belong to TAS or SAS");
224  }
225 
226  // set index to char position after substring "sas/tas"
227  if (asType == STUB_AS || asType == TRANSIT_AS)
228  {
229  index += 3;
230  string currentId;
231  while (isdigit(fullPath[index]) && (index < (int) fullPath.length()))
232  currentId += fullPath[index++];
233  id = atoi(currentId.data());
234  }
235  }
236 };
237 
238 
239 typedef std::vector<nodeInfoAS> NODE_INFO_AS_VEC;
240 
252 class RUNetworkConfigurator : public cSimpleModule
253 {
254 protected:
255  std::vector<cTopology*> rlTopology;
256  cTopology asTopology;
257  int noAS;
258  int nextPow; //<! number bits for AS addressing
260  unsigned int IP_NET_SHIFT; //<! number of bits reserved for AS addressing
261  uint32_t NET_MASK; //<! netmask calculated by netshift
262 public:
264  virtual ~RUNetworkConfigurator();
265 
266 protected:
267  //
268  // stage = 0 --> register interfaces
269  //
270  virtual int numInitStages() const {return 3;}
277  virtual void initialize(int stage);
278  virtual void handleMessage(cMessage *msg) {opp_error("message received");};
287  void createInterASPaths();
293  void disableStubLinks(nodeInfoRL &dst, nodeInfoRL &src);
298  void enableStubLinks();
305  void extractTopology();
325  void setIntraASRoutes(cTopology &topology, nodeInfoAS &asInfo);
326 
327 };
328 namespace RUNetConf {
329 
341 static bool getCoreNodes(cModule *curMod, void *nullPointer);
354 static bool getRouterLevelNodes(cModule *curMod, void *name);
355 };
356 #endif /*RUNetworkConfigurator_H_*/