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