add src/TinsNetworkInterfaceCard_t.h (send pdu and store their hash in a thread safe list)

This commit is contained in:
stubbfel
2017-03-02 00:14:53 +01:00
parent 1664136d14
commit 1f40e10d5c
6 changed files with 233 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
#include "fakeit.hpp"
#include "tins/ethernetII.h"
#include <fakeit.hpp>
#include <tins/ethernetII.h>
#include <tins/ip.h>
#include <tins/ipv6.h>
#include <tins/ip_address.h>
@@ -7,8 +7,11 @@
#include <tins/tcp.h>
#include "Ip6ToIp4PacketHandler.h"
#include "IpAddressTranslator.h"
#include "TinsNetworkInterfaceCard_t.h"
using namespace fakeit;
namespace TestIp6ToIp4PacketHandler
{
Tins::PDU * currentInputPdu = nullptr;
@@ -57,4 +60,22 @@ TEST_CASE( "test Ip6ToIp4PacketHandler", "[Ip6ToIp4PacketHandler]" ) {
pkt = Tins::EthernetII("11:22:33:44:55:66", "66:55:44:33:22:11") / Tins::IPv6("::1", "::2") / Tins::TCP();
REQUIRE(handler.handle(pkt, &mockHandler.get()) == true);
Verify(Method(mockHandler, handle)).Twice();
// test pkt hashes
Tins::EthernetII * clonePkt = pkt.clone();
REQUIRE((long) clonePkt != (long) &pkt);
Tins::PDU::serialization_type ser_pkt = pkt.serialize();
Tins::PDU::serialization_type ser_clonepkt = clonePkt->serialize();
REQUIRE(ser_pkt == ser_clonepkt);
Tins::PDU & pdu = *((Tins::PDU *)&pkt);
std::hash<Tins::PDU::serialization_type>pdu_hash;
std::size_t h1 = pdu_hash(ser_pkt);
std::size_t h2 = pdu_hash(ser_clonepkt);
REQUIRE(h1 == h2);
pkt = Tins::EthernetII("11:22:33:44:55:66", "66:55:44:33:22:11") / Tins::IPv6("::2", "::1") / Tins::TCP();
ser_pkt = pkt.serialize();
h1 = pdu_hash(ser_pkt);
REQUIRE(h1 != h2);
}