blob: 2b18d4da43041b9ab0cd22249ba0208a4383bda9 [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";
39 default:
40 return os << static_cast<unsigned>(faceScope);
Chengyu Fan36dca992014-09-25 13:42:03 -060041 }
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";
56 default:
57 return os << static_cast<unsigned>(facePersistency);
Chengyu Fan36dca992014-09-25 13:42:03 -060058 }
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";
71 default:
72 return os << static_cast<unsigned>(linkType);
Chengyu Fan36dca992014-09-25 13:42:03 -060073 }
Junxiao Shi18ef4de2015-10-17 16:58:23 +000074}
75
76std::ostream&
77operator<<(std::ostream& os, RouteOrigin routeOrigin)
78{
79 switch (routeOrigin) {
80 case ROUTE_ORIGIN_NONE:
81 return os << "none";
82 case ROUTE_ORIGIN_APP:
83 return os << "app";
84 case ROUTE_ORIGIN_AUTOREG:
85 return os << "autoreg";
86 case ROUTE_ORIGIN_CLIENT:
87 return os << "client";
88 case ROUTE_ORIGIN_AUTOCONF:
89 return os << "autoconf";
90 case ROUTE_ORIGIN_NLSR:
91 return os << "nlsr";
92 case ROUTE_ORIGIN_STATIC:
93 return os << "static";
94 default:
95 return os << static_cast<unsigned>(routeOrigin);
96 }
97}
98
99std::ostream&
100operator<<(std::ostream& os, RouteFlags routeFlags)
101{
102 if (routeFlags == ROUTE_FLAGS_NONE) {
103 return os << "none";
104 }
105
106 bool isFirst = true;
107 auto printToken = [&os, &isFirst] (const std::string& token) {
108 if (isFirst) {
109 isFirst = false;
110 }
111 else {
112 os << '|';
113 }
114 os << token;
115 };
116
117 static const std::map<RouteFlags, std::string> knownBits = {
118 {ROUTE_FLAG_CHILD_INHERIT, "child-inherit"},
119 {ROUTE_FLAG_CAPTURE, "capture"}};
120 for (const auto& pair : knownBits) {
121 RouteFlags bit = ROUTE_FLAGS_NONE;
122 std::string token;
123 std::tie(bit, token) = pair;
124
125 if ((routeFlags & bit) == 0) {
126 continue;
127 }
128
129 printToken(token);
130 routeFlags = static_cast<RouteFlags>(routeFlags & ~bit);
131 }
132
133 if (routeFlags != 0) {
134 printToken("0x");
135 std::ios_base::fmtflags oldFmt = os.flags();
136 os << std::hex << std::nouppercase
137 << static_cast<unsigned>(routeFlags);
138 os.flags(oldFmt);
139 }
140
Chengyu Fan36dca992014-09-25 13:42:03 -0600141 return os;
142}
143
144} // namespace nfd
145} // namespace ndn