diff options
author | Jordan Augé <jordan.auge+fdio@cisco.com> | 2022-09-21 17:11:22 +0200 |
---|---|---|
committer | Jordan Augé <jordan.auge+fdio@cisco.com> | 2022-09-30 09:17:13 +0200 |
commit | 3476dd9ddecc87d9212c3bf56a5be52079e27def (patch) | |
tree | 3c7ea2664e8f99fc4fd4588b9e4493f0dc9bbb93 /libtransport/src | |
parent | 29647f687c8dadc90e2ba4d3a772eee09a1a4f1b (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')
-rw-r--r-- | libtransport/src/core/packet.cc | 65 | ||||
-rw-r--r-- | libtransport/src/implementation/socket.cc | 21 | ||||
-rw-r--r-- | libtransport/src/implementation/socket.h | 1 | ||||
-rw-r--r-- | libtransport/src/implementation/socket_consumer.h | 11 | ||||
-rw-r--r-- | libtransport/src/implementation/socket_producer.h | 10 | ||||
-rw-r--r-- | libtransport/src/interfaces/socket_consumer.cc | 10 | ||||
-rw-r--r-- | libtransport/src/interfaces/socket_producer.cc | 10 | ||||
-rw-r--r-- | libtransport/src/protocols/prod_protocol_rtc.cc | 2 | ||||
-rw-r--r-- | libtransport/src/protocols/rtc/rtc_verifier.cc | 2 | ||||
-rw-r--r-- | libtransport/src/protocols/transport_protocol.cc | 2 | ||||
-rw-r--r-- | libtransport/src/test/test_auth.cc | 8 | ||||
-rw-r--r-- | libtransport/src/test/test_packet.cc | 243 |
12 files changed, 128 insertions, 257 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; } diff --git a/libtransport/src/implementation/socket.cc b/libtransport/src/implementation/socket.cc index 8e9760a5d..c554d09d3 100644 --- a/libtransport/src/implementation/socket.cc +++ b/libtransport/src/implementation/socket.cc @@ -23,34 +23,17 @@ namespace implementation { Socket::Socket(std::shared_ptr<core::Portal> &&portal) : portal_(std::move(portal)), is_async_(false), - packet_format_(interface::default_values::packet_format), signer_(std::make_shared<auth::VoidSigner>()), verifier_(std::make_shared<auth::VoidVerifier>()) {} int Socket::setSocketOption(int socket_option_key, hicn_packet_format_t packet_format) { - switch (socket_option_key) { - case interface::GeneralTransportOptions::PACKET_FORMAT: - packet_format_ = packet_format; - break; - default: - return SOCKET_OPTION_NOT_SET; - } - - return SOCKET_OPTION_SET; + return SOCKET_OPTION_NOT_SET; } int Socket::getSocketOption(int socket_option_key, hicn_packet_format_t &packet_format) { - switch (socket_option_key) { - case interface::GeneralTransportOptions::PACKET_FORMAT: - packet_format = packet_format_; - break; - default: - return SOCKET_OPTION_NOT_GET; - } - - return SOCKET_OPTION_GET; + return SOCKET_OPTION_NOT_GET; } } // namespace implementation diff --git a/libtransport/src/implementation/socket.h b/libtransport/src/implementation/socket.h index 55132eb75..d0d2ba2ac 100644 --- a/libtransport/src/implementation/socket.h +++ b/libtransport/src/implementation/socket.h @@ -71,7 +71,6 @@ class Socket { protected: std::shared_ptr<core::Portal> portal_; bool is_async_; - hicn_packet_format_t packet_format_; std::shared_ptr<auth::Signer> signer_; std::shared_ptr<auth::Verifier> verifier_; }; diff --git a/libtransport/src/implementation/socket_consumer.h b/libtransport/src/implementation/socket_consumer.h index 4721f426c..3117e21e7 100644 --- a/libtransport/src/implementation/socket_consumer.h +++ b/libtransport/src/implementation/socket_consumer.h @@ -39,6 +39,7 @@ class ConsumerSocket : public Socket { std::shared_ptr<core::Portal> &&portal) : Socket(std::move(portal)), consumer_interface_(consumer), + packet_format_(default_values::packet_format), interest_lifetime_(default_values::interest_lifetime), min_window_size_(default_values::min_window_size), max_window_size_(default_values::max_window_size), @@ -273,6 +274,10 @@ class ConsumerSocket : public Socket { manifest_factor_alert_ = socket_option_value; break; + case GeneralTransportOptions::PACKET_FORMAT: + packet_format_ = socket_option_value; + break; + default: return SOCKET_OPTION_NOT_SET; } @@ -318,7 +323,6 @@ class ConsumerSocket : public Socket { on_content_object_input_ = VOID_HANDLER; break; } - default: return SOCKET_OPTION_NOT_SET; } @@ -602,6 +606,10 @@ class ConsumerSocket : public Socket { socket_option_value = manifest_factor_alert_; break; + case GeneralTransportOptions::PACKET_FORMAT: + socket_option_value = packet_format_; + break; + default: return SOCKET_OPTION_NOT_GET; } @@ -854,6 +862,7 @@ class ConsumerSocket : public Socket { // set from the consume Name network_name_; + hicn_packet_format_t packet_format_; int interest_lifetime_; double min_window_size_; diff --git a/libtransport/src/implementation/socket_producer.h b/libtransport/src/implementation/socket_producer.h index 53ce28766..c5e0929b2 100644 --- a/libtransport/src/implementation/socket_producer.h +++ b/libtransport/src/implementation/socket_producer.h @@ -48,6 +48,7 @@ class ProducerSocket : public Socket { std::shared_ptr<core::Portal> &&portal) : Socket(std::move(portal)), producer_interface_(producer_socket), + packet_format_(default_values::packet_format), data_packet_size_(default_values::content_object_packet_size), max_segment_size_(default_values::content_object_packet_size), content_object_expiry_time_(default_values::content_object_expiry_time), @@ -199,6 +200,10 @@ class ProducerSocket : public Socket { content_object_expiry_time_ = socket_option_value; break; + case GeneralTransportOptions::PACKET_FORMAT: + packet_format_ = socket_option_value; + break; + default: return SOCKET_OPTION_NOT_SET; } @@ -490,6 +495,10 @@ class ProducerSocket : public Socket { socket_option_value = content_object_expiry_time_; break; + case GeneralTransportOptions::PACKET_FORMAT: + socket_option_value = packet_format_; + break; + default: return SOCKET_OPTION_NOT_SET; } @@ -758,6 +767,7 @@ class ProducerSocket : public Socket { // Threads protected: interface::ProducerSocket *producer_interface_; + std::atomic<hicn_packet_format_t> packet_format_; std::atomic<size_t> data_packet_size_; std::atomic<size_t> max_segment_size_; std::atomic<uint32_t> content_object_expiry_time_; diff --git a/libtransport/src/interfaces/socket_consumer.cc b/libtransport/src/interfaces/socket_consumer.cc index cc496c8a5..afb672c95 100644 --- a/libtransport/src/interfaces/socket_consumer.cc +++ b/libtransport/src/interfaces/socket_consumer.cc @@ -127,11 +127,6 @@ int ConsumerSocket::setSocketOption(int socket_option_key, return socket_->setSocketOption(socket_option_key, socket_option_value); } -int ConsumerSocket::setSocketOption(int socket_option_key, - Packet::Format socket_option_value) { - return socket_->setSocketOption(socket_option_key, socket_option_value); -} - int ConsumerSocket::getSocketOption(int socket_option_key, double &socket_option_value) { return socket_->getSocketOption(socket_option_key, socket_option_value); @@ -200,11 +195,6 @@ int ConsumerSocket::getSocketOption(int socket_option_key, return socket_->getSocketOption(socket_option_key, socket_option_value); } -int ConsumerSocket::getSocketOption(int socket_option_key, - Packet::Format &socket_option_value) { - return socket_->getSocketOption(socket_option_key, socket_option_value); -} - } // namespace interface } // namespace transport diff --git a/libtransport/src/interfaces/socket_producer.cc b/libtransport/src/interfaces/socket_producer.cc index 2155ebd78..77e3bf633 100644 --- a/libtransport/src/interfaces/socket_producer.cc +++ b/libtransport/src/interfaces/socket_producer.cc @@ -154,11 +154,6 @@ int ProducerSocket::setSocketOption( return socket_->setSocketOption(socket_option_key, socket_option_value); } -int ProducerSocket::setSocketOption(int socket_option_key, - Packet::Format socket_option_value) { - return socket_->setSocketOption(socket_option_key, socket_option_value); -} - int ProducerSocket::getSocketOption(int socket_option_key, uint32_t &socket_option_value) { return socket_->getSocketOption(socket_option_key, socket_option_value); @@ -206,11 +201,6 @@ int ProducerSocket::getSocketOption( return socket_->getSocketOption(socket_option_key, socket_option_value); } -int ProducerSocket::getSocketOption(int socket_option_key, - Packet::Format &socket_option_value) { - return socket_->getSocketOption(socket_option_key, socket_option_value); -} - } // namespace interface } // namespace transport diff --git a/libtransport/src/protocols/prod_protocol_rtc.cc b/libtransport/src/protocols/prod_protocol_rtc.cc index aebad23d6..83cd23ac6 100644 --- a/libtransport/src/protocols/prod_protocol_rtc.cc +++ b/libtransport/src/protocols/prod_protocol_rtc.cc @@ -692,7 +692,7 @@ void RTCProductionProtocol::sendNack(uint32_t sequence) { void RTCProductionProtocol::sendContentObject( std::shared_ptr<ContentObject> content_object, bool nack, bool fec) { - bool is_ah = _is_ah(content_object->getFormat()); + bool is_ah = HICN_PACKET_FORMAT_IS_AH(content_object->getFormat()); // Compute signature if (is_ah) { diff --git a/libtransport/src/protocols/rtc/rtc_verifier.cc b/libtransport/src/protocols/rtc/rtc_verifier.cc index 861ceee89..60fce92a5 100644 --- a/libtransport/src/protocols/rtc/rtc_verifier.cc +++ b/libtransport/src/protocols/rtc/rtc_verifier.cc @@ -106,7 +106,7 @@ auth::VerificationPolicy RTCVerifier::verifyFec( auth::VerificationPolicy RTCVerifier::verifyData( core::ContentObject &content_object) { - if (_is_ah(content_object.getFormat())) { + if (HICN_PACKET_FORMAT_IS_AH(content_object.getFormat())) { return verifier_->verifyPackets(&content_object); } diff --git a/libtransport/src/protocols/transport_protocol.cc b/libtransport/src/protocols/transport_protocol.cc index 5b262e4e7..29d140454 100644 --- a/libtransport/src/protocols/transport_protocol.cc +++ b/libtransport/src/protocols/transport_protocol.cc @@ -179,7 +179,7 @@ void TransportProtocol::sendInterest( if (content_sharing_mode) lifetime = ceil((double)lifetime * 0.9); // Compute signature - bool is_ah = _is_ah(interest->getFormat()); + bool is_ah = HICN_PACKET_FORMAT_IS_AH(interest->getFormat()); if (is_ah) signer_->signPacket(interest.get()); portal_->sendInterest(interest, lifetime); diff --git a/libtransport/src/test/test_auth.cc b/libtransport/src/test/test_auth.cc index 5b9b04c5c..2ee3c0776 100644 --- a/libtransport/src/test/test_auth.cc +++ b/libtransport/src/test/test_auth.cc @@ -88,7 +88,7 @@ TEST_F(AuthTest, AsymmetricRSA) { std::shared_ptr<Verifier> verifier = std::make_shared<AsymmetricVerifier>(pubKey); - EXPECT_EQ(packet.getFormat().as_u32, HICN_PACKET_FORMAT_IPV6_TCP_AH.as_u32); + EXPECT_EQ(packet.getFormat(), HICN_PACKET_FORMAT_IPV6_TCP_AH); EXPECT_EQ(signer->getHashType(), CryptoHashType::SHA256); EXPECT_EQ(signer->getSuite(), CryptoSuite::RSA_SHA256); EXPECT_EQ(signer->getSignatureSize(), 256u); @@ -202,7 +202,7 @@ TEST_F(AuthTest, AsymmetricVerifierDSA) { std::shared_ptr<Verifier> verifier = std::make_shared<AsymmetricVerifier>(cert); - EXPECT_EQ(packet.getFormat().as_u32, HICN_PACKET_FORMAT_IPV6_TCP_AH.as_u32); + EXPECT_EQ(packet.getFormat(), HICN_PACKET_FORMAT_IPV6_TCP_AH); EXPECT_EQ(signer->getHashType(), CryptoHashType::SHA256); EXPECT_EQ(signer->getSuite(), CryptoSuite::DSA_SHA256); EXPECT_EQ(verifier->verifyPackets(&packet), VerificationPolicy::ACCEPT); @@ -269,7 +269,7 @@ TEST_F(AuthTest, AsymmetricVerifierECDSA) { packet.appendPayload(buffer, 256); signer->signPacket(&packet); - EXPECT_EQ(packet.getFormat().as_u32, HICN_PACKET_FORMAT_IPV6_TCP_AH.as_u32); + EXPECT_EQ(packet.getFormat(), HICN_PACKET_FORMAT_IPV6_TCP_AH); EXPECT_EQ(signer->getHashType(), CryptoHashType::SHA256); EXPECT_EQ(signer->getSuite(), CryptoSuite::ECDSA_SHA256); EXPECT_EQ(verifier->verifyPackets(&packet), VerificationPolicy::ACCEPT); @@ -314,7 +314,7 @@ TEST_F(AuthTest, HMACVerifier) { std::shared_ptr<Verifier> verifier = std::make_shared<SymmetricVerifier>(PASSPHRASE); - EXPECT_EQ(packet.getFormat().as_u32, HICN_PACKET_FORMAT_IPV6_TCP_AH.as_u32); + EXPECT_EQ(packet.getFormat(), HICN_PACKET_FORMAT_IPV6_TCP_AH); EXPECT_EQ(signer->getHashType(), CryptoHashType::SHA256); EXPECT_EQ(signer->getSuite(), CryptoSuite::HMAC_SHA256); EXPECT_EQ(signer->getSignatureSize(), 32u); diff --git a/libtransport/src/test/test_packet.cc b/libtransport/src/test/test_packet.cc index 3dfca8f9a..f2f658932 100644 --- a/libtransport/src/test/test_packet.cc +++ b/libtransport/src/test/test_packet.cc @@ -76,8 +76,8 @@ class PacketTest : public ::testing::Test { PacketTest() : name_("b001::123|321"), packet(Packet::COPY_BUFFER, - &raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32][0], - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size()) { + &raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP][0], + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP].size()) { // You can do set-up work for each test here. } @@ -119,7 +119,7 @@ class PacketTest : public ::testing::Test { }; std::map<uint32_t, std::vector<uint8_t>> PacketTest::raw_packets_ = { - {HICN_PACKET_FORMAT_IPV6_TCP.as_u32, + {HICN_PACKET_FORMAT_IPV6_TCP, {// IPv6 src=b001::ab:cdab:cdef, dst=b002::ca IPV6_HEADER(TCP_PROTO, 20 + PAYLOAD_SIZE), @@ -128,7 +128,7 @@ std::map<uint32_t, std::vector<uint8_t>> PacketTest::raw_packets_ = { // Payload PAYLOAD}}, - {HICN_PACKET_FORMAT_IPV4_TCP.as_u32, + {HICN_PACKET_FORMAT_IPV4_TCP, {// IPv4 src=3.13.127.8, dst=192.168.1.92 IPV4_HEADER(TCP_PROTO, 20 + PAYLOAD_SIZE), // TCP src=0x1234 dst=0x4321, seq=0x0001 @@ -136,19 +136,19 @@ std::map<uint32_t, std::vector<uint8_t>> PacketTest::raw_packets_ = { // Other PAYLOAD}}, - {HICN_PACKET_FORMAT_IPV4_ICMP.as_u32, + {HICN_PACKET_FORMAT_IPV4_ICMP, {// IPv4 src=3.13.127.8, dst=192.168.1.92 IPV4_HEADER(ICMP_PROTO, 64), // ICMP echo request ICMP_ECHO_REQUEST}}, - {HICN_PACKET_FORMAT_IPV6_ICMP.as_u32, + {HICN_PACKET_FORMAT_IPV6_ICMP, {// IPv6 src=b001::ab:cdab:cdef, dst=b002::ca IPV6_HEADER(ICMP6_PROTO, 60), // ICMP6 echo request ICMP6_ECHO_REQUEST}}, - {HICN_PACKET_FORMAT_IPV6_TCP_AH.as_u32, + {HICN_PACKET_FORMAT_IPV6_TCP_AH, {// IPv6 src=b001::ab:cdab:cdef, dst=b002::ca IPV6_HEADER(TCP_PROTO, 20 + 44 + 128), // ICMP6 echo request @@ -156,7 +156,7 @@ std::map<uint32_t, std::vector<uint8_t>> PacketTest::raw_packets_ = { // hICN AH header AH_HEADER, SIGNATURE}}, - {HICN_PACKET_FORMAT_IPV4_TCP_AH.as_u32, + {HICN_PACKET_FORMAT_IPV4_TCP_AH, {// IPv6 src=b001::ab:cdab:cdef, dst=b002::ca IPV4_HEADER(TCP_PROTO, 20 + 44 + 128), // ICMP6 echo request @@ -165,7 +165,7 @@ std::map<uint32_t, std::vector<uint8_t>> PacketTest::raw_packets_ = { AH_HEADER, SIGNATURE}}, // XXX No flag defined in ICMP header to signal AH header. - {HICN_PACKET_FORMAT_IPV4_ICMP_AH.as_u32, + {HICN_PACKET_FORMAT_IPV4_ICMP_AH, {// IPv6 src=b001::ab:cdab:cdef, dst=b002::ca IPV4_HEADER(ICMP_PROTO, 64 + 44), // ICMP6 echo request @@ -173,7 +173,7 @@ std::map<uint32_t, std::vector<uint8_t>> PacketTest::raw_packets_ = { // hICN AH header AH_HEADER, SIGNATURE}}, - {HICN_PACKET_FORMAT_IPV6_ICMP_AH.as_u32, + {HICN_PACKET_FORMAT_IPV6_ICMP_AH, {// IPv6 src=b001::ab:cdab:cdef, dst=b002::ca IPV6_HEADER(ICMP6_PROTO, 60 + 44), // ICMP6 echo request @@ -213,7 +213,7 @@ void testRawBufferConstructor(std::vector<uint8_t> packet, packet.size()); // Check format is expected one. - EXPECT_EQ(p.getFormat().as_u32, format.as_u32); + EXPECT_EQ(p.getFormat(), format); // // Try the same using a MemBuf // auto buf = utils::MemBuf::wrapBuffer(&packet[0], packet.size()); @@ -237,7 +237,7 @@ void testRawBufferConstructor(std::vector<uint8_t> packet, packet.size()); // Format should fallback to HICN_PACKET_FORMAT_NONE - EXPECT_EQ(p.getFormat().as_u32, HICN_PACKET_FORMAT_NONE.as_u32); + EXPECT_EQ(p.getFormat(), HICN_PACKET_FORMAT_NONE); } catch (errors::MalformedPacketException &exc) { // Ok right exception } catch (...) { @@ -267,7 +267,7 @@ void getPayloadSizeFromBuffer(std::vector<uint8_t> &packet, void getFormatFromBuffer(Packet::Format expected, std::vector<uint8_t> &packet) { auto format = PacketForTest::getFormatFromBuffer(&packet[0], packet.size()); - EXPECT_EQ(format.as_u32, expected.as_u32); + EXPECT_EQ(format, expected); } void getHeaderSize(std::size_t expected, const PacketForTest &packet) { @@ -277,7 +277,7 @@ void getHeaderSize(std::size_t expected, const PacketForTest &packet) { void testGetFormat(Packet::Format expected, const Packet &packet) { auto format = packet.getFormat(); - EXPECT_EQ(format.as_u32, expected.as_u32); + EXPECT_EQ(format, expected); } } // namespace @@ -306,7 +306,7 @@ TEST_F(PacketTest, ConstructorWithFormatAndAdditionalHeader) { } TEST_F(PacketTest, ConstructorWithNew) { - auto &_packet = raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32]; + auto &_packet = raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP]; auto packet_ptr = new PacketForTest(Packet::WRAP_BUFFER, &_packet[0], _packet.size(), _packet.size()); delete packet_ptr; @@ -314,53 +314,53 @@ TEST_F(PacketTest, ConstructorWithNew) { TEST_F(PacketTest, ConstructorWithRawBufferInet6Tcp) { auto format = HICN_PACKET_FORMAT_IPV6_TCP; - testRawBufferConstructor(raw_packets_[format.as_u32], format); + testRawBufferConstructor(raw_packets_[format], format); } TEST_F(PacketTest, ConstructorWithRawBufferInetTcp) { auto format = HICN_PACKET_FORMAT_IPV4_TCP; - testRawBufferConstructor(raw_packets_[format.as_u32], format); + testRawBufferConstructor(raw_packets_[format], format); } TEST_F(PacketTest, ConstructorWithRawBufferInetIcmp) { auto format = HICN_PACKET_FORMAT_IPV4_ICMP; - testRawBufferConstructor(raw_packets_[format.as_u32], format); + testRawBufferConstructor(raw_packets_[format], format); } TEST_F(PacketTest, ConstructorWithRawBufferInet6Icmp) { auto format = HICN_PACKET_FORMAT_IPV6_ICMP; - testRawBufferConstructor(raw_packets_[format.as_u32], format); + testRawBufferConstructor(raw_packets_[format], format); } TEST_F(PacketTest, ConstructorWithRawBufferInet6TcpAh) { auto format = HICN_PACKET_FORMAT_IPV6_TCP_AH; - testRawBufferConstructor(raw_packets_[format.as_u32], format); + testRawBufferConstructor(raw_packets_[format], format); } TEST_F(PacketTest, ConstructorWithRawBufferInetTcpAh) { auto format = HICN_PACKET_FORMAT_IPV4_TCP_AH; - testRawBufferConstructor(raw_packets_[format.as_u32], format); + testRawBufferConstructor(raw_packets_[format], format); } TEST_F(PacketTest, MoveConstructor) { PacketForTest p0(HICN_PACKET_TYPE_INTEREST, HICN_PACKET_FORMAT_IPV6_TCP); PacketForTest p1(std::move(p0)); - EXPECT_EQ(p0.getFormat().as_u32, HICN_PACKET_FORMAT_NONE.as_u32); - EXPECT_EQ(p1.getFormat().as_u32, HICN_PACKET_FORMAT_IPV6_TCP.as_u32); + EXPECT_EQ(p0.getFormat(), HICN_PACKET_FORMAT_NONE); + EXPECT_EQ(p1.getFormat(), HICN_PACKET_FORMAT_IPV6_TCP); } TEST_F(PacketTest, TestGetHeaderSizeFromBuffer) { - getHeaderSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32], + getHeaderSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP], IPV6_HDRLEN + TCP_HDRLEN); - getHeaderSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP.as_u32], + getHeaderSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP], IPV4_HDRLEN + TCP_HDRLEN); - getHeaderSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP.as_u32], + getHeaderSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP], IPV6_HDRLEN + 4); - getHeaderSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV4_ICMP.as_u32], + getHeaderSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV4_ICMP], IPV4_HDRLEN + 4); - getHeaderSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP_AH.as_u32], + getHeaderSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP_AH], IPV6_HDRLEN + TCP_HDRLEN + AH_HDRLEN + 128); - getHeaderSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP_AH.as_u32], + getHeaderSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP_AH], IPV4_HDRLEN + TCP_HDRLEN + AH_HDRLEN + 128); } @@ -378,23 +378,17 @@ TEST_F(PacketTest, TestGetHeaderSizeFromFormat) { } TEST_F(PacketTest, TestGetPayloadSizeFromBuffer) { - getPayloadSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32], - 12); - getPayloadSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP.as_u32], - 12); - getPayloadSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP.as_u32], - 56); - getPayloadSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV4_ICMP.as_u32], - 60); - getPayloadSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP_AH.as_u32], - 0); - getPayloadSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP_AH.as_u32], - 0); + getPayloadSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP], 12); + getPayloadSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP], 12); + getPayloadSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP], 56); + getPayloadSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV4_ICMP], 60); + getPayloadSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP_AH], 0); + getPayloadSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP_AH], 0); } #if 0 TEST_F(PacketTest, TestIsInterest) { - auto ret = PacketForTest::isInterest(&raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32][0]); + auto ret = PacketForTest::isInterest(&raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP][0]); EXPECT_TRUE(ret); } @@ -402,27 +396,27 @@ TEST_F(PacketTest, TestIsInterest) { TEST_F(PacketTest, TestGetFormatFromBuffer) { getFormatFromBuffer(HICN_PACKET_FORMAT_IPV6_TCP, - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32]); + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP]); getFormatFromBuffer(HICN_PACKET_FORMAT_IPV4_TCP, - raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP.as_u32]); + raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP]); getFormatFromBuffer(HICN_PACKET_FORMAT_IPV6_ICMP, - raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP.as_u32]); + raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP]); getFormatFromBuffer(HICN_PACKET_FORMAT_IPV4_ICMP, - raw_packets_[HICN_PACKET_FORMAT_IPV4_ICMP.as_u32]); + raw_packets_[HICN_PACKET_FORMAT_IPV4_ICMP]); getFormatFromBuffer(HICN_PACKET_FORMAT_IPV6_TCP_AH, - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP_AH.as_u32]); + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP_AH]); getFormatFromBuffer(HICN_PACKET_FORMAT_IPV4_TCP_AH, - raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP_AH.as_u32]); + raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP_AH]); } // TEST_F(PacketTest, TestReplace) { // PacketForTest packet(Packet::WRAP_BUFFER, -// &raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32][0], -// raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size()); +// &raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP][0], +// raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP].size()); // // Replace current packet with another one -// packet.replace(&raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP.as_u32][0], -// raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP.as_u32].size()); +// packet.replace(&raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP][0], +// raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP].size()); // // Check new format // ASSERT_EQ(packet.getFormat(), HICN_PACKET_FORMAT_IPV4_TCP); @@ -430,7 +424,7 @@ TEST_F(PacketTest, TestGetFormatFromBuffer) { TEST_F(PacketTest, TestPayloadSize) { // Check payload size of existing packet - auto &_packet = raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32]; + auto &_packet = raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP]; PacketForTest packet(Packet::WRAP_BUFFER, &_packet[0], _packet.size(), _packet.size()); @@ -489,7 +483,7 @@ TEST_F(PacketTest, TestHeaderSize) { TEST_F(PacketTest, TestMemBufReference) { // Create packet - auto &_packet = raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32]; + auto &_packet = raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP]; // Packet was not created as a shared_ptr. If we try to get a membuf shared // ptr we should get an exception. @@ -530,9 +524,8 @@ TEST_F(PacketTest, TestMemBufReference) { TEST_F(PacketTest, TestReset) { // Check everything is ok - EXPECT_EQ(packet.getFormat().as_u32, HICN_PACKET_FORMAT_IPV6_TCP.as_u32); - EXPECT_EQ(packet.length(), - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size()); + EXPECT_EQ(packet.getFormat(), HICN_PACKET_FORMAT_IPV6_TCP); + EXPECT_EQ(packet.length(), raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP].size()); EXPECT_EQ(packet.headerSize(), IPV6_HDRLEN + TCP_HDRLEN); EXPECT_EQ(packet.payloadSize(), packet.length() - packet.headerSize()); @@ -540,7 +533,7 @@ TEST_F(PacketTest, TestReset) { packet.reset(); // Rerun test - EXPECT_EQ(packet.getFormat().as_u32, HICN_PACKET_FORMAT_NONE.as_u32); + EXPECT_EQ(packet.getFormat(), HICN_PACKET_FORMAT_NONE); EXPECT_EQ(packet.length(), std::size_t(0)); EXPECT_EQ(packet.headerSize(), std::size_t(0)); EXPECT_EQ(packet.payloadSize(), std::size_t(0)); @@ -581,7 +574,7 @@ TEST_F(PacketTest, TestAppendPayload) { // There should be no more bufferls left in the chain EXPECT_EQ(&packet, packet.next()); - EXPECT_EQ(packet.getFormat().as_u32, HICN_PACKET_FORMAT_NONE.as_u32); + EXPECT_EQ(packet.getFormat(), HICN_PACKET_FORMAT_NONE); EXPECT_EQ(packet.length(), std::size_t(0)); EXPECT_EQ(packet.headerSize(), std::size_t(0)); EXPECT_EQ(packet.payloadSize(), std::size_t(0)); @@ -655,41 +648,39 @@ TEST_F(PacketTest, SetGetPayloadType) { TEST_F(PacketTest, GetFormat) { { PacketForTest p0(Packet::WRAP_BUFFER, - &raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP.as_u32][0], - raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP.as_u32].size(), - raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP.as_u32].size()); + &raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP][0], + raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP].size(), + raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP].size()); testGetFormat(HICN_PACKET_FORMAT_IPV4_TCP, p0); PacketForTest p1(Packet::WRAP_BUFFER, - &raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32][0], - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size(), - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size()); + &raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP][0], + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP].size(), + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP].size()); testGetFormat(HICN_PACKET_FORMAT_IPV6_TCP, p1); PacketForTest p2(Packet::WRAP_BUFFER, - &raw_packets_[HICN_PACKET_FORMAT_IPV4_ICMP.as_u32][0], - raw_packets_[HICN_PACKET_FORMAT_IPV4_ICMP.as_u32].size(), - raw_packets_[HICN_PACKET_FORMAT_IPV4_ICMP.as_u32].size()); + &raw_packets_[HICN_PACKET_FORMAT_IPV4_ICMP][0], + raw_packets_[HICN_PACKET_FORMAT_IPV4_ICMP].size(), + raw_packets_[HICN_PACKET_FORMAT_IPV4_ICMP].size()); testGetFormat(HICN_PACKET_FORMAT_IPV4_ICMP, p2); PacketForTest p3(Packet::WRAP_BUFFER, - &raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP.as_u32][0], - raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP.as_u32].size(), - raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP.as_u32].size()); + &raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP][0], + raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP].size(), + raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP].size()); testGetFormat(HICN_PACKET_FORMAT_IPV6_ICMP, p3); - PacketForTest p4( - Packet::WRAP_BUFFER, - &raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP_AH.as_u32][0], - raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP_AH.as_u32].size(), - raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP_AH.as_u32].size()); + PacketForTest p4(Packet::WRAP_BUFFER, + &raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP_AH][0], + raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP_AH].size(), + raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP_AH].size()); testGetFormat(HICN_PACKET_FORMAT_IPV4_TCP_AH, p4); - PacketForTest p5( - Packet::WRAP_BUFFER, - &raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP_AH.as_u32][0], - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP_AH.as_u32].size(), - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP_AH.as_u32].size()); + PacketForTest p5(Packet::WRAP_BUFFER, + &raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP_AH][0], + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP_AH].size(), + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP_AH].size()); testGetFormat(HICN_PACKET_FORMAT_IPV6_TCP_AH, p5); } @@ -848,83 +839,39 @@ TEST_F(PacketTest, DISABLED_TestChecksum) { EXPECT_TRUE(integrity); } -TEST_F(PacketTest, TestSetGetSrcPort) { - try { - auto p = - PacketForTest(Packet::WRAP_BUFFER, - &raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP.as_u32][0], - raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP.as_u32].size(), - raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP.as_u32].size()); - // Let's make compiler happy - p.setSrcPort(12345); - FAIL() << "We should not reach this point."; - } catch (const errors::RuntimeException &exc) { - /* ok right exception*/ - } catch (...) { - FAIL() << "Unexpected exception"; - } - - packet.setSrcPort(12345); - EXPECT_EQ(packet.getSrcPort(), 12345); -} - -TEST_F(PacketTest, TestSetGetDstPort) { - try { - auto p = - PacketForTest(Packet::WRAP_BUFFER, - &raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP.as_u32][0], - raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP.as_u32].size(), - raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP.as_u32].size()); - // Let's make compiler happy - p.setDstPort(12345); - FAIL() << "We should not reach this point."; - } catch (const errors::RuntimeException &exc) { - /* ok right exception*/ - } catch (...) { - FAIL() << "Unexpected exception"; - } - - packet.setDstPort(12345); - EXPECT_EQ(packet.getDstPort(), 12345); -} - TEST_F(PacketTest, TestEnsureCapacity) { PacketForTest &p = packet; // This shoul be false - auto ret = p.ensureCapacity( - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size() + 10); + auto ret = + p.ensureCapacity(raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP].size() + 10); EXPECT_FALSE(ret); // This should be true - ret = - p.ensureCapacity(raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size()); + ret = p.ensureCapacity(raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP].size()); EXPECT_TRUE(ret); // This should be true - ret = p.ensureCapacity( - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size() - 10); + ret = p.ensureCapacity(raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP].size() - 10); EXPECT_TRUE(ret); // Try to trim the packet start p.trimStart(10); // Now this should be false - ret = - p.ensureCapacity(raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size()); + ret = p.ensureCapacity(raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP].size()); EXPECT_FALSE(ret); // Create a new packet - auto p2 = - PacketForTest(Packet::WRAP_BUFFER, - &raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP.as_u32][0], - raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP.as_u32].size(), - raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP.as_u32].size()); + auto p2 = PacketForTest(Packet::WRAP_BUFFER, + &raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP][0], + raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP].size(), + raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP].size()); p2.appendPayload(utils::MemBuf::createCombined(2000)); // This should be false, since the buffer is chained - ret = p2.ensureCapacity( - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size() - 10); + ret = + p2.ensureCapacity(raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP].size() - 10); EXPECT_FALSE(ret); } @@ -936,21 +883,20 @@ TEST_F(PacketTest, DISABLED_TestEnsureCapacityAndFillUnused) { // Create packet by excluding the payload (So only L3 + L4 headers). The // payload will be trated as unused tailroom PacketForTest p = PacketForTest( - Packet::WRAP_BUFFER, &raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32][0], - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size() - PAYLOAD_SIZE, - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size()); + Packet::WRAP_BUFFER, &raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP][0], + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP].size() - PAYLOAD_SIZE, + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP].size()); // Copy original packet payload, which is here trated as a unused tailroom uint8_t original_payload[PAYLOAD_SIZE]; - uint8_t *payload = &raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32][0] + - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size() - + uint8_t *payload = &raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP][0] + + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP].size() - PAYLOAD_SIZE; std::memcpy(original_payload, payload, PAYLOAD_SIZE); // This should be true and the unused tailroom should be unmodified auto ret = p.ensureCapacityAndFillUnused( - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size() - - (PAYLOAD_SIZE + 10), + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP].size() - (PAYLOAD_SIZE + 10), 0); EXPECT_TRUE(ret); ret = std::memcmp(original_payload, payload, PAYLOAD_SIZE); @@ -958,7 +904,7 @@ TEST_F(PacketTest, DISABLED_TestEnsureCapacityAndFillUnused) { // This should fill the payload with zeros ret = p.ensureCapacityAndFillUnused( - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size(), 0); + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP].size(), 0); EXPECT_TRUE(ret); uint8_t zeros[PAYLOAD_SIZE]; std::memset(zeros, 0, PAYLOAD_SIZE); @@ -967,7 +913,7 @@ TEST_F(PacketTest, DISABLED_TestEnsureCapacityAndFillUnused) { // This should fill the payload with ones ret = p.ensureCapacityAndFillUnused( - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size(), 1); + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP].size(), 1); EXPECT_TRUE(ret); uint8_t ones[PAYLOAD_SIZE]; std::memset(ones, 1, PAYLOAD_SIZE); @@ -976,16 +922,11 @@ TEST_F(PacketTest, DISABLED_TestEnsureCapacityAndFillUnused) { // This should return false and the payload should be unmodified ret = p.ensureCapacityAndFillUnused( - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size() + 1, 1); + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP].size() + 1, 1); EXPECT_FALSE(ret); ret = std::memcmp(payload, ones, PAYLOAD_SIZE); EXPECT_EQ(ret, 0); } -TEST_F(PacketTest, TestSetGetTTL) { - packet.setTTL(128); - EXPECT_EQ(packet.getTTL(), 128); -} - } // namespace core } // namespace transport |