NLSR: Named Data Link State Routing Protocol 24.08-16-gfc0b45a5 documentation
Loading...
Searching...
No Matches
routing-table-entry.cpp
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2014-2022, The University of Memphis,
4
* Regents of the University of California
5
*
6
* This file is part of NLSR (Named-data Link State Routing).
7
* See AUTHORS.md for complete list of NLSR authors and contributors.
8
*
9
* NLSR is free software: you can redistribute it and/or modify it under the terms
10
* of the GNU General Public License as published by the Free Software Foundation,
11
* either version 3 of the License, or (at your option) any later version.
12
*
13
* NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
* PURPOSE. See the GNU General Public License for more details.
16
*
17
* You should have received a copy of the GNU General Public License along with
18
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
19
*/
20
21
#include "
routing-table-entry.hpp
"
22
#include "
nexthop-list.hpp
"
23
#include "
tlv-nlsr.hpp
"
24
25
namespace
nlsr
{
26
27
template
<ndn::encoding::Tag TAG>
28
size_t
29
RoutingTableEntry::wireEncode
(ndn::EncodingImpl<TAG>& block)
const
30
{
31
size_t
totalLength = 0;
32
33
for
(
auto
it =
m_nexthopList
.
rbegin
(); it !=
m_nexthopList
.
rend
(); ++it) {
34
totalLength += it->wireEncode(block);
35
}
36
37
totalLength +=
m_destination
.wireEncode(block);
38
39
totalLength += block.prependVarNumber(totalLength);
40
totalLength += block.prependVarNumber(
nlsr::tlv::RoutingTableEntry
);
41
42
return
totalLength;
43
}
44
45
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS
(
RoutingTableEntry
);
46
47
const
ndn::Block&
48
RoutingTableEntry::wireEncode
()
const
49
{
50
if
(
m_wire
.hasWire()) {
51
return
m_wire
;
52
}
53
54
ndn::EncodingEstimator estimator;
55
size_t
estimatedSize =
wireEncode
(estimator);
56
57
ndn::EncodingBuffer buffer(estimatedSize, 0);
58
wireEncode
(buffer);
59
60
m_wire
= buffer.block();
61
62
return
m_wire
;
63
}
64
65
void
66
RoutingTableEntry::wireDecode
(
const
ndn::Block& wire)
67
{
68
m_nexthopList
.
clear
();
69
70
m_wire
= wire;
71
72
if
(
m_wire
.type() !=
nlsr::tlv::RoutingTableEntry
) {
73
NDN_THROW(
Error
(
"RoutingTableEntry"
,
m_wire
.type()));
74
}
75
76
m_wire
.parse();
77
auto
val =
m_wire
.elements_begin();
78
79
if
(val !=
m_wire
.elements_end() && val->type() == ndn::tlv::Name) {
80
m_destination
.wireDecode(*val);
81
++val;
82
}
83
else
{
84
NDN_THROW(
Error
(
"Missing required Name field"
));
85
}
86
87
for
(; val !=
m_wire
.elements_end(); ++val) {
88
if
(val->type() ==
nlsr::tlv::NextHop
) {
89
m_nexthopList
.
addNextHop
(
NextHop
(*val));
90
}
91
else
{
92
NDN_THROW(
Error
(
"NextHop"
, val->type()));
93
}
94
}
95
}
96
97
std::ostream&
98
operator<<
(std::ostream& os,
const
RoutingTableEntry
& rte)
99
{
100
return
os <<
" Destination: "
<< rte.
getDestination
() <<
"\n"
101
<< rte.
getNexthopList
() <<
"\n"
;
102
}
103
104
}
// namespace nlsr
nlsr::NextHop
Data abstraction for Nexthop.
Definition
nexthop.hpp:47
nlsr::NexthopListT::rbegin
reverse_iterator rbegin() const
Definition
nexthop-list.hpp:134
nlsr::NexthopListT::addNextHop
void addNextHop(const NextHop &nh)
Adds a next hop to the list.
Definition
nexthop-list.hpp:57
nlsr::NexthopListT::rend
reverse_iterator rend() const
Definition
nexthop-list.hpp:140
nlsr::NexthopListT::clear
void clear()
Definition
nexthop-list.hpp:93
nlsr::RoutingTableEntry
Data abstraction for RouteTableInfo.
Definition
routing-table-entry.hpp:42
nlsr::RoutingTableEntry::wireDecode
void wireDecode(const ndn::Block &wire)
Definition
routing-table-entry.cpp:66
nlsr::RoutingTableEntry::Error
ndn::tlv::Error Error
Definition
routing-table-entry.hpp:44
nlsr::RoutingTableEntry::getNexthopList
NexthopList & getNexthopList()
Definition
routing-table-entry.hpp:65
nlsr::RoutingTableEntry::getDestination
const ndn::Name & getDestination() const
Definition
routing-table-entry.hpp:59
nlsr::RoutingTableEntry::m_destination
ndn::Name m_destination
Definition
routing-table-entry.hpp:94
nlsr::RoutingTableEntry::m_wire
ndn::Block m_wire
Definition
routing-table-entry.hpp:97
nlsr::RoutingTableEntry::wireEncode
const ndn::Block & wireEncode() const
Definition
routing-table-entry.cpp:48
nlsr::RoutingTableEntry::m_nexthopList
NexthopList m_nexthopList
Definition
routing-table-entry.hpp:95
nlsr::tlv::NextHop
@ NextHop
Definition
tlv-nlsr.hpp:46
nlsr::tlv::RoutingTableEntry
@ RoutingTableEntry
Definition
tlv-nlsr.hpp:48
nlsr
Copyright (c) 2014-2020, The University of Memphis, Regents of the University of California.
Definition
adjacency-list.cpp:27
nlsr::operator<<
std::ostream & operator<<(std::ostream &os, const Adjacent &adjacent)
Definition
adjacent.cpp:176
nlsr::NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(Adjacent)
nexthop-list.hpp
routing-table-entry.hpp
tlv-nlsr.hpp
src
route
routing-table-entry.cpp
Generated by
1.9.8