aboutsummaryrefslogtreecommitdiffstats
path: root/libtransport/src/core
diff options
context:
space:
mode:
authorJordan Augé <jordan.auge+fdio@cisco.com>2022-09-21 17:11:22 +0200
committerJordan Augé <jordan.auge+fdio@cisco.com>2022-09-30 09:17:13 +0200
commit3476dd9ddecc87d9212c3bf56a5be52079e27def (patch)
tree3c7ea2664e8f99fc4fd4588b9e4493f0dc9bbb93 /libtransport/src/core
parent29647f687c8dadc90e2ba4d3a772eee09a1a4f1b (diff)
feat: support for new packet format in hicn-light
Ref: HICN-792 Change-Id: I3204006bd2dd2be6504c33035c6578ec0292455a Signed-off-by: Jordan Augé <jordan.auge+fdio@cisco.com>
Diffstat (limited to 'libtransport/src/core')
-rw-r--r--libtransport/src/core/packet.cc65
1 files changed, 7 insertions, 58 deletions
diff --git a/libtransport/src/core/packet.cc b/libtransport/src/core/packet.cc
index e670ecb54..bcd0b8498 100644
--- a/libtransport/src/core/packet.cc
+++ b/libtransport/src/core/packet.cc
@@ -41,9 +41,9 @@ Packet::Packet(Type type, Format format, std::size_t additional_header_size)
* We define the format and the storage area of the packet buffer we
* manipulate
*/
- setType(type);
setFormat(format);
setBuffer();
+ initializeType(type); // type requires packet format
initialize(additional_header_size);
}
@@ -142,6 +142,10 @@ void Packet::analyze() {
Packet::Type Packet::getType() const { return hicn_packet_get_type(&pkbuf_); }
+void Packet::initializeType(Packet::Type type) {
+ hicn_packet_initialize_type(&pkbuf_, type);
+}
+
void Packet::setType(Packet::Type type) { hicn_packet_set_type(&pkbuf_, type); }
void Packet::setBuffer() {
@@ -313,62 +317,7 @@ bool Packet::checkIntegrity() const {
return true;
}
-Packet &Packet::setSrcPort(uint16_t srcPort) {
- if (hicn_packet_set_src_port(&pkbuf_, srcPort) < 0) {
- throw errors::RuntimeException("Error setting source port in the packet.");
- }
-
- return *this;
-}
-
-Packet &Packet::setDstPort(uint16_t dstPort) {
- if (hicn_packet_set_dst_port(&pkbuf_, dstPort) < 0) {
- throw errors::RuntimeException(
- "Error setting destination port in the packet.");
- }
-
- return *this;
-}
-
-uint16_t Packet::getSrcPort() const {
- uint16_t port = 0;
-
- if (hicn_packet_get_src_port(&pkbuf_, &port) < 0) {
- throw errors::RuntimeException("Error reading source port in the packet.");
- }
-
- return port;
-}
-
-uint16_t Packet::getDstPort() const {
- uint16_t port = 0;
-
- if (hicn_packet_get_dst_port(&pkbuf_, &port) < 0) {
- throw errors::RuntimeException(
- "Error reading destination port in the packet.");
- }
-
- return port;
-}
-
-Packet &Packet::setTTL(uint8_t hops) {
- if (hicn_packet_set_ttl(&pkbuf_, hops) < 0) {
- throw errors::RuntimeException("Error setting TTL.");
- }
-
- return *this;
-}
-
-uint8_t Packet::getTTL() const {
- uint8_t hops = 0;
- if (hicn_packet_get_ttl(&pkbuf_, &hops) < 0) {
- throw errors::RuntimeException("Error reading TTL.");
- }
-
- return hops;
-}
-
-bool Packet::hasAH() const { return _is_ah(getFormat()); }
+bool Packet::hasAH() const { return HICN_PACKET_FORMAT_IS_AH(getFormat()); }
utils::MemBuf::Ptr Packet::getSignature() const {
if (!hasAH()) {
@@ -553,7 +502,7 @@ std::size_t Packet::getHeaderSizeFromFormat(Format format,
std::size_t signature_size) {
std::size_t header_length;
hicn_packet_get_header_length_from_format(format, &header_length);
- int is_ah = _is_ah(format);
+ int is_ah = HICN_PACKET_FORMAT_IS_AH(format);
return is_ah * (header_length + signature_size) + (!is_ah) * header_length;
}