RINASim  October 2016
Documentation of framework for OMNeT++
SimpleDCGenerator.cc
Go to the documentation of this file.
1 //
2 // This program is free software: you can redistribute it and/or modify
3 // it under the terms of the GNU Lesser General Public License as published by
4 // the Free Software Foundation, either version 3 of the License, or
5 // (at your option) any later version.
6 //
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public License
13 // along with this program. If not, see http://www.gnu.org/licenses/.
14 //
15 
17 #include "APN.h"
18 
19 
20 
21 namespace NSPSimpleDC {
22 
24 
25 using namespace std;
26 using namespace common_GraphCL;
27 
28 // A new flow has been inserted/or removed
29 void SimpleDCGenerator::insertedFlow(const Address &addr, const QoSCube &qos, RMTPort * port){
30  string dst = addr.getIpcAddress().getName();
31  DCAddr dst_addr = DCAddr(dst);
32  neighsAddr[dst] = dst_addr;
33 
34  if(!fwd->setNeigh(dst, port)){ return; }
35 
36  bool first = ports[dst_addr].empty();
37  ports[dst_addr].insert(port);
38 
39  if(first){
40  rt->insertFlow(addr, dst, "", 1);
41  routingUpdated();
42  }
43 }
44 void SimpleDCGenerator::removedFlow(const Address &addr, const QoSCube& qos, RMTPort * port){
45  std::string dst = addr.getIpcAddress().getName();
46  DCAddr dst_addr = DCAddr(dst);
47  neighsAddr[dst] = dst_addr;
48 
49 
50  ports[dst_addr].erase(port);
51  bool last = ports[dst_addr].empty();
52  RMTPort * p = nullptr;
53  if(!last) {
54  p = *ports[dst_addr].begin();
55  } else {
56  ports.erase(dst_addr);
57  }
58 
59  if(!fwd->setNeigh(dst, p)){ return; }
60 
61  if(last){
62  rt->removeFlow(addr, dst, "");
63  routingUpdated();
64  }
65 }
66 
67 //Routing has processes a routing update
69  if(!updateRoutes) { return; }
70 
71  map<string, map<string, nhLMetric<mType> > > changes = rt->getChanges();
72 
73  for(const auto & qosEntries : changes){
74  for(const auto & entry : qosEntries.second){
75  set<DCAddr> links;
76  for(string nextHop : entry.second.nh){
77  DCAddr n_addr = neighsAddr[nextHop];
78  if(n_addr.type < 0) {
79  cerr << "Unknown neighbour "<< nextHop << endl;
80  } else {
81  links.insert(n_addr);
82  }
83  }
84  fwd->setDst(entry.first, links);
85  }
86  }
87 }
88 
89 void SimpleDCGenerator::handleMessage(cMessage *msg) {
90  delete msg;
91  updateRoutes = true;
92 
93  map<string, map<string, nhLMetric<mType> > > changes = rt->getAll();
94 
95  for(const auto & qosEntries : changes){
96  for(const auto & entry : qosEntries.second){
97 
98  set<DCAddr> links;
99  for(string nextHop : entry.second.nh){
100  DCAddr n_addr = neighsAddr[nextHop];
101  if(n_addr.type < 0) {
102  cerr << "Unknown neighbour "<< nextHop << endl;
103  } else {
104  links.insert(n_addr);
105  }
106  }
107  fwd->setDst(entry.first, links);
108  }
109  }
110 }
111 
112 // Called after initialize
114  //Set Forwarding policy
115  fwd = check_and_cast<iSimpleDCForwarding *>
116  (getModuleByPath("^.^.relayAndMux.pduForwardingPolicy"));
117  rt = check_and_cast<IntTSimpleRouting<mType> *>
118  (getModuleByPath("^.^.routingPolicy"));
119 
120  difA = check_and_cast<DA *>(getModuleByPath("^.^.^.difAllocator.da"));
121 
122  mType infMetric = par("infinite");
123  rt->setInfinite(infMetric);
124 
125  string myAddr = getModuleByPath("^.^")->par("ipcAddress").stringValue();
126  Im = DCAddr(myAddr);
127  fwd->setNodeInfo(myAddr);
128 
129  simtime_t startUpdating = par("startUpdating").doubleValue();
130  if(startUpdating > simTime()) {
131  updateRoutes = false;
132  scheduleAt(startUpdating, new cMessage("start"));
133  } else {
134  updateRoutes = true;
135  }
136 }
137 
138 }
virtual void removedFlow(const Address &addr, const QoSCube &qos, RMTPort *port)
Register_Class(SimpleDCGenerator)
unsigned short mType
const APN & getIpcAddress() const
Getter of IPC Process address which should be unambiguous within DIF.
Definition: Address.cc:83
Definition: DA.h:43
Class representing QoSCube with all its properties that is primarily used by FA, RMT and RA Specifica...
Definition: QoSCube.h:57
const std::string & getName() const
Gets APN string name representation.
Definition: APN.cc:40
virtual void insertedFlow(const Address &addr, const QoSCube &qos, RMTPort *port)
Address class holds IPC Process identification.
Definition: Address.h:42