1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-27 04:11:35 +01:00

Added STP root_id and bridge_id setters/getters.

This commit is contained in:
Matias Fontanini
2013-04-21 13:22:15 -03:00
parent 759e92706f
commit 077b54bbed
5 changed files with 124 additions and 4 deletions

View File

@@ -12,6 +12,7 @@ using namespace Tins;
class STPTest : public testing::Test {
public:
static const uint8_t expected_packet[];
static void test_equals(const STP::bpdu_id_type &lhs, const STP::bpdu_id_type &rhs);
};
const uint8_t STPTest::expected_packet[] = {
@@ -20,6 +21,12 @@ const uint8_t STPTest::expected_packet[] = {
0
};
void STPTest::test_equals(const STP::bpdu_id_type &lhs, const STP::bpdu_id_type &rhs) {
EXPECT_EQ(lhs.priority, rhs.priority);
EXPECT_EQ(lhs.ext_id, rhs.ext_id);
EXPECT_EQ(lhs.id, rhs.id);
}
TEST_F(STPTest, DefaultConstructor) {
STP pdu;
EXPECT_EQ(0, pdu.proto_id());
@@ -36,12 +43,15 @@ TEST_F(STPTest, DefaultConstructor) {
TEST_F(STPTest, ConstructorFromBuffer) {
STP pdu(expected_packet, sizeof(expected_packet));
STP::bpdu_id_type bpdu(0x8, 0, "00:90:4c:08:17:b5");
EXPECT_EQ(0x9283, pdu.proto_id());
EXPECT_EQ(0x8a, pdu.proto_version());
EXPECT_EQ(0x92, pdu.bpdu_type());
EXPECT_EQ(0x92, pdu.bpdu_flags());
test_equals(bpdu, pdu.root_id());
// root identifier(32768. 0, 00:90:4c:08:17:b5
EXPECT_EQ(0x928378, pdu.root_path_cost());
test_equals(bpdu, pdu.bridge_id());
// bridge identifier(32768. 0, 00:90:4c:08:17:b5
EXPECT_EQ(0x8001, pdu.port_id());
EXPECT_EQ(15, pdu.msg_age());
@@ -50,6 +60,17 @@ TEST_F(STPTest, ConstructorFromBuffer) {
EXPECT_EQ(0, pdu.fwd_delay());
}
TEST_F(STPTest, BPDUId) {
const uint8_t expected_packet[] = {
0, 0, 0, 0, 0, 128, 100, 0, 28, 14, 135, 120, 0, 0, 0, 0, 4, 128,
100, 0, 28, 14, 135, 133, 0, 128, 4, 1, 0, 20, 0, 2, 0, 15, 0, 0,
0, 0, 0, 0, 0, 0, 0
};
STP pdu(expected_packet, sizeof(expected_packet));
STP::bpdu_id_type bpdu(0x8, 100, "00:1c:0e:87:78:00");
test_equals(bpdu, pdu.root_id());
}
TEST_F(STPTest, ChainedPDUs) {
const uint8_t input[] = {
1, 128, 194, 0, 0, 0, 0, 144, 76, 8, 23, 181, 0, 38, 66, 66, 3,
@@ -140,3 +161,17 @@ TEST_F(STPTest, HelloTime) {
pdu.hello_time(15);
EXPECT_EQ(15, pdu.hello_time());
}
TEST_F(STPTest, RootID) {
STP pdu;
STP::bpdu_id_type bpdu(0x8, 100, "00:1c:0e:87:78:00");
pdu.root_id(bpdu);
test_equals(bpdu, pdu.root_id());
}
TEST_F(STPTest, BridgeID) {
STP pdu;
STP::bpdu_id_type bpdu(0x8, 100, "00:1c:0e:87:78:00");
pdu.bridge_id(bpdu);
test_equals(bpdu, pdu.bridge_id());
}