#######################################################################################
#######################################################################################
#NIDD_VER: SBTS17_1701_002_00, GSM17_1610_003_00
#GF17 MRBTS and GNBTS part
#Migration from GF17 to SBTS17
#16.12.2016/I. Harangus
# v0.1 30.12.2016 Ioan Harangus: first draft for new CUTool
# v0.2 01.03.2017 Ioan Harangus: second draft after validation with scfValidation, based on SBTSD17_NIDD_1701_005_00
# v0.3 10.04.2017 Ioan Harangus: pronto 232766: GNCELCs migration
# v0.4 22.04.2017 Ioan Harangus: pronto 232766: removal of optionals: switchoverFailTimer, switchoverStartTimer
# v0.4 27.04.2017 Ioan Harangus: pronto xxxxxx: perTrxPower * 10 ; siteName -> btsName
# v0.5 19.06.2017 Ioan Harangus: pronto 248213:  [OAM_SCT][SBTS17][RP1062] To small range for GNCEL in SBTS17 in comparison to LCELC in SBTS16
#######################################################################################

#######################################################################################
#######################################################################################
# define global constants
define "operation" "create"
define "version" "GSM17_1610_003"
define "versionMrbts" "SBTS17_1701_002"
define "adaptation" "com.nokia.srbts.gsm"
define "adaptationMrbts" "com.nokia.srbts"

#General version checking

if ( objects_count "BCF/MRBTS/BTSSCC/BTSSCG/BTSNE" ) == 0 abort_file

for_objects "BCF/MRBTS/BTSSCC/BTSSCG/BTSNE"
	begin
		if not ( get_version $current_dist_name ) == "GF17"
			abort_file
		define "bcfId" $current_BCF		
	end

define "mrbtsId" 1
for_objects "BCF/MRBTS/BTSSCC/BTSSCG/BTSNE"
    begin
        if ( param_exist $current_dist_name "installationNotes" )
            begin
                define "value" get_param $current_dist_name "installationNotes"
                define "tempValue" replace value "(\D+)" "" flags "g"
                if ( tempValue ) != "" && ( tempValue >= 0 ) && ( tempValue <= 1048575 )
                    begin
                        define "mrbtsId" tempValue
                    end
            end
    end

#create mrbtsRoot, sbtsRoot for later usage
define "mrbtsRoot" "MRBTS-" JOIN mrbtsId
define "btsccDN" "BCF-" JOIN bcfId JOIN "/MRBTS-1/BTSSCC-1"
define "btsccgDN" btsccDN JOIN "/BTSSCG-1"
define "sctpDN" btsccgDN JOIN "/SCTP-1"
define "btsneDN" btsccgDN JOIN "/BTSNE-1"

define "tnlsvcDN" mrbtsRoot JOIN "/TNLSVC-1"
define "tnlDN" tnlsvcDN JOIN "/TNL-1"
define "ipnoDn" tnlDN JOIN "/IPNO-1"
define "ipifDn1" ipnoDn JOIN "/IPIF-201"
define "ipaddressv4Dn1" ipifDn1 JOIN "/IPADDRESSV4-1"
#######################################################################################

#######################################################################################
#######################################################################################
#Add GNBTS GNBCF GNCEL  
#if ( objects_count "MRBTS" ) == 0 
define "mrbtsDn" "MRBTS-" JOIN mrbtsId
add_object mrbtsDn

define "gnbtsDN" mrbtsRoot JOIN "/GNBTS-1"
define "gnbcfDN" gnbtsDN JOIN "/GNBCF-1"

if ( objects_count "GNBTS" ) == 0 add_object mrbtsRoot JOIN "/GNBTS-1"
if ( objects_count "GNBTS/GNBCF" ) == 0 add_object mrbtsRoot JOIN "/GNBTS-1" JOIN "/GNBCF-1"

#######################################################################################
# check actual value of txPowerPooling

for_objects "BCF/MRBTS/BTSSCC/LCELC"
	begin
		if ( param_exist $current_dist_name "txPowerPooling" )
			begin
				if ( get_param $current_dist_name "txPowerPooling" ) == "Enabled"
					add_param gnbcfDN "txPowerPooling" "true"
			end
	end
	
#######################################################################################
for_objects "MRBTS"
	begin
		set_operation $current_dist_name operation
		set_version $current_dist_name versionMrbts
		set_adaptation $current_dist_name adaptationMrbts
		# siteName -> btsName 
		if ( param_exist btsneDN "siteName" ) add_param mrbtsRoot "btsName" get_param btsneDN "siteName"
		else add_param mrbtsRoot "btsName" "GHITA"
	end

for_objects "BCF/MRBTS/BTSSCC/BTSSCG/SCTP"
	begin 
	# 
		if ( param_exist $current_dist_name "maxRTO" ) add_param gnbcfDN "sctpRtoMaxOmuSig" get_param $current_dist_name "maxRTO"
		if ( param_exist $current_dist_name "minRTO" ) add_param gnbcfDN "sctpRtoMinOmuSig" get_param $current_dist_name "minRTO"
		if ( param_exist $current_dist_name "periodSACK" ) add_param gnbcfDN "sctpSackPeriodOmuSig" get_param $current_dist_name "periodSACK"
		if ( param_exist $current_dist_name "initRTO" ) add_param gnbcfDN "sctpRtoInitOmuSig" get_param $current_dist_name "initRTO"
		if ( param_exist $current_dist_name "minSctpPort" ) add_param gnbcfDN "sctpPortOmuSig" get_param $current_dist_name "minSctpPort"
		if ( param_exist $current_dist_name "maxRetransPath" ) add_param gnbcfDN "sctpMaxRetransPathOmuSig" get_param $current_dist_name "maxRetransPath"
		if ( param_exist $current_dist_name "maxRetransAssoc" ) add_param gnbcfDN "sctpMaxRetransAssocOmuSig" get_param $current_dist_name "maxRetransAssoc"
		if ( param_exist $current_dist_name "hbInterval" ) add_param gnbcfDN "sctpHbIntervalOmuSig" get_param $current_dist_name "hbInterval"
		if ( param_exist $current_dist_name "ackTimerIUA" ) add_param gnbcfDN "iuaAckTimerOmuSig" get_param $current_dist_name "ackTimerIUA"
	end

for_objects "BCF/MRBTS/BTSSCC/BTSSCG/BTSNE"
	begin
		if ( param_exist $current_dist_name "rxds" ) add_param gnbcfDN "rxds" get_param $current_dist_name "rxds"
			else add_param gnbcfDN "rxds" 1
		if ( param_exist $current_dist_name "bscId" ) add_param gnbcfDN "bscId" get_param $current_dist_name "bscId"
			else add_param gnbcfDN "bscId" 1
		if ( param_exist $current_dist_name "switchoverFailTimer" ) add_param gnbcfDN "switchoverFailTimer" get_param $current_dist_name "switchoverFailTimer"		
		if ( param_exist $current_dist_name "switchoverStartTimer" ) add_param gnbcfDN "switchoverStartTimer" get_param $current_dist_name "switchoverStartTimer"		
	end	
	
define "ethprtDN" "null"
for_objects "BCF/MRBTS/BTSSCC/BTSSCG/ETHPRT"
	begin
		define "ethprtDN" $current_dist_name
		#define "sctpMaxPayloadSize" get_param $current_dist_name "ethernetMtuSize"
		if ( param_exist $current_dist_name "ethernetMtuSize" )
			begin
				define "tempValue" get_param $current_dist_name "ethernetMtuSize"
				define "tempValue" tempValue - 32
				add_param gnbcfDN "sctpMaxPayloadSize" tempValue
			end
		
		# optional else add_param gnbcfDN "sctpMaxPayloadSize" 60
	end
	
#check if sctpMaxPayloadSize fits in range, if not change value to default
	if ( param_exist gnbcfDN "sctpMaxPayloadSize" )
		begin
			if ( get_param gnbcfDN "sctpMaxPayloadSize" ) < 200 || ( get_param gnbcfDN "sctpMaxPayloadSize" ) > 1468
				add_param gnbcfDN "sctpMaxPayloadSize" "1395"
		end
	else add_param gnbcfDN "sctpMaxPayloadSize" "1395"
	
for_objects "GNBTS/GNBCF"
	begin
        if ( param_exist $current_dist_name "udpMaxDatagramSize" )
            begin
                add_param gnbcfDN "udpMaxDatagramSize" get_param $current_dist_name "udpMaxDatagramSize"
            end

		if ( param_exist ethprtDN "ethernetMtuSize" )
			begin
				define "value" get_param ethprtDN "ethernetMtuSize"
				define "value" value - 28
				if value > 199
					begin
						if value < 1473
							begin
								add_param gnbcfDN "udpMaxDatagramSize" value
							end
					end
				
			end

        if not ( param_exist gnbcfDN "udpMaxDatagramSize" )
            begin
                add_param gnbcfDN "udpMaxDatagramSize" "1427"
            end

		if ( param_exist $current_dist_name "mPlaneDscpOmuSig" ) add_param gnbcfDN "mPlaneDscpOmuSig" get_param $current_dist_name "mPlaneDscpOmuSig"
		# optional else add_param gnbcfDN "mPlaneDscpOmuSig" 34		
		if ( param_exist btsneDN "bcfId" ) add_param gnbcfDN "bcfId" get_param btsneDN "bcfId"
		else add_param gnbcfDN "bcfId" 1
	end	
#
	
for_objects "BCF/MRBTS/BTSSCC/BTSSCG/PABTRS"
	begin
		if ( param_exist $current_dist_name "ucsSupervisionPktTimerValue" ) add_param gnbcfDN "ucsSupervisionPktTimerValue" get_param $current_dist_name "ucsSupervisionPktTimerValue"		
		if ( param_exist $current_dist_name "upsSupervisionPktTimerValue" ) add_param gnbcfDN "upsSupervisionPktTimerValue" get_param $current_dist_name "upsSupervisionPktTimerValue"					
		if ( param_exist $current_dist_name "mPlaneRemoteIpAddress" ) add_param gnbcfDN "mPlaneRemoteIpAddressOmuSig" get_param $current_dist_name "mPlaneRemoteIpAddress"
		else add_param gnbcfDN "mPlaneRemoteIpAddressOmuSig" "0.0.0.0"		
		add_param gnbcfDN "mPlaneLocalIpAddressDN" ipaddressv4Dn1
	end

for_objects "BCF/MRBTS/BTSSCC/BTSSCG/SYNC"
    begin
        del_param $current_dist_name "delayRequestMsgRate"
    end

#######################################################################################
#set version to SBTS17

define "gnbtsDn" "MRBTS-" JOIN mrbtsId JOIN "/GNBTS-1"
for_branch gnbtsDn
	begin
		set_operation $current_dist_name operation
		set_version $current_dist_name version
		set_adaptation $current_dist_name adaptation		
	end

########################################################################################
