blob: 2b9f8ffb25a9610537ccce41c09e9ea7366dceee [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 Pesaventoe78eeca2017-02-23 23:22:32 -050023#include "util/string-helper.hpp"
Davide Pesavento56bd3ee2017-02-26 16:05:16 -050024
Junxiao Shi18ef4de2015-10-17 16:58:23 +000025#include <map>
Davide Pesaventoe78eeca2017-02-23 23:22:32 -050026#include <ostream>
Chengyu Fan36dca992014-09-25 13:42:03 -060027
28namespace ndn {
29namespace nfd {
30
31std::ostream&
32operator<<(std::ostream& os, FaceScope faceScope)
33{
34 switch (faceScope) {
Junxiao Shi18ef4de2015-10-17 16:58:23 +000035 case FACE_SCOPE_NONE:
36 return os << "none";
37 case FACE_SCOPE_NON_LOCAL:
38 return os << "non-local";
39 case FACE_SCOPE_LOCAL:
40 return os << "local";
Chengyu Fan36dca992014-09-25 13:42:03 -060041 }
Davide Pesaventoe55589c2017-02-20 03:02:51 -050042 return os << static_cast<unsigned>(faceScope);
Chengyu Fan36dca992014-09-25 13:42:03 -060043}
44
45std::ostream&
46operator<<(std::ostream& os, FacePersistency facePersistency)
47{
48 switch (facePersistency) {
Junxiao Shi18ef4de2015-10-17 16:58:23 +000049 case FACE_PERSISTENCY_NONE:
50 return os << "none";
51 case FACE_PERSISTENCY_PERSISTENT:
52 return os << "persistent";
53 case FACE_PERSISTENCY_ON_DEMAND:
54 return os << "on-demand";
55 case FACE_PERSISTENCY_PERMANENT:
56 return os << "permanent";
Chengyu Fan36dca992014-09-25 13:42:03 -060057 }
Davide Pesaventoe55589c2017-02-20 03:02:51 -050058 return os << static_cast<unsigned>(facePersistency);
Chengyu Fan36dca992014-09-25 13:42:03 -060059}
60
61std::ostream&
62operator<<(std::ostream& os, LinkType linkType)
63{
64 switch (linkType) {
Junxiao Shi18ef4de2015-10-17 16:58:23 +000065 case LINK_TYPE_NONE:
66 return os << "none";
67 case LINK_TYPE_POINT_TO_POINT:
68 return os << "point-to-point";
69 case LINK_TYPE_MULTI_ACCESS:
70 return os << "multi-access";
Chengyu Fan36dca992014-09-25 13:42:03 -060071 }
Davide Pesaventoe55589c2017-02-20 03:02:51 -050072 return os << static_cast<unsigned>(linkType);
73}
74
75std::ostream&
76operator<<(std::ostream& os, FaceEventKind faceEventKind)
77{
78 switch (faceEventKind) {
79 case FACE_EVENT_NONE:
80 return os << "none";
81 case FACE_EVENT_CREATED:
82 return os << "created";
83 case FACE_EVENT_DESTROYED:
84 return os << "destroyed";
85 case FACE_EVENT_UP:
86 return os << "up";
87 case FACE_EVENT_DOWN:
88 return os << "down";
89 }
90 return os << static_cast<unsigned>(faceEventKind);
Junxiao Shi18ef4de2015-10-17 16:58:23 +000091}
92
93std::ostream&
94operator<<(std::ostream& os, RouteOrigin routeOrigin)
95{
96 switch (routeOrigin) {
97 case ROUTE_ORIGIN_NONE:
98 return os << "none";
99 case ROUTE_ORIGIN_APP:
100 return os << "app";
101 case ROUTE_ORIGIN_AUTOREG:
102 return os << "autoreg";
103 case ROUTE_ORIGIN_CLIENT:
104 return os << "client";
105 case ROUTE_ORIGIN_AUTOCONF:
106 return os << "autoconf";
107 case ROUTE_ORIGIN_NLSR:
108 return os << "nlsr";
109 case ROUTE_ORIGIN_STATIC:
110 return os << "static";
Junxiao Shi18ef4de2015-10-17 16:58:23 +0000111 }
Davide Pesaventoe55589c2017-02-20 03:02:51 -0500112 return os << static_cast<unsigned>(routeOrigin);
Junxiao Shi18ef4de2015-10-17 16:58:23 +0000113}
114
115std::ostream&
116operator<<(std::ostream& os, RouteFlags routeFlags)
117{
118 if (routeFlags == ROUTE_FLAGS_NONE) {
119 return os << "none";
120 }
121
122 bool isFirst = true;
123 auto printToken = [&os, &isFirst] (const std::string& token) {
124 if (isFirst) {
125 isFirst = false;
126 }
127 else {
128 os << '|';
129 }
130 os << token;
131 };
132
133 static const std::map<RouteFlags, std::string> knownBits = {
134 {ROUTE_FLAG_CHILD_INHERIT, "child-inherit"},
135 {ROUTE_FLAG_CAPTURE, "capture"}};
136 for (const auto& pair : knownBits) {
137 RouteFlags bit = ROUTE_FLAGS_NONE;
138 std::string token;
139 std::tie(bit, token) = pair;
140
Davide Pesaventoe78eeca2017-02-23 23:22:32 -0500141 if ((routeFlags & bit) != 0) {
142 printToken(token);
143 routeFlags = static_cast<RouteFlags>(routeFlags & ~bit);
Junxiao Shi18ef4de2015-10-17 16:58:23 +0000144 }
Junxiao Shi18ef4de2015-10-17 16:58:23 +0000145 }
146
Davide Pesaventoe78eeca2017-02-23 23:22:32 -0500147 if (routeFlags != ROUTE_FLAGS_NONE) {
148 if (!isFirst) {
149 os << '|';
150 }
151 os << AsHex{routeFlags};
Junxiao Shi18ef4de2015-10-17 16:58:23 +0000152 }
153
Chengyu Fan36dca992014-09-25 13:42:03 -0600154 return os;
155}
156
157} // namespace nfd
158} // namespace ndn