#######################################################################################
#######################################################################################
#NIDD_VER: WCDMA17_1610_003_00
#WNBTS: WNBTS_WCDMA17_1610_003
#Migration from SBTS16.10 to SBTS17
#14.11.2016/ v0.1 /draft for new CUTool /L.Preuss
#######################################################################################

#######################################################################################
#######################################################################################
#If SCF version == 16.10 proceed with migration, else abort this ruleset

for_objects "SBTS"
	define "sbtsRoot" $current_dist_name

if ( objects_count "SBTS" ) == 0 abort_file
	
if not ( get_version sbtsRoot ) == "SBTS16.10" 
	begin
		abort_file
	end
#######################################################################################

#######################################################################################
#######################################################################################
#If BTSSCW exists in SBTS6.10 continue 

if not ( objects_count "SBTS/BTSSCW" ) > 0
	begin
		abort_file
	end
#######################################################################################

#######################################################################################
#######################################################################################
#create mrbtsRoot, sbtsRoot for later usage

for_objects "MRBTS"
	begin
		define "mrbtsRoot" $current_dist_name
	end
	
for_objects "SBTS"
	begin
		define "sbtsRoot" $current_dist_name
	end
#######################################################################################

#######################################################################################
#######################################################################################
#copy BTSSCW to WNBTS

define "wnbtsDN" mrbtsRoot JOIN "/WNBTS-1"
copy_object sbtsRoot JOIN "/BTSSCW-1" wnbtsDN
#######################################################################################

#######################################################################################
#######################################################################################
#delete WNBTS removed params

if ( param_exist wnbtsDN "numberOfHSDPASet1" ) del_param wnbtsDN "numberOfHSDPASet1"
if ( param_exist wnbtsDN "numberOfHSDPASet2" ) del_param wnbtsDN "numberOfHSDPASet2"
if ( param_exist wnbtsDN "numberOfHSDPASet3" ) del_param wnbtsDN "numberOfHSDPASet3"
if ( param_exist wnbtsDN "numberOfHSUPASet1" ) del_param wnbtsDN "numberOfHSUPASet1"

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

#######################################################################################
#######################################################################################
#copy LCELGW to WNCELG and fix params

for_objects "SBTS/BTSSCW/LCELGW"
	begin
		define "wncelgDn" mrbtsRoot JOIN "/WNBTS-1/WNCELG-" JOIN $current_LCELGW
		copy_object $current_dist_name wncelgDn
		
		if ( param_exist wncelgDn "lCelwIdList" )
			begin
				add_list wncelgDn "wncelIdList"
				for_list $current_dist_name "lCelwIdList"
					begin
						add_param wncelgDn "wncelIdList" JOIN "." JOIN $current_index $current_value  
					end
				del_param wncelgDn "lCelwIdList"
			end
	end
#######################################################################################

#######################################################################################
#######################################################################################
#copy LCELW to WNCEL
#
#for_objects "SBTS/BTSSCW/LCELW"#
#	begin
#		define "wncelDn" mrbtsRoot JOIN "/WNBTS-1/WNCEL-" JOIN $current_LCELW
#		copy_object $current_dist_name wncelDn
#	end
#######################################################################################

#######################################################################################
#######################################################################################
#Fix params in WNBTS

for_objects "MRBTS/WNBTS"
	begin
		define "wnbtsDN" $current_dist_name
		if ( param_exist wnbtsDN "uPlaneList.0.ipV4Address" ) define "uplaneIP" get_param $current_dist_name "uPlaneList.0.ipV4Address" else define "uplaneIP" "0"
		if ( param_exist wnbtsDN "cPlaneList.0.ipV4Address" ) define "cplaneIP" get_param $current_dist_name "cPlaneList.0.ipV4Address" else define "cplaneIP" "0"

		for_objects "MRBTS/TNLSVC/TNL/IPNO/IPIF/IPADDRESSV4"
			begin
				define "tnlIP" get_param $current_dist_name "localIpAddr"
				if tnlIP == uplaneIP
					begin
						add_param wnbtsDN "uPlaneList.0.ipV4AddressDN" $current_dist_name
						del_param wnbtsDN "uPlaneList.0.ipV4Address"
					end
				
				if tnlIP == cplaneIP
					begin
						add_param wnbtsDN "cPlaneList.0.ipV4AddressDN" $current_dist_name
						del_param wnbtsDN "cPlaneList.0.ipV4Address" 
					end
			end
	end	
#######################################################################################

