NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
abstract-fib.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
21 #ifndef LFID_ABS_FIB_H
22 #define LFID_ABS_FIB_H
23 
24 #include <set>
25 #include <unordered_map>
26 
27 #include "ns3/abort.h"
28 #include "ns3/ndnSIM/helper/lfid/fib-nexthop.hpp"
29 #include "ns3/ptr.h"
30 
31 namespace ns3 {
32 namespace ndn {
33 
34 class GlobalRouter;
35 
39 class AbstractFib {
40 public:
41  using AllNodeFib = std::unordered_map<int, AbstractFib>;
42 
47  AbstractFib(const Ptr<GlobalRouter> own, int numNodes);
48 
49 public:
50  // Getters:
54  const std::set<FibNextHop>&
55  getNexthops(int dstId) const;
56 
60  const std::set<FibNextHop>&
61  getUpwardNexthops(int dstId) const;
62 
66  void
67  checkFib() const;
68 
73  int
74  numEnabledNhPerDst(int dstId) const
75  {
76  NS_ABORT_UNLESS(dstId != nodeId);
77  return static_cast<int>(getNexthops(dstId).size());
78  }
79 
80  int
81  getNodeId() const
82  {
83  return nodeId;
84  }
85 
86  Ptr<GlobalRouter>
87  getGR() const;
88 
89  std::string
90  getName() const
91  {
92  return nodeName;
93  }
94 
95  int
96  getDegree() const
97  {
98  return nodeDegree;
99  }
100 
101  int
102  getNumDsts() const
103  {
104  return static_cast<int>(perDstFib.size());
105  }
106 
107  bool
108  contains(int dstId) const
109  {
110  return perDstFib.count(dstId) > 0;
111  }
112 
113  // Functions for range-based loop:
114  auto
115  begin() const
116  {
117  return perDstFib.cbegin();
118  }
119 
120  auto
121  end() const
122  {
123  return perDstFib.cend();
124  }
125 
126  // Setters:
127  void
128  insert(int dstId, const FibNextHop& nh);
129 
130  size_t
131  erase(int dstId, int nhId);
132 
133 private:
134  void
135  checkInputs();
136 
137  void
138  createEmptyFib();
139 
140 private:
141  const int nodeId; // Own node id
142  const std::string nodeName; // Own node name
143  const int numberOfNodes;
144  const int nodeDegree;
145  const Ptr<GlobalRouter> ownRouter;
146 
147  int upwardCounter;
148  int totalNhCounter;
149 
150  // DstId -> set<FibNextHop>
151  std::unordered_map<int, std::set<FibNextHop>> perDstFib;
152  std::unordered_map<int, std::set<FibNextHop>> upwardPerDstFib;
153 
154  friend std::ostream&
155  operator<<(std::ostream&, const AbstractFib& fib);
156 };
157 
158 std::ostream&
159 operator<<(std::ostream& os, const AbstractFib& fib);
160 
161 } // namespace ndn
162 } // namespace ns-3
163 
164 #endif // LFID_ABS_FIB_H
ns3::ndn::operator<<
std::ostream & operator<<(std::ostream &os, const AbstractFib &fib)
Definition: abstract-fib.cpp:175
ns3::ndn::AbstractFib::AllNodeFib
std::unordered_map< int, AbstractFib > AllNodeFib
Definition: abstract-fib.hpp:41
ns3::ndn::AbstractFib::checkFib
void checkFib() const
Make sure that FIB is consistent (each destination has at least one downward nexthop)
Definition: abstract-fib.cpp:149
ns3
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-app-link-service.cpp:32
ns3::ndn::AbstractFib::insert
void insert(int dstId, const FibNextHop &nh)
Definition: abstract-fib.cpp:85
ns3::ndn::AbstractFib::getNexthops
const std::set< FibNextHop > & getNexthops(int dstId) const
Definition: abstract-fib.cpp:130
ns3::ndn::AbstractFib::contains
bool contains(int dstId) const
Definition: abstract-fib.hpp:108
ns3::ndn::AbstractFib
An abstract, lightweight representation of the FIB.
Definition: abstract-fib.hpp:39
ns3::ndn::AbstractFib::AbstractFib
AbstractFib(const Ptr< GlobalRouter > own, int numNodes)
Definition: abstract-fib.cpp:36
ns3::ndn::AbstractFib::getName
std::string getName() const
Definition: abstract-fib.hpp:90
ns3::ndn::AbstractFib::operator<<
friend std::ostream & operator<<(std::ostream &, const AbstractFib &fib)
Definition: abstract-fib.cpp:175
ns3::ndn::AbstractFib::end
auto end() const
Definition: abstract-fib.hpp:121
ns3::ndn::AbstractFib::getGR
Ptr< GlobalRouter > getGR() const
Definition: abstract-fib.cpp:78
ns3::ndn::AbstractFib::getUpwardNexthops
const std::set< FibNextHop > & getUpwardNexthops(int dstId) const
Definition: abstract-fib.cpp:140
ns3::ndn::AbstractFib::getNodeId
int getNodeId() const
Definition: abstract-fib.hpp:81
ns3::ndn::FibNextHop
Definition: fib-nexthop.hpp:36
ns3::ndn::AbstractFib::getNumDsts
int getNumDsts() const
Definition: abstract-fib.hpp:102
ns3::ndn::AbstractFib::getDegree
int getDegree() const
Definition: abstract-fib.hpp:96
ns3::ndn::AbstractFib::begin
auto begin() const
Definition: abstract-fib.hpp:115
ns3::ndn::AbstractFib::erase
size_t erase(int dstId, int nhId)
Definition: abstract-fib.cpp:102
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-strategy-choice-helper.hpp:34
ns3::ndn::AbstractFib::numEnabledNhPerDst
int numEnabledNhPerDst(int dstId) const
Definition: abstract-fib.hpp:74