feta(mgmt): Support set bandwith while create face by nfdc
This commit is contained in:
1 parent
e72ce81d2b
commit
58b423fe00
5 files changed
+95
-35
No files matched your search
+37
-34
@@ -22,6 +22,7 @@
|
||||
#include "ndn-cxx/data.hpp"
|
||||
#include "ndn-cxx/signature.hpp"
|
||||
#include "ndn-cxx/util/sha256.hpp"
|
||||
#include <iostream>
|
||||
|
||||
namespace ndn {
|
||||
|
||||
@@ -50,14 +51,25 @@ Data::wireEncode(EncodingImpl<TAG>& encoder, bool wantUnsignedPortionOnly) const
|
||||
// Name
|
||||
// [MetaInfo]
|
||||
// [Content]
|
||||
// SignatureInfo
|
||||
// SignatureValue
|
||||
// [ServiceClass]
|
||||
// [TargetRate]
|
||||
// SignatureInfo
|
||||
// SignatureValue
|
||||
// (elements are encoded in reverse order)
|
||||
|
||||
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
|
||||
if (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));
|
||||
}
|
||||
|
||||
// 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
|
||||
if (hasContent()) {
|
||||
totalLength += encoder.prependBlock(m_content);
|
||||
@@ -147,10 +148,10 @@ Data::wireDecode(const Block& wire)
|
||||
// Name
|
||||
// [MetaInfo]
|
||||
// [Content]
|
||||
// SignatureInfo
|
||||
// SignatureValue
|
||||
// [ServiceClass]
|
||||
// [TargetRate]
|
||||
// SignatureInfo
|
||||
// SignatureValue
|
||||
|
||||
auto element = m_wire.elements_begin();
|
||||
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
|
||||
for (++element; element != m_wire.elements_end(); ++element) {
|
||||
// std::cout << "element: " << element->type() << std::endl;
|
||||
switch (element->type()) {
|
||||
case tlv::MetaInfo: {
|
||||
if (lastElement >= 2) {
|
||||
@@ -183,35 +185,19 @@ Data::wireDecode(const Block& wire)
|
||||
lastElement = 3;
|
||||
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: {
|
||||
if (lastElement >= 6) {
|
||||
if (lastElement >= 4) {
|
||||
break; // ServiceClass is non-critical, ignore out-of-order appearance
|
||||
}
|
||||
if (element->value_size() != 1) {
|
||||
NDN_THROW(Error("ServiceClass element is malformed"));
|
||||
}
|
||||
m_serviceClass = *element->value();
|
||||
lastElement = 6;
|
||||
lastElement = 4;
|
||||
break;
|
||||
}
|
||||
case tlv::TargetRate: {
|
||||
if (lastElement >= 7) {
|
||||
if (lastElement >= 5) {
|
||||
break; // TargetRate is non-critical, ignore out-of-order appearance
|
||||
}
|
||||
uint64_t targetRate = 0;
|
||||
@@ -220,9 +206,26 @@ Data::wireDecode(const Block& wire)
|
||||
}
|
||||
std::memcpy(&targetRate, element->value(), sizeof(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;
|
||||
break;
|
||||
}
|
||||
|
||||
default: { // unrecognized element
|
||||
// if the TLV-TYPE is critical, abort decoding
|
||||
if (tlv::isCriticalType(element->type())) {
|
||||
|
||||
@@ -70,6 +70,7 @@ enum {
|
||||
BaseCongestionMarkingInterval = 135,
|
||||
DefaultCongestionThreshold = 136,
|
||||
Mtu = 137,
|
||||
Bandwidth = 138,
|
||||
FaceQueryFilter = 150,
|
||||
FaceEventNotification = 192,
|
||||
FaceEventKind = 193,
|
||||
|
||||
@@ -106,6 +106,7 @@ FaceCreateCommand::FaceCreateCommand()
|
||||
.optional(CONTROL_PARAMETER_BASE_CONGESTION_MARKING_INTERVAL)
|
||||
.optional(CONTROL_PARAMETER_DEFAULT_CONGESTION_THRESHOLD)
|
||||
.optional(CONTROL_PARAMETER_MTU)
|
||||
.optional(CONTROL_PARAMETER_BANDWIDTH)
|
||||
.optional(CONTROL_PARAMETER_FLAGS)
|
||||
.optional(CONTROL_PARAMETER_MASK);
|
||||
m_responseValidator
|
||||
@@ -116,6 +117,7 @@ FaceCreateCommand::FaceCreateCommand()
|
||||
.optional(CONTROL_PARAMETER_BASE_CONGESTION_MARKING_INTERVAL)
|
||||
.optional(CONTROL_PARAMETER_DEFAULT_CONGESTION_THRESHOLD)
|
||||
.optional(CONTROL_PARAMETER_MTU)
|
||||
.optional(CONTROL_PARAMETER_BANDWIDTH)
|
||||
.required(CONTROL_PARAMETER_FLAGS);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "ndn-cxx/encoding/tlv-nfd.hpp"
|
||||
#include "ndn-cxx/util/concepts.hpp"
|
||||
#include "ndn-cxx/util/string-helper.hpp"
|
||||
#include <iostream>
|
||||
|
||||
namespace ndn {
|
||||
namespace nfd {
|
||||
@@ -51,6 +52,9 @@ ControlParameters::wireEncode(EncodingImpl<TAG>& encoder) const
|
||||
{
|
||||
size_t totalLength = 0;
|
||||
|
||||
if (this->hasBandwidth()) {
|
||||
totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::Bandwidth, m_bandwidth);
|
||||
}
|
||||
if (this->hasMtu()) {
|
||||
totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::Mtu, m_mtu);
|
||||
}
|
||||
@@ -238,6 +242,12 @@ ControlParameters::wireDecode(const Block& block)
|
||||
if (this->hasMtu()) {
|
||||
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
|
||||
@@ -382,6 +392,10 @@ operator<<(std::ostream& os, const ControlParameters& parameters)
|
||||
os << "Mtu: " << parameters.getMtu() << ", ";
|
||||
}
|
||||
|
||||
if (parameters.hasBandwidth()) {
|
||||
os << "Bandwidth: " << parameters.getBandwidth() << ", ";
|
||||
}
|
||||
|
||||
os << ")";
|
||||
return os;
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ enum ControlParameterField {
|
||||
CONTROL_PARAMETER_BASE_CONGESTION_MARKING_INTERVAL,
|
||||
CONTROL_PARAMETER_DEFAULT_CONGESTION_THRESHOLD,
|
||||
CONTROL_PARAMETER_MTU,
|
||||
CONTROL_PARAMETER_BANDWIDTH,
|
||||
CONTROL_PARAMETER_UBOUND
|
||||
};
|
||||
|
||||
@@ -69,7 +70,8 @@ const std::string CONTROL_PARAMETER_FIELD[CONTROL_PARAMETER_UBOUND] = {
|
||||
"FacePersistency",
|
||||
"BaseCongestionMarkingInterval",
|
||||
"DefaultCongestionThreshold",
|
||||
"Mtu"
|
||||
"Mtu",
|
||||
"Bandwidth",
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -595,6 +597,43 @@ public: // getters & setters
|
||||
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>&
|
||||
getPresentFields() const
|
||||
{
|
||||
@@ -652,6 +691,7 @@ private: // fields
|
||||
time::nanoseconds m_baseCongestionMarkingInterval;
|
||||
uint64_t m_defaultCongestionThreshold;
|
||||
uint64_t m_mtu;
|
||||
uint64_t m_bandwidth;
|
||||
|
||||
private:
|
||||
mutable Block m_wire;
|
||||
|
||||
Reference in new issue
Block a user