Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Davide Pesavento | 56bd3ee | 2017-02-26 16:05:16 -0500 | [diff] [blame] | 3 | * Copyright (c) 2013-2017 Regents of the University of California. |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 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 Shi | 65f1a71 | 2014-11-20 14:59:36 -0700 | [diff] [blame] | 22 | #include "nfd-constants.hpp" |
Davide Pesavento | e78eeca | 2017-02-23 23:22:32 -0500 | [diff] [blame] | 23 | #include "util/string-helper.hpp" |
Davide Pesavento | 56bd3ee | 2017-02-26 16:05:16 -0500 | [diff] [blame] | 24 | |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 25 | #include <map> |
Davide Pesavento | e78eeca | 2017-02-23 23:22:32 -0500 | [diff] [blame] | 26 | #include <ostream> |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 27 | |
| 28 | namespace ndn { |
| 29 | namespace nfd { |
| 30 | |
| 31 | std::ostream& |
| 32 | operator<<(std::ostream& os, FaceScope faceScope) |
| 33 | { |
| 34 | switch (faceScope) { |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 35 | 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 Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 41 | } |
Davide Pesavento | e55589c | 2017-02-20 03:02:51 -0500 | [diff] [blame] | 42 | return os << static_cast<unsigned>(faceScope); |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | std::ostream& |
| 46 | operator<<(std::ostream& os, FacePersistency facePersistency) |
| 47 | { |
| 48 | switch (facePersistency) { |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 49 | 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 Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 57 | } |
Davide Pesavento | e55589c | 2017-02-20 03:02:51 -0500 | [diff] [blame] | 58 | return os << static_cast<unsigned>(facePersistency); |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | std::ostream& |
| 62 | operator<<(std::ostream& os, LinkType linkType) |
| 63 | { |
| 64 | switch (linkType) { |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 65 | 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 Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 71 | } |
Davide Pesavento | e55589c | 2017-02-20 03:02:51 -0500 | [diff] [blame] | 72 | return os << static_cast<unsigned>(linkType); |
| 73 | } |
| 74 | |
| 75 | std::ostream& |
| 76 | operator<<(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 Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | std::ostream& |
| 94 | operator<<(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 Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 111 | } |
Davide Pesavento | e55589c | 2017-02-20 03:02:51 -0500 | [diff] [blame] | 112 | return os << static_cast<unsigned>(routeOrigin); |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | std::ostream& |
| 116 | operator<<(std::ostream& os, RouteFlags routeFlags) |
| 117 | { |
| 118 | if (routeFlags == ROUTE_FLAGS_NONE) { |
| 119 | return os << "none"; |
| 120 | } |
| 121 | |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 122 | static const std::map<RouteFlags, std::string> knownBits = { |
| 123 | {ROUTE_FLAG_CHILD_INHERIT, "child-inherit"}, |
Davide Pesavento | cf41576 | 2017-02-25 23:46:47 -0500 | [diff] [blame^] | 124 | {ROUTE_FLAG_CAPTURE, "capture"} |
| 125 | }; |
| 126 | |
| 127 | auto join = make_ostream_joiner(os, '|'); |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 128 | for (const auto& pair : knownBits) { |
| 129 | RouteFlags bit = ROUTE_FLAGS_NONE; |
| 130 | std::string token; |
| 131 | std::tie(bit, token) = pair; |
| 132 | |
Davide Pesavento | e78eeca | 2017-02-23 23:22:32 -0500 | [diff] [blame] | 133 | if ((routeFlags & bit) != 0) { |
Davide Pesavento | cf41576 | 2017-02-25 23:46:47 -0500 | [diff] [blame^] | 134 | join = token; |
Davide Pesavento | e78eeca | 2017-02-23 23:22:32 -0500 | [diff] [blame] | 135 | routeFlags = static_cast<RouteFlags>(routeFlags & ~bit); |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 136 | } |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 137 | } |
| 138 | |
Davide Pesavento | e78eeca | 2017-02-23 23:22:32 -0500 | [diff] [blame] | 139 | if (routeFlags != ROUTE_FLAGS_NONE) { |
Davide Pesavento | cf41576 | 2017-02-25 23:46:47 -0500 | [diff] [blame^] | 140 | join = AsHex{routeFlags}; |
Junxiao Shi | 18ef4de | 2015-10-17 16:58:23 +0000 | [diff] [blame] | 141 | } |
| 142 | |
Chengyu Fan | 36dca99 | 2014-09-25 13:42:03 -0600 | [diff] [blame] | 143 | return os; |
| 144 | } |
| 145 | |
| 146 | } // namespace nfd |
| 147 | } // namespace ndn |