blob: 9cda265c2fb61026c758cc79e45a7a32c6c23596 [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";
Teng Liangb4ecadc2017-03-25 10:55:40 -050071 case LINK_TYPE_AD_HOC:
72 return os << "adhoc";
Chengyu Fan36dca992014-09-25 13:42:03 -060073 }
Davide Pesaventoe55589c2017-02-20 03:02:51 -050074 return os << static_cast<unsigned>(linkType);
75}
76
77std::ostream&
78operator<<(std::ostream& os, FaceEventKind faceEventKind)
79{
80 switch (faceEventKind) {
81 case FACE_EVENT_NONE:
82 return os << "none";
83 case FACE_EVENT_CREATED:
84 return os << "created";
85 case FACE_EVENT_DESTROYED:
86 return os << "destroyed";
87 case FACE_EVENT_UP:
88 return os << "up";
89 case FACE_EVENT_DOWN:
90 return os << "down";
91 }
92 return os << static_cast<unsigned>(faceEventKind);
Junxiao Shi18ef4de2015-10-17 16:58:23 +000093}
94
95std::ostream&
96operator<<(std::ostream& os, RouteOrigin routeOrigin)
97{
98 switch (routeOrigin) {
99 case ROUTE_ORIGIN_NONE:
100 return os << "none";
101 case ROUTE_ORIGIN_APP:
102 return os << "app";
103 case ROUTE_ORIGIN_AUTOREG:
104 return os << "autoreg";
105 case ROUTE_ORIGIN_CLIENT:
106 return os << "client";
107 case ROUTE_ORIGIN_AUTOCONF:
108 return os << "autoconf";
109 case ROUTE_ORIGIN_NLSR:
110 return os << "nlsr";
111 case ROUTE_ORIGIN_STATIC:
112 return os << "static";
Junxiao Shi18ef4de2015-10-17 16:58:23 +0000113 }
Davide Pesaventoe55589c2017-02-20 03:02:51 -0500114 return os << static_cast<unsigned>(routeOrigin);
Junxiao Shi18ef4de2015-10-17 16:58:23 +0000115}
116
117std::ostream&
118operator<<(std::ostream& os, RouteFlags routeFlags)
119{
120 if (routeFlags == ROUTE_FLAGS_NONE) {
121 return os << "none";
122 }
123
Junxiao Shi18ef4de2015-10-17 16:58:23 +0000124 static const std::map<RouteFlags, std::string> knownBits = {
125 {ROUTE_FLAG_CHILD_INHERIT, "child-inherit"},
Davide Pesaventocf415762017-02-25 23:46:47 -0500126 {ROUTE_FLAG_CAPTURE, "capture"}
127 };
128
129 auto join = make_ostream_joiner(os, '|');
Junxiao Shi18ef4de2015-10-17 16:58:23 +0000130 for (const auto& pair : knownBits) {
131 RouteFlags bit = ROUTE_FLAGS_NONE;
132 std::string token;
133 std::tie(bit, token) = pair;
134
Davide Pesaventoe78eeca2017-02-23 23:22:32 -0500135 if ((routeFlags & bit) != 0) {
Davide Pesaventocf415762017-02-25 23:46:47 -0500136 join = token;
Davide Pesaventoe78eeca2017-02-23 23:22:32 -0500137 routeFlags = static_cast<RouteFlags>(routeFlags & ~bit);
Junxiao Shi18ef4de2015-10-17 16:58:23 +0000138 }
Junxiao Shi18ef4de2015-10-17 16:58:23 +0000139 }
140
Davide Pesaventoe78eeca2017-02-23 23:22:32 -0500141 if (routeFlags != ROUTE_FLAGS_NONE) {
Davide Pesaventocf415762017-02-25 23:46:47 -0500142 join = AsHex{routeFlags};
Junxiao Shi18ef4de2015-10-17 16:58:23 +0000143 }
144
Chengyu Fan36dca992014-09-25 13:42:03 -0600145 return os;
146}
147
148} // namespace nfd
149} // namespace ndn