123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- #include "HeaderRemovalTests.h"
- #include "TestsUtils.h"
- #include <stdio.h>
- static const unsigned int HEADER_REMOVAL_TEST_MAX_PACKET_BYTE_SIZE = 1024;
- HeaderRemovalTOSCheck::HeaderRemovalTOSCheck()
- {
- m_name = "HeaderRemovalTOSCheck";
- m_description = "HeaderRemovalTOSCheck: Remove the header from the A2NDUN pipe and check the TOS field of the IP packet";
- }
- bool HeaderRemovalTOSCheck::Run()
- {
- bool bTestResult = true;
- Byte pPacketReceiveBuffer[HEADER_REMOVAL_TEST_MAX_PACKET_BYTE_SIZE] = {0};
- unsigned int nMagicNumber = 0x12345678;
- unsigned int nChannelID = 0xABCD;
- unsigned int nA2NDUNPacketByteSize = 0;
- unsigned int nBytesSent = 0;
- int nBytesReceived = 0;
- Byte *pA2NDUNPacket = CreateA2NDUNPacket(nMagicNumber, nChannelID, IPV4_FILE_PATH, &nA2NDUNPacketByteSize);
- if(0 == pA2NDUNPacket) {
- LOG_MSG_ERROR("Cannot load file to memory, exiting");
- return false;
- }
- LOG_MSG_INFO("A2 Packet was successfully created (%d bytes)", nA2NDUNPacketByteSize);
- if ( false == SetIPATablesToPassAllToSpecificClient(IPA_CLIENT_TEST2_PROD, IPA_CLIENT_TEST_CONS)) {
- LOG_MSG_ERROR("SetIPATablesToPassAllToSpecificClient failed, exiting test case");
- bTestResult = false;
- goto bail;
- }
- LOG_MSG_INFO("All tables were configured in order to output the packet to the correct pipe");
- LOG_MSG_INFO("Sending packet into the A2NDUN pipe(%d bytes) and the Pipe will add an header",
- nA2NDUNPacketByteSize);
- nBytesSent = m_A2NDUNToIpaPipe.Send(pA2NDUNPacket, nA2NDUNPacketByteSize);
- if (nA2NDUNPacketByteSize != nBytesSent)
- {
- bTestResult = false;
- goto bail;
- }
-
- LOG_MSG_INFO("Reading packet from the USB pipe");
- nBytesReceived = m_IpaToUsbPipe.Receive(pPacketReceiveBuffer, HEADER_REMOVAL_TEST_MAX_PACKET_BYTE_SIZE);
-
-
- if (0 == nBytesReceived)
- {
- bTestResult = false;
- goto bail;
- }
- LOG_MSG_INFO("Read buffer : ");
-
- for (int i = 0 ; i < nBytesReceived ; i++)
- {
- printf("0x%02x", pPacketReceiveBuffer[i]);
- }
- LOG_MSG_INFO("End of Read buffer.");
- if(0 != memcmp((const void *)pPacketReceiveBuffer,
- (const void *)(pA2NDUNPacket + (nBytesSent - nBytesReceived)),
- nBytesReceived)) {
- LOG_MSG_ERROR("Memory contains don't match");
- bTestResult = false;
- goto bail;
- }
- bail:
- delete pA2NDUNPacket;
- return bTestResult;
- }
- HeaderRemovalMetaDataFiltering::HeaderRemovalMetaDataFiltering()
- {
- m_name = "HeaderRemovalMetaDataFiltering";
- m_description =
- "HeaderRemovalMetaDataFiltering: check meta data based filtering";
- }
- bool HeaderRemovalMetaDataFiltering::Run()
- {
- bool bTestResult = true;
- Byte pPacketReceiveBuffer[HEADER_REMOVAL_TEST_MAX_PACKET_BYTE_SIZE] = {0};
- unsigned int nMagicNumber = 0x12345678;
- unsigned int nChannelID = 0xABCD;
- unsigned int nA2NDUNPacketByteSize = 0;
- unsigned int nMetaData = 0;
- unsigned int nMetaDataMask = 0xFFFF;
- unsigned int nBytesSent = 0;
- int nBytesReceived = 0;
- Byte *pA2NDUNPacket = CreateA2NDUNPacket(nMagicNumber, nChannelID, IPV4_FILE_PATH, &nA2NDUNPacketByteSize);
- if(0 == pA2NDUNPacket) {
- LOG_MSG_ERROR("Cannot load file to memory, exiting");
- return false;
- }
- nMetaData = (nChannelID << 16) | (0xFFFF & nA2NDUNPacketByteSize);
- LOG_MSG_INFO("*************nMetaData == (0x%x)", nMetaData);
- LOG_MSG_INFO("A2 Packet was successfully created (%d bytes)", nA2NDUNPacketByteSize);
- SetRoutingTableToPassAllToSpecificClient(IPA_CLIENT_TEST_CONS);
- SetHeaderInsertionTableAddEmptyHeaderForTheClient(IPA_CLIENT_TEST_CONS);
- LOG_MSG_INFO("Configuring Filtering module...");
- if (false ==
- ConfigureFilteringBlockWithMetaDataEq(
- IPA_CLIENT_TEST_CONS,
- nMetaData,
- nMetaDataMask)) {
- bTestResult = false;
- goto bail;
- }
- LOG_MSG_INFO("Sending packet into the A2NDUN pipe(%d bytes) and the Pipe will add an header",
- nA2NDUNPacketByteSize);
- nBytesSent = m_A2NDUNToIpaPipe.Send(pA2NDUNPacket, nA2NDUNPacketByteSize);
- if (nA2NDUNPacketByteSize != nBytesSent) {
- bTestResult = false;
- goto bail;
- }
-
- LOG_MSG_INFO("Reading packet from the USB pipe");
- nBytesReceived = m_IpaToUsbPipe.Receive(pPacketReceiveBuffer, HEADER_REMOVAL_TEST_MAX_PACKET_BYTE_SIZE);
-
-
- if (0 == nBytesReceived) {
- bTestResult = false;
- goto bail;
- }
- LOG_MSG_INFO("Read buffer : ");
-
- for (int i = 0 ; i < nBytesReceived ; i++) {
- printf("0x%02x", pPacketReceiveBuffer[i]);
- }
- LOG_MSG_INFO("End of Read buffer.");
- if(0 != memcmp((const void *)pPacketReceiveBuffer,
- (const void *)(pA2NDUNPacket + (nBytesSent - nBytesReceived)),
- nBytesReceived)) {
- LOG_MSG_ERROR("Memory contains don't match");
- bTestResult = false;
- goto bail;
- }
- bail:
- delete pA2NDUNPacket;
- return bTestResult;
- }
- static HeaderRemovalTOSCheck headerRemovalTOSCheck;
- static HeaderRemovalMetaDataFiltering headerRemovalMetaDataFiltering;
|