Commit 7835cce5 authored by berge's avatar berge
Browse files

Merged NewModuleStructure into Phase2/ttcn3 (174-Head)

parent 8784ae52
Loading
Loading
Loading
Loading
+49 −129
Original line number Original line Diff line number Diff line
@@ -12,66 +12,11 @@
	import from LibCommon_DataStrings all;
	import from LibCommon_DataStrings all;
	import from LibCommon_VerdictControl { type FncRetCode };
	import from LibCommon_VerdictControl { type FncRetCode };
	//LibIpv6
	//LibIpv6
	import from LibIpv6_Interface_TypesAndValues all ;
	import from LibIpv6_ExternalFunctions all;
	import from LibIpv6_ExternalFunctions all;
	import from LibIpv6_Interface all ;
	import from LibIpv6_ModuleParameters all ;
	import from LibIpv6_ModuleParameters all ;
	import from LibIpv6_CommonRfcs_TypesAndValues all;
	import from LibIpv6_CommonRfcs_TypesAndValues all;
	import from LibIpv6_CommonRfcs_Templates all;
	import from LibIpv6_CommonRfcs_Templates all;
	import from LibIpv6_Rfc2460Root_TypesAndValues { type all; const all };
	//import from LibIpv6_Rfc2460Root_Templates all;
	import from LibIpv6_Rfc3775Mipv6_ExtHdrFunctions all;

