Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2013 Regents of the University of California. |
| 4 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
| 5 | * See COPYING for copyright and distribution information. |
| 6 | */ |
| 7 | |
| 8 | #ifndef NDN_FORWARDING_FLAGS_HPP |
Jeff Thompson | e589c3f | 2013-10-12 17:30:50 -0700 | [diff] [blame] | 9 | #define NDN_FORWARDING_FLAGS_HPP |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 10 | |
Alexander Afanasyev | 10d902e | 2014-01-03 15:27:40 -0800 | [diff] [blame] | 11 | #include "encoding/block.hpp" |
| 12 | #include "encoding/tlv-face-management.hpp" |
| 13 | |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 14 | namespace ndn { |
| 15 | |
| 16 | /** |
| 17 | * A ForwardingFlags object holds the flags which specify how the forwarding daemon should forward an interest for |
| 18 | * a registered prefix. We use a separate ForwardingFlags object to retain future compatibility if the daemon forwarding |
| 19 | * bits are changed, amended or deprecated. |
| 20 | */ |
Alexander Afanasyev | 895b2f3 | 2014-01-03 13:24:52 -0800 | [diff] [blame] | 21 | class ForwardingFlags { |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 22 | public: |
| 23 | /** |
| 24 | * Create a new ForwardingFlags with "active" and "childInherit" set and all other flags cleared. |
| 25 | */ |
| 26 | ForwardingFlags() |
Alexander Afanasyev | 895b2f3 | 2014-01-03 13:24:52 -0800 | [diff] [blame] | 27 | : active_(true) |
| 28 | , childInherit_(true) |
| 29 | , advertise_(false) |
| 30 | , last_(false) |
| 31 | , capture_(false) |
| 32 | , local_(false) |
| 33 | , tap_(false) |
| 34 | , captureOk_(false) |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 35 | { |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Get the value of the "active" flag. |
| 40 | * @return true if the flag is set, false if it is cleared. |
| 41 | */ |
Alexander Afanasyev | 895b2f3 | 2014-01-03 13:24:52 -0800 | [diff] [blame] | 42 | bool getActive() const { return active_; } |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 43 | |
| 44 | /** |
| 45 | * Get the value of the "childInherit" flag. |
| 46 | * @return true if the flag is set, false if it is cleared. |
| 47 | */ |
Alexander Afanasyev | 895b2f3 | 2014-01-03 13:24:52 -0800 | [diff] [blame] | 48 | bool getChildInherit() const { return childInherit_; } |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 49 | |
| 50 | /** |
| 51 | * Get the value of the "advertise" flag. |
| 52 | * @return true if the flag is set, false if it is cleared. |
| 53 | */ |
Alexander Afanasyev | 895b2f3 | 2014-01-03 13:24:52 -0800 | [diff] [blame] | 54 | bool getAdvertise() const { return advertise_; } |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 55 | |
| 56 | /** |
| 57 | * Get the value of the "last" flag. |
| 58 | * @return true if the flag is set, false if it is cleared. |
| 59 | */ |
Alexander Afanasyev | 895b2f3 | 2014-01-03 13:24:52 -0800 | [diff] [blame] | 60 | bool getLast() const { return last_; } |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 61 | |
| 62 | /** |
| 63 | * Get the value of the "capture" flag. |
| 64 | * @return true if the flag is set, false if it is cleared. |
| 65 | */ |
Alexander Afanasyev | 895b2f3 | 2014-01-03 13:24:52 -0800 | [diff] [blame] | 66 | bool getCapture() const { return capture_; } |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 67 | |
| 68 | /** |
| 69 | * Get the value of the "local" flag. |
| 70 | * @return true if the flag is set, false if it is cleared. |
| 71 | */ |
Alexander Afanasyev | 895b2f3 | 2014-01-03 13:24:52 -0800 | [diff] [blame] | 72 | bool getLocal() const { return local_; } |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 73 | |
| 74 | /** |
| 75 | * Get the value of the "tap" flag. |
| 76 | * @return true if the flag is set, false if it is cleared. |
| 77 | */ |
Alexander Afanasyev | 895b2f3 | 2014-01-03 13:24:52 -0800 | [diff] [blame] | 78 | bool getTap() const { return tap_; } |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 79 | |
| 80 | /** |
| 81 | * Get the value of the "captureOk" flag. |
| 82 | * @return true if the flag is set, false if it is cleared. |
| 83 | */ |
Alexander Afanasyev | 895b2f3 | 2014-01-03 13:24:52 -0800 | [diff] [blame] | 84 | bool getCaptureOk() const { return captureOk_; } |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 85 | |
| 86 | /** |
| 87 | * Set the value of the "active" flag |
Jeff Thompson | 83bf07e | 2013-11-19 11:46:18 -0800 | [diff] [blame] | 88 | * @param active true to set the flag, false to clear it. |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 89 | */ |
Alexander Afanasyev | 10d902e | 2014-01-03 15:27:40 -0800 | [diff] [blame] | 90 | void setActive(bool active) { this->active_ = active; wire_.reset(); } |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 91 | |
| 92 | /** |
| 93 | * Set the value of the "childInherit" flag |
Jeff Thompson | 83bf07e | 2013-11-19 11:46:18 -0800 | [diff] [blame] | 94 | * @param childInherit true to set the flag, false to clear it. |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 95 | */ |
Alexander Afanasyev | 10d902e | 2014-01-03 15:27:40 -0800 | [diff] [blame] | 96 | void setChildInherit(bool childInherit) { this->childInherit_ = childInherit; wire_.reset(); } |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 97 | |
| 98 | /** |
| 99 | * Set the value of the "advertise" flag |
Jeff Thompson | 83bf07e | 2013-11-19 11:46:18 -0800 | [diff] [blame] | 100 | * @param advertise true to set the flag, false to clear it. |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 101 | */ |
Alexander Afanasyev | 10d902e | 2014-01-03 15:27:40 -0800 | [diff] [blame] | 102 | void setAdvertise(bool advertise) { this->advertise_ = advertise; wire_.reset(); } |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 103 | |
| 104 | /** |
| 105 | * Set the value of the "last" flag |
Jeff Thompson | 83bf07e | 2013-11-19 11:46:18 -0800 | [diff] [blame] | 106 | * @param last true to set the flag, false to clear it. |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 107 | */ |
Alexander Afanasyev | 10d902e | 2014-01-03 15:27:40 -0800 | [diff] [blame] | 108 | void setLast(bool last) { this->last_ = last; wire_.reset(); } |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 109 | |
| 110 | /** |
| 111 | * Set the value of the "capture" flag |
Jeff Thompson | 83bf07e | 2013-11-19 11:46:18 -0800 | [diff] [blame] | 112 | * @param capture true to set the flag, false to clear it. |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 113 | */ |
Alexander Afanasyev | 10d902e | 2014-01-03 15:27:40 -0800 | [diff] [blame] | 114 | void setCapture(bool capture) { this->capture_ = capture; wire_.reset(); } |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 115 | |
| 116 | /** |
| 117 | * Set the value of the "local" flag |
Jeff Thompson | 83bf07e | 2013-11-19 11:46:18 -0800 | [diff] [blame] | 118 | * @param local true to set the flag, false to clear it. |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 119 | */ |
Alexander Afanasyev | 10d902e | 2014-01-03 15:27:40 -0800 | [diff] [blame] | 120 | void setLocal(bool local) { this->local_ = local; wire_.reset(); } |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 121 | |
| 122 | /** |
| 123 | * Set the value of the "tap" flag |
Jeff Thompson | 83bf07e | 2013-11-19 11:46:18 -0800 | [diff] [blame] | 124 | * @param tap true to set the flag, false to clear it. |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 125 | */ |
Alexander Afanasyev | 10d902e | 2014-01-03 15:27:40 -0800 | [diff] [blame] | 126 | void setTap(bool tap) { this->tap_ = tap; wire_.reset(); } |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 127 | |
| 128 | /** |
| 129 | * Set the value of the "captureOk" flag |
Jeff Thompson | 83bf07e | 2013-11-19 11:46:18 -0800 | [diff] [blame] | 130 | * @param captureOk true to set the flag, false to clear it. |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 131 | */ |
Alexander Afanasyev | 10d902e | 2014-01-03 15:27:40 -0800 | [diff] [blame] | 132 | void setCaptureOk(bool captureOk) { this->captureOk_ = captureOk; wire_.reset(); } |
Alexander Afanasyev | 895b2f3 | 2014-01-03 13:24:52 -0800 | [diff] [blame] | 133 | |
Alexander Afanasyev | 10d902e | 2014-01-03 15:27:40 -0800 | [diff] [blame] | 134 | inline const Block& |
| 135 | wireEncode() const; |
| 136 | |
| 137 | inline void |
| 138 | wireDecode(const Block &block); |
| 139 | |
Alexander Afanasyev | 895b2f3 | 2014-01-03 13:24:52 -0800 | [diff] [blame] | 140 | private: |
| 141 | bool active_; |
| 142 | bool childInherit_; |
| 143 | bool advertise_; |
| 144 | bool last_; |
| 145 | bool capture_; |
| 146 | bool local_; |
| 147 | bool tap_; |
| 148 | bool captureOk_; |
Alexander Afanasyev | 10d902e | 2014-01-03 15:27:40 -0800 | [diff] [blame] | 149 | |
| 150 | mutable Block wire_; |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 151 | }; |
| 152 | |
Alexander Afanasyev | 10d902e | 2014-01-03 15:27:40 -0800 | [diff] [blame] | 153 | inline const Block& |
| 154 | ForwardingFlags::wireEncode() const |
| 155 | { |
| 156 | if (wire_.hasWire()) |
| 157 | return wire_; |
| 158 | |
| 159 | uint32_t result = 0; |
| 160 | if (active_) |
| 161 | result |= Tlv::FaceManagement::FORW_ACTIVE; |
| 162 | if (childInherit_) |
| 163 | result |= Tlv::FaceManagement::FORW_CHILD_INHERIT; |
| 164 | if (advertise_) |
| 165 | result |= Tlv::FaceManagement::FORW_ADVERTISE; |
| 166 | if (last_) |
| 167 | result |= Tlv::FaceManagement::FORW_LAST; |
| 168 | if (capture_) |
| 169 | result |= Tlv::FaceManagement::FORW_CAPTURE; |
| 170 | if (local_) |
| 171 | result |= Tlv::FaceManagement::FORW_LOCAL; |
| 172 | if (tap_) |
| 173 | result |= Tlv::FaceManagement::FORW_TAP; |
| 174 | if (captureOk_) |
| 175 | result |= Tlv::FaceManagement::FORW_CAPTURE_OK; |
| 176 | |
| 177 | wire_ = nonNegativeIntegerBlock(Tlv::FaceManagement::ForwardingFlags, result); |
| 178 | |
| 179 | return wire_; |
| 180 | } |
| 181 | |
| 182 | inline void |
| 183 | ForwardingFlags::wireDecode(const Block &wire) |
| 184 | { |
| 185 | wire_ = wire; |
| 186 | |
| 187 | uint32_t flags = readNonNegativeInteger(wire_); |
| 188 | |
| 189 | active_ = (flags & Tlv::FaceManagement::FORW_ACTIVE) ? true : false; |
| 190 | childInherit_ = (flags & Tlv::FaceManagement::FORW_CHILD_INHERIT) ? true : false; |
| 191 | advertise_ = (flags & Tlv::FaceManagement::FORW_ADVERTISE) ? true : false; |
| 192 | last_ = (flags & Tlv::FaceManagement::FORW_LAST) ? true : false; |
| 193 | capture_ = (flags & Tlv::FaceManagement::FORW_CAPTURE) ? true : false; |
| 194 | local_ = (flags & Tlv::FaceManagement::FORW_LOCAL) ? true : false; |
| 195 | tap_ = (flags & Tlv::FaceManagement::FORW_TAP) ? true : false; |
| 196 | captureOk_ = (flags & Tlv::FaceManagement::FORW_CAPTURE_OK) ? true : false; |
| 197 | } |
| 198 | |
Alexander Afanasyev | 816cf94 | 2014-01-03 15:33:41 -0800 | [diff] [blame] | 199 | inline std::ostream& |
| 200 | operator << (std::ostream &os, const ForwardingFlags &flags) |
| 201 | { |
| 202 | if (flags.getActive()) |
| 203 | os << "ACTIVE "; |
| 204 | if (flags.getChildInherit()) |
| 205 | os << "CHILE_INHERIT "; |
| 206 | if (flags.getAdvertise()) |
| 207 | os << "ADVERTISE "; |
| 208 | if (flags.getLast()) |
| 209 | os << "LAST "; |
| 210 | if (flags.getCapture()) |
| 211 | os << "CAPTURE "; |
| 212 | if (flags.getLocal()) |
| 213 | os << "LOCAL "; |
| 214 | if (flags.getTap()) |
| 215 | os << "TAP "; |
| 216 | if (flags.getCaptureOk()) |
| 217 | os << "CAPTURE_OK "; |
| 218 | |
| 219 | return os; |
| 220 | } |
| 221 | |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | #endif |