blob: c1c80604d38d606e4b3b9842ad8c3d4641ac69e0 [file] [log] [blame]
Chengyu Fan36dca992014-09-25 13:42:03 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Davide Pesavento56bd3ee2017-02-26 16:05:16 -05003 * Copyright (c) 2013-2017 Regents of the University of California.
Chengyu Fan36dca992014-09-25 13:42:03 -06004 *
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"
Davide Pesavento56bd3ee2017-02-26 16:05:16 -050023
Junxiao Shi65f1a712014-11-20 14:59:36 -070024#include <iostream>
Junxiao Shi18ef4de2015-10-17 16:58:23 +000025#include <map>
Chengyu Fan36dca992014-09-25 13:42:03 -060026
27namespace ndn {
28namespace nfd {
29
30std::ostream&
31operator<<(std::ostream& os, FaceScope faceScope)
32{
33 switch (faceScope) {
Junxiao Shi18ef4de2015-10-17 16:58:23 +000034 case FACE_SCOPE_NONE:
35 return os << "none";
36 case FACE_SCOPE_NON_LOCAL:
37 return os << "non-local";
38 case FACE_SCOPE_LOCAL:
39 return os << "local";
Chengyu Fan36dca992014-09-25 13:42:03 -060040 }
Davide Pesaventoe55589c2017-02-20 03:02:51 -050041 return os << static_cast<unsigned>(faceScope);
Chengyu Fan36dca992014-09-25 13:42:03 -060042}
43
44std::ostream&
45operator<<(std::ostream& os, FacePersistency facePersistency)
46{
47 switch (facePersistency) {
Junxiao Shi18ef4de2015-10-17 16:58:23 +000048 case FACE_PERSISTENCY_NONE:
49 return os << "none";
50 case FACE_PERSISTENCY_PERSISTENT:
51 return os << "persistent";
52 case FACE_PERSISTENCY_ON_DEMAND:
53 return os << "on-demand";
54 case FACE_PERSISTENCY_PERMANENT:
55 return os << "permanent";
Chengyu Fan36dca992014-09-25 13:42:03 -060056 }
Davide Pesaventoe55589c2017-02-20 03:02:51 -050057 return os << static_cast<unsigned>(facePersistency);
Chengyu Fan36dca992014-09-25 13:42:03 -060058}
59
60std::ostream&
61operator<<(std::ostream& os, LinkType linkType)
62{
63 switch (linkType) {
Junxiao Shi18ef4de2015-10-17 16:58:23 +000064 case LINK_TYPE_NONE:
65 return os << "none";
66 case LINK_TYPE_POINT_TO_POINT:
67 return os << "point-to-point";
68 case LINK_TYPE_MULTI_ACCESS:
69 return os << "multi-access";
Chengyu Fan36dca992014-09-25 13:42:03 -060070 }
Davide Pesaventoe55589c2017-02-20 03:02:51 -050071 return os << static_cast<unsigned>(linkType);
72}
73
74std::ostream&
75operator<<(std::ostream& os, FaceEventKind faceEventKind)
76{
77 switch (faceEventKind) {
78 case FACE_EVENT_NONE:
79 return os << "none";
80 case FACE_EVENT_CREATED:
81 return os << "created";
82 case FACE_EVENT_DESTROYED:
83 return os << "destroyed";
84 case FACE_EVENT_UP:
85 return os << "up";
86 case FACE_EVENT_DOWN:
87 return os << "down";
88 }
89 return os << static_cast<unsigned>(faceEventKind);
Junxiao Shi18ef4de2015-10-17 16:58:23 +000090}
91
92std::ostream&
93operator<<(std::ostream& os, RouteOrigin routeOrigin)
94{
95 switch (routeOrigin) {
96 case ROUTE_ORIGIN_NONE:
97 return os << "none";
98 case ROUTE_ORIGIN_APP:
99 return os << "app";
100 case ROUTE_ORIGIN_AUTOREG:
101 return os << "autoreg";
102 case ROUTE_ORIGIN_CLIENT:
103 return os << "client";
104 case ROUTE_ORIGIN_AUTOCONF:
105 return os << "autoconf";
106 case ROUTE_ORIGIN_NLSR:
107 return os << "nlsr";
108 case ROUTE_ORIGIN_STATIC:
109 return os << "static";
Junxiao Shi18ef4de2015-10-17 16:58:23 +0000110 }
Davide Pesaventoe55589c2017-02-20 03:02:51 -0500111 return os << static_cast<unsigned>(routeOrigin);
Junxiao Shi18ef4de2015-10-17 16:58:23 +0000112}
113
114std::ostream&
115operator<<(std::ostream& os, RouteFlags routeFlags)
116{
117 if (routeFlags == ROUTE_FLAGS_NONE) {
118 return os << "none";
119 }
120
121 bool isFirst = true;
122 auto printToken = [&os, &isFirst] (const std::string& token) {
123 if (isFirst) {
124 isFirst = false;
125 }
126 else {
127 os << '|';
128 }
129 os << token;
130 };
131
132 static const std::map<RouteFlags, std::string> knownBits = {
133 {ROUTE_FLAG_CHILD_INHERIT, "child-inherit"},
134 {ROUTE_FLAG_CAPTURE, "capture"}};
135 for (const auto& pair : knownBits) {
136 RouteFlags bit = ROUTE_FLAGS_NONE;
137 std::string token;
138 std::tie(bit, token) = pair;
139
140 if ((routeFlags & bit) == 0) {
141 continue;
142 }
143
144 printToken(token);
145 routeFlags = static_cast<RouteFlags>(routeFlags & ~bit);
146 }
147
148 if (routeFlags != 0) {
149 printToken("0x");
150 std::ios_base::fmtflags oldFmt = os.flags();
151 os << std::hex << std::nouppercase
Davide Pesavento56bd3ee2017-02-26 16:05:16 -0500152 << static_cast<uint64_t>(routeFlags);
Junxiao Shi18ef4de2015-10-17 16:58:23 +0000153 os.flags(oldFmt);
154 }
155
Chengyu Fan36dca992014-09-25 13:42:03 -0600156 return os;
157}
158
159} // namespace nfd
160} // namespace ndn