blob: ac345885e6786982d2eb50b8481a0ecf2da0a837 [file] [log] [blame]
Chengyu Fan36dca992014-09-25 13:42:03 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2014 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
Junxiao Shi65f1a712014-11-20 14:59:36 -070022#include "nfd-constants.hpp"
23#include <iostream>
Junxiao Shi18ef4de2015-10-17 16:58:23 +000024#include <map>
Chengyu Fan36dca992014-09-25 13:42:03 -060025
26namespace ndn {
27namespace nfd {
28
29std::ostream&
30operator<<(std::ostream& os, FaceScope faceScope)
31{
32 switch (faceScope) {
Junxiao Shi18ef4de2015-10-17 16:58:23 +000033 case FACE_SCOPE_NONE:
34 return os << "none";
35 case FACE_SCOPE_NON_LOCAL:
36 return os << "non-local";
37 case FACE_SCOPE_LOCAL:
38 return os << "local";
Chengyu Fan36dca992014-09-25 13:42:03 -060039 }
Davide Pesaventoe55589c2017-02-20 03:02:51 -050040 return os << static_cast<unsigned>(faceScope);
Chengyu Fan36dca992014-09-25 13:42:03 -060041}
42
43std::ostream&
44operator<<(std::ostream& os, FacePersistency facePersistency)
45{
46 switch (facePersistency) {
Junxiao Shi18ef4de2015-10-17 16:58:23 +000047 case FACE_PERSISTENCY_NONE:
48 return os << "none";
49 case FACE_PERSISTENCY_PERSISTENT:
50 return os << "persistent";
51 case FACE_PERSISTENCY_ON_DEMAND:
52 return os << "on-demand";
53 case FACE_PERSISTENCY_PERMANENT:
54 return os << "permanent";
Chengyu Fan36dca992014-09-25 13:42:03 -060055 }
Davide Pesaventoe55589c2017-02-20 03:02:51 -050056 return os << static_cast<unsigned>(facePersistency);
Chengyu Fan36dca992014-09-25 13:42:03 -060057}
58
59std::ostream&
60operator<<(std::ostream& os, LinkType linkType)
61{
62 switch (linkType) {
Junxiao Shi18ef4de2015-10-17 16:58:23 +000063 case LINK_TYPE_NONE:
64 return os << "none";
65 case LINK_TYPE_POINT_TO_POINT:
66 return os << "point-to-point";
67 case LINK_TYPE_MULTI_ACCESS:
68 return os << "multi-access";
Chengyu Fan36dca992014-09-25 13:42:03 -060069 }
Davide Pesaventoe55589c2017-02-20 03:02:51 -050070 return os << static_cast<unsigned>(linkType);
71}
72
73std::ostream&
74operator<<(std::ostream& os, FaceEventKind faceEventKind)
75{
76 switch (faceEventKind) {
77 case FACE_EVENT_NONE:
78 return os << "none";
79 case FACE_EVENT_CREATED:
80 return os << "created";
81 case FACE_EVENT_DESTROYED:
82 return os << "destroyed";
83 case FACE_EVENT_UP:
84 return os << "up";
85 case FACE_EVENT_DOWN:
86 return os << "down";
87 }
88 return os << static_cast<unsigned>(faceEventKind);
Junxiao Shi18ef4de2015-10-17 16:58:23 +000089}
90
91std::ostream&
92operator<<(std::ostream& os, RouteOrigin routeOrigin)
93{
94 switch (routeOrigin) {
95 case ROUTE_ORIGIN_NONE:
96 return os << "none";
97 case ROUTE_ORIGIN_APP:
98 return os << "app";
99 case ROUTE_ORIGIN_AUTOREG:
100 return os << "autoreg";
101 case ROUTE_ORIGIN_CLIENT:
102 return os << "client";
103 case ROUTE_ORIGIN_AUTOCONF:
104 return os << "autoconf";
105 case ROUTE_ORIGIN_NLSR:
106 return os << "nlsr";
107 case ROUTE_ORIGIN_STATIC:
108 return os << "static";
Junxiao Shi18ef4de2015-10-17 16:58:23 +0000109 }
Davide Pesaventoe55589c2017-02-20 03:02:51 -0500110 return os << static_cast<unsigned>(routeOrigin);
Junxiao Shi18ef4de2015-10-17 16:58:23 +0000111}
112
113std::ostream&
114operator<<(std::ostream& os, RouteFlags routeFlags)
115{
116 if (routeFlags == ROUTE_FLAGS_NONE) {
117 return os << "none";
118 }
119
120 bool isFirst = true;
121 auto printToken = [&os, &isFirst] (const std::string& token) {
122 if (isFirst) {
123 isFirst = false;
124 }
125 else {
126 os << '|';
127 }
128 os << token;
129 };
130
131 static const std::map<RouteFlags, std::string> knownBits = {
132 {ROUTE_FLAG_CHILD_INHERIT, "child-inherit"},
133 {ROUTE_FLAG_CAPTURE, "capture"}};
134 for (const auto& pair : knownBits) {
135 RouteFlags bit = ROUTE_FLAGS_NONE;
136 std::string token;
137 std::tie(bit, token) = pair;
138
139 if ((routeFlags & bit) == 0) {
140 continue;
141 }
142
143 printToken(token);
144 routeFlags = static_cast<RouteFlags>(routeFlags & ~bit);
145 }
146
147 if (routeFlags != 0) {
148 printToken("0x");
149 std::ios_base::fmtflags oldFmt = os.flags();
150 os << std::hex << std::nouppercase
151 << static_cast<unsigned>(routeFlags);
152 os.flags(oldFmt);
153 }
154
Chengyu Fan36dca992014-09-25 13:42:03 -0600155 return os;
156}
157
158} // namespace nfd
159} // namespace ndn