RINASim  October 2016
Documentation of framework for OMNeT++
TDomainRouting.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <map>
5 
6 #include <IntRouting.h>
7 
8 #include "common/nhLMetric.h"
10 #include "common/LS_Module.h"
11 #include "common/DV_Module.h"
12 
13 using namespace std;
14 using namespace common_LSModule;
15 using namespace common_DVModule;
16 
17 namespace tDomain {
18 
19 enum ModuleAlgs { DV, LS };
20 
21 class updateI {};
22 
23 template<class T>
25 protected:
26  map<string, Routing_Alg<T> * > modules;
27 
29  string myAddr;
30 
31  class Update : public IntRoutingUpdate {
32  public:
33  string domId;
35  };
36 
37  class AutoMsg : public cMessage {
38  public:
39  string domId;
40  };
41 
42 public:
43  virtual void addDomain(const string & domId, const string &_addr, T infinite, ModuleAlgs alg) {
44  if(modules[domId] == NULL) {
45  switch(alg) {
46  case DV : modules[domId] = new DV_Module<T>(this, myAddress, _addr, infinite); break;
47  case LS : modules[domId] = new LS_Module<T>(this, myAddress, _addr, infinite); break;
48  }
49  modules[domId]->setDescriptor(domId);
50  }
51  }
52  virtual void removeDomain(const string & domId) {
53 
54  if(modules[domId] != NULL) {
55  delete modules[domId];
56  }
57  modules.erase(domId);
58  }
59 
60  //Process a Routing Update, return true => inform FWDG of the update
61  virtual bool processUpdate(IntRoutingUpdate * update) {
62  if(Update * u = dynamic_cast<Update*>(update)) {
63  if(modules[u->domId] != NULL) {
64  return modules[u->domId]->processUpdate(u->u);
65  }
66  }
67  return false;
68  }
69 
70  //Modules connection
71  virtual void chSendUpdate(Routing_Update * update, const Address & dst, Routing_Alg_I * module) {
72  bool found = false;
73  Update * up = new Update();
74  up->setDestination(dst);
75  up->setSource(myAddress);
76  up->u = update;
77 
78  for(const auto & md : modules) {
79  if(md.second == module) {
80  found = true;
81  up->domId = md.first;
82  break;
83  }
84  }
85 
86  if(found){
87  sendUpdate(up);
88  }
89  }
90 
91  virtual void chScheduleAt(Routing_Alg_I * module, const simtime_t & t) {
92  Enter_Method_Silent();
93  bool found = false;
94  AutoMsg * m = new AutoMsg();
95 
96  for(const auto & md : modules) {
97  if(md.second == module) {
98  found = true;
99  m->domId = md.first;
100  break;
101  }
102  }
103 
104  if(found){
105  scheduleAt(simTime()+t, m);
106  }
107  }
108 
109 
110  //Flow inserted/removed
111  virtual void insertFlow(const Address &addr, const string &dst, const string& domId, const T &metric) {
112  if(modules[domId] != NULL) {
113  modules[domId]->addFlow(addr, dst, metric);
114  }
115  }
116  virtual void removeFlow(const Address &addr, const string &dst, const string& domId) {
117  if(modules[domId] != NULL) {
118  modules[domId]->removeFlow(addr, dst);
119  }
120  }
121 
122  //Get Changes // QoS // Dst // <metric, next hops>
123  virtual map<string, map<string, nhLMetric<T> > > getChanges() {
124  map<string, map<string, nhLMetric<T> > > ret;
125  for(auto & md : modules) {
126  ret[md.first] = md.second->getChanges();
127  }
128  return ret;
129  }
130  virtual map<string, map<string, nhLMetric<T> > > getAll() {
131  map<string, map<string, nhLMetric<T> > > ret;
132  for(auto & md : modules) {
133  ret[md.first] = md.second->getAll();
134  }
135  return ret;
136  }
137 
138  virtual void handleMessage(cMessage *msg){
139  if(AutoMsg * m = dynamic_cast<AutoMsg*>(msg)) {
140  if(modules[m->domId] != NULL) {
141  modules[m->domId]->sendUpdate();
142  }
143  }
144  delete msg;
145  }
146 
147  // Add/Remove secondary addresses
148  void addAddr(const std::string &domId, const std::string &syn){
149  if(modules[domId] != NULL) {
150  modules[domId]->addSynonym(syn);
151  }
152  }
153 
154  void removeAddr(const std::string &domId, const std::string &syn){
155  if(modules[domId] != NULL) {
156  modules[domId]->removeSynonym(syn);
157  }
158  }
159 
160 
161 protected:
162  // Called after initialize
163  virtual void onPolicyInit() {
164  myAddr = par("myAddr").stdstringValue();
165  if(myAddr == "") {
166  myAddr = myAddress.getIpcAddress().getName();
167  }
168  };
169 
170  void finish(){
171  if(par("printAtEnd").boolValue()){
172  EV<< "Routing at "<< myAddress <<endl;
173  for(auto & md : modules) {
174  EV << "-----With Domain \"" << md.first <<"\"" << endl;
175  md.second->print();
176  }
177  }
178  }
179 };
180 
181 }
virtual void insertFlow(const Address &addr, const string &dst, const string &domId, const T &metric)
map< string, Routing_Alg< T > * > modules
virtual bool processUpdate(IntRoutingUpdate *update)
virtual void removeDomain(const string &domId)
virtual void removeFlow(const Address &addr, const string &dst, const string &domId)
virtual map< string, map< string, nhLMetric< T > > > getAll()
void addAddr(const std::string &domId, const std::string &syn)
void setDescriptor(const string &des)
Definition: Routing_Alg.h:72
virtual void handleMessage(cMessage *msg)
virtual void chSendUpdate(Routing_Update *update, const Address &dst, Routing_Alg_I *module)
virtual void addDomain(const string &domId, const string &_addr, T infinite, ModuleAlgs alg)
void removeAddr(const std::string &domId, const std::string &syn)
virtual void onPolicyInit()
virtual void chScheduleAt(Routing_Alg_I *module, const simtime_t &t)
Address class holds IPC Process identification.
Definition: Address.h:42
virtual map< string, map< string, nhLMetric< T > > > getChanges()