Skip to content
LibIpv6_CommonRfcs_Functions.ttcn 7.81 KiB
Newer Older
alex's avatar
alex committed
/*
 *	@author 	STF 276
 *  @version 	$Id$
 *	@desc		This module specifies functions definitions
 *              that can be used by any RCF function.  
alex's avatar
alex committed
 *  
 */
 module LibIpv6_CommonRfcs_Functions {
alex's avatar
alex committed

	//LibCommon
peter's avatar
peter committed
	import from LibCommon_BasicTypesAndValues all;
	import from LibCommon_DataStrings all;
alex's avatar
alex committed
	import from LibCommon_VerdictControl { type FncRetCode };
	//LibIpv6
	import from LibIpv6_Interface_TypesAndValues all ;
alex's avatar
alex committed
	import from LibIpv6_ExternalFunctions all;
	import from LibIpv6_ModuleParameters all ;
	import from LibIpv6_CommonRfcs_TypesAndValues all;
	import from LibIpv6_CommonRfcs_Templates all;
seb's avatar
seb committed
	group calcPrefixFns {
		
validator's avatar
validator committed
/*		function createIpAddresses(Prefix p_prefix, Oct6to15 p_macAddr)
		runs on LibIpv6Node
		return FncRetCode {
			const UInt8 c_uniIdLen := 64;
			var Oct8 v_prefixReady := int2oct(0,8);
			var Oct8 v_interfaceIdReady := int2oct(0,8);
			var Oct3 v_leftPartMac := int2oct(0,3);
			var Oct3 v_rightPartMac := int2oct(0,3);
			var Bit24 v_leftPartBits := int2bit(0,24);
			var Bit24 v_leftPartBitMask := int2bit(131072,24);
			var Ipv6Address v_gla := int2oct(0,16);
			
			if (lengthof(p_prefix) > 8) {
				log("Error");
			}
			else {
				//Fill v_prefixReady with existing Prefix
				for (i:=0; i<lengthof(p_prefix); i:=i+1) {
					v_prefixReady[i] := p_prefix[i];
				}
				//Complete v_prefixReady with Zero Bytes
				for (i:=lengthof(p_prefix); i<8; i:=i+1) {
					v_prefixReady[i] := '00'O;
				}
			}
			//get leftPart
			for (i:=0; i<lengthof(p_macAddr)-3; i:=i+1) {
				v_leftPartMac[i] := p_macAddr[i];
			}
			//get leftPart
  			for (i:=3; i<lengthof(p_macAddr); i:=i+1) {
	  			v_rightPartMac[i-3] := p_macAddr[i];
  			}
  			//flipBit universalBit of leftPart
			v_leftPartBits :=  oct2int(v_leftPartMac);
			v_leftPartBits := v_leftPartBits xor4b v_leftPartBitMask;
			v_leftPartMac := bit2oct(v_leftPartBits);
			//build InterfaceId
			v_interfaceIdReady := v_leftPartMac & 'FFFE'O & v_rightPartMac;
			
			//MAC_MCA
			
			//GLA
			v_gla := v_prefixReady & v_interfaceIdReady;
			//LLA
			
			//SOL_NODE_MCA
		
		}
	*/	
seb's avatar
seb committed
		/*
	 * @desc 	Creates a prefix using p_address and p_prefixLength. The p_prefixLength
	 *			MSB bits remain unchanged, the others are set to zero.
	 * @param	p_address Address used for prefix creation
	 * @param	p_prefixLength Length of the prefix
	*/
	function f_createPrefix ( template Ipv6Address p_address, template UInt8 p_prefixLength )
	runs on LibIpv6Node
    return Ipv6Address {

		var Bit128 v_prefix;
		var integer v_pos;

		v_prefix := oct2bit ( valueof ( p_address ) );

		for ( v_pos := 128 - valueof ( p_prefixLength ); v_pos < 128; v_pos := v_pos + 1 ) {
			v_prefix[v_pos] := '0'B;
		}

		return bit2oct ( v_prefix );

	} // end f_createPrefix

	/*
	 * @desc 	Creates a prefix using p_address. The length of the prefix is fixed
	 *			in 64. The first 64 bits remain unchanged, the others are set to zero.
	 * @param	p_address Address used for prefix creation
	*/
	function f_createPrefix64 ( template Ipv6Address p_address )
	runs on LibIpv6Node
    return Ipv6Address {

		var Bit128 v_prefix;
		var integer v_pos;

		v_prefix := oct2bit ( valueof ( p_address ) );

		for ( v_pos := 64; v_pos < 128; v_pos := v_pos + 1 ) {
			v_prefix[v_pos] := '0'B;
		}

		return bit2oct ( v_prefix );

	} // end f_createPrefix64
		
	}//end group calcPrefixFns
validator's avatar
""  
validator committed

seb's avatar
seb committed
	
validator's avatar
""  
validator committed


	/*
	 * @desc 	This goes through the ExtensionHeaderList and
	 *			checks if a HomeAddressOption is present.
	 * @param 	p_extHdrList ExtensionHeaderList to be treated
validator's avatar
validator committed
	 * @param 	p_homeAddr Home address
	 * @return 	execution status 
	*/
	function f_isPresentHomeAddressOption(	in ExtensionHeaderList p_extHdrList,
											inout Ipv6Address p_homeAddr)
validator's avatar
validator committed

	runs on LibIpv6Node
	return FncRetCode {
		var FncRetCode v_ret := e_error;
		var UInt8 i,j;

		//select ext hdrs that need special calculation
validator's avatar
validator committed
		for (i:=0; i<sizeof(p_extHdrList) and (v_ret != e_success); i:=i+1) {
			if (ischosen(p_extHdrList[i].destinationOptionHeader)) {
validator's avatar
validator committed
				for (j:=0; j<sizeof(p_extHdrList[i].destinationOptionHeader.destOptionList);j:=j+1) {
					if (ischosen(p_extHdrList[i].destinationOptionHeader.destOptionList[j].homeAddressOption)) {
						p_homeAddr := p_extHdrList[i].destinationOptionHeader.destOptionList[j].homeAddressOption.homeAddress;
						v_ret := e_success;
					}
				}
			}
		}
		return v_ret;
	}//end function f_isPresentHomeAddressOption
validator's avatar
validator committed

	/*
	 * @desc 	This goes through the ExtensionHeaderList and
	 *			checks if a Routing Header type 2 is present.
	 * @param 	p_extHdrList ExtensionHeaderList to be treated
	 * @return 	execution status 
	*/
	function f_isPresentRoutingHeaderType2(	in ExtensionHeaderList p_extHdrList,
											inout Ipv6Address p_homeAddr)

	runs on LibIpv6Node
	return FncRetCode {
		var FncRetCode v_ret := e_error;
		var UInt8 i,j;

		//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].routingHeader) and (p_extHdrList[i].routingHeader.routingType == c_routeHdrType2)) {
				if (ischosen(p_extHdrList[i].routingHeader.routingHeaderData.rtHdrDataHomeAddress)) {
					p_homeAddr := p_extHdrList[i].routingHeader.routingHeaderData.rtHdrDataHomeAddress;
					v_ret := e_success;
				}
			}
		}
		return v_ret;
	}//end function f_isPresentRoutingHeaderType2
	 * @desc 	This goes through the ExtensionHeaderList and
	 *			checks if a Binding Authority Data option is present.
	 * @param 	p_extHdrList ExtensionHeaderList to be treated
	 * @return 	execution status 
	function f_isPresentBindingAuthorityDataOption ( in ExtensionHeaderList p_extHdrList )
	return FncRetCode {
		var FncRetCode v_ret := e_error;
		var UInt8 i,j;
		//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].mipBindingAuthorizationData ) == true ) {
							v_ret := e_success;
						}
					}
				}
			}
		if ( v_ret == e_error ) {
			log ( "**** f_isPresentBindingAuthorityDataOption: ERROR: Binding Authentication Data option is not present in Binding Ack **** " );
	}//end function f_isPresentBindingAuthorityDataOption
	 * @desc 	This goes through the ExtensionHeaderList and
	 *			checks if a Binding Refresh Advice option is present.
	 * @param 	p_extHdrList ExtensionHeaderList to be treated
	 * @return 	execution status 
	function f_isPresentBindingRefreshAdviceOption ( in ExtensionHeaderList p_extHdrList )
	return FncRetCode {
		var FncRetCode v_ret := e_error;
		var UInt8 i,j;
		//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 **** " );
		}
peter's avatar
peter committed

peter's avatar
peter committed

	}//end function f_isPresentBindingRefreshAdviceOption
peter's avatar
peter committed

} // end module LibIpv6_CommonRfcs_Functions
alex's avatar
alex committed