RINASim  October 2016
Documentation of framework for OMNeT++
MSimpleGenerator.cc
Go to the documentation of this file.
1 // The MIT License (MIT)
2 //
3 // Copyright (c) 2014-2016 Brno University of Technology, PRISTINE project
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 // THE SOFTWARE.
22 
24 #include "APN.h"
25 
26 
27 
28 namespace MSimpleGenerator {
29 
31 
32 using namespace std;
33 
34 // A new flow has been inserted/or removed
35 void MSimpleGenerator::insertedFlow(const Address &addr, const QoSCube &qos, RMTPort * port){
36  std::string dst = addr.getIpcAddress().getName();
37  neighbours[dst].insert(port);
38  if(neighbours[dst].size() == 1){
39  rt->insertFlow(addr, dst, "", 1);
40  routingUpdated();
41  }
42 }
43 void MSimpleGenerator::removedFlow(const Address &addr, const QoSCube& qos, RMTPort * port){
44  std::string dst = addr.getIpcAddress().getName();
45  neighbours[dst].erase(port);
46  if(neighbours[dst].size() <= 0){
47  rt->removeFlow(addr, dst, "");
48  neighbours.erase(dst);
49  routingUpdated();
50  }
51 }
52 
53 //Routing has processes a routing update
55  entries2Next changes = rt->getChanges();
56 
57  for(entries2NextIt it = changes.begin(); it!= changes.end(); it++){
58  qosPaddr dst = it->first;
59  std::vector< RMTPort * > ps;
60 
61  for(std::string nextHop : it->second.nh){
62  RMTPort * p = NULL;
63  if(nextHop != "") {
64  NTableIt n = neighbours.find(nextHop);
65  if(n != neighbours.end()){
66  if(!n->second.empty()) {
67  p = *(n->second.begin());
68  }
69  }
70  }
71  if(p != NULL) {
72  ps.push_back(p);
73  }
74  }
75  fwd->addReplace(dst.second, ps);
76  }
77 }
78 
79 // Called after initialize
81  //Set Forwarding policy
82  fwd = getRINAModule<IntMMForwarding *>(this, 2, {MOD_RELAYANDMUX, MOD_POL_RMT_PDUFWD});
83  rt = getRINAModule<IntSimpleRouting *>(this, 2, {MOD_POL_ROUTING});
84 
85  difA = getRINAModule<DA *>(this, 3, {MOD_DIFALLOC, MOD_DA});
86 }
87 
88 }
Register_Class(MSimpleGenerator)
const char * MOD_POL_ROUTING
Definition: ExternConsts.cc:77
const char * MOD_DIFALLOC
Definition: ExternConsts.cc:34
const APN & getIpcAddress() const
Getter of IPC Process address which should be unambiguous within DIF.
Definition: Address.cc:83
virtual void insertedFlow(const Address &addr, const QoSCube &qos, RMTPort *port)
std::map< qosPaddr, std::string > entries2Next
const char * MOD_RELAYANDMUX
Definition: ExternConsts.cc:57
NTable::iterator NTableIt
Class representing QoSCube with all its properties that is primarily used by FA, RMT and RA Specifica...
Definition: QoSCube.h:57
entries2Next::iterator entries2NextIt
const char * MOD_DA
Definition: ExternConsts.cc:33
std::pair< std::string, std::string > qosPaddr
const std::string & getName() const
Gets APN string name representation.
Definition: APN.cc:40
virtual void removedFlow(const Address &addr, const QoSCube &qos, RMTPort *port)
const char * MOD_POL_RMT_PDUFWD
Definition: ExternConsts.cc:73
Address class holds IPC Process identification.
Definition: Address.h:42