RINASim  October 2016
Documentation of framework for OMNeT++
QoSTable.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 <QoSTable/QoSTable.h>
24 
25 
27 
28 namespace QoSTable {
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 * > QoSTable::lookup(const PDU * pdu){
36  return lookup(pdu->getDstAddr(), pdu->getConnId().getQoSId());
37 }
38 vector<RMTPort * > QoSTable::lookup(const Address &dst, const std::string &qos){
39  vector<RMTPort* > ret;
40  string dstAddr = dst.getIpcAddress().getName();
41 
42  ret = lookupInt(dstAddr, qos);
43 
44  if(ret.empty() && !qos.compare(VAL_MGMTQOSID) ) {
45  for(QoSFWDTableIt qIt = table.begin(); qIt != table.end(); qIt++){
46  ret = lookupInt(dstAddr, qIt->first);
47  if(!ret.empty()) { return ret; }
48  }
49  }
50 
51  return ret;
52 }
53 
54 vector<RMTPort * > QoSTable::lookupInt(const string &dst, const std::string &qos){
55  vector<RMTPort* > ret;
56  FWDTableIt it = table[qos].find(dst);
57  if(it != table[qos].end()){
58  ret.push_back(it->second);
59  }
60  return ret;
61 }
62 
63 // Returns a representation of the Forwarding Knowledge
65  std::ostringstream os;
66 
67  os << this->getFullPath()<<endl;
68 
69  for(QoSFWDTableIt qIt = table.begin(); qIt != table.end(); qIt++){
70  os << "\tQoS : " <<qIt->first << endl;
71  for(FWDTableIt tIt = qIt->second.begin(); tIt != qIt->second.end(); tIt++){
72  os << "\t\t" <<tIt->first << " -> " <<tIt->second->getFullPath() << endl;
73  }
74  }
75 
76 
77  return os.str();
78 }
79 
80 //Insert/Remove an entry
81 void QoSTable::insert(const Address &addr, const std::string &qos, RMTPort * port){
82  insert(addr.getIpcAddress().getName(), qos, port);
83 }
84 void QoSTable::remove(const Address &addr, const std::string &qos){
85  remove(addr.getIpcAddress().getName(), qos);
86 }
87 void QoSTable::insert(const string &addr, const std::string &qos, RMTPort * port){
88  table[qos][addr] = port;
89 }
90 void QoSTable::remove(const string &addr, const std::string &qos){
91  table[qos].erase(addr);
92  if(table[qos].empty()){
93  table.erase(qos);
94  }
95 }
97  table.clear();
98 }
99 
100 
101 // Called after initialize
103 
105  if(par("printAtEnd").boolValue()){
106  EV << toString() <<endl;
107  }
108 }
109 
110 }
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 remove(const std::string &addr, const std::string &qos)
QoSFWDTable::iterator QoSFWDTableIt
Definition: QoSTable.h:40
const std::string VAL_MGMTQOSID
Definition: QoSCube.cc:37
virtual ConnectionId & getConnId()
Definition: PDU_m.cc:336
Definition: PDU.h:42
string toString()
Definition: QoSTable.cc:64
void insert(const std::string &addr, const std::string &qos, RMTPort *port)
vector< RMTPort * > lookup(const PDU *pdu)
Definition: QoSTable.cc:35
virtual Address & getDstAddr()
Definition: PDU_m.cc:306
vector< RMTPort * > lookupInt(const string &dst, const std::string &qos)
Definition: QoSTable.cc:54
const std::string & getName() const
Gets APN string name representation.
Definition: APN.cc:40
Register_Class(QoSTable::QoSTable)
FWDTable::iterator FWDTableIt
Definition: QoSTable.h:37
Address class holds IPC Process identification.
Definition: Address.h:42