123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- #include "RoutingDriverWrapper.h"
- #include "HeaderInsertion.h"
- #include "Filtering.h"
- #include "IPAFilteringTable.h"
- #include "TestsUtils.h"
- #include "ExceptionsTestFixture.h"
- #include "IPv4Packet.h"
- #include <string.h>
- #define MAX_SENT_BUFFER_SIZE 1500
- #define MAX_RECEIVE_BUFFER_SIZE 1500
- #define VALIDATE_WITH_MSG_AND_RETVAL(bRetVal,msg) \
- if (false == bRetVal){ \
- LOG_MSG_ERROR(msg); \
- return false; \
- }
- using namespace IPA;
- class ExceptionsTestNonIpPacket: public ExceptionsTestFixture {
- public:
-
- size_t m_nPacketSize;
-
- Byte *m_pSendBuffer;
-
-
- ExceptionsTestNonIpPacket() :
- m_nPacketSize(0), m_pSendBuffer(NULL) {
- m_name = "ExceptionsTestNonIpPacket";
- m_description =
- "Create a non-IP packet(version!=4 && version !=6) and \
- expect exception from Filter block";
- }
-
- virtual bool Run() {
- bool bRetVal = true;
- Byte *pReceiveBuffer = new Byte[MAX_RECEIVE_BUFFER_SIZE];
-
- LOG_MSG_DEBUG("Send the non-IPV4/IPV6 packet to the IPA");
- size_t nBytesSent = m_USB1ToIpaPipe.Send(m_pSendBuffer, m_nPacketSize);
- if (nBytesSent != m_nPacketSize) {
- LOG_MSG_ERROR("Not all data was sent into the IPA");
- return false;
- }
-
- size_t nBytesRead = m_IpaToA5ExceptionPipe.Receive(pReceiveBuffer,
- MAX_RECEIVE_BUFFER_SIZE);
- if (nBytesRead != nBytesSent) {
- LOG_MSG_ERROR("Not all data was read:");
- print_buff(pReceiveBuffer, nBytesRead);
- return false;
- }
-
- bRetVal = !memcmp(m_pSendBuffer, pReceiveBuffer, nBytesSent);
- if (false == bRetVal) {
- LOG_MSG_ERROR("Received packet is not equal, Received:");
- print_buff(pReceiveBuffer, nBytesRead);
- LOG_MSG_ERROR("Received packet is not equal, Sent:");
- print_buff(m_pSendBuffer, m_nPacketSize);
- return false;
- }
- return true;
- }
-
-
- virtual bool Setup() {
- bool bRetVal = true;
- m_pSendBuffer = new Byte[MAX_SENT_BUFFER_SIZE];
-
- m_nPacketSize = MAX_SENT_BUFFER_SIZE;
- bRetVal = LoadDefaultPacket(IPA_IP_v4, m_pSendBuffer, m_nPacketSize);
- VALIDATE_WITH_MSG_AND_RETVAL(bRetVal, "Load failed");
-
- m_pSendBuffer[0] &= 0x0F;
- m_pSendBuffer[0] |= 0x50;
-
- bRetVal = m_USB1ToIpaPipe.Init();
- VALIDATE_WITH_MSG_AND_RETVAL(bRetVal, "Pipe Initialization failed");
- bRetVal = m_IpaToA5ExceptionPipe.Init();
- VALIDATE_WITH_MSG_AND_RETVAL(bRetVal, "Pipe Initialization failed");
- return true;
- }
-
- virtual bool Teardown() {
- bool bRetVal = true;
- delete[] m_pSendBuffer;
- m_USB1ToIpaPipe.Destroy();
- m_IpaToA5ExceptionPipe.Destroy();
- return bRetVal;
- }
-
- };
- class ExceptionsTestFragmentedException: public ExceptionsTestFixture {
- public:
-
- size_t m_nPacketSize;
-
- Byte *m_pSendBuffer;
- Byte *m_pReceiveBuffer;
-
-
- ExceptionsTestFragmentedException():m_nPacketSize(0), m_pSendBuffer(NULL),
- m_pReceiveBuffer(NULL){
- m_name = "ExceptionsTestFragmentedException";
- m_description =
- "Send IP packet with MF set, create global Filter rule \
- that will hit it as Exception";
- }
-
- virtual bool Run() {
- bool bRetVal = true;
-
- ConfigureFilterGlobalRuleForMF();
-
- LOG_MSG_DEBUG("Send the IP packet with the MF bit set(size = %d)", m_nPacketSize);
- size_t nBytesSent = m_USB1ToIpaPipe.Send(m_pSendBuffer, m_nPacketSize);
- if (nBytesSent != m_nPacketSize) {
- LOG_MSG_ERROR("Not all data was sent into the IPA(only %d)", nBytesSent);
- return false;
- }
-
- size_t nBytesRead = m_IpaToA5ExceptionPipe.Receive(m_pReceiveBuffer,
- MAX_RECEIVE_BUFFER_SIZE);
- if (nBytesRead != nBytesSent) {
- LOG_MSG_ERROR("Not all data was read:");
- print_buff(m_pReceiveBuffer, nBytesRead);
- return false;
- }
-
- bRetVal = !memcmp(m_pSendBuffer, m_pReceiveBuffer, nBytesSent);
- if (false == bRetVal) {
- LOG_MSG_ERROR("Received packet is not equal, Received:");
- print_buff(m_pReceiveBuffer, nBytesRead);
- LOG_MSG_ERROR("Received packet is not equal, Sent:");
- print_buff(m_pSendBuffer, m_nPacketSize);
- return false;
- }
- return true;
- }
-
-
- virtual bool Setup() {
- bool bRetVal = true;
- m_pReceiveBuffer = new Byte[MAX_RECEIVE_BUFFER_SIZE];
- m_pSendBuffer = new Byte[MAX_RECEIVE_BUFFER_SIZE];
-
- TCPPacket tcpPacket;
-
- tcpPacket.SetMF(true);
-
- m_nPacketSize = tcpPacket.GetSize();
- tcpPacket.ToNetworkByteStream(m_pSendBuffer);
-
- bRetVal = m_USB1ToIpaPipe.Init();
- VALIDATE_WITH_MSG_AND_RETVAL(bRetVal, "Pipe Initialization failed");
- bRetVal = m_IpaToA5ExceptionPipe.Init();
- VALIDATE_WITH_MSG_AND_RETVAL(bRetVal, "Pipe Initialization failed");
- return true;
- }
-
- virtual bool Teardown() {
- bool bRetVal = true;
- delete[] m_pSendBuffer;
- m_USB1ToIpaPipe.Destroy();
- m_IpaToA5ExceptionPipe.Destroy();
- return bRetVal;
- }
-
- void ConfigureFilterGlobalRuleForMF(){
-
-
-
-
- }
-
- };
- class ExceptionsTestNonTCPUDP: public ExceptionsTestFixture {
- };
- static ExceptionsTestNonIpPacket exceptionsTestNonIpPacket;
- static ExceptionsTestFragmentedException exceptionsTestFragmentedException;
|