Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /** |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame^] | 3 | * Copyright (c) 2013-2014, Regents of the University of California. |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 7 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 8 | * |
| 9 | * This file licensed under New BSD License. See COPYING for detailed information about |
| 10 | * ndn-cxx library copyright, permissions, and redistribution restrictions. |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 11 | */ |
| 12 | |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 13 | #ifndef NDN_MANAGEMENT_NDND_FACE_INSTANCE_HPP |
| 14 | #define NDN_MANAGEMENT_NDND_FACE_INSTANCE_HPP |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 15 | |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 16 | #include "../encoding/tlv-ndnd.hpp" |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 17 | #include "../encoding/block.hpp" |
| 18 | #include "../name.hpp" |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 19 | |
| 20 | namespace ndn { |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 21 | namespace ndnd { |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * An FaceInstance holds an action and Name prefix and other fields for an forwarding entry. |
| 25 | */ |
Alexander Afanasyev | 2a7f720 | 2014-04-23 14:25:29 -0700 | [diff] [blame] | 26 | class FaceInstance |
| 27 | { |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 28 | public: |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 29 | FaceInstance(const std::string& action, |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 30 | int64_t faceId, |
| 31 | uint32_t ipProto, |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 32 | const std::string& host, |
| 33 | const std::string& port, |
| 34 | const std::string& multicastInterface, |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 35 | uint32_t multicastTtl, |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 36 | const time::milliseconds& freshnessPeriod) |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 37 | : action_(action) |
| 38 | , faceId_(faceId) |
| 39 | , ipProto_(ipProto) |
| 40 | , host_(host) |
| 41 | , port_(port) |
| 42 | , multicastInterface_(multicastInterface) |
| 43 | , multicastTtl_(multicastTtl) |
| 44 | , freshnessPeriod_(freshnessPeriod) |
| 45 | { |
| 46 | } |
| 47 | |
| 48 | FaceInstance() |
| 49 | : faceId_(-1) |
| 50 | , ipProto_(-1) |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 51 | , multicastTtl_(-1) |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 52 | , freshnessPeriod_(time::milliseconds::min()) |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 53 | { |
| 54 | } |
| 55 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 56 | /** |
| 57 | * @brief Create from wire encoding |
| 58 | */ |
| 59 | explicit |
| 60 | FaceInstance(const Block& wire) |
| 61 | { |
| 62 | wireDecode(wire); |
| 63 | } |
| 64 | |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 65 | // Action |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 66 | const std::string& |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 67 | getAction() const { return action_; } |
| 68 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 69 | void |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 70 | setAction(const std::string& action) { action_ = action; wire_.reset(); } |
| 71 | |
| 72 | // FaceID |
| 73 | int64_t |
| 74 | getFaceId() const { return faceId_; } |
| 75 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 76 | void |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 77 | setFaceId(int64_t faceId) { faceId_ = faceId; wire_.reset(); } |
| 78 | |
| 79 | // IPProto |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 80 | int32_t |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 81 | getIpProto() const { return ipProto_; } |
| 82 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 83 | void |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 84 | setIpProto(int32_t ipProto) { ipProto_ = ipProto; wire_.reset(); } |
| 85 | |
| 86 | // Host |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 87 | const std::string& |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 88 | getHost() const { return host_; } |
| 89 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 90 | void |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 91 | setHost(const std::string& host) { host_ = host; wire_.reset(); } |
| 92 | |
| 93 | // Port |
Alexander Afanasyev | 0a5eabf | 2014-01-02 09:03:25 -0800 | [diff] [blame] | 94 | const std::string& |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 95 | getPort() const { return port_; } |
| 96 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 97 | void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 98 | setPort(const std::string& port) { port_ = port; wire_.reset(); } |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 99 | |
| 100 | // MulticastInterface |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 101 | const std::string& |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 102 | getMulticastInterface() const { return multicastInterface_; } |
| 103 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 104 | void |
| 105 | setMulticastInterface(const std::string& multicastInterface) |
| 106 | { |
| 107 | multicastInterface_ = multicastInterface; wire_.reset(); |
| 108 | } |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 109 | |
| 110 | // MulticastTTL |
| 111 | int32_t |
| 112 | getMulticastTtl() const { return multicastTtl_; } |
| 113 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 114 | void |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 115 | setMulticastTtl(int32_t multicastTtl) { multicastTtl_ = multicastTtl; wire_.reset(); } |
| 116 | |
| 117 | // Freshness |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 118 | const time::milliseconds& |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 119 | getFreshnessPeriod() const { return freshnessPeriod_; } |
| 120 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 121 | void |
| 122 | setFreshnessPeriod(const time::milliseconds& freshnessPeriod) |
| 123 | { |
| 124 | freshnessPeriod_ = freshnessPeriod; wire_.reset(); |
| 125 | } |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 126 | |
| 127 | // Wire |
| 128 | inline const Block& |
| 129 | wireEncode() const; |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 130 | |
| 131 | inline void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 132 | wireDecode(const Block& wire); |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 133 | |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 134 | private: |
| 135 | std::string action_; |
| 136 | int64_t faceId_; |
| 137 | int32_t ipProto_; |
| 138 | std::string host_; |
Alexander Afanasyev | 0a5eabf | 2014-01-02 09:03:25 -0800 | [diff] [blame] | 139 | std::string port_; |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 140 | std::string multicastInterface_; |
| 141 | int32_t multicastTtl_; |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 142 | time::milliseconds freshnessPeriod_; |
| 143 | |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 144 | mutable Block wire_; |
| 145 | }; |
| 146 | |
| 147 | inline const Block& |
| 148 | FaceInstance::wireEncode() const |
| 149 | { |
| 150 | if (wire_.hasWire()) |
| 151 | return wire_; |
| 152 | |
| 153 | // FaceInstance ::= FACE-INSTANCE-TYPE TLV-LENGTH |
| 154 | // Action? |
| 155 | // FaceID? |
| 156 | // IPProto? |
| 157 | // Host? |
| 158 | // Port? |
| 159 | // MulticastInterface? |
| 160 | // MulticastTTL? |
| 161 | // FreshnessPeriod? |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 162 | |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 163 | wire_ = Block(tlv::ndnd::FaceInstance); |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 164 | |
| 165 | // Action |
| 166 | if (!action_.empty()) |
| 167 | { |
| 168 | wire_.push_back |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 169 | (dataBlock(tlv::ndnd::Action, action_.c_str(), action_.size())); |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | // FaceID |
| 173 | if (faceId_ >= 0) |
| 174 | { |
| 175 | wire_.push_back |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 176 | (nonNegativeIntegerBlock(tlv::ndnd::FaceID, faceId_)); |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | // IPProto |
| 180 | if (ipProto_ >= 0) |
| 181 | { |
| 182 | wire_.push_back |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 183 | (nonNegativeIntegerBlock(tlv::ndnd::IPProto, ipProto_)); |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 184 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 185 | |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 186 | // Host |
| 187 | if (!host_.empty()) |
| 188 | { |
| 189 | wire_.push_back |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 190 | (dataBlock(tlv::ndnd::Host, host_.c_str(), host_.size())); |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | // Port |
Alexander Afanasyev | 0a5eabf | 2014-01-02 09:03:25 -0800 | [diff] [blame] | 194 | if (!port_.empty()) |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 195 | { |
| 196 | wire_.push_back |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 197 | (dataBlock(tlv::ndnd::Port, port_.c_str(), port_.size())); |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | // MulticastInterface |
| 201 | if (!multicastInterface_.empty()) |
| 202 | { |
| 203 | wire_.push_back |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 204 | (dataBlock(tlv::ndnd::MulticastInterface, multicastInterface_.c_str(), multicastInterface_.size())); |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | // MulticastTTL |
| 208 | if (multicastTtl_ >= 0) |
| 209 | { |
| 210 | wire_.push_back |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 211 | (nonNegativeIntegerBlock(tlv::ndnd::MulticastTTL, multicastTtl_)); |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | // FreshnessPeriod |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 215 | if (freshnessPeriod_ >= time::milliseconds::zero()) |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 216 | { |
| 217 | wire_.push_back |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 218 | (nonNegativeIntegerBlock(Tlv::FreshnessPeriod, freshnessPeriod_.count())); |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 219 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 220 | |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 221 | wire_.encode(); |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 222 | return wire_; |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 223 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 224 | |
| 225 | inline void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 226 | FaceInstance::wireDecode(const Block& wire) |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 227 | { |
| 228 | action_.clear(); |
| 229 | faceId_ = -1; |
| 230 | ipProto_ = -1; |
| 231 | host_.clear(); |
Alexander Afanasyev | 0a5eabf | 2014-01-02 09:03:25 -0800 | [diff] [blame] | 232 | port_.clear(); |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 233 | multicastInterface_.clear(); |
| 234 | multicastTtl_ = -1; |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 235 | freshnessPeriod_ = time::milliseconds::min(); |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 236 | |
| 237 | wire_ = wire; |
| 238 | wire_.parse(); |
| 239 | |
| 240 | // FaceInstance ::= FACE-INSTANCE-TYPE TLV-LENGTH |
| 241 | // Action? |
| 242 | // FaceID? |
| 243 | // IPProto? |
| 244 | // Host? |
| 245 | // Port? |
| 246 | // MulticastInterface? |
| 247 | // MulticastTTL? |
| 248 | // FreshnessPeriod? |
| 249 | |
| 250 | // Action |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 251 | Block::element_const_iterator val = wire_.find(tlv::ndnd::Action); |
Alexander Afanasyev | 29e5c3d | 2014-02-11 00:01:10 -0800 | [diff] [blame] | 252 | if (val != wire_.elements_end()) |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 253 | { |
| 254 | action_ = std::string(reinterpret_cast<const char*>(val->value()), val->value_size()); |
| 255 | } |
| 256 | |
| 257 | // FaceID |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 258 | val = wire_.find(tlv::ndnd::FaceID); |
Alexander Afanasyev | 29e5c3d | 2014-02-11 00:01:10 -0800 | [diff] [blame] | 259 | if (val != wire_.elements_end()) |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 260 | { |
| 261 | faceId_ = readNonNegativeInteger(*val); |
| 262 | } |
| 263 | |
| 264 | // IPProto |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 265 | val = wire_.find(tlv::ndnd::IPProto); |
Alexander Afanasyev | 29e5c3d | 2014-02-11 00:01:10 -0800 | [diff] [blame] | 266 | if (val != wire_.elements_end()) |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 267 | { |
| 268 | ipProto_ = readNonNegativeInteger(*val); |
| 269 | } |
| 270 | |
| 271 | // Host |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 272 | val = wire_.find(tlv::ndnd::Host); |
Alexander Afanasyev | 29e5c3d | 2014-02-11 00:01:10 -0800 | [diff] [blame] | 273 | if (val != wire_.elements_end()) |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 274 | { |
| 275 | host_ = std::string(reinterpret_cast<const char*>(val->value()), val->value_size()); |
| 276 | } |
| 277 | |
| 278 | // Port |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 279 | val = wire_.find(tlv::ndnd::Port); |
Alexander Afanasyev | 29e5c3d | 2014-02-11 00:01:10 -0800 | [diff] [blame] | 280 | if (val != wire_.elements_end()) |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 281 | { |
Alexander Afanasyev | 0a5eabf | 2014-01-02 09:03:25 -0800 | [diff] [blame] | 282 | port_ = std::string(reinterpret_cast<const char*>(val->value()), val->value_size()); |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | // MulticastInterface |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 286 | val = wire_.find(tlv::ndnd::MulticastInterface); |
Alexander Afanasyev | 29e5c3d | 2014-02-11 00:01:10 -0800 | [diff] [blame] | 287 | if (val != wire_.elements_end()) |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 288 | { |
| 289 | multicastInterface_ = std::string(reinterpret_cast<const char*>(val->value()), val->value_size()); |
| 290 | } |
| 291 | |
| 292 | // MulticastTTL |
Alexander Afanasyev | 6d48bc1 | 2014-02-18 00:10:51 -0800 | [diff] [blame] | 293 | val = wire_.find(tlv::ndnd::MulticastTTL); |
Alexander Afanasyev | 29e5c3d | 2014-02-11 00:01:10 -0800 | [diff] [blame] | 294 | if (val != wire_.elements_end()) |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 295 | { |
| 296 | multicastTtl_ = readNonNegativeInteger(*val); |
| 297 | } |
| 298 | |
| 299 | // FreshnessPeriod |
| 300 | val = wire_.find(Tlv::FreshnessPeriod); |
Alexander Afanasyev | 29e5c3d | 2014-02-11 00:01:10 -0800 | [diff] [blame] | 301 | if (val != wire_.elements_end()) |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 302 | { |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 303 | freshnessPeriod_ = time::milliseconds(readNonNegativeInteger(*val)); |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 304 | } |
| 305 | } |
| 306 | |
| 307 | inline std::ostream& |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 308 | operator << (std::ostream& os, const FaceInstance& entry) |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 309 | { |
| 310 | os << "FaceInstance("; |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 311 | |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 312 | // Action |
| 313 | if (!entry.getAction().empty()) |
| 314 | { |
| 315 | os << "Action:" << entry.getAction() << ", "; |
| 316 | } |
| 317 | |
| 318 | // FaceID |
| 319 | if (entry.getFaceId() >= 0) |
| 320 | { |
| 321 | os << "FaceID:" << entry.getFaceId() << ", "; |
| 322 | } |
| 323 | |
| 324 | // IPProto |
| 325 | if (entry.getIpProto() >= 0) |
| 326 | { |
| 327 | os << "IPProto:" << entry.getIpProto() << ", "; |
| 328 | } |
| 329 | |
| 330 | // Host |
| 331 | if (!entry.getHost().empty()) |
| 332 | { |
| 333 | os << "Host:" << entry.getHost() << ", "; |
| 334 | } |
| 335 | |
| 336 | // Port |
Alexander Afanasyev | 0a5eabf | 2014-01-02 09:03:25 -0800 | [diff] [blame] | 337 | if (!entry.getPort().empty()) |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 338 | { |
| 339 | os << "Port:" << entry.getPort() << ", "; |
| 340 | } |
| 341 | |
| 342 | // MulticastInterface |
| 343 | if (!entry.getMulticastInterface().empty()) |
| 344 | { |
| 345 | os << "MulticastInterface:" << entry.getMulticastInterface() << ", "; |
| 346 | } |
| 347 | |
| 348 | // MulticastTTL |
| 349 | if (entry.getMulticastTtl() >= 0) |
| 350 | { |
| 351 | os << "MulticastTTL:" << entry.getMulticastTtl() << ", "; |
| 352 | } |
| 353 | |
| 354 | // FreshnessPeriod |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 355 | if (entry.getFreshnessPeriod() >= time::milliseconds::zero()) |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 356 | { |
| 357 | os << "FreshnessPeriod:" << entry.getFreshnessPeriod() << ", "; |
| 358 | } |
| 359 | |
| 360 | os << ")"; |
| 361 | return os; |
| 362 | } |
| 363 | |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 364 | } // namespace ndnd |
| 365 | } // namespace ndn |
Alexander Afanasyev | 5d7db8e | 2014-01-05 22:43:57 -0800 | [diff] [blame] | 366 | |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 367 | #endif // NDN_MANAGEMENT_NDND_FACE_INSTANCE_HPP |