RINASim  October 2016
Documentation of framework for OMNeT++
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SimpleTable.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 #include <iostream>
25 
27 
28 namespace SimpleTable {
29 
30 using namespace std;
31 
32 #include <sstream>
33 
35 {
36  //Inits
37  //initSignalsAndListeners();
38 
39  sigStatPDUFTLENGTH = registerSignal(SIG_STAT_PDUFT_LENGTH);
40  // Display active policy name.
41  cDisplayString& disp = getDisplayString();
42  disp.setTagArg("t", 1, "t");
43  disp.setTagArg("t", 0, getClassName());
44  onPolicyInit();
45 }
46 
47 // Lookup function, return a list of RMTPorts to forward a PDU/Address+qos.
48 vector<RMTPort *> SimpleTable::lookup(const PDU * pdu)
49 {
50  return lookup(pdu->getDstAddr(), pdu->getConnId().getQoSId());
51 }
52 vector<RMTPort *> SimpleTable::lookup(const Address &dst, const std::string&qos)
53 {
54  vector<RMTPort*> ret;
55  string dstAddr = dst.getIpcAddress().getName();
56  qos2Port * t = &table[dstAddr];
57  if (t->empty())
58  {
59  return ret;
60  }
61  if (t->find(qos) != t->end())
62  {
63  ret.push_back((*t)[qos]);
64  }
65  else if (!qos.compare(VAL_MGMTQOSID) && t->size() > 0)
66  {
67  ret.push_back(t->begin()->second);
68  }
69  if (ret.empty())
70  {
71  if (t->find(ANY_QOS) != t->end())
72  {
73  ret.push_back((*t)[ANY_QOS]);
74  }
75  }
76  return ret;
77 }
78 // Returns a representation of the Forwarding Knowledge
80 {
81  std::ostringstream os;
82 
83  os << this->getName() << endl;
84  for (FWDTableIt tIt = table.begin(); tIt != table.end(); tIt++)
85  {
86  os << "\t" << tIt->first << endl;
87  for (qos2PortIt qIt = tIt->second.begin(); qIt != tIt->second.end();
88  qIt++)
89  {
90  os << "\t\t->(" << qIt->first << " , " << qIt->second->getFullPath()
91  << ")" << endl;
92  }
93  }
94  return os.str();
95 }
96 //Insert/Remove an entry
97 void SimpleTable::insert(const Address &addr, const std::string&qos,
98  RMTPort * port)
99 {
100  insert(addr.getIpcAddress().getName(), qos, port);
101  emit(sigStatPDUFTLENGTH, (long) table.size());
102 }
103 void SimpleTable::remove(const Address &addr, const std::string&qos)
104 {
105  remove(addr.getIpcAddress().getName(), qos);
106  emit(sigStatPDUFTLENGTH, (long) table.size());
107 }
108 void SimpleTable::insert(const string &addr, const std::string&qos,
109  RMTPort * port)
110 {
111  table[addr][qos] = port;
112  emit(sigStatPDUFTLENGTH, (long) table.size());
113 }
114 void SimpleTable::remove(const string &addr, const std::string&qos)
115 {
116  table[addr].erase(qos);
117  if (table[addr].empty())
118  {
119  table.erase(addr);
120  }
121 
122  emit(sigStatPDUFTLENGTH, (long) table.size());
123 }
124 //Insert/Remove a mini entry
125 void SimpleTable::insert(const Address &addr, RMTPort * port)
126 {
127  insert(addr.getIpcAddress().getName(), port);
128  emit(sigStatPDUFTLENGTH, (long) table.size());
129 }
130 void SimpleTable::remove(const Address &addr)
131 {
132  remove(addr.getIpcAddress().getName());
133  emit(sigStatPDUFTLENGTH, (long) table.size());
134 }
135 void SimpleTable::insert(const string &addr, RMTPort * port)
136 {
137  table[addr][ANY_QOS] = port;
138  emit(sigStatPDUFTLENGTH, (long) table.size());
139 }
140 void SimpleTable::remove(const string &addr)
141 {
142  table[addr].erase(ANY_QOS);
143  if (table[addr].empty())
144  {
145  table.erase(addr);
146  }
147  emit(sigStatPDUFTLENGTH, (long) table.size());
148 }
149 // Called after initialize
152 {
153  sigStatPDUFTLENGTH = registerSignal(SIG_STAT_PDUFT_LENGTH);
154 }
156 {
157  if (par("printAtEnd").boolValue())
158  {
159  EV << toString() << endl;
160  }
161 }
162 }
map< std::string, RMTPort * > qos2Port
Definition: SimpleTable.h:37
void remove(const std::string &addr, const std::string &qos)
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
qos2Port::iterator qos2PortIt
Definition: SimpleTable.h:39
const std::string VAL_MGMTQOSID
Definition: QoSCube.cc:37
virtual ConnectionId & getConnId()
Definition: PDU_m.cc:336
FWDTable::iterator FWDTableIt
Definition: SimpleTable.h:40
Definition: PDU.h:42
#define ANY_QOS
Definition: SimpleTable.h:32
virtual Address & getDstAddr()
Definition: PDU_m.cc:306
vector< RMTPort * > lookup(const PDU *pdu)
Definition: SimpleTable.cc:48
void insert(const std::string &addr, const std::string &qos, RMTPort *port)
Register_Class(SimpleTable::SimpleTable)
const std::string & getName() const
Gets APN string name representation.
Definition: APN.cc:40
Address class holds IPC Process identification.
Definition: Address.h:42