NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
nfd-constants.cpp
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22
#include "
nfd-constants.hpp
"
23
#include "
util/string-helper.hpp
"
24
25
#include <boost/algorithm/string.hpp>
26
#include <boost/lexical_cast.hpp>
27
#include <istream>
28
#include <map>
29
#include <ostream>
30
31
namespace
ndn
{
32
namespace
nfd
{
33
34
std::ostream&
35
operator<<
(std::ostream& os,
FaceScope
faceScope)
36
{
37
switch
(faceScope) {
38
case
FACE_SCOPE_NONE
:
39
return
os <<
"none"
;
40
case
FACE_SCOPE_NON_LOCAL
:
41
return
os <<
"non-local"
;
42
case
FACE_SCOPE_LOCAL
:
43
return
os <<
"local"
;
44
}
45
return
os << static_cast<unsigned>(faceScope);
46
}
47
48
std::ostream&
49
operator<<
(std::ostream& os,
FacePersistency
facePersistency)
50
{
51
switch
(facePersistency) {
52
case
FACE_PERSISTENCY_NONE
:
53
return
os <<
"none"
;
54
case
FACE_PERSISTENCY_PERSISTENT
:
55
return
os <<
"persistent"
;
56
case
FACE_PERSISTENCY_ON_DEMAND
:
57
return
os <<
"on-demand"
;
58
case
FACE_PERSISTENCY_PERMANENT
:
59
return
os <<
"permanent"
;
60
}
61
return
os << static_cast<unsigned>(facePersistency);
62
}
63
64
std::ostream&
65
operator<<
(std::ostream& os,
LinkType
linkType)
66
{
67
switch
(linkType) {
68
case
LINK_TYPE_NONE
:
69
return
os <<
"none"
;
70
case
LINK_TYPE_POINT_TO_POINT
:
71
return
os <<
"point-to-point"
;
72
case
LINK_TYPE_MULTI_ACCESS
:
73
return
os <<
"multi-access"
;
74
case
LINK_TYPE_AD_HOC
:
75
return
os <<
"adhoc"
;
76
}
77
return
os << static_cast<unsigned>(linkType);
78
}
79
80
std::ostream&
81
operator<<
(std::ostream& os,
FaceEventKind
faceEventKind)
82
{
83
switch
(faceEventKind) {
84
case
FACE_EVENT_NONE
:
85
return
os <<
"none"
;
86
case
FACE_EVENT_CREATED
:
87
return
os <<
"created"
;
88
case
FACE_EVENT_DESTROYED
:
89
return
os <<
"destroyed"
;
90
case
FACE_EVENT_UP
:
91
return
os <<
"up"
;
92
case
FACE_EVENT_DOWN
:
93
return
os <<
"down"
;
94
}
95
return
os << static_cast<unsigned>(faceEventKind);
96
}
97
98
std::istream&
99
operator>>
(std::istream& is,
RouteOrigin
& routeOrigin)
100
{
101
using
boost::algorithm::iequals;
102
103
std::string s;
104
is >> s;
105
106
if
(iequals(s,
"none"
))
107
routeOrigin =
ROUTE_ORIGIN_NONE
;
108
else
if
(iequals(s,
"app"
))
109
routeOrigin =
ROUTE_ORIGIN_APP
;
110
else
if
(iequals(s,
"autoreg"
))
111
routeOrigin =
ROUTE_ORIGIN_AUTOREG
;
112
else
if
(iequals(s,
"client"
))
113
routeOrigin =
ROUTE_ORIGIN_CLIENT
;
114
else
if
(iequals(s,
"autoconf"
))
115
routeOrigin =
ROUTE_ORIGIN_AUTOCONF
;
116
else
if
(iequals(s,
"nlsr"
))
117
routeOrigin =
ROUTE_ORIGIN_NLSR
;
118
else
if
(iequals(s,
"static"
))
119
routeOrigin =
ROUTE_ORIGIN_STATIC
;
120
else
{
121
// To reject negative numbers, we parse as a wider signed type, and compare with the range.
122
static_assert(std::numeric_limits<std::underlying_type<RouteOrigin>::type>::max() <=
123
std::numeric_limits<int>::max(),
""
);
124
125
int
v = -1;
126
try
{
127
v = boost::lexical_cast<
int
>(s);
128
}
129
catch
(
const
boost::bad_lexical_cast&) {
130
}
131
132
if
(v >= std::numeric_limits<std::underlying_type<RouteOrigin>::type>::min() &&
133
v <= std::numeric_limits<std::underlying_type<RouteOrigin>::type>::max()) {
134
routeOrigin =
static_cast<
RouteOrigin
>
(v);
135
}
136
else
{
137
routeOrigin =
ROUTE_ORIGIN_NONE
;
138
is.setstate(std::ios::failbit);
139
}
140
}
141
142
return
is;
143
}
144
145
std::ostream&
146
operator<<
(std::ostream& os,
RouteOrigin
routeOrigin)
147
{
148
switch
(routeOrigin) {
149
case
ROUTE_ORIGIN_NONE
:
150
return
os <<
"none"
;
151
case
ROUTE_ORIGIN_APP
:
152
return
os <<
"app"
;
153
case
ROUTE_ORIGIN_AUTOREG
:
154
return
os <<
"autoreg"
;
155
case
ROUTE_ORIGIN_CLIENT
:
156
return
os <<
"client"
;
157
case
ROUTE_ORIGIN_AUTOCONF
:
158
return
os <<
"autoconf"
;
159
case
ROUTE_ORIGIN_NLSR
:
160
return
os <<
"nlsr"
;
161
case
ROUTE_ORIGIN_STATIC
:
162
return
os <<
"static"
;
163
}
164
return
os << static_cast<unsigned>(routeOrigin);
165
}
166
167
std::ostream&
168
operator<<
(std::ostream& os,
RouteFlags
routeFlags)
169
{
170
if
(routeFlags ==
ROUTE_FLAGS_NONE
) {
171
return
os <<
"none"
;
172
}
173
174
static
const
std::map<RouteFlags, std::string> knownBits = {
175
{
ROUTE_FLAG_CHILD_INHERIT
,
"child-inherit"
},
176
{
ROUTE_FLAG_CAPTURE
,
"capture"
}
177
};
178
179
auto
join =
make_ostream_joiner
(os,
'|'
);
180
for
(
const
auto
& pair : knownBits) {
181
RouteFlags
bit =
ROUTE_FLAGS_NONE
;
182
std::string token;
183
std::tie(bit, token) = pair;
184
185
if
((routeFlags & bit) != 0) {
186
join = token;
187
routeFlags =
static_cast<
RouteFlags
>
(routeFlags & ~bit);
188
}
189
}
190
191
if
(routeFlags !=
ROUTE_FLAGS_NONE
) {
192
join =
AsHex
{routeFlags};
193
}
194
195
return
os;
196
}
197
198
}
// namespace nfd
199
}
// namespace ndn
ndn::nfd::ROUTE_FLAG_CHILD_INHERIT
Definition:
nfd-constants.hpp:114
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:99
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:95
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:91
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:96
string-helper.hpp
ndn::nfd::FACE_EVENT_DESTROYED
face was destroyed
Definition:
nfd-constants.hpp:79
ndn::AsHex
Helper class to convert a number to hexadecimal format, for use with stream insertion operators...
Definition:
string-helper.hpp:52
ndn::nfd::LINK_TYPE_MULTI_ACCESS
link is multi-access
Definition:
nfd-constants.hpp:60
ndn::nfd::ROUTE_FLAGS_NONE
Definition:
nfd-constants.hpp:113
nfd-constants.hpp
ndn::make_ostream_joiner
ostream_joiner< typename std::decay< DelimT >::type, CharT, Traits > make_ostream_joiner(std::basic_ostream< CharT, Traits > &os, DelimT &&delimiter)
Definition:
backports-ostream-joiner.hpp:117
ndn::nfd::ROUTE_ORIGIN_AUTOREG
Definition:
nfd-constants.hpp:92
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:40
ndn::nfd::ROUTE_FLAG_CAPTURE
Definition:
nfd-constants.hpp:115
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:80
ndn::nfd::ROUTE_ORIGIN_CLIENT
Definition:
nfd-constants.hpp:93
ndn::nfd::FaceEventKind
FaceEventKind
Definition:
nfd-constants.hpp:76
ndn::nfd::operator<<
std::ostream & operator<<(std::ostream &os, FaceScope faceScope)
Definition:
nfd-constants.cpp:35
ndn::nfd::FACE_EVENT_NONE
Definition:
nfd-constants.hpp:77
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:94
ndn::nfd::FACE_EVENT_CREATED
face was created
Definition:
nfd-constants.hpp:78
ndn::nfd::RouteOrigin
RouteOrigin
Definition:
nfd-constants.hpp:89
ndn::nfd::RouteFlags
RouteFlags
Definition:
nfd-constants.hpp:112
ndn::nfd::ROUTE_ORIGIN_NONE
Definition:
nfd-constants.hpp:90
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:81
ndnSIM
ndn-cxx
src
encoding
nfd-constants.cpp
Generated on Thu Nov 2 2017 03:30:28 for ndnSIM by
1.8.11