PROFINET IO Controller Stack 1.0.0
Modern C++ implementation of a PROFINET IO Controller stack
Loading...
Searching...
No Matches
test_rtFrame.cpp
Go to the documentation of this file.
1
10
11#include <gtest/gtest.h>
12
13#include <array>
14#include <cstdint>
15
16#include "profinet/rt.h"
17namespace profinet::rt
18{
19
26class RtFrameTest : public ::testing::Test
27{
28 protected:
33 {
35
36 frame.frameId = 0xC001;
37 frame.cycleCounter = 42;
39 frame.transferStatus = 0;
40 frame.payload = {0xDE, 0xAD, 0xBE, 0xEF};
41 frame.payload.resize(40U, 0x00);
42
43 return frame;
44 }
45};
46
48TEST_F(RtFrameTest, DISABLED_TaggedEthernetFrameRoundTrips)
49{
50 const RTFrame frame = MakeFrame();
51
52 const Bytes raw = BuildEthernetFrame(
53 std::array<std::uint8_t, 6>{
54 0x02,
55 0x00,
56 0x00,
57 0x00,
58 0x00,
59 0x01},
60 std::array<std::uint8_t, 6>{
61 0x00,
62 0x11,
63 0x22,
64 0x33,
65 0x44,
66 0x55},
67 frame);
68
69 ASSERT_GE(raw.size(), 18U);
70
71 EXPECT_EQ(raw[12], 0x81);
72 EXPECT_EQ(raw[13], 0x00);
73
74 const auto parsed = ParseEthernetFrame(raw);
75
76 ASSERT_TRUE(parsed.has_value());
77
78 EXPECT_EQ(parsed->frameId, 0xC001U);
79 EXPECT_EQ(parsed->cycleCounter, 42U);
80}
81
83TEST_F(RtFrameTest, UntaggedEthernetFrameParses)
84{
85 const RTFrame frame = MakeFrame();
86
87 Bytes raw{
88 0x02,
89 0x00,
90 0x00,
91 0x00,
92 0x00,
93 0x01,
94 0x00,
95 0x11,
96 0x22,
97 0x33,
98 0x44,
99 0x55,
100 0x88,
101 0x92};
102
103 const Bytes rt = frame.ToBytes();
104
105 raw.insert(raw.end(), rt.begin(), rt.end());
106
107 const auto parsed = ParseEthernetFrame(raw);
108
109 ASSERT_TRUE(parsed.has_value());
110
111 EXPECT_EQ(parsed->frameId, 0xC001U);
112}
113
115TEST_F(RtFrameTest, NonProfinetEtherTypeIsRejected)
116{
117 Bytes raw{
118 0x02,
119 0x00,
120 0x00,
121 0x00,
122 0x00,
123 0x01,
124 0x00,
125 0x11,
126 0x22,
127 0x33,
128 0x44,
129 0x55,
130 0x08,
131 0x00};
132
133 raw.insert(raw.end(), 46U, 0x00);
134
135 EXPECT_FALSE(ParseEthernetFrame(raw).has_value());
136}
137} // namespace profinet::rt
Test fixture for RT Ethernet frame serialization.
static RTFrame MakeFrame()
Build the canonical RT frame used by the tests.
std::optional< RTFrame > ParseEthernetFrame(const Bytes &data)
Parse a complete Ethernet frame and extract its RT frame.
Definition rt.cpp:261
TEST_F(RtFrameTest, DISABLED_TaggedEthernetFrameRoundTrips)
Bytes BuildEthernetFrame(const MacAddress &dstMac, const MacAddress &srcMac, const RTFrame &rtFrame)
Build a complete Ethernet frame carrying an RT frame.
Definition rt.cpp:242
std::vector< std::uint8_t > Bytes
Generic byte buffer alias used throughout the library for raw wire data.
Definition protocol.h:55
Declares PROFINET RT_CLASS_1 cyclic frame and IOCR data structures.
A single PROFINET Real-Time cyclic frame: Frame ID + C_SDU payload + cycle counter/status trailer.
Definition rt.h:208
std::uint16_t frameId
Frame ID identifying which IOCR this frame belongs to.
Definition rt.h:210
static constexpr std::uint8_t DATA_RUN
Alias for DATA_STATUS_PROVIDER_RUN, for readability at call sites.
Definition rt.h:232
static constexpr std::uint8_t DATA_VALID
Alias for DATA_STATUS_VALID, for readability at call sites.
Definition rt.h:226
Bytes frame