From 60383295cca68f9f71b26919bccdd5896b26018f Mon Sep 17 00:00:00 2001 From: "anchi.liu" Date: Fri, 4 Oct 2024 19:22:51 +0900 Subject: [PATCH] move the method to layers --- Packet++/header/GvcpLayer.h | 116 ++++++++-------- Packet++/header/ProtocolType.h | 2 +- Packet++/src/GvcpLayer.cpp | 16 +-- Tests/Packet++Test/Tests/GvcpTests.cpp | 180 ++++++++++++------------- 4 files changed, 157 insertions(+), 157 deletions(-) diff --git a/Packet++/header/GvcpLayer.h b/Packet++/header/GvcpLayer.h index a5828f2e8c..df9a40c422 100644 --- a/Packet++/header/GvcpLayer.h +++ b/Packet++/header/GvcpLayer.h @@ -125,44 +125,10 @@ namespace pcpp requestId(hostToNet16(requestId)) {} - GvcpFlag getFlag() const - { - return flag; - } - GvcpCommand getCommand() const { return static_cast(netToHost16(command)); } - - uint16_t getDataSize() const - { - return netToHost16(dataSize); - } - - uint16_t getRequestId() const - { - return netToHost16(requestId); - } - - /** - * @brief Verify the magic number - * @return true The magic number is valid - */ - bool verifyMagicNumber() const - { - return magicNumber == internal::kGvcpMagicNumber; - } - - /** - * @brief Check if the acknowledge is required - * @return true The acknowledge is required - */ - bool hasAcknowledgeFlag() const - { - constexpr GvcpFlag kAcknowledgeFlag = 0b0000001; - return (flag & kAcknowledgeFlag) == kAcknowledgeFlag; - } }; static_assert(sizeof(GvcpRequestHeader) == internal::kGvcpRequestHeaderLength, "Gvcp request header size should be 8 bytes"); @@ -206,25 +172,10 @@ namespace pcpp dataSize(hostToNet16(dataSize)), ackId(hostToNet16(ackId)) {} - GvcpResponseStatus getStatus() const - { - return static_cast(netToHost16(status)); - } - GvcpCommand getCommand() const { return static_cast(netToHost16(command)); } - - uint16_t getDataSize() const - { - return netToHost16(dataSize); - } - - uint16_t getAckId() const - { - return netToHost16(ackId); - } }; static_assert(sizeof(GvcpAckHeader) == internal::kGvcpAckHeaderLength, "Gvcp ack header size should be 8 bytes"); @@ -378,10 +329,56 @@ namespace pcpp return reinterpret_cast(m_Data); // the header is at the beginning of the data } - /// @brief get the GVCP command + /** + * @brief Get the flag from the header + */ + GvcpFlag getFlag() const + { + return getGvcpHeader()->flag; + } + + /** + * @brief Get the data size from the header + */ + uint16_t getDataSize() const + { + return netToHost16(getGvcpHeader()->dataSize); + } + + /** + * @brief Get the request ID from the header + */ + uint16_t getRequestId() const + { + return netToHost16(getGvcpHeader()->requestId); + } + + + /** + * @brief Get the command from the header + */ GvcpCommand getCommand() const { - return getGvcpHeader()->getCommand(); + return static_cast(netToHost16(getGvcpHeader()->command)); + } + + /** + * @brief Verify the magic number in the header + * @return true The magic number is valid + */ + bool verifyMagicNumber() const + { + return getGvcpHeader()->magicNumber == internal::kGvcpMagicNumber; + } + + /** + * @brief Check if the acknowledge is required from the header + * @return true The acknowledge is required + */ + bool hasAcknowledgeFlag() const + { + constexpr GvcpFlag kAcknowledgeFlag = 0b0000001; + return (getGvcpHeader()->flag & kAcknowledgeFlag) == kAcknowledgeFlag; } // implement Layer's abstract methods @@ -435,33 +432,36 @@ namespace pcpp return reinterpret_cast(m_Data); // the header is at the beginning of the data } + /** + * @return the response status from the header + */ GvcpResponseStatus getStatus() const { - return getGvcpHeader()->getStatus(); + return static_cast((netToHost16(getGvcpHeader()->status))); } /** - * @return the response command type + * @return the response command type from the header */ GvcpCommand getCommand() const { - return getGvcpHeader()->getCommand(); + return static_cast(netToHost16(getGvcpHeader()->command)); } /** - * @return the size of the data in bytes + * @return the size of the data in bytes from the header */ uint16_t getDataSize() const { - return getGvcpHeader()->getDataSize(); + return netToHost16(getGvcpHeader()->dataSize); } /** - * @return uint16_t The acknowledge ID + * @return uint16_t The acknowledge ID from the header */ uint16_t getAckId() const { - return getGvcpHeader()->getAckId(); + return netToHost16(getGvcpHeader()->ackId); } // implement Layer's abstract methods diff --git a/Packet++/header/ProtocolType.h b/Packet++/header/ProtocolType.h index a5f3709251..5213496778 100644 --- a/Packet++/header/ProtocolType.h +++ b/Packet++/header/ProtocolType.h @@ -355,7 +355,7 @@ namespace pcpp /* * GVCP protocol */ - const ProtocolType Gvcp = 57; + const ProtocolType GVCP = 57; /** * An enum representing OSI model layers diff --git a/Packet++/src/GvcpLayer.cpp b/Packet++/src/GvcpLayer.cpp index 429fa37d27..9b9bd83a2f 100644 --- a/Packet++/src/GvcpLayer.cpp +++ b/Packet++/src/GvcpLayer.cpp @@ -27,7 +27,7 @@ namespace pcpp /*---------------------- Class GvcpLayer ----------------------------*/ GvcpLayer::GvcpLayer(uint8_t* data, size_t dataSize, Layer* prevLayer, Packet* packet) - : Layer(data, dataSize, prevLayer, packet, Gvcp) + : Layer(data, dataSize, prevLayer, packet, GVCP) {} GvcpLayer* GvcpLayer::parseGvcpLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) @@ -74,7 +74,7 @@ namespace pcpp GvcpRequestLayer::GvcpRequestLayer(GvcpCommand command, const uint8_t* payloadData, uint16_t payloadDataSize, GvcpFlag flag, uint16_t requestId) { - m_Protocol = Gvcp; + m_Protocol = GVCP; m_DataLen = getHeaderLen() + payloadDataSize; m_Data = new uint8_t[m_DataLen]; @@ -92,7 +92,7 @@ namespace pcpp GvcpRequestLayer::GvcpRequestLayer(const uint8_t* data, size_t dataSize) { - m_Protocol = Gvcp; + m_Protocol = GVCP; m_DataLen = dataSize; m_Data = new uint8_t[m_DataLen]; @@ -102,7 +102,7 @@ namespace pcpp std::string GvcpRequestLayer::toString() const { std::stringstream ss; - ss << "GVCP Request Layer, Command: " << getCommand() << ", Request ID: " << getGvcpHeader()->getRequestId(); + ss << "GVCP Request Layer, Command: " << getCommand() << ", Request ID: " << getRequestId(); return ss.str(); } @@ -114,7 +114,7 @@ namespace pcpp GvcpAcknowledgeLayer::GvcpAcknowledgeLayer(GvcpResponseStatus status, GvcpCommand command, const uint8_t* payloadData, uint16_t payloadDataSize, uint16_t ackId) { - m_Protocol = Gvcp; + m_Protocol = GVCP; m_DataLen = getHeaderLen() + payloadDataSize; m_Data = new uint8_t[m_DataLen]; @@ -132,7 +132,7 @@ namespace pcpp GvcpAcknowledgeLayer::GvcpAcknowledgeLayer(const uint8_t* data, size_t dataSize) { - m_Protocol = Gvcp; + m_Protocol = GVCP; m_DataLen = dataSize; m_Data = new uint8_t[m_DataLen]; @@ -142,8 +142,8 @@ namespace pcpp std::string GvcpAcknowledgeLayer::toString() const { std::stringstream ss; - ss << "GVCP Acknowledge Layer, Command: " << getCommand() << ", Acknowledge ID: " << getGvcpHeader()->getAckId() - << ", Status: " << getGvcpHeader()->getStatus(); + ss << "GVCP Acknowledge Layer, Command: " << getCommand() << ", Acknowledge ID: " << getAckId() + << ", Status: " << getStatus(); return ss.str(); } } // namespace pcpp diff --git a/Tests/Packet++Test/Tests/GvcpTests.cpp b/Tests/Packet++Test/Tests/GvcpTests.cpp index 48976957de..2f9d81c113 100644 --- a/Tests/Packet++Test/Tests/GvcpTests.cpp +++ b/Tests/Packet++Test/Tests/GvcpTests.cpp @@ -14,26 +14,26 @@ PTF_TEST_CASE(GvcpBasicTest) { std::vector payload = { 0x00, 0x01, 0x02, 0x03 }; GvcpRequestLayer gvcpRequestLayer(GvcpCommand::DiscoveredCmd, payload.data(), payload.size(), 1, 2); - PTF_ASSERT_EQUAL(gvcpRequestLayer.getProtocol(), Gvcp); + PTF_ASSERT_EQUAL(gvcpRequestLayer.getProtocol(), GVCP); GvcpRequestHeader* header = gvcpRequestLayer.getGvcpHeader(); PTF_ASSERT_TRUE(header != nullptr); - PTF_ASSERT_EQUAL(header->getCommand(), GvcpCommand::DiscoveredCmd); - PTF_ASSERT_EQUAL(header->getFlag(), 1); - PTF_ASSERT_EQUAL(header->getRequestId(), 2); - PTF_ASSERT_EQUAL(header->getDataSize(), payload.size()); + PTF_ASSERT_EQUAL(gvcpRequestLayer.getCommand(), GvcpCommand::DiscoveredCmd); + PTF_ASSERT_EQUAL(gvcpRequestLayer.getFlag(), 1); + PTF_ASSERT_EQUAL(gvcpRequestLayer.getRequestId(), 2); + PTF_ASSERT_EQUAL(gvcpRequestLayer.getDataSize(), payload.size()); } { std::vector payload = { 0x00, 0x01, 0x02, 0x03 }; GvcpAcknowledgeLayer gvcpAcknowledgeLayer(GvcpResponseStatus::Success, GvcpCommand::DiscoveredAck, payload.data(), payload.size(), 2); - PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer.getProtocol(), Gvcp); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer.getProtocol(), GVCP); GvcpAckHeader* header = gvcpAcknowledgeLayer.getGvcpHeader(); PTF_ASSERT_TRUE(header != nullptr); - PTF_ASSERT_EQUAL(header->getStatus(), GvcpResponseStatus::Success); - PTF_ASSERT_EQUAL(header->getCommand(), GvcpCommand::DiscoveredAck); - PTF_ASSERT_EQUAL(header->getAckId(), 2); - PTF_ASSERT_EQUAL(header->getDataSize(), payload.size()); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer.getStatus(), GvcpResponseStatus::Success); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer.getCommand(), GvcpCommand::DiscoveredAck); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer.getAckId(), 2); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer.getDataSize(), payload.size()); } } @@ -53,14 +53,14 @@ PTF_TEST_CASE(GvcpDiscoveryCommand) // we get the raw buffer from the payload of the UDP layer and create a gvcpRequestLayer from the buffer GvcpDiscoveryRequestLayer gvcpRequestLayer(udpLayer->getLayerPayload(), udpLayer->getLayerPayloadSize()); - PTF_ASSERT_EQUAL(gvcpRequestLayer.getProtocol(), Gvcp); + PTF_ASSERT_EQUAL(gvcpRequestLayer.getProtocol(), GVCP); GvcpRequestHeader* header = gvcpRequestLayer.getGvcpHeader(); PTF_ASSERT_TRUE(header != nullptr); - PTF_ASSERT_EQUAL(uint8_t(header->getFlag()), uint8_t(0x11)); // allow broadcast, acknowledge required - PTF_ASSERT_EQUAL(header->hasAcknowledgeFlag(), true); - PTF_ASSERT_EQUAL(header->getCommand(), GvcpCommand::DiscoveredCmd); - PTF_ASSERT_EQUAL(header->verifyMagicNumber(), true); - PTF_ASSERT_EQUAL(header->getDataSize(), gvcpRequestLayer.getLayerPayloadSize()); + PTF_ASSERT_EQUAL(uint8_t(gvcpRequestLayer.getFlag()), uint8_t(0x11)); // allow broadcast, acknowledge required + PTF_ASSERT_EQUAL(gvcpRequestLayer.hasAcknowledgeFlag(), true); + PTF_ASSERT_EQUAL(gvcpRequestLayer.getCommand(), GvcpCommand::DiscoveredCmd); + PTF_ASSERT_EQUAL(gvcpRequestLayer.verifyMagicNumber(), true); + PTF_ASSERT_EQUAL(gvcpRequestLayer.getDataSize(), gvcpRequestLayer.getLayerPayloadSize()); } // test the GVCP layer directly from the packet @@ -75,14 +75,14 @@ PTF_TEST_CASE(GvcpDiscoveryCommand) // we get the GVCP layer from the packet auto gvcpRequestLayer = discoverCmdPacket.getLayerOfType(); - PTF_ASSERT_EQUAL(gvcpRequestLayer->getProtocol(), Gvcp); + PTF_ASSERT_EQUAL(gvcpRequestLayer->getProtocol(), GVCP); GvcpRequestHeader* header = gvcpRequestLayer->getGvcpHeader(); PTF_ASSERT_TRUE(header != nullptr); - PTF_ASSERT_EQUAL(uint8_t(header->getFlag()), uint8_t(0x11)); // allow broadcast, acknowledge required - PTF_ASSERT_EQUAL(header->hasAcknowledgeFlag(), true); - PTF_ASSERT_EQUAL(header->getCommand(), GvcpCommand::DiscoveredCmd); - PTF_ASSERT_EQUAL(header->verifyMagicNumber(), true); - PTF_ASSERT_EQUAL(header->getDataSize(), gvcpRequestLayer->getLayerPayloadSize()); + PTF_ASSERT_EQUAL(uint8_t(gvcpRequestLayer->getFlag()), uint8_t(0x11)); // allow broadcast, acknowledge required + PTF_ASSERT_EQUAL(gvcpRequestLayer->hasAcknowledgeFlag(), true); + PTF_ASSERT_EQUAL(gvcpRequestLayer->getCommand(), GvcpCommand::DiscoveredCmd); + PTF_ASSERT_EQUAL(gvcpRequestLayer->verifyMagicNumber(), true); + PTF_ASSERT_EQUAL(gvcpRequestLayer->getDataSize(), gvcpRequestLayer->getLayerPayloadSize()); } } @@ -103,13 +103,13 @@ PTF_TEST_CASE(GvcpDiscoveryAck) GvcpDiscoveryAcknowledgeLayer gvcpAcknowledgeLayer(udpLayer->getLayerPayload(), udpLayer->getLayerPayloadSize()); - PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer.getProtocol(), Gvcp); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer.getProtocol(), GVCP); GvcpAckHeader* header = gvcpAcknowledgeLayer.getGvcpHeader(); PTF_ASSERT_TRUE(header != nullptr); - PTF_ASSERT_EQUAL(header->getStatus(), GvcpResponseStatus::Success); - PTF_ASSERT_EQUAL(header->getCommand(), GvcpCommand::DiscoveredAck); - PTF_ASSERT_EQUAL(header->getAckId(), 1); - PTF_ASSERT_EQUAL(header->getDataSize(), udpLayer->getLayerPayloadSize() - sizeof(GvcpAckHeader)); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer.getStatus(), GvcpResponseStatus::Success); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer.getCommand(), GvcpCommand::DiscoveredAck); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer.getAckId(), 1); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer.getDataSize(), udpLayer->getLayerPayloadSize() - sizeof(GvcpAckHeader)); PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer.getMacAddress(), pcpp::MacAddress("00:04:4b:ea:b0:b4")); PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer.getIpAddress(), pcpp::IPv4Address("172.28.60.100")); @@ -131,13 +131,13 @@ PTF_TEST_CASE(GvcpDiscoveryAck) auto gvcpAcknowledgeLayer = discoverAckPacket.getLayerOfType(); PTF_ASSERT_NOT_NULL(gvcpAcknowledgeLayer); - PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer->getProtocol(), Gvcp); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer->getProtocol(), GVCP); GvcpAckHeader* header = gvcpAcknowledgeLayer->getGvcpHeader(); PTF_ASSERT_TRUE(header != nullptr); - PTF_ASSERT_EQUAL(header->getStatus(), GvcpResponseStatus::Success); - PTF_ASSERT_EQUAL(header->getCommand(), GvcpCommand::DiscoveredAck); - PTF_ASSERT_EQUAL(header->getAckId(), 1); - PTF_ASSERT_EQUAL(header->getDataSize(), gvcpAcknowledgeLayer->getLayerPayloadSize()); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer->getStatus(), GvcpResponseStatus::Success); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer->getCommand(), GvcpCommand::DiscoveredAck); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer->getAckId(), 1); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer->getDataSize(), gvcpAcknowledgeLayer->getLayerPayloadSize()); PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer->getMacAddress(), pcpp::MacAddress("00:04:4b:ea:b0:b4")); PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer->getIpAddress(), pcpp::IPv4Address("172.28.60.100")); @@ -163,13 +163,13 @@ PTF_TEST_CASE(GvcpForceIpCommand) // we get the raw buffer from the payload of the UDP layer and create a GvcpRequestLayer from the buffer GvcpForceIpRequestLayer gvcpRequestLayer(udpLayer->getLayerPayload(), udpLayer->getLayerPayloadSize()); - PTF_ASSERT_EQUAL(gvcpRequestLayer.getProtocol(), Gvcp); + PTF_ASSERT_EQUAL(gvcpRequestLayer.getProtocol(), GVCP); GvcpRequestHeader* header = gvcpRequestLayer.getGvcpHeader(); PTF_ASSERT_TRUE(header != nullptr); - PTF_ASSERT_EQUAL(header->getFlag(), 0x01); - PTF_ASSERT_EQUAL(header->getCommand(), GvcpCommand::ForceIpCmd); - PTF_ASSERT_EQUAL(header->getDataSize(), udpLayer->getLayerPayloadSize() - sizeof(GvcpRequestHeader)); - PTF_ASSERT_EQUAL(header->getRequestId(), 8787); + PTF_ASSERT_EQUAL(gvcpRequestLayer.getFlag(), 0x01); + PTF_ASSERT_EQUAL(gvcpRequestLayer.getCommand(), GvcpCommand::ForceIpCmd); + PTF_ASSERT_EQUAL(gvcpRequestLayer.getDataSize(), udpLayer->getLayerPayloadSize() - sizeof(GvcpRequestHeader)); + PTF_ASSERT_EQUAL(gvcpRequestLayer.getRequestId(), 8787); PTF_ASSERT_EQUAL(gvcpRequestLayer.getMacAddress(), pcpp::MacAddress("8c:e9:b4:01:63:b2")); PTF_ASSERT_EQUAL(gvcpRequestLayer.getIpAddress(), pcpp::IPv4Address("192.168.5.1")); @@ -189,13 +189,13 @@ PTF_TEST_CASE(GvcpForceIpCommand) // we get the GVCP layer from the packet auto gvcpRequestLayer = forceIpCommandPacket.getLayerOfType(); - PTF_ASSERT_EQUAL(gvcpRequestLayer->getProtocol(), Gvcp); + PTF_ASSERT_EQUAL(gvcpRequestLayer->getProtocol(), GVCP); GvcpRequestHeader* header = gvcpRequestLayer->getGvcpHeader(); PTF_ASSERT_TRUE(header != nullptr); - PTF_ASSERT_EQUAL(header->getFlag(), 0x01); - PTF_ASSERT_EQUAL(header->getCommand(), GvcpCommand::ForceIpCmd); - PTF_ASSERT_EQUAL(header->getDataSize(), gvcpRequestLayer->getLayerPayloadSize()); - PTF_ASSERT_EQUAL(header->getRequestId(), 8787); + PTF_ASSERT_EQUAL(gvcpRequestLayer->getFlag(), 0x01); + PTF_ASSERT_EQUAL(gvcpRequestLayer->getCommand(), GvcpCommand::ForceIpCmd); + PTF_ASSERT_EQUAL(gvcpRequestLayer->getDataSize(), gvcpRequestLayer->getLayerPayloadSize()); + PTF_ASSERT_EQUAL(gvcpRequestLayer->getRequestId(), 8787); PTF_ASSERT_EQUAL(gvcpRequestLayer->getMacAddress(), pcpp::MacAddress("8c:e9:b4:01:63:b2")); PTF_ASSERT_EQUAL(gvcpRequestLayer->getIpAddress(), pcpp::IPv4Address("192.168.5.1")); @@ -220,13 +220,13 @@ PTF_TEST_CASE(GvcpForceIpAck) // we get the raw buffer from the payload of the UDP layer and create a GvcpAcknowledgeLayer from the buffer GvcpForceIpAcknowledgeLayer gvcpAcknowledgeLayer(udpLayer->getLayerPayload(), udpLayer->getLayerPayloadSize()); - PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer.getProtocol(), Gvcp); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer.getProtocol(), GVCP); GvcpAckHeader* header = gvcpAcknowledgeLayer.getGvcpHeader(); PTF_ASSERT_TRUE(header != nullptr); - PTF_ASSERT_EQUAL(header->getStatus(), GvcpResponseStatus::Success); - PTF_ASSERT_EQUAL(header->getCommand(), GvcpCommand::ForceIpAck); - PTF_ASSERT_EQUAL(header->getAckId(), 8787); - PTF_ASSERT_EQUAL(header->getDataSize(), 0); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer.getStatus(), GvcpResponseStatus::Success); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer.getCommand(), GvcpCommand::ForceIpAck); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer.getAckId(), 8787); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer.getDataSize(), 0); } // test the GVCP layer directly from the packet @@ -241,7 +241,7 @@ PTF_TEST_CASE(GvcpForceIpAck) // we get the GVCP layer from the packet auto gvcpAcknowledgeLayer = forceIpAckPacket.getLayerOfType(); - PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer->getProtocol(), Gvcp); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer->getProtocol(), GVCP); PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer->getStatus(), GvcpResponseStatus::Success); PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer->getCommand(), GvcpCommand::ForceIpAck); PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer->getAckId(), 8787); @@ -265,13 +265,13 @@ PTF_TEST_CASE(GvcpReadRegisterCommand) // we get the raw buffer from the payload of the UDP layer and create a GvcpRequestLayer from the buffer GvcpRequestLayer gvcpRequestLayer(udpLayer->getLayerPayload(), udpLayer->getLayerPayloadSize()); - PTF_ASSERT_EQUAL(gvcpRequestLayer.getProtocol(), Gvcp); + PTF_ASSERT_EQUAL(gvcpRequestLayer.getProtocol(), GVCP); GvcpRequestHeader* header = gvcpRequestLayer.getGvcpHeader(); PTF_ASSERT_TRUE(header != nullptr); - PTF_ASSERT_EQUAL(header->getFlag(), 0x01); - PTF_ASSERT_EQUAL(header->getCommand(), GvcpCommand::ReadRegCmd); - PTF_ASSERT_EQUAL(header->getDataSize(), udpLayer->getLayerPayloadSize() - sizeof(GvcpRequestHeader)); - PTF_ASSERT_EQUAL(header->getRequestId(), 35824); + PTF_ASSERT_EQUAL(gvcpRequestLayer.getFlag(), 0x01); + PTF_ASSERT_EQUAL(gvcpRequestLayer.getCommand(), GvcpCommand::ReadRegCmd); + PTF_ASSERT_EQUAL(gvcpRequestLayer.getDataSize(), udpLayer->getLayerPayloadSize() - sizeof(GvcpRequestHeader)); + PTF_ASSERT_EQUAL(gvcpRequestLayer.getRequestId(), 35824); auto payload = gvcpRequestLayer.getLayerPayload(); PTF_ASSERT_TRUE(payload != nullptr); @@ -290,13 +290,13 @@ PTF_TEST_CASE(GvcpReadRegisterCommand) // we get the GVCP layer from the packet auto gvcpRequestLayer = readRegCmdPacket.getLayerOfType(); - PTF_ASSERT_EQUAL(gvcpRequestLayer->getProtocol(), Gvcp); + PTF_ASSERT_EQUAL(gvcpRequestLayer->getProtocol(), GVCP); GvcpRequestHeader* header = gvcpRequestLayer->getGvcpHeader(); PTF_ASSERT_TRUE(header != nullptr); - PTF_ASSERT_EQUAL(header->getFlag(), 0x01); - PTF_ASSERT_EQUAL(header->getCommand(), GvcpCommand::ReadRegCmd); - PTF_ASSERT_EQUAL(header->getDataSize(), gvcpRequestLayer->getLayerPayloadSize()); - PTF_ASSERT_EQUAL(header->getRequestId(), 35824); + PTF_ASSERT_EQUAL(gvcpRequestLayer->getFlag(), 0x01); + PTF_ASSERT_EQUAL(gvcpRequestLayer->getCommand(), GvcpCommand::ReadRegCmd); + PTF_ASSERT_EQUAL(gvcpRequestLayer->getDataSize(), gvcpRequestLayer->getLayerPayloadSize()); + PTF_ASSERT_EQUAL(gvcpRequestLayer->getRequestId(), 35824); auto payload = gvcpRequestLayer->getLayerPayload(); PTF_ASSERT_TRUE(payload != nullptr); @@ -320,13 +320,13 @@ PTF_TEST_CASE(GvcpReadRegisterAcknowledge) // we get the raw buffer from the payload of the UDP layer and create a GvcpAcknowledgeLayer from the buffer GvcpAcknowledgeLayer gvcpAcknowledgeLayer(udpLayer->getLayerPayload(), udpLayer->getLayerPayloadSize()); - PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer.getProtocol(), Gvcp); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer.getProtocol(), GVCP); auto header = gvcpAcknowledgeLayer.getGvcpHeader(); PTF_ASSERT_TRUE(header != nullptr); - PTF_ASSERT_EQUAL(header->getAckId(), 0x1fee); - PTF_ASSERT_EQUAL(header->getCommand(), GvcpCommand::ReadRegAck); - PTF_ASSERT_EQUAL(header->getDataSize(), udpLayer->getLayerPayloadSize() - sizeof(GvcpAckHeader)); - PTF_ASSERT_EQUAL(header->getStatus(), 0x0000); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer.getAckId(), 0x1fee); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer.getCommand(), GvcpCommand::ReadRegAck); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer.getDataSize(), udpLayer->getLayerPayloadSize() - sizeof(GvcpAckHeader)); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer.getStatus(), 0x0000); auto payload = gvcpAcknowledgeLayer.getLayerPayload(); PTF_ASSERT_TRUE(payload != nullptr); @@ -345,13 +345,13 @@ PTF_TEST_CASE(GvcpReadRegisterAcknowledge) // we get the GVCP layer from the packet auto gvcpAcknowledgeLayer = readRegAckPacket.getLayerOfType(); - PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer->getProtocol(), Gvcp); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer->getProtocol(), GVCP); auto header = gvcpAcknowledgeLayer->getGvcpHeader(); PTF_ASSERT_TRUE(header != nullptr); - PTF_ASSERT_EQUAL(header->getAckId(), 0x1fee); - PTF_ASSERT_EQUAL(header->getCommand(), GvcpCommand::ReadRegAck); - PTF_ASSERT_EQUAL(header->getDataSize(), gvcpAcknowledgeLayer->getLayerPayloadSize()); - PTF_ASSERT_EQUAL(header->getStatus(), 0x0000); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer->getAckId(), 0x1fee); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer->getCommand(), GvcpCommand::ReadRegAck); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer->getDataSize(), gvcpAcknowledgeLayer->getLayerPayloadSize()); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer->getStatus(), 0x0000); auto payload = gvcpAcknowledgeLayer->getLayerPayload(); PTF_ASSERT_TRUE(payload != nullptr); @@ -375,13 +375,13 @@ PTF_TEST_CASE(GvcpWriteRegisterCommand) // we get the raw buffer from the payload of the UDP layer and create a GvcpRequestLayer from the buffer GvcpRequestLayer gvcpRequestLayer(udpLayer->getLayerPayload(), udpLayer->getLayerPayloadSize()); - PTF_ASSERT_EQUAL(gvcpRequestLayer.getProtocol(), Gvcp); + PTF_ASSERT_EQUAL(gvcpRequestLayer.getProtocol(), GVCP); GvcpRequestHeader* header = gvcpRequestLayer.getGvcpHeader(); PTF_ASSERT_TRUE(header != nullptr); - PTF_ASSERT_EQUAL(header->getFlag(), 0x01); - PTF_ASSERT_EQUAL(header->getCommand(), GvcpCommand::WriteRegCmd); - PTF_ASSERT_EQUAL(header->getDataSize(), udpLayer->getLayerPayloadSize() - sizeof(GvcpRequestHeader)); - PTF_ASSERT_EQUAL(header->getRequestId(), 8788); + PTF_ASSERT_EQUAL(gvcpRequestLayer.getFlag(), 0x01); + PTF_ASSERT_EQUAL(gvcpRequestLayer.getCommand(), GvcpCommand::WriteRegCmd); + PTF_ASSERT_EQUAL(gvcpRequestLayer.getDataSize(), udpLayer->getLayerPayloadSize() - sizeof(GvcpRequestHeader)); + PTF_ASSERT_EQUAL(gvcpRequestLayer.getRequestId(), 8788); auto payload = gvcpRequestLayer.getLayerPayload(); PTF_ASSERT_TRUE(payload != nullptr); @@ -402,13 +402,13 @@ PTF_TEST_CASE(GvcpWriteRegisterCommand) // we get the GVCP layer from the packet auto gvcpRequestLayer = writeRegCmdPacket.getLayerOfType(); - PTF_ASSERT_EQUAL(gvcpRequestLayer->getProtocol(), Gvcp); + PTF_ASSERT_EQUAL(gvcpRequestLayer->getProtocol(), GVCP); GvcpRequestHeader* header = gvcpRequestLayer->getGvcpHeader(); PTF_ASSERT_TRUE(header != nullptr); - PTF_ASSERT_EQUAL(header->getFlag(), 0x01); - PTF_ASSERT_EQUAL(header->getCommand(), GvcpCommand::WriteRegCmd); - PTF_ASSERT_EQUAL(header->getDataSize(), gvcpRequestLayer->getLayerPayloadSize()); - PTF_ASSERT_EQUAL(header->getRequestId(), 8788); + PTF_ASSERT_EQUAL(gvcpRequestLayer->getFlag(), 0x01); + PTF_ASSERT_EQUAL(gvcpRequestLayer->getCommand(), GvcpCommand::WriteRegCmd); + PTF_ASSERT_EQUAL(gvcpRequestLayer->getDataSize(), gvcpRequestLayer->getLayerPayloadSize()); + PTF_ASSERT_EQUAL(gvcpRequestLayer->getRequestId(), 8788); auto payload = gvcpRequestLayer->getLayerPayload(); PTF_ASSERT_TRUE(payload != nullptr); @@ -434,13 +434,13 @@ PTF_TEST_CASE(GvcpWriteRegisterAcknowledge) // we get the raw buffer from the payload of the UDP layer and create a GvcpAcknowledgeLayer from the buffer GvcpAcknowledgeLayer gvcpAcknowledgeLayer(udpLayer->getLayerPayload(), udpLayer->getLayerPayloadSize()); - PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer.getProtocol(), Gvcp); - auto header = gvcpAcknowledgeLayer.getGvcpHeader(); - PTF_ASSERT_TRUE(header != nullptr); - PTF_ASSERT_EQUAL(header->getAckId(), 8788); - PTF_ASSERT_EQUAL(header->getCommand(), GvcpCommand::WriteRegAck); - PTF_ASSERT_EQUAL(header->getDataSize(), udpLayer->getLayerPayloadSize() - sizeof(GvcpAckHeader)); - PTF_ASSERT_EQUAL(header->getStatus(), 0x8006); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer.getProtocol(), GVCP); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer.getAckId(), 8788); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer.getCommand(), GvcpCommand::WriteRegAck); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer.getStatus(), 0x8006); + // In this file, the header data size is 0, but there are paddings in the payload, so we don't compare with the + // UDP's payload size. + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer.getDataSize(), 0); } // test the GVCP layer directly from the packet @@ -455,12 +455,12 @@ PTF_TEST_CASE(GvcpWriteRegisterAcknowledge) // we get the GVCP layer from the packet auto gvcpAcknowledgeLayer = writeRegAckPacket.getLayerOfType(); - PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer->getProtocol(), Gvcp); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer->getProtocol(), GVCP); auto header = gvcpAcknowledgeLayer->getGvcpHeader(); PTF_ASSERT_TRUE(header != nullptr); - PTF_ASSERT_EQUAL(header->getAckId(), 8788); - PTF_ASSERT_EQUAL(header->getCommand(), GvcpCommand::WriteRegAck); - PTF_ASSERT_EQUAL(header->getDataSize(), gvcpAcknowledgeLayer->getLayerPayloadSize()); - PTF_ASSERT_EQUAL(header->getStatus(), 0x8006); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer->getAckId(), 8788); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer->getCommand(), GvcpCommand::WriteRegAck); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer->getDataSize(), gvcpAcknowledgeLayer->getLayerPayloadSize()); + PTF_ASSERT_EQUAL(gvcpAcknowledgeLayer->getStatus(), 0x8006); } }