25 #include "ns3/names.h" 26 #include "ns3/ndnSIM/NFD/daemon/fw/forwarder.hpp" 27 #include "ns3/ndnSIM/model/ndn-global-router.hpp" 28 #include "ns3/ndnSIM/model/ndn-l3-protocol.hpp" 37 : nodeId{
static_cast<int>(own->GetObject<
ns3::Node>()->GetId())}
38 , nodeName{ns3::Names::FindName(own->GetObject<
ns3::Node>())}
39 , numberOfNodes{numNodes}
40 , nodeDegree{
static_cast<int>(own->GetIncidencies().size())}
51 AbstractFib::checkInputs()
53 if (nodeDegree <= 0) {
54 std::cerr << nodeName <<
" has a degree of " << nodeDegree <<
"!\n\n";
57 const auto MAX_SIZE{1e5};
58 NS_ABORT_UNLESS(nodeId >= 0 && nodeId <= MAX_SIZE);
59 NS_ABORT_UNLESS(nodeName.size() > 0 && nodeName.size() <= MAX_SIZE);
60 NS_ABORT_UNLESS(nodeDegree >= 0 && nodeDegree <= MAX_SIZE);
61 NS_ABORT_UNLESS(numberOfNodes > 1 && numberOfNodes <= MAX_SIZE);
65 AbstractFib::createEmptyFib()
68 for (
int dstId = 0; dstId < numberOfNodes; dstId++) {
69 if (dstId == nodeId) {
72 perDstFib.insert({dstId, {}});
73 upwardPerDstFib.insert({dstId, {}});
90 bool inserted1 = perDstFib.at(dstId).insert(nh).second;
91 BOOST_VERIFY(inserted1);
95 bool inserted2 = upwardPerDstFib.at(dstId).insert(nh).second;
96 BOOST_VERIFY(inserted2);
104 auto& fib{perDstFib.at(dstId)};
106 auto fibNh = std::find_if(fib.begin(), fib.end(),
107 [&](
const FibNextHop& item) {
return item.getNexthopId() == nhId; });
110 if (fibNh == fib.end()) {
116 NS_ABORT_UNLESS(fibNh != perDstFib.at(dstId).end());
121 auto numErased2 = upwardPerDstFib.at(dstId).erase(*fibNh);
122 NS_ABORT_UNLESS(numErased2 == 1);
129 const set<FibNextHop>&
132 NS_ABORT_MSG_IF(dstId == nodeId,
"Requested destination id is the same as current nodeId!");
133 NS_ABORT_MSG_IF(perDstFib.count(dstId) == 0,
134 "Node " << nodeId <<
" No nexthops for dst: " << dstId <<
"!");
135 NS_ABORT_UNLESS(perDstFib.count(dstId) != 0);
136 return perDstFib.at(dstId);
139 const set<FibNextHop>&
142 NS_ABORT_MSG_IF(dstId == nodeId,
"Requested destination id is the same as current nodeId!");
143 NS_ABORT_MSG_IF(perDstFib.count(dstId) == 0,
144 "Node " << nodeId <<
" No nexthops for dst: " << dstId <<
"!");
145 return upwardPerDstFib.at(dstId);
151 BOOST_VERIFY(perDstFib.size() > 0);
153 for (
const auto& fibSet : perDstFib) {
154 const size_t numNhs = fibSet.second.size();
156 bool hasDownward{
false};
157 std::unordered_set<int> nextHopSet{};
159 for (
const FibNextHop& nextHop : fibSet.second) {
166 BOOST_VERIFY(nextHopSet.count(nextHop.
getNexthopId()) == 0);
169 BOOST_VERIFY(hasDownward || numNhs == 0);
170 BOOST_VERIFY(nextHopSet.size() == fibSet.second.size());
177 for (
const auto& entry : fib.perDstFib) {
178 os <<
"\nFIB node: " << fib.nodeName << fib.nodeId <<
"\n";
179 os <<
"Dst: " << entry.first <<
"\n";
180 for (
const auto& nh : entry.second) {
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.
NextHopType getType() const
Copyright (c) 2011-2015 Regents of the University of California.
static constexpr int MAX_COST
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)
Ptr< GlobalRouter > getGR() const