RINASim  October 2016
Documentation of framework for OMNeT++
PortsLoadLS.cc
Go to the documentation of this file.
1 #include <PortsLoadLS.h>
2 
4 
6  const Address &addr,
7  const std::string &dst,
8  const std::string &qos,
9  const unsigned short &metric,
10  bool sendUpdate)
11 {
12  // Update/insert the entry.
13  neig[qos][addr] = metric;
14  // It's a change, mate!
15  lastChanges[qos].insert(myAddr);
16 
17  // Guess it's some sort of unique id.
18  secId++;
19 
20  linksU * myEntry = &(netState[qos][myAddr]);
21  myEntry->sId = secId;
22  myEntry->links[dst] = metric;
23 
24  if(sendUpdate)
25  {
26  // Schedule the update, bro'!
28  }
29 }
30 
32  const Address &addr,
33  const std::string &dst,
34  const std::string &qos,
35  bool sendUpdate)
36 {
37  neig[qos].erase(addr);
38 
39  if(neig[qos].size() <= 0)
40  {
41  neig.erase(qos);
42  }
43 
44  // It's a change, mate!
45  lastChanges[qos].insert(myAddr);
46 
47  // Guess it's some sort of unique id.
48  secId++;
49 
50  linksU * myEntry = &(netState[qos][myAddr]);
51  myEntry->sId = secId;
52  myEntry->links.erase(dst);
53 
54  if(sendUpdate)
55  {
56  // Schedule the update, bro'!
58  }
59 }
60 
61 
63 {
64  Enter_Method_Silent();
65 
66  if(!scheduledUpdate)
67  {
68  scheduledUpdate = true;
69  scheduleAt(simTime() + updateTimeout, new cMessage("Time2Update"));
70  }
71 }
72 
73 
74 //Get Changes
76 {
77  entries2Next ret;
78  for(
79  linksStColIt qosIt = netState.begin();
80  qosIt != netState.end();
81  qosIt++)
82  {
83  std::string qos = qosIt->first;
84  TreeNode t = constructTree(qosIt->second);
85 
86  for(TreeNodeIt it = t.chl.begin(); it != t.chl.end(); it++)
87  {
88  ret[qosPaddr(qos, (*it)->addr)] = (*it)->addr;
89  addRecursive(ret, qos, (*it)->addr, *it);
90  }
91  }
92 
93  entries2Next t = ret;
94 
95  for(entries2NextIt tIt = table.begin(); tIt != table.end(); tIt++)
96  {
97  if (ret[tIt->first] == tIt->second){
98  ret.erase(tIt->first);
99  }
100  }
101 
102  table = t;
103 
104  return ret;
105 }
106 
108  entries2Next ret;
109 
110  for(
111  linksStColIt qosIt = netState.begin();
112  qosIt != netState.end();
113  qosIt++)
114  {
115  std::string qos = qosIt->first;
116  TreeNode t = constructTree(qosIt->second);
117 
118  for(TreeNodeIt it = t.chl.begin(); it != t.chl.end(); it++)
119  {
120  ret[qosPaddr(qos, (*it)->addr)] = (*it)->addr;
121  addRecursive(ret, qos, (*it)->addr, *it);
122  }
123  }
124 
125  table = ret;
126  return table;
127 }
128 
130 {
131  TreeNode t(myAddr, 0);
132  aMap added;
133  added[myAddr] = 0;
134 
135  wMap waiting;
136  aMap * links = &(ls[myAddr].links);
137 
138  for(linksIt it = links->begin(); it !=links->end(); it++)
139  {
140  waiting[it->first] = psT(&t, it->second);
141  }
142 
143  while(!waiting.empty())
144  {
145  unsigned short min = UINT16_MAX;
146  addrList mins;
147 
148  for (wMapIt it = waiting.begin(); it != waiting.end(); it++)
149  {
150  if(it->second.metric < min)
151  {
152  min = it->second.metric;
153  mins.clear();
154  }
155  if(it->second.metric == min)
156  {
157  mins.push_back(it->first);
158  }
159  }
160 
161  while(!mins.empty())
162  {
163  std::string addr = mins.back();
164  mins.pop_back();
165 
166  psT ps = waiting[addr];
167  waiting.erase(addr);
168 
169  TreeNode * nt = new TreeNode(addr, ps.metric);
170  ps.p->chl.insert(nt);
171 
172  added[addr] = ps.metric;
173 
174  links = &(ls[addr].links);
175 
176  for(linksIt it = links->begin(); it !=links->end(); it++)
177  {
178  std::string daddr = it->first;
179 
180  if(added.find(daddr) == added.end())
181  {
182  wMapIt eI = waiting.find(daddr);
183 
184  if(eI == waiting.end())
185  {
186  waiting[daddr] = psT(nt, ps.metric + it->second);
187 
188  }
189  else if(eI->second.metric > ps.metric + it->second)
190  {
191  eI->second.metric = ps.metric + it->second;
192  eI->second.p = nt;
193  }
194  }
195  }
196  }
197  }
198 
199  return t;
200 }
202  entries2Next &ret,
203  const std::string &qos,
204  const std::string &next, TreeNode * t)
205 {
206  for(TreeNodeIt it = t->chl.begin(); it != t->chl.end(); it++)
207  {
208  ret[qosPaddr(qos, (*it)->addr)] = next;
209  addRecursive(ret, qos, next, *it);
210  }
211 }
212 
214 {
215  PortsLoadRU * up = dynamic_cast<PortsLoadRU *>(update);
216 
217  std::string qos = up->getQoS();
218  linksSt * st = &(netState[qos]);
219 
220  // Not of the type we desire.
221  if(!up)
222  {
223  return false;
224  }
225 
226  for(linksStIt it = up->entriesBegin(); it != up->entriesEnd(); it++)
227  {
228  std::string node = it->first;
229 
230  if((*st)[node].sId < it->second.sId){
231  (*st)[node] = it->second;
232  lastChanges[qos].insert(node);
233  }
234  }
235 
236  if(!lastChanges.empty())
237  {
238  scheduleUpdate();
239  return true;
240  }
241 
242  return false;
243 }
244 
245 // Called after initialize
247 {
248  myAddr = par("myAddr").stdstringValue();
249 
250  if(myAddr == "")
251  {
253  }
254 
255  updateTimeout = par("updateTimeout");
256 
257  scheduledUpdate = false;
258 
259  infMetric = 32;
260  secId = 1;
261 }
262 
263 
264 void PortsLoadLS::handleMessage(cMessage *msg)
265 {
266  if(msg->isSelfMessage())
267  {
268  //Iterate all Qos
269  for(qosNeighMetricIt it = neig.begin(); it!= neig.end(); it++)
270  {
271  //get Changes per QoS;
272  linksSt _entries = getChangedEntries(it->first);
273 
274  //iterate all Qos->Neighbour
275  for(
276  neighMetricIt it2 = it->second.begin();
277  it2 != it->second.end();
278  it2++)
279  {
280  //New Update to QoS + Neighbour
281  PortsLoadRU * update = new PortsLoadRU(it2->first, it->first);
282 
283  //Add entries
284  update->setEntries(_entries);
285 
286  //And send
287  sendUpdate(update);
288  }
289  }
290 
291  lastChanges.clear();
292  scheduledUpdate = false;
293  }
294  delete msg;
295 }
296 
297 linksSt PortsLoadLS::getChangedEntries (const std::string &qos)
298 {
299  linksSt ret;
300  addrSet * set = &lastChanges[qos];
301 
302  for(addrSetIt it = set->begin(); it != set->end(); it++)
303  {
304  ret.insert(linksStEntry(*it, netState[qos][*it]));
305  }
306 
307  return ret;
308 }
309 
310 
312 {
314 
315  EV << "I'm "<< myAddr<<endl;
316 
317  for(
318  linksStColIt qosIt = netState.begin();
319  qosIt != netState.end();
320  qosIt++)
321  {
322  EV << " QoS " << qosIt->first<<endl;
323  TreeNode t = constructTree(qosIt->second);
324 
325  for(TreeNodeIt it = t.chl.begin(); it != t.chl.end(); it++)
326  {
327  printTreeNode(*it, (*it)->addr);
328  }
329 
330  }
331 }
332 
333 void PortsLoadLS::printTreeNode(TreeNode *t, const std::string &next)
334 {
335  EV<<" " << t->addr << " -> "<<next << " ("<<t->metric<<") "
336  << " c: "<< t->chl.size() << endl;
337 
338  for(TreeNodeIt it = t->chl.begin(); it != t->chl.end(); it++)
339  {
340  printTreeNode(*it, next);
341  }
342 }
qosNeighMetric neig
Definition: PortsLoadLS.h:61
std::map< std::string, linksU > linksSt
Definition: PLLSCommon.h:38
neighMetric::iterator neighMetricIt
Definition: PLLSCommon.h:50
virtual void insertFlow(const Address &addr, const std::string &dst, const std::string &qos, const unsigned short &metric, bool sendUpdate)
Definition: PortsLoadLS.cc:5
linksSt getChangedEntries(const std::string &qos)
Definition: PortsLoadLS.cc:297
entries2Next table
Definition: PortsLoadLS.h:79
linksStIt entriesBegin()
Definition: PortsLoadRU.cc:43
unsigned short metric
Definition: PLLSCommon.h:67
virtual void removeFlow(const Address &addr, const std::string &dst, const std::string &qos, bool sendUpdate)
Definition: PortsLoadLS.cc:31
const APN & getIpcAddress() const
Getter of IPC Process address which should be unambiguous within DIF.
Definition: Address.cc:83
entries2Next getChanges()
Definition: PortsLoadLS.cc:75
std::map< std::string, psT > wMap
Definition: PLLSCommon.h:130
std::vector< std::string > addrList
Definition: PLLSCommon.h:55
qosNeighMetric::iterator qosNeighMetricIt
Definition: PLLSCommon.h:51
void handleMessage(cMessage *msg)
Definition: PortsLoadLS.cc:264
void addRecursive(entries2Next &ret, const std::string &qos, const std::string &next, TreeNode *t)
Definition: PortsLoadLS.cc:201
unsigned int updateTimeout
Definition: PortsLoadLS.h:68
std::set< std::string > addrSet
Definition: PLLSCommon.h:54
linksStCol::iterator linksStColIt
Definition: PLLSCommon.h:46
std::set< TreeNode * > chl
Definition: PLLSCommon.h:68
std::map< qosPaddr, std::string > entries2Next
entries2Next getAll()
Definition: PortsLoadLS.cc:107
void finish()
Definition: PortsLoadLS.cc:311
std::string addr
Definition: PLLSCommon.h:66
bool scheduledUpdate
Definition: PortsLoadLS.h:77
virtual void finish()
Definition: IntRouting.cc:25
addrSet::iterator addrSetIt
Definition: PLLSCommon.h:59
Address myAddress
Definition: IntRouting.h:49
std::string myAddr
Definition: PortsLoadLS.h:60
std::string getQoS()
Definition: PortsLoadRU.cc:25
bool processUpdate(IntRoutingUpdate *update)
Definition: PortsLoadLS.cc:213
linksStCol netState
Definition: PortsLoadLS.h:62
std::map< std::string, unsigned short >::iterator linksIt
Definition: PLLSCommon.h:44
virtual void scheduleUpdate()
Definition: PortsLoadLS.cc:62
linksStIt entriesEnd()
Definition: PortsLoadRU.cc:47
unsigned short infMetric
Definition: PortsLoadLS.h:59
std::pair< std::string, linksU > linksStEntry
Definition: PLLSCommon.h:39
std::map< std::string, unsigned short > aMap
Definition: PLLSCommon.h:131
void printTreeNode(TreeNode *t, const std::string &next)
Definition: PortsLoadLS.cc:333
TreeNode * p
Definition: PLLSCommon.h:104
std::set< TreeNode * >::iterator TreeNodeIt
Definition: PLLSCommon.h:100
entries2Next::iterator entries2NextIt
unsigned int secId
Definition: PortsLoadLS.h:64
void onPolicyInit()
Definition: PortsLoadLS.cc:246
void sendUpdate(IntRoutingUpdate *update)
Definition: IntRouting.cc:62
std::pair< std::string, std::string > qosPaddr
unsigned short metric
Definition: PLLSCommon.h:105
void setEntries(linksSt)
Definition: PortsLoadRU.cc:37
const std::string & getName() const
Gets APN string name representation.
Definition: APN.cc:40
linksSt::iterator linksStIt
Definition: PLLSCommon.h:45
Register_Class(PortsLoadLS)
qos2addrSet lastChanges
Definition: PortsLoadLS.h:63
Address class holds IPC Process identification.
Definition: Address.h:42
wMap::iterator wMapIt
Definition: PLLSCommon.h:133
TreeNode constructTree(linksSt &ls)
Definition: PortsLoadLS.cc:129