blob: b502a9c85ccf1bb779c43cc2b8dd39f61446ec55 [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
Junxiao Shi18ef4de2015-10-17 16:58:23 +0000122 static const std::map<RouteFlags, std::string> knownBits = {
123 {ROUTE_FLAG_CHILD_INHERIT, "child-inherit"},
Davide Pesaventocf415762017-02-25 23:46:47 -0500124 {ROUTE_FLAG_CAPTURE, "capture"}
125 };
126
127 auto join = make_ostream_joiner(os, '|');
Junxiao Shi18ef4de2015-10-17 16:58:23 +0000128 for (const auto& pair : knownBits) {
129 RouteFlags bit = ROUTE_FLAGS_NONE;
130 std::string token;
131 std::tie(bit, token) = pair;
132
Davide Pesaventoe78eeca2017-02-23 23:22:32 -0500133 if ((routeFlags & bit) != 0) {
Davide Pesaventocf415762017-02-25 23:46:47 -0500134 join = token;
Davide Pesaventoe78eeca2017-02-23 23:22:32 -0500135 routeFlags = static_cast<RouteFlags>(routeFlags & ~bit);
Junxiao Shi18ef4de2015-10-17 16:58:23 +0000136 }
Junxiao Shi18ef4de2015-10-17 16:58:23 +0000137 }
138
Davide Pesaventoe78eeca2017-02-23 23:22:32 -0500139 if (routeFlags != ROUTE_FLAGS_NONE) {
Davide Pesaventocf415762017-02-25 23:46:47 -0500140 join = AsHex{routeFlags};
Junxiao Shi18ef4de2015-10-17 16:58:23 +0000141 }
142
Chengyu Fan36dca992014-09-25 13:42:03 -0600143 return os;
144}
145
146} // namespace nfd
147} // namespace ndn