RINASim  October 2016
Documentation of framework for OMNeT++
SimpleDCForwarding.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 "SimpleDCForwarding.h"
24 #include <sstream>
25 #include "Utils.h"
26 
27 namespace NSPSimpleDC {
28 
29  using namespace std;
30 
31  vector<Port> iSimpleDCForwarding::lookup(const PDU * pdu) {
32 
33  //Search cache
34 
35  string s_addr = pdu->getDstAddr().getIpcAddress().getName();
36  DCAddr n_addr = DCAddr(s_addr);
37 
38  PDU * p = const_cast<PDU*>(pdu);
39  p->setHopCount(p->getHopCount()+1);
40  if(p->getHopCount()> 15) {
41  return vector<Port>();
42  }
43 
44  if(n_addr.type < 0) { return vector<Port >(); }
45 
46  vector<Port> possible = search(n_addr);
47  vector<Port> ret;
48  if(possible.size() > 0) {
49  int k = intuniform(0, possible.size()-1);
50  ret.push_back(possible[k]);
51  }
52 
53 
54  return ret;
55  }
56 
57  vector<Port> iSimpleDCForwarding::lookup(const Address & dst, const std::string & qos) {
58  string s_addr = dst.getIpcAddress().getName();
59  DCAddr n_addr = DCAddr(s_addr);
60 
61  if(n_addr.type < 0) { return vector<Port>(); }
62 
63  vector<Port> possible = search(n_addr);
64  vector<Port> ret;
65  if(possible.size() > 0) {
66  int k = intuniform(0, possible.size()-1);
67  ret.push_back(possible[k]);
68  }
69  return ret;
70  }
71 
72 
73  void iSimpleDCForwarding::setNodeInfo(const string & n_addr) {
74  Im = DCAddr(n_addr);
75  }
76 
77  void iSimpleDCForwarding::setNodeInfo(const int & type, const int & a, const int & b) {
78  Im = DCAddr(type, a, b);
79  }
80 
81 
83  return "";
84  }
85 
88 }
const APN & getIpcAddress() const
Getter of IPC Process address which should be unambiguous within DIF.
Definition: Address.cc:83
virtual void refreshCache(Port oldP, Port newP)
virtual void setHopCount(unsigned int hopCount)
Definition: PDU_m.cc:391
Definition: PDU.h:42
virtual Address & getDstAddr()
Definition: PDU_m.cc:306
void setNodeInfo(const string &n_addr)
virtual unsigned int getHopCount() const
Definition: PDU_m.cc:386
const std::string & getName() const
Gets APN string name representation.
Definition: APN.cc:40
Address class holds IPC Process identification.
Definition: Address.h:42
vector< Port > lookup(const PDU *pdu)