RINASim  October 2016
Documentation of framework for OMNeT++
DomainTable.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 
26 
27 #include <Utils.h>
28 #include <sstream>
29 
30 namespace DomainTable {
31 
33 
34 using namespace std;
35 
36 
37 // Lookup function, return a list of RMTPorts to forward a PDU/Address+qos.
38 vector<RMTPort * > DomainTable::lookup(const PDU * pdu){
39  return lookup(pdu->getDstAddr(), pdu->getConnId().getQoSId());
40 }
41 
42 vector<RMTPort * > DomainTable::lookup(const Address &dst, const std::string& qos){
43  vector<RMTPort* > ret;
44 
45  pAddr pa = parseAddr(dst.getIpcAddress().getName());
46  if(table[pa.domain].entries.find(pa.addr) != table[pa.domain].entries.end()){
47  ret.push_back(table[pa.domain].entries[pa.addr]);
48  return ret;
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 Domain : \"" <<tIt->first<<"\""<<endl;
61  for(s2PortIt qIt = tIt->second.entries.begin();
62  qIt != tIt->second.entries.end();
63  qIt++){
64  os << "\t\t->(" << qIt->first << " , "<<qIt->second->getFullPath()<<")" <<endl;
65  }
66  }
67 
68  return os.str();
69 }
70 
71 //Insert/Remove a domain
72 void DomainTable::addDomain(const string &domain){
73  domains.push_back(domain);
74  if(domain == ""){
75  table[""].len = 0;
76  } else {
77  table[domain].len = split(domain, '.').size();
78  }
79 }
80 void DomainTable::removeDomain(const string &domain){
81  for(sListIt it = domains.begin(); it!= domains.end(); it++){
82  if(*it == domain){
83  domains.erase(it);
84  break;
85  }
86  }
87  domains.push_back(domain);
88  table.erase(domain);
89 }
90 
91 //Insert/Remove an entry
92 void DomainTable::insert(const string &domain, const string &addr, RMTPort * port){
93  table[domain].entries[addr] = port;
94 }
95 void DomainTable::remove(const string &domain, const string &addr){
96  table[domain].entries.erase(addr);
97 }
98 
99 pAddr DomainTable::parseAddr(const string &addr){
100  for(sListIt it = domains.begin(); it!= domains.end(); it++){
101  if(isPrefix(*it, addr)){
102  unsigned short len = table[*it].len;
103  vector<string> sep = split(addr, '.');
104  if(sep.size() <= len) {
105  return pAddr(*it, "");
106  } else {
107  return pAddr(*it, sep[len]);
108  }
109  }
110  }
111  return pAddr("", addr);
112 }
113 
114 // Called after initialize
116 
118  if(par("printAtEnd").boolValue()){
119  EV << toString() <<endl;
120  }
121 }
122 
123 }
s2Port::iterator s2PortIt
Definition: DomainTable.h:49
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
bool isPrefix(std::string prefix, std::string s)
Definition: Utils.cc:62
std::vector< std::string > & split(const std::string &s, char delim, std::vector< std::string > &elems)
Definition: Utils.cc:33
virtual ConnectionId & getConnId()
Definition: PDU_m.cc:336
FWDTable::iterator FWDTableIt
Definition: DomainTable.h:50
vector< RMTPort * > lookup(const PDU *pdu)
Definition: DomainTable.cc:38
void remove(const string &domain, const string &addr)
Definition: DomainTable.cc:95
Definition: PDU.h:42
virtual Address & getDstAddr()
Definition: PDU_m.cc:306
sList::iterator sListIt
Definition: DomainTable.h:37
pAddr parseAddr(const string &addr)
Definition: DomainTable.cc:99
void removeDomain(const string &domain)
Definition: DomainTable.cc:80
void addDomain(const string &domain)
Definition: DomainTable.cc:72
const std::string & getName() const
Gets APN string name representation.
Definition: APN.cc:40
Address class holds IPC Process identification.
Definition: Address.h:42
void insert(const string &domain, const string &addr, RMTPort *port)
Definition: DomainTable.cc:92
Register_Class(DomainTable)