RINASim  October 2016
Documentation of framework for OMNeT++
VoidDCGenerator.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 
23 Register_Class(VoidDCGenerator);
24 
25 using namespace std;
26 
27 // A new flow has been inserted/or removed
28 void VoidDCGenerator::insertedFlow(const Address &addr, const QoSCube &qos, RMTPort * port){
29  string dst = addr.getIpcAddress().getName();
30  DCAddr dst_addr = DCAddr(dst);
31  neighsAddr[dst] = dst_addr;
32 
33  if(!fwd->setNeigh(dst, port)){ return; }
34 
35  bool first = ports[dst_addr].empty();
36  ports[dst_addr].insert(port);
37 
38  if(first){
39  rt->insertNeighbour(addr, dst_addr);
40  routingUpdated();
41  }
42 }
43 void VoidDCGenerator::removedFlow(const Address &addr, const QoSCube& qos, RMTPort * port){
44  std::string dst = addr.getIpcAddress().getName();
45  DCAddr dst_addr = DCAddr(dst);
46  neighsAddr[dst] = dst_addr;
47 
48 
49  ports[dst_addr].erase(port);
50  bool last = ports[dst_addr].empty();
51  RMTPort * p = nullptr;
52  if(!last) {
53  p = *ports[dst_addr].begin();
54  } else {
55  ports.erase(dst_addr);
56  }
57 
58  if(!fwd->setNeigh(dst, p)){ return; }
59 
60  if(last){
61  rt->removeNeighbour(addr, dst_addr);
62  routingUpdated();
63  }
64 }
65 
66 //Routing has processes a routing update
68  if(!updateRoutes) { return; }
69 
70  auto entries = rt->getChanges();
71 
72  for(auto & e : entries) {
73  fwd->setDst(e.dst, e.next);
74  }
75 
76 }
77 
78 void VoidDCGenerator::handleMessage(cMessage *msg) {
79  delete msg;
80  updateRoutes = true;
81  routingUpdated();
82 }
83 
84 
85 // Called after initialize
87  //Set Forwarding policy
88  fwd = check_and_cast<iSimpleDCForwarding *>
89  (getModuleByPath("^.^.relayAndMux.pduForwardingPolicy"));
90  rt = check_and_cast<IntDCRouting *>
91  (getModuleByPath("^.^.routingPolicy"));
92 
93  difA = check_and_cast<DA *>(getModuleByPath("^.^.^.difAllocator.da"));
94 
95  string myAddr = getModuleByPath("^.^")->par("ipcAddress").stringValue();
96  Im = DCAddr(myAddr);
97  fwd->setNodeInfo(myAddr);
98 
99  simtime_t startUpdating = par("startUpdating").doubleValue();
100  if(startUpdating > simTime()) {
101  updateRoutes = false;
102  scheduleAt(startUpdating, new cMessage("start"));
103  } else {
104  updateRoutes = true;
105  }
106 }
107 
108 }
Register_Class(SimpleDCGenerator)
const APN & getIpcAddress() const
Getter of IPC Process address which should be unambiguous within DIF.
Definition: Address.cc:83
void handleMessage(cMessage *msg)
virtual void removedFlow(const Address &addr, const QoSCube &qos, RMTPort *port)
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
virtual void insertedFlow(const Address &addr, const QoSCube &qos, RMTPort *port)
const std::string & getName() const
Gets APN string name representation.
Definition: APN.cc:40
Address class holds IPC Process identification.
Definition: Address.h:42