feta(mgmt): Support set bandwith while create face by nfdc

This commit is contained in:
SunnyQjm committed 2023-12-15 14:56:35 +00:00
1 parent e72ce81d2b
commit 58b423fe00
5 files changed
+95 -35

No files matched your search

+37 -34
View File
@@ -22,6 +22,7 @@
#include "ndn-cxx/data.hpp" #include "ndn-cxx/data.hpp"
#include "ndn-cxx/signature.hpp" #include "ndn-cxx/signature.hpp"
#include "ndn-cxx/util/sha256.hpp" #include "ndn-cxx/util/sha256.hpp"
#include <iostream>
namespace ndn { namespace ndn {
@@ -50,14 +51,25 @@ Data::wireEncode(EncodingImpl<TAG>& encoder, bool wantUnsignedPortionOnly) const
// Name // Name
// [MetaInfo] // [MetaInfo]
// [Content] // [Content]
// SignatureInfo
// SignatureValue
// [ServiceClass] // [ServiceClass]
// [TargetRate] // [TargetRate]
// SignatureInfo
// SignatureValue
// (elements are encoded in reverse order) // (elements are encoded in reverse order)
size_t totalLength = 0; size_t totalLength = 0;
// SignatureValue
if (!wantUnsignedPortionOnly) {
if (!m_signatureInfo) {
NDN_THROW(Error("Requested wire format, but Data has not been signed"));
}
totalLength += encoder.prependBlock(m_signatureValue);
}
// SignatureInfo
totalLength += m_signatureInfo.wireEncode(encoder, SignatureInfo::Type::Data);
// TargetRate // TargetRate
if (getTargetRate()) { if (getTargetRate()) {
uint64_t targetRate = *getTargetRate(); uint64_t targetRate = *getTargetRate();
@@ -70,17 +82,6 @@ Data::wireEncode(EncodingImpl<TAG>& encoder, bool wantUnsignedPortionOnly) const
totalLength += encoder.prependByteArrayBlock(tlv::ServiceClass, reinterpret_cast<uint8_t*>(&serviceClass), sizeof(serviceClass)); totalLength += encoder.prependByteArrayBlock(tlv::ServiceClass, reinterpret_cast<uint8_t*>(&serviceClass), sizeof(serviceClass));
} }
// SignatureValue
if (!wantUnsignedPortionOnly) {
if (!m_signatureInfo) {
NDN_THROW(Error("Requested wire format, but Data has not been signed"));
}
totalLength += encoder.prependBlock(m_signatureValue);
}
// SignatureInfo
totalLength += m_signatureInfo.wireEncode(encoder, SignatureInfo::Type::Data);
// Content // Content
if (hasContent()) { if (hasContent()) {
totalLength += encoder.prependBlock(m_content); totalLength += encoder.prependBlock(m_content);
@@ -147,10 +148,10 @@ Data::wireDecode(const Block& wire)
// Name // Name
// [MetaInfo] // [MetaInfo]
// [Content] // [Content]
// SignatureInfo
// SignatureValue
// [ServiceClass] // [ServiceClass]
// [TargetRate] // [TargetRate]
// SignatureInfo
// SignatureValue
auto element = m_wire.elements_begin(); auto element = m_wire.elements_begin();
if (element == m_wire.elements_end() || element->type() != tlv::Name) { if (element == m_wire.elements_end() || element->type() != tlv::Name) {
@@ -166,6 +167,7 @@ Data::wireDecode(const Block& wire)
int lastElement = 1; // last recognized element index, in spec order int lastElement = 1; // last recognized element index, in spec order
for (++element; element != m_wire.elements_end(); ++element) { for (++element; element != m_wire.elements_end(); ++element) {
// std::cout << "element: " << element->type() << std::endl;
switch (element->type()) { switch (element->type()) {
case tlv::MetaInfo: { case tlv::MetaInfo: {
if (lastElement >= 2) { if (lastElement >= 2) {
@@ -183,35 +185,19 @@ Data::wireDecode(const Block& wire)
lastElement = 3; lastElement = 3;
break; break;
} }
case tlv::SignatureInfo: {
if (lastElement >= 4) {
NDN_THROW(Error("SignatureInfo element is out of order"));
}
m_signatureInfo.wireDecode(*element);
lastElement = 4;
break;
}
case tlv::SignatureValue: {
if (lastElement >= 5) {
NDN_THROW(Error("SignatureValue element is out of order"));
}
m_signatureValue = *element;
lastElement = 5;
break;
}
case tlv::ServiceClass: { case tlv::ServiceClass: {
if (lastElement >= 6) { if (lastElement >= 4) {
break; // ServiceClass is non-critical, ignore out-of-order appearance break; // ServiceClass is non-critical, ignore out-of-order appearance
} }
if (element->value_size() != 1) { if (element->value_size() != 1) {
NDN_THROW(Error("ServiceClass element is malformed")); NDN_THROW(Error("ServiceClass element is malformed"));
} }
m_serviceClass = *element->value(); m_serviceClass = *element->value();
lastElement = 6; lastElement = 4;
break; break;
} }
case tlv::TargetRate: { case tlv::TargetRate: {
if (lastElement >= 7) { if (lastElement >= 5) {
break; // TargetRate is non-critical, ignore out-of-order appearance break; // TargetRate is non-critical, ignore out-of-order appearance
} }
uint64_t targetRate = 0; uint64_t targetRate = 0;
@@ -220,9 +206,26 @@ Data::wireDecode(const Block& wire)
} }
std::memcpy(&targetRate, element->value(), sizeof(targetRate)); std::memcpy(&targetRate, element->value(), sizeof(targetRate));
m_targetRate = targetRate; m_targetRate = targetRate;
lastElement = 5;
break;
}
case tlv::SignatureInfo: {
if (lastElement >= 6) {
NDN_THROW(Error("SignatureInfo element is out of order"));
}
m_signatureInfo.wireDecode(*element);
lastElement = 6;
break;
}
case tlv::SignatureValue: {
if (lastElement >= 7) {
NDN_THROW(Error("SignatureValue element is out of order"));
}
m_signatureValue = *element;
lastElement = 7; lastElement = 7;
break; break;
} }
default: { // unrecognized element default: { // unrecognized element
// if the TLV-TYPE is critical, abort decoding // if the TLV-TYPE is critical, abort decoding
if (tlv::isCriticalType(element->type())) { if (tlv::isCriticalType(element->type())) {
+1
View File
@@ -70,6 +70,7 @@ enum {
BaseCongestionMarkingInterval = 135, BaseCongestionMarkingInterval = 135,
DefaultCongestionThreshold = 136, DefaultCongestionThreshold = 136,
Mtu = 137, Mtu = 137,
Bandwidth = 138,
FaceQueryFilter = 150, FaceQueryFilter = 150,
FaceEventNotification = 192, FaceEventNotification = 192,
FaceEventKind = 193, FaceEventKind = 193,
+2
View File
@@ -106,6 +106,7 @@ FaceCreateCommand::FaceCreateCommand()
.optional(CONTROL_PARAMETER_BASE_CONGESTION_MARKING_INTERVAL) .optional(CONTROL_PARAMETER_BASE_CONGESTION_MARKING_INTERVAL)
.optional(CONTROL_PARAMETER_DEFAULT_CONGESTION_THRESHOLD) .optional(CONTROL_PARAMETER_DEFAULT_CONGESTION_THRESHOLD)
.optional(CONTROL_PARAMETER_MTU) .optional(CONTROL_PARAMETER_MTU)
.optional(CONTROL_PARAMETER_BANDWIDTH)
.optional(CONTROL_PARAMETER_FLAGS) .optional(CONTROL_PARAMETER_FLAGS)
.optional(CONTROL_PARAMETER_MASK); .optional(CONTROL_PARAMETER_MASK);
m_responseValidator m_responseValidator
@@ -116,6 +117,7 @@ FaceCreateCommand::FaceCreateCommand()
.optional(CONTROL_PARAMETER_BASE_CONGESTION_MARKING_INTERVAL) .optional(CONTROL_PARAMETER_BASE_CONGESTION_MARKING_INTERVAL)
.optional(CONTROL_PARAMETER_DEFAULT_CONGESTION_THRESHOLD) .optional(CONTROL_PARAMETER_DEFAULT_CONGESTION_THRESHOLD)
.optional(CONTROL_PARAMETER_MTU) .optional(CONTROL_PARAMETER_MTU)
.optional(CONTROL_PARAMETER_BANDWIDTH)
.required(CONTROL_PARAMETER_FLAGS); .required(CONTROL_PARAMETER_FLAGS);
} }
+14
View File
@@ -24,6 +24,7 @@
#include "ndn-cxx/encoding/tlv-nfd.hpp" #include "ndn-cxx/encoding/tlv-nfd.hpp"
#include "ndn-cxx/util/concepts.hpp" #include "ndn-cxx/util/concepts.hpp"
#include "ndn-cxx/util/string-helper.hpp" #include "ndn-cxx/util/string-helper.hpp"
#include <iostream>
namespace ndn { namespace ndn {
namespace nfd { namespace nfd {
@@ -51,6 +52,9 @@ ControlParameters::wireEncode(EncodingImpl<TAG>& encoder) const
{ {
size_t totalLength = 0; size_t totalLength = 0;
if (this->hasBandwidth()) {
totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::Bandwidth, m_bandwidth);
}
if (this->hasMtu()) { if (this->hasMtu()) {
totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::Mtu, m_mtu); totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::Mtu, m_mtu);
} }
@@ -238,6 +242,12 @@ ControlParameters::wireDecode(const Block& block)
if (this->hasMtu()) { if (this->hasMtu()) {
m_mtu = readNonNegativeInteger(*val); m_mtu = readNonNegativeInteger(*val);
} }
val = m_wire.find(tlv::nfd::Bandwidth);
m_hasFields[CONTROL_PARAMETER_BANDWIDTH] = val != m_wire.elements_end();
if (this->hasBandwidth()) {
m_bandwidth = readNonNegativeInteger(*val);
}
} }
bool bool
@@ -382,6 +392,10 @@ operator<<(std::ostream& os, const ControlParameters& parameters)
os << "Mtu: " << parameters.getMtu() << ", "; os << "Mtu: " << parameters.getMtu() << ", ";
} }
if (parameters.hasBandwidth()) {
os << "Bandwidth: " << parameters.getBandwidth() << ", ";
}
os << ")"; os << ")";
return os; return os;
} }
+41 -1
View File
@@ -50,6 +50,7 @@ enum ControlParameterField {
CONTROL_PARAMETER_BASE_CONGESTION_MARKING_INTERVAL, CONTROL_PARAMETER_BASE_CONGESTION_MARKING_INTERVAL,
CONTROL_PARAMETER_DEFAULT_CONGESTION_THRESHOLD, CONTROL_PARAMETER_DEFAULT_CONGESTION_THRESHOLD,
CONTROL_PARAMETER_MTU, CONTROL_PARAMETER_MTU,
CONTROL_PARAMETER_BANDWIDTH,
CONTROL_PARAMETER_UBOUND CONTROL_PARAMETER_UBOUND
}; };
@@ -69,7 +70,8 @@ const std::string CONTROL_PARAMETER_FIELD[CONTROL_PARAMETER_UBOUND] = {
"FacePersistency", "FacePersistency",
"BaseCongestionMarkingInterval", "BaseCongestionMarkingInterval",
"DefaultCongestionThreshold", "DefaultCongestionThreshold",
"Mtu" "Mtu",
"Bandwidth",
}; };
/** /**
@@ -595,6 +597,43 @@ public: // getters & setters
return *this; return *this;
} }
bool hasBandwidth() const
{
return m_hasFields[CONTROL_PARAMETER_BANDWIDTH];
}
/** \brief get bandwidth (measured in bps)
*
* This value is capped at MAX_NDN_BITRATE, even if the bandwidth of the face is unlimited.
*/
uint64_t
getBandwidth() const
{
BOOST_ASSERT(this->hasBandwidth());
return m_bandwidth;
}
/** \brief set bandwidth (measured in bps)
*
* This value is capped at MAX_NDN_BITRATE, even if the bandwidth of the face is unlimited.
*/
ControlParameters&
setBandwidth(uint64_t bandwidth)
{
m_wire.reset();
m_bandwidth = bandwidth;
m_hasFields[CONTROL_PARAMETER_BANDWIDTH] = true;
return *this;
}
ControlParameters&
unsetBandwidth()
{
m_wire.reset();
m_hasFields[CONTROL_PARAMETER_BANDWIDTH] = false;
return *this;
}
const std::vector<bool>& const std::vector<bool>&
getPresentFields() const getPresentFields() const
{ {
@@ -652,6 +691,7 @@ private: // fields
time::nanoseconds m_baseCongestionMarkingInterval; time::nanoseconds m_baseCongestionMarkingInterval;
uint64_t m_defaultCongestionThreshold; uint64_t m_defaultCongestionThreshold;
uint64_t m_mtu; uint64_t m_mtu;
uint64_t m_bandwidth;
private: private:
mutable Block m_wire; mutable Block m_wire;