blob: dc3b0699abe8400f6148a6a78771e8b658660387 [file] [log] [blame]
Klaus Schneider38784302019-08-31 18:26:36 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2019 Klaus Schneider, The University of Arizona
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Klaus Schneider <klaus@cs.arizona.edu>
19 */
20
21#include "fib-nexthop.hpp"
22
23#include <boost/functional/hash.hpp>
24#include <ostream>
25
26namespace ns3 {
27namespace ndn {
28
29constexpr int NODE_ID_LIMIT = 1000;
30
31FibNextHop::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
42std::ostream&
43operator<<(std::ostream& os, const NextHopType& type)
44{
45 switch (type) {
46 case NextHopType::DOWNWARD:
47 return os << "DOWNWARD";
48 case NextHopType::UPWARD:
49 return os << "UPWARD";
50 case NextHopType::DISABLED:
51 return os << "DISABLED";
52 }
53 return os << static_cast<int>(type);
54}
55
56std::ostream&
57operator<<(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
65namespace std {
66
67using ns3::ndn::FibNextHop;
68
69template <>
70struct 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}