feat: Add qsccp tags

This commit is contained in:
SunnyQjm committed 2023-12-03 04:16:14 +00:00
1 parent 6d4a6536fd
commit 6ad02f3428
8 files changed
+288 -3

No files matched your search

+61
View File
@@ -44,10 +44,25 @@ Data::wireEncode(EncodingImpl<TAG>& encoder, bool wantUnsignedPortionOnly) const
// [Content]
// SignatureInfo
// SignatureValue
// [ServiceClass]
// [TargetRate]
// (elements are encoded in reverse order)
size_t totalLength = 0;
// TargetRate
if (getTargetRate()) {
uint64_t targetRate = *getTargetRate();
totalLength += prependNonNegativeIntegerBlock(encoder, tlv::TargetRate, targetRate);
// totalLength += encoder.prependByteArrayBlock(tlv::TargetRate, reinterpret_cast<uint8_t*>(&targetRate), sizeof(targetRate));
}
// ServiceClass
if (getServiceClass()) {
uint8_t serviceClass = *getServiceClass();
totalLength += prependNonNegativeIntegerBlock(encoder, tlv::ServiceClass, serviceClass);
// totalLength += encoder.prependByteArrayBlock(tlv::ServiceClass, reinterpret_cast<uint8_t*>(&serviceClass), sizeof(serviceClass));
}
// SignatureValue
if (!wantUnsignedPortionOnly) {
if (!m_signatureInfo) {
@@ -129,6 +144,8 @@ Data::wireDecode(const Block& wire)
// [Content]
// SignatureInfo
// SignatureValue
// [ServiceClass]
// [TargetRate]
auto element = m_wire.elements_begin();
if (element == m_wire.elements_end() || element->type() != tlv::Name) {
@@ -177,6 +194,30 @@ Data::wireDecode(const Block& wire)
lastElement = 5;
break;
}
case tlv::ServiceClass: {
if (lastElement >= 6) {
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;
break;
}
case tlv::TargetRate: {
if (lastElement >= 7) {
break; // TargetRate is non-critical, ignore out-of-order appearance
}
uint64_t targetRate = 0;
if (element->value_size() != 8) {
NDN_THROW(Error("TargetRate element is malformed"));
}
std::memcpy(&targetRate, element->value(), sizeof(targetRate));
m_targetRate = targetRate;
lastElement = 7;
break;
}
default: { // unrecognized element
// if the TLV-TYPE is critical, abort decoding
if (tlv::isCriticalType(element->type())) {
@@ -333,6 +374,25 @@ Data::extractSignedRanges() const
return bufs;
}
const Data&
Data::setServiceClass(std::optional<uint8_t> serviceClass) const
{
if (m_serviceClass != serviceClass) {
m_serviceClass = serviceClass;
m_wire.reset();
}
return *this;
}
const Data&
Data::setTargetRate(std::optional<uint64_t> targetRate) const
{
if (m_targetRate != targetRate) {
m_targetRate = targetRate;
m_wire.reset();
}
return *this;
}
Data&
Data::setContentType(uint32_t type)
{
@@ -390,3 +450,4 @@ operator<<(std::ostream& os, const Data& data)
}
} // namespace ndn
+20
View File
@@ -300,6 +300,22 @@ public: // Data fields
[[nodiscard]] InputBuffers
extractSignedRanges() const;
std::optional<uint8_t>
getServiceClass() const noexcept
{
return m_serviceClass;
}
const Data&
setServiceClass(std::optional<uint8_t> serviceClass) const;
std::optional<uint64_t>
getTargetRate() const noexcept
{
return m_targetRate;
}
const Data&
setTargetRate(std::optional<uint64_t> targetRate) const;
public: // MetaInfo fields
uint32_t
getContentType() const
@@ -365,6 +381,9 @@ private:
Block m_content;
SignatureInfo m_signatureInfo;
Block m_signatureValue;
// Add for QSCCP
mutable std::optional<uint8_t> m_serviceClass;
mutable std::optional<uint64_t> m_targetRate;
mutable Block m_wire;
mutable Name m_fullName; // cached FullName computed from m_wire
@@ -393,3 +412,4 @@ operator!=(const Data& lhs, const Data& rhs)
} // namespace ndn
#endif // NDN_CXX_DATA_HPP
+5
View File
@@ -85,6 +85,10 @@ enum : uint32_t {
Nonce = 10,
InterestLifetime = 12,
HopLimit = 34,
ServiceClass = 129,
DownstreamRate = 130,
TargetRate = 131,
Dsz = 132,
ApplicationParameters = 36,
InterestSignatureInfo = 44,
InterestSignatureValue = 46,
@@ -438,3 +442,4 @@ sizeOfNonNegativeInteger(uint64_t integer) noexcept
} // namespace ndn
#endif // NDN_CXX_ENCODING_TLV_HPP
+96 -2
View File
@@ -60,6 +60,9 @@ Interest::wireEncode(EncodingImpl<TAG>& encoder) const
// [Nonce]
// [InterestLifetime]
// [HopLimit]
// [Dsz]
// [ServiceClass]
// [DownstreamRate]
// [ApplicationParameters [InterestSignature]]
// (elements are encoded in reverse order)
@@ -81,6 +84,25 @@ Interest::wireEncode(EncodingImpl<TAG>& encoder) const
totalLength += prependBlock(encoder, block);
}
// DownstreamRate
if (getDownstreamRate()) {
uint64_t downstreamRate = *getDownstreamRate();
totalLength += prependNonNegativeIntegerBlock(encoder, tlv::DownstreamRate, downstreamRate);
// totalLength += encoder.prependByteArrayBlock(tlv::DownstreamRate, reinterpret_cast<uint8_t*>(&downstreamRate), sizeof(downstreamRate));
}
// ServiceClass
if (getServiceClass()) {
uint8_t serviceClass = *getServiceClass();
totalLength += prependNonNegativeIntegerBlock(encoder, tlv::ServiceClass, serviceClass);
// totalLength += encoder.prependByteArrayBlock(tlv::ServiceClass, reinterpret_cast<uint8_t*>(&serviceClass), sizeof(serviceClass));
}
// Dsz
if (getDsz()) {
uint16_t dsz = *getDsz();
totalLength += prependNonNegativeIntegerBlock(encoder, tlv::Dsz, dsz);
// totalLength += encoder.prependByteArrayBlock(tlv::Dsz, reinterpret_cast<uint8_t*>(&dsz), sizeof(dsz));
}
// HopLimit
if (getHopLimit()) {
totalLength += prependBinaryBlock(encoder, tlv::HopLimit, {*m_hopLimit});
@@ -156,6 +178,9 @@ Interest::wireDecode(const Block& wire)
// [Nonce]
// [InterestLifetime]
// [HopLimit]
// [Dsz]
// [ServiceClass]
// [DownstreamRate]
// [ApplicationParameters [InterestSignature]]
auto element = m_wire.elements_begin();
@@ -179,6 +204,9 @@ Interest::wireDecode(const Block& wire)
m_nonce.reset();
m_interestLifetime = DEFAULT_INTEREST_LIFETIME;
m_hopLimit.reset();
m_serviceClass.reset();
m_downstreamRate.reset();
m_dsz.reset();
m_parameters.clear();
int lastElement = 1; // last recognized element index, in spec order
@@ -277,13 +305,50 @@ Interest::wireDecode(const Block& wire)
lastElement = 7;
break;
}
case tlv::ApplicationParameters: {
case tlv::Dsz: {
if (lastElement >= 8) {
break; // Dsz is non-critical, ignore out-of-order appearance
}
if (element->value_size() != 2) {
NDN_THROW(Error("Dsz element is malformed"));
}
uint16_t dsz = 0;
std::memcpy(&dsz, element->value(), sizeof(dsz));
m_dsz = dsz;
lastElement = 8;
break;
}
case tlv::ServiceClass: {
if (lastElement >= 9) {
break; // ServiceClass is non-critical, ignore out-of-order appearance
}
if (element->value_size() != 1) {
NDN_THROW(Error("ServiceClass element is malformed" + std::to_string(element->value_size())));
}
m_serviceClass = *element->value();
lastElement = 9;
break;
}
case tlv::DownstreamRate: {
if (lastElement >= 10) {
break; // DownstreamRate is non-critical, ignore out-of-order appearance
}
uint64_t downstreamRate = 0;
if (element->value_size() != 8) {
NDN_THROW(Error("DownstreamRate element is malformed"));
}
std::memcpy(&downstreamRate, element->value(), sizeof(downstreamRate));
m_downstreamRate = downstreamRate;
lastElement = 10;
break;
}
case tlv::ApplicationParameters: {
if (lastElement >= 11) {
break; // ApplicationParameters is non-critical, ignore out-of-order appearance
}
BOOST_ASSERT(!hasApplicationParameters());
m_parameters.push_back(*element);
lastElement = 8;
lastElement = 11;
break;
}
default: { // unrecognized element
@@ -397,6 +462,34 @@ Interest::setForwardingHint(std::vector<Name> value)
return *this;
}
const Interest&
Interest::setServiceClass(std::optional<uint8_t> serviceClass) const
{
if (m_serviceClass != serviceClass) {
m_serviceClass = serviceClass;
m_wire.reset();
}
return *this;
}
const Interest&
Interest::setDownstreamRate(std::optional<uint64_t> downstreamRate) const
{
if (m_downstreamRate != downstreamRate) {
m_downstreamRate = downstreamRate;
m_wire.reset();
}
return *this;
}
const Interest&
Interest::setDsz(std::optional<uint16_t> dsz) const
{
if (m_dsz != dsz) {
m_dsz = dsz;
m_wire.reset();
}
return *this;
}
[[nodiscard]] static auto
generateNonce()
{
@@ -793,3 +886,4 @@ operator<<(std::ostream& os, const Interest& interest)
}
} // namespace ndn
+32
View File
@@ -254,6 +254,33 @@ public: // Interest fields
Interest&
setNonce(std::optional<Nonce> nonce);
std::optional<uint8_t>
getServiceClass() const noexcept
{
return m_serviceClass;
}
const Interest&
setServiceClass(std::optional<uint8_t> serviceClass) const;
std::optional<uint64_t>
getDownstreamRate() const noexcept
{
return m_downstreamRate;
}
const Interest&
setDownstreamRate(std::optional<uint64_t> downstreamRate) const;
std::optional<uint16_t>
getDsz() const noexcept
{
return m_dsz;
}
const Interest&
setDsz(std::optional<uint16_t> dsz) const;
/**
* @brief Change nonce value.
*
@@ -508,6 +535,10 @@ private:
Name m_name;
std::vector<Name> m_forwardingHint;
mutable std::optional<Nonce> m_nonce;
// Add for QSCCP
mutable std::optional<uint8_t> m_serviceClass;
mutable std::optional<uint64_t> m_downstreamRate;
mutable std::optional<uint16_t> m_dsz;
time::milliseconds m_interestLifetime = DEFAULT_INTEREST_LIFETIME;
std::optional<uint8_t> m_hopLimit;
bool m_canBePrefix = false;
@@ -534,3 +565,4 @@ operator<<(std::ostream& os, const Interest& interest);
} // namespace ndn
#endif // NDN_CXX_INTEREST_HPP
+37 -1
View File
@@ -114,6 +114,37 @@ typedef FieldDecl<field_location_tags::Header,
PrefixAnnouncementHeader,
tlv::PrefixAnnouncement> PrefixAnnouncementField;
/**
* DSZ Field
* Data Size field
*/
typedef FieldDecl<field_location_tags::Header,
uint64_t, tlv::DSZ> DSZField;
/**
* Tos Field
*/
typedef FieldDecl<field_location_tags::Header,
uint64_t, tlv::Tos> TosField;
/**
* Fair rate field
*/
typedef FieldDecl<field_location_tags::Header,
uint64_t, tlv::TargetRate> TargetRateField;
///**
// * Queue occupy rate
// */
//typedef FieldDecl<field_location_tags::Header,
// uint64_t, tlv::QueueOccupyRate> QueueOccupyRateField;
//BOOST_CONCEPT_ASSERT((Field<QueueOccupyRateField>));
/**
* Available rate field
*/
typedef FieldDecl<field_location_tags::Header,
uint64_t, tlv::DownstreamRate> DownstreamRateField;
/**
* \brief Set of all field declarations.
*/
@@ -131,7 +162,12 @@ using FieldSet = boost::mp11::mp_list<
AckField,
TxSequenceField,
NonDiscoveryField,
PrefixAnnouncementField
PrefixAnnouncementField,
DSZField,
TosField,
TargetRateField,
// QueueOccupyRateField,
DownstreamRateField
>;
static_assert(boost::mp11::mp_is_set<FieldSet>());
+25
View File
@@ -77,6 +77,31 @@ using NonDiscoveryTag = SimpleTag<EmptyValue, 14>;
*/
using PrefixAnnouncementTag = SimpleTag<PrefixAnnouncementHeader, 15>;
/**
* DSZ
* Data Size
*/
using DSZTag = SimpleTag<uint64_t, 16>;
/**
* Tos
*/
using TosTag = SimpleTag<uint64_t, 17>;
/**
* Fair rate tag
*/
using FairRateTag = SimpleTag<uint64_t, 18>;
///**
// * Queue occupy rate(0 ~ 100)
// */
//typedef SimpleTag<uint64_t, 19> QueueOccupyRateTag;
/**
* Available Rate tag
*/
using DownstreamRateTag = SimpleTag<uint64_t, 19>;
// typedef SimpleTag<uint64_t, 19> DownstreamRateTag;
} // namespace ndn::lp
#endif // NDN_CXX_LP_TAGS_HPP
+12
View File
@@ -52,6 +52,18 @@ enum : uint32_t {
NonDiscovery = 844,
PrefixAnnouncement = 848,
// Add DSZ Tag
DSZ = 852,
// Add Tos Tag
Tos = 856,
// Add Target Rate
TargetRate = 890,
// // Add queue occupy rate
// QueueOccupyRate = 894,
// Add Downstream Rate
DownstreamRate = 894,
/**
* \brief Lower bound of 1-octet header field.
*/