1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-23 02:35:57 +01:00

Fixed bug in EthernetII when changing its inner PDU.

This commit is contained in:
Matias Fontanini
2014-08-07 19:38:05 -03:00
parent 1c2bfd42ca
commit 8e6ddfd764
3 changed files with 20 additions and 16 deletions

View File

@@ -43,12 +43,13 @@ const uint8_t AllocatorsTest::ipv6_data_buffer[] = {
65
};
template<size_t n>
class DummyPDU : public PDU {
public:
static const PDU::PDUType pdu_flag;
DummyPDU(const uint8_t* data, uint32_t sz) : buffer(data, data + sz) { }
DummyPDU *clone() const { return new DummyPDU(*this); }
DummyPDU *clone() const { return new DummyPDU<n>(*this); }
uint32_t header_size() const { return buffer.size(); }
PDUType pdu_type() const { return pdu_flag; }
void write_serialization(uint8_t *data, uint32_t, const PDU *)
@@ -59,35 +60,38 @@ public:
std::vector<uint8_t> buffer;
};
const PDU::PDUType DummyPDU::pdu_flag = USER_DEFINED_PDU;
template<size_t n>
const PDU::PDUType DummyPDU<n>::pdu_flag = static_cast<PDU::PDUType>(
USER_DEFINED_PDU + n
);
TEST_F(AllocatorsTest, LinkLayerPDUs) {
Allocators::register_allocator<EthernetII, DummyPDU>(1638);
Allocators::register_allocator<SNAP, DummyPDU>(25);
Allocators::register_allocator<Dot1Q, DummyPDU>(4562);
Allocators::register_allocator<SLL, DummyPDU>(16705);
Allocators::register_allocator<EthernetII, DummyPDU<0> >(1638);
Allocators::register_allocator<SNAP, DummyPDU<1> >(25);
Allocators::register_allocator<Dot1Q, DummyPDU<2> >(4562);
Allocators::register_allocator<SLL, DummyPDU<3> >(16705);
std::vector<uint8_t> link_layer_data(
link_layer_data_buffer,
link_layer_data_buffer + sizeof(link_layer_data_buffer)
);
{
EthernetII pkt(&link_layer_data[0], link_layer_data.size());
EXPECT_TRUE(pkt.find_pdu<DummyPDU>());
EXPECT_TRUE(pkt.find_pdu<DummyPDU<0> >());
EXPECT_EQ(pkt.serialize(), link_layer_data);
}
{
SNAP pkt(&link_layer_data[0], link_layer_data.size());
EXPECT_TRUE(pkt.find_pdu<DummyPDU>());
EXPECT_TRUE(pkt.find_pdu<DummyPDU<1> >());
EXPECT_EQ(pkt.serialize(), link_layer_data);
}
{
SLL pkt(&link_layer_data[0], link_layer_data.size());
EXPECT_TRUE(pkt.find_pdu<DummyPDU>());
EXPECT_TRUE(pkt.find_pdu<DummyPDU<3> >());
EXPECT_EQ(pkt.serialize(), link_layer_data);
}
{
Dot1Q pkt(&link_layer_data[0], link_layer_data.size());
EXPECT_TRUE(pkt.find_pdu<DummyPDU>());
EXPECT_TRUE(pkt.find_pdu<DummyPDU<2> >());
EXPECT_EQ(pkt.serialize(), link_layer_data);
}
}
@@ -97,10 +101,10 @@ TEST_F(AllocatorsTest, IP) {
ipv4_data_buffer,
ipv4_data_buffer + sizeof(ipv4_data_buffer)
);
Allocators::register_allocator<IP, DummyPDU>(255);
Allocators::register_allocator<IP, DummyPDU<0> >(255);
EthernetII pkt(&ipv4_data[0], ipv4_data.size());
EXPECT_TRUE(pkt.find_pdu<IP>());
EXPECT_TRUE(pkt.find_pdu<DummyPDU>());
EXPECT_TRUE(pkt.find_pdu<DummyPDU<0> >());
EXPECT_EQ(pkt.serialize(), ipv4_data);
}
@@ -109,11 +113,11 @@ TEST_F(AllocatorsTest, IPv6) {
ipv6_data_buffer,
ipv6_data_buffer + sizeof(ipv6_data_buffer)
);
Allocators::register_allocator<IPv6, DummyPDU>(250);
Allocators::register_allocator<IPv6, DummyPDU<0> >(250);
{
EthernetII pkt(&ipv6_data[0], ipv6_data.size());
EXPECT_TRUE(pkt.find_pdu<IPv6>());
EXPECT_TRUE(pkt.find_pdu<DummyPDU>());
EXPECT_TRUE(pkt.find_pdu<DummyPDU<0> >());
EXPECT_EQ(pkt.serialize(), ipv6_data);
}
}