/****************************************************************************** * File: ICMP2ETH.ttcn * * Purpose: * This module sends a cycle of ICMP/IP messages (pings) * over a LANL2 test port in Translation port mode * and receives the ICMP echo sent by the kernel IP stack * http://www.eclipse.org/legal/epl-v10.html * https://en.wikipedia.org/wiki/List_of_IP_protocol_numbers * * The standard specifies permitted values for setstate: * - 0 (meaning translated) * - 1 (meaning not translated) * - 2 (meaning fragmented) * - 3 (meaning partially translated) * - 4 (meaning discarded message) * ******************************************************************************/ //root privileges needed!!!! module ICMP2ETH { //========================================================================= // Module Parameters //========================================================================= modulepar OCT6 tsp_eth_dst_addr; modulepar OCT6 tsp_eth_src_addr; modulepar OCT2 tsp_type_field; modulepar charstring src_IP; modulepar charstring dst_IP1, dst_IP2, dst_IP3; //========================================================================= // Import Part //========================================================================= import from ICMP_Types all; import from IP_Types all; import from LANL2asp_Types all; import from LANL2asp_PortType all; import from General_Types all; //import from StringLib all; //========================================================================= //Component Types //========================================================================= type component MTC { port IcmpPort Icmp_PCO; } type component MySystem { port LANL2asp_PT Lan_PCO; } //========================================================================= // Templates //========================================================================= template PDU_ICMP t_PDU_ICMP_ECho(OCT2 par_seq):= { echo:={ type_field:=8, code:=0, checksum:='0000'O, identifier:='0002'O, sequence_number:=par_seq, data:='6162636465666768696a6b6c6d6e6f7071727374757677616263646566676869'O } } template IPv4_header t_IPv4_header := { ver:=4, hlen:=5, tos:=0, tlen:=10, id:=50000, res:='0'B, dfrag:='0'B, mfrag:='0'B, foffset:=0, ttl:=128, proto:=1,//ICMP cksum:=0, srcaddr:=f_IPv4_addr_enc(src_IP), dstaddr:=f_IPv4_addr_enc(dst_IP1) } template IPv4_packet t_IPv4_packet(octetstring par_payload):= { header:= t_IPv4_header , ext_headers:=omit, payload:=par_payload } //========================================================================= // Data Types //========================================================================= type boolean Bool1; //ControlRequest type boolean Bool2; //ControlResponse type record Bool3 { boolean bool } type record Bool4 { boolean bool } type charstring ip_address [1..3]; //========================================================================= // Translation port //========================================================================= // port type IcmpPort is the internal interface of the dual-faced port // This port is communicating directly with the SUT using the Test Port of LANL2asp_PT type port IcmpPort message map to LANL2asp_PT{ in PDU_ICMP from ASP_LANL2 with dec_ASP_LANL2_Icmp(); // Sender port out PDU_ICMP to ASP_LANL2 with enc_PDU_ICMP(); // Receiver port in Bool3, Bool4; in ASP_LANL2_Error, ASP_LANL2_open_result, ASP_v2_LANL2_Error, ASP_v2_LANL2; } //========================================================================= // Functions //========================================================================= //========================================================================= // enc_PDU_ICMP //========================================================================= function enc_PDU_ICMP (in PDU_ICMP par_PDU_ICMP, out ASP_LANL2 par_ASP_LANL2 ) { var PDU_ICMP v_PDU_ICMP:=par_PDU_ICMP; var IPv4_packet v_IPv4_packet; v_IPv4_packet.payload:=f_enc_PDU_ICMP(v_PDU_ICMP); log ("************* Destination address", v_IPv4_packet.header) v_IPv4_packet.ext_headers:=omit; v_IPv4_packet.header:=valueof(t_IPv4_header); var ASP_LANL2 v_ASP_LANL2; var octetstring data:=f_IPv4_enc_eth(v_IPv4_packet); var OCT2 cksum := f_IPv4_checksum(data); data[10] := cksum[0]; data[11] := cksum[1]; v_ASP_LANL2.payload:=data; log("************* Sent Payload is: ", lengthof (v_ASP_LANL2.payload), " Bytes") v_ASP_LANL2.eth_src_addr:=tsp_eth_src_addr; v_ASP_LANL2.eth_dst_addr:=tsp_eth_dst_addr; v_ASP_LANL2.type_field:=tsp_type_field; par_ASP_LANL2 := v_ASP_LANL2; port.setstate(0, "Translated"); // translated log("************* ICMP message translated"); } with { extension "prototype(fast)" } //========================================================================= // dec_ASP_LANL2_Icmp //========================================================================= function dec_ASP_LANL2_Icmp (in ASP_LANL2 par_msg, out PDU_ICMP result ) { var PDU_ICMP v_PDU_ICMP; var IPv4_packet v_IPv4_packet:= f_IPv4_dec(par_msg.payload); if (v_IPv4_packet.header.proto ==1)//ICMP { v_PDU_ICMP:= f_dec_PDU_ICMP(v_IPv4_packet.payload) result:=v_PDU_ICMP; log("************* Received Payload is: ", lengthof (par_msg.payload), " Bytes") log("************* ICMP Echo Reply received") // translated port.setstate(0, "Translated"); // translated return; } else { log("************* Non-ICMP message received"); port.setstate(3); //discard return; } port.setstate(1, "Not translated"); // not translated } with { extension "prototype(fast)" } //========================================================================= // dec_ASP_v2_LANL2_Icmp //========================================================================= function dec_ASP_v2_LANL2_Icmp (in ASP_v2_LANL2 par_msg, out PDU_ICMP result) { var PDU_ICMP v_PDU_ICMP; var IPv4_packet v_IPv4_packet:= f_IPv4_dec(par_msg.payload); if (v_IPv4_packet.header.proto ==1)//ICMP { v_PDU_ICMP:= f_dec_PDU_ICMP(v_IPv4_packet.payload) result:=v_PDU_ICMP; log("************* ICMP Echo Reply received") // translated port.setstate(0, "Translated"); // translated return; } else { log("Non-ICMP message received!!"); port.setstate(3); //discard return; } port.setstate(1, "Not translated"); // not translated } with { extension "prototype(fast)" } //========================================================================= // Testcases //========================================================================= testcase tc_ICMP_echo() runs on MTC system MySystem { timer t_time:= 4.0; var integer nbr_macAddress:= 3; var OCT2 v_cycle; var IPv4_packet v_IPv4_packet; // initiate internal connections with mapped ports // mapping MTC's port to system's port map(self:Icmp_PCO, system:Lan_PCO); for (var integer j := 1; j <= nbr_macAddress; j := j + 1) { v_cycle:=int2oct(j+200,2); for (var integer i := 1; i <= 3; i := i + 1) { var ip_address v_ip_address; v_ip_address[1] := dst_IP1; v_ip_address[2] := dst_IP2; v_ip_address[3] := dst_IP3; v_IPv4_packet.header.dstaddr:= char2oct(v_ip_address[i]); log("************* Destination IP Address is: ", v_IPv4_packet.header.dstaddr); log("************* Destination counter is: ", i); Icmp_PCO.send(t_PDU_ICMP_ECho(v_cycle)); log("************* ICMP Request sent"); t_time.start; // check possible answers and evaluate them alt { []Icmp_PCO.receive { log("************* ICMP Echo Reply Received") ; setverdict (pass, "Life is beautiful"); }; []t_time.timeout { log("************* Bye"); stop; }; }; } } //endfor // destroy connections unmap(self:Icmp_PCO, system:Lan_PCO); setverdict(pass) }//testcase end //========================================================================= // Control //========================================================================= control { execute(tc_ICMP_echo()) } }//endmodule