mirror of
https://github.com/mfontanini/libtins
synced 2026-01-28 12:44:25 +01:00
Added Dot1Q class.
This commit is contained in:
@@ -192,6 +192,23 @@
|
||||
../include/packet_sender.h:
|
||||
|
||||
../include/snap.h:
|
||||
../src/dot1q.o: ../src/dot1q.cpp ../include/dot1q.h ../include/pdu.h \
|
||||
../include/endianness.h ../include/macros.h ../include/small_uint.h \
|
||||
../include/internals.h ../include/constants.h
|
||||
|
||||
../include/dot1q.h:
|
||||
|
||||
../include/pdu.h:
|
||||
|
||||
../include/endianness.h:
|
||||
|
||||
../include/macros.h:
|
||||
|
||||
../include/small_uint.h:
|
||||
|
||||
../include/internals.h:
|
||||
|
||||
../include/constants.h:
|
||||
../src/eapol.o: ../src/eapol.cpp ../include/eapol.h ../include/pdu.h \
|
||||
../include/macros.h ../include/small_uint.h ../include/endianness.h \
|
||||
../include/dot11.h ../include/hw_address.h ../include/pdu_option.h \
|
||||
@@ -1563,6 +1580,18 @@ src/dot11/rts.o: src/dot11/rts.cpp ../include/dot11.h ../include/macros.h \
|
||||
include/tests/dot11.h:
|
||||
|
||||
include/tests/dot11.h:
|
||||
src/dot1q.o: src/dot1q.cpp ../include/dot1q.h ../include/pdu.h \
|
||||
../include/endianness.h ../include/macros.h ../include/small_uint.h
|
||||
|
||||
../include/dot1q.h:
|
||||
|
||||
../include/pdu.h:
|
||||
|
||||
../include/endianness.h:
|
||||
|
||||
../include/macros.h:
|
||||
|
||||
../include/small_uint.h:
|
||||
src/ethernetII.o: src/ethernetII.cpp ../include/ethernetII.h \
|
||||
../include/macros.h ../include/pdu.h ../include/endianness.h \
|
||||
../include/hw_address.h ../include/network_interface.h \
|
||||
|
||||
76
tests/src/dot1q.cpp
Normal file
76
tests/src/dot1q.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <stdint.h>
|
||||
#include "dot1q.h"
|
||||
#include "arp.h"
|
||||
#include "ethernetII.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace Tins;
|
||||
|
||||
class Dot1QTest : public testing::Test {
|
||||
public:
|
||||
static const uint8_t expected_packet[];
|
||||
|
||||
void test_equals(const Dot1Q &pdu1, const Dot1Q &pdu2);
|
||||
};
|
||||
|
||||
const uint8_t Dot1QTest::expected_packet[] = {
|
||||
'\xff', '\xff', '\xff', '\xff', '\xff', '\xff', '\x00', '\x19', '\x06',
|
||||
'\xea', '\xb8', '\xc1', '\x81', '\x00', '\xb0', '{', '\x08', '\x06',
|
||||
'\x00', '\x01', '\x08', '\x00', '\x06', '\x04', '\x00', '\x02', '\x00',
|
||||
'\x19', '\x06', '\xea', '\xb8', '\xc1', '\xc0', '\xa8', '{', '\x01',
|
||||
'\xff', '\xff', '\xff', '\xff', '\xff', '\xff', '\xc0', '\xa8', '{',
|
||||
'\x01', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00',
|
||||
'\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00',
|
||||
'\x00'
|
||||
};
|
||||
|
||||
|
||||
TEST_F(Dot1QTest, DefaultConstructor) {
|
||||
Dot1Q dot1;
|
||||
EXPECT_EQ(0, dot1.payload_type());
|
||||
EXPECT_EQ(0, dot1.priority());
|
||||
EXPECT_EQ(0, dot1.cfi());
|
||||
EXPECT_EQ(0, dot1.id());
|
||||
}
|
||||
|
||||
TEST_F(Dot1QTest, ConstructorFromBuffer) {
|
||||
EthernetII eth(expected_packet, sizeof(expected_packet));
|
||||
const Dot1Q *dot1 = eth.find_pdu<Dot1Q>();
|
||||
ASSERT_TRUE(dot1);
|
||||
EXPECT_EQ(0x806, dot1->payload_type());
|
||||
EXPECT_EQ(5, dot1->priority());
|
||||
EXPECT_EQ(1, dot1->cfi());
|
||||
EXPECT_EQ(123, dot1->id());
|
||||
|
||||
const ARP *arp = dot1->find_pdu<ARP>();
|
||||
ASSERT_TRUE(arp);
|
||||
// just to check it the offset's OK
|
||||
EXPECT_EQ(ARP::hwaddress_type("00:19:06:ea:b8:c1"), arp->sender_hw_addr());
|
||||
}
|
||||
|
||||
TEST_F(Dot1QTest, PayloadType) {
|
||||
Dot1Q dot1;
|
||||
dot1.payload_type(0x9283);
|
||||
EXPECT_EQ(0x9283, dot1.payload_type());
|
||||
}
|
||||
|
||||
TEST_F(Dot1QTest, Priority) {
|
||||
Dot1Q dot1;
|
||||
dot1.priority(5);
|
||||
EXPECT_EQ(5, dot1.priority());
|
||||
}
|
||||
|
||||
TEST_F(Dot1QTest, CFI) {
|
||||
Dot1Q dot1;
|
||||
dot1.cfi(1);
|
||||
EXPECT_EQ(1, dot1.cfi());
|
||||
}
|
||||
|
||||
TEST_F(Dot1QTest, Id) {
|
||||
Dot1Q dot1;
|
||||
dot1.id(3543);
|
||||
EXPECT_EQ(3543, dot1.id());
|
||||
}
|
||||
Reference in New Issue
Block a user