NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
fib-nexthop.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
21 #ifndef LFID_FIB_NH_H
22 #define LFID_FIB_NH_H
23 
24 #include <iosfwd>
25 #include <unordered_set>
26 
27 #include "ns3/abort.h"
28 
29 namespace ns3 {
30 namespace ndn {
31 
32 enum class NextHopType { DOWNWARD,
33  UPWARD,
34  DISABLED };
35 
36 class FibNextHop {
37 public:
38  static constexpr int MAX_COST = 1 * 1000 * 1000;
39 
46  FibNextHop(int cost, int nhId, int costDelta = -1, NextHopType type = NextHopType::DISABLED);
47 
48  // Getters
49  int
50  getNexthopId() const
51  {
52  return m_nhId;
53  }
54 
55  int
56  getCost() const
57  {
58  return m_cost;
59  }
60 
61  int
62  getCostDelta() const
63  {
64  return m_costDelta;
65  }
66 
68  getType() const
69  {
70  return m_type;
71  }
72 
73  // Setters:
74  void
75  setType(const NextHopType& newType)
76  {
77  NS_ABORT_UNLESS(newType != NextHopType::DISABLED);
78  this->m_type = newType;
79  }
80 
81  // Only used in old fillFib:
82  void
83  setCost(int newCost, int newCostDelta)
84  {
85  NS_ABORT_UNLESS(newCost > 0);
86  NS_ABORT_UNLESS(newCostDelta >= 0);
87  this->m_cost = newCost;
88  this->m_costDelta = newCostDelta;
89  }
90 
91 private:
92  // Order of FibNexthop:
93  friend bool
94  operator<(const FibNextHop& own, const FibNextHop& other)
95  {
96  NS_ABORT_UNLESS(own.m_nhId != -1);
97 
98  return std::tie(own.m_costDelta, own.m_cost, own.m_nhId)
99  < std::tie(other.m_costDelta, other.m_cost, other.m_nhId);
100  }
101 
102  friend bool
103  operator==(const FibNextHop& own, const FibNextHop& other)
104  {
105  if (other.m_nhId == own.m_nhId) {
106  // Check that there are no FibNextHop with identical id, but different cost.
107  NS_ABORT_UNLESS(other.m_cost == own.m_cost);
108  NS_ABORT_UNLESS(other.m_costDelta == own.m_costDelta);
109  return true;
110  }
111  else {
112  return false;
113  }
114  }
115 
116  friend bool
117  operator!=(const FibNextHop& own, const FibNextHop& other)
118  {
119  return !(own == other);
120  }
121 
122  friend std::ostream&
123  operator<<(std::ostream&, const FibNextHop& fib);
124 
125 private:
126  int m_cost;
127  int m_nhId;
128  NextHopType m_type;
129  int m_costDelta;
130 };
131 
132 std::ostream&
133 operator<<(std::ostream& os, const NextHopType& type);
134 std::ostream&
135 operator<<(std::ostream& os, const FibNextHop& a);
136 
137 } // namespace ndn
138 } // namespace ns-3
139 
140 namespace std {
141 template <>
142 struct hash<ns3::ndn::FibNextHop>;
143 }
144 
145 #endif // LFID_FIB_NH_H
int getNexthopId() const
Definition: fib-nexthop.hpp:50
Copyright (c) 2011-2015 Regents of the University of California.
friend bool operator!=(const FibNextHop &own, const FibNextHop &other)
void setCost(int newCost, int newCostDelta)
Definition: fib-nexthop.hpp:83
STL namespace.
std::ostream & operator<<(std::ostream &os, const AbstractFib &fib)
void setType(const NextHopType &newType)
Definition: fib-nexthop.hpp:75
NextHopType getType() const
Definition: fib-nexthop.hpp:68
Copyright (c) 2011-2015 Regents of the University of California.
int getCostDelta() const
Definition: fib-nexthop.hpp:62
friend bool operator==(const FibNextHop &own, const FibNextHop &other)
bool operator<(const ReadvertisedRoute &lhs, const ReadvertisedRoute &rhs)