RINASim  October 2016
Documentation of framework for OMNeT++
PrefixMatch.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 "PrefixMatch.h"
24 #include "Utils.h"
25 
27 
29 {
30  any = par("any").stdstringValue();
31  std::string del = par("delimiter").stdstringValue();
32  if(del.length() > 0 && del.at(0)!= ' '){
33  delimiter = del.at(0);
34  } else {
35  delimiter = '.';
36  }
37 
39 }
40 
41 bool PrefixMatch::matchesThisIPC(const Address& addr, PDU * pdu)
42 {
43  if(addr == thisIPCAddr){
44  return true;
45  }
46 
47  std::vector<std::string> addrParsed = split(addr.getIpcAddress().getName(), delimiter);
48 
49  std::vector<std::string>::iterator itS = addrParsed.begin();
50  std::vector<std::string>::iterator itM = thisIPCAddrParsed.begin();
51 
52  while(itS != addrParsed.end() && itM != thisIPCAddrParsed.end()){
53  if(*itS == any){
54  return true;
55  } else if(*itS != *itM){
56  return false;
57  }
58  itS++;
59  itM++;
60  }
61 
62  return (itS == addrParsed.end() && itM == thisIPCAddrParsed.end());
63 }
std::vector< std::string > thisIPCAddrParsed
Definition: PrefixMatch.h:37
char delimiter
Definition: PrefixMatch.h:39
const APN & getIpcAddress() const
Getter of IPC Process address which should be unambiguous within DIF.
Definition: Address.cc:83
std::vector< std::string > & split(const std::string &s, char delim, std::vector< std::string > &elems)
Definition: Utils.cc:33
virtual bool matchesThisIPC(const Address &addr, PDU *pdu)
Definition: PrefixMatch.cc:41
Definition: PDU.h:42
Define_Module(PrefixMatch)
virtual void onPolicyInit()
Definition: PrefixMatch.cc:28
std::string any
Definition: PrefixMatch.h:38
const std::string & getName() const
Gets APN string name representation.
Definition: APN.cc:40
Address class holds IPC Process identification.
Definition: Address.h:42