Skip to content

Commit

Permalink
packet: encode ForwardingHint per 2021 spec
Browse files Browse the repository at this point in the history
2017 format is no longer accepted.
  • Loading branch information
yoursunny committed Jan 4, 2022
1 parent 6aef550 commit fbab97c
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Expand Up @@ -49,7 +49,7 @@ jobs:
uses: actions/checkout@v2
with:
repository: FDio/vpp
ref: v21.06
ref: v21.10.1
path: vpp
- name: install libmemif
run: |
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,6 +1,6 @@
ISC License

Copyright (c) 2020-2021, Junxiao Shi
Copyright (c) 2020-2022, Junxiao Shi

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
Expand Down
2 changes: 1 addition & 1 deletion library.properties
@@ -1,5 +1,5 @@
name=NDNph
version=0.0.20211208
version=0.0.20220104
author=Junxiao Shi
maintainer=Junxiao Shi
sentence=Named Data Networking packet headers.
Expand Down
2 changes: 0 additions & 2 deletions src/ndnph/packet/an.hpp
Expand Up @@ -32,8 +32,6 @@ enum
CanBePrefix = 0x21,
MustBeFresh = 0x12,
ForwardingHint = 0x1E,
Delegation = 0x1F,
Preference = 0x1E,
Nonce = 0x0A,
InterestLifetime = 0x0C,
HopLimit = 0x22,
Expand Down
12 changes: 2 additions & 10 deletions src/ndnph/packet/interest.hpp
Expand Up @@ -17,21 +17,13 @@ encodeFwHint(Encoder& encoder, const Name& fwHint)
if (!fwHint) {
return false;
}
return encoder.prependTlv(TT::ForwardingHint, [&fwHint](Encoder& encoder) {
return encoder.prependTlv(
TT::Delegation, [](Encoder& encoder) { encoder.prependTlv(TT::Preference, tlv::NNI(0)); },
fwHint);
});
return encoder.prependTlv(TT::ForwardingHint, fwHint);
}

inline bool
decodeFwHint(const Decoder::Tlv& d, Name* target)
{
return EvDecoder::decode(d, { TT::ForwardingHint },
EvDecoder::def<TT::Delegation>([target](const Decoder::Tlv& d) {
return EvDecoder::decode(d, {}, EvDecoder::defIgnore<TT::Preference>(),
EvDecoder::def<TT::Name>(target));
}));
return EvDecoder::decode(d, { TT::ForwardingHint }, EvDecoder::def<TT::Name>(target));
}

/** @brief Fields in parameterized/signed Interest. */
Expand Down
46 changes: 0 additions & 46 deletions src/ndnph/packet/name.hpp
Expand Up @@ -214,52 +214,6 @@ class Name : public Printable
return Name(encoder.begin(), encoder.size(), m_nComps + nComps);
}

/**
* @brief Append a sequence of components.
* @return new Name that copies TLV-VALUE of this name and all components.
* @retval Name() any Component is invalid or allocation error.
*
* If you need to append multiple components, it's recommended to append them all at once,
* so that memory allocation and copying occur only once.
*/
[[deprecated("append(region, comp, comp, ...)")]] Name append(
Region& region, std::initializer_list<Component> comps) const
{
size_t nComps = m_nComps, length = m_length;
for (const auto& comp : comps) {
if (!comp) {
return Name();
}
++nComps;
length += comp.size();
}

uint8_t* value = region.alloc(length);
if (value == nullptr) {
return Name();
}

uint8_t* pos = value;
pos = std::copy_n(m_value, m_length, pos);
for (const auto& comp : comps) {
pos = std::copy_n(comp.tlv(), comp.size(), pos);
}
return Name(value, length, nComps);
}

/**
* @brief Append a component from naming convention.
* @tparam Convention the naming convention.
* @return new Name that copies TLV-VALUE of this name and the new component.
* @retval Name() any Component is invalid or allocation error.
*/
template<typename Convention, typename Arg>
[[deprecated("append(region, Convention(), arg)")]] Name append(Region& region,
const Arg& arg) const
{
return append(region, Convention(), arg);
}

/**
* @brief Clone TLV-VALUE into given region.
* @return new Name that does not reference memory of this Name,
Expand Down
7 changes: 0 additions & 7 deletions tests/unit/packet/convention.t.cpp
Expand Up @@ -55,13 +55,6 @@ TEST(Convention, Segment)

uint64_t segment = name[-1].as<convention::Segment>();
EXPECT_EQ(segment, 700);

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
name = name.append<convention::Segment>(region, 701);
#pragma GCC diagnostic pop
EXPECT_EQ(test::toString(name[-1]), "50=%02%BD");
EXPECT_TRUE(name[-1].is<convention::Segment>());
}

} // namespace
Expand Down
23 changes: 11 additions & 12 deletions tests/unit/packet/interest.t.cpp
Expand Up @@ -59,18 +59,17 @@ TEST(Interest, EncodeFull)
ASSERT_FALSE(!interest);

std::vector<uint8_t> wire({
0x64, 0x2D, // LpPacket
0x62, 0x04, 0xB0, 0xB1, 0xB2, 0xB3, // PitToken
0x50, 0x25, // LpPayload
0x05, 0x23, // Interest
0x07, 0x03, 0x08, 0x01, 0x41, // Name
0x21, 0x00, // CanBePrefix
0x12, 0x00, // MustBeFresh
0x1E, 0x0B, 0x1F, 0x09, 0x1E, 0x01, 0x00, // ForwardingHint
0x07, 0x04, 0x08, 0x02, 0x66, 0x68, // ForwardingHint
0x0A, 0x04, 0xA0, 0xA1, 0xA2, 0xA3, // Nonce
0x0C, 0x02, 0x20, 0x06, // InterestLifetime
0x22, 0x01, 0x05, // HopLimit
0x64, 0x28, // LpPacket
0x62, 0x04, 0xB0, 0xB1, 0xB2, 0xB3, // PitToken
0x50, 0x20, // LpPayload
0x05, 0x1E, // Interest
0x07, 0x03, 0x08, 0x01, 0x41, // Name
0x21, 0x00, // CanBePrefix
0x12, 0x00, // MustBeFresh
0x1E, 0x06, 0x07, 0x04, 0x08, 0x02, 0x66, 0x68, // ForwardingHint
0x0A, 0x04, 0xA0, 0xA1, 0xA2, 0xA3, // Nonce
0x0C, 0x02, 0x20, 0x06, // InterestLifetime
0x22, 0x01, 0x05, // HopLimit
});
interest.setName(Name::parse(region, "/A"));
interest.setCanBePrefix(true);
Expand Down
7 changes: 0 additions & 7 deletions tests/unit/packet/name.t.cpp
Expand Up @@ -173,13 +173,6 @@ TEST(Name, Append)
EXPECT_THAT(std::vector<uint8_t>(name2.value(), name2.value() + name2.length()),
g::ElementsAreArray(wire));

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
name2 = name.append(region, { comp1, comp2, comp1, comp3 });
#pragma GCC diagnostic pop
EXPECT_THAT(std::vector<uint8_t>(name2.value(), name2.value() + name2.length()),
g::ElementsAreArray(wire));

name2 = name.append(region, comp1, Component(), comp2); // invalid component
EXPECT_FALSE(!!name2);
}
Expand Down

0 comments on commit fbab97c

Please sign in to comment.