group extHdrFns {

	/*
	 * @desc 	This goes through the extension header list and calculates length, checksum
	 *			and other specific functions of the different extension headers
	 * @param 	p_srcAddr Source Address of IPv6 packet
	 * @param 	p_dstAddr Dst Address of IPv6 packet
	 * @param 	p_extHdrList Extension Header List
	 * @return 	execution status 
	*/
	function f_setExtensionHeaders(	inout ExtensionHeaderList p_extHdrList,
									in Ipv6Address p_srcAddr,
									in Ipv6Address p_dstAddr,
									in Ipv6Packet p_ipv6Packet)
	runs on LibIpv6Node
	return FncRetCode {
		var UInt8 i;
		var Ipv6Address v_homeAddress := c_16ZeroBytes;
		var UInt8 v_nrOfTunnelHdr := 0;

		for (i:=0; i<sizeof(p_extHdrList);i:=i+1) {
			if (ischosen(p_extHdrList[i].mipHeader)) {
				if (f_isPresentHomeAddressOption(p_extHdrList, v_homeAddress) == e_success) {
					f_setMipHeader(	v_homeAddress,
									p_dstAddr,
									p_extHdrList[i].mipHeader);	
				}
				else if (f_isPresentRoutingHeaderType2(p_extHdrList, v_homeAddress) == e_success) {
					f_setMipHeader(	p_srcAddr,
									v_homeAddress,									
									p_extHdrList[i].mipHeader);	
				}
				else {
					f_setMipHeader(	p_srcAddr,
									p_dstAddr,
									p_extHdrList[i].mipHeader);
				}
			}
			else if (ischosen(p_extHdrList[i].tunneledIpv6)) {
				v_nrOfTunnelHdr := v_nrOfTunnelHdr + 1;
				p_extHdrList[i].tunneledIpv6.payloadLength := fx_tunnelledPayloadLength(p_ipv6Packet, v_nrOfTunnelHdr);
			}
		/*	else if (ischosen(p_extHdrList[i].)) {
				f_setSecurityHdr();
			}  */
		}//end for

		return e_success;
	}//end f_setExtensionHeaders
		
	}//end group extHdrFns


	group calcPrefixFns {
	group calcPrefixFns {
		
		
@@ -208,7 +153,6 @@ group extHdrFns {
	 * @desc 	This goes through the ExtensionHeaderList and
	 * @desc 	This goes through the ExtensionHeaderList and
	 *			checks if a Routing Header type 2 is present.
	 *			checks if a Routing Header type 2 is present.
	 * @param 	p_extHdrList ExtensionHeaderList to be treated
	 * @param 	p_extHdrList ExtensionHeaderList to be treated
	 * @param 	p_homeAddr Home address
	 * @return 	execution status 
	 * @return 	execution status 
	*/
	*/
	function f_isPresentRoutingHeaderType2(	in ExtensionHeaderList p_extHdrList,
	function f_isPresentRoutingHeaderType2(	in ExtensionHeaderList p_extHdrList,
@@ -231,97 +175,73 @@ group extHdrFns {
		return v_ret;
		return v_ret;
	}//end function f_isPresentRoutingHeaderType2
	}//end function f_isPresentRoutingHeaderType2



	/*
	/*
	 * @desc 	This generates a random Init Cookie
	 * @desc 	This goes through the ExtensionHeaderList and
	 * @return 	Init Cookie
	 *			checks if a Binding Authority Data option is present.
	 * @param 	p_extHdrList ExtensionHeaderList to be treated
	 * @return 	execution status 
	*/
	*/
	function f_createInitCookie()
	function f_isPresentBindingAuthorityDataOption ( in ExtensionHeaderList p_extHdrList )
	runs on LibIpv6Node
	return Oct8 {
		var Oct8 v_cookie := int2oct(float2int(int2float(20000-5000)*rnd())+5000, 8);


		return v_cookie;
	}//end f_createInitCookie

	/*
	 * @desc 	This generates a Home Keygen Token
	 * @param 	p_kcn Correspondant node's secret key
	 * @param 	p_homeAddr Home address
	 * @param 	p_nonce Home nonce
	 * @return 	Home Keygen Token
	*/
	function f_createHomeKeygenToken(in octetstring p_kcn, in Ipv6Address p_homeAddr, in octetstring p_nonce)
	runs on LibIpv6Node
	runs on LibIpv6Node
	return Oct8 {
	return FncRetCode {
		var octetstring v_mac := c_8ZeroBytes;
		var FncRetCode v_ret := e_error;
		var Oct8 v_token := c_8ZeroBytes;
		var UInt8 i,j;
		var UInt8 i;

		v_mac := fx_computeHMAC(p_kcn, p_homeAddr & p_nonce & int2oct(0,1), e_sha1 );


		for ( i := 0; i < 8; i := i + 1 ) {
		//select ext hdrs that need special calculation
			v_token[i] := v_mac[i];
		for ( i := 0; i < sizeof ( p_extHdrList ) and ( v_ret != e_success ); i := i + 1 ) {
			if ( ischosen ( p_extHdrList[i].mipHeader )  ) {
				if ( ischosen ( p_extHdrList[i].mipHeader.mipMessage.bindingAck ) ) {
					for ( j := 0; j < sizeof ( p_extHdrList[i].mipHeader.mipMessage.bindingAck.mipOptions ); j := j + 1 ) {
						if ( ischosen ( p_extHdrList[i].mipHeader.mipMessage.bindingAck.mipOptions[j].mipBindingAuthorizationData ) == true ) {
							v_ret := e_success;
						}
					}
				}
			}
		}
		}


		return v_token;
		if ( v_ret == e_error ) {
	}//end f_createHomeKeygenToken
			log ( "**** f_isPresentBindingAuthorityDataOption: ERROR: Binding Authentication Data option is not present in Binding Ack **** " );

	/*
	 * @desc 	This generates a Care-of Keygen Token
	 * @param 	p_kcn Correspondant node's secret key
	 * @param 	p_careOfAddr Care-of address
	 * @param 	p_nonce Home nonce
	 * @return 	Care-of Keygen Token
	*/
	function f_createCareOfKeygenToken(in octetstring p_kcn, in Ipv6Address p_careOfAddr, in octetstring p_nonce)
	runs on LibIpv6Node
	return Oct8 {
		var octetstring v_mac := c_8ZeroBytes;
		var Oct8 v_token := c_8ZeroBytes;
		var UInt8 i;

		v_mac := fx_computeHMAC(p_kcn, p_careOfAddr & p_nonce & int2oct(1,1), e_sha1 );

		for ( i := 0; i < 8; i := i + 1 ) {
			v_token[i] := v_mac[i];
		}
		}


		return v_token;
		return v_ret;
	}//end f_createCareOfKeygenToken


	}//end function f_isPresentBindingAuthorityDataOption


	/*
	/*
	 * @desc 	This generates a Binding Management Key
	 * @desc 	This goes through the ExtensionHeaderList and
	 * @param 	p_homeKeygenToken Home Keygen Token
	 *			checks if a Binding Refresh Advice option is present.
	 * @param 	p_careOfKeygenToken Care-of Keygen Token 
	 * @param 	p_extHdrList ExtensionHeaderList to be treated
	 * @return 	Binding Management Key
	 * @return 	execution status 
	*/
	*/
	function f_createBindingManagementKey(in Oct8 p_homeKeygenToken, in Oct8 p_careOfKeygenToken)
	function f_isPresentBindingRefreshAdviceOption ( in ExtensionHeaderList p_extHdrList )
	runs on LibIpv6Node
	return Oct8 {
		var octetstring v_key := c_8ZeroBytes;

		v_key := fx_computeHash(p_homeKeygenToken & p_careOfKeygenToken, e_sha1);

		return v_key;
	}//end f_createBindingManagementKey


	/*
	 * @desc 	This generates a random Security Parameters Index
	 * @return 	Security Parameters Index
	*/
	function f_createSecurityParametersIndex()
	runs on LibIpv6Node
	runs on LibIpv6Node
	return Oct4 {
	return FncRetCode {
		var Oct4 v_spi := int2oct(float2int(int2float(20000-5000)*rnd())+5000, 4);
		var FncRetCode v_ret := e_error;

		var UInt8 i,j;
		return v_spi;
	}//end f_createSecurityParametersIndex


		//select ext hdrs that need special calculation
		for ( i := 0; i < sizeof ( p_extHdrList ) and ( v_ret != e_success ); i := i + 1 ) {
			if ( ischosen ( p_extHdrList[i].mipHeader )  ) {
				if ( ischosen ( p_extHdrList[i].mipHeader.mipMessage.bindingAck ) ) {
					for ( j := 0; j < sizeof ( p_extHdrList[i].mipHeader.mipMessage.bindingAck.mipOptions ); j := j + 1 ) {
						if ( ischosen ( p_extHdrList[i].mipHeader.mipMessage.bindingAck.mipOptions[j].mipOptBindingRefreshAdvice ) == true ) {
							v_ret := e_success;
						}
					}
				}
			}
		}


		if ( v_ret == e_error ) {
			log ( "**** f_isPresentBindingRefreshAdviceOption: ERROR: Binding Authentication Data option is not present in Binding Ack **** " );
		}


		return v_ret;


	}//end function f_isPresentBindingRefreshAdviceOption


} // end module LibIpv6_CommonRfcs_Functions
} // end module LibIpv6_CommonRfcs_Functions
	
	
+6 −15
Original line number Original line Diff line number Diff line
@@ -15,13 +15,12 @@ module LibIpv6_CommonRfcs_TypesAndValues {
	import from LibCommon_TextStrings all;
	import from LibCommon_TextStrings all;
	import from LibCommon_Time all ;
	import from LibCommon_Time all ;



	group DefaultConstants {
	group DefaultConstants {
		const UInt16 c_defId 	:= 10; // for ICMP echo proc
		const UInt16 c_defId 	:= 10; // for ICMP echo proc
		const UInt16 c_defSeqNo	:= 20; // for ICMP echo proc
		const UInt16 c_defSeqNo	:= 20; // for ICMP echo proc
	}
	}


	group rfc3513AddressingArchitecture {
	group rfc4291AddressingArchitecture {


		type Oct16 Ipv6Address;
		type Oct16 Ipv6Address;
		type UInt8 PrefixLength ;//indicates nr of bits to be used as Prefix
		type UInt8 PrefixLength ;//indicates nr of bits to be used as Prefix
@@ -35,7 +34,7 @@ module LibIpv6_CommonRfcs_TypesAndValues {
		}
		}
		
		
		
		
	}//end group rfc3513AddressingArchitecture
	}//end group rfc4291AddressingArchitecture
	
	


	group ipv6Options {
	group ipv6Options {
@@ -43,6 +42,7 @@ module LibIpv6_CommonRfcs_TypesAndValues {
		const UInt8	c_optLen0 := 0;
		const UInt8	c_optLen0 := 0;
		const UInt8 c_optLen1 := 1;
		const UInt8 c_optLen1 := 1;
		const UInt8 c_optLen2 := 2;
		const UInt8 c_optLen2 := 2;
		const UInt8 c_optLen3 := 3;
		const UInt8 c_optLen4 := 4;
		const UInt8 c_optLen4 := 4;
		const UInt8 c_optLen6 := 6;
		const UInt8 c_optLen6 := 6;
		const UInt8	c_optLen16 := 16;
		const UInt8	c_optLen16 := 16;
@@ -235,6 +235,9 @@ module LibIpv6_CommonRfcs_TypesAndValues {
	
	
		group rfc3775Options {
		group rfc3775Options {


			const octetstring		c_preDefAIOption := '0101000000001000'O;
			const octetstring		c_preDefHAIOption := '0801000000000040'O;

			/*
			/*
			 * @desc  Extra ICMP option introduced by RFC3775, clause 7.3
			 * @desc  Extra ICMP option introduced by RFC3775, clause 7.3
			*/
			*/
@@ -294,16 +297,4 @@ module LibIpv6_CommonRfcs_TypesAndValues {
	} // end ipv6Options
	} // end ipv6Options




	group security {

		type enumerated CryptoFunction {
			e_null(0),
			e_sha1(1)
		}
		with {
			encode "use=com.testingtech.ttcn.tci.*;";
		}
	} // end security


} // end LibIpv6_CommonRfcs_TypesAndValues
} // end LibIpv6_CommonRfcs_TypesAndValues
+70 −29
Original line number Original line Diff line number Diff line
@@ -12,13 +12,11 @@
	//LibCommon
	//LibCommon
	import from LibCommon_BasicTypesAndValues all;
	import from LibCommon_BasicTypesAndValues all;
	import from LibCommon_DataStrings all;
	import from LibCommon_DataStrings all;
	import from LibCommon_VerdictControl all;
	//LibIpv6
	//LibIpv6
	import from LibIpv6_CommonRfcs_TypesAndValues { type all };
	import from LibIpv6_CommonRfcs_TypesAndValues { type all };
	import from LibIpv6_Interface { type Ipv6Packet };
	import from LibIpv6_Interface_TypesAndValues all;
	import from LibIpv6_Rfc2460Root_TypesAndValues {type all};
	import from LibIpv6_Interface_TypesAndValues all;

	import from LibIpv6_Rfc3775Mipv6_ExtHdrTypesAndValues all;



	/* @desc    This external function calculates the payload length
	/* @desc    This external function calculates the payload length
	 *			of a IPv6 packet
	 *			of a IPv6 packet
@@ -77,36 +75,65 @@
//	external function fx_dstOptHdrLength( in  ExtensionHeader p_extHdr) 
//	external function fx_dstOptHdrLength( in  ExtensionHeader p_extHdr) 
//	return UInt8;
//	return UInt8;


	/* @desc   This external function calculates a Message Authentication Code
	/* @desc   Apply indicated encryption algorithm to the message.
	 *			
	 * @param  p_crypto Cryptographic function used to compute MAC
	 * @param  p_key Key used to compute the MAC
	 * @param  p_key Key used to compute the MAC
	 * @param  p_message Octetstring message
	 * @param  p_message Octetstring message
	 * @param  p_crypto Cryptographic function used to compute MAC
	 * @return Message HMAC
	 * @return Message HMAC
	*/
	*/
	external function fx_computeHMAC(in octetstring p_key, in octetstring p_message, CryptoFunction p_crypto ) 
//	external function fx_encrypt( EncryptionAlgo p_encryptionAlgo, in octetstring p_key, in octetstring p_message) 
	return octetstring;
//	return octetstring;


	/* @desc   This external function calculates a SHA1 hash
	external function fx_encrypt( 	in IpSecProtocolMode p_ipSecProtocolMode,
									in EncryptionAlgo p_encryptionAlgo,
									in octetstring p_key,
									in PlaintextData p_plaintextData,
									out EncryptResult p_encryptResult) 
	return FncRetCode;

	external function fx_decrypt( 	in UInt8 p_ivLength, 
									in UInt8 p_icvLength, 
									in IpSecProtocolMode p_ipSecProtocolMode, 
									in EncryptionAlgo p_encryptionAlgo, 
									in octetstring p_key,
									in octetstring p_encryptedMsg,
									out PlaintextData p_plaintextData) 
	return FncRetCode;

	/* @desc    Apply indicated Integrity algorithm to the message. Message is an octetstring.
	 *			If e_sha1_96 is chosen, then the key input shall be ignored.
	 *			
	 * @param  p_integrityAlgo Cryptographic function used to compute MAC
	 * @param  p_key Key used to compute the MAC
	 * @param  p_message Octetstring message
	 * @param  p_message Octetstring message
	 * @param  p_crypto Cryptographic function used to compute MAC
	 * @return Message HMAC
	 * @return Message hash
	*/
	*/
	external function fx_computeHash(in octetstring p_message, CryptoFunction p_crypto ) 
	external function fx_integrity( IntegrityAlgo p_integrityAlgo, in octetstring p_key, in octetstring p_message) 
	return octetstring;
	return octetstring;


	/* @desc 	This external function computes the Authenticator for 
	/* @desc    Apply indicated Integrity algorithm to the message. Message can only be an EspHeader.
	 *          return routability procedure
	 *			If e_sha1_96 is chosen, then the key input shall be ignored.
	 * @param 	p_careOfAddr Care-of address
	 *			
	 * @param 	p_cnAddr Address of the correspondant
	 * @param  p_integrityAlgo Cryptographic function used to compute MAC
	 * @param 	p_ipv6Packet Ipv6 Packet
	 * @param  p_key Key used to compute the MAC
	 * @param 	p_kbm Binding management key
	 * @param  p_espHeader EspHeader
	 * @return 	Authenticator
	 * @param  p_integrityResult  Result of Integrity function
	 * @return Message HMAC
	*/
	*/
	external function fx_bindingAuthenticator(in octetstring p_careOfAddr, 
	external function fx_integrityEspHdr( 	in IntegrityAlgo p_integrityAlgo,
											  in Ipv6Address p_careOfAddr, 
											in octetstring p_key,
											  in Ipv6Address cnAddr,
											in EspHeader p_espHeader,
											  in Ipv6Packet p_ipv6Packet,
											out IntegrityResult p_integrityResult) 
											  in octetstring p_kbm)
	return FncRetCode;

	/* @desc 	This external function runs the MipHeader through Codec and returns 
	 *			the octetstring representing the MipHeader
	 *			
	 * @param 	p_mipHeader MIp Header to be encoded to octetstring
	 * @return 	octetstring
	*/
	external function fx_mipHdrToOct(MipHeader p_mipHeader)
	return octetstring;
	return octetstring;
	
	
	/* @desc 	This external function computes Integrity Check Value
	/* @desc 	This external function computes Integrity Check Value
@@ -114,8 +141,22 @@
	 * @param 	p_sa Security association
	 * @param 	p_sa Security association
	 * @return 	Integrity Check Value
	 * @return 	Integrity Check Value
	*/
	*/
	external function fx_IntegrityCheckValue( in Ipv6Packet p_ipv6Packet,
	external function fx_integrityCheckValue( in Ipv6Packet p_ipv6Packet,
											  in octetstring p_sa)
											  in octetstring p_sa,
	return octetstring; 
											  out octetstring p_result)
	return FncRetCode;

	/* @desc 	This external function returns the padding octets that
	 *			are needed to align to a given Byte Boundary.
	 *			Example: Byte Boundary == 4
	 *			If lenghtof EspHeader is 3, then result = 1
	 * @param 	p_byteBoundary Align to a multiple of this value
	 * @param 	p_espHeader ESP-HDR to be aligned
	 * @return 	Padding needed to align
	*/
	external function fx_byteAlignEspHeader(	in UInt8 p_byteBoundary,
												in EspHeader p_espHeader,
												out octetstring p_result)
	return FncRetCode;


}// end module LibIpv6_ExternalFunctions
}// end module LibIpv6_ExternalFunctions
+0 −129
Original line number Original line Diff line number Diff line
/*
 *	@author 	STF 276
 *  @version 	$Id$
 *	@desc		This module defines the interface for any function
 *              part of the IPv6 library.
 *				Further on, this module defines a meta type over all IPv6
 *              packets supported by the IPv6 library as well as
 *              templates for it. Also it includes the raw Ipv6
 *              message type which can be used for sending encoded
 *              Ipv6 packets.
 *
 */
module LibIpv6_Interface {

	//LibCommon
	import from LibCommon_Time all ;
	//LibIpv6
	import from LibIpv6_Rfc2460Root_TypesAndValues {type all};
	import from LibIpv6_Rfc2463Icmpv6_TypesAndValues {type all};
	import from LibIpv6_Rfc2461NeighborDiscovery_TypesAndValues {type all};
	import from LibIpv6_Rfc2894RouterRenumbering_TypesAndValues {type all};
	import from LibIpv6_Rfc3775Mipv6_TypesAndValues {type all};
	import from LibIpv6_Rfc0768Udp_TypesAndValues all ;
	import from LibIpv6_Rfc4303Esp_TypesAndValues all;

	/*
	 * @desc	This type is used to define behavior within the IPv6 library
	 *			which can be executed on  both, host as well as router,
	 *			components. It may also be used to specify behavior outside of
	 *			the IPv6 library. In order to call IPv6 library functions
	 *			defined based on this type the caller function must
	 *			be defined based on a type compatible component type.
	*/
	type component LibIpv6Node {
		port Ipv6Port ipPort;
		timer tc_ac:= PX_TAC;
		timer tc_noAc:= PX_TNOAC;
		timer tc_wait:= PX_TWAIT;
	}

	type port Ipv6Port message {
		inout

		//Imported from Rfc 2463
		DestinationUnreachable,
		PacketTooBig,
		TimeExceeded,
		ParameterProblem,
		EchoRequest,
		EchoReply,
		//Imported from Rfc 2461
		RouterAdvertisement,
		RouterSolicitation,
		NeighborSolicitation,
		NeighborAdvertisement,
		Redirect,
		//Imported from Rfc 2894
		RouterRenumbering,
		//Imported from Rfc XXXX Mipv6
		HomeAgentAddressDiscoveryRequest,
		HomeAgentAddressDiscoveryReply,
		MobilePrefixSolicitation,
		MobilePrefixAdvertisement,
		MipRouterAdvertisement,
		OtherIcmpv6Hdr,
		//hand encoded IPv6 packets
		RawIpv6Packet,
		//UDP
		UdpPacket,
		//MetaPdu
		Ipv6Packet,
		//General IPv6 packet
		GeneralIpv6,
		//EspPackets
		EspTunnelModePacket,
		EspTransportModePacket
	}

	/*
	 * @desc This meta packet type contains any Ipv6 packets.
	 *		 This type is used mainly for checksum calculation
	*/
    type union Ipv6Packet  {
		//Imported from Rfc 2463
		DestinationUnreachable 				destinationUnreachable,
		PacketTooBig						packetTooBig,
		TimeExceeded						timeExceeded,
		ParameterProblem					parameterProblem,
		EchoRequest							echoRequest,
		EchoReply							echoReply,
		//Imported from Rfc 2461
		RouterAdvertisement					routerAdvert,
		RouterSolicitation      			routerSolicitation,
		NeighborSolicitation				nbrSolicitation,
		NeighborAdvertisement				nbrAdvert,
		Redirect							redirect,
		//Imported from Rfc 2894
		RouterRenumbering					routerRenumbering,
		//Imported from Rfc XXXX Mipv6
		HomeAgentAddressDiscoveryRequest	homeAgentAddressDiscoveryRequest,
		HomeAgentAddressDiscoveryReply		homeAgentAddressDiscoveryReply,
		MobilePrefixSolicitation			mobilePrefixSolicitation,
		MobilePrefixAdvertisement			mobilePrefixAdvertisement,
		MipRouterAdvertisement				mipRouterAdvertisement,
		//Default value
		OtherIcmpv6Hdr						otherHeader,
		//Udp
		UdpPacket							udpPacket,
	  	//General IPv6 packet
	  	GeneralIpv6                         generalIpv6
	}
	with {
		encode "isPDU=LibIpv6_Interface;"
	}

	template Ipv6Packet mw_ipPkt := ? ;

	template Ipv6Packet m_ipPkt_echoRequest (in template EchoRequest p_echoRequest) := {
		echoRequest := p_echoRequest
	}

	/*
	*  @desc This type is intended to be used to send "hand encoded"
	*        IPv6 packets. It can also be used to create incorrect
	*        IPv6 messages.
    */
	type octetstring RawIpv6Packet;

} // end module LibIpv6_Interface
+380 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading