RINASim  October 2016
Documentation of framework for OMNeT++
MiniTable.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 
23 #include <MiniTable/MiniTable.h>
24 
25 
27 
28 namespace MiniTable {
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 * > MiniTable::lookup(const PDU * pdu){
36  return lookup(pdu->getDstAddr(), pdu->getConnId().getQoSId());
37 }
38 vector<RMTPort * > MiniTable::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  ret.push_back(it->second);
46  } else {
47  // std::cout << this->getFullPath()<<endl;
48  // std::cout << dst << " not found "<<endl;
49  }
50 
51  return ret;
52 }
53 
54 // Returns a representation of the Forwarding Knowledge
56  std::ostringstream os;
57 
58  os << this->getName()<<endl;
59  for(FWDTableIt tIt = table.begin(); tIt != table.end(); tIt++){
60  os << "\t" <<tIt->first << " -> " <<tIt->second->getFullPath() << endl;
61  }
62 
63  return os.str();
64 }
65 
66 //Insert/Remove an entry
67 void MiniTable::insert(const Address &addr, RMTPort * port){
68  insert(addr.getIpcAddress().getName(), port);
69 }
70 void MiniTable::remove(const Address &addr){
71  remove(addr.getIpcAddress().getName());
72 }
73 void MiniTable::insert(const string &addr, RMTPort * port){
74  table[addr] = port;
75 }
76 void MiniTable::remove(const string &addr){
77  table.erase(addr);
78 }
80  table.clear();
81 }
82 
83 
84 // Called after initialize
86 
88  if(par("printAtEnd").boolValue()){
89  EV << toString() <<endl;
90  }
91 }
92 
93 }
FWDTable::iterator FWDTableIt
Definition: MiniTable.h:37
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
void insert(const std::string &addr, RMTPort *port)
virtual ConnectionId & getConnId()
Definition: PDU_m.cc:336
Register_Class(MiniTable::MiniTable)
Definition: PDU.h:42
virtual Address & getDstAddr()
Definition: PDU_m.cc:306
void remove(const std::string &addr)
vector< RMTPort * > lookup(const PDU *pdu)
Definition: MiniTable.cc:35
const std::string & getName() const
Gets APN string name representation.
Definition: APN.cc:40
Address class holds IPC Process identification.
Definition: Address.h:42