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
Copyright (c) 2011-2015 Regents of the University of California.
const std::set< FibNextHop > & getUpwardNexthops(int dstId) const
size_t erase(int dstId, int nhId)
An abstract, lightweight representation of the FIB.
std::unordered_map< int, AbstractFib > AllNodeFib
Copyright (c) 2011-2015 Regents of the University of California.
const std::set< FibNextHop > & getNexthops(int dstId) const
void insert(int dstId, const FibNextHop &nh)
void checkFib() const
Make sure that FIB is consistent (each destination has at least one downward nexthop) ...
friend std::ostream & operator<<(std::ostream &, const AbstractFib &fib)
AbstractFib(const Ptr< GlobalRouter > own, int numNodes)
int numEnabledNhPerDst(int dstId) const
bool contains(int dstId) const
std::string getName() const
Ptr< GlobalRouter > getGR() const