RINASim  October 2016
Documentation of framework for OMNeT++
FloodMiniTable.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 
25 
27 
28 namespace FloodMiniTable {
29 
30 using namespace std;
31 
32 #include <sstream>
33 
34 // Lookup function, return a list of RMTPorts to forward a PDU/Address+qos.
35 vector<RMTPort * > FloodMiniTable::lookup(const PDU * pdu){
36  return lookup(pdu->getDstAddr(), pdu->getConnId().getQoSId());
37 }
38 vector<RMTPort * > FloodMiniTable::lookup(const Address &dst, const std::string& qos){
39 
40  vector<RMTPort* > ret;
41  string dstAddr = dst.getIpcAddress().getName();
42  FWDTableIt it = table.find(dstAddr);
43 
44  if(it != table.end()){
45  for(RMTPort* p : it->second) {
46  ret.push_back(p);
47  }
48  }
49 
50  return ret;
51 }
52 
53 // Returns a representation of the Forwarding Knowledge
55  std::ostringstream os;
56 
57  os << this->getName()<<endl;
58  for(FWDTableIt tIt = table.begin(); tIt != table.end(); tIt++){
59  os << "\t" <<tIt->first << " -> ";
60  for(RMTPort * p : tIt->second){
61  os << p->getFullPath() << " ";
62  }
63  os << endl;
64  }
65 
66  return os.str();
67 }
68 
69 //Insert/Remove an entry
70 void FloodMiniTable::addReplace(const std::string &addr, vector<RMTPort *> ports){
71  if(ports.empty()){
72  table.erase(addr);
73  } else {
74  table[addr] = ports;
75  }
76 }
77 
78 // Called after initialize
80 
82  if(par("printAtEnd").boolValue()){
83  EV << "-----------------" << endl;
84  EV << "Forwarding table::" << endl;
85  EV << toString() <<endl;
86  EV << "-----------------" << endl;
87  }
88 }
89 
90 }
Register_Class(FloodMiniTable::FloodMiniTable)
std::string getQoSId() const
Getter of selected QoS-cube identifier.
Definition: ConnectionId.cc:44
const APN & getIpcAddress() const
Getter of IPC Process address which should be unambiguous within DIF.
Definition: Address.cc:83
virtual ConnectionId & getConnId()
Definition: PDU_m.cc:336
Definition: PDU.h:42
void addReplace(const std::string &addr, vector< RMTPort * > ports)
virtual Address & getDstAddr()
Definition: PDU_m.cc:306
vector< RMTPort * > lookup(const PDU *pdu)
FWDTable::iterator FWDTableIt
const std::string & getName() const
Gets APN string name representation.
Definition: APN.cc:40
Address class holds IPC Process identification.
Definition: Address.h:42