PROFINET IO Controller Stack 1.0.0
Modern C++ implementation of a PROFINET IO Controller stack
Loading...
Searching...
No Matches
test_skipVlanTags.cpp
Go to the documentation of this file.
1
12
13#include <gtest/gtest.h>
14
15#include <array>
16#include <cstdint>
17
18#include "profinet/protocol.h"
19#include "profinet/util.h"
20
21namespace
22{
23constexpr std::array<std::uint8_t, 6> kControllerMac{0x00, 0x11, 0x22, 0x33, 0x44, 0x55};
24constexpr std::array<std::uint8_t, 6> kDeviceMac{0x02, 0x00, 0x00, 0x00, 0x00, 0x01};
25constexpr std::array<std::uint8_t, 4> kVlanTag{0x81, 0x00, 0xC0, 0x00};
26constexpr std::uint16_t kProfinetEtherType = 0x8892;
27} // namespace
28
29namespace profinet
30{
31namespace
32{
39class SkipVlanTagsTest : public ::testing::Test
40{
41 protected:
49 static Bytes BuildUntaggedFrame()
50 {
51 Bytes frame{kDeviceMac.begin(), kDeviceMac.end()};
52 frame.insert(frame.end(), kControllerMac.begin(), kControllerMac.end());
53 frame.push_back(static_cast<std::uint8_t>((kProfinetEtherType >> 8U) & 0xFFU));
54 frame.push_back(static_cast<std::uint8_t>(kProfinetEtherType & 0xFFU));
55 frame.insert(frame.end(), 50U, 0x00);
56 return frame;
57 }
58};
59} // namespace
61TEST_F(SkipVlanTagsTest, UntaggedFrameReturnsOffset12)
62{
63 const Bytes frame = BuildUntaggedFrame();
64 EXPECT_EQ(SkipVlanTags(frame), 12U);
65}
66
68TEST_F(SkipVlanTagsTest, Single8021QTagReturnsOffset16)
69{
70 Bytes frame = BuildUntaggedFrame();
71
72 frame.insert(frame.begin() + 12, kVlanTag.begin(), kVlanTag.end());
73
74 EXPECT_EQ(SkipVlanTags(frame), 16U);
75}
76
78TEST_F(SkipVlanTagsTest, DoubleTaggedQinQFrameReturnsOffset20)
79{
80 Bytes frame{kDeviceMac.begin(), kDeviceMac.end()};
81
82 frame.insert(frame.end(), kControllerMac.begin(), kControllerMac.end());
83
84 // QinQ outer tag.
85 frame.insert(frame.end(), {0x88, 0xA8, 0x00, 0x00});
86
87 frame.insert(frame.end(), kVlanTag.begin(), kVlanTag.end());
88
89 frame.insert(frame.end(), {0x88, 0x92});
90
91 frame.insert(frame.end(), 50U, 0x00);
92
93 EXPECT_EQ(SkipVlanTags(frame), 20U);
94}
95
97TEST_F(SkipVlanTagsTest, ShortFrameReturnsEthernetHeaderLength)
98{
99 const Bytes frame(13U, 0x00);
100
101 EXPECT_EQ(SkipVlanTags(frame), 12U);
102}
103} // namespace profinet
constexpr MacAddress kControllerMac
TEST_F(AlarmListenerTests, InitializesWithEndpoint)
std::size_t SkipVlanTags(std::span< const std::uint8_t > frame) noexcept
Return the byte offset of the real EtherType in a raw Ethernet frame.
Definition util.cpp:70
std::vector< std::uint8_t > Bytes
Generic byte buffer alias used throughout the library for raw wire data.
Definition protocol.h:55
PROFINET protocol wire-format structures and serialization helpers.
Bytes frame
Declares Linux Ethernet, addressing, timing, and utility helpers used by the PROFINET stack.