#######################################################################################
#######################################################################################
#Fix params in WNBTS/WNCEL

for_objects "SBTS/BTSSCW/LCELW"
	begin
		define "wncelDn" mrbtsRoot JOIN "/WNBTS-1/WNCEL-" JOIN $current_LCELW
		copy_object $current_dist_name wncelDn
		define "olcelwCount" objects_count "SBTS/BTSSCW/LCELW" 
		define "nlcelwCount" objects_count "MRBTS/WNBTS/WNCEL" 
		define "lcelwId" olcelwCount - nlcelwCount + 1
		define "lcelwDn" mrbtsRoot JOIN "/MNL-1/MNLENT-1/CELLMAPPING-1/LCELW-" JOIN lcelwId
		add_param wncelDn "lCelwDN" lcelwDn
		del_param wncelDn "usageState"
	end

#######################################################################################
#######################################################################################
#crerate WNPMRNL and populate with parameters

define "wnpmrnlDn" wnbtsDN JOIN "/WNPMRNL-1"
add_object wnpmrnlDn
set_operation wnpmrnlDn "create"

for_objects "SBTS/MGMNT/PM"
	begin
		if ( param_exist $current_dist_name "mtCellThrWBTS" ) add_param wnpmrnlDn "mtCellThrWBTS" get_param $current_dist_name "mtCellThrWBTS"
		if ( param_exist $current_dist_name "mtFrameProtWBTS" ) add_param wnpmrnlDn "mtFrameProtWBTS" get_param $current_dist_name "mtFrameProtWBTS"
		if ( param_exist $current_dist_name "mtFSMLevelMon" ) add_param wnpmrnlDn "mtFSMLevelMon" get_param $current_dist_name "mtFSMLevelMon"
		if ( param_exist $current_dist_name "mtHSPASchedMon" ) add_param wnpmrnlDn "mtHSPASchedMon" get_param $current_dist_name "mtHSPASchedMon"
		if ( param_exist $current_dist_name "mtFSMLevelMon" ) add_param wnpmrnlDn "mtFSMLevelMon" get_param $current_dist_name "mtFSMLevelMon"
		if ( param_exist $current_dist_name "mtHSPAWBTS" ) add_param wnpmrnlDn "mtHSPAWBTS" get_param $current_dist_name "mtHSPAWBTS"
		if ( param_exist $current_dist_name "mtHSPAWBTSExt" ) add_param wnpmrnlDn "mtHSPAWBTSExt" get_param $current_dist_name "mtHSPAWBTSExt"
		if ( param_exist $current_dist_name "mtOperSpecStat" ) add_param wnpmrnlDn "mtOperSpecStat" get_param $current_dist_name "mtOperSpecStat"
		if ( param_exist $current_dist_name "mtPICPoolWBTS" ) add_param wnpmrnlDn "mtPICPoolWBTS" get_param $current_dist_name "mtPICPoolWBTS"
		if ( param_exist $current_dist_name "mtSignLoadWBTS" ) add_param wnpmrnlDn "mtSignLoadWBTS" get_param $current_dist_name "mtSignLoadWBTS"
		if ( param_exist $current_dist_name "mtWBTSLevelMon" ) add_param wnpmrnlDn "mtWBTSLevelMon" get_param $current_dist_name "mtWBTSLevelMon"
		if ( param_exist $current_dist_name "mtWBTSR99Res" ) add_param wnpmrnlDn "mtWBTSR99Res" get_param $current_dist_name "mtWBTSR99Res"
	end
#######################################################################################

#######################################################################################
#######################################################################################
#Set proper version and adaptations for WNBTS subtree

for_objects "MRBTS/WNBTS"
	begin
		set_version $current_dist_name "WCDMA17_1610_003"
		set_adaptation $current_dist_name "com.nokia.srbts.wcdma"
	end
	
for_objects "MRBTS/WNBTS/WNCEL"
	begin
		set_version $current_dist_name "WCDMA17_1610_003"
		set_adaptation $current_dist_name "com.nokia.srbts.wcdma"
	end

for_objects "MRBTS/WNBTS/WNCELG"
	begin
		set_version $current_dist_name "WCDMA17_1610_003"
		set_adaptation $current_dist_name "com.nokia.srbts.wcdma"
	end
	
for_objects "MRBTS/WNBTS/WNPMRNL"
	begin
		set_version $current_dist_name "WCDMA17_1610_003"
		set_adaptation $current_dist_name "com.nokia.srbts.wcdma"
	end

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