RINASim  October 2016
Documentation of framework for OMNeT++
NFlowTable.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 "NFlowTable.h"
24 
25 //Statistic collextion
26 const char* SIG_STAT_FT_SIZE = "FT_FlowTableSize";
27 
29 
31 {
32  //Inits
34  //Watchers
35  WATCH_LIST(NFlowTab);
36 }
37 
38 std::string NFlowTable::info() const {
39  std::ostringstream os;
40  os << "id=" << this->getId() << endl;
41  /*
42  for(TFTConstIter it = FaiTable.begin(); it != FaiTable.end(); ++it )
43  {
44  FAITableEntry tft = *it;
45  os << tft << endl;
46  }
47  */
48  return os.str();
49 }
50 
52  for(TFTIter it = NFlowTab.begin(); it != NFlowTab.end(); ++it) {
53  NFlowTableEntry tft = *it;
54  if (tft.getCFlow()->getDstAddr().getApn() == apname
56  return &(*it);
57  }
58  return NULL;
59 }
60 
62  //EV << "Look APN> " << ipcAddr << endl;
63  for(TFTIter it = NFlowTab.begin(); it != NFlowTab.end(); ++it) {
64  NFlowTableEntry tft = *it;
65  //EV << "XXXX " << tft.getCFlow()->getSrcAddr().getIpcAddress() << endl
66  // << "YYYY " << (tft.getAllocateStatus() == FAITableEntry::FORWARDED) << endl;
67  if (tft.getCFlow()->getSrcAddr().getIpcAddress() == apname
69  return &(*it);
70  }
71  return NULL;
72 
73 }
74 
75 NFlowTableEntry* NFlowTable::findEntryByApns(const APN& srcApn, const APN& dstApn) {
76  for(TFTIter it = NFlowTab.begin(); it != NFlowTab.end(); ++it) {
77  NFlowTableEntry tft = *it;
78  if (tft.getCFlow()->getSrcApni().getApn() == srcApn
79  && tft.getCFlow()->getDstApni().getApn() == dstApn
81  return &(*it);
82  }
83  return NULL;
84 }
85 
87  TFAIPtrs list;
88  for(TFTIter it = NFlowTab.begin(); it != NFlowTab.end(); ++it) {
89  NFlowTableEntry tft = *it;
90  if (tft.getCFlow()->getDstNeighbor().getApn() == apname
92  list.push_back(&(*it));
93  }
94  return list;
95 }
96 
98  if (!invId) return NULL;
99  for(TFTIter it = NFlowTab.begin(); it != NFlowTab.end(); ++it) {
100  NFlowTableEntry tft = *it;
101  if (tft.getCFlow()->getAllocInvokeId() == invId)
102  return &(*it);
103  }
104  return NULL;
105 }
106 
107 /*
108 TFAIPtrs NFlowTable::findEntriesAffectedByMgmt(const Flow* flow) {
109  TFAIPtrs list;
110  for(TFTIter it = FaiTable.begin(); it != FaiTable.end(); ++it) {
111  NFlowTableEntry tft = *it;
112  if (tft.getCFlow()->getSrcNeighbor().getApname() == flow->getSrcApni().getApn()
113  && tft.getCFlow()->getDstNeighbor().getApname() == flow->getDstApni().getApn()
114  && tft.getAllocateStatus() == NFlowTableEntry::ALLOC_PEND)
115  list.push_back(&(*it));
116  }
117  return list;
118 }
119 */
120 
121 //XXX: Vesely - This search does not yield exact intended match!
123  for(TFTIter it = NFlowTab.begin(); it != NFlowTab.end(); ++it) {
124  NFlowTableEntry tft = *it;
125  if (tft.getCFlow()->getDstNeighbor() == addr
127  return &(*it);
128  }
129  return NULL;
130 }
131 
132 void NFlowTable::handleMessage(cMessage *msg)
133 {
134 }
135 
137  this->insert(NFlowTableEntry(flow));
139  //EV << "FT emits signal " << (long)FaiTable.size() << endl;
140  emit(sigStatFTSize, (long)NFlowTab.size());
141 }
142 
144  Enter_Method("insertFlow()");
145  NFlowTab.push_back(entry);
146 }
147 
149  Enter_Method("removeFlow()");
150  NFlowTableEntry* entry = findEntryByFlow(flow);
151  if (entry)
152  NFlowTab.remove(*entry);
153 }
154 
156  for(TFTIter it = NFlowTab.begin(); it != NFlowTab.end(); ++it) {
157  NFlowTableEntry tft = *it;
158  if (*(tft.getCFlow()) == *flow)
159  return &(*it);
160  }
161  return NULL;
162 }
163 
165  for(TFTIter it = NFlowTab.begin(); it != NFlowTab.end(); ++it) {
166  NFlowTableEntry tft = *it;
167  if (tft.getFai() == fai)
168  return &(*it);
169  }
170  return NULL;
171 }
172 
174  NFlowTableEntry* fte = findEntryByFlow(flow);
175  if (fte) {
176  fte->setAllocateStatus(status);
177  }
178  else
179  EV << "findByFlow() returned NULL" << endl;
180 }
181 
183  NFlowTableEntry* fte = findEntryByFai(fai);
184  if (fte)
185  fte->setAllocateStatus(status);
186  else
187  EV << "findByFai() returned NULL" << endl;
188 }
189 
191  NFlowTableEntry* fte = findEntryByFlow(flow);
192  fte->setFai(fai);
193 }
194 
196  // display number of flows
197  std::ostringstream os;
198  os << "records: " << getSize();
199  setPolicyDisplayString(this, os.str().c_str());
200 }
201 
203  sigStatFTSize = registerSignal(SIG_STAT_FT_SIZE);
204 }
205 
207  for(TFTIter it = NFlowTab.begin(); it != NFlowTab.end(); ++it) {
208  NFlowTableEntry tft = *it;
210  return &(*it);
211  }
212  return NULL;
213 }
214 
216  for(TFTIter it = NFlowTab.begin(); it != NFlowTab.end(); ++it) {
217  NFlowTableEntry tft = *it;
218  if (tft.getCFlow()->getDstAddr() == addr
220  return &(*it);
221  }
222  return NULL;
223 }
224 
226  for(TFTIter it = NFlowTab.begin(); it != NFlowTab.end(); ++it) {
227  NFlowTableEntry tft = *it;
228  if (tft.getCFlow()->getDstApni().getApn() == dstApn
230  return &(*it);
231  }
232  return NULL;
233 }
234 
235 const unsigned int NFlowTable::getSize() const {
236  return NFlowTab.size();
237 }
238 
240  TFAIPtrs list;
241  for(TFTIter it = NFlowTab.begin(); it != NFlowTab.end(); ++it) {
242  NFlowTableEntry tft = *it;
243  if (tft.getCFlow()->getSrcAddr().getApn() == apnip->first.getApn()
244  && tft.getCFlow()->getDstNeighbor().getApn() == apnip->second.getApn()
246  list.push_back(&(*it));
247  }
248  return list;
249 }
void initSignalsAndListeners()
Definition: NFlowTable.cc:202
NFlowTableEntry * findMgmtEntryByDstApni(const APN &dstApn)
Definition: NFlowTable.cc:225
NFlowTableEntry * findEntryByDstAddressAndFwd(const APN &apname)
Definition: NFlowTable.cc:51
Class representing flow object with attributes from specs.
Definition: Flow.h:45
TFAIPtrs findEntriesByDstNeighborAndFwd(const APN &apname)
Definition: NFlowTable.cc:86
unsigned const int getSize() const
Definition: NFlowTable.cc:235
TFAITable NFlowTab
Definition: NFlowTable.h:75
const APNamingInfo & getSrcApni() const
Gets read-only source APNamingInfo.
Definition: Flow.cc:134
NFlowTableEntry::EAllocateStatus getAllocateStatus() const
Application Process Name class.
Definition: APN.h:36
void removeByFlow(Flow *flow)
Definition: NFlowTable.cc:148
const APN & getIpcAddress() const
Getter of IPC Process address which should be unambiguous within DIF.
Definition: Address.cc:83
APNamingInfo first
Definition: APNamingInfo.h:200
void insertNew(Flow *flow)
Definition: NFlowTable.cc:136
FAIBase * getFai() const
long getAllocInvokeId() const
Gets allocation InvokeId Used inside M_CREATE(_R)(flow) messages.
Definition: Flow.cc:277
void insert(const NFlowTableEntry &entry)
Definition: NFlowTable.cc:143
void changeAllocStatus(Flow *flow, NFlowTableEntry::EAllocateStatus status)
Definition: NFlowTable.cc:173
virtual void handleMessage(cMessage *msg)
Definition: NFlowTable.cc:132
void setFai(FAIBase *nfai)
const APN & getApn() const
Getter of APN.
Definition: APNamingInfo.h:142
NFlowTableEntry * findEntryByInvokeId(long invId)
Definition: NFlowTable.cc:97
const Flow * getCFlow() const
Define_Module(NFlowTable)
APNamingInfo second
Definition: APNamingInfo.h:201
const Address & getSrcAddr() const
Gets source Address, which is the address of communication start-point.
Definition: Flow.cc:158
TFAIPtrs findEntriesAffectedByMgmt(const APNIPair *apnip)
Definition: NFlowTable.cc:239
const Address & getDstNeighbor() const
Gets neighbor destination Address, which is the address of (interim) hop-by-hop destination Used duri...
Definition: Flow.cc:340
EAllocateStatus
std::list< NFlowTableEntry * > TFAIPtrs
Definition: NFlowTable.h:33
virtual void initialize()
Definition: NFlowTable.cc:30
NFlowTableEntry * findMgmtEntry(const Flow *flow)
Definition: NFlowTable.cc:206
void setAllocateStatus(NFlowTableEntry::EAllocateStatus allocateStatus)
const char * SIG_STAT_FT_SIZE
Definition: NFlowTable.cc:26
void setPolicyDisplayString(cModule *mod, const char *str)
Definition: Utils.cc:69
std::string info() const
Definition: NFlowTable.cc:38
void setFaiToFlow(FAIBase *fai, Flow *flow)
Definition: NFlowTable.cc:190
NFlowTableEntry * findEntryByApns(const APN &srcApn, const APN &dstApn)
Definition: NFlowTable.cc:75
NFlowTableEntry * findMgmtEntryByDstNeighbor(const Address &addr)
Definition: NFlowTable.cc:122
simsignal_t sigStatFTSize
Definition: NFlowTable.h:72
const APN & getApn() const
Getter of unique APN which is initialized during object construction.
Definition: Address.cc:119
NFlowTableEntry * findEntryBySrcAddressAndFwd(const APN &apname)
Definition: NFlowTable.cc:61
void updateDisplayString()
Definition: NFlowTable.cc:195
const Address & getDstAddr() const
Gets source Address, which is the address of communication end-point.
Definition: Flow.cc:150
bool isManagementFlowLocalToIPCP() const
Definition: Flow.cc:370
TFAITable::iterator TFTIter
Definition: NFlowTable.h:34
Address class holds IPC Process identification.
Definition: Address.h:42
const APNamingInfo & getDstApni() const
Gets read-only destination APNamingInfo.
Definition: Flow.cc:102
NFlowTableEntry * findEntryByFlow(const Flow *flow)
Definition: NFlowTable.cc:155
NFlowTableEntry * findMgmtEntryByDstAddr(const Address &addr)
Definition: NFlowTable.cc:215
NFlowTableEntry * findEntryByFai(FAIBase *fai)
Definition: NFlowTable.cc:164