NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
nfd-constants.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #include "nfd-constants.hpp"
23 #include <iostream>
24 #include <map>
25 
26 namespace ndn {
27 namespace nfd {
28 
29 std::ostream&
30 operator<<(std::ostream& os, FaceScope faceScope)
31 {
32  switch (faceScope) {
33  case FACE_SCOPE_NONE:
34  return os << "none";
36  return os << "non-local";
37  case FACE_SCOPE_LOCAL:
38  return os << "local";
39  default:
40  return os << static_cast<unsigned>(faceScope);
41  }
42 }
43 
44 std::ostream&
45 operator<<(std::ostream& os, FacePersistency facePersistency)
46 {
47  switch (facePersistency) {
49  return os << "none";
51  return os << "persistent";
53  return os << "on-demand";
55  return os << "permanent";
56  default:
57  return os << static_cast<unsigned>(facePersistency);
58  }
59 }
60 
61 std::ostream&
62 operator<<(std::ostream& os, LinkType linkType)
63 {
64  switch (linkType) {
65  case LINK_TYPE_NONE:
66  return os << "none";
68  return os << "point-to-point";
70  return os << "multi-access";
71  default:
72  return os << static_cast<unsigned>(linkType);
73  }
74 }
75 
76 std::ostream&
77 operator<<(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";
85  return os << "autoreg";
87  return os << "client";
89  return os << "autoconf";
90  case ROUTE_ORIGIN_NLSR:
91  return os << "nlsr";
93  return os << "static";
94  default:
95  return os << static_cast<unsigned>(routeOrigin);
96  }
97 }
98 
99 std::ostream&
100 operator<<(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) {
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 
141  return os;
142 }
143 
144 } // namespace nfd
145 } // namespace ndn
Copyright (c) 2011-2015 Regents of the University of California.
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
std::ostream & operator<<(std::ostream &os, FaceScope faceScope)