NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
nfd-constants.cpp
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2013-2020 Regents of the University of California.
4
*
5
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6
*
7
* ndn-cxx library is free software: you can redistribute it and/or modify it under the
8
* terms of the GNU Lesser General Public License as published by the Free Software
9
* Foundation, either version 3 of the License, or (at your option) any later version.
10
*
11
* ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14
*
15
* You should have received copies of the GNU General Public License and GNU Lesser
16
* General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17
* <http://www.gnu.org/licenses/>.
18
*
19
* See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20
*/
21
22
#include "
ndn-cxx/encoding/nfd-constants.hpp
"
23
#include "
ndn-cxx/util/ostream-joiner.hpp
"
24
#include "
ndn-cxx/util/string-helper.hpp
"
25
26
#include <boost/algorithm/string/predicate.hpp>
27
#include <boost/lexical_cast.hpp>
28
#include <istream>
29
#include <map>
30
#include <ostream>
31
32
namespace
ndn
{
33
namespace
nfd
{
34
35
std::ostream&
36
operator<<
(std::ostream& os,
FaceScope
faceScope)
37
{
38
switch
(faceScope) {
39
case
FACE_SCOPE_NONE
:
40
return
os <<
"none"
;
41
case
FACE_SCOPE_NON_LOCAL
:
42
return
os <<
"non-local"
;
43
case
FACE_SCOPE_LOCAL
:
44
return
os <<
"local"
;
45
}
46
return
os << static_cast<unsigned>(faceScope);
47
}
48
49
std::ostream&
50
operator<<
(std::ostream& os,
FacePersistency
facePersistency)
51
{
52
switch
(facePersistency) {
53
case
FACE_PERSISTENCY_NONE
:
54
return
os <<
"none"
;
55
case
FACE_PERSISTENCY_PERSISTENT
:
56
return
os <<
"persistent"
;
57
case
FACE_PERSISTENCY_ON_DEMAND
:
58
return
os <<
"on-demand"
;
59
case
FACE_PERSISTENCY_PERMANENT
:
60
return
os <<
"permanent"
;
61
}
62
return
os << static_cast<unsigned>(facePersistency);
63
}
64
65
std::ostream&
66
operator<<
(std::ostream& os,
LinkType
linkType)
67
{
68
switch
(linkType) {
69
case
LINK_TYPE_NONE
:
70
return
os <<
"none"
;
71
case
LINK_TYPE_POINT_TO_POINT
:
72
return
os <<
"point-to-point"
;
73
case
LINK_TYPE_MULTI_ACCESS
:
74
return
os <<
"multi-access"
;
75
case
LINK_TYPE_AD_HOC
:
76
return
os <<
"adhoc"
;
77
}
78
return
os << static_cast<unsigned>(linkType);
79
}
80
81
std::ostream&
82
operator<<
(std::ostream& os,
FaceEventKind
faceEventKind)
83
{
84
switch
(faceEventKind) {
85
case
FACE_EVENT_NONE
:
86
return
os <<
"none"
;
87
case
FACE_EVENT_CREATED
:
88
return
os <<
"created"
;
89
case
FACE_EVENT_DESTROYED
:
90
return
os <<
"destroyed"
;
91
case
FACE_EVENT_UP
:
92
return
os <<
"up"
;
93
case
FACE_EVENT_DOWN
:
94
return
os <<
"down"
;
95
}
96
return
os << static_cast<unsigned>(faceEventKind);
97
}
98
99
std::istream&
100
operator>>
(std::istream& is,
RouteOrigin
& routeOrigin)
101
{
102
using
boost::algorithm::iequals;
103
104
std::string s;
105
is >> s;
106
107
if
(iequals(s,
"none"
))
108
routeOrigin =
ROUTE_ORIGIN_NONE
;
109
else
if
(iequals(s,
"app"
))
110
routeOrigin =
ROUTE_ORIGIN_APP
;
111
else
if
(iequals(s,
"autoreg"
))
112
routeOrigin =
ROUTE_ORIGIN_AUTOREG
;
113
else
if
(iequals(s,
"client"
))
114
routeOrigin =
ROUTE_ORIGIN_CLIENT
;
115
else
if
(iequals(s,
"autoconf"
))
116
routeOrigin =
ROUTE_ORIGIN_AUTOCONF
;
117
else
if
(iequals(s,
"nlsr"
))
118
routeOrigin =
ROUTE_ORIGIN_NLSR
;
119
else
if
(iequals(s,
"prefixann"
))
120
routeOrigin =
ROUTE_ORIGIN_PREFIXANN
;
121
else
if
(iequals(s,
"static"
))
122
routeOrigin =
ROUTE_ORIGIN_STATIC
;
123
else
{
124
// To reject negative numbers, we parse as a wider signed type, and compare with the range.
125
static_assert(std::numeric_limits<std::underlying_type_t<RouteOrigin>>::max() <=
126
std::numeric_limits<int>::max(),
""
);
127
128
int
v = -1;
129
try
{
130
v = boost::lexical_cast<
int
>(s);
131
}
132
catch
(
const
boost::bad_lexical_cast&) {
133
}
134
135
if
(v >= std::numeric_limits<std::underlying_type_t<RouteOrigin>>::min() &&
136
v <= std::numeric_limits<std::underlying_type_t<RouteOrigin>>::max()) {
137
routeOrigin =
static_cast<
RouteOrigin
>
(v);
138
}
139
else
{
140
routeOrigin =
ROUTE_ORIGIN_NONE
;
141
is.setstate(std::ios::failbit);
142
}
143
}
144
145
return
is;
146
}
147
148
std::ostream&
149
operator<<
(std::ostream& os,
RouteOrigin
routeOrigin)
150
{
151
switch
(routeOrigin) {
152
case
ROUTE_ORIGIN_NONE
:
153
return
os <<
"none"
;
154
case
ROUTE_ORIGIN_APP
:
155
return
os <<
"app"
;
156
case
ROUTE_ORIGIN_AUTOREG
:
157
return
os <<
"autoreg"
;
158
case
ROUTE_ORIGIN_CLIENT
:
159
return
os <<
"client"
;
160
case
ROUTE_ORIGIN_AUTOCONF
:
161
return
os <<
"autoconf"
;
162
case
ROUTE_ORIGIN_NLSR
:
163
return
os <<
"nlsr"
;
164
case
ROUTE_ORIGIN_PREFIXANN
:
165
return
os <<
"prefixann"
;
166
case
ROUTE_ORIGIN_STATIC
:
167
return
os <<
"static"
;
168
}
169
return
os << static_cast<unsigned>(routeOrigin);
170
}
171
172
std::ostream&
173
operator<<
(std::ostream& os,
RouteFlags
routeFlags)
174
{
175
if
(routeFlags ==
ROUTE_FLAGS_NONE
) {
176
return
os <<
"none"
;
177
}
178
179
static
const
std::map<RouteFlags, std::string> knownBits = {
180
{
ROUTE_FLAG_CHILD_INHERIT
,
"child-inherit"
},
181
{
ROUTE_FLAG_CAPTURE
,
"capture"
}
182
};
183
184
auto
join =
make_ostream_joiner
(os,
'|'
);
185
for
(
const
auto
& pair : knownBits) {
186
RouteFlags
bit =
ROUTE_FLAGS_NONE
;
187
std::string token;
188
std::tie(bit, token) = pair;
189
190
if
((routeFlags & bit) != 0) {
191
join = token;
192
routeFlags =
static_cast<
RouteFlags
>
(routeFlags & ~bit);
193
}
194
}
195
196
if
(routeFlags !=
ROUTE_FLAGS_NONE
) {
197
join =
AsHex
{routeFlags};
198
}
199
200
return
os;
201
}
202
203
}
// namespace nfd
204
}
// namespace ndn
ndn::nfd::ROUTE_FLAG_CHILD_INHERIT
Definition:
nfd-constants.hpp:125
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
ndn::nfd::operator>>
std::istream & operator>>(std::istream &is, RouteOrigin &routeOrigin)
extract RouteOrigin from stream
Definition:
nfd-constants.cpp:100
ndn::nfd::LinkType
LinkType
Definition:
nfd-constants.hpp:57
ndn::nfd::FACE_PERSISTENCY_PERMANENT
face is permanent
Definition:
nfd-constants.hpp:49
ndn::nfd::ROUTE_ORIGIN_NLSR
Definition:
nfd-constants.hpp:105
ndn::nfd::LINK_TYPE_NONE
Definition:
nfd-constants.hpp:58
ndn::nfd::FACE_SCOPE_NON_LOCAL
face is non-local
Definition:
nfd-constants.hpp:36
ndn::nfd::LINK_TYPE_AD_HOC
link is ad hoc
Definition:
nfd-constants.hpp:61
ndn::nfd::ROUTE_ORIGIN_APP
Definition:
nfd-constants.hpp:101
ndn::nfd::LINK_TYPE_POINT_TO_POINT
link is point-to-point
Definition:
nfd-constants.hpp:59
ndn::nfd::ROUTE_ORIGIN_STATIC
Definition:
nfd-constants.hpp:107
string-helper.hpp
ndn::nfd::FACE_EVENT_DESTROYED
face was destroyed
Definition:
nfd-constants.hpp:80
ndn::AsHex
Helper class to convert a number to hexadecimal format, for use with stream insertion operators...
Definition:
string-helper.hpp:98
ndn::nfd::LINK_TYPE_MULTI_ACCESS
link is multi-access
Definition:
nfd-constants.hpp:60
ndn::nfd::ROUTE_FLAGS_NONE
Definition:
nfd-constants.hpp:124
nfd-constants.hpp
ndn::nfd::ROUTE_ORIGIN_AUTOREG
Definition:
nfd-constants.hpp:102
ndn::nfd::FacePersistency
FacePersistency
Definition:
nfd-constants.hpp:45
ndn::nfd::FaceScope
FaceScope
Definition:
nfd-constants.hpp:34
ndn::nfd::FACE_PERSISTENCY_NONE
Definition:
nfd-constants.hpp:46
nfd
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-common.hpp:39
ostream-joiner.hpp
Backport of ostream_joiner from the Library Fundamentals v2 TS.
ndn::nfd::ROUTE_FLAG_CAPTURE
Definition:
nfd-constants.hpp:126
ndn::nfd::FACE_SCOPE_NONE
Definition:
nfd-constants.hpp:35
ndn::nfd::FACE_EVENT_UP
face went UP (from DOWN state)
Definition:
nfd-constants.hpp:81
ndn::nfd::ROUTE_ORIGIN_CLIENT
Definition:
nfd-constants.hpp:103
ndn::nfd::FaceEventKind
FaceEventKind
Definition:
nfd-constants.hpp:77
ndn::make_ostream_joiner
ostream_joiner< std::decay_t< DelimT >, CharT, Traits > make_ostream_joiner(std::basic_ostream< CharT, Traits > &os, DelimT &&delimiter)
Definition:
ostream-joiner.hpp:117
ndn::nfd::operator<<
std::ostream & operator<<(std::ostream &os, FaceScope faceScope)
Definition:
nfd-constants.cpp:36
ndn::nfd::FACE_EVENT_NONE
Definition:
nfd-constants.hpp:78
ndn::nfd::FACE_PERSISTENCY_ON_DEMAND
face is on-demand
Definition:
nfd-constants.hpp:48
ndn::nfd::FACE_SCOPE_LOCAL
face is local
Definition:
nfd-constants.hpp:37
ndn::nfd::ROUTE_ORIGIN_AUTOCONF
Definition:
nfd-constants.hpp:104
ndn::nfd::FACE_EVENT_CREATED
face was created
Definition:
nfd-constants.hpp:79
ndn::nfd::RouteOrigin
RouteOrigin
Definition:
nfd-constants.hpp:99
ndn::nfd::RouteFlags
RouteFlags
Definition:
nfd-constants.hpp:123
ndn::nfd::ROUTE_ORIGIN_PREFIXANN
Definition:
nfd-constants.hpp:106
ndn::nfd::ROUTE_ORIGIN_NONE
Definition:
nfd-constants.hpp:100
ndn::nfd::FACE_PERSISTENCY_PERSISTENT
face is persistent
Definition:
nfd-constants.hpp:47
ndn::nfd::FACE_EVENT_DOWN
face went DOWN (from UP state)
Definition:
nfd-constants.hpp:82
ndnSIM
ndn-cxx
ndn-cxx
encoding
nfd-constants.cpp
Generated on Fri May 6 2022 12:34:12 for ndnSIM by
1.8.13