Commit e17d5e3a authored by garciay's avatar garciay
Browse files

Finalize PCAP, ETH, BTP & GN layers & codecs

Optimization and logs clean up should be done later
parent 47d4d8d0
Loading
Loading
Loading
Loading
+165 −1
Original line number Diff line number Diff line
@@ -101,6 +101,17 @@ module TestCodec_Btp {

    group LibItsBtp_testCases {

      testcase tc_Btp_A_Without_Payload() runs on TCType system TCType {
	TestBtpPacket(
		      m_btpA_Without_Payload ( 
					   1234,
					   0 
					    ),
		      true,
		      oct2bit('04D20000'O)
		      );
      }
	
      testcase tc_Btp_A() runs on TCType system TCType {
	TestBtpPacket(
		      m_btpA_With_Payload ( 
@@ -127,6 +138,20 @@ module TestCodec_Btp {
		      );
      }
	
      testcase tc_BtpReq_A() runs on TCType system TCType {
	TestBtpReq(
		   BtpReq:{msgOut := m_btpA_With_Payload ( 
							  1234,
							  0,
							  omit, 
							  'CAFEDECA'O 
							   )
		     },
		   true,
		   oct2bit('04D20000CAFEDECA'O)
		   );
      }
	
	/*testcase tc_Btp_A() runs on TCType system TCType {
	TestBtpPacket(
		      m_btpA (
@@ -137,6 +162,43 @@ module TestCodec_Btp {

    } // End of group LibItsBtp_testCases

    group testBtpPort {
            
      /**
       * @desc validate BtpReq
       * @verdict Pass on success, Fail otherwise
       */
      testcase tc_Btp_Port() runs on ItsBtp system ItsBtpSystem {
	var BtpReq v_btpReq;
	
	map(self:btpPort, system:btpPort);
        
      v_btpReq := valueof(
			  BtpReq : { msgOut := m_btpA_With_Payload ( 
								 1234,
								 0,
								 omit, 
								 'CAFEDECA'O 
								  )
			    }
			  );                
	btpPort.send(v_btpReq);
	tc_ac.start;
	alt {
	  [] btpPort.receive(BtpInd : { msgIn := ? }) {
	    setverdict(pass);
	  }
	  [] tc_ac.timeout {
	    setverdict(fail, "Expected message not received1");
	  }
	}
                
	unmap(self:btpPort, system:btpPort);
                
      }
            
    } // End of group testBtpPort 
        
  } // End of group LibItsBtp_testCases

  group encdec_functions {
@@ -190,7 +252,109 @@ module TestCodec_Btp {
	}
      }

    } // End of function TestBtpBtpPacket
    } // End of function TestBtpPacket

    function TestBtpReq(
			in template (value) BtpReq p_btpReq,
			in boolean p_decode := true, 
			in template (omit) bitstring p_expEncMsg := omit 
			) runs on TCType {
      var bitstring v_encMsg;
      var template (omit) TestRecord v_tr := { bs := p_expEncMsg };
      var BtpReq v_decMsg;
      var integer v_res := 0;

      // Encode template
      log("Encode template ", valueof(p_btpReq));
    v_encMsg := encvalue(p_btpReq);
      log("Encoded message:  ", bit2oct(v_encMsg));
      // Check result
      if (not isbound(v_encMsg)) {
	setverdict(fail, "Encoding failed!");
	stop;
      }
      if (ispresent(v_tr.bs)) {
	if (not match(v_encMsg, p_expEncMsg)) {
	  log("Expected message: ", bit2oct(valueof(p_expEncMsg)));
	  setverdict(fail, "Encoding failed, not the expected result!");
	  stop;
	}
      }
      setverdict(pass, "Encoding passed.");

      // Check decoding
      if (p_decode == true) {
      v_res := decvalue(v_encMsg, v_decMsg);
	log("Decoded message: ", v_decMsg);
	select (v_res) {
	case (0) {
	  if(match(v_decMsg, p_btpReq)) {
	    setverdict(pass);
	  } else {
	    setverdict(fail);
	  }
	}
	case (1) {
	  setverdict(fail, "Decoding failed.");
	}
	case (2) {
	  setverdict(fail, "Not enough bits.");
	}
	}
      }

    } // End of function TestBtpReq

    function TestBtpInd(
			in template (value) BtpInd p_btpInd,
			in boolean p_decode := true, 
			in template (omit) bitstring p_expEncMsg := omit 
			) runs on TCType {
      var bitstring v_encMsg;
      var template (omit) TestRecord v_tr := { bs := p_expEncMsg };
      var BtpInd v_decMsg;
      var integer v_res := 0;

      // Encode template
      log("Encode template ", valueof(p_btpInd));
    v_encMsg := encvalue(p_btpInd);
      log("Encoded message:  ", bit2oct(v_encMsg));
      // Check result
      if (not isbound(v_encMsg)) {
	setverdict(fail, "Encoding failed!");
	stop;
      }
      if (ispresent(v_tr.bs)) {
	if (not match(v_encMsg, p_expEncMsg)) {
	  log("Expected message: ", bit2oct(valueof(p_expEncMsg)));
	  setverdict(fail, "Encoding failed, not the expected result!");
	  stop;
	}
      }
      setverdict(pass, "Encoding passed.");

      // Check decoding
      if (p_decode == true) {
      v_res := decvalue(v_encMsg, v_decMsg);
	log("Decoded message: ", v_decMsg);
	select (v_res) {
	case (0) {
	  if(match(v_decMsg, p_btpInd)) {
	    setverdict(pass);
	  } else {
	    setverdict(fail);
	  }
	}
	case (1) {
	  setverdict(fail, "Decoding failed.");
	}
	case (2) {
	  setverdict(fail, "Not enough bits.");
	}
	}
      }

    } // End of function TestBtpInd

  } // End of group encdec_functions