NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
fib-nexthop.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
21 #include "fib-nexthop.hpp"
22 
23 #include <boost/functional/hash.hpp>
24 #include <ostream>
25 
26 namespace ns3 {
27 namespace ndn {
28 
29 constexpr int NODE_ID_LIMIT = 1000;
30 
31 FibNextHop::FibNextHop(int cost, int nhId, int costDelta, NextHopType type)
32 {
33  NS_ABORT_UNLESS(cost > 0 && cost <= MAX_COST);
34  NS_ABORT_UNLESS(nhId >= 0 && nhId <= NODE_ID_LIMIT);
35 
36  this->m_nhId = nhId;
37  this->m_cost = cost;
38  this->m_type = type;
39  this->m_costDelta = costDelta;
40 }
41 
42 std::ostream&
43 operator<<(std::ostream& os, const NextHopType& type)
44 {
45  switch (type) {
47  return os << "DOWNWARD";
49  return os << "UPWARD";
51  return os << "DISABLED";
52  }
53  return os << static_cast<int>(type);
54 }
55 
56 std::ostream&
57 operator<<(std::ostream& os, const FibNextHop& a)
58 {
59  return os << "Id: " << a.getNexthopId() << ", cost: " << a.m_cost << ", type: " << a.m_type;
60 }
61 
62 } // namespace ndn
63 } // namespace ns-3
64 
65 namespace std {
66 
68 
69 template <>
70 struct hash<FibNextHop> {
71  size_t
72  operator()(const FibNextHop& k) const
73  {
74  // Combine hash via boost library
75  std::size_t seed = 0;
76  boost::hash_combine(seed, k.getNexthopId());
77  boost::hash_combine(seed, k.getCost());
78 
79  return seed;
80  }
81 };
82 
83 }
int getNexthopId() const
Definition: fib-nexthop.hpp:50
Copyright (c) 2011-2015 Regents of the University of California.
FibNextHop(int cost, int nhId, int costDelta=-1, NextHopType type=NextHopType::DISABLED)
Definition: fib-nexthop.cpp:31
span_CONFIG_SIZE_TYPE size_t
Definition: span-lite.hpp:565
STL namespace.
friend std::ostream & operator<<(std::ostream &, const FibNextHop &fib)
Definition: fib-nexthop.cpp:57
size_t operator()(const FibNextHop &k) const
Definition: fib-nexthop.cpp:72
Copyright (c) 2011-2015 Regents of the University of California.
static constexpr int MAX_COST
Definition: fib-nexthop.hpp:38
constexpr int NODE_ID_LIMIT
Definition: fib-nexthop.cpp:29