#!/usr/lib/perl

my $local_debug = 0;

if ( $local_debug == 1 ) {
    $newdb2 = "newdb2";
    $newdb5 = "newdb5";
    $newdb10 = "newdb10";
    $cli2xmldb1 = "cli2xmldb1";
    $strmap = "strmap";
    $strvalmap = "strvalmap";
    $fldarraydbase = "fldarraydbase";
    $fldfrmtdbase = "fldfrmtdbase";
    $clifile = "clifile";
    $clifile_no_rogue = "clifile_no_rogue";
    $clifile_rogue_add = "clifile_rogue_add";
    $clifile_no_country = "clifile_no_country";
    $clifile_country_add = "clifile_country_add";
    $clifile_no_interface = "clifile_no_interface";
    $clifile_interface_add = "clifile_interface_add";
    $clifile_policy_add = "clifile_policy_add";
    $clifile_no_policy = "clifile_no_policy";
    $clixmlConfigfile = "commands1";
    $resultfile = "resultfile";
    $xmldir = "";
    $invalid_config_tags_file = "invalid_db";
    $commonCountryInfo = "commonCountryInfo";
    $APMgrInfo = "StaticAPMgr";
    $mobilityFlag = "mobilityFlag";
} else {
    $newdb2 = "/bsn/newdb2";
    $newdb5 = "/bsn/newdb5";
    $newdb10 = "/bsn/newdb10";
    $cli2xmldb1 = "/bsn/cli2xmldb1";
    $strmap = "/bsn/strmap";
    $strvalmap = "/bsn/strvalmap";
    $fldarraydbase = "/bsn/fldarraydbase";
    $fldfrmtdbase = "/bsn/fldfrmtdbase";
    $clifile = "/mnt/application/xml/clis/clifile";
    $clifile_no_rogue = "/mnt/application/xml/clis/clifile_no_rogue";
    $clifile_rogue_add = "/mnt/application/xml/clis/clifile_rogue_add";
    $clifile_no_country = "/mnt/application/xml/clis/clifile_no_country";
    $clifile_country_add = "/mnt/application/xml/clis/clifile_country_add";
    $clifile_no_interface = "/mnt/application/xml/clis/clifile_no_interface";
    $clifile_interface_add = "/mnt/application/xml/clis/clifile_interface_add";
    $clifile_policy_add = "/mnt/application/xml/clis/clifile_policy_add";
    $clifile_no_policy = "/mnt/application/xml/clis/clifile_no_policy";
    $clixmlConfigfile = "/mnt/application/xml/clixmlConfigfile";
    $resultfile = "/mnt/application/xml/clis/resultfile";
    $xmldir = $ARGV[0];
    $invalid_config_tags_file = "/mnt/application/xml/clis/XMLInvalidTagConfig.txt";
    $commonCountryInfo = "/mnt/application/xml/commonCountryInfo";
    $APMgrInfo = "/mnt/application/xml/StaticAPMgr";
    $mobilityFlag = "/mnt/application/xml/mobilityFlag";
}

my %vlan_port_map;
my %rogue_rule_ssid_flag;
my %rogue_rule_wssid_flag;
my @glb_array_fld_values;
my %mobility_group_mcast_address;
my $glb_flag_mac_add = 0;
my %dbase;
my %xml_dbase_filename;
my %local_fld_dbase;
my %policy_name_id_mapping;
my %digit_to_tag;
my %digit_to_tag_actual;
my %tag_to_digit;
my %global_dummy_instance_hash;
my $glb_sigId_index = 0;
my %sigIdMap;
my %global_bytearray_index_start;
my $global_bytearray_index = 0;
my $gbl_offset = 33;
my $flag_for_byte_offset = 0;
my $mgmt_ip_addr = 0;
my $ipv6_mgmt_address = 0;
my $ipv6_prefixlen = 0;
my $anch_ip_addr_fld = 0;
my $mwar_count_fld = 0;
my $new_mobility_enabled = 2; # 1-yes, 0-NO, 2-not updated from Flash
my $mobility_success_case = 0;
my $make_next_node_mandatory = 0;
my $keyword_map_for_new_mobility = 0;
my $current_keyword_for_new_mobility = 0;
#START MAX FLEX-ACL supported .these values are for non-ME controller for ME please update the value in initialize_ME_platform 
my $maxhreapacl=512; #HREAP_ACL_IPV4_MAX  
my $maxhreapipv6acl=512;#HREAP_ACL_IPV6_MAX 
#END MAX FLEX-ACL supported .these values are for non-ME controller for ME please  update the value in initialize_ME_platform 
my $hreapacl=0;
my $hreapipv6acl=0;
my @hreapAclName;
my $xferSchedPolicy=0;
my @xferSchedPolicyName;
my @maxXferSchedPolicy = 0;
my @stack_digit;
my @stack_digit_actual;
my $stack_digit_level = 1;;
my @stack_tag;
my $stack_tag_level = 1;
my $line;
my @string_value_map;
my @value_string_map;
my @string_map;
my %array_index;
my $mapped_input_index = 0;
my $created_input_index = 1;
my $useasis_input_index = 2;
my $created_useasis_input_index = 3;
my $created_input_index_with_offset = 4;
my $last_array_flag = 0;
my $last_string_byte_array_flag = 0;
my $input_index_type;
my %fldarraydbase_hash;
my %fldfrmtdbase_hash;
my %current_instance_indices;
my %clitoxmldb1_instances;
my %clitoxmldb1;
my $input_cli;
my @clitoxmldb1_ptr;
my $clitoxmldb1_index = 0;
my $clitoxmldb1_ptr_level = 0;
my $current_instance_indices_level = 0;
my @retcheck;

my $xmldbase_index_not_updated = 0;
my $xmldbase_index_updated = 1;
my $CLI_INPUT_OPTIONAL = 0;
my $ADVANCE_TO_NEXT_DEPTH = 1;
my $END_OF_CLI_TREE = 2;
my $INPUT_NOT_MATCHED = 3;
my $INVALID_CLI_OPTION = 4;
my $CLI_JUMP_OPTION = 5;
my $INSUFFICIENT_CLI_OPTIONS = 6;
my $NOOP_CLI_RETURN_OPTION = 7;

my $UPDATE_CLI_NODE = 8;
my $NO_INSTANCE_FOUND = 9;
my $BACKTRACK_TO_PREVIOUS_LEVEL = 10;
my $DELETE_CURRENT_AND_BACKTRACK_TO_PREVIOUS_LEVEL = 11;
my $DONOT_UPDATE_CLI_NODE_AND_STOP = 12;
my $MORE_INSTANCES_PRESENT = 13;
my $NO_MORE_INSTANCES = 14;
my $CLI_PRINTED = 15;
my $PARAM_UPDATE_SUCCESS = 16;
my $STRVALMAP_NO_VALUE_FOUND = 17;
my $STRVALMAP_NO_STRING_FOUND = 18;
my $GET_NEXT_INDEX_FOR_SET_LEVEL = 19;
my $TAG_FORMAT_NOT_MATCHED = 20;
my $TAG_FORMAT_MATCHED = 21;
my $GET_NEXT_INDEX_FOR_SET_LEVEL_INITIAL = 22;
my $MORE_THAN_REQD_CLI_OPTIONS = 23;
my $VALUE_HAS_NON_DIGIT_CHARS = 24;
my $ILLEGAL_CONVERSION_OPTION = 25;
my $VALUE_NOT_FOUND_IN_LOCALDBASE = 26;
my $INVALID_IP_ADRESS = 27;
my $DEFAULT_TAG_UPDATED_ALREADY = 28;
my $INVALID_MAC_ADRESS = 29;
my $USERDB_SIZE_OUT_OF_RANGE = 30;

my $local_node = 0;
my $pre_action = 1;
my $post_action = 2;
my $cli_map = 3;
my $keyword_string = 4;
my $value_field = 5;
my $action_value = 6;
my $action_string_value = 7;
my $action_local_node = 8;
my $action_node = 9;
my $reverse_action = 10;
my $action_map = 11;
my $keyword_string_map = 12;
my $action_node_arraybase = 13;
my $keyword_string_with_local = 14;
my $keyword_string_special = 15;
my $keyword_string_special_with_local = 16;

my $nodeconnector = "\.";
my $nodekewordvalend = "\%";
my $nodeparamconnector = "\,";

my $show_all_clis = 0;
my $show_invalid_config = 1;
my $output_cli_type = $show_all_clis;
my %invalid_config_tag_hash;
my $invalid_cli_found = 0;
my $PS_NULL = "PS_NULL_NULL_NULL";
my $foxhound_intf_complete = 0;
my $upd_foxhound_intf = 0;
my $is_szabla = 0;
my $is_kukri = 0;
my $is_ambassador = 0;
my $is_saber = 0;
my $is_pata = 0;
my $is_khanda = 0;
my $is_vm = 0;
my $service_port_err_flag = 0;

my $add_op = 1;
my $sub_op = 2;
my $mul_op = 3;
my $div_op = 4;

my $XML_config_variables = "XML_config_variables";
my $xml_value_entered = 0;
my $start_tag_entered = 0;

my $xml_format ="xml_formats";
my $qvlan_name = ".sys.quarantine-0/";

my $cli_format ="cli_formats";
my $max_formats = "MAX_TYPE_OF_VAR";
my $prefix_rogue_rule_cli = "config rogue rule add";
my $prefix_config_country_cli = "config country";
my $prefix_config_interface_cli = "config interface";
my $prefix_config_policy_cli = "config policy";
my @format_conv_arr;
my @global_byte_arr;
my $flag_index_set_diff = 0;
my $flag_set_supplied_index = 0;
my $servintf = "service-port";
my $servicePortSupp = "1";
my $szabla_max_wlan = 16;

initialize_cli2xml_maps();
generate_digit_to_tag_viceversa();
move_rogue_rule_add_up();

if ( $local_debug == 1) {
    open(CLI,"commands1") or die "Can't open input CLI File:$!";
    open(IGNORED,"+>ignored_clis") or die "Can't create ignored CLIs File:$!";
    open(RESULTFILE,"+>resultfile") or die "Can't create Result Code File:$!";
    open(DB1,"newdb1") or die "Can't open main database File:$!";
    open(DB2,"newdb2") or die "Can't open supporting database File:$!";
    open(DB3,"newdb3") or die "Can't open value to string database File:$!";
    open(DB5,"newdb5") or die "Can't open xml filenames database File:$!";
    open(DB6,"newdb6") or die "Can't open format specifier database File:$!";
    open(DB7,"newdb7") or die "Can't open format specifier database File:$!";
    open(DB10,"newdb10") or die "Can't open format specifier database File:$!";
    open(DB11,"newdb11") or die "Can't open format specifier database File:$!";
    open(DB113,"platformInfo.txt") or die "Can't open format specifier database File:$!";
} else {
    open(CLI,"/mnt/application/xml/clixmlConfigfile") or die "Can't open input CLI File:$!";
    open(IGNORED,"+>/mnt/application/xml/clis/XMLIgnoredCLIConfig.txt") or die "Can't create ignored CLIs File:$!";
    open(RESULTFILE,"+>/mnt/application/xml/clis/resultfile") or die "Can't create Result Code File:$!";
    open(DB1,"/bsn/newdb1") or die "Can't open main database File:$!";
    open(DB2,"/bsn/newdb2") or die "Can't open supporting database File:$!";
    open(DB3,"/bsn/newdb3") or die "Can't open value to string database File:$!";
    open(DB5,"/bsn/newdb5") or die "Can't open xml file names database:$!";
    open(DB6,"/bsn/newdb6") or die "Can't open format specifier database File:$!";
    open(DB7,"/bsn/newdb7") or die "Can't open format specifier database File:$!";
    open(DB10,"/bsn/newdb10") or die "Can't open action names database File:$!";
    open(DB11,"/bsn/newdb11") or die "Can't open default tag database File:$!";
    open(DB113,"/mnt/application/xml/platformInfo.txt") or die "Can't open format specifier database File:$!";
    if (!( -e "/bsn/newdb1" && "/bsn/newdb2" && "/bsn/newdb3" && "/mnt/application/xml/clixmlConfigfile")){
        exit;
    }
}

#TODO: check for optional /mandatory put check at TOP.
my @decimal_to_hex_string_array = ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f");
my @format_specifier;
my $First_file=1;
my ($FD);#All Global variables
my (%hash1,%hash2,%hash3,%hash7,%dbase,@stack,@dummy,%hash_xml,%local_dbase, %hash6);
my $k=0;
my $input_command;
my $spl_char_hash="#";
my $spl_char_hash1="!";
my $last_updated_input_command = "";
my %hash_action_names;
my %hash_format_names;
my @action_array;
my @clitree_action_array;
my @format_array;
my %hash_interface;
my $base_cli;
my %global_index_hash;
my $value_check = "FFFFFFFFFFFFFFFFFFFFFFFF";
my @format_detail;
my $dynamicAPMgr = "0";
########################Platform Related Info#########################
my $platform_type;
my @platform_database;
my $max_platforms_supported = 9;
my $platform_2106 = "AIR-WLC2106-K9";
my $platform_4402_25 = "AIR-WLC4402-25-K9";
my $platform_4402_50 = "AIR-WLC4402-50-K9";
my $platform_4404_100 = "AIR-WLC4404-100-K9";
my $platform_WiSM_1 = "WS-SVC-WISM-1-K9";
my $platform_C3750G_24WS_25 = "WS-C3750G-24WS-S25"; #Foxhound
my $platform_C3750G_24WS_50 = "WS-C3750G-24WS-S50"; #Foxhound
my $platform_NME_8 = "NME-AIR-WLC8-K9";  #Rocky
my $platform_NME_12 = "NME-AIR-WLC12-K9"; #Rocky
my $platform_Talwar = "AIR-WLCNG-TBD-K9"; #TALWAR
my $platform_Szabla = "AIR-CT2504-K9";
my $platform_Kukri = "AIR-CT3504-K9";
my $platform_ambassador = "AIR-CT7510-K9"; #7500
my $platform_pata = "AIR-CT5520";
my $platform_khanda = "AIR-CT8540";
my $platform_saber1 = "AIR-CT8510"; #8500 can have two PIDs CT8510 and CT85DC
my $platform_saber2 = "AIR-CT85DC"; #8500 can have two PIDs CT8510 and CT85DC
my $platform_vm = "AIR-CTVM-K9";
#Add a new ME platform here
my @me_platform = ("AIR-AP1852","AIR-AP3802","AIR-AP1832", "AIR-AP1810", "AIR-AP2802", "AIR-AP1562","AIR-AP4800",
                    "AIR-AP1815","AIR-AP1542","AIR-AP1815M","ISR-AP1100AC","ISR-AP1101AC","ISR-AP900AC","AIR-AP1840");
my $max_port_number;
####################################################################
  print RESULTFILE "1";
initialise_action_names();
initialise_format_names();
#creating hash for database and storing base clis in a dummy array.
for $line(<DB1>){
#This database contains base cli to tag hierarchy mapping.
	chomp $line;
	@line=split('\t',$line,2);  
	$hash1{$line[0]}=$line[1];
	$dummy[$k++]=$line[0];
}
if(! close(DB1))
{
    remove_xml_files();
    die "Error: File System is out of Disk Space.:$!";
}
for $line(<DB2>){
#This database contains tag hierarchy in digit dot to tag name mapping.
        chomp $line;
        @line=split('\t',$line,2);
        $hash2{$line[0]}=$line[1];
}
if(! close(DB2))
{
    remove_xml_files();
    die "Error: File System is out of Disk Space.:$!";
}

for $line(<DB3>){
#This database contains tag hierarchy in digit dot to string to value mapping.
        chomp $line;
        @line=split('\t',$line,2);
        $hash3{$line[0]}=$line[1];
}
if(! close(DB3))
{
    remove_xml_files();
    die "Error: File System is out of Disk Space.:$!";
}
for $line(<DB7>){
#This database contains tag hierarchy in digit dot to string to value mapping.
        chomp $line;
        @line=split('\t',$line,2);
        $hash7{$line[1]}=$line[0];
}
for $line(<DB7>){
#This database contains number to format name mapping.
        chomp $line;
        @line=split('\t',$line,2);
        $format_array[$line[0]] = $hash_format_names{$line[1]};
}
if(! close(DB7))
{
    remove_xml_files();
    die "Error: File System is out of Disk Space.:$!";
}

for $line(<DB10>){
#This database contains number to action name mapping.
        chomp $line;
        @line=split('\t',$line,2);
        $action_array[$line[0]] = $hash_action_names{$line[1]};
}
if(! close(DB10))
{
    remove_xml_files();
    die "Error: File System is out of Disk Space.:$!";
}
generate_platform_info_database();
populate_array();
generate_xml_filename_dbase();
intialise_interface_clis();
read_default_tag();
for $line_new(<DB113>) {
    chomp $line_new;
    $platform_type = $line_new;
    initialize_foxhound_platform();
    initialize_szabla_platform();
    initialize_kukri_platform();
    initialize_ambassador_platform();
    initialize_saber_platform();
    initialize_pata_platform();
    initialize_khanda_platform();
    initialize_vm_platform();
    initialize_ME_platform();
}

if ( $platform_type !~ m/^(AIR-WLC21|AIR-WLC440|WS-SVC-WISM|WS-C3750G|NME-AIR-WL)/ ) {	
	$dynamicAPMgr = "1";
}

if (($platform_type =~ m/^(AIR-WLC21)/) | ($platform_type =~ m/^(AIR-CT25)/)) {
#print "platform_type:2 $platform_type\n";
    $servicePortSupp = "0";
}

if(! close(DB113))
{
    remove_xml_files();
    die "Error: File System is out of Disk Space.:$!";
}


for $line(<CLI>) {
	chomp $line;
	$base_cli="FALSE";
	my ($tag_hierarchy,@multiple_tag_string,@tags_with_default_tag,@multi_tag_value);
#	$line =~ tr/[A-Z]/[a-z]/;
#   $line =~ s/[\']+/\"/g;
	$line =~ s/^[ |\t]+//g;
	$line =~ s/[ |\t]+$//g;
	$line =~ s/[ |\t]+/ /g;
	$line =~ s/[\r]+//g;
        $input_command = $line;
#print "all commands $line\n";
        if (check_for_clitree_database($line)) {
#print "$line\n";
            next;
        } else {
           #Ignore # or ! in the config file 
	   if( ($spl_char_hash ne substr($input_command, 0, 1)) && ($spl_char_hash1 ne substr($input_command, 0, 1)))
	   {
               print IGNORED "$input_command\n";
               if($platform_type eq $platform_2106) {
                   my @temp=split(/ /,$input_command);      
                   if(($temp[0] eq "config") && ($temp[1] eq "interface") && ($temp[2] eq "port")) {
                       if($temp[3] eq "management" || $temp[3] eq "ap-manager") {
                           print_to_console("Error: Mandatory CLI is invalid for $platform_type platform:$input_command\nConfig CLI:$input_command\n");
                           seek(RESULTFILE,0,0);
                           print RESULTFILE "Error: Mandatory CLI is invalid for $platform_type platform:$input_command\r\nConfig CLI:$input_command\r\n";
                           exit;
                       }
                   } 
               }
           }
#print "rejected $ignored_cli{reason} $line\n";
           next;
        }
#print "old $line\n";
        
	@line=split(/ /,$line);
	$base_cli=&search($line);
	print IGNORED "$input_command\n"if ($base_cli eq "FALSE");
        next if ($base_cli eq "FALSE");

	$tag_hierarchy=$hash1{$base_cli} if defined $hash1{$base_cli}; #getting tag hierarchy
	@cli_with_value=split($base_cli,$line,2);
	$cli_with_value[1]=~ s/^ //;
	if($tag_hierarchy =~ /(\d)a\t/ || $tag_hierarchy =~ /(\d)a#/){
		index_create_structure_field_create($tag_hierarchy,$cli_with_value[1]);
	} elsif ($tag_hierarchy=~ /(\d)b\t/ || $tag_hierarchy =~ /(\d)b#/) {
		check_create_direct_autodirect_index($tag_hierarchy,$cli_with_value[1],b);

	} elsif($tag_hierarchy=~ /(\d)c\t/ || $tag_hierarchy =~ /(\d)c#/) {
		index_direct_structure_field_create($tag_hierarchy,$cli_with_value[1]);
	} elsif($tag_hierarchy=~ /(\d)d\t/ || $tag_hierarchy=~ /(\d)d#/) {
#print " d test $1\n";
		check_create_direct_autodirect_index($tag_hierarchy,$cli_with_value[1], d);

	} elsif($tag_hierarchy=~ /(\d)e\t/ || $tag_hierarchy =~ /(\d)e#/) {
		index_autodirect_structure_field_create($tag_hierarchy,$cli_with_value[1]);
	} elsif($tag_hierarchy=~ /(\d)f\t/ || $tag_hierarchy =~ /(\d)f#/) {
             	check_create_direct_autodirect_index($tag_hierarchy,$cli_with_value[1], f);

	} elsif($tag_hierarchy=~ /(\d)g\t/ || $tag_hierarchy =~ /(\d)g#/) {
		index_mapped_structure_field_create($tag_hierarchy,$cli_with_value[1]);
	} elsif($tag_hierarchy=~ /(\d)h\t/ || $tag_hierarchy =~ /(\d)h#/) {
		check_mapped_structure_field_index($tag_hierarchy,$cli_with_value[1], h);

	} elsif($tag_hierarchy=~ /(\d)i/ ) {
#put a additional check for tagi3
		index_automapped_structure_field_create($tag_hierarchy,$cli_with_value[1]);
	} elsif($tag_hierarchy=~ /j\t/ || $tag_hierarchy =~ /j#/) {
		check_automapped_structure_field_index($tag_hierarchy,$cli_with_value[1], j);

	} else {
		@multiple_tag_string=split('\t',$tag_hierarchy);#for multiple keywords
		if ($multiple_tag_string[1]=~/[a-z]/i) {#for strings in cli.
			@rem_cli=split($line[$i],$line,2);
			&string_in_cli($base_cli,$multiple_tag_string[1],$rem_cli[1]);
		}
		@split_cli_values=split(/ /,$cli_with_value[1] );
		if ($#split_cli_values == -1) {
			my @action_format_array = split('#', $tag_hierarchy);
                        for (my $i=1; $i <=$#action_format_array; $i++) {
                            my ($action_num, $dest_field, $input_param) = split('\-', $action_format_array[$i], 3);
                            $action_array[$action_num]($dest_field, $input_param);
                        }
		}
		my ($t1, $t2, $base_str);
		for(my $j = 0; $j<=$#split_cli_values; $j++) {
		        my ($new_tag_arr, $action_format) = split('#', $multiple_tag_string[$j], 2);
#added temporarily for interface
			if (defined ($hash_interface{$base_cli})) {
				$base_str = $hash_interface{$base_cli};
				($t1, $t2) = split ('#', $base_str); 
			}
			$new_tag_arr =~ s/$t1/$base_str/;
            		if (defined ($action_format)) {
                		tree_create($new_tag_arr, $split_cli_values[$j], 0);
				@action_format_array = split('#', $action_format);
			        for (my $i=0; $i <=$#action_format_array; $i++) {
			            my ($action_num, $dest_field, $input_param) = split('\-', $action_format_array[$i], 3);
			  	    $dest_field =~ s/$t1/$base_str/;
				    $input_param =~ s/$t1/$base_str/;
			            $action_array[$action_num]($dest_field, $input_param);
            			}
		        } else {
                		tree_create($new_tag_arr, $split_cli_values[$j], 0);
			}
		}
	}
}
if(! close(CLI))
{
    remove_xml_files();
    die "Error: File System is out of Disk Space. Config is too big to save on the disk space:$!";
}

my $ref=\%dbase;
#print Dumper \%dbase;
#&parse($ref,0,'');
 add_mobilitygroup_mcastaddress();
 check_anchor_ip_with_mgmt_ip();
 print_xml_dbase();

sub add_mobilitygroup_mcastaddress
{
    my $mobilitygroup = \$mobility_group_mcast_address{group};
    my $tempCnt;
    my $xmlref = \%digit_to_tag_actual;
    my $result = $NOOP_CLI_RETURN_OPTION;
    my $hex_val;
    my @temp = split(/\./, $mobility_group_mcast_address{group_field});
    for (my $i = 0; $i <= $#temp; $i++) {
        if (defined($$xmlref{nxt}{$temp[$i]})) {
            $xmlref = \%{$$xmlref{nxt}{$temp[$i]}};
            $tempCnt = $i;
        }
    }
    if (defined($$xmlref{instance})) {
        foreach my $key1 (keys %{$$xmlref{instance}}) {
            my $pxmlref = \%{$$xmlref{instance}{$key1}};
            for (my $i = $tempCnt+1; $i <= $#temp; $i++) {
                if (defined($$pxmlref{nxt}{$temp[$i]})) {
                    $pxmlref = \%{$$pxmlref{nxt}{$temp[$i]}};
                }
            }
            foreach my $key2 (keys %$$mobilitygroup) {
                my $hex_val;
                foreach my $c (split(//,$key2)) {
                    $hex_val .= sprintf "%x", ord($c);
                }
#print "Mobility Group:$key2, Mcastaddress: $mobility_group_mcast_address{group}{$key2}, $$pxmlref{val}, $hex_val\n";
                if($hex_val eq $$pxmlref{val}) {
                    update_local_dbase($mobility_group_mcast_address{mcast_field}, $mobility_group_mcast_address{group}{$key2});
                    $array_index{index}[0] = $key1;
                    $array_index{flag}[0] = $xml_dbase_index_update_reqd;
                    $result = update_xml_dbase_with_localdb(0);
                    delete_local_dbase();
                    if ($result != $NOOP_CLI_RETURN_OPTION) {
                        return $result;
                    }
                }
            }
        }
    }

#print "group_field: $mobility_group_mcast_address{group_field}, mcastflield: $mobility_group_mcast_address{mcast_field}\n";
}

sub check_anchor_ip_with_mgmt_ip
{
    my $tempCnt;
    my $xmlref = \%digit_to_tag_actual;
    my $result = $NOOP_CLI_RETURN_OPTION;
    my $hex_val;
    my $val1;
    my $update_anch_ip = "0.0.0.0";
    my @temp = split(/\./, $anch_ip_addr_fld);
#print "add_anchor_group1: temp: @temp\n";
    for (my $i = 0; $i <= $#temp; $i++) {
        if (defined($$xmlref{nxt}{$temp[$i]})) {
#print "add_anchor_group2: i: $i, next defined: $$xmlref{nxt}{$temp[$i]}\n";
            $xmlref = \%{$$xmlref{nxt}{$temp[$i]}};
            $tempCnt = $i;
        }
    }
    if (defined($$xmlref{instance})) {
        foreach my $key1 (keys %{$$xmlref{instance}}) {
#print "add_anchor_group3: key1: $key1\n";
            my $pxmlref = \%{$$xmlref{instance}{$key1}};
            for (my $i = $tempCnt+1; $i <= $#temp; $i++) {
                if (defined($$pxmlref{nxt}{$temp[$i]})) {
                    $pxmlref = \%{$$pxmlref{nxt}{$temp[$i]}};
                }
            }
#print "add_anchor_group4: pxmlref{val}: $$pxmlref{val}\n";
            if($mgmt_ip_addr eq $$pxmlref{val}) {
#print "add_anchor_group5: EQUAL\n";

                if (get_value_from_xml_dbase($mwar_count_fld, \$val1)) {
                    $val1++;
                }
                else {
                   $val1 = 1;
                }
                update_local_dbase($mwar_count_fld, $val1);
#print "mwar_count_fld: $mwar_count_fld, val1: $val1\n";

                update_local_dbase($anch_ip_addr_fld, $update_anch_ip);
                $array_index{index}[0] = $key1;
                $array_index{flag}[0] = $xml_dbase_index_update_reqd;
                $result = update_xml_dbase_with_localdb(0);
                delete_local_dbase();
                if ($result != $NOOP_CLI_RETURN_OPTION) {
                    return $result;
                }
            }
        }
    }
}

sub set_mgmt_ip_global
{
    my $input = $_[0];
    my $result = $NOOP_CLI_RETURN_OPTION;
    my $actgroup;
    my $actfld;
    my $fld;
    my $groupfld;
    my $group;
    my $actfld2;
    my $fld2;
    ($actgroup, $actfld, $actfld2) = split(/$nodeparamconnector/, $input, 3);

    $result = param_value_return($actgroup, \$mgmtip);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actfld2, \$fld2);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $mgmt_ip_addr = $mgmtip;
    $anch_ip_addr_fld = $fld;
    $mwar_count_fld = $fld2;

#print "set_mgmt_ip_global:\n\tglobal mgmt_ip_addr: $mgmt_ip_addr\n\tglobal anch_ip_addr_fld: $anch_ip_addr_fld\n\tmwar_count_fld: $mwar_count_fld\n\tinput mgmt IP: $mgmtip\n\tinput fld: $fld\n\tinput count:$fld2\n";

    return $PARAM_UPDATE_SUCCESS;
}

sub set_mgmt_ipV6_param_global
{
    my $input = $_[0];
    my $result = $NOOP_CLI_RETURN_OPTION;
    my $actgroup;
    my $actfld;
    my $fld;
    my $groupfld;
    my $group;
    my $actfld2;
    my $fld2;
    ($actgroup, $actfld) = split(/$nodeparamconnector/, $input, 2);

    $result = param_value_return($actgroup, \$mgmtip);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $ipv6_mgmt_address = $mgmtip;
    $ipv6_prefixlen = $fld;
#print "set_mgmt_ip_global:\n\tglobal mgmt_ip_addr: $mgmt_ip_addr\n\tglobal anch_ip_addr_fld: $anch_ip_addr_fld\n\tmwar_count_fld: $mwar_count_fld\n\tinput mgmt IP: $mgmtip\n\tinput fld: $fld\n\tinput count:$fld2\n";

    return $PARAM_UPDATE_SUCCESS;
}

sub check_group_member_ip_with_mgmt 
{
    my $input = $_[0];
    my $result;
    my $mwar_ip_fld;
    my $mwar_ip_val;

    my($actfld, $actval) = split(/\,/, $input, 2);

#print"check_group_member_ip_with_mgmt1: $actfld, $actval\n";
    $result = param_value_return($actfld, \$mwar_ip_fld);
    if($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval, \$mwar_ip_val);
    if($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

#print "check_group_member_ip_with_mgmt2: mwarIP: $mwar_ip_val, mgmtIP: $mgmt_ip_addr\n";
#print "check_group_member_ip_with_mgmt2: mwarIP: $mwar_ip_val, mgmtIP: $mgmt_ip_addr, ipv6Ip: $ipv6_mgmt_address, ipv6prefixlen : $ipv6_prefixlen\n";
        #Check if Peer Ip is same as the management Ip
        if( ($mwar_ip_val eq $mgmt_ip_addr) || ($mwar_ip_val eq $ipv6_mgmt_address)) {
#print"BOTH EQUAL: mwarIP: $mwar_ip_val, mgmtIP: $mgmt_ip_addr\n";
            return $INVALID_CLI_OPTION;
        }

    return $result;
}

sub tree_create {
        my ($str,$value,$flag)=@_;
#print "tree_create $str, $value\n";
	my @temp;
        @temp=split('\.',$str);
	my ( $local_str, $index) = split_tag_with_index($str);
	if ($flag == 0) {
		if (defined $hash3{$local_str}) {
			if (!(string_to_num_bit_check($local_str,\$value))) {
				print IGNORED "$input_command\n";
				return ;
			} 
		}
	}
	if ($str =~ /^0\./) {
		local_tree_create($str,$value);
	} elsif($#temp==1){
		$dbase{0}{$temp[0]}{$temp[1]}=$value;
       	} elsif ($#temp==2){
		$dbase{0}{$temp[0]}{$temp[1]}{$temp[2]}=$value;
	} elsif ($#temp==3){
		$dbase{0}{$temp[0]}{$temp[1]}{$temp[2]}{$temp[3]}=$value;
       	} elsif ($#temp==4){
		$dbase{0}{$temp[0]}{$temp[1]}{$temp[2]}{$temp[3]}{$temp[4]}=$value;
	} elsif ($#temp==5){			
		$dbase{0}{$temp[0]}{$temp[1]}{$temp[2]}{$temp[3]}{$temp[4]}{$temp[5]}=$value;
       	} elsif ($#temp==6){
                $dbase{0}{$temp[0]}{$temp[1]}{$temp[2]}{$temp[3]}{$temp[4]}{$temp[5]}{$temp[6]}=$value;
       	}
}

sub parse{
        my ($add_basenode,$depth,$temp_str)=@_;
        $depth++;
	my ($var,@value_index,@index);

        for my $k1 ( sort keys %$add_basenode) {
                if ($depth !=1){
                        if ($temp_str){
                                $tmpval = $add_basenode->{ $k1 };
				my $local_str = "$temp_str."."$k1";
				my ($tag_str, $index) = split_tag_with_index("$temp_str.$k1");
				$var = $hash2{$tag_str};

				#die if (!defined ($var));
                                if (!defined ($var)) { 
			            print_to_console("Error: There is no entry for $tag_str  and component $k1 in DB2\nConfig CLI:$input_command\n");
                                    seek(RESULTFILE,0,0);
                                    print RESULTFILE "Error: There is no entry for $tag_str  and component $k1 in DB2\r\nConfig CLI:$input_command\r\n";
                                    exit;
                                }
                                push @stack,$var;
                                if(!(keys %$tmpval)){
					#&xml_write($depth,"$var",$tmpval,-1);
					&xml_write($depth,"$var",$tmpval,$index) if defined $index;
					&xml_write($depth,"$var",$tmpval,-1) if (!defined ($index));
				}
				else {
					&xml_write($depth,"$var",$value_check,$index) if defined $index;
					&xml_write($depth,"$var",$value_check,-1) if (!defined ($index));
				}
                                &parse($add_basenode->{ $k1 },$depth,$temp_str.".$k1");
                        }

                        else{#else if temp_str is not defined.
				#this is used for start of traversing of component subtrees.
				if ($First_file==0){
					#print $FD "</XML_config_variables>\n";	
                                        if(! close($FD))
                                        {
                                          remove_xml_files();
			                  print_to_console("Error: File System is out of Disk Space. Config is too big to save on the disk space:$!");
                                          seek(RESULTFILE,0,0);
                                          print RESULTFILE "Error: File System is out of Disk Space. Config is too big to save on the disk space.\r\n";
                                          exit;
                                        }
				}
				$xml_filename=$hash_xml{$k1};
# print "$k1\t $hash_xml{$k1}\n"
                                if ( $local_debug == 1 ) {
                                    open ($FD,"+>$xml_filename")or die "Can't create $k1 XML  File:$!";
                                } else {
                                    open ($FD,"+>/mnt/application/xml/$xml_filename")or die "Can't create $k1 XML  File:$!";
                                }
				print $FD "<XML_config_variables>\n";
				$First_file=0;
				#Also call split_tag_with_index here.but this loop is only root node for indiv. comp.
				my @value_index=split('#',$k1);
                                if($value_index[1]){
                                        $var=$hash2{$value_index[0]} ;                   
					&xml_write($depth,"$var",$value_check,$value_index[1])if defined $var;
                                }
                                else{
                                        $var=$hash2{"$k1"};
					&xml_write($depth,"$var",$value_check,-1)if defined $var;
                                }
				#die if (!defined ($var));
                                if (!defined ($var)) { 
			            print_to_console("Error: There is no entry for $k1 in DB5\nConfig CLI:$input_command\n:$!");
                                    seek(RESULTFILE,0,0);
                                    print RESULTFILE "Error: There is no entry for $k1 in DB5\r\nConfig CLI:$input_command.\r\n";
                                    exit;
                                }
                        	push @stack,$var;
                                &parse($add_basenode->{ $k1 },$depth,$k1);
                       }
                }
		else{   #else if depth is equal 1 temp_str is blank i.e. initial case.root node
                        &parse($add_basenode->{ $k1 },$depth,$temp_str);
                }
        }
	$tags=pop @stack;
	&xml_write($depth,"/$tags",$value_check,-1)if defined $tags;
}

sub xml_write{
        my ($depth,$tag,$value,$index)=@_;
        my @newtag;
        if ((!($tag=~/\//))||(!($FLAG eq "TRUE"))){
                for (my $m=0;$m<$depth;$m++){
                        print $FD " ";
                }
        }
        @newtag=split('\t',$tag);
        $tag=$newtag[0];
        if ($index>=0){
                $tag="$newtag[0]"." index="."\""."$index"."\"" if defined $index;
        }
        if ($value ne $value_check){
                print $FD "<$tag>$value";
                $FLAG="TRUE";
        }
        else{
                print $FD "<$tag>\n";
                $FLAG="FALSE";
        }
}
    #print $FD "</XML_config_variables>\n";

sub index_create_structure_field_create
{
    my ($tag_hierarchy,$cli_with_value)=@_;
    my @tag_arr=split('\t',$tag_hierarchy);
    my @cli_arr=split(' ',$cli_with_value);
    my ($index_tag,$tag_with_index, @index_search_reverse_digitdot,@index_value);
    for(my $i=0; $i<= $#tag_arr; $i++) {
        @tag_without_indexhelp=split('a',$tag_arr[$i]) if($tag_arr[$i] =~ /a/);
        $ref_in_cli=$i if($tag_arr[$i] =~ /a/);
	last;
    }
    my @index_backtrack_info=split('\t',$hash2{$tag_without_indexhelp[0]});

    print IGNORED "This CLI is repeated..\t$base_cli $cli_with_value\n"if defined $global_index_hash{$tag_without_indexhelp[0]}{$cli_arr[$ref_in_cli]};
    return if defined $global_index_hash{$tag_without_indexhelp[0]}{$cli_arr[$ref_in_cli]}; 

    if (defined($index_backtrack_info[1])) {#also check for presence of #
	@index_search_reverse_digitdot=split('\#',$index_backtrack_info[1]);
        @index_value=split('\t\t',$hash2{$index_search_reverse_digitdot[0]});
        $index_value[1]++;
        $hash2{$index_search_reverse_digitdot[0]}=$index_value[0]."\t".$index_value[1];#added for future index
        $tag_with_index=$index_search_reverse_digitdot[0]."#".$index_value[1];
        $global_index_hash{$tag_without_indexhelp[0]}{$cli_arr[$ref_in_cli]}=$tag_with_index;
    }
    else {
        print "The tag $tag_without_indexhelp[0] is not defined or doesn't have backtrace information in DB2\n";
    }

    $tag_without_indexhelp[0] =~ s/^$index_search_reverse_digitdot[0]/$tag_with_index/;
    @base_str=split('\#',$tag_with_index);
    &tree_create($tag_without_indexhelp[0], $cli_arr[$ref_in_cli], 0);
    if (defined ($tag_without_indexhelp[1])) {
#	process_action($tag_without_indexhelp[1], $base_str[0], $tag_with_index);
        @action_format_array = split('#', $tag_without_indexhelp[1]);
        for (my $i=1; $i <=$#action_format_array; $i++) {
            my ($action_num, $dest_field, $input_param) = split('\-', $action_format_array[$i], 3);
            $dest_field =~ s/^$base_str[0]/$tag_with_index/;
            $input_param =~ s/^$base_str[0]/$tag_with_index/;
            $action_array[$action_num]($dest_field, $input_param);
            }
    }
                                                                                                           
     for(my $i=0; $i<= $#tag_arr; $i++) {
        my ($new_tag_arr, $action_format) = split('#', $tag_arr[$i], 2);
        if(!($tag_arr[$i] =~ /a/)) {
            $new_tag_arr =~ s/^$base_str[0]/$tag_with_index/;
            if (defined ($action_format)) {
                my @action_format_array = split('#', $action_format);
                tree_create($new_tag_arr, $cli_arr[$i], 0);
#		process_action("#$action_format", $base_str[0], $tag_with_index);
                for (my $i=0; $i <=$#action_format_array; $i++) {
                        my ($action_num, $dest_field, $input_param) = split('\-', $action_format_array[$i], 3);
                        $dest_field =~ s/^$base_str[0]/$tag_with_index/;
                        $input_param =~ s/^$base_str[0]/$tag_with_index/;
                        $action_array[$action_num]($dest_field, $input_param);
                }
             } else {
                &tree_create($new_tag_arr, $cli_arr[$i], 0);
            }
         } 
    }
}

sub index_direct_structure_field_create
{
    my ($tag_hierarchy,$cli_with_value)=@_;
    my @tag_arr=split('\t',$tag_hierarchy);
    my @cli_arr=split(' ',$cli_with_value);
    my ($index_tag,$tag_with_index);
    for(my $i=0; $i<= $#tag_arr; $i++) {
        @tag_without_indexhelp=split('c$',$tag_arr[$i]) if($tag_arr[$i] =~ /c$/);
	$ref_in_cli=$i if($tag_arr[$i] =~ /c$/);
	last;
    }
 
    print IGNORED "This CLI is repeated..\t$base_cli $cli_with_value\n"if defined $global_index_hash{$tag_without_indexhelp[0]}{$cli_arr[$ref_in_cli]};#put this check when tree_create is called and check using if defined.
    return if defined $global_index_hash{$tag_without_indexhelp[0]}{$cli_arr[$ref_in_cli]}; 
   
    $tag_with_index_local = rearrange_tag($tag_without_indexhelp[0]);#taking out first index.
    my @index_backtrack_info=split('\t',$hash2{$tag_with_index_local});
    if (defined($index_backtrack_info[1])) {#also check for presence of #
	$index_backtrack_info[1] = put_back_original_index ($tag_without_indexhelp[0], $index_backtrack_info[1]);#putting original index.
	$tag_with_index = $index_backtrack_info[1].$cli_arr[$ref_in_cli];
	$global_index_hash{$tag_without_indexhelp[0]}{$cli_arr[$ref_in_cli]}=$tag_with_index;
    }
    else {
	print "The tag $tag_without_indexhelp[0] is not defined or doesn't have backtrace information in DB2\n";
    }
    @base_str=split('#'.$cli_arr[$ref_in_cli], $tag_with_index, 2);
    $tag_without_indexhelp[0] =~ s/^$base_str[0]/$tag_with_index/;
    &tree_create($tag_without_indexhelp[0], $cli_arr[$ref_in_cli], 0);
    if (defined ($tag_without_indexhelp[1])) {
        process_action($tag_without_indexhelp[1], $base_str[0], $tag_with_index);
    }

     for(my $i=0; $i<= $#tag_arr; $i++) {
        my ($new_tag_arr, $action_format) = split('#', $tag_arr[$i],2);
        if(!($tag_arr[$i] =~ /c$/)) {
            $new_tag_arr =~ s/^$base_str[0]/$tag_with_index/;
            if (defined ($action_format)) {
		@action_format_array = split('#', $action_format);
                tree_create($new_tag_arr, $cli_arr[$i], 0);
		#process_action("#$action_format", $base_str[0], $tag_with_index);
		for (my $i=0; $i <=$#action_format_array; $i++) {	
                	my ($action_num, $dest_field, $input_param) = split('\-', $action_format_array[$i], 3);
			$dest_field =~ s/^$base_str[0]/$tag_with_index/;
			$input_param =~ s/^$base_str[0]/$tag_with_index/;
                	$action_array[$action_num]($dest_field, $input_param);
		}
             } else {
                tree_create($new_tag_arr, $cli_arr[$i], 0);
            }
         } 
    }
}

sub index_autodirect_structure_field_create 
{
    my ($tag_hierarchy,$cli_with_value)=@_;
    my @tag_arr=split('\t',$tag_hierarchy);
    my @cli_arr=split(' ',$cli_with_value);
    my ($index_tag,$tag_with_index);
    for(my $i=0; $i<= $#tag_arr; $i++) {
        @tag_without_indexhelp=split('e$',$tag_arr[$i]) if($tag_arr[$i] =~ /e$/);
        $ref_in_cli=$i if($tag_arr[$i] =~ /e$/);
    }
 
    $tag_with_index = $tag_without_indexhelp[0]."#".$cli_arr[$ref_in_cli];
    $global_index_hash{$tag_without_indexhelp[0]}{$cli_arr[$ref_in_cli]}=$tag_with_index;
    
    @base_str=split('\#',$tag_with_index);
    $tag_without_indexhelp[0] =~ s/^$base_str[0]/$tag_with_index/;
    #&tree_create($tag_without_indexhelp[0], $cli_arr[$ref_in_cli], 0);
    if (defined ($tag_without_indexhelp[1])) {
        process_action($tag_without_indexhelp[1], $base_str[0], $tag_with_index);
    }

    for(my $i=0; $i<= $#tag_arr; $i++) {
	my ($new_tag_arr, $action_format) = split('#', $tag_arr[$i]);
        $new_tag_arr =~ s/^$base_str[0]/$tag_with_index/;
        if(!($tag_arr[$i] =~ /e$/)) {
	    if (defined ($action_format)) {
	        my ($action_num, $dest_field, $input_param) = split('\-', $action_format,3); 
                tree_create($new_tag_arr, $cli_arr[$i], 0);
                $dest_field =~ s/^$base_str[0]/$tag_with_index/;
                $input_param =~ s/^$base_str[0]/$tag_with_index/;
		#process_action("#$action_format", $base_str[0], $tag_with_index);
                $action_array[$action_num]($dest_field, $input_param);
             } else {
                 &tree_create($new_tag_arr, $cli_arr[$i], 0);
             }
         }
    }
}

sub index_mapped_structure_field_create
{
    my ($tag_hierarchy,$cli_with_value)=@_;
    my @tag_arr=split('\t',$tag_hierarchy);
    my @cli_arr=split(' ',$cli_with_value);
    my ($index_tag,$tag_with_index);
    for(my $i=0; $i<= $#tag_arr; $i++) {
        @tag_without_indexhelp=split('g',$tag_arr[$i]) if($tag_arr[$i] =~ /g/);
        $ref_in_cli=$i if($tag_arr[$i] =~ /g/);
    }
    $index = $cli_arr[$ref_in_cli];
    if (defined $hash3{$tag_without_indexhelp[0]}) {
        if (!(string_to_num_bit_check($tag_without_indexhelp[0], \$index))) {
            return ;
        }
    }
 
    if (!defined ($index)) {
        print_to_console("Error: The tag $tag_arr[$ref_in_cli] doesn't have string to number mapping defined for $cli_arr[$ref_in_cli].\nConfig CLI:$input_command\n");
        seek(RESULTFILE,0,0);
        print RESULTFILE "Error: The tag $tag_arr[$ref_in_cli] doesn't have string to number mapping defined for $cli_arr[$ref_in_cli].\r\nConfig CLI:$input_command\r\n";
        exit;
    }

    print IGNORED "This CLI is repeated..\t$base_cli $cli_with_value\n"if defined $global_index_hash{$tag_without_indexhelp[0]}{$index};
    return if defined $global_index_hash{$tag_without_indexhelp[0]}{$index};

    my @index_backtrack_info=split('\t',$hash2{$tag_without_indexhelp[0]});
    if (defined($index_backtrack_info[1])) { 
        $tag_with_index = $index_backtrack_info[1].$index;
        $global_index_hash{$tag_without_indexhelp[0]}{$index}=$tag_with_index;
    }
    else {
        print "The tag $tag_without_indexhelp[0] is not defined or doesn't have backtrace information in DB2\n";
    }
    @base_str=split('\#',$tag_with_index);
    $tag_without_indexhelp[0] =~ s/^$base_str[0]/$tag_with_index/;
    &tree_create($tag_without_indexhelp[0], $cli_arr[$ref_in_cli], 0);
    if (defined ($tag_without_indexhelp[1])) {#Added for actions with parent node.
	#process_action($tag_without_indexhelp[1], $base_str[0], $tag_with_index);
        @action_format_array = split('#', $tag_without_indexhelp[1]);
        for (my $i=1; $i <=$#action_format_array; $i++) {
            my ($action_num, $dest_field, $input_param) = split('\-', $action_format_array[$i], 3);
            $dest_field =~ s/^$base_str[0]/$tag_with_index/;
            $input_param =~ s/^$base_str[0]/$tag_with_index/;
            $action_array[$action_num]($dest_field, $input_param);
        }
    } 
    for(my $i=0; $i<= $#tag_arr; $i++) {
        my ($new_tag_arr, $action_format) = split('#', $tag_arr[$i]);
        $new_tag_arr =~ s/^$base_str[0]/$tag_with_index/;
        if(!($tag_arr[$i] =~ /g/)) {
            if (defined ($action_format)) {
                my ($action_num, $dest_field, $input_param) = split('\-', $action_format,3);
                tree_create($new_tag_arr, $cli_arr[$i], 0);
	#	process_action("#$action_format", $base_str[0], $tag_with_index);
            	$dest_field =~ s/^$base_str[0]/$tag_with_index/;
            	$input_param =~ s/^$base_str[0]/$tag_with_index/;
                $action_array[$action_num]($dest_field, $input_param);
             } else {
                tree_create($new_tag_arr, $cli_arr[$i], 0);
             }
         } 
    }
}

sub index_automapped_structure_field_create 
{
#Specific case only for rrm CLIs 802.11a refers index=0 while 802.11b refers index=1
    my ($tag_hierarchy,$cli_with_value)=@_;
    my @tag_arr = split('\t',$tag_hierarchy);
    my @cli_arr = split(' ',$cli_with_value);
    my @base_cli_arr = split(' ',$base_cli);
    #Base CLI splitting needed to pick the automapped structure field.
    my ($index_tag,$tag_with_index, $index);

    for(my $i=0; $i<= $#tag_arr; $i++) {
        @tag_without_indexhelp=split('i',$tag_arr[$i]) if($tag_arr[$i] =~ /i/);
        $ref_in_cli=$i if($tag_arr[$i] =~ /i/);
    }

    my @index_backtrack_info=split('\t',$hash2{$tag_without_indexhelp[0]});
    if (defined($index_backtrack_info[1])) {
        my @index_search_reverse_digitdot=split('\#',$index_backtrack_info[1]);  
	if (!(string_to_num_bit_check($index_search_reverse_digitdot[0], \$base_cli_arr[$tag_without_indexhelp[1]-1]))) {
            print "Error: The tag $tag_arr[$ref_in_cli] doesn't have string to number mapping defined for $cli_arr[$ref_in_cli].\n" ;
            #seek(RESULTFILE,0,0);
            #print RESULTFILE "0";
            return ; #?? 
	    #die;
        }
        $index = $base_cli_arr[$tag_without_indexhelp[1]-1];

	print IGNORED "This CLI is repeated..\t$base_cli $cli_with_value\n"if defined $global_index_hash{$tag_without_indexhelp[0]}{$index};#put this check when tree_create is called and check using if defined.
        return if defined $global_index_hash{$tag_without_indexhelp[0]}{$index};

        $tag_with_index = $index_backtrack_info[1].$index;
        $global_index_hash{$tag_without_indexhelp[0]}{$index}=$tag_with_index;
    }
    else {
        print "The tag $tag_without_indexhelp[0] is not defined or doesn't have backtrace information in DB2\n";
    }
     
    @base_str=split('\#',$tag_with_index);
    $tag_without_indexhelp[0] =~ s/^$base_str[0]/$tag_with_index/;
    &tree_create($tag_without_indexhelp[0], $cli_arr[$ref_in_cli], 0);
    #if (defined ($tag_without_indexhelp[1])) {
     #   process_action($tag_without_indexhelp[1], $base_str[0], $tag_with_index);
    #}
#take care for action attached with i parent node further split at digit(1,2).
    for(my $i=0; $i<= $#tag_arr; $i++) {
        my ($new_tag_arr, $action_format) = split('#', $tag_arr[$i], 2);
        $new_tag_arr =~ s/^$base_str[0]/$tag_with_index/;
        if(!($tag_arr[$i] =~ /i/)) {
            if (defined ($action_format)) {
                my ($action_num, $dest_field, $input_param) = split('\-', $action_format,3);
                tree_create($new_tag_arr, $cli_arr[$i], 0);
	#	process_action("#$action_format", $base_str[0], $tag_with_index);
                $dest_field =~ s/^$base_str[0]/$tag_with_index/;
                $input_param =~ s/^$base_str[0]/$tag_with_index/;
                $action_array[$action_num]($dest_field, $input_param);
             } else {
                tree_create($new_tag_arr, $cli_arr[$i], 0);
             }
         }
    }
}

sub check_create_direct_autodirect_index 
{
    #This function checks for b,d,f identifier cases.
    my ($tag_hierarchy, $cli_with_value, $identifier)=@_;
    my @tag_arr = split('\t',$tag_hierarchy);
    my @cli_arr = split(' ',$cli_with_value);
    my $index_tag;

    for(my $i = 0; $i <= $#tag_arr; $i++) {
        if($tag_arr[$i] =~ /$identifier/) {
	    my $temp = $i;
            @tag_without_indexhelp=split("$identifier" , $tag_arr[$i]);
            $index_tag=$global_index_hash{$tag_without_indexhelp[0]}{$cli_arr[$i]};
            if (!defined $index_tag) {
                print IGNORED "$base_cli $cli_with_value\n";
                return ;
            }
            last;
        }
    }
    my @base_str=split('\#',$index_tag);
    if (defined ($tag_without_indexhelp[1])) {
	#process_action($tag_without_indexhelp[1], $base_str[0], $index_tag);
        @action_format_array = split('#', $tag_without_indexhelp[1]);
        for (my $i=1; $i <=$#action_format_array; $i++) {
            my ($action_num, $dest_field, $input_param) = split('\-', $action_format_array[$i], 3);
            $dest_field =~ s/^$base_str[0]/$index_tag/;
            $input_param =~ s/^$base_str[0]/$index_tag/;
#print "Action test:$tag_without_indexhelp[1]--$action_num $dest_field, $input_param\n";
            $action_array[$action_num]($dest_field, $input_param);
            }
    } 
    my @new_tag_without_indexhelp;
    my ($temp_tag_arr, $temp_cli_arr);
    for(my $i=0; $i<= $#tag_arr; $i++) {
	my ($new_tag_arr, $action_format) = split('#', $tag_arr[$i], 2);
        $new_tag_arr =~ s/^$base_str[0]/$index_tag/;
        if((!($tag_arr[$i] =~ /$identifier/)) && ($tag_arr[$i] !~ /^0\./)){
		if ($tag_arr[$i] =~ /c/) {
                    $temp_tag_arr = $new_tag_arr;
                    $temp_cli_arr = $cli_arr[$i];
		index_direct_structure_field_create($new_tag_arr, $cli_arr[$i]);
		} elsif ($tag_arr[$i] =~ /a/) {
                     $temp_tag_arr = $new_tag_arr;
                     $temp_cli_arr = $cli_arr[$i];
                     index_create_structure_field_create($new_tag_arr, $cli_arr[$i]);
		} elsif ($tag_arr[$i] =~ /d/) {
                     $temp_tag_arr = $new_tag_arr;
                     $temp_cli_arr = $cli_arr[$i];
                     check_create_direct_autodirect_index($new_tag_arr, $cli_arr[$i], 'd');
                } else {
                     $new_tag_arr = add_index ($new_tag_arr, $temp_tag_arr, $temp_cli_arr) if defined  $temp_tag_arr;
                     tree_create($new_tag_arr,$cli_arr[$i],0);
               }
         if (defined ($action_format)) {
	        my @action_format_array = split('#', $action_format);
		#process_action("#$action_format", $base_str[0], $index_tag);
        	for (my $i=0; $i <=$#action_format_array; $i++) {
	            my ($action_num, $dest_field, $input_param) = split('\-', $action_format_array[$i], 3);
        	    $dest_field =~ s/^$base_str[0]/$index_tag/;
	            $input_param =~ s/^$base_str[0]/$index_tag/;
	            $action_array[$action_num]($dest_field, $input_param);
        	    }
        }
	}
	else {
	    if (($i == $temp ) ) {
		next;
	    }
	}
    }
}

sub check_mapped_structure_field_index 
{
    my ($tag_hierarchy, $cli_with_value, $identifier)=@_;
    my @tag_arr = split('\t',$tag_hierarchy);
    my @cli_arr = split(' ',$cli_with_value);
    my ($index_tag,$index);

    for(my $i = 0; $i <= $#tag_arr; $i++) {
        if($tag_arr[$i] =~ /$identifier/) {
            @tag_without_indexhelp=split("$identifier" , $tag_arr[$i]);
	    $index = $cli_arr[$i];
	    if (!(string_to_num_bit_check($tag_without_indexhelp[0], \$index))) {
		print "Error\n";
	    }
            $index_tag = $global_index_hash{$tag_without_indexhelp[0]}{$index};
            if (!defined $index_tag) {
                print IGNORED "$base_cli $cli_with_value\n";
                return ;
            }
            last;
        }
    }

    @base_str=split('\#',$index_tag);
    for(my $i=0; $i<= $#tag_arr; $i++) {
        if(!($tag_arr[$i] =~ /$identifier/)) {
            $tag_arr[$i]=~ s/^$base_str[0]/$index_tag/;
            &tree_create($tag_arr[$i],$cli_arr[$i],0);
        }
    }
}
sub check_automapped_structure_field_index
{
    my ($tag_hierarchy, $cli_with_value, $identifier)=@_;
    my @tag_arr = split('\t',$tag_hierarchy);
    my @cli_arr = split(' ',$cli_with_value);
    my ($index_tag,$index);
    my @base_cli_arr = split(' ',$base_cli);
    #Base CLI splitting needed to pick the automapped structure field.
    for(my $i = 0; $i <= $#tag_arr; $i++) {
        if($tag_arr[$i] =~ /$identifier/) {
            @tag_without_indexhelp=split("$identifier" , $tag_arr[$i]);
            $index = string_to_num_bit_check($tag_without_indexhelp[0], \$base_cli_arr[$tag_without_indexhelp[1]]);
            $index_tag = $global_index_hash{$tag_without_indexhelp[0]}{$index};
            if (!defined $index_tag) {
                print IGNORED "$base_cli $cli_with_value\n";
                return ;
            }
            last;
        }
    }

    @base_str=split('\#',$index_tag);
    for(my $i=0; $i<= $#tag_arr; $i++) {
        if(!($tag_arr[$i] =~ /$identifier/)) {
            $tag_arr[$i]=~ s/^$base_str[0]/$index_tag/;
            &tree_create($tag_arr[$i],$cli_arr[$i],0);
        }
    }
}


sub string_to_num_bit_check{
	 my ($tag_str,$value)=@_;
	 my ($tmpval,@split_stv,@split_lv,$bit_val);
         my $str_to_val=$hash3{$tag_str};
         if(defined($str_to_val)){
                @split_stv=split('\t',$str_to_val);
                foreach(@split_stv){
                        my $local_var=$_;
                        @split_lv=split('=',$local_var);
                        if($split_lv[0] eq $$value){
                                $tmpval=$split_lv[1];
                                last;
                                }
                        }
			if (defined ($tmpval)) {
        			$$value = $tmpval;
				return 1;
			} else {
				return 0;
			}
        } else {
                return 0;
        }
}

sub string_in_cli{
	my($base_cli,$str,$rem_cli)=@_;
	@value=split(" ",$rem_cli);
	$new_base_cli=$base_cli." ".$str;
	$tag_hierarchy=$hash1{$new_base_cli} if defined $hash1{$new_base_cli}; #getting tag hierarchy
	@multiple_tag_string=split('\t',$tag_hierarchy);#for multiple keywords
	&tree_create($multiple_tag_string[0],$value[1],0);
	$i=3;
	while ($multiple_tag_string[1]){
		$new_base_cli.= " ".$multiple_tag_string[1];
		$tag_hierarchy=$hash1{$new_base_cli} if defined $hash1{$new_base_cli}; #getting tag hierarchy
       		@multiple_tag_string=split('\t',$tag_hierarchy);
		&tree_create($multiple_tag_string[0],"$value[$i]",0);
		$i=$i+2;
	}
}
#This subroutines searches tag string in DB2 and returns corresponding number string.
#Use this subroutine in parse function also.

sub search_for_tag_new{
    my ($tag_str, $href)=@_;
    my @linearr = split(/\./, $tag_str);
    my $digitdotline;
    my $tmpdigitdotline;
    my $flagfirsttime = 1;
    for (my $j = 0; $j <= $#linearr; $j++) {
        foreach my $digittag (keys %hash2) {
            my ($tag_name, $index_info) = split('\t', $hash2{$digittag});
            if ($linearr[$j] eq $tag_name) {
                if($flagfirsttime == 1) {
                    $flagfirsttime = 0;
                    $tmpdigitdotline = $digittag;
                }elsif($digittag =~ $tmpdigitdotline) {
                    $tmpdigitdotline = $digittag;
                }
            }
        }
    }
    $$href = $tmpdigitdotline;
}

sub search_for_tag{
        my ($tag_str, $href)=@_;
        foreach (keys %hash2) {
                my ($tag_name, $index_info) = split('\t', $hash2{$_});
		if ($tag_name eq $tag_str) {
                	$$href = $_ ;
			return 1 ;
		}
        }
	print "The $tag_str don't have any digitdot mapping defined in DB2\n";
	return 0;
}
sub search 
{
    my ($line)=@_;
    my $var = "FALSE";
    my @temp;
    my $length = 0;
    @line=split(/ /,$line);
    for ( my $i = $#line; $i >0 ;$i--) {
	splice(@line, $i+1, $length);
#Changed to accomodate search starting from end.
	$var=more_search(@line);
	$length =1;
	last if ($var ne "FALSE");
    }
    return $var;
}

sub more_search
{
    my (@temp) = @_;
    my $var = "FALSE";
    foreach(@dummy) {
        if ($_ eq "@temp") {
            $var = $_;
	    last;
        }
    }
    return $var;
}

sub generate_xml_filename_dbase 
{
#This database contains component number to xml file name mapping.
    for my $line(<DB5>) {
        chomp $line;
        @line = split('\t',$line,2);
        $hash_xml{$line[0]}=$line[1];
    }
}

sub local_tree_create
{
    my ($str,$value)=@_;
    my @temp;
    @temp=split('\.',$str);

    if($#temp==1){
        $local_dbase{0}{$temp[0]}{$temp[1]}=$value;
    } elsif ($#temp==2){
        $local_dbase{0}{$temp[0]}{$temp[1]}{$temp[2]}=$value;
    }
}

sub rearrange_tag 
{
    #This sub routine rearranges the tag by removing index(#index) .Currently only one level implemented.
    my ($tag_str)=@_;
    if ($tag_str =~ /#/) {
	@new_tag = split ('\#', $tag_str);
	my ($t1 , $t2)= split('\.', $new_tag[1], 2);
	$tag_str = $new_tag[0].".".$t2;
	return $tag_str;
    }
    else {
	return $tag_str;
    }
}

sub put_back_original_index
{
    #Here index in index backtrack info is added with the help of original tag.
    my ($orig_tag, $idx_backtrack_info) = @_;
    my @orig_idx = split('\.', $orig_tag);
    my @idx_bktrc = split('\.', $idx_backtrack_info);
    for (my $i = 0; $i< $#idx_bktrc ;$i++) {
	if ($orig_idx[$i] ne $idx_bktrc[$i] ) {
	    $idx_bktrc[$i] = $orig_idx[$i];
	  #  last;
	}
    }
    $idx_bktrc = join('.', @idx_bktrc);
    return $idx_bktrc;
}

sub add_new_index
{
    #Here index in old tag is added with the help of new tag.
    my ($old_tag, $new_tag) = @_;
    my @old_tag = split('\.', $old_tag);
    my @new_tag = split('\.', $new_tag);
    for (my $i = 0; $i< $#old_tag ;$i++) {
	if ($old_tag[$i] ne $new_tag[$i]) {
 	    $old_tag[$i] = $new_tag[$i];
	    last;
	}
    }
    $old_tag = join('.', @old_tag);
    return $old_tag;
}
#split_tag_with_index('18.6#0.6#0.1#0');
sub split_tag_with_index
{
    #This subroutine takes tree node with index and returns the tag in digitdot and outermost index.
    #return index only if #index is last element.
    #else returns -1.
    my ($tag_str) = @_;
    my $new_tag_str;

    my ($local_index, $local_tag_hierarchy);
    @tag_index = split('\#',$tag_str);
    $new_tag_str = $tag_index[0];
    for (my $i=1; $i <= $#tag_index; $i++) {
	($local_index, $local_tag_hierarchy)=split ('\.', $tag_index[$i], 2);
        $new_tag_str = $new_tag_str .".".$local_tag_hierarchy if defined $local_tag_hierarchy;
	$local_index = -1 if defined $local_tag_hierarchy;
    }
    return ($new_tag_str, $local_index);
}

sub initialise_action_names
{
    $hash_action_names{"update"} = \&update;
    $hash_action_names{"asciitohex"} = \&asciitohex;
    $hash_action_names{"stringlen"} = \&stringlen;
    $hash_action_names{"updatebit"} = \&updatebit;
    $hash_action_names{"increment"} = \&increment;
    $hash_action_names{"updatewithmap"} = \&updatewithmap;
    $hash_action_names{"add_delete_node"} = \&add_delete_node;
    $hash_action_names{"updatebitposition"} = \&updatebitposition;
    $hash_action_names{"update_with_node"} = \&update_with_node;
    $hash_action_names{"mobilityOui_action"} = \&mobilityOui_action;
    $hash_action_names{"update_hex_for_node"} = \&update_hex_for_node;
    $hash_action_names{"set_create_index_hash"} = \&set_create_index_hash;
    $hash_action_names{"update_both_dbases"} = \&update_both_dbases;
}
sub initialise_format_names
{
   $hash_format_names{"byte_TYPE"} = \&byte_TYPE; 
   $hash_format_names{"unsignedByte_TYPE"} = \&unsignedByte_TYPE; 
   $hash_format_names{"int_TYPE"} = \&int_TYPE; 
   $hash_format_names{"unsignedInt_TYPE"} = \&unsignedInt_TYPE; 
   $hash_format_names{"short_TYPE"} = \&short_TYPE; 
   $hash_format_names{"unsignedShort_TYPE"} = \&unsignedShort_TYPE; 
   $hash_format_names{"unsignedLong_TYPE"} = \&unsignedLong_TYPE; 
   $hash_format_names{"long_TYPE"} = \&long_TYPE; 
   $hash_format_names{"string_TYPE"} = \&string_TYPE; 
   $hash_format_names{"HEXstring_TYPE"} = \&HEXstring_TYPE; 
   $hash_format_names{"enum_TYPE"} = \&enum_TYPE;
   $hash_format_names{"struct_TYPE"} = \&struct_TYPE; 
   $hash_format_names{"variable_TYPE"} = \&variable_TYPE; 
   $hash_format_names{"IPv4addr_TYPE"} = \&IPv4addr_TYPE; 
   $hash_format_names{"MACaddr_TYPE"} = \&MACaddr_TYPE; 
   $hash_format_names{"MAX_TYPE_OF_VAR"} = \&MAX_TYPE_OF_VAR; 
}

sub intialise_interface_clis
{
    my $new_digit_dot;
    if (search_for_tag("simInterface",\$digit_dot)) {
	if (search_for_tag("InterfaceName",\$new_digit_dot)) {
            $hash2{$digit_dot} = "simInterface"."\t"."3";
            $hash_interface{"config interface address management"} = "$digit_dot#0";
            $global_index_hash{$new_digit_dot}{"management"} = "$digit_dot#0";
            $hash_interface{"config interface address ap-manager"} = "$digit_dot#3";
            $global_index_hash{$new_digit_dot}{"ap-manager"} = "$digit_dot#3";
            $hash_interface{"config interface address service-port"} = "$digit_dot#1";
            $global_index_hash{$new_digit_dot}{"service-port"} = "$digit_dot#1";
            $hash_interface{"config interface address virtual"} = "$digit_dot#2";
            $global_index_hash{$new_digit_dot}{"virtual"} = "$digit_dot#2";
            $hash_interface{"config interface vlan management"} = "$digit_dot#0";
            #$global_index_hash{$new_digit_dot}{"management"} = "$digit_dot#0";
       }
    }
}
 

sub update
#action 0
{
    my $dest_field = $_[0];
    my $input_param = $_[1];
    &tree_create($dest_field, $input_param, 1);
}

sub asciitohex
#action 1
{
    my $dest_field = $_[0];
    my $input_param = $_[1];
    my @temp = split('\.', $input_param);
    my $ascii_or_hex = $local_dbase{0}{$temp[0]}{$temp[1]};
    my $string ;
    my $hexchars = '';
    if (get_value_from_tree($dest_field, \$string)) { 
        if ($ascii_or_hex eq 'ascii') {
            foreach my $c (split(//,$string)) {
                $hexchars .= sprintf "%x", ord($c);
            }
        }
     &tree_create($dest_field, $hexchars,1);
     }
     else {
        #print IGNORED "$base_cli\n";
    }
}

sub stringlen 
#action 2
{
    my $dest_field = $_[0];
    my $input_param = $_[1];
    my $value;
    if (get_value_from_tree($input_param, \$value)) {
        my $len = length($value);
        &tree_create($dest_field, $len, 1);
    } else {
        print "stringlen:The value for $input_param is not defined for $base_cli.\n";
    }
}

sub updatebit
#action 3 
{
    my $dest_field = $_[0];
    my $input_param = $_[1];
    my $value;
    my ($bitmap, $set_reset_bit) = split('\,', $input_param,2);
    $bitmap = convert_hex_to_decimal_without_header($bitmap);
    if (get_value_from_tree($dest_field, \$value)) {
        if ($set_reset_bit == 1) {
	    $value = $value | $bitmap;
            my ( $local_str, $index) = split_tag_with_index($dest_field);
	    if (defined $hash3{$local_str}) {
                if (!(string_to_num_bit_check($local_str,\$value))) {
                    return ;
                }
            }
	    tree_create ($dest_field, $value, 1);
        } else {
            $value = $value & (~$bitmap);
            my ( $local_str, $index) = split_tag_with_index($dest_field);
	    if (defined $hash3{$local_str}) {
                if (!(string_to_num_bit_check($local_str,\$value))) {
                    return ;
                }
            }
            tree_create ($dest_field, $value, 1);
        }
    } else {
        if ($set_reset_bit == 1) {
            my ( $local_str, $index) = split_tag_with_index($dest_field);
	    if (defined $hash3{$local_str}) {
                if (!(string_to_num_bit_check($local_str,\$bitmap))) {
                    return ;
                }
            }
            tree_create ($dest_field, $bitmap, 1);
        } else {
            my ( $local_str, $index) = split_tag_with_index($dest_field);
	    if (defined $hash3{$local_str}) {
                if (!(string_to_num_bit_check($local_str,\$bitmap))) {
                    return ;
                }
            }
            tree_create ($dest_field, 0, 1);
        }
    }
}

sub increment
#action 4 
{
    my $dest_field = $_[0];
    my $input_param = $_[1];

    my ($offset, $input_tag) = split('\,', $input_param,2);
    my ($tag_name,$value) = split ('\t', $hash2{$input_tag});
    $value = $value + $offset;
    $hash2{$input_tag} = $tag_name."\t".$value;
    &tree_create ($dest_field, $value, 1);
}

sub updatewithmap
#action 5
{
    my $dest_field = $_[0];
    my $input_param = $_[1];

}

sub add_delete_node
#action 6
{
    my $dest_field = $_[0];
    my $input_param = $_[1];

}

sub updatebitposition
#action 7
{
    my $dest_field = $_[0];
    my $input_param = $_[1];
    my $value;
    if (get_value_from_tree($input_param, \$value)) {
        $value = 2 ** $value;    
        tree_create ($dest_field, $value, 1);
    } else {
        print "The value for $input_param  with destination $dest_field is not found in tree.\n";
    }
}

sub update_country_code_info
{
    my $headline;
    my $tailline;
    my $rrmchan_digitdot;
    search_for_tag_new("RadioResourceManager-Configuration.rrm2.rrmAllowedChans.chans", \$rrmchan_digitdot);
    delete_from_xml_dbase($rrmchan_digitdot);
    if(open(DB_commonCountryInfo,"$commonCountryInfo")){
    for my $line1(<DB_commonCountryInfo>) {
        chomp $line1;
        my @linetmp = split('\t', $line1);
        my @linearr = split(/\./, $linetmp[0]);
        my $digitdotline;
        my $tmpdigitdotline;
        for (my $j = 0; $j <= $#linearr; $j++) {
           my @tempfield = split(/\#/, $linearr[$j]);
           my $flagfirsttime = 1;
           foreach my $digittag (keys %hash2) {
               my ($tag_name, $index_info) = split('\t', $hash2{$digittag});
               if ($tempfield[0] eq $tag_name) {
                   if($flagfirsttime == 1) {
                       $tmpdigitdotline = $digittag;
                   }elsif($digittag =~ $tmpdigitdotline) {
                       $tmpdigitdotline = $digittag;
                   }
               }
           }
           my @tmpdigitdotarr = split(/\./, $tmpdigitdotline);
           if($#tempfield == 1){
               $linearr[$j] = $tmpdigitdotarr[$j] . "#" . $tempfield[1];
           } else {
               $linearr[$j] = $tmpdigitdotarr[$j];
           }
        }
        $digitdotline = join ('.', @linearr) . "\t" . $linetmp[1];
#print "$digitdotline\n";
        my ($dest_field, $val) = split('\t', $digitdotline, 2);
        my $fld;
        my $dim = 0;

        my @temp = split(/\#/, $dest_field);

        $fld = $temp[0];
        for (my $i = 1; $i <= $#temp; $i++) {
            my @tmp = split(/\./, $temp[$i], 2);
            $array_index{index}[$dim] = $tmp[0];
            $array_index{flag}[$dim] = $xmldbase_index_updated;
            $fld = $fld . "." . $tmp[1];
# print "update_country_code_info $dim, $tmp[0]\n";
            $dim += 1;
        }
# print "update_country_code_info $fld, $val\n";
        update_xml_dbase($fld, $val);
    }
    close($DB_commonCountryInfo);
    system("/bin/rm $commonCountryInfo");
    }
}


sub update_both_dbases
{
    my $dest_field = $_[0];
    my $val = $_[1];
    my $fld;
    my $dim = 0;
    
    my @temp = split(/\#/, $dest_field);

    $fld = $temp[0];
    for (my $i = 1; $i <= $#temp; $i++) {
        my @tmp = split(/\./, $temp[$i], 2);
        $array_index{index}[$dim] = $tmp[0];
        $array_index{flag}[$dim] = $xmldbase_index_updated;
        $fld = $fld . "." . $tmp[1];
#print "update_both_dbases1 $dim, $tmp[0]\n";
        $dim += 1;
    }
#print "update_both_dbases2 $fld, $val\n";
    update_xml_dbase($fld, $val);
}

sub set_mobilitygroup_mcastaddress_hash
{
    my $input = $_[0];
    my $result = $NOOP_CLI_RETURN_OPTION;
    my $actgroup;
    my $group;
    my $actmcastaddress;
    my $mcastaddress;
    my $actgroupfld;
    my $groupfld;
    my $actmcastfld;
    my $mcastfld;
    my $xmlref = \%digit_to_tag_actual;
    ($actgroupfld, $actmcastfld, $actgroup, $actmcastaddress) = split(/$nodeparamconnector/, $input, 4);
    $result = param_value_return($actgroupfld, \$groupfld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actmcastfld, \$mcastfld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actgroup, \$group);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actmcastaddress, \$mcastaddress);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
     $mobility_group_mcast_address{group}{$group} = $mcastaddress;
     $mobility_group_mcast_address{group_field} = $groupfld;
     $mobility_group_mcast_address{mcast_field} = $mcastfld;
    return $PARAM_UPDATE_SUCCESS;
}

sub set_create_index_hash
{
    my $dest_field = $_[0];
    my $input_param = $_[1];
    my $fld;
    my $index;
    
    my($string, $init) = split(/\,/, $input_param);
    my @temp = split(/\#/, $dest_field);

    $fld = $temp[0];
#print "set_create_index_hash $string, $init $input_param, $dest_field\n";
    for (my $i = 1; $i <= $#temp; $i++) {
        my @tmp = split(/\./, $temp[$i], 2);
        if ($i == $#temp) {
            $index = $tmp[0];
        }
        $fld = $fld . "." . $tmp[1];
    }
    if (defined($index)) {
        $create_index_hash{$created_input_index}{$fld}{str}{$string} = $index;
        if (defined($create_index_hash{$created_input_index}{$fld}{count})) {
            $create_index_hash{$created_input_index}{$fld}{count} += 1;
        } else {
            $create_index_hash{$created_input_index}{$fld}{count} = $init;
        }
    }
}

sub update_with_node
#action 8
{
    my $dest_field = $_[0];
    my $input_param = $_[1];
#    my ( $local_str, $index) = split_tag_with_index($input_param); 
    my $value = 1;
    if (get_value_from_tree($input_param, \$value)) {
        tree_create($dest_field, $value, 1);
    } else {
        print "update_with_node:The value for $input_param is not defined for $base_cli.\n";
    }    
}

sub mobilityOui_action
{
    my $dest_field = $_[0];
    my $input_param = $_[1];
    $new_dest_field = $dest_field .'#1';
    tree_create($new_dest_field, 20, 1);
    $new_dest_field = $dest_field .'#2';
    tree_create($new_dest_field, 126, 1);
}

sub update_hex_for_node
{
    my $dest_field = $_[0];
    my $input_param = $_[1];
    my $value;
    my $hexchars = '';
    if (get_value_from_tree($input_param, \$value)) {
        foreach my $c (split(//,$value)) {
            $hexchars .= sprintf "%x", ord($c);
        }
        tree_create($dest_field, $hexchars, 1);
    } else {
        print "update_hex_for_node:The value for $input_param is not defined for $base_cli.\n";
    }
}

sub add_node_to_tree
{
    my $str = $_[0];
    my $value = $_[1];
    my @temp;
    @temp=split('\.',$str);
    my $href;
    if (defined ($dbase{0})) {
        $href = \%{$dbase{0}};
        for (my $i = 0; $i < $#temp; $i++) {
            if (defined $$href{$temp[$i]}) {
                $href = \%{$$href{$temp[$i]}};
            } else {
                return 0;
            }
        }
        if (defined $$href{$temp[$#temp]}) {
            $$href{$temp[$#temp]} = $value ;
        } else {
            return 0;
        }
    } else {
        return 0;
   }
   return 1;
                                                                                                              
}

sub get_value_from_tree
{
    my $str = $_[0];
    my $value = $_[1];
    my @temp;
    @temp=split('\.',$str);
    my $href;
    if (defined ($dbase{0})) {
        $href = \%{$dbase{0}};
        for (my $i = 0; $i < $#temp; $i++) {
            if (defined $$href{$temp[$i]}) {
                $href = \%{$$href{$temp[$i]}};
            } else {
                return 0;
            }           
	}
        if (defined $$href{$temp[$#temp]}) {
            $$value = $$href{$temp[$#temp]};
        } else {
            return 0;
        }
    } else {
        return 0;
   }
   return 1;

}

sub populate_array
{
    my $max = $hash7{$max_formats};
    for (my $i =0; $i<= $max; $i++) {
        for (my $j =0; $j<= $max; $j++) {
	    if ($i == $j) {
	        $format_conv_arr[$i][$j] = \&no_format_conversion;
	    } else {
		$format_conv_arr[$i][$j] = \&format_conversion_illegal;
            }
	}
    }
    $format_conv_arr[$hash7{string_TYPE}][$hash7{byte_TYPE}] = \&STRING_to_BYTE;
    $format_conv_arr[$hash7{string_TYPE}][$hash7{unsignedByte_TYPE}] = \&STRING_to_BYTE;
    $format_conv_arr[$hash7{IPv4addr_TYPE}][$hash7{int_TYPE}] =  \&IP_to_INT;
    $format_conv_arr[$hash7{IPv4addr_TYPE}][$hash7{unsignedInt_TYPE}] =  \&IP_to_INT;
    $format_conv_arr[$hash7{string_TYPE}][$hash7{HEXstring_TYPE}] =  \&STRING_to_HEX;
    $format_conv_arr[$hash7{IPv4addr_TYPE}][$hash7{HEXstring_TYPE}] =  \&IP_to_HEX;
    $format_conv_arr[$hash7{MACaddr_TYPE}][$hash7{byte_TYPE}] = \&MAC_to_BYTE;
    $format_conv_arr[$hash7{string_TYPE}][$hash7{int_TYPE}] = \&STRING_to_int;
    $format_conv_arr[$hash7{string_TYPE}][$hash7{unsignedInt_TYPE}] = \&STRING_to_int;
    $format_conv_arr[$hash7{string_TYPE}][$hash7{short_TYPE}] = \&STRING_to_int;
    $format_conv_arr[$hash7{string_TYPE}][$hash7{unsignedShort_TYPE}] = \&STRING_to_int;
    $format_conv_arr[$hash7{string_TYPE}][$hash7{long_TYPE}] = \&STRING_to_int;
    $format_conv_arr[$hash7{string_TYPE}][$hash7{unsignedLong_TYPE}] = \&STRING_to_int;
    $format_conv_arr[$hash7{string_TYPE}][$hash7{IPv4addr_TYPE}] = \&STRING_to_IP;
    $format_conv_arr[$hash7{string_TYPE}][$hash7{MACaddr_TYPE}] = \&STRING_to_MAC;
    $format_conv_arr[$hash7{MACaddr_TYPE}][$hash7{HEXstring_TYPE}] = \&MAC_to_HEX;
    $format_conv_arr[$hash7{unsignedInt_TYPE}][$hash7{IPv4addr_TYPE}] =  \&INT_to_IP;    
}

sub no_format_conversion
{
    return $NOOP_CLI_RETURN_OPTION;
}

sub format_conversion_illegal
{
    return $ILLEGAL_CONVERSION_OPTION;
}

sub process_format_specifiers
{
    my ($str, $value) =@_;
    my ( $local_str, $index) = split_tag_with_index($str);
    $format_num = $hash6{$local_str};
    $format_array[$num]($str, $value);
    #$value = $format_array[$num]($value);
    #$format_detail[$local_str][$format_num] = $format_array[$num];

}
sub convert_to_hex
{
    my ($str) = @_;
    my $hexchars = '';
    foreach my $c (split(//,$str)) {
            $hexchars .= sprintf "%x", ord($c);
    }

    return $hexchars;
}

sub STRING_to_BYTE 
{
    my $value= $_[0];
    my $local_decimal = $_[1];
    my $arr_flag = $_[2];
    my @temp = split(//, $value);
    my $local_hex ;
    if ($arr_flag == 0) {
       my $result =  check_for_digits($value);
       if ($result != $PARAM_UPDATE_SUCCESS) {
           #seek(RESULTFILE,0,0);
           #print RESULTFILE "0";
           print "Value $value does not contains digit for CLI:$input_command\n";
           print IGNORED "$input_command\n";
           #die;
           return $result;
       }
       $$local_decimal = $value;
       return $NOOP_CLI_RETURN_OPTION;
    }

    for(my $i = 0; $i <= $#temp; $i++) {
        $local_hex = convert_to_hex($temp[$i]);
        if ($flag_for_byte_offset == 0) {
            $global_byte_arr[$i + $global_bytearray_index] = convert_hex_to_decimal_without_header($local_hex);
#print "STRING_to_BYTE :Input $value,localhex $local_hex global_byte_arr $global_byte_arr[$i + $global_bytearray_index], $global_bytearray_index+$i, $flag_for_byte_offset\n";
        } else {
            $global_byte_arr[$i] = convert_hex_to_decimal_without_header($local_hex);
#print "STRING_to_BYTE :Input $value,localhex $local_hex global_byte_arr $global_byte_arr[$i],$i, $flag_for_byte_offset\n";
        }
    }
    return $NOOP_CLI_RETURN_OPTION;
}

sub STRING_to_int 
{
    my $value= $_[0];
    my $local_decimal = $_[1];
    my $arr_flag = $_[2];
    my $result =  check_for_digits($value);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        #seek(RESULTFILE,0,0);
        #print RESULTFILE "0";
        print "Value $value does not contains digit for CLI:$input_command\n";
        print IGNORED "$input_command\n";
        #die;
        return $result;
    }
    $$local_decimal = $value;
    return $NOOP_CLI_RETURN_OPTION;
}

sub STRING_to_IP 
{
    my $value= $_[0];
    my $local_decimal = $_[1];
    my $arr_flag = $_[2];
    my @temp = split('\.',$value);
    if($#temp != 3) {
        return $INVALID_IP_ADRESS;
    }
    for(my $i=0; $i<=$#temp; $i++) {
        if(($temp[$i]>255) || ($temp[$i]<0)) {
        return $INVALID_IP_ADRESS;
        }
    }
    $$local_decimal = $value;
    return $NOOP_CLI_RETURN_OPTION;
}

sub STRING_to_MAC 
{
    my $value= $_[0];
    my $local_decimal = $_[1];
    my $arr_flag = $_[2];
    my $dec_val;

    my @temp = split(':',$value);     
#Added to take care of mac addr without colons.
    if($#temp == 0) {
        my @temp2 = split('', $value);
        if($#temp2 != 11) {
       return $INVALID_MAC_ADRESS;
        } else {
            for(my $i=0; $i<=$#temp2; $i++) {
                if($i==0) {
                    $value = $temp2[$i];
                } else {
                    $value .= $temp2[$i];
                    if(($i%2==1)&&($i<$#temp2)) {
                        $value .= ':';
    }
                }
            }
        }
    } elsif($#temp != 5) {
       return $INVALID_MAC_ADRESS;
    } else {
        for(my $i=0; $i<=5; $i++) {
            $dec_val = hex($temp[$i]);   
            if($dec_val < 0 || $dec_val > 255) {
                return $INVALID_MAC_ADRESS;
            } 
        }
    } 
    $$local_decimal = $value;
    return $NOOP_CLI_RETURN_OPTION;
}

sub BYTE_to_STRING
{
#getting single element of array and append at top to get full string.
    my $value= $_[0];
    my $local_hex = convert_decimal_to_hex_string($value);
    my $str = HEX_to_STRING($local_hex);
    return $str;
}

sub unsignedShort_TYPE 
{
#Do nothing same string as output.
    my $str = $_[0]; 
    my $value= $_[1];
    add_node_to_tree($str, $value);
} 

sub string_TYPE
{
#Do nothing same string as output.
} 

sub STRING_to_HEX 
{
# Convert each ASCII character to a two-digit hex number.
    my $value= $_[0];
    my $hex_val = $_[1];
    my $arr_flag = $_[2];
    my @temp = split(//, $value);
    if (($temp[0] eq '\\') && ($temp[1] eq '0')) {
        $$hex_val = "";
#print "STRING_to_HEX1: $value $$hex_val\n";
    } else {
#   $value =~ s/(.|\n)/sprintf("%02lx", ord $1)/eg;
        $$hex_val =~ s/(.|\n)/sprintf("%02lx", ord $1)/eg;
#print "STRING_to_HEX2: $value $$hex_val\n";
    }
    return $NOOP_CLI_RETURN_OPTION;
}

sub MAC_to_HEX
{
    my $value= $_[0];
    my $hex_val = $_[1];
    my $arr_flag = $_[2];
    my $result;
    $result = STRING_to_HEX ($value, $hex_val, $arr_flag);
    return $NOOP_CLI_RETURN_OPTION;
}

sub HEX_to_STRING 
{
    ## Convert each two-digit hex number back to an ASCII character.
#    $value =~ s/([a-fA-F0-9]{2})/chr(hex $1)/eg;
    (my $value = shift) =~ s/([a-fA-F0-9]{2})/chr(hex $1)/eg;
    return $value;
}

sub IP_to_INT
{
    my $value = $_[0];
    my $ip_to_int = $_[1];
    my $arr_flag = $_[2];
    my @temp = split('\.', $value);
    my @hexstring;
    for(my $i=0; $i <= $#temp; $i++) {
        if ($temp[$i]>255 || $temp[$i]<0) {
            return $INVALID_IP_ADRESS;
        }
	$hexstring[$i] = convert_decimal_to_hex_string($temp[$i]);
	$hexstring[$i] = '0'.$hexstring[$i] if (length($hexstring[$i]) == 1);
    }
    my $temp_hex = join('',@hexstring);
    $$ip_to_int = convert_hex_to_decimal_without_header($temp_hex);
#print "IP_to_INT $value temp_hex $temp_hex $$ip_to_int\n";
    return $NOOP_CLI_RETURN_OPTION;
#   add_node_to_tree($str, $str_in_int);
}

sub IP_to_HEX
{
    my $value = $_[0];
    my $ip_to_hex = $_[1];
    my $arr_flag = $_[2];
    my @temp = split('\.', $value);

    for(my $i=0; $i <= $#temp; $i++) {
        if ($temp[$i]>255 || $temp[$i]<0) {
            return $INVALID_IP_ADRESS;
        }
    }
    $$ip_to_hex =~ s/(.|\n)/sprintf("%02lx", ord $1)/eg;
#print "IP_to_HEX $value $$ip_to_hex\n";
    return $NOOP_CLI_RETURN_OPTION;
}

sub INT_to_IP
{
    my $value = $_[0];
    my $ip_val = $_[1];
    my @ip_arr;

    for(my $j = 0; $j < 4; $j++){
       $ip_arr[3-$j] = $value%256;
       $value >>= 8;
    }
    $$ip_val = join('.', @ip_arr);

    return $NOOP_CLI_RETURN_OPTION;
}

sub MAC_to_BYTE
{ 
    my $value= $_[0];
    my $decimal = $_[1];
    my $arr_flag = $_[2];
    my @temp = split('\:', $value);
    if($#temp != 5) {
       return $INVALID_MAC_ADRESS;
    }
    else
    {
        for(my $i=0; $i<=5; $i++) {
	$global_byte_arr[$i] = convert_hex_to_decimal_without_header($temp[$i]);
#print "MAC_to_BYTE $value $global_byte_arr[$i]\n";
					if($global_byte_arr[$i]< 0 || $global_byte_arr[$i] > 255) {
                return $INVALID_MAC_ADRESS;
            } 
        }
    }
    return $NOOP_CLI_RETURN_OPTION;
}

sub BYTE_to_MAC 
{
#for xml to CLI  merge the array and convert decimal to hex and then separate using colon.
    my $value= $_[0];#Here we can get value in decimal for each index separated using .192.123......)
    my @temp = split('\.', $value);

    for(my $i=0; $i <= $#temp; $i++) {
	$hexstring[$i] = convert_decimal_to_hex_string($temp[$i]);
    }
    my $combined_hex = join(':',@hexstring);
    return $combined_hex;
}

sub convert_hex_to_decimal_without_header
{
    my ($str) = @_;
    my $decimal;
    if ($str =~ /x/) {
       ($hex_header, $str) = split('x', $str);
    }
    my @temp1 = split(//, $str);
    for (my $i = 0; $i <= $#temp1; $i++) {
        if ($temp1[$i] eq 'a' || $temp1[$i] eq 'A') {
            $temp1[$i] = 10;
        } elsif ($temp1[$i] eq 'b' || $temp1[$i] eq 'B') {
            $temp1[$i] = 11;
        } elsif ($temp1[$i] eq 'c' || $temp1[$i] eq 'C') {
            $temp1[$i] = 12;
        } elsif ($temp1[$i] eq 'd' || $temp1[$i] eq 'D') {
            $temp1[$i] = 13;
        } elsif ($temp1[$i] eq 'e' || $temp1[$i] eq 'E') {
            $temp1[$i] = 14;
        } elsif ($temp1[$i] eq 'f' || $temp1[$i] eq 'F') {
            $temp1[$i] = 15;
        }
        $decimal = $decimal * 16 + $temp1[$i];
    }
#print "convert_hex_to_decimal_without_header Input $str $decimal\n";
    return($decimal);
}

sub convert_decimal_to_hex_string
{
    my $value = $_[0];
    my $temp1 = 1;
    my $temp2 = 0;
    my $hexstring;
    while ($temp1) {
        $temp1 = $value / 16;
        $temp1 = int($temp1);
        $temp2 = $value % 16;
        $hexstring = $decimal_to_hex_string_array[$temp2] . $hexstring;
#print "convert_decimal_to_hex_string2 $temp1, $temp2,$hexstring\n";
        $value = $temp1;
    }
    return ($hexstring);
}

sub read_default_tag
{
    for $line(<DB11>) {
        chomp $line;
        my ($action_num, $dest_field, $value) = split('\-', $line, 3);
        $action_array[$action_num]($dest_field, $value);
    }	
    if(! close(DB11))
    {
       remove_xml_files();
      die "Error: File System is out of Disk Space. Config is too big to save on the disk space:$!";
    }
}

sub add_index
{
    my ($tag_str, $tag_help, $cli_help) = @_;
#Here $tag_str =26.1#0.4.2 $tag_help=26.1#0.4.14d
    my $tag_with_index;
    my ($tag_without_index_help, $identifier) = split('\w$',$tag_help);
    if ($tag_help != NULL) {
        $tag_with_index = $global_index_hash{$tag_without_index_help}{$cli_help};
        my @tag_with_index = split('\.', $tag_with_index);
        my @tag_str = split('\.', $tag_str);
        for (my $i = 0; $i <= $#tag_with_index; $i++) {
            if ($tag_with_index[$i] ne $tag_str[$i]) {
                 $tag_str[$i] = $tag_with_index[$i];
            }
        }
        $tag_str = join('.', @tag_str);
    } 
    return $tag_str;
      
}
sub process_action
{
#Here $tag_without_indexhelp contains #num-dest-input#...
    my ($tag_without_indexhelp, $base_str, $tag_with_index) = @_;
#print "$tag_without_indexhelp, $base_str, $tag_with_index\n";
    @action_format_array = split('#', $tag_without_indexhelp);
    for (my $i=1; $i <=$#action_format_array; $i++) {
        my ($action_num, $dest_field, $input_param) = split('\-', $action_format_array[$i], 3);
        $dest_field =~ s/^$base_str/$tag_with_index/;
        $input_param =~ s/^$base_str/$tag_with_index/;
        $action_array[$action_num]($dest_field, $input_param);
    }
}

sub generate_index_create
{
    my $index_backtrack_info = $_[0];
    my ($local_str, $index)= split_tag_with_index();

}
#    print Dumper \%digit_to_tag;
#    print Dumper \%digit_to_tag_actual;
#    print Dumper \%tag_to_digit;

sub generate_digit_to_tag_viceversa
{
    my $href = \%digit_to_tag;
    my $href1 = \%tag_to_digit;
    my $href2 = \%fldarraydbase_hash;
    my $tag;
    open(DB2,"$newdb2") or die "Can't open digitidot to string database File:$!";
    for my $line(<DB2>) {
        $href = \%digit_to_tag;
        $href1 = \%tag_to_digit;
        $href2 = \%fldarraydbase_hash;
        my @temp = split('\t', $line);   
        my @digit_dot = split('\.', $temp[0]);
        for (my $i=0; $i < $#digit_dot; $i++) {
            $tag = $$href{nxt}{$digit_dot[$i]}{tag};
            $href1 = \%{$$href1{nxt}{$tag}};
            $href = \%{$$href{nxt}{$digit_dot[$i]}};
            $href2 = \%{$$href2{nxt}{$digit_dot[$i]}};
        }
        $$href{nxt}{$digit_dot[$#digit_dot]}{tag} = $temp[1];
        $$href1{nxt}{$temp[1]}{digit} = $digit_dot[$#digit_dot];
        $href2 = \%{$$href2{nxt}{$digit_dot[$#digit_dot]}};
        $href = \%{$$href{nxt}{$digit_dot[$#digit_dot]}};
        if (defined($$href2{array})) {
            $$href{array} = $$href2{array};
        }
# print "generate_digit_to_tag_viceversa1 $temp[0], $temp[1]\n";
# print "generate_digit_to_tag_viceversa $temp[1], $digit_dot[$#digit_dot], \%{$$href{nxt}{$digit_dot[$#digit_dot]}}, \%{$$href1{nxt}{$temp[1]}}\n";
    }
    if(! close(DB2))
    {
       remove_xml_files();
       die "Error: File System is out of Disk Space.:$!";
    }
}

sub initialize_retcheck
{
    $retcheck[$CLI_INPUT_OPTIONAL] = 0;
    $retcheck[$ADVANCE_TO_NEXT_DEPTH] = 1;
    $retcheck[$END_OF_CLI_TREE] = 1;
    $retcheck[$INPUT_NOT_MATCHED] = 0;
    $retcheck[$INVALID_CLI_OPTION] = 0;
    $retcheck[$CLI_JUMP_OPTION] = 0;
    $retcheck[$INSUFFICIENT_CLI_OPTIONS] = 0;
    $retcheck[$NOOP_CLI_RETURN_OPTION] = 1;
    $retcheck[$UPDATE_CLI_NODE] = 1;
    $retcheck[$NO_INSTANCE_FOUND] = 0;
    $retcheck[$BACKTRACK_TO_PREVIOUS_LEVEL] = 0;
    $retcheck[$DELETE_CURRENT_AND_BACKTRACK_TO_PREVIOUS_LEVEL] = 0;
    $retcheck[$DONOT_UPDATE_CLI_NODE_AND_STOP] = 0;
    $retcheck[$MORE_INSTANCES_PRESENT] = 1;
    $retcheck[$NO_MORE_INSTANCES] = 0;
    $retcheck[$CLI_PRINTED] = 1;
    $retcheck[$PARAM_UPDATE_SUCCESS] = 1;
    $retcheck[$STRVALMAP_NO_VALUE_FOUND] = 0;
    $retcheck[$STRVALMAP_NO_STRING_FOUND] = 0;
    $retcheck[$GET_NEXT_INDEX_FOR_SET_LEVEL] = 0;
    $retcheck[$TAG_FORMAT_NOT_MATCHED] = 1;
    $retcheck[$TAG_FORMAT_MATCHED] = 1;
    $retcheck[$GET_NEXT_INDEX_FOR_SET_LEVEL_INITIAL] = 1;
    $retcheck[$MORE_THAN_REQD_CLI_OPTIONS] = 0;
    $retcheck[$VALUE_HAS_NON_DIGIT_CHARS] = 0;
    $retcheck[$ILLEGAL_CONVERSION_OPTION] = 0;
    $retcheck[$VALUE_NOT_FOUND_IN_LOCALDBASE] = 0;
    $retcheck[$INVALID_IP_ADRESS] = 0;
    $retcheck[$DEFAULT_TAG_UPDATED_ALREADY] = 1;
    $retcheck[$INVALID_MAC_ADRESS] = 0;
    $retcheck[$USERDB_SIZE_OUT_OF_RANGE] = 0;
}

# Terminate CLI traversal if the array index has 1 in it otherwise continue
sub initialize_clitermcheck
{
    $clitermcheck[$CLI_INPUT_OPTIONAL] = 1;
    $clitermcheck[$ADVANCE_TO_NEXT_DEPTH] = 0;
    $clitermcheck[$END_OF_CLI_TREE] = 0;
    $clitermcheck[$INPUT_NOT_MATCHED] = 0;
    $clitermcheck[$INVALID_CLI_OPTION] = 1;
    $clitermcheck[$CLI_JUMP_OPTION] = 1;
    $clitermcheck[$INSUFFICIENT_CLI_OPTIONS] = 1;
    $clitermcheck[$NOOP_CLI_RETURN_OPTION] = 0;
    $clitermcheck[$UPDATE_CLI_NODE] = 0;
    $clitermcheck[$NO_INSTANCE_FOUND] = 0;
    $clitermcheck[$BACKTRACK_TO_PREVIOUS_LEVEL] = 0;
    $clitermcheck[$DELETE_CURRENT_AND_BACKTRACK_TO_PREVIOUS_LEVEL] = 0;
    $clitermcheck[$DONOT_UPDATE_CLI_NODE_AND_STOP] = 0;
    $clitermcheck[$MORE_INSTANCES_PRESENT] = 0;
    $clitermcheck[$NO_MORE_INSTANCES] = 0;
    $clitermcheck[$CLI_PRINTED] = 0;
    $clitermcheck[$PARAM_UPDATE_SUCCESS] = 0;
    $clitermcheck[$STRVALMAP_NO_VALUE_FOUND] = 1;
    $clitermcheck[$STRVALMAP_NO_STRING_FOUND] = 0;
    $clitermcheck[$GET_NEXT_INDEX_FOR_SET_LEVEL] = 0;
    $clitermcheck[$TAG_FORMAT_NOT_MATCHED] = 0;
    $clitermcheck[$TAG_FORMAT_MATCHED] = 0;
    $clitermcheck[$GET_NEXT_INDEX_FOR_SET_LEVEL_INITIAL] = 0;
    $clitermcheck[$MORE_THAN_REQD_CLI_OPTIONS] = 1;
    $clitermcheck[$VALUE_HAS_NON_DIGIT_CHARS] = 1;
    $clitermcheck[$ILLEGAL_CONVERSION_OPTION] = 1;
    $clitermcheck[$VALUE_NOT_FOUND_IN_LOCALDBASE] = 1;
    $clitermcheck[$INVALID_IP_ADRESS] = 1;
    $clitermcheck[$DEFAULT_TAG_UPDATED_ALREADY] = 0;
    $clitermcheck[$INVALID_MAC_ADRESS] = 1;
    $clitermcheck[$USERDB_SIZE_OUT_OF_RANGE] = 1;
}

sub initialize_parser_action
{
    $parser_action[$local_node] = \&local_node;
    $parser_action[$pre_action] = \&pre_action;
    $parser_action[$post_action] = \&post_action;
    $parser_action[$cli_map] = \&cli_map;
    $parser_action[$keyword_string] = \&keyword_string;
    $parser_action[$value_field] = \&value_field;
    $parser_action[$action_value] = \&action_value;
    $parser_action[$action_string_value] = \&action_string_value;
    $parser_action[$action_local_node] = \&action_local_node;
    $parser_action[$action_node] = \&action_node;
    $parser_action[$reverse_action] = \&reverse_action;
    $parser_action[$action_map] = \&action_map;
    $parser_action[$keyword_string_map] = \&keyword_string_map;
    $parser_action[$action_node_arraybase] = \&action_node_arraybase;
    $parser_action[$keyword_string_with_local] = \&keyword_string_with_local;
    $parser_action[$keyword_string_special] = \&keyword_string;
    $parser_action[$keyword_string_special_with_local] = \&keyword_string_with_local;
}

sub local_node
{
    my $input = $_[0];
    my $input_present = $_[1];
    my $inpcmd = $_[2];
    my $href = $_[3];
    my $hreff = $clitoxmldb1_ptr[$clitoxmldb1_ptr_level];
    my $result = $NOOP_CLI_RETURN_OPTION;
    my $string;

    my @tmp = split(/\%/, $inpcmd);
    $$href = $tmp[1];
    
    if (!$input_present) {
        return $INSUFFICIENT_CLI_OPTIONS;
    }
    $gbl_local_node_value[$tmp[0]] = $input;

# print "local_node1 $input, $tmp[0], $clitoxmldb1_ptr_level, $clitoxmldb1_index\n";
    if (defined($$hreff{array}{$clitoxmldb1_index}{nxt})) {
        $clitoxmldb1_ptr_level += 1;
        $clitoxmldb1_ptr[$clitoxmldb1_ptr_level] = \%{$$hreff{array}{$clitoxmldb1_index}{nxt}};
        $clitoxmldb1_index = 1;
        return $ADVANCE_TO_NEXT_DEPTH;
    } else {
        return $END_OF_CLI_TREE;
    }
    return $result;
}

sub pre_action
{
    my $input = $_[0];
    my $input_present = $_[1];
    my $inpcmd = $_[2];
    my $href = $_[3];
    my $result;

#    my @tmp = split(/\./, $inpcmd, 2);
    my @tmp1 = split(/\)/, $inpcmd, 2);
    my @tmp2 = split(/\(/, $tmp1[0], 2);   
    
    $$href = $tmp1[1];

# print "pre_action $tmp2[0], $clitree_action_array[$tmp2[0]]\n";
    $result = $clitree_action_array[$tmp2[0]]($tmp2[1]);        

    if ($input_present && $result == $CLI_INPUT_OPTIONAL) {
        $clitoxmldb1_instances{instance}[$clitoxmldb1_ptr_level]{optional} = 1;
        $result = $NOOP_CLI_RETURN_OPTION;
    }
    
    return $result;
}

sub post_action
{
    my $input = $_[0];
    my $input_present = $_[1];
    my $inpcmd = $_[2];
    my $href = $_[3];
    my $result;

#    my @tmp = split(/\./, $inpcmd, 2);
    my @tmp1 = split(/\)/, $inpcmd, 2);
    my @tmp2 = split(/\(/, $tmp1[0], 2);   
    
    $$href = $tmp1[1];
# print "post_action $tmp2[0], $clitree_action_array[$tmp2[0]]\n";
    $result = $clitree_action_array[$tmp2[0]]($tmp2[1]);        

    return $result;  
}

sub reverse_action
{
    my $input = $_[0];
    my $input_present = $_[1];
    my $inpcmd = $_[2];
    my $href = $_[3];
    my $result;

#    my @tmp = split(/\./, $inpcmd, 2);
    my @tmp1 = split(/\)/, $inpcmd, 2);
    my @tmp2 = split(/\(/, $tmp1[0], 2);   
    
    $$href = $tmp1[1];

    return $NOOP_CLI_RETURN_OPTION;
#    $result = $clitree_action_array[$tmp2[0]]($tmp2[1]);        
# print "reverse_action $$href, $tmp2[0], $tmp2[1], $result, $clitoxmldb1_ptr_level\n";
}

sub value_field
{
    my $input = $_[0];
    my $input_present = $_[1];
    my $inpcmd = $_[2];
    my $href = $_[3];

#    my @tmp = split(/\./, $inpcmd, 2);
    my @tmp1 = split(/\)/, $inpcmd, 2);
    my @tmp2 = split(/\(/, $tmp1[0], 2);   
    
    $$href = $tmp1[1];

    return $NOOP_CLI_RETURN_OPTION;;
}

sub cli_map
{
    my $input = $_[0];
    my $input_present = $_[1];
    my $inpcmd = $_[2];
    my $href = $_[3];
    my $result = $NOOP_CLI_RETURN_OPTION;

    if (!defined($string_value_map[$inpcmd])) {
        print_to_console("Error: Index $inpcmd is not part of string value map in CLI $input_cli\n");
        seek(RESULTFILE,0,0);
        print RESULTFILE "Error: Index $inpcmd is not part of string value map in CLI $input_cli\r\n";
        exit;
    } else {
        $$href = $string_value_map[$inpcmd];
    }
    return $result;
}

sub action_value
{
    my $input = $_[0];
    my $input_present = $_[1];
    my $inpcmd = $_[2];
    my $href = $_[3];
    my $result = $PARAM_UPDATE_SUCCESS;

    $$href = convert_hex_to_decimal($inpcmd);
# print "action_value1 $$href\n";
    return $result;    
}

sub action_string_value
{
    my $input = $_[0];
    my $input_present = $_[1];
    my $inpcmd = $_[2];
    my $href = $_[3];
    my $result = $PARAM_UPDATE_SUCCESS;

    if (!defined($string_map[$inpcmd])) {
        print_to_console("Error: Index $inpcmd is not part of string map in CLI $input_cli\n");
        seek(RESULTFILE,0,0);
        print RESULTFILE "Error: Index $inpcmd is not part of string map in CLI $input_cli\r\n";
        exit;
    } else {
        $$href = $string_map[$inpcmd];
    }
    return $result;
}

sub action_local_node
{
    my $input = $_[0];
    my $input_present = $_[1];
    my $inpcmd = $_[2];
    my $href = $_[3];
    my $result = $PARAM_UPDATE_SUCCESS;

    $$href = $gbl_local_node_value[$inpcmd];
    return $result;    
}

sub action_map
{
    my $input = $_[0];
    my $input_present = $_[1];
    my $inpcmd = $_[2];
    my $href = $_[3];
    my $result = $PARAM_UPDATE_SUCCESS;

    if (!defined($string_value_map[$inpcmd])) {
        print_to_console("Error: Index $inpcmd is not part of string value map in CLI $input_cli\n");
        seek(RESULTFILE,0,0);
        print RESULTFILE "Error: Index $inpcmd is not part of string value map in CLI $input_cli\r\n";
        exit;
    } else {
        $$href = $string_value_map[$inpcmd];
    }
# print "action_map1 $$href, $inpcmd\n";
    return $result;
}

sub param_value_return
{
    my $input = $_[0];
    my $pparam = $_[1];
    my $result;

    my @tmp1 = split(/\./, $input, 2);

# print "param_value_return1 $tmp1[0], $input, $tmp1[1]\n";
    $result = $parser_action[$tmp1[0]]($input, 0, $tmp1[1], $pparam);
# print "param_value_return2 $tmp1[0], $input, $tmp1[1], $$pparam\n";
    return $result;
}

sub action_node
{
    my $input = $_[0];
    my $input_present = $_[1];
    my $inpcmd = $_[2];
    my $pparam = $_[3];
    my $result = $PARAM_UPDATE_SUCCESS;

    $$pparam = $inpcmd;
    return $result;
}

sub action_node_arraybase
{
    my $input = $_[0];
    my $input_present = $_[1];
    my $inpcmd = $_[2];
    my $pparam = $_[3];
    my $result = $PARAM_UPDATE_SUCCESS;

    $$pparam = $inpcmd;
    return $result;
}
sub keyword_string
{
    my $input = $_[0];
    my $input_present = $_[1];
    my $inpcmd = $_[2];
    my $href = $_[3];
    my $hreff = $clitoxmldb1_ptr[$clitoxmldb1_ptr_level];
    my $result = $NOOP_CLI_RETURN_OPTION;
    my $string;

    my @tmp = split(/\%/, $inpcmd);
    $$href = $tmp[1];
    
    $input =~ tr/[A-Z]/[a-z]/;    
#print "inpcmd $inpcmd\n";
#print "keyword_string2 $input, $input_present, $tmp[0], $tmp[1]\n";
    if (!$input_present) {
        return $INSUFFICIENT_CLI_OPTIONS;
    }
    if (defined($string_map[$tmp[0]])) {
        $string = $string_map[$tmp[0]];
    } else {
        print_to_console("Error in database for $input_cli, keyword_string_value = $tmp[0] not present\nConfig CLI:$input_command\n");
        seek(RESULTFILE,0,0);
        print RESULTFILE "Error in database for $input_cli, keyword_string_value = $tmp[0] not present\r\nConfig CLI:$input_command\r\n";
        exit;
    }
#print "keyword_string1 $input, $string, $clitoxmldb1_ptr_level, $clitoxmldb1_index\n";
    if ($input eq $string) {
        if (defined($$hreff{array}{$clitoxmldb1_index}{nxt})) {
            $clitoxmldb1_ptr_level += 1;
            $clitoxmldb1_ptr[$clitoxmldb1_ptr_level] = \%{$$hreff{array}{$clitoxmldb1_index}{nxt}};
            $clitoxmldb1_index = 1;
            return $ADVANCE_TO_NEXT_DEPTH;
        } else {
            return $END_OF_CLI_TREE;
        }
    } else {
        $clitoxmldb1_index += 1;
        return $INPUT_NOT_MATCHED;
    }
    return $result;
}

sub keyword_string_with_local
{
    my $input = $_[0];
    my $input_present = $_[1];
    my $inpcmd = $_[2];
    my $href = $_[3];
    my $hreff = $clitoxmldb1_ptr[$clitoxmldb1_ptr_level];
    my $result = $NOOP_CLI_RETURN_OPTION;
    my $val;
    my $cmd;

    my @temp = split(/\%/, $inpcmd);
    $$href = $temp[1];
    my @tmp = split(/\./, $temp[0]);
    
    if (!$input_present) {
        return $INSUFFICIENT_CLI_OPTIONS;
    }
# print "keyword_string_with_local2 $input, $input_present, $tmp[0], $tmp[1]\n";
    if (defined($string_map[$tmp[0]])) {
        $string = $string_map[$tmp[0]];
    } else {
        print_to_console("Error in database for $input_cli, keyword_string_value = $tmp[0] not present\nConfig CLI:$input_command\n");
        seek(RESULTFILE,0,0);
        print RESULTFILE "Error in database for $input_cli, keyword_string_value = $tmp[0] not present\r\nConfig CLI:$input_command\r\n";
        exit;
    }
# print "keyword_string_with_local1 $input, $string, $clitoxmldb1_ptr_level, $clitoxmldb1_index\n";
    if ($input eq $string) {
# print "keyword_string_with_local3 $input, $tmp[0], $val\n";
        $result = $parser_action[$tmp[1]]($input, $input_present, $tmp[2], \$cmd);
        return $result;
    } else {
        $clitoxmldb1_index += 1;
        return $INPUT_NOT_MATCHED;
    }
    return $result;
}

sub keyword_string_map
{
    my $input = $_[0];
    my $input_present = $_[1];
    my $inpcmd = $_[2];
    my $href = $_[3];
    my $hreff = $clitoxmldb1_ptr[$clitoxmldb1_ptr_level];
    my $result = $NOOP_CLI_RETURN_OPTION;
    my $val;
    my $cmd;
    my $mapstr;

    my @temp = split(/\%/, $inpcmd);
    $$href = $temp[1];
    my @tmp = split(/\./, $temp[0]);
    $input =~ tr/[A-Z]/[a-z]/;    
    
    $input =~ tr/[A-Z]/[a-z]/;    
#print "keyword_string_map3 $input, $input_present, $inpcmd, $tmp[0]\n";
    if (!$input_present) {
        return $INSUFFICIENT_CLI_OPTIONS;
    }
    if (!defined($string_value_map[$tmp[0]])) {
        print_to_console("Error: No map defined for $tmp[0]\nConfig CLI:$input_command\n");
        seek(RESULTFILE,0,0);
        print RESULTFILE "Error: No map defined for $tmp[0]\r\nConfig CLI:$input_command\r\n";
        exit;
    }
    $mapstr = $string_value_map[$tmp[0]];
    if (get_value_from_string($mapstr, $input, \$val) == $PARAM_UPDATE_SUCCESS) {
# print "keyword_string_map1 $input, $tmp[0], $val\n";
        $result = $parser_action[$tmp[1]]($input, $input_present, $tmp[2], \$cmd);
    } else {
# print "keyword_string_map2 $input, $tmp[0], $clitoxmldb1_index\n";
        $clitoxmldb1_index += 1;
        return $INPUT_NOT_MATCHED;
    }
    return $result;
}

sub param_local_index_return
{
    my $input = $_[0];

    my @tmp1 = split(/\./, $input, 2);

    if ($tmp1[0] == $action_local_node || $tmp1[0] == $local_node) {
        return $tmp1[1];
    } else {
        print_to_console("Error in database local node index for non local node\nConfig CLI:$input_command\n");
        seek(RESULTFILE,0,0);
        print RESULTFILE "Error in database local node index for non local node\r\nConfig CLI:$input_command\r\n";
        exit;
    }
}

sub database1_read
{
    my $input = $_[0];
    my $href;
    my $hreff;

    my ($tmp1, $tmp2) = split(/\t/, $input);
    my @temp = split(/\./, $tmp1);

    $href = \%clitoxmldb1;
# print "database1_read1 $tmp1, $tmp2, $href\n";
    for (my $i = 0; $i <= $#temp; $i++) {
        if (!defined($$href{cnt})) {
            $$href{cnt} = 0;
        }
        if (!defined($$href{array}{$temp[$i]})) {
            $$href{cnt} += 1;
        }
        if ($i == $#temp) {
            $$href{array}{$temp[$i]}{cur} = $tmp2;
        } else {
            $href = \%{$$href{array}{$temp[$i]}{nxt}};
        }
    }
}

sub database1_execute
{
    my $input = $_[0];
    my $input_present = $_[1];
    my $href = $clitoxmldb1_ptr[$clitoxmldb1_ptr_level];
    my $cmd;
    my @tmp1;
    my $result = $NOOP_CLI_RETURN_OPTION;
    my $prevresult = $NOOP_CLI_RETURN_OPTION;

# print "database1_execute1 $clitoxmldb1_ptr_level, $clitoxmldb1_index, $href\n";
    if (!defined($$href{array}) || !defined($$href{array}{$clitoxmldb1_index})) {
        return $INVALID_CLI_OPTION;
    }

    if (!defined($$href{array}{$clitoxmldb1_index}{cur})) {
        print_to_console("Error in database, no cur option for $input_cli\n");
        seek(RESULTFILE,0,0);
        print RESULTFILE "Error in database, no cur option for $input_cli\r\n";
        exit;
    }


    $cmd = $$href{array}{$clitoxmldb1_index}{cur};

    @tmp1 = split(/\./, $cmd, 2);
 
#print "database1_execute2 $cmd, @tmp1\n";
    while ($retcheck[$result] && defined($tmp1[0])) {
#print "database1_execute in while loop parser_action[$tmp1[0]] ...$input, $input_present, $tmp1[1], \$cmd \n";

        $result = $parser_action[$tmp1[0]]($input, $input_present, $tmp1[1], \$cmd);
#print "database1_execute result in while loop $result\n";
        @tmp1 = split(/\./, $cmd, 2);
        if ($result == $END_OF_CLI_TREE || $result == $ADVANCE_TO_NEXT_DEPTH || $result == $CLI_INPUT_OPTIONAL) {
            $prevresult = $result;
        }
    }
#print "database1_execute3 $cmd, @tmp1, $result, $prevresult\n";
    if (!$clitermcheck[$result]) {
        if ($prevresult != $NOOP_CLI_RETURN_OPTION) {
            return $prevresult;
        }
    }
    return $result;
}

sub check_for_clitree_database
{
    my $line = $_[0];
    my $result = $NOOP_CLI_RETURN_OPTION;
    my $cnt_for_quote = 0;
    my $cnt_for_space = 0;
    my @temp;
    my @temp1=split(/\"/,$line);
    while($cnt_for_quote <= $#temp1) {
        if(($cnt_for_quote % 2)==0) {
            $temp1[$cnt_for_quote] =~ s/^[ |\t]+//g;
            my @temp2 = split(/ /,$temp1[$cnt_for_quote]);
            for (my $cnt = 0; $cnt <= $#temp2; $cnt++) {
                $temp[$cnt_for_space] = $temp2[$cnt];
                $cnt_for_space += 1;
            }
        } else {
            $temp[$cnt_for_space] = $temp1[$cnt_for_quote];
            $cnt_for_space += 1;
        }
        $cnt_for_quote += 1;
#print "temp3 = $temp3[0],$temp3[1],$temp3[2],$temp3[3],$temp3[4],temp = $temp[0],$temp[1],$temp[2],$temp[3],$temp[4]\n";
    }
    #my @temp=split(/ /,$line);

    $clitoxmldb1_ptr_level = 0;
    $clitoxmldb1_index = 1;
    $clitoxmldb1_ptr[$clitoxmldb1_ptr_level] = \%clitoxmldb1;
    for (my $i = 0; $i <= $#temp; $i++) {
        $result =  $NOOP_CLI_RETURN_OPTION;
        while ($result != $END_OF_CLI_TREE && $result != $ADVANCE_TO_NEXT_DEPTH) {
            $result = database1_execute($temp[$i], 1);
#print "check_for_clitree_database1 $temp[$i], $result, $clitermcheck[$result] \n";
            if ($clitermcheck[$result]) {
#print "check_for_clitree_database2 $temp[$i], $result \n";
                $ignored_cli{cli} = $line;
                $ignored_cli{param} = $i;
                $ignored_cli{reason} = $result;
                delete_local_dbase();
                return 0;
            }
            if ($result == $NOOP_CLI_RETURN_OPTION) {
                $result = $ADVANCE_TO_NEXT_DEPTH;
            }
        }
        if ($result == $END_OF_CLI_TREE && $i < $#temp) {
            $result = $MORE_THAN_REQD_CLI_OPTIONS;
            $ignored_cli{cli} = $line;
            $ignored_cli{param} = $i;
            $ignored_cli{reason} = $result;
            delete_local_dbase();
            return 0;
        }
#print "check_for_clitree_database7 $result\n";
    }
    if ($result == $ADVANCE_TO_NEXT_DEPTH) {
        $result = database1_execute("  ", 0);
    }
#print "check_for_clitree_database3 $result\n";
    if ($result == $END_OF_CLI_TREE || $result == $CLI_INPUT_OPTIONAL) {
        $result = update_xml_dbase_with_localdb(1);
        delete_local_dbase();
#print "check_for_clitree_database5 $result\n";
        if ($result != $NOOP_CLI_RETURN_OPTION) {
            $ignored_cli{cli} = $line;
            $ignored_cli{param} = $i;
            $ignored_cli{reason} = $result;
            return 0;        
        } else {
            return 1;
        }
    } elsif ($result == $ADVANCE_TO_NEXT_DEPTH || $result == $NOOP_CLI_RETURN_OPTION) {
        $result = $INSUFFICIENT_CLI_OPTIONS;
#print "check_for_clitree_database6 $result\n";
    }
    $ignored_cli{cli} = $line;
    $ignored_cli{position} = $#temp + 1;
    $ignored_cli{reason} = $result;
    delete_local_dbase();
#print "check_for_clitree_database4 $result\n";
    return 0;
}

sub xmlfilename_read
{
    my $input = $_[0];
    my @tmp = split(/\t/, $input, 2);
    $xml_dbase_filename{$tmp[0]} = $tmp[1];
}

sub strmap_read
{
    my $input = $_[0];
    my @tmp = split(/\t/, $input, 2);
    $string_map[$tmp[0]] = $tmp[1];
}

sub strvalmap_read
{
    my $input = $_[0];
    my @tmp = split(/\t/, $input, 2);
    $string_value_map[$tmp[0]] = $tmp[1];
}

sub fldarraydbase_read
{
    my $input = $_[0];
    my @tmp = split(/\t/, $input, 2);
    my @temp = split(/\./, $tmp[0]);
    my $href = \%fldarraydbase_hash;
    
    for (my $i = 0; $i <= $#temp; $i++) {
        $href = \%{$$href{nxt}{$temp[$i]}};
    }
    $$href{array} = $tmp[1];
}

sub fldfrmtdbase_read
{
    my $input = $_[0];
    my @tmp = split(/\t/, $input, 3);
    my @temp = split(/\./, $tmp[0]);
    my $href = \%fldfrmtdbase_hash;
    
    for (my $i = 0; $i <= $#temp; $i++) {
        $href = \%{$$href{nxt}{$temp[$i]}};
    }
    $$href{$xml_format} = $tmp[1];
    $$href{$cli_format} = $tmp[2];
}

sub initialize_cli2xml_maps
{
    open(DB5,"$newdb5") or die "Can't open XML filename database File:$!";
    open(DB10,"$newdb10") or die "Can't open action name database File:$!";
    open(DB12,"$cli2xmldb1") or die "Can't open cli to tag database File:$!";
    open(DB13,"$strmap") or die "Can't open string map database File:$!";
    open(DB14,"$strvalmap") or die "Can't open string value map database File:$!";
    open(DB15,"$fldarraydbase") or die "Can't open string value map database File:$!";
    open(DB16,"$fldfrmtdbase") or die "Can't open format map database File:$!";
    open(CLIFILE, "+>", "$clifile") or die "Can't open File:$!";

# print "Initializaton started\n";
    for $line(<DB10>){
#This database contains number to action name mapping.
        chomp $line;
        @line=split('\t',$line,2);
        $clitree_action_array[$line[0]] = \&{$line[1]};
# print "DB10 $line[0], $line[1]\n";
    }

    for $line(<DB5>){
        chomp $line;
        xmlfilename_read($line);
    }
    for $line(<DB12>){
        chomp $line;
        database1_read($line);
    }
    for $line(<DB13>){
        chomp $line;
        strmap_read($line);
    }
    for $line(<DB14>){
        chomp $line;
        strvalmap_read($line);
    }
    for $line(<DB15>){
        chomp $line;
        fldarraydbase_read($line);
    }
    for $line(<DB16>){
        chomp $line;
        fldfrmtdbase_read($line);
    }

    initialize_retcheck();
    initialize_clitermcheck();
    initialize_parser_action();
    if(!close(DB10) || !close(DB12) || !close(DB13) || !close(DB14) || !close(DB15) || !close(DB16))
    {
       remove_xml_files();
      die "Error: File System is out of Disk Space.:$!";
    }
}

sub get_value_from_string
{
    my $map = $_[0];
    my $string = $_[1];
    my $pval = $_[2];
    my $mapstr;

    my @temp = split(/\t/, $map);
    for (my $i = 0; $i <= $#temp; $i++) {
        (my $t1, my $t2) = split(/=/, $temp[$i]);
# print "get_value_from_string1 $t1, $string, $map, $mapstr\n";
        if ($t1 eq $string) {
            $$pval = $t2;
            return $PARAM_UPDATE_SUCCESS;
        }
    }
    return $STRVALMAP_NO_STRING_FOUND;
}

sub get_string_from_value
{
    my $map = $_[0];
    my $value = $_[1];
    my $pstr = $_[2];
    my $mapstr;
    
    my @temp = split(/\t/, $map);
    for (my $i = 0; $i <= $#temp; $i++) {
        (my $t1, my $t2) = split(/=/, $temp[$i]);
        if ($t2 eq $value) {
            $$pstr = $t1;
            return $PARAM_UPDATE_SUCCESS;
        }
    }
    return $STRVALMAP_NO_VALUE_FOUND;
}

sub convert_hex_to_decimal
{
    my ($str) = @_;
    my $decimal = 0;
    my @temp1 = split(//, $str);
    if ($str =~ /x/) {
       ($hex_header, $str) = split('x', $str);
        for (my $i = 0; $i <= $#temp1; $i++) {
            if ($temp1[$i] eq 'a' || $temp1[$i] eq 'A') {
                $temp1[$i] = 10;
            } elsif ($temp1[$i] eq 'b' || $temp1[$i] eq 'B') {
                $temp1[$i] = 11;
            } elsif ($temp1[$i] eq 'c' || $temp1[$i] eq 'C') {
                $temp1[$i] = 12;
            } elsif ($temp1[$i] eq 'd' || $temp1[$i] eq 'D') {
                $temp1[$i] = 13;
            } elsif ($temp1[$i] eq 'e' || $temp1[$i] eq 'E') {
                $temp1[$i] = 14;
            } elsif ($temp1[$i] eq 'f' || $temp1[$i] eq 'F') {
                $temp1[$i] = 15;
            }
            $decimal = $decimal * 16 + $temp1[$i];
        }
    } else {
        $decimal = $str;
    }
    return($decimal);
}


sub optional_input
{
    return $CLI_INPUT_OPTIONAL;
}

sub optional_input_mobility
{
    if ($make_next_node_mandatory == 1){
        $make_next_node_mandatory = 0;
        return $ADVANCE_TO_NEXT_DEPTH;
    } else {
        return $CLI_INPUT_OPTIONAL;
    }
}
# Map for wlan Anchor map. This function maps set bit wlan anchor map to WLAN ID
sub update_bitarray_field
{
    my $input = $_[0];
    my $result = $NOOP_CLI_RETURN_OPTION;
    my $actfld;
    my $actval;
    my $actsetreset;
    my $fld;
    my $val;
    my $dim;
    my $index;
    my $rem;
    my $setreset;

    my @temp = split(/\,/, $input);
    
# print "update_bitarray_field $input\n";

    $actfld = $temp[0];
    $actval = $temp[1];
    $actsetreset = $temp[2];

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
# print "update_bitarray_field1 $input, $result\n";
        return $result;
    }

# print "update_bitarray_field7 $fld, $actfld\n";
    $result = check_and_get_array_dbase_level($fld, $useasis_input_index, \$dim);
    if ($result != $PARAM_UPDATE_SUCCESS) {
# print "update_bitarray_field2 $input, $result\n";
        return $result;
    }

    $result = param_value_return($actval, \$val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
# print "update_bitarray_field3 $input, $result\n";
        return $result;
    }
    $result = check_for_digits($val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
# print "update_bitarray_field4 $input, $result\n";
        return $result;
    }
    $rem = $val % 32;
    $index = ($val - $rem) / 32;
    $bitval = 1 << ($rem - 1);
# print "update_bitarray_field5 $input, $result, $fld, $dim, $val\n";

    $array_index{index}[$dim] = $index;
    $array_index{flag}[$dim] = $xml_dbase_index_update_reqd;
# print "update_bitarray_field6 $val, $dim, $index\n";

    $result = param_value_return($actsetreset, \$setreset);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    if (get_value_from_xml_dbase($fld, \$val)) {
        if ($setreset) {
            $val |= $bitval;
        } else {
            $val  &= (~$bitval);
        }
    } else {
        if ($setreset) {
            $val = $bitval;
        } else {
            $val  = 0;
        }
    }

#print "update_bitarray_field7 $fld, $val, $dim, $index\n";
    update_local_dbase($fld, $val);
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;    
    
}
sub update_bitarray_field_wlanAnchorMap
{
    my $input = $_[0];
    my $result = $NOOP_CLI_RETURN_OPTION;
    my $actfld;
    my $actval;
    my $actsetreset;
    my $fld;
    my $val;
    my $dim;
    my $index;
    my $rem;
    my $setreset;

    my @temp = split(/\,/, $input);
    
# print "update_bitarray_field_wlanAnchorMap $input\n";

    $actfld = $temp[0];
    $actval = $temp[1];
    $actsetreset = $temp[2];

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
# print "update_bitarray_field1 $input, $result\n";
        return $result;
    }

# print "update_bitarray_field7 $fld, $actfld\n";
    $result = check_and_get_array_dbase_level($fld, $useasis_input_index, \$dim);
    if ($result != $PARAM_UPDATE_SUCCESS) {
# print "update_bitarray_field2 $input, $result\n";
        return $result;
    }

    $result = param_value_return($actval, \$val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
# print "update_bitarray_field3 $input, $result\n";
        return $result;
    }
    $result = check_for_digits($val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
# print "update_bitarray_field4 $input, $result\n";
        return $result;
    }
    $rem = $val % 32;
    $index = ($val - $rem) / 32;
    $bitval = 1 << ($rem - 1);
    if ($index != 0) {
       return $NOOP_CLI_RETURN_OPTION;
    }
# print "update_bitarray_field5 $input, $result, $fld, $dim, $val\n";

    $array_index{index}[$dim] = $index;
    $array_index{flag}[$dim] = $xml_dbase_index_update_reqd;
# print "update_bitarray_field6 $val, $dim, $index\n";

    $result = param_value_return($actsetreset, \$setreset);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    if (get_value_from_xml_dbase($fld, \$val)) {
        if ($setreset) {
            $val |= $bitval;
        } else {
            $val  &= (~$bitval);
        }
    } else {
        if ($setreset) {
            $val = $bitval;
        } else {
            $val  = 0;
        }
    }

#print "update_bitarray_field7 $fld, $val, $dim, $index\n";
    update_local_dbase($fld, $val);
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;    
    
}

sub update_bit_field
{
    my $input = $_[0];
    my $result;
    my $fld,
    my $bitval;
    my $setreset;
    my $val;

    my ($actfld, $actval, $actsetreset) = split(/\,/, $input, 3);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval, \$bitval);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actsetreset, \$setreset);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    if (get_value_from_xml_dbase($fld, \$val)) {
        if ($setreset) {
            $val |= $bitval;
        } else {
            $val  &= (~$bitval);
        }
    } else {
        if ($setreset) {
            $val = $bitval;
        } else {
            $val  = 0;
        }
    }

    update_local_dbase($fld, $val);

    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}

sub update_bit_field_with_setreset_map
{
    my $input = $_[0];
    my $result;
    my $fld,
    my $bitval;
    my $setreset;
    my $map;
    my $val;
    my $str;

    my ($actfld, $actval, $actsetreset, $actmap) = split(/\,/, $input, 4);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval, \$bitval);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actsetreset, \$setreset);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actmap, \$map);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $str = $setreset;
    $result = get_value_from_string($map, $str, \$setreset);
# print "update_field_with_map1 $result\n";
    if ($result != $PARAM_UPDATE_SUCCESS) {
        $clitoxmldb1_index += 1;
        return $result;
    }

    if (get_value_from_xml_dbase($fld, \$val)) {
        if ($setreset) {
            $val |= $bitval;
        } else {
            $val  &= (~$bitval);
        }
    } else {
        if ($setreset) {
            $val = $bitval;
        } else {
            $val  = 0;
        }
    }

    update_local_dbase($fld, $val);

    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}

sub update_bit_field_with_disable_map
{
    my $input = $_[0];
    my $result;
    my $fld,
    my $bitval;
    my $setreset;
    my $map;
    my $val;
    my $str;

    my ($actfld, $actval, $actsetreset, $actmap) = split(/\,/, $input, 4);
    
    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval, \$bitval);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actsetreset, \$setreset);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actmap, \$map);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $str = $setreset;
    $result = get_value_from_string($map, $str, \$setreset);
# print "update_field_with_map1 $result\n";
    if ($result != $PARAM_UPDATE_SUCCESS) {
        $clitoxmldb1_index += 1;
        return ($result);
    }

    if (get_value_from_xml_dbase($fld, \$val)) {
        if(! $val) {
# Added to make sure that always all the bits are set at the beginning
            $val = 0xFF;
        }

        if ($setreset) {
            $val |= $bitval;
        } else {
            $val  &= (~$bitval);
        }
    } else {
        $val = 0xFF;
        if ($setreset) {
            $val = $bitval;
        } else {
            $val &= (~$bitval);
        }
    }
    update_local_dbase($fld, $val);

    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}

sub update_bit_field_with_shift_and_setreset_map
{
    my $input = $_[0];
    my $result;
    my $fld,
    my $bitval;
    my $setreset;
    my $map;
    my $val;
    my $str;

    my ($actfld, $actval, $actsetreset, $actmap) = split(/\,/, $input, 4);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval, \$bitval);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actsetreset, \$setreset);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actmap, \$map);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $bitval = 1 << $bitval;
    $str = $setreset;
    $result = get_value_from_string($map, $str, \$setreset);
#print "update_bit_field_with_shift_and_setreset_map $result fld $fld bitval $bitval setrst $str--- $setreset map $map \n";
    if ($result != $PARAM_UPDATE_SUCCESS) {
        $clitoxmldb1_index += 1;
        return $result;
    }

    if (get_value_from_xml_dbase($fld, \$val)) {
        if ($setreset) {
            $val |= $bitval;
        } else {
            $val  &= (~$bitval);
        }
    } else {
        if ($setreset) {
            $val = $bitval;
        } else {
            $val  = 0;
        }
    }

#print "update_local_dbase($fld, $val)map \n";
    update_local_dbase($fld, $val);

    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}

sub update_bit_field_with_value_setreset_map
{
    my $input = $_[0];
    my $result;
    my $fld,
    my $bitval;
    my $setreset;
    my $map;
    my $valmap;
    my $val;
    my $str;

    my ($actfld, $actval, $actvalmap, $actsetreset, $actmap) = split(/\,/, $input, 5);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval, \$bitval);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actvalmap, \$valmap);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actsetreset, \$setreset);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actmap, \$map);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $str = $bitval;
    $result = get_value_from_string($valmap, $str, \$bitval);
# print "update_field_with_map1 $result\n";
    if ($result != $PARAM_UPDATE_SUCCESS) {
        $clitoxmldb1_index += 1;
        return $result;
    }

    $str = $setreset;
    $result = get_value_from_string($map, $str, \$setreset);
# print "update_field_with_map1 $result\n";
    if ($result != $PARAM_UPDATE_SUCCESS) {
        $clitoxmldb1_index += 1;
        return $result;
    }

    if (get_value_from_xml_dbase($fld, \$val)) {
        if ($setreset) {
            $val |= $bitval;
        } else {
            $val  &= (~$bitval);
        }
    } else {
        if ($setreset) {
            $val = $bitval;
        } else {
            $val  = 0;
        }
    }

    update_local_dbase($fld, $val);

    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}

sub update_field_conditional
{
    my $input = $_[0];
    my $result;
    my $fld,
    my $val;

    my ($actfld, $actval, $actval1, $actval2) = split(/\,/, $input, 4);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval, \$val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval1, \$val1);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval2, \$val2);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    if ($val1 eq $val2) {
        update_local_dbase($fld, $val);
    }
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}

sub update_format_for_field
{
    my $input = $_[0];
    my $result;
    my $fld,
    my $val;
    my $href = \%fldfrmtdbase_hash;

    my ($actfld, $actval) = split(/\,/, $input, 2);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval, \$val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
#print "update_format_for_field $fld $val\n";

    my @temp = split(/\./, $fld);
    for (my $i = 0; $i <= $#temp; $i++) {
        $href = \%{$$href{nxt}{$temp[$i]}};
    }
    $$href{$cli_format} = $hash7{$val};

    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}

# Custom function, to handle updating ip-address and mask fields for flexconnect 
# acl source/destination rules
#
# "config flexconnect acl rule source address <acl_name> <index> <ip-addr> <mask>"
# "config flexconnect acl rule destination address <acl_name> <index> <ip-addr> <mask>"
#
# The <ip-addr> and <mask> fields can be in either unsigned int or dotted decimal format.
# The appropriate handler is assigned based on the format of the ip-address present in
# the cli command
sub update_field_flxacl_srcdst_uint_to_ipv4ddr 
{
    my $input = $_[0];
    my $result;
    my $fld,
    my $val;
    my $href = \%fldfrmtdbase_hash;

    my ($actfld, $actval) = split(/\,/, $input, 2);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval, \$val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

#print "update_format_for_field $fld $val\n";

    my @temp = split(/\./, $fld);
    for (my $i = 0; $i <= $#temp; $i++) {
        $href = \%{$$href{nxt}{$temp[$i]}};
    }

    if($val =~ m/\./) {
      $$href{$cli_format} = $hash7{"IPv4addr_TYPE"};
    }else {
      $$href{$cli_format} = $hash7{"unsignedInt_TYPE"};
    }

    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;

}
sub update_field_with_index
{
    my $input = $_[0];
    my $result = $NOOP_CLI_RETURN_OPTION;
    my $fld;
    my $level=0;
    my $actfld;
    my $actindexfld;
    my $indexfld;
    my $xmlref = \%digit_to_tag_actual;
    my $indexval;

    my ($actfld, $actindexfld) = split(/\,/, $input, 2);
    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actindexfld, \$indexfld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    my @temp = split(/\./, $indexfld);
    for (my $i = 0; $i <= $#temp; $i++) {
        if (defined($$xmlref{nxt}{$temp[$i]})) {
            $xmlref = \%{$$xmlref{nxt}{$temp[$i]}};
            if (defined($$xmlref{instance})) {
                $xmlref = \%{$$xmlref{instance}{$array_index{index}[$level]}};
                $level += 1;
            }
        }
    }
    if($level > 0) {
        $indexval =  $array_index{index}[$level-1]; 
    } else {
        return $result;
    }
#print "update_field_with_index $level, $array_index{index}[$level-1], $indexfld\n";
    update_local_dbase($fld, $indexval);
    return $result;
}

sub update_field
{
    my $input = $_[0];
    my $result;
    my $fld,
    my $val;

    my ($actfld, $actval) = split(/\,/, $input, 2);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval, \$val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

#print "update_field1 $fld, $val\n";
    update_local_dbase($fld, $val);
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}


# This function is specifically used to update a decimal value when a keyword string
# is present.
# For example,"config ipv6 neighbor-binding max-through <0-256> or <no-limit".
# Since a decimal value and keyword is treated at same level, if the Key word
# "no-limit" is present, then the corresponding integer value is to be updated.

sub update_field_with_exception
{
    my $input = $_[0];
    my $result;
    my $fld,
    my $val;

    my ($actfld, $actval) = split(/\,/, $input, 2);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
    	return $result;
	}

	$result = param_value_return($actval, \$val);
	if ($result != $PARAM_UPDATE_SUCCESS) {
		return $result;
	}
 
	if ($val eq "no-limit")
	{
		$val = 4294967295;
	}
	if ($val == -1)
	{
	   return $INVALID_CLI_OPTION;
	}

	update_local_dbase($fld, $val);
	$result = $NOOP_CLI_RETURN_OPTION;
	
    return $result;
}
																		

#This function is used to update the string with a check for null string. If null string is present, 
#none is uploaded instead
sub update_field_with_none_str_default
{
    my $input = $_[0];
    my $result;
    my $fld,
    my $val;
    my $nonevar = "none";

    my ($actfld, $actval) = split(/\,/, $input, 2);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    
    $result = param_value_return($actval, \$val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    if($val eq "none") {
        $val = "";
    }
        
#print "update_field1 $fld, $val\n";
    update_local_dbase($fld, $val);
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}

# This function is used to update the field if value is non-zero.
# In case where value is 0, we ignore the CLI.
sub update_field_with_zero_exception
{
    my $input = $_[0];
    my $result;
    my $fld,
    my $val;

    my ($actfld, $actval) = split(/\,/, $input, 2);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
    	return $result;
	}

	$result = param_value_return($actval, \$val);
	if ($result != $PARAM_UPDATE_SUCCESS) {
		return $result;
	}
 
	if ($val == 0)
	{
#print"update_field_with_zero_exception: Ignore\n";
	   return $INVALID_CLI_OPTION;
	}

#print"update_field_with_zero_exception: fld: $fld, val: $val\n";
	update_local_dbase($fld, $val);
	$result = $NOOP_CLI_RETURN_OPTION;
	
    return $result;
}

sub update_bit_field_default
{
    my $input = $_[0];
    my $result;
    my $fld,
    my $bitval;
    my $setreset;
    my $val;
    my $val1;

    my ($actfld, $actval, $actsetreset) = split(/\,/, $input, 3);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval, \$bitval);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actsetreset, \$setreset);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    if (get_value_from_xml_dbase($fld, \$val)) {
        if ($setreset) {
            $val |= $bitval;
        } else {
            $val  &= (~$bitval);
        }
    } else {
        if ($setreset) {
            $val = $bitval;
        } else {
            $val  = 0;
        }
    }

    if (!get_value_from_xml_dbase($fld, \$val1)) {
        update_local_dbase($fld, $val);
        $result = $NOOP_CLI_RETURN_OPTION;
    } else {
        $result = $DEFAULT_TAG_UPDATED_ALREADY;
    }
    return $result;
}

sub update_field_default
{
    my $input = $_[0];
    my $xmlref = \%digit_to_tag_actual;
    my $result;
    my $fld,
    my $val;
    my $val1;

    my ($actfld, $actval) = split(/\,/, $input, 2);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval, \$val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    if (!get_value_from_xml_dbase($fld, \$val1)) {
         update_local_dbase($fld, $val);
         $result = $NOOP_CLI_RETURN_OPTION;
    } else {
          $result = $DEFAULT_TAG_UPDATED_ALREADY;
    }
    return $result;
}


sub update_field_with_map
{
    my $input = $_[0];
    my $result;
    my $actfld,
    my $actval;
    my $actmap;
    my $fld,
    my $val;
    my $map;
    my $str;

    my ($actfld, $actval, $actmap) = split(/\,/, $input, 3);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval, \$val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actmap, \$map);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $str = $val;
    $result = get_value_from_string($map, $str, \$val);
# print "update_field_with_map1 $map, $str, $val, $fld, $result\n";
    if ($result != $PARAM_UPDATE_SUCCESS) {
        $clitoxmldb1_index += 1;
        return $result;
    }

    update_local_dbase($fld, $val);
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}

################################################
#Used to induct values in the next two fields  #
#with $idx being the first index You want to   #
#update and $val, value of the field           #
################################################
sub update_next_two_fields
{
	
	my $input = $_[0];
	my $actfld;
	my $actidx;
	my $actlvl;
	my $actval;
	my $fld;
	my $idx;
	my $lvl;
	my $val;

    my ($actfld, $actidx, $actlvl,$actval) = split(/\,/, $input, 4);

    $result = param_value_return($actfld, \$fld);
#print "Two fields2, $fld, $idx, $lvl,$val, $result\n";
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actidx, \$idx);
#print "Two fields3, $fld, $idx, $lvl,$val, $result\n";
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actlvl, \$lvl);
#print "Two fields4, $fld, $idx, $lvl,$val, $result\n";
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actval, \$val);
#print "Two fields5, $fld, $idx, $lvl,$val, $result\n";
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
	$array_index{index}[$lvl]=$idx;
	update_local_dbase($fld, $val);
	flush_local_dbase();
#print "Two fields, $fld, $idx, $lvl,$val\n";
	$array_index{index}[$lvl]=$idx+1;
	update_local_dbase($fld, $val);
	$result=flush_local_dbase();
	
#print "Two fields1, $fld, $idx, $lvl,$val\n";
#print "$level $index";
	return $result;
}

sub update_text_passwd_v1
{
    my $input = $_[0];
    my $actfld_ps_type;
    my $actfld_iv;
    my $actfld_mac;
    my $actfld_passwd_len;
    my $actfld_passwd;
    my $actfld_ps_type_v1;
    my $actfld_iv_v1;
    my $actfld_mac_v1;
    my $actfld_passwd_len_v1;
    my $actfld_passwd_v1;
    my $actpasswd;
    my $fld_ps_type;
    my $fld_iv;
    my $fld_mac;
    my $fld_passwd_len;
    my $fld_passwd;
    my $fld_ps_type_v1;
    my $fld_iv_v1;
    my $fld_mac_v1;
    my $fld_passwd_len_v1;
    my $fld_passwd_v1;
    my $passwd;
    my $passwd_v1;
    my $result;

    my $str;
    my $strLength;
    my $fld_actpasswd;
    my @temp = split(/\,/, $input);

    $actfld_ps_type = $temp[0];
    $actfld_iv = $temp[1];
    $actfld_mac = $temp[2];
    $actfld_passwd_len = $temp[3];
    $actfld_passwd = $temp[4];
    $actfld_ps_type_v1 = $temp[5];
    $actfld_iv_v1 = $temp[6];
    $actfld_mac_v1 = $temp[7];
    $actfld_passwd_len_v1 = $temp[8];
    $actfld_passwd_v1 = $temp[9];
    $actpasswd = $temp[10];

    
    $result = param_value_return($actpasswd, \$fld_actpasswd);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $str  = $fld_actpasswd;
    $str  =~ s/([a-fA-F0-9]{2})/chr(hex $1)/eg;

    $strLength = length($str);
    #print "str:$str, len:$strLength\n";

   
#    print "update_text_passwd  $actfld_ps_type_v1, $actfld_iv_v1, $actfld_mac_v1, $actfld_passwd_len_v1, $actpasswd\n";
    $result = param_value_return($actfld_ps_type_v1, \$fld_ps_type_v1);
#    print "update_text_passwd  $actfld_ps_type_v1, $fld_ps_type_v1\n";
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actfld_iv_v1, \$fld_iv_v1);
#    print "update_text_passwd  $actfld_iv_v1, $fld_iv_v1\n";
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actfld_mac_v1, \$fld_mac_v1);
#    print "update_text_passwd $actfld_mac_v1, $fld_mac_v1\n";
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actfld_passwd_len_v1, \$fld_passwd_len_v1);
#    print "update_text_passwd $actfld_passwd_len_v1, $fld_passwd_len_v1\n";
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actfld_passwd_v1, \$fld_passwd_v1);
#    print "update_text_passwd $actfld_passwd_v1, $fld_passwd_v1\n";
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actpasswd, \$passwd);
#    print "update_text_passwd $act_passwd, $passwd, $result\n";
    if ($result != $PARAM_UPDATE_SUCCESS) {
        #print "ERROR SATD $act_passwd, $passwd, $result\n";
        return $result;
    }

#    print "15 - passwd:$passwd\n";
    $local_passwd_len = length($passwd);
    $local_passwd_len = $local_passwd_len/2;
    $result = check_for_digits($local_passwd_len);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
#    print "16 - passwd:$passwd\n";
    update_local_dbase($fld_ps_type_v1, $PS_NULL);
    update_local_dbase($fld_iv_v1, 0);
    update_local_dbase($fld_mac_v1, 0);
    update_local_dbase($fld_passwd_len_v1, $local_passwd_len);
    update_local_dbase($fld_passwd_v1, $passwd);

    if ($strLength <= 24) {
#        print "update_text_passwd $actfld_ps_type, $actfld_iv, $actfld_mac, $actfld_passwd_len, $actpasswd\n";
        $result = param_value_return($actfld_ps_type, \$fld_ps_type);
#        print "update_text_passwd $actfld_ps_type, $fld_ps_type\n";
        if ($result != $PARAM_UPDATE_SUCCESS) {
            return $result;
        }
        $result = param_value_return($actfld_iv, \$fld_iv);
#        print "update_text_passwd $actfld_iv, $fld_iv\n";
        if ($result != $PARAM_UPDATE_SUCCESS) {
            return $result;
        }
        $result = param_value_return($actfld_mac, \$fld_mac);
#        print "update_text_passwd $actfld_mac, $fld_mac\n";
        if ($result != $PARAM_UPDATE_SUCCESS) {
            return $result;
        }
        $result = param_value_return($actfld_passwd_len, \$fld_passwd_len);
#        print "update_text_passwd $actfld_passwd_len, $fld_passwd_len\n";
        if ($result != $PARAM_UPDATE_SUCCESS) {
            return $result;
        }
        $result = param_value_return($actfld_passwd, \$fld_passwd);
#        print "update_text_passwd $actfld_passwd, $fld_passwd\n";
        if ($result != $PARAM_UPDATE_SUCCESS) {
            return $result;
        }
#        $result = param_value_return($actpasswd, \$passwd);
#        print "update_text_passwd $act_passwd, $passwd, $result\n";
#        if ($result != $PARAM_UPDATE_SUCCESS) {
#            return $result;
#        }

        update_local_dbase($fld_ps_type, $PS_NULL);
        update_local_dbase($fld_iv, 0);
        update_local_dbase($fld_mac, 0);
        update_local_dbase($fld_passwd_len, $local_passwd_len);
        update_local_dbase($fld_passwd, $passwd);
#    $result = $NOOP_CLI_RETURN_OPTION;
    } 
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}

sub update_text_passwd
{
    my $input = $_[0];
    my $actfld_ps_type;
    my $actfld_iv;
    my $actfld_mac;
    my $actfld_passwd_len;
    my $actfld_passwd;
    my $actpasswd;
    my $fld_ps_type;
    my $fld_iv;
    my $fld_mac;
    my $fld_passwd_len;
    my $fld_passwd;
    my $passwd;
    my $result;

    my @temp = split(/\,/, $input);

    $actfld_ps_type = $temp[0];
    $actfld_iv = $temp[1];
    $actfld_mac = $temp[2];
    $actfld_passwd_len = $temp[3];
    $actfld_passwd = $temp[4];
    $actpasswd = $temp[5];

# print "update_text_passwd $actfld_ps_type, $actfld_iv, $actfld_mac, $actfld_passwd_len, $actpasswd\n";
    $result = param_value_return($actfld_ps_type, \$fld_ps_type);
# print "update_text_passwd $actfld_ps_type, $fld_ps_type\n";
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actfld_iv, \$fld_iv);
# print "update_text_passwd $actfld_iv, $fld_iv\n";
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actfld_mac, \$fld_mac);
# print "update_text_passwd $actfld_mac, $fld_mac\n";
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actfld_passwd_len, \$fld_passwd_len);
# print "update_text_passwd $actfld_passwd_len, $fld_passwd_len\n";
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actfld_passwd, \$fld_passwd);
# print "update_text_passwd $actfld_passwd, $fld_passwd\n";
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actpasswd, \$passwd);
# print "update_text_passwd $act_passwd, $passwd, $result\n";
    if ($result != $PARAM_UPDATE_SUCCESS) {
       return $result;
    }

    $local_passwd_len = length($passwd);
    $local_passwd_len = $local_passwd_len/2;
    $result = check_for_digits($local_passwd_len);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    update_local_dbase($fld_ps_type, $PS_NULL);
    update_local_dbase($fld_iv, 0);
    update_local_dbase($fld_mac, 0);
    update_local_dbase($fld_passwd_len, $local_passwd_len);
    update_local_dbase($fld_passwd, $passwd);
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}

sub multiply_update_field
{
    my $input = $_[0];
    my $result;
    my $fld,
    my $val;
    my $val1;
    my $len;

    my ($actfld, $actval, $actval1) = split(/\,/, $input, 3);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval, \$val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval1, \$val1);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $val *= $val1;

    update_local_dbase($fld, $val);
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}

sub update_field_stringlength
{
    my $input = $_[0];
    my $result;
    my $fld,
    my $val;
    my $len;

    my ($actfld, $actval) = split(/\,/, $input, 2);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval, \$val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $len = length($val);

    update_local_dbase($fld, $len);
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}

sub increment_field_roguerule_ssid_conditional
{
    my $input = $_[0];
    my $actfld;
    my $actval;
    my $actrulename;
    my $rulename;
    my $fld;
    my $val;
    my $val1;

    ($actfld, $actval, $actrulename) = split(/\,/, $input, 3);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval, \$val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actrulename, \$rulename);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    if (get_value_from_xml_dbase($fld, \$val1)) {
        $val = $val + $val1;
    }
    if(!defined($rogue_rule_ssid_flag{$rulename})){
        $rogue_rule_ssid_flag{$rulename} = 1;
        update_local_dbase($fld, $val);
    }
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}

sub increment_field_roguerule_wildcardssid_conditional 
{
    my $input = $_[0];
    my $actfld;
    my $actval;
    my $actrulename;
    my $rulename;
    my $fld;
    my $val;
    my $val1;

    ($actfld, $actval, $actrulename) = split(/\,/, $input, 3);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval, \$val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actrulename, \$rulename);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    if (get_value_from_xml_dbase($fld, \$val1)) {
        $val = $val + $val1;
    }
    if(!defined($rogue_rule_wssid_flag{$rulename})){
        $rogue_rule_wssid_flag{$rulename} = 1;
        update_local_dbase($fld, $val);
    }
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}

sub increment_field
{
    my $input = $_[0];
    my $actfld;
    my $actval;
    my $fld;
    my $val;
    my $val1;

    ($actfld, $actval) = split(/\,/, $input);
    
    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval, \$val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    if (get_value_from_xml_dbase($fld, \$val1)) {
        $val = $val + $val1;
    }
    update_local_dbase($fld, $val);
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}


sub increment_field_with_check
{
    my $input = $_[0];
    my $actfld;
    my $actval;
    my $actlimit;
    my $limit;
    my $fld;
    my $val;
    my $val1;

    ($actfld, $actval, $actlimit) = split(/\,/, $input, 3);
    
    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval, \$val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actlimit, \$limit);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    if (get_value_from_xml_dbase($fld, \$val1)) {
        if($val1 < $limit) {
            $val = $val + $val1;
        } else {
            $val = $limit;
        }
    }
    update_local_dbase($fld, $val);
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}

sub add_field_to_create_index_hash
{
    my $indtype = $_[0];
    my $fld = $_[1];
    my $string = $_[2];
    my $add = $_[3];
    my $dim = $_[4];
    my $pind = $_[5];
    my $val;
    my $result = $PARAM_UPDATE_SUCCESS;
    my $inst = "";
    my $inst_present = 0;
    my $oldinst; 
    my $newinst; 
    my $pcreateref; 

    for (my $i = 0; $i < $dim; $i++) {
        $inst_present = 1;
        if ($i == 0) {
            $inst = $array_index{index}[$i];
        } else {
            $inst = $inst . "-" . $array_index{index}[$i];
        }
        if ($inst =~ "dummy") {
            $global_dummy_instance_hash{$inst}{$fld} = $fld;
        }
#print "inst $inst, $fld, $string, $global_dummy_instance_hash{$inst}{$fld}\n";
    }
#print "add_field_to_create_index_hash $inst, $inst_present\n";
    if ($indtype == $mapped_input_index) {
        if ((!defined($create_index_hash{$mapped_input_index}) || !defined($create_index_hash{$mapped_input_index}{$fld})) && ($inst_present == 0)) {
            $create_index_hash{$mapped_input_index}{$fld}{map} = $add;
            $result = get_value_from_string($add, $string, \$val);
            if ($result != $PARAM_UPDATE_SUCCESS) {
                return $result;
            }
            $$pind = $val;
            $create_index_hash{$mapped_input_index}{$fld}{str}{$string} = $val;
        } elsif ($inst_present) {
            if (!defined($create_index_hash{$mapped_input_index}{$fld}{instance}{$inst})) {
                $create_index_hash{$mapped_input_index}{$fld}{instance}{$inst}{map} = $add;
                $result = get_value_from_string($add, $string, \$val);
                if ($result != $PARAM_UPDATE_SUCCESS) {
                    return $result;
                }
                $$pind = $val;
                $create_index_hash{$mapped_input_index}{$fld}{instance}{$inst}{str}{$string} = $val;
            } elsif ($create_index_hash{$mapped_input_index}{$fld}{instance}{$inst}{map} == $add) {
                $result = get_value_from_string($add, $string, \$val);
                if ($result != $PARAM_UPDATE_SUCCESS) {
                    return $result;
                }
                $$pind = $val;
                $create_index_hash{$mapped_input_index}{$fld}{instance}{$inst}{str}{$string} = $val;
            } else {
                print_to_console("Error: There can not be multiple maps for the field $fld\nConfig CLI:$input_command\n");
                seek(RESULTFILE,0,0);
                print RESULTFILE "Error: There can not be multiple maps for the field $fld\r\nConfig CLI:$input_command\r\n";
                exit;
            }
        } elsif ($create_index_hash{$mapped_input_index}{$fld}{map} == $add) {
            $result = get_value_from_string($add, $string, \$val);
            if ($result != $PARAM_UPDATE_SUCCESS) {
                return $result;
            }
            $$pind = $val;
            $create_index_hash{$mapped_input_index}{$fld}{str}{$string} = $val;
        } else {
            print_to_console("Error: There can not be multiple maps for the field $fld\nConfig CLI:$input_command\n");
            seek(RESULTFILE,0,0);
            print RESULTFILE "Error: There can not be multiple maps for the field $fld\r\nConfig CLI:$input_command\r\n";
            exit;
        }
    } elsif (($indtype == $created_input_index) || ($indtype == $created_input_index_with_offset)) {
        if ($flag_index_set_diff == 0) {
            $array_index{compind}[$dim] = $add;
        }
        if ((!defined($create_index_hash{$created_input_index}) || !defined($create_index_hash{$created_input_index}{$fld})) && ($inst_present == 0)) {
            $create_index_hash{$created_input_index}{$fld}{count} = $add;
            $create_index_hash{$created_input_index}{$fld}{str}{$string} = $create_index_hash{$created_input_index}{$fld}{count};
            $$pind =  $create_index_hash{$created_input_index}{$fld}{count};
#print "add_field_to_create_index_hash0 $fld,$string, $$pind, $inst $input_command\n";
        } elsif ($inst_present) {
            if (!defined($create_index_hash{$created_input_index}{$fld}{instance}{$inst})) {
                $create_index_hash{$created_input_index}{$fld}{instance}{$inst}{count} = $add;
                $create_index_hash{$created_input_index}{$fld}{instance}{$inst}{str}{$string} = $create_index_hash{$created_input_index}{$fld}{instance}{$inst}{count};
                $$pind =  $create_index_hash{$created_input_index}{$fld}{instance}{$inst}{count};
#print "add_field_to_create_index_hash1 $fld,$string, $$pind, $inst\n";
            } elsif (!defined($create_index_hash{$created_input_index}{$fld}{instance}{$inst}{str}{$string})) {
                $create_index_hash{$created_input_index}{$fld}{instance}{$inst}{count} += 1;
                $create_index_hash{$created_input_index}{$fld}{instance}{$inst}{str}{$string} = $create_index_hash{$created_input_index}{$fld}{instance}{$inst}{count};
                $$pind =  $create_index_hash{$created_input_index}{$fld}{instance}{$inst}{count};
#print "add_field_to_create_index_hash2 $string, $$pind, $inst\n";
            } else {
                $$pind =  $create_index_hash{$created_input_index}{$fld}{instance}{$inst}{str}{$string};
#print "add_field_to_create_index_hash55 $string, $$pind, $inst $input_command\n";
                      }
#print "add_field_to_create_index_hash3 $string, $$pind, $inst\n";
            }
         elsif (!defined($create_index_hash{$created_input_index}{$fld}{str}{$string})) {
            $create_index_hash{$created_input_index}{$fld}{count} += 1;
            $create_index_hash{$created_input_index}{$fld}{str}{$string} = $create_index_hash{$created_input_index}{$fld}{count};
            $$pind =  $create_index_hash{$created_input_index}{$fld}{count};
#print "add_field_to_create_index_hash4 $string, $$pind, $inst\n";
        } else {
            $$pind =  $create_index_hash{$created_input_index}{$fld}{str}{$string};
#print "add_field_to_create_index_hash5 $string, $$pind, $inst $input_command\n";
        }
    } elsif ($indtype == $created_useasis_input_index) {
        if ((!defined($create_index_hash{$created_input_index}) || !defined($create_index_hash{$created_input_index}{$fld})) && ($inst_present == 0)) {
            $create_index_hash{$created_input_index}{$fld}{count} = $add;
            if ($flag_set_supplied_index == 0) {
                $create_index_hash{$created_input_index}{$fld}{str}{$string} = "dummy" . $create_index_hash{$created_input_index}{$fld}{count};
                $$pind =  "dummy" . $create_index_hash{$created_input_index}{$fld}{count};
#print "1-$$pind, $create_index_hash{$created_input_index}{$fld}{str}{$string},$string, $inst\n";
            } else {
#print "1--$$pind\n";
                $create_index_hash{$created_input_index}{$fld}{str}{$string} = $$pind; 
            }
        } elsif ($inst_present) {
            if (!defined($create_index_hash{$created_input_index}{$fld}{instance}{$inst})) {
                if ($flag_set_supplied_index == 0) {
                    $create_index_hash{$created_input_index}{$fld}{instance}{$inst}{count} = $add;
                    $create_index_hash{$created_input_index}{$fld}{instance}{$inst}{str}{$string} = "dummy" . $create_index_hash{$created_input_index}{$fld}{instance}{$inst}{count};
                    $$pind =  "dummy" . $create_index_hash{$created_input_index}{$fld}{instance}{$inst}{count};
#print "2-$$pind\n";
                } else {
#print "2--$$pind\n";
                    $create_index_hash{$created_input_index}{$fld}{instance}{$inst}{str}{$string} = $$pind; 
                }
#print "add_field_to_create_index_hash1 $string, $$pind, $inst\n";
            } elsif (!defined($create_index_hash{$created_input_index}{$fld}{instance}{$inst}{str}{$string})) {
                if ($flag_set_supplied_index == 0) {
                    $create_index_hash{$created_input_index}{$fld}{instance}{$inst}{count} += 1;
                    $create_index_hash{$created_input_index}{$fld}{instance}{$inst}{str}{$string} = "dummy" . $create_index_hash{$created_input_index}{$fld}{instance}{$inst}{count};
                    $$pind =  "dummy" .  $create_index_hash{$created_input_index}{$fld}{instance}{$inst}{count};
#print "3-$$pind\n";
                } else {
#print "3--$$pind\n";
                    $create_index_hash{$created_input_index}{$fld}{instance}{$inst}{str}{$string} = $$pind; 
                }
#print "add_field_to_create_index_hash2 $string, $$pind, $inst\n";
            } else {
                $$pind =  $create_index_hash{$created_input_index}{$fld}{instance}{$inst}{str}{$string};
#print "add_field_to_create_index_hash3 $string, $$pind, $inst\n";
            }
        } elsif (!defined($create_index_hash{$created_input_index}{$fld}{str}{$string})) {
            if ($flag_set_supplied_index == 0) {
                $create_index_hash{$created_input_index}{$fld}{count} += 1;
                $create_index_hash{$created_input_index}{$fld}{str}{$string} = "dummy" . $create_index_hash{$created_input_index}{$fld}{count};
                $$pind =  "dummy" . $create_index_hash{$created_input_index}{$fld}{count};
#print "4->$$pind\n";
            } else {
#print "4-->$$pind\n";
                $create_index_hash{$created_input_index}{$fld}{str}{$string} = $$pind; 
#print "4--> $string,,,$$pind\n";
            }
        } else {
            if ($flag_set_supplied_index == 0) {
                $$pind = $create_index_hash{$created_input_index}{$fld}{str}{$string};
#print "5--> $string,,,$$pind $input_command\n";
            } else {
                $oldinst = $create_index_hash{$created_input_index}{$fld}{str}{$string};
#print "call to copy0--$oldinst, $$pind, \n";
                foreach my $curinst (keys %global_dummy_instance_hash) {
#print "call to copy3--$oldinst, $$pind, $newinst, $curinst\n";
                    if ($curinst =~ $oldinst) {
#print "call to copy4--$oldinst, $$pind, $newinst, $curinst\n";
                        foreach my $newfld (keys %{$global_dummy_instance_hash{$curinst}}) {
                            $pcreateref = \%{$create_index_hash{$created_input_index}{$newfld}{instance}};
                            $newinst = $curinst;
                            $newinst =~ s/$oldinst/$$pind/;
#print "call to copy5--$oldinst, $$pind, $newinst, $curinst\n";
                            copy_old_to_new($pcreateref, $curinst, $pcreateref, $newinst);
                        }    
                    }
                }
                $create_index_hash{$created_input_index}{$fld}{str}{$string} = $$pind;
#print "6--> $string,,,$$pind $input_command\n";
            }
        }
    }
    return $result;
}

sub read_default_xml_dbase
{

}

sub update_local_dbase
{
    my $fld = $_[0];
    my $val = $_[1];

    if (!defined($local_fld_dbase{fldval})) {
        $local_fld_dbase{count} = 0;
    }
    $local_fld_dbase{fldval}[$local_fld_dbase{count}]{fld} = $fld;
    $local_fld_dbase{fldval}[$local_fld_dbase{count}]{val} = $val;
    $local_fld_dbase{count} += 1;
}

sub delete_local_dbase
{
    delete($local_fld_dbase{fldval});
    delete($local_fld_dbase{count});
    delete($array_index{compind});
}

sub update_xml_dbase_with_localdb
{
    my $flag = $_[0];
    my $result = $NOOP_CLI_RETURN_OPTION;
    if (defined($local_fld_dbase{fldval})) {
        for (my $i = 0; $i < $local_fld_dbase{count}; $i++) {
            $result = update_xml_dbase($local_fld_dbase{fldval}[$i]{fld}, $local_fld_dbase{fldval}[$i]{val}, $flag);
        }
    }
#print "update_xml_dbase_with_localdb $local_fld_dbase{fldval}[$i]{fld}, $local_fld_dbase{fldval}[$i]{val}\n";
    return $result;
}
    my @mgmt_arr;
    my @apmgr_arr;
    my @virtual_arr;
    my @serviceport_arr;
    my $platform_serviceport_flag = 0;
    #my $newdb10 = "newdb10";
sub get_value_from_xml_dbase_with_key
{

    my $fld = $_[0];
    my $pval = $_[1];
    my $instance_index = $_[2];
    my $xmlref = \%digit_to_tag_actual;
    my $str;
    my $level = 0;

    my @temp = split(/\./, $fld);
    if($fld == -1) {
        return 0;
    }
    for (my $i = 0; $i <= $#temp; $i++) {
        if ($i == 0) {
            $str = $temp[$i];
        } else {
            $str = $str . "." . $temp[$i];
        }

        if (defined($$xmlref{nxt}{$temp[$i]})) {
            $xmlref = \%{$$xmlref{nxt}{$temp[$i]}};
            if (defined($$xmlref{instance})) {
                if (!defined($array_index{index}[$level])) {
                    if ($i != $#temp || !defined($create_index_hash{$created_input_index}) || !defined($create_index_hash{$created_input_index}{$str})) {
                        print_to_console("Error: Index not defined for array base $str in field $fld\nConfig CLI:$input_command\n");
                        seek(RESULTFILE,0,0);
                        print RESULTFILE "Error: Index not defined for array base $str in field $fld\r\nConfig CLI:$input_command\r\n";
                        exit;
                    }
                } else {
                        $xmlref = \%{$$xmlref{instance}{$instance_index}};
                }
                $level += 1;
            }
        } else {
            return 0;
        }
    }
    $$pval = $$xmlref{val};
    return 1;
}
sub check_for_vlan_mandatory_fields
{
    my $val;
    my $dhcp_val;
    my $xmlref = \%digit_to_tag_actual;
    my $fld;
    my $ipfld;
    my $netmaskfld;
    my $gatewayfld;
    my $primaryportfld;
    my $backupportfld;
    my $vlantagfld;
    my $lagflagfld;
    my $lagflagval;
    my $passwdencflagfld;
    my $dhcpflag;
    my $key_val;
    my $servicetype;
    my $roguerulecondition;
    my $rogueruleconditionvalue;
    my $staticAPMgr;
    my $tempCnt;
        open(DB114,"$APMgrInfo") or die "Can't open format specifier database File:$!";
        for $line(<DB114>) {
            chomp $line;
            $staticAPMgr = $line;
        } 
        if ( $local_debug == 1 ) {
            open(DB112,"newdb12") or die "Can't open format specifier database File:$!";
        } else {
            open(DB112,"/bsn/newdb12") or die "Can't open format specifier database File:$!";
        }
        for $line(<DB112>) {
            chomp $line;
            my ($name, $value) = split('\t', $line, 2);
            if($name eq "index_field") {
                $fld = $value;
            }
            elsif($name eq "ip_addr_field") {
                $ipfld = $value;
            }
            elsif($name eq "netmask_field") {
                $netmaskfld = $value;
            }
            elsif($name eq "gateway_field") {
                $gatewayfld = $value;
            }
            elsif($name eq "primary_port") {
                $primaryportfld = $value;
            }
            elsif($name eq "backup_port") {
                $backupportfld = $value;
            }
            elsif($name eq "vlan_id") {
                $vlantagfld = $value;
            }
            elsif($name eq "lag_flag") {
                $lagflagfld = $value;
            }
            elsif($name eq "passwd_enc_flag") {
                $passwdencflagfld = $value;
            }
            elsif($name eq "dhcp_flag") {
                $dhcpflag = $value;
            }
            elsif($name eq "service_type") {
                $servicetypefld = $value;
            }
            elsif($name eq "rogue_condition_type") {
                $roguerulecondition = $value;
            }
            elsif($name eq "rogue_condition_value_field") {
                $rogueruleconditionvalue = $value;
            }
        }
        if(! close(DB112))
        {
           remove_xml_files();
          die "Error: File System is out of Disk Space.:$!";
        }
        $max_port_number = get_max_port_number_for_platform();
        if (get_value_from_xml_dbase($lagflagfld, \$lagflagval)) {
            if($lagflagval eq "AES_LAG_CFG1") {
                $max_port_number = -1;
            }
            if(($lagflagval ne "AES_LAG_CFG1") && ($platform_type eq $platform_WiSM_1)) {
                print_to_console("Error: LAG is not enabled. \'config lag enable\' is mandatory CLI for this platform.\n");
                seek(RESULTFILE,0,0);
                print RESULTFILE "Error: LAG is not enabled. \'config lag enable\' is mandatory CLI for this platform.\r\n";
                exit;
            }
        }
         if (get_value_from_xml_dbase($passwdencflagfld, \$val)) {
            if($val == 2) {
                if(check_masterkey_not_configured()) {
                    print_to_console("Error: Master key is missing when password-encryption is enabled. Please set the same master key from the downloaded config wlc.\n");
                    seek(RESULTFILE,0,0);
                    print RESULTFILE "Error: Master key is missing when password-encryption is enabled. Please set the same master key from the downloaded config wlc.\r\n";
                    exit;
                }        
            }
        }
        my @temp = split(/\./, $fld);
        for (my $i = 0; $i <= $#temp; $i++) {
            if (defined($$xmlref{nxt}{$temp[$i]})) {
                $xmlref = \%{$$xmlref{nxt}{$temp[$i]}};
                $tempCnt = $i;
            }
        }
        if (defined($$xmlref{instance})) {
            foreach my $key (keys %{$$xmlref{instance}}) {
                my $pxmlref = \%{$$xmlref{instance}{$key}};
                for (my $i = $tempCnt+1; $i <= $#temp; $i++) {
                    if (defined($$pxmlref{nxt}{$temp[$i]})) {
                        $pxmlref = \%{$$pxmlref{nxt}{$temp[$i]}};
                    } else {
                        print "Error: Mandatory Field Not Found\n";
                    }
                }
                if($$pxmlref{val} eq "6d616e6167656d656e74") {
                    if (get_value_from_xml_dbase_with_key($ipfld, \$val, $key)) {
                        $mgmt_arr[0] = $val;
                    }
                    else {
                        print_to_console("Error: IP Address for Management Interface is Invalid\n");
                        seek(RESULTFILE,0,0);
                        print RESULTFILE "Error: IP Address for Management Interface is Invalid\r\n";
                        exit;
                    }
                    if (get_value_from_xml_dbase_with_key($netmaskfld, \$val, $key)) {
                        $mgmt_arr[1] = $val;
                    }
                    else {
                        print_to_console("Error: Netmask field for Management Interface is Invalid\n");
                        seek(RESULTFILE,0,0);
                        print RESULTFILE "Error: Netmask field for Management Interface is Invalid\r\n";
                        exit;
                    }
                    if (get_value_from_xml_dbase_with_key($gatewayfld, \$val, $key)) {
                        $mgmt_arr[2] = $val;
                    }
                    else {
                        print_to_console("Error: IP Gateway for Management Interface is Invalid\n");
                        seek(RESULTFILE,0,0);
                        print RESULTFILE "Error: IP Gateway for Management Interface is Invalid\r\n";
                        exit;
                    }
                    if($max_port_number != -1) {
                        if (get_value_from_xml_dbase_with_key($primaryportfld, \$val, $key)) {
                            $mgmt_arr[3] = $val;
                            if($mgmt_arr[3] > $max_port_number) {
                                print_to_console("Error: Primary Port Number for Management Interface is Invalid\n");
                                seek(RESULTFILE,0,0);
                                print RESULTFILE "Error: Primary Port Number for Management Interface is Invalid\r\n";
                                exit;
                            } 
                        }
                        elsif($primaryportfld != -1) {
                            print_to_console("Error: Primary Port Number for Management Interface is Invalid\n");
                            seek(RESULTFILE,0,0);
                            print RESULTFILE "Error: Primary Port Number for Management Interface is Invalid\r\n";
                            exit;
                        }
                        if (get_value_from_xml_dbase_with_key($backupportfld, \$val, $key)) {
                            $mgmt_arr[4] = $val;
                            if($mgmt_arr[4] > $max_port_number) {
                                print_to_console("Error: Backup Port Number for Management Interface is Invalid\n");
                                seek(RESULTFILE,0,0);
                                print RESULTFILE "Error: Backup Port Number for Management Interface is Invalid\r\n";
                                exit;
                            } 
                        }
                    }
#print "Save management Data, $mgmt_arr[0],$mgmt_arr[1],$mgmt_arr[2]\n";
                }
                if( (($$pxmlref{val} eq "61702d6d616e61676572")&&($staticAPMgr eq "1")) || (($$pxmlref{val} eq "61702d6d616e61676572")&&($dynamicAPMgr eq "1")) ) {
                    if (get_value_from_xml_dbase_with_key($ipfld, \$val, $key)) {
                        $apmgr_arr[0] = $val;
                    }
                    else {
                        print_to_console("Error: IP Address for AP-Manager Interface is Invalid\n");
                        seek(RESULTFILE,0,0);
                        print RESULTFILE "Error: IP Address for AP-Manager Interface is Invalid\r\n";
                        exit;
                    }
                    if (get_value_from_xml_dbase_with_key($netmaskfld, \$val, $key)) {
                        $apmgr_arr[1] = $val;
                    }
                    else {
                        print_to_console("Error: Netmask field for AP-Manager Interface is Invalid\n");
                        seek(RESULTFILE,0,0);
                        print RESULTFILE "Error: Netmask field for AP-Manager Interface is Invalid\r\n";
                        exit;
                    }
                    if (get_value_from_xml_dbase_with_key($gatewayfld, \$val, $key)) {
                        $apmgr_arr[2] = $val;
                    }
                    else {
                        print_to_console("Error: IP Gateway for AP-Manager Interface is Invalid\n");
                        seek(RESULTFILE,0,0);
                        print RESULTFILE "Error: IP Gateway for AP-Manager Interface is Invalid\r\n";
                        exit;
                    }
                    if($max_port_number != -1) {
                        if (get_value_from_xml_dbase_with_key($primaryportfld, \$val, $key)) {
                            $apmgr_arr[3] = $val;
                            if($apmgr_arr[3] > $max_port_number) {
                                print_to_console("Error: Primary Port Number for AP-Manager Interface is Invalid\n");
                                seek(RESULTFILE,0,0);
                                print RESULTFILE "Error: Primary Port Number for AP-Manager Interface is Invalid\r\n";
                                exit;
                            } 
                        }
                        elsif($primaryportfld != -1) {
                            print_to_console("Error: Primary Port Number for AP-Manager Interface is Invalid\n");
                            seek(RESULTFILE,0,0);
                            print RESULTFILE "Error: Primary Port Number for AP-Manager Interface is Invalid\r\n";
                            exit;
                        }
                        if (get_value_from_xml_dbase_with_key($backupportfld, \$val, $key)) {
                            $apmgr_arr[4] = $val;
                            if($apmgr_arr[4] > $max_port_number) {
                                print_to_console("Error: Backup Port Number for AP-Manager Interface is Invalid\n");
                                seek(RESULTFILE,0,0);
                                print RESULTFILE "Error: Backup Port Number for AP-Manager Interface is Invalid\r\n";
                                exit;
                            } 
                        }
                    }
#print "Save ap-manager Data, $apmgr_arr[0],$apmgr_arr[1],$apmgr_arr[2]\n";
                }
                if($$pxmlref{val} eq "7669727475616c") {
                    if (get_value_from_xml_dbase_with_key($ipfld, \$val, $key)) {
                        $virtual_arr[0] = $val;
                    }
                    else {
                        print_to_console("Error: IP Address for Virtual Interface is Invalid\n");
                        seek(RESULTFILE,0,0);
                        print RESULTFILE "Error: IP Address for Virtual Interface is Invalid\r\n";
                        exit;
                    }
#print "Save virtual Data, $virtual_arr[0]\n";
                }
#Added to check out-of-band interface present on FoxHound platform.
                if(($$pxmlref{val} eq "6f75742d6f662d62616e64") && ($upd_foxhound_intf == 1)) {
                    $foxhound_intf_complete = 1;
                }
                if(($max_port_number != -1) && ($$pxmlref{val} ne "61702d6d616e61676572")) {
                    my $vlan_value;
                    if (get_value_from_xml_dbase_with_key($vlantagfld, \$val, $key)) {
                       $vlan_value = $val;
                    }
                    if (get_value_from_xml_dbase_with_key($primaryportfld, \$val, $key)) {
                        if(defined($vlan_port_map{port}{$vlan_value}) && ($vlan_port_map{port}{$vlan_value}==$val)) {
                            print_to_console("Error: Interface \'$$pxmlref{val}\' and interface \'$vlan_port_map{interface}{$vlan_value}\' has same VLAN($vlan_value) and PORT($val)\n");
                            seek(RESULTFILE,0,0);
                            print RESULTFILE "Error: Interface \'$$pxmlref{val}\' and interface \'$vlan_port_map{interface}{$vlan_value}\' has same VLAN($vlan_value) and PORT($val)\r\n";
                            exit;
                        } else {
                            $vlan_port_map{port}{$vlan_value}=$val;
                            $vlan_port_map{interface}{$vlan_value} = $$pxmlref{val};
                        }
                    }
                    if (get_value_from_xml_dbase_with_key($backupportfld, \$val, $key)) {
                        if(defined($vlan_port_map{port}{$vlan_value}) && ($vlan_port_map{port}{$vlan_value}==$val)) {
                            print_to_console("Error: Interface \'$$pxmlref{val}\' and interface \'$vlan_port_map{interface}{$vlan_value}\' has same VLAN($vlan_value) and PORT($val)\n");
                            seek(RESULTFILE,0,0);
                            print RESULTFILE "Error: Interface \'$$pxmlref{val}\' and interface \'$vlan_port_map{interface}{$vlan_value}\' has same VLAN($vlan_value) and PORT($val)\r\n";
                            exit;
                        } else {
                            $vlan_port_map{port}{$vlan_value}=$val;
                            $vlan_port_map{interface}{$vlan_value} = $$pxmlref{val};
                        }
                    }
                }
            }
        }
        if ((!$foxhound_intf_complete)&& ($upd_foxhound_intf == 1)) {
            print_to_console("Error: config lag enable CLI is missing from config\n");
            seek(RESULTFILE,0,0);
            print RESULTFILE "Error: config lag enable CLI is missing from config\r\n";
            exit;
        }
        
        if(!get_key_for_index_value_from_xml_dbase($servicetypefld, 6)) {
            print_to_console("Error: \'config mgmtuser add\' CLI is missing from config\n");
            seek(RESULTFILE,0,0);
            print RESULTFILE "Error: \'config mgmtuser add\' CLI is missing from config\r\n";
            exit;
       }
    shift_rogue_rule_ssid_condition_to_last($roguerulecondition, "RULE_CONDITION_USER_CONFIG_SSID", $rogueruleconditionvalue);    
    validate_mandatory_fields();
}

sub get_next_level_instance
{
    my $cnt = $_[0];
    my $xmlref = $_[1];
    my $value_to_compare = $_[2];
    my $pkeysarray = $_[3];
    my $local_cnt = $cnt;
    while($local_cnt <= $#glb_array_fld_values) {
#print "get_next_level_instance1 $glb_array_fld_values[$local_cnt], $local_cnt, $$xmlref{nxt}\n";
        if (defined($$xmlref{nxt}{$glb_array_fld_values[$local_cnt]})) {
            $xmlref = \%{$$xmlref{nxt}{$glb_array_fld_values[$local_cnt]}};
#print "get_next_level_instance3 $glb_array_fld_values[$local_cnt], $local_cnt\n";
            $local_cnt += 1; 
            if (defined($$xmlref{instance})) {
                foreach my $key(keys %{$$xmlref{instance}}) {
#print "get_next_level_instance2 $key\n";
                    my $pxmlref = \%{$$xmlref{instance}{$key}};
                    $result=get_next_level_instance($local_cnt, $pxmlref, $value_to_compare, $pkeysarray);
                    if($result == 1)
                    {
                        if(!defined($$pkeysarray{cnt})) {
                            $$pkeysarray{cnt} = 0;
                        }
                        $$pkeysarray{array}[$$pkeysarray{cnt}] = $key;
                        $$pkeysarray{cnt} += 1;
                        return $result;
                    }
                }
                $local_cnt = $#glb_array_fld_values + 1;
            } elsif($local_cnt == $#glb_array_fld_values+1) {
                if($$xmlref{val} eq $value_to_compare) {
                    return 1;
                }
            }
        } else {
            return 0; 
        }
    }
    return 0;
}

sub get_key_for_index_value_from_xml_dbase
{
    my $fld = $_[0];
    my $val_to_compare = $_[1];
    my $xmlref = \%digit_to_tag_actual;
    my $level = 0;
    my %keys_hash;
    my $i = 0;
#print "get_key_for_index_value_from_xml_dbase $$xmlref{nxt}\n"; 
        for(my $j=0; $j<=$#glb_array_fld_values; $j++){
           delete($glb_array_fld_values[$j]);
        }
        @glb_array_fld_values = split(/\./, $fld);
  
        $result = get_next_level_instance($i, $xmlref, $val_to_compare, \%key_hash);
    
}

sub shift_rogue_rule_ssid_condition_to_last
{
    my $fld = $_[0];
    my $val_to_compare = $_[1];
    my $valfld = $_[2];
    my $xmlref = \%digit_to_tag_actual;
    my $level = 0;
    my %keys_hash;
    my $i = 0;
    my $ssidRef;
    my $flagssidfound = 0;
    my $cnt_for_val;
    my $flagRuleNotFirst = 0;
    my @temp = split(/\./, $fld);
    my @temp_val = split(/\./, $valfld);
    for (my $i = 0; $i <= $#temp; $i++) {
        if (defined($$xmlref{nxt}{$temp[$i]})) {
            $xmlref = \%{$$xmlref{nxt}{$temp[$i]}};
            $tempCnt = $i;
        }
    }
    if (defined($$xmlref{instance})) {
        foreach my $key (keys %{$$xmlref{instance}}) {
#swappind of last conditiontype with ssid if next ruleTable is available.
            if($flagRuleNotFirst == 1 && $flagssidfound == 1) {
               my $tempConditionStr = $$pppxmlref{val};
               $flagssidfound = 0;
               $$pppxmlref{val} = $$ssidRef{val};
               $$ssidRef{val} = $tempConditionStr;
               if(defined($$prevRefVal{nxt}{$temp_val[$cnt_for_val]})) {
                   $$ssidPrevRef{nxt}{$temp_val[$cnt_for_val]} = $$prevRefVal{nxt}{$temp_val[$cnt_for_val]};
                   delete($$prevRefVal{nxt}{$temp_val[$cnt_for_val]});
               }
            }
            $flagRuleNotFirst = 1;
            my $pxmlref = \%{$$xmlref{instance}{$key}};
            if (defined($$pxmlref{nxt}{$temp[$tempCnt+1]})) {
                $pxmlref = \%{$$pxmlref{nxt}{$temp[$tempCnt+1]}};
            }
            if (defined($$pxmlref{instance})) {
                foreach my $key1 (sort keys %{$$pxmlref{instance}}) {
                    my $ppxmlref = \%{$$pxmlref{instance}{$key1}};
                    if (defined($$ppxmlref{nxt}{$temp[$tempCnt+2]})) {
                        $pppxmlref = \%{$$ppxmlref{nxt}{$temp[$tempCnt+2]}};
                        if($val_to_compare eq $$pppxmlref{val}) {
                           $flagssidfound = 1;
                           $ssidRef = $pppxmlref;
                           $ssidPrevRef = $ppxmlref;
                        }
                    }
                    $cnt_for_val = $tempCnt+2;
                    #if (defined($$ppxmlref{nxt}{$temp_val[$cnt_for_val]})) {
                        $prevRefVal = $ppxmlref;
                    #}
                }
            }
        }
#swapping of last conditiontype with ssid for last  ruleTable index.
        if($flagRuleNotFirst == 1 && $flagssidfound == 1) {
           my $tempConditionStr = $$pppxmlref{val};
           $flagssidfound = 0;
           $$pppxmlref{val} = $$ssidRef{val};
           $$ssidRef{val} = $tempConditionStr;
           if(defined($$prevRefVal{nxt}{$temp_val[$cnt_for_val]})) {
               $$ssidPrevRef{nxt}{$temp_val[$cnt_for_val]} = $$prevRefVal{nxt}{$temp_val[$cnt_for_val]};
               delete($$prevRefVal{nxt}{$temp_val[$cnt_for_val]});
           }
        }
    }
}

sub validate_mandatory_fields
{


}

sub get_value_from_xml_dbase
{
    my $fld = $_[0];
    my $pval = $_[1];
    my $xmlref = \%digit_to_tag_actual;
    my $str;
    my $level = 0;

    my @temp = split(/\./, $fld);
    for (my $i = 0; $i <= $#temp; $i++) {
        if ($i == 0) {
            $str = $temp[$i];
        } else {
            $str = $str . "." . $temp[$i];
        }
        if (defined($$xmlref{nxt}{$temp[$i]})) {
            $xmlref = \%{$$xmlref{nxt}{$temp[$i]}};
            if (defined($$xmlref{instance})) {
                if (!defined($array_index{index}[$level])) {
                    if ($i != $#temp || !defined($create_index_hash{$created_input_index}) || !defined($create_index_hash{$created_input_index}{$str})) {
                        print_to_console("Error: Index not defined for array base $str in field $fld\nConfig CLI:$input_command\n");
                        seek(RESULTFILE,0,0);
                        print RESULTFILE "Error: Index not defined for array base $str in field $fld\r\nConfig CLI:$input_command\r\n";
                        exit;
                    }
                } else {
                    $xmlref = \%{$$xmlref{instance}{$array_index{index}[$level]}};
                }
                $level += 1;
            }
        } else {
            return 0;
        }
    }
    $$pval = $$xmlref{val};
    return 1;
}

sub delete_from_xml_dbase
{
    my $fld = $_[0];
    my $tempCnt;
    my @temp = split(/\./, $fld);
    my $xmlref = \%digit_to_tag_actual;
#print "delete_from_xml_dbase1 $fld\n";
    for (my $i = 0; $i <= $#temp; $i++) {
        if (defined($$xmlref{nxt}{$temp[$i]})) {
            $xmlref = \%{$$xmlref{nxt}{$temp[$i]}};
            $tempCnt = $i;
        }
    }
INSTANCE_FOUND:
#print "delete_from_xml_dbase2 $tempCnt, $temp[$tempCnt], $temp[$tempCnt+1]\n";
    if (defined($$xmlref{instance})) {
        foreach my $key1 (keys %{$$xmlref{instance}}) {
            my $pxmlref = \%{$$xmlref{instance}{$key1}};
            for (my $i = $tempCnt+1; $i <= $#temp; $i++) {
                if($i < $#temp) {
                    if (defined($$pxmlref{nxt}{$temp[$i]})) {
                        $pxmlref = \%{$$pxmlref{nxt}{$temp[$i]}};
#print "delete_from_xml_dbase3 $i, $temp[$i],  $$pxmlref{instance}, $$pxmlref{val}\n";
                    } elsif(defined($$pxmlref{instance})) {
                        $tempCnt = $i;
                        $xmlref = $pxmlref;
#print "delete_from_xml_dbase4 $i, $temp[$i], $$pxmlref{val}\n";
                        goto INSTANCE_FOUND;
                    }
                } else {
                    if (defined($$pxmlref{nxt}{$temp[$i]})) {
                        $pxmlref = \%{$$pxmlref{nxt}{$temp[$i]}};
#print "delete_from_xml_dbase5 $i, $$pxmlref{val}, $$pxmlref{instance}\n";
                        if(defined($$pxmlref{instance})) {
                            foreach my $key2 (keys %{$$pxmlref{instance}}) {
                               delete($$pxmlref{instance}{$key2});
                            }
                        } else {
                            delete($$pxmlref{val});
                        }
                    }
                }
            }
        }
    }
}


sub update_xml_dbase
{
    my $fld = $_[0];
    my $val = $_[1];
    my $flag = $_[2];
    my $href = \%digit_to_tag;
    my $fmtref = \%fldfrmtdbase_hash;
    my $xmlref = \%digit_to_tag_actual;
    my $level = 0;
    my $str = "";
    my $strhash = "";
    my $strhash1 = "";
    my $xmlfmt;
    my $clifmt;
    my $conv_val;
    my $result = $NOOP_CLI_RETURN_OPTION;
    my $new_index;  

    my @temp = split(/\./, $fld);
    for (my $i = 0; $i <= $#temp; $i++) {
        if (defined($$href{nxt}{$temp[$i]})) {
            $fmtref = \%{$$fmtref{nxt}{$temp[$i]}};
            $href = \%{$$href{nxt}{$temp[$i]}};
        }
    }

    $conv_val = $val;
    @global_byte_arr =();

#Added to remove byteoffset coming for rule name,as offset should be used only for ssidList. 
    if (defined ($global_bytearray_index_start{$val})) { 
       $flag_for_byte_offset = 1;
    }
 
    if (defined($$fmtref{$xml_format})) {
        $xmlfmt = $$fmtref{$xml_format};
        $clifmt = $$fmtref{$cli_format};
# print "update_xml_dbase $strhash $clifmt $xmlfmt value:$val \n";
        if (defined($$href{array}) || defined($$href{bytearray})) {
#print "update_xml_dbase $strhash $clifmt $xmlfmt value:$val, $fld \n";
            $result = $format_conv_arr[$clifmt][$xmlfmt]($val, \$conv_val, 1);
        } else {
#print "update_xml_dbase1 $strhash $clifmt $xmlfmt value:$val, $fld\n";
            $result = $format_conv_arr[$clifmt][$xmlfmt]($val, \$conv_val, 0);
        }
    }
    if ($result != $NOOP_CLI_RETURN_OPTION) {
        return $result;
    }


    $href = \%digit_to_tag;
    for (my $i = 0; $i <= $#temp; $i++) {
        if ($i == 0) {
            $str = $temp[$i];
            $strhash = $temp[$i];
        } else {
            $str = $str . "." . $temp[$i];
            $strhash = $strhash . "." . $temp[$i];
        }
        if (defined($$href{nxt}{$temp[$i]})) {
            $href = \%{$$href{nxt}{$temp[$i]}};
            $xmlref = \%{$$xmlref{nxt}{$temp[$i]}};
            if (defined($$href{array})) {
#print "update_xml_dbase2 $str\n";
                if (!defined($array_index{index}[$level])) {
                    if ($i != $#temp || !defined($create_index_hash{$created_input_index}) || !defined($create_index_hash{$created_input_index}{$str})) {
                        print_to_console("Error: Index not defined for array base $str in field $fld in update_xml_dbase\nConfig CLI:$input_command\n");
                        seek(RESULTFILE,0,0);
                        print RESULTFILE "Error: Index not defined for array base $str in field $fld in update_xml_dbase\r\nConfig CLI:$input_command\r\n";
                        exit;
                    }
                } else {
                    if (defined($array_index{compind}[$level])) {
                        $$xmlref{compind}{index} = $array_index{compind}[$level];
                    }
                    $xmlref = \%{$$xmlref{instance}{$array_index{index}[$level]}};
                    if ($flag == 1 && $last_updated_input_command ne $input_command) {
                        $last_updated_input_command = $input_command;
                        if (!defined($$xmlref{clilist}{count})) {
                            $$xmlref{clilist}{count} = 0;
                        }
                        $$xmlref{clilist}{cliarray}[$$xmlref{clilist}{count}] = $input_command;
                        $$xmlref{clilist}{count} += 1;
                    }
                    $strhash = $strhash . "#". $array_index{index}[$level];
                    if (!defined($$xmlref{updflag}) || $$xmlref{updflag} == $xmldbase_index_not_updated) {
                        $$xmlref{updflag} = $array_index{flag}[$level];
                    }
                }
                $level += 1;
            }
        } else {
            print_to_console("Error: Field $fld is not defined in update_xml_dbase\nConfig CLI:$input_command\n");
            seek(RESULTFILE,0,0);
            print RESULTFILE "Error: Field $fld is not defined in update_xml_dbase\r\nConfig CLI:$input_command\r\n";
            exit;
        }
    }
#print "update_xml_dbase3 $global_bytearray_index, $#global_byte_arr\n"; 
    if ($flag_for_byte_offset == 0) {
        $new_index = $global_bytearray_index;
    } else {
        $new_index = 0;
    }

    if (defined ($global_byte_arr[$new_index])) {
        for (my $i =$new_index; $i<= $#global_byte_arr; $i++) {
            $strhash1 =  $strhash. "#" .$i;
            tree_create($strhash1, $global_byte_arr[$i], 1);
#print "update_xml_dbase global_byte_array $strhash $strhash1, $global_byte_arr[$i]\n";
            $$xmlref{instance}{$i}{val} = $global_byte_arr[$i];
            $$xmlref{instance}{$i}{updflag} = $xmldbase_index_updated;
        }
    } else {
        $$xmlref{val} = $conv_val;
        tree_create($strhash, $conv_val, 1);
#print "update_xml_dbase else $strhash, $val $result\n";
    }
    $flag_for_byte_offset = 0;
    return $result;
}

sub add_to_list_of_ignored_clis
{
    my $xmlinpref = $_[0];

    if (defined($$xmlinpref{clilist}) && defined($$xmlinpref{clilist}{count})) {
        for (my $i = 0; $i < $$xmlinpref{clilist}{count}; $i++) {
            print IGNORED "$$xmlinpref{clilist}{cliarray}[$i]\n";
        }
    }
} 

sub print_xml_dbase
{
    my $href = \%digit_to_tag;
    my $xmlref = \%digit_to_tag_actual;
    my $xmltotref = \%digit_to_tag_actual;
    my $fd;
    my $filename;
    my $less = "\<";
    my $grt = "\>";
    my $slash = "\/";
    my $dbqt = "\"";
    my $space = " ";
    check_for_vlan_mandatory_fields();
    foreach my $digit (sort keys %{$$xmltotref{nxt}}) {
        $href = \%{$digit_to_tag{nxt}{$digit}};
        $xmlref = \%{$digit_to_tag_actual{nxt}{$digit}};
        if (defined($xml_dbase_filename{$digit})) {
            $filename = $xmldir . $xml_dbase_filename{$digit};
            open($fd, "+>", $filename) or die "can not open file $filename";
        } else {
            print_to_console("Error: No XML file found for tag $$href{tag}\nConfig CLI:$input_command\n");
            seek(RESULTFILE,0,0);
            print RESULTFILE "Error: No XML file found for tag $$href{tag}\r\nConfig CLI:$input_command\r\n";
            exit;
        }
        print $fd "$less$XML_config_variables$grt\n";
        print $fd "$space$less$$href{tag}$grt\n";
#print "print_xml_dbase1 $digit, $filename, $$href{tag}\n";
        print_xml_dbase_recur($href, $xmlref, $fd, $space);
        print $fd "$space$less$slash$$href{tag}$grt\n";
    }
    
    if(! close($fd))
    {
      remove_xml_files();
      die "Error: File System is out of Disk Space. Config is too big to save on the disk space:$!";
    }
}

sub print_xml_dbase_recur
{
    my $href = $_[0];
    my $hinpref = $_[0];
    my $xmlref = $_[1];
    my $xmlinpref = $_[1];
    my $fd = $_[2];
    my $space = $_[3];
    my $less = "\<";
    my $grt = "\>";
    my $slash = "\/";
    my $dbqt = "\"";

    $space = $space . " ";
    if (defined($$xmlref{val})) {
#print "print_xml_dbase_recur1 $$xmlref{val}, $$href{tag}\n";
        $xml_value_entered = 1;
        print $fd "$$xmlref{val}";
    } elsif (defined($$xmlref{instance})) {
#print "print_xml_dbase_recur2 $$href{tag}\n";
        foreach my $index (sort {$a <=> $b} keys %{$$xmlref{instance}}) {
#print "print_xml_dbase_recur3 $index, $$href{tag}\n";
            $xmlinpref = \%{$$xmlref{instance}{$index}};
            if ($$xmlinpref{updflag} == $xmldbase_index_not_updated) {
#print "print_xml_dbase_recur6 $index, $$href{tag}\n";
                add_to_list_of_ignored_clis($xmlinpref);
                next;
            }
            if (defined($$xmlinpref{starttag})) {
                print $fd "\n";
            }
            if (defined($$xmlinpref{arraysize})) {
                $$hinpref{arraysize} = $$xmlinpref{arraysize};
            }
            if ($start_tag_entered == 0) {
                if (defined($$hinpref{arraysize})) {
                    if (defined($$xmlref{compind}{index})) {
                        print $fd "$space$less$$hinpref{tag} index=$dbqt$$xmlref{compind}{index}$dbqt arraySize=$dbqt$$hinpref{arraysize}$dbqt$grt";
                        $$xmlref{compind}{index} += 1;
                    } else {
                        print $fd "$space$less$$hinpref{tag} index=$dbqt$index$dbqt arraySize=$dbqt$$hinpref{arraysize}$dbqt$grt";
                    }
                } else {
                    if (defined($$xmlref{compind}{index})) {
                        print $fd "$space$less$$hinpref{tag} index=$dbqt$$xmlref{compind}{index}$dbqt$grt";
                        $$xmlref{compind}{index} += 1;
                    } else {
                        print $fd "$space$less$$hinpref{tag} index=$dbqt$index$dbqt$grt";
                    }
                }
                $start_tag_entered = 1;
            } else {
                if (defined($$hinpref{arraysize})) {
                    if (defined($$xmlref{compind}{index})) {
                        print $fd "\n$space$less$$hinpref{tag} index=$dbqt$$xmlref{compind}{index}$dbqt arraysize=$dbqt$$hinpref{arraysize}$dbqt$grt";
                        $$xmlref{compind}{index} += 1;
                    } else {
                        print $fd "\n$space$less$$hinpref{tag} index=$dbqt$index$dbqt arraysize=$dbqt$$hinpref{arraysize}$dbqt$grt";
                    }
                } else {
                    if (defined($$xmlref{compind}{index})) {
                        print $fd "\n$space$less$$hinpref{tag} index=$dbqt$$xmlref{compind}{index}$dbqt$grt";
                        $$xmlref{compind}{index} += 1;
                    } else {
                        print $fd "\n$space$less$$hinpref{tag} index=$dbqt$index$dbqt$grt";
                    }
                }
            }
            $$xmlinpref{starttag} = 1;
            print_xml_dbase_recur($hinpref, $xmlinpref, $fd, $space);
            if ($xml_value_entered == 0) {
                 print $fd "$space$less$slash$$hinpref{tag}$grt\n";
            } else {
                 print $fd "$less$slash$$hinpref{tag}$grt\n";
            }
#           print $fd "$space$less$slash$$hinpref{tag}$grt\n";
            $xml_value_entered = 0;
            $start_tag_entered = 0;
        }
    } elsif (defined($$xmlref{nxt})) {
#print "print_xml_dbase_recur4 $$href{tag}\n";
        foreach my $digit (sort keys %{$$xmlref{nxt}}) {
            $hinpref = \%{$$href{nxt}{$digit}};
            $xmlinpref = \%{$$xmlref{nxt}{$digit}};
#print "print_xml_dbase_recur5 $digit, $$hinpref{tag}\n";
            if (!defined($$xmlinpref{instance})) {
                if ($start_tag_entered == 0) {
                    print $fd "$space$less$$hinpref{tag}$grt";
                    $start_tag_entered = 1;
                } else {
                    print $fd "\n$space$less$$hinpref{tag}$grt";
                }
            }
            print_xml_dbase_recur($hinpref, $xmlinpref, $fd, $space);
            if (!defined($$xmlinpref{instance})) {
                if ($xml_value_entered == 0) {
                    print $fd "$space$less$slash$$hinpref{tag}$grt\n";
                } else {
                    print $fd "$less$slash$$hinpref{tag}$grt\n";
                }
            }
            $xml_value_entered = 0;
            $start_tag_entered = 0;
        }
    }
}

sub check_and_get_array_dbase_level
{
    my $fld = $_[0];
    my $indtype = $_[1];
    my $plevel = $_[2];
    my $result = $PARAM_UPDATE_SUCCESS;

    $href = \%digit_to_tag;
    $$plevel = 0;
    my @temp = split(/\./, $fld);
    for (my $i = 0; $i <= $#temp; $i++) {
        if (defined($$href{nxt}{$temp[$i]})) {
            $href = \%{$$href{nxt}{$temp[$i]}};
            if (defined($$href{array})) {
                $$plevel += 1;
            }
        } else {
            print_to_console("Error: Invalid field $fld sent in check_and_get_array_dbase_level\nConfig CLI:$input_command\n");
            seek(RESULTFILE,0,0);
            print RESULTFILE "Error: Invalid field $fld sent in check_and_get_array_dbase_level\r\nConfig CLI:$input_command\r\n";
            exit;
        }
        if ($i == $#temp && defined($$href{array}) && ($$href{array} == 1 || $last_string_byte_array_flag == 1) && ($indtype == $created_input_index || $indtype == $created_input_index_with_offset) && $last_array_flag == 0) {
            delete($$href{array});
            $$plevel -= 1;
            if ($last_string_byte_array_flag == 1) {
                $$href{bytearray} = 1;
            }
        }
    }
    if ($$plevel == 0) {
        print_to_console("Error: No array base present for the field $fld in check_and_get_array_dbase_level\nConfig CLI:$input_command\n");
        seek(RESULTFILE,0,0);
        print RESULTFILE "Error: No array base present for the field $fld in check_and_get_array_dbase_level\r\nConfig CLI:$input_command\r\n";
        exit;
    }
    $$plevel -= 1;
    return $result;
}

sub ascii_to_hex
{
    my $actstr = $_[0];
    my $string;
    my $index;
    my $hexchars = "";
    my $result ; 

    $result = param_value_return($actstr, \$string);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $index = param_local_index_return($actstr);
    foreach my $c (split(//,$string)) {
        $hexchars .= sprintf "%x", ord($c);
    }
    $gbl_local_node_value[$index] = $hexchars;
# print "ascii_to_hex1 $index, $hexchars\n";
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}

sub update_field_with_operated_value_guest
{
    my $input = $_[0];
    my $actfld;
    my $actval1;
    my $actval2;
    my $actop;
    my $fld;
    my $val1;
    my $val2;
    my $op;
    my $val;
    my $result;

    ($actfld, $actval1, $actval2, $actop) = split(/\,/, $input, 4);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval1, \$val1);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval2, \$val2);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actop, \$op);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

	if($is_szabla == 1) {
		if($val2 == 513) {
			$val2 = 17;
	    }
	}

    if ($op == $add_op) {
        $val = $val1 + $val2;
    } elsif ($op == $sub_op) {
        $val = $val1 - $val2;
    } elsif ($op == $mul_op) {
        $val = $val1 * $val2;
    } elsif ($op == $div_op) {
        $val = $val1 / $val2;
    } else {
        print_to_console("Error: Wrong operator entered in database should be 1 = add, 2 = sub, 3 = mul or 4 = div\n");
        seek(RESULTFILE,0,0);
        print RESULTFILE "Error: Wrong operator entered in database should be 1 = add, 2 = sub, 3 = mul or 4 = div\r\n";
        exit;
    }

    update_local_dbase($fld, $val);
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;    
}
sub update_field_with_operated_value
{
    my $input = $_[0];
    my $actfld;
    my $actval1;
    my $actval2;
    my $actop;
    my $fld;
    my $val1;
    my $val2;
    my $op;
    my $val;
    my $result;

    ($actfld, $actval1, $actval2, $actop) = split(/\,/, $input, 4);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval1, \$val1);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval2, \$val2);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actop, \$op);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    if ($op == $add_op) {
        $val = $val1 + $val2;
    } elsif ($op == $sub_op) {
        $val = $val1 - $val2;
    } elsif ($op == $mul_op) {
        $val = $val1 * $val2;
    } elsif ($op == $div_op) {
        $val = $val1 / $val2;
    } else {
        print_to_console("Error: Wrong operator entered in database should be 1 = add, 2 = sub, 3 = mul or 4 = div\n");
        seek(RESULTFILE,0,0);
        print RESULTFILE "Error: Wrong operator entered in database should be 1 = add, 2 = sub, 3 = mul or 4 = div\r\n";
        exit;
    }

    update_local_dbase($fld, $val);
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;    
}

sub update_field_with_operated_index
{
    my $input = $_[0];
    my $actfld;
    my $actval1;
    my $actval2;
    my $actop;
    my $fld;
    my $val1;
    my $val2;
    my $op;
    my $val;
    my $result;
    my $level=0;
    my $xmlref = \%digit_to_tag_actual;

    ($actfld, $actval1, $actval2, $actop) = split(/\,/, $input, 4);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval1, \$val1);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval2, \$val2);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actop, \$op);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    my @temp = split(/\./, $val1);
    for (my $i = 0; $i <= $#temp; $i++) {
        if (defined($$xmlref{nxt}{$temp[$i]})) {
            $xmlref = \%{$$xmlref{nxt}{$temp[$i]}};
            if (defined($$xmlref{instance})) {
                $xmlref = \%{$$xmlref{instance}{$array_index{index}[$level]}};
                $level += 1;
            }
        }
    }

    if($level > 0) {
        $val =  $array_index{index}[$level-1]; 
	}
	elsif($level == 0) {
        $val =  $array_index{index}[$level]; 
    } else {
        return $result;
    }

    if ($op == $add_op) {
        $val = $val + $val2;
    } elsif ($op == $sub_op) {
        $val = $val - $val2;
    } elsif ($op == $mul_op) {
        $val = $val * $val2;
    } elsif ($op == $div_op) {
        $val = $val / $val2;
    } else {
        print_to_console("Error: Wrong operator entered in database should be 1 = add, 2 = sub, 3 = mul or 4 = div\n");
        seek(RESULTFILE,0,0);
        print RESULTFILE "Error: Wrong operator entered in database should be 1 = add, 2 = sub, 3 = mul or 4 = div\r\n";
        exit;
    }

    update_local_dbase($fld, $val);
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;    
}

sub search_key_operated_index
{
    my $input = $_[0];
    my $actfld;
    my $actval1;
    my $actval2;
    my $actop;
    my $fld;
    my $val1;
    my $val2;
    my $op;
    my $val;
    my $result;

    ($actfld, $actval1, $actval2, $actop) = split(/\,/, $input, 4);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval1, \$val1);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval2, \$val2);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actop, \$op);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $input_index_type = $useasis_input_index;
    $result = check_and_get_array_dbase_level($fld, $input_index_type, \$dim);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    if ($op == $add_op) {
        $val = $val1 + $val2;
    } elsif ($op == $sub_op) {
        $val = $val1 - $val2;
    } elsif ($op == $mul_op) {
        $val = $val1 * $val2;
    } elsif ($op == $div_op) {
        $val = $val1 / $val2;
    } else {
        print_to_console("Error: Wrong operator entered in database should be 1 = add, 2 = sub, 3 = mul or 4 = div\n");
        seek(RESULTFILE,0,0);
        print RESULTFILE "Error: Wrong operator entered in database should be 1 = add, 2 = sub, 3 = mul or 4 = div\r\n";
        exit;
    }

    $array_index{index}[$dim] = $val;
#print "search_key_operated_index $val, $dim, $index\n";
    $array_index{flag}[$dim] = $xmldbase_index_not_updated;
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}

sub set_key_map_index_last_array
{
    my $input = $_[0];
    my $result;

    $input_index_type = $mapped_input_index;
    $xml_dbase_index_update_reqd = $xmldbase_index_updated;
    $xml_dbase_update_reqd = 0;
    $last_array_flag = 1;
    $result = set_search_key_field_internal($input);
    $last_array_flag = 0;
    return $result;
}

sub set_key_operated_index
{
    my $input = $_[0];
    my $actfld;
    my $actval1;
    my $actval2;
    my $actop;
    my $fld;
    my $val1;
    my $val2;
    my $op;
    my $val;
    my $result;

    ($actfld, $actval1, $actval2, $actop) = split(/\,/, $input, 4);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval1, \$val1);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval2, \$val2);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actop, \$op);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $input_index_type = $useasis_input_index;
    $result = check_and_get_array_dbase_level($fld, $input_index_type, \$dim);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    if ($op == $add_op) {
        $val = $val1 + $val2;
    } elsif ($op == $sub_op) {
        $val = $val1 - $val2;
    } elsif ($op == $mul_op) {
        $val = $val1 * $val2;
    } elsif ($op == $div_op) {
        $val = $val1 / $val2;
    } else {
        print_to_console("Error: Wrong operator entered it should be 1 = add, 2 = sub, 3 = mul or 4 = div\n");
        seek(RESULTFILE,0,0);
        print RESULTFILE "Error: Wrong operator entered it should be 1 = add, 2 = sub, 3 = mul or 4 = div\r\n";
        exit;
    }

    $array_index{index}[$dim] = $val;
# print "set_search_key_field_internal11 $val, $dim, $index\n";
    $array_index{flag}[$dim] = $xmldbase_index_updated;
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;    
}

sub set_key_operated_index_new_str_bytearray
{
    my $input = $_[0];
    my $actfld;
    my $actval1;
    my $actval2;
    my $actop;
    my $actstring;
    my $fld;
    my $val1;
    my $val2;
    my $op;
    my $val;
    my $string;
    my $result;
    my $xmlref = \%digit_to_tag_actual;
    my $newxmlref = \%digit_to_tag_actual;
    my $tempCnt;
    my @temp;
    my $inst_present = 0;
    my $pxmlref;
    my $newpxmlref;
    my $pcreateref;
    my $inst = "";
    my $inst_present = 0;

    ($actfld, $actval1, $actval2, $actop, $actstring) = split(/\,/, $input, 5);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval1, \$val1);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval2, \$val2);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actop, \$op);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actstring, \$string);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $input_index_type = $created_input_index;
    $last_string_byte_array_flag = 1;
    $result = check_and_get_array_dbase_level($fld, $input_index_type, \$dim);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $last_string_byte_array_flag = 0;
    $input_index_type = $created_useasis_input_index;

    if ($op == $add_op) {
        $val = $val1 + $val2;
    } elsif ($op == $sub_op) {
        $val = $val1 - $val2;
    } elsif ($op == $mul_op) {
        $val = $val1 * $val2;
    } elsif ($op == $div_op) {
        $val = $val1 / $val2;
    } else {
        print_to_console("Error: Wrong operator entered it should be 1 = add, 2 = sub, 3 = mul or 4 = div\n");
        seek(RESULTFILE,0,0);
        print RESULTFILE "Error: Wrong operator entered it should be 1 = add, 2 = sub, 3 = mul or 4 = div\r\n";
        exit;
    }
    $flag_set_supplied_index = 1;
    $result = add_field_to_create_index_hash($input_index_type, $fld, $string, 0, $dim, \$val);
    $flag_set_supplied_index = 0;

    $array_index{index}[$dim] = $val;
    $array_index{flag}[$dim] = $xmldbase_index_updated;
#print "set_key_operated_index_new-- $val, $dim, $input_command,$fld,$string \n";

    @temp = split(/\./, $fld);

    for (my $i = 0; $i < $dim; $i++) {
        $inst_present = 1;
        if ($i == 0) {
            $inst = $array_index{index}[$i];
        } else {
            $inst = $inst . "-" . $array_index{index}[$i];
        }
    }

    for (my $i = 0; $i <= $#temp; $i++) {
        if (defined($$xmlref{nxt}{$temp[$i]}) && defined($$xmlref{nxt}{$temp[$i]})) {
            $xmlref = \%{$$xmlref{nxt}{$temp[$i]}};
            $newxmlref = \%{$$newxmlref{nxt}{$temp[$i]}};
            $tempCnt = $i;
        }
    }
    if (defined($$xmlref{instance})) {
        foreach my $key (keys %{$$xmlref{instance}}) {
            if ($key =~ "dummy") {
                $pxmlref = \%{$$xmlref{instance}{$key}};
                $newpxmlref = \%{$$newxmlref{instance}{$val}};
#print " new action 2 $$xmlref{instance}{$key},$key , $val,$inst\n";
                shift_old_to_new($pxmlref, $newpxmlref);
                $$newpxmlref{updflag} = $xmldbase_index_updated;
#print "set_key_operated_index_new1 $val, $newpxmlref, $newxmlref\n";
                delete($$xmlref{instance}{$key});
            }
        }
    }

    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;    
}

sub set_key_useasis_index
{
    my $input = $_[0];
    my $result;

    $input_index_type = $useasis_input_index;
    $xml_dbase_index_update_reqd = $xmldbase_index_updated;
    $xml_dbase_update_reqd = 0;
    $result = set_search_key_field_internal($input);
    return $result;
}

sub search_key_useasis_index
{
    my $input = $_[0];
    my $result;

    $input_index_type = $useasis_input_index;
    $xml_dbase_index_update_reqd = $xmldbase_index_not_updated;
    $xml_dbase_update_reqd = 0;
    $result = set_search_key_field_internal($input);
    return $result;
}

sub set_key_map_index
{
    my $input = $_[0];
    my $result;

    $input_index_type = $mapped_input_index;
    $xml_dbase_index_update_reqd = $xmldbase_index_updated;
    $xml_dbase_update_reqd = 0;
    $result = set_search_key_field_internal($input);
    return $result;
}

sub search_key_map_index
{
    my $input = $_[0];
    my $result;

    $input_index_type = $mapped_input_index;
    $xml_dbase_index_update_reqd = $xmldbase_index_not_updated;
    $xml_dbase_update_reqd = 0;
    $result = set_search_key_field_internal($input);
    return $result;
}

sub search_key_field_useasis_index
{
    my $input = $_[0];
    my $result;

    $input_index_type = $useasis_input_index;
    $xml_dbase_index_update_reqd = $xmldbase_index_not_updated;
    $xml_dbase_update_reqd = 1;
    $result = set_search_key_field_internal($input);
    return $result;
}

sub set_key_field_useasis_index
{
    my $input = $_[0];
    my $result;

    $input_index_type = $useasis_input_index;
    $xml_dbase_index_update_reqd = $xmldbase_index_updated;
    $xml_dbase_update_reqd = 1;
    $result = set_search_key_field_internal($input);
    return $result;
}

sub search_key_field_map_index
{
    my $input = $_[0];
    my $result;

    $input_index_type = $mapped_input_index;
    $xml_dbase_index_update_reqd = $xmldbase_index_not_updated;
    $xml_dbase_update_reqd = 1;
    $result = set_search_key_field_internal($input);
    return $result;
}

sub set_key_field_map_index
{
    my $input = $_[0];
    my $result;

    $input_index_type = $mapped_input_index;
    $xml_dbase_index_update_reqd = $xmldbase_index_updated;
    $xml_dbase_update_reqd = 1;
    $result = set_search_key_field_internal($input);
    return $result;
}
sub set_key_field_create_index_with_interfaceId
{
    my $input = $_[0];
    my $result;
    $input_index_type = $created_input_index;
    $xml_dbase_index_update_reqd = $xmldbase_index_updated;
    $xml_dbase_update_reqd = 1;
    $result = set_search_key_field_internal_interfaceId($input);
    return $result;
}

sub search_key_field_create_index_for_mac
{
    my $input = $_[0];
    my $result;
    $glb_flag_mac_add = 1;
    $input_index_type = $created_input_index;
    $xml_dbase_index_update_reqd = $xmldbase_index_not_updated;
    $xml_dbase_update_reqd = 1;
    $result = set_search_key_field_internal($input);
    $glb_flag_mac_add = 0;
    return $result;
}

sub search_key_field_create_index
{
    my $input = $_[0];
    my $result;

    $input_index_type = $created_input_index;
    $xml_dbase_index_update_reqd = $xmldbase_index_not_updated;
    $xml_dbase_update_reqd = 1;
    $result = set_search_key_field_internal($input);
    return $result;
}

sub search_key_field_create_index_str_bytearray
{
    my $input = $_[0];
    my $result;

    $input_index_type = $created_input_index;
    $xml_dbase_index_update_reqd = $xmldbase_index_not_updated;
    $xml_dbase_update_reqd = 1;
    $last_string_byte_array_flag = 1;
    $result = set_search_key_field_internal($input);
    $last_string_byte_array_flag = 0;
    $last_array_flag = 0;
    return $result;
}

sub set_key_field_create_index_str_bytearray
{
    my $input = $_[0];
    my $result;

    $input_index_type = $created_input_index;
    $xml_dbase_index_update_reqd = $xmldbase_index_updated;
    $xml_dbase_update_reqd = 1;
    $last_string_byte_array_flag = 1;
#print "set_key_field_create_index_str_bytearray $input_command, $input\n";
    $result = set_search_key_field_internal($input);
    $last_string_byte_array_flag = 0;
    return $result;
}

sub set_key_field_create_index_str_bytearray_ssidList_specific
{
    my $input = $_[0];
    my $result;
    my $actfld;
    my $actval;
    my $actrulename;
    my $fld;
    my $val;
    my $rulename;
    my $offset;

    ($actfld, $actval, $actrulename) = split(/$nodeparamconnector/, $input, 3);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    #$result = check_and_get_array_dbase_level($fld, $input_index_type, \$dim);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval, \$val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actrulename, \$rulename);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    
    $input = $actfld . "$nodeparamconnector" . $actval;
    $input_index_type = $created_input_index;
    $xml_dbase_index_update_reqd = $xmldbase_index_updated;
    $xml_dbase_update_reqd = 1;
    $last_string_byte_array_flag = 1;
#Added to global hash for index storage to be used in ssidList byte generation
    if (defined ($global_bytearray_index_start{$rulename})) { 
        $global_bytearray_index_start{$rulename} += 1;
        $offset = $global_bytearray_index_start{$rulename};
        $global_bytearray_index = $offset * $gbl_offset; 
#print "set_key_field_create_index_str_bytearray_ssidList_specific1 $rulename, $val $global_bytearray_index--dim $dim\n";
    #    $array_index{index}[$dim] = $index;
        $array_index{index}[$dim] = 0;
        $array_index{flag}[$dim] = $xml_dbase_index_update_reqd;
        update_local_dbase($fld, $val);
    } else {
        $result = set_search_key_field_internal($input);
        $last_string_byte_array_flag = 0;
        $global_bytearray_index_start{$rulename} = 0;
        $offset = $global_bytearray_index_start{$rulename};
        $global_bytearray_index = $offset * $gbl_offset; 
#print "set_key_field_create_index_str_bytearray_ssidList_specific2 $rulename, $val $global_bytearray_index\n";
    }
    return $result;
}

sub search_key_field_create_index_modified_str_bytearray
{
    my $input = $_[0];
    my $result;

    $input_index_type = $created_useasis_input_index;
    $xml_dbase_index_update_reqd = $xmldbase_index_not_updated;
    $xml_dbase_update_reqd = 1;
    $flag_index_set_diff = 1;
#print "search_key_field_create_index_modified $input $input_command\n";
    $result = set_search_key_field_internal($input);
    $flag_index_set_diff = 0;
    return $result;
}

sub set_key_field_create_index_for_mac
{

    my $input = $_[0];
    my $result;
    $glb_flag_mac_add = 1;
    $input_index_type = $created_input_index;
    $xml_dbase_index_update_reqd = $xmldbase_index_updated;
    $xml_dbase_update_reqd = 1;
    $result = set_search_key_field_internal($input);
    $glb_flag_mac_add = 0;
    return $result;
}

sub set_key_field_create_index
{
    my $input = $_[0];
    my $result;

    $input_index_type = $created_input_index;
    $xml_dbase_index_update_reqd = $xmldbase_index_updated;
    $xml_dbase_update_reqd = 1;
    $result = set_search_key_field_internal($input);
    return $result;
}

####################################################################################################################
#
# 1.config mobility group member add <mac>   <ip>    <group-name> 
# 2.config mobility group member add <ip> group-name <group-name> mac-address <mac-address> public-ip-address <pubIp>
#                                      ^
#                                      |
# This function is called everytime for keywords/Values pointed above 
#
####################################################################################################################
sub set_key_field_for_new_mobility
{
    my $input = $_[0];
    my $result;

    my @temp = split(/\,/, $input);

    $result = param_value_return($temp[1], \$ip);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    #If this is the first time invocation we should read from 
    if ($new_mobility_enabled == 2) {
        #open(DB114,"$mobilityFlag") or die "Can't open format specifier database File- mobilityFlag";
        open(DB115,"$mobilityFlag") or $new_mobility_enabled = 0;
            for $line(<DB115>) {
                chomp $line;
                if ($line == 0 || $line == 1){
                    $new_mobility_enabled = $line;
                } else {
                    $new_mobility_enabled = 0;
                }
            } 
    }

    # Reset the global variables for the new CLI
    $mobility_success_case = 0;
    $keyword_map_for_new_mobility = 0;
    $current_keyword_for_new_mobility = 0;
    if (($new_mobility_enabled == 1) && ($ip =~ /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/)) {
        $mobility_success_case = 1;
        #Case of new mobility, have to create an idex
        $result = set_key_field_create_index($input);
        if ($result == 7){
            $result = check_group_member_ip_with_mgmt($input);
            update_field($input);
        }
        return $result;
    } else {
        #Case of old mobility, don't have to do anything or a failure case
        $make_next_node_mandatory = 1;
        return $ADVANCE_TO_NEXT_DEPTH;
    }
}

####################################################################################################################
#
# 1.config mobility group member add <mac>   <ip>    <group-name> 
# 2.config mobility group member add <ip> group-name <group-name> mac-address <mac-address> public-ip-address <pubIp>
#                                              ^                      ^                           ^                        
#                                              |                      |                           |                        
# This function is called everytime for keywords/Values pointed above 
#
####################################################################################################################
sub update_ip_for_old_mobility_keyword_for_new_mobility
{
    my $input = $_[0];
    my $result = $NOOP_CLI_RETURN_OPTION;
    my $keyword_local = 0;
    my @temp = split(/\,/, $input);
    my $mapGroupName = 1;
    my $mapPubIp     = 2;
    my $mapMac       = 4;

    $result = param_value_return($temp[1], \$keyword);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    if ($new_mobility_enabled) {
        #new mobility enabled case, Take care of the error cases
        #Look for the keyword, otherwise return failure
        if ($keyword eq 'group-name'){
            $keyword_local = $mapGroupName; 
        } elsif ($keyword eq 'public-ip-address'){
            $keyword_local = $mapPubIp; 
        } elsif ($keyword eq 'mac-address') {
            $keyword_local = $mapMac; 
        } else {
            return $INVALID_CLI_OPTION; 
        }

        # If say, the keyword is already seen, then do not allow it next time
        if (($keyword_local & $keyword_map_for_new_mobility) == $keyword_local){
            return $INVALID_CLI_OPTION; 
        } else {
            $keyword_map_for_new_mobility |= $keyword_local;
            #print $keyword_map_for_new_mobility, "we found it to be proper, so should make the next node mandatory\n";
            $current_keyword_for_new_mobility = $keyword_local;
            $make_next_node_mandatory = 1;
        }
    } else {
        
        #Old mobility enabled case, Expect IP here
        if( ($keyword eq 'group-name') || ($keyword eq 'public-ip-address') || ($keyword eq 'mac-address') ){
            return $INVALID_CLI_OPTION; 
        }
        
        $result = set_key_field_create_index($input);
        if ($result == 7){
            $mobility_success_case = 1;
            $result = check_group_member_ip_with_mgmt($input);
            update_field($input);
        }
    }
    return $result;
}

####################################################################################################################
#
# 1.config mobility group member add <mac>   <ip>    <group-name> 
# 2.config mobility group member add <ip> group-name <group-name> mac-address <mac-address> public-ip-address <pubIp>
#                                                         ^                         ^                            ^                        
#                                                         |                         |                            |                        
# This function is called everytime for keywords/Values pointed above 
#
####################################################################################################################
sub update_paramenter_for_new_mobility_based_on_keyword {
    my $input = $_[0];
    my $result = $NOOP_CLI_RETURN_OPTION;
    my $fld;
    my $val;
    my @temp = split(/\,/, $input);

    if ($new_mobility_enabled) {
        #group-name public-ip-address mac-address
        if ($current_keyword_for_new_mobility == 1){
            #GroupName should be updated
            #ptr_mmCfgData.mwarList.group
            $result = param_value_return($temp[0], \$fld);
            if ($result != $PARAM_UPDATE_SUCCESS) {
                return $result;
            }
        } elsif ($current_keyword_for_new_mobility == 2){ 
            #Public-ip-address should be updated
            #ptr_mmCfgData.mwarList.peerAddr.pubIp
            $result = param_value_return($temp[1], \$fld);
            if ($result != $PARAM_UPDATE_SUCCESS) {
                return $result;
            }
        } elsif ($current_keyword_for_new_mobility == 4){ 
            #mac-address should be updated
            #ptr_mmCfgData.mwarList.peerAddr.mac.id
            $result = param_value_return($temp[2], \$fld);
            if ($result != $PARAM_UPDATE_SUCCESS) {
                return $result;
            }
        }
    } else {
            #GroupName should be updated in the old mobility case
            #ptr_mmCfgData.mwarList.group
            $result = param_value_return($temp[0], \$fld);
            if ($result != $PARAM_UPDATE_SUCCESS) {
                return $result;
            }
    }

    $result = param_value_return($temp[3], \$val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    update_local_dbase($fld, $val);
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}

########################################################################
#                                                                      #
# Will be called for every successful updation of mobility peer data   #
# to increment mwarCnt`                                                #
#                                                                      #
########################################################################
sub increment_field_mobility
{
    my $input = $_[0];
    my $result = $NOOP_CLI_RETURN_OPTION;
    
    if ($mobility_success_case == 1){
        $result = increment_field($input);
    }
    $mobility_success_case = 0;
    return $result;
}

########################################################################
#                                                                      #
# Will be functional in the case of old mobility                       #
# Would be used to update mac in the old mobility case                 #
#                                                                      #
########################################################################
sub update_field_with_mac_delimiter_new_mobility
{
    my $input = $_[0];
    my $result = $NOOP_CLI_RETURN_OPTION;
    if ($new_mobility_enabled == 0) {
        $result = update_field_with_mac_delimiter($input);
    }
    return $result;
}


sub search_key_field_create_index_moblity_anchor
{
    my $input = $_[0];
    my $result;

    my @temp = split(/\,/, $input);

    $result = param_value_return($temp[1], \$ip);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $input_index_type = $created_input_index;
	
	if( ($ip eq $mgmt_ip_addr) || ($ip eq $ipv6_mgmt_address)) {
			$xml_dbase_index_update_reqd = $xmldbase_index_updated;
	} else {
			$xml_dbase_index_update_reqd = $xmldbase_index_not_updated;
	}
    $xml_dbase_update_reqd = 1;
    $result = set_search_key_field_internal($input);
    return $result;
}
sub set_key_field_create_index_with_offset
{
    my $input = $_[0];
    my $result;

    $input_index_type = $created_input_index_with_offset;
    $xml_dbase_index_update_reqd = $xmldbase_index_updated;
    $xml_dbase_update_reqd = 1;
    $result = set_search_key_field_internal($input);
    return $result;
}

sub set_key_field_create_index_last_array
{
    my $input = $_[0];
    my $result;

    $input_index_type = $created_input_index;
    $last_array_flag = 1;
    $xml_dbase_index_update_reqd = $xmldbase_index_updated;
    $xml_dbase_update_reqd = 1;
    $result = set_search_key_field_internal($input);
    $last_array_flag = 0;
    flush_local_dbase();
    return $result;
}

sub set_key_field_create_index_for_sigId
{
    my $input = $_[0];
    my $result;
    my $sigId;

    my @temp = split(/\,/, $input);

    $result = param_value_return($temp[1], \$sigId);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    if (!defined($sigIdMap{$sigId})) {
        $sigIdMap{$sigId} = $glb_sigId_index;
#print "set_key_field_create_index_for_sigId  $sigId = $glb_sigId_index\n";
        $glb_sigId_index += 1;
    }

    $input_index_type = $created_input_index;
    $last_array_flag = 1;
    $xml_dbase_index_update_reqd = $xmldbase_index_updated;
    $xml_dbase_update_reqd = 1;
    $result = set_search_key_field_internal($input);
    $last_array_flag = 0;
    flush_local_dbase();
    return $result;
}

sub set_key_field_create_index_with_interfaceId_conditional
{
    my $input = $_[0];
    my $result = $NOOP_CLI_RETURN_OPTION;
    my $actfld;
    my $actval;
    my $fld;
    my $val;

    if ($upd_foxhound_intf) {
        set_key_field_create_index_with_interfaceId($input);

        my @temp = split(/\,/, $input);

        for(my $i = 4; $i <= $#temp; $i++){
            $actfld = $temp[$i];
            $actval = $temp[$i+1];
            $i++;
            $result = param_value_return($actfld, \$fld);
            if ($result != $PARAM_UPDATE_SUCCESS) {
                return $result;
            }
            $result = param_value_return($actval, \$val);
            if ($result != $PARAM_UPDATE_SUCCESS) {
                return $result;
            }
            update_local_dbase($fld, $val);
        }
    }
    return $result;
}

sub set_key_field_create_index_last_array_multiple_input
{
    my $input = $_[0];
    my $result = $NOOP_CLI_RETURN_OPTION;
    my $actfld;
    my $actfldcnt;
    my $actfldcountry;
    my $actval;
    my $fld;
    my $fldcnt;
    my $fldcountry;
    my $val;
    my $dim;
    my $init;
    my $str;
    my $index;
    my @multiple_values;

    my @temp = split(/\,/, $input);
    $input_index_type =  $created_input_index;
    $xml_dbase_index_update_reqd = $xmldbase_index_updated;
    $xml_dbase_update_reqd = 1;

    $actfld = $temp[0];
    $actval = $temp[1];
    $actfldcnt = $temp[2];
    $actfldcountry = $temp[3];

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actfldcnt, \$fldcnt);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actfldcountry, \$fldcountry);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $last_array_flag = 1;
    $result = check_and_get_array_dbase_level($fld, $input_index_type, \$dim);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $last_array_flag = 0;

#print "set_key_field_create_index_last_array_multiple_input1 $input, $fld\n";

    $result = param_value_return($actval, \$val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    @multiple_values = split(',', $val);
    for (my $i = 0; $i <=$#multiple_values; $i++) {
        $multiple_values[$i] =~ tr/[a-z]/[A-Z]/;
        if(length($multiple_values[$i]) == 2) {
            $multiple_values[$i].= " ";
        }
        $index = $multiple_values[$i];
#print "set_key_field_create_index_last_array_multiple_input2 $input, $result, $fld, $dim, $multiple_values[$i]\n";

        $result = add_field_to_create_index_hash($input_index_type, $fld, $multiple_values[$i], 0, $dim, \$index);
#print "set_key_field_create_index_last_array_multiple_input3 $fld,$dim, $index\n";
        if ($result != $PARAM_UPDATE_SUCCESS) {
            $clitoxmldb1_index += 1;
            return $result;
        }

        $array_index{index}[$dim] = $index;
        $array_index{flag}[$dim] = $xml_dbase_index_update_reqd;
#print "set_key_field_create_index_last_array_multiple_input4 $fld,$dim, $index,$multiple_values[$i], $xml_dbase_update_reqd\n";
        if ($xml_dbase_update_reqd) {
#print " $fld,$multiple_values[$i], $xml_dbase_update_reqd\n";
            update_local_dbase($fld, $multiple_values[$i]);
            $result = update_xml_dbase_with_localdb(1);
            delete_local_dbase();
            if ($result != $NOOP_CLI_RETURN_OPTION) {
                return $result;
            }
        }
    }
        update_local_dbase($fldcnt, ($#multiple_values+1));
        $result = update_xml_dbase_with_localdb(1);
        delete_local_dbase();
        if ($result != $NOOP_CLI_RETURN_OPTION) {
            return $result;
        }
    if($#multiple_values > 0) {

        $array_index{index}[$dim] = $index + 1;
        update_local_dbase($fldcountry, "ZZ ");
        $result = update_xml_dbase_with_localdb(1);
        delete_local_dbase();
        if ($result != $NOOP_CLI_RETURN_OPTION) {
            return $result;
        }
        update_country_code_info("ZZ ");
    }
    else {
        update_local_dbase($fldcountry, $multiple_values[0]);
        $result = update_xml_dbase_with_localdb(1);
        delete_local_dbase();
        if ($result != $NOOP_CLI_RETURN_OPTION) {
            return $result;
        }
        update_country_code_info($multiple_values[0]);
    }
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}

sub delete_instance
{
    return $NOOP_CLI_RETURN_OPTION;
}

sub check_for_digits
{
    my $val = $_[0];

    if (($val =~ /\D/) && ($val !~ /^\-/)) {
        return $VALUE_HAS_NON_DIGIT_CHARS;
    } 
    return $PARAM_UPDATE_SUCCESS;
}

sub set_key_field_create_index_with_interfaceId_qvlan
{
    my $input = $_[0];
    my $result;
    $input_index_type = $created_input_index;
    $xml_dbase_index_update_reqd = $xmldbase_index_updated;
    $xml_dbase_update_reqd = 1;
    $result = set_search_key_field_internal_interfaceId_qvlan($input);
    return $result;
}

sub set_search_key_field_internal_interfaceId_qvlan
{
    my $input = $_[0];
    my $result = $NOOP_CLI_RETURN_OPTION;
    my $actfld1;
    my $actval1;
    my $actfld2;
    my $actval2;
    my $actmap;
    my $actinit;
    my $fld1;
    my $val1;
    my $fld2;
    my $val2;
    my $dim;
    my $map;
    my $init;
    my $str;
    my $index;
    my @temp = split(/\,/, $input);

    $actfld1 = $temp[0];
    $actval1 = $temp[1];
    $actfld2 = $temp[2];
    $actval2 = $temp[3];

    $result = param_value_return($actfld1, \$fld1);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actfld2, \$fld2);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = check_and_get_array_dbase_level($fld1, $input_index_type, \$dim);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actval1, \$val1);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actval2, \$val2);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $index = $val1;
    $val1 = $qvlan_name . $val1;
#print "set_search_key_field_internal_interfaceId_qvlan $qvlan_val\n";

    $result = add_field_to_create_index_hash($input_index_type, $fld1, $val1, 0, $dim, \$index);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        $clitoxmldb1_index += 1;
        return $result;
    }

    $array_index{index}[$dim] = $index;
    $val = $index + $val2;
    $array_index{flag}[$dim] = $xml_dbase_index_update_reqd;
    update_local_dbase($fld1, $val1);
    update_local_dbase($fld2, $val);
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}

sub set_search_key_field_internal_interfaceId
{
    my $input = $_[0];
    my $result = $NOOP_CLI_RETURN_OPTION;
    my $actfld1;
    my $actval1;
    my $actfld2;
    my $actval2;
    my $actmap;
    my $actinit;
    my $fld1;
    my $val1;
    my $fld2;
    my $val2;
    my $dim;
    my $map;
    my $init;
    my $str;
    my $index;
    my @temp = split(/\,/, $input);


    $actfld1 = $temp[0];
    $actval1 = $temp[1];
    $actfld2 = $temp[2];
    $actval2 = $temp[3];

    $result = param_value_return($actfld1, \$fld1);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actfld2, \$fld2);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = check_and_get_array_dbase_level($fld1, $input_index_type, \$dim);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actval1, \$val1);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actval2, \$val2);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $index = $val1;

    $result = add_field_to_create_index_hash($input_index_type, $fld1, $val1, 0, $dim, \$index);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        $clitoxmldb1_index += 1;
        return $result;
    }

    $array_index{index}[$dim] = $index;
    $val = $index + $val2;
    $array_index{flag}[$dim] = $xml_dbase_index_update_reqd;
    update_local_dbase($fld1, $val1);
    update_local_dbase($fld2, $val);
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}

sub set_search_key_field_internal
{
    my $input = $_[0];
    my $result = $NOOP_CLI_RETURN_OPTION;
    my $actfld;
    my $actval;
    my $actmap;
    my $actinit;
    my $fld;
    my $val;
    my $dim;
    my $map;
    my $init;
    my $str;
    my $index;

    my @temp = split(/\,/, $input);
    
# print "set_search_key_field_internal $input\n";
    if ($input_index_type == $mapped_input_index) {
        if (!defined($temp[2])) {
            print_to_console("Error: mapped key needs map as input\n");
            seek(RESULTFILE,0,0);
            print RESULTFILE "Error: mapped key needs map as input\r\n";
            exit;
        } else {
            $actmap = $temp[2];
        }
    } elsif ($input_index_type == $created_input_index) {
        if (defined($temp[2])) {
            $actinit = $temp[2];
        }
    } elsif ($input_index_type == $created_input_index_with_offset) {
        if (defined($temp[2])) {
            $actinit = $temp[2];
        }
    }

    $actfld = $temp[0];
    $actval = $temp[1];

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
# print "set_search_key_field_internal1 $input, $result\n";
        return $result;
    }

# print "set_search_key_field_internal13 $actfld, $fld \n";
    $result = check_and_get_array_dbase_level($fld, $input_index_type, \$dim);
    if ($result != $PARAM_UPDATE_SUCCESS) {
# print "set_search_key_field_internal2 $input, $result\n";
        return $result;
    }

    $result = param_value_return($actval, \$val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
# print "set_search_key_field_internal3 $input, $result\n";
        return $result;
    }
    if($glb_flag_mac_add == 1) {
# print "MAC ADD is called $val \n";
        $result = do_mac_add_validation(\$val); 
        if ($result != $PARAM_UPDATE_SUCCESS) {
            return $result;
        }
    }
    $index = $val;
#print "set_search_key_field_internal12 $input, $result, $fld, $dim, $val\n";
    if ($input_index_type == $useasis_input_index) {
        $result = check_for_digits($val);
        if ($result != $PARAM_UPDATE_SUCCESS) {
# print "set_search_key_field_internal4 $input, $result\n";
            return $result;
        }
    }

    if ($input_index_type == $mapped_input_index) {
        $result = param_value_return($actmap, \$map);
        if ($result != $PARAM_UPDATE_SUCCESS) {
# print "set_search_key_field_internal5 $input, $result\n";
            return $result;
        }
        $result = add_field_to_create_index_hash($input_index_type, $fld, $val, $map, $dim, \$index);
        if ($result != $PARAM_UPDATE_SUCCESS) {
            $clitoxmldb1_index += 1;
# print "set_search_key_field_internal6 $input, $result\n";
            return $result;
        }
    } elsif ($input_index_type == $created_input_index || $input_index_type == $created_useasis_input_index || $input_index_type == $created_input_index_with_offset) {
        if (defined($temp[2])) {
            $result = param_value_return($actinit, \$init);
            if ($result != $PARAM_UPDATE_SUCCESS) {
# print "set_search_key_field_internal8 $input, $result\n";
                return $result;
            }
            $result = add_field_to_create_index_hash($input_index_type, $fld, $val, $init, $dim, \$index);
            if ($result != $PARAM_UPDATE_SUCCESS) {
                $clitoxmldb1_index += 1;
# print "set_search_key_field_internal9 $input, $result\n";
                return $result;
            }
        } else {
            $result = add_field_to_create_index_hash($input_index_type, $fld, $val, 0, $dim, \$index);
#print "set_search_key_field_internal13 $fld, $dim, $val, $index , $input_command\n";
            if ($result != $PARAM_UPDATE_SUCCESS) {
                $clitoxmldb1_index += 1;
# print "set_search_key_field_internal10 $input, $result\n";
                return $result;
            }
        }
    }


    $array_index{index}[$dim] = $index;
#print "set_search_key_field_internal11 $fld, $val, $dim, $index\n";
    $array_index{flag}[$dim] = $xml_dbase_index_update_reqd;
    if ($xml_dbase_update_reqd) {
        update_local_dbase($fld, $val);
    }
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;    
}


sub set_key_field_using_sigId_last_array
{
    my $input = $_[0];
    my $result;
     
#print "set_key_field_using_sigId_last_array1 $input\n";
    my @temp = split(/\,/, $input);

    $result = param_value_return($temp[1], \$sigId);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    if (defined($sigIdMap{$sigId})) {
        $input = "$temp[0]" . "," . "$action_value." . "$sigIdMap{$sigId}";
#print "set_key_field_using_sigId_last_array1 $input  : $sigId\n";
    }
    $input_index_type = $useasis_input_index;
    $last_array_flag = 1;
    $xml_dbase_index_update_reqd = $xmldbase_index_updated;
    $xml_dbase_update_reqd = 1;
    $result = set_search_key_field_internal($input);
    $last_array_flag = 0;
    return $result;
}

sub set_key_field_useasis_index_last_array
{
    my $input = $_[0];
    my $result;

    $input_index_type = $useasis_input_index;
    $last_array_flag = 1;
    $xml_dbase_index_update_reqd = $xmldbase_index_updated;
    $xml_dbase_update_reqd = 1;
    $result = set_search_key_field_internal($input);
    $last_array_flag = 0;
    return $result;

}

sub set_STP_mode_with_LAG_flag
{
    my $input = $_[0];
    my $xmlref = \%digit_to_tag_actual;
    my $result = $NOOP_CLI_RETURN_OPTION;
    my $actdisable_lag_fld;
    my $disable_lag_fld;
    my $actstp_fld;
    my $stp_fld;
    my $dim;
    my $fldval;
    my $actstp_mode;
    my $stp_mode;
    ($actdisable_lag_fld, $actstp_fld, $actstp_mode) = split(/$nodeparamconnector/, $input, 3);
    $result = param_value_return($actstp_fld, \$stp_fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actstp_mode, \$stp_mode);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actdisable_lag_fld, \$disable_lag_fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    if($disable_lag_fld eq "enable") {
        my @temp = split(/\./, $stp_fld);
        my $tempCnt;
        for (my $i = 0; $i <= $#temp; $i++) {
            if (defined($$xmlref{nxt}{$temp[$i]})) {
                $xmlref = \%{$$xmlref{nxt}{$temp[$i]}};
                $tempCnt = $i;
            }
        }
        if (defined($$xmlref{instance})) {
            foreach my $key (keys %{$$xmlref{instance}}) {
                 update_local_dbase($stp_fld, $stp_mode);
                 $array_index{index}[0] = $key;
                 $array_index{flag}[0] = $xml_dbase_index_update_reqd;
                 $result = update_xml_dbase_with_localdb(1);
                 delete_local_dbase();
                 if ($result != $NOOP_CLI_RETURN_OPTION) {
                     return $result;
                 }
            }
        }
    }
    return $result;
}
sub set_wlan_disable_with_LAG_flag
{
    my $input = $_[0];
    my $xmlref = \%digit_to_tag_actual;
    my $result = $NOOP_CLI_RETURN_OPTION;
    my $actdisable_lag_fld;
    my $disable_lag_fld;
    my $actstatus_fld;
    my $status_fld;
    my $actstatus_val;
    my $status_val;
    my $fldval;
    ($actdisable_lag_fld, $actstatus_fld, $actstatus_val) = split(/$nodeparamconnector/, $input, 3);
    $result = param_value_return($actstatus_fld, \$status_fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actstatus_val, \$status_val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actdisable_lag_fld, \$disable_lag_fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    if($disable_lag_fld eq "enable") {
        my @temp = split(/\./, $status_fld);
        my $tempCnt;
        for (my $i = 0; $i <= $#temp; $i++) {
            if (defined($$xmlref{nxt}{$temp[$i]})) {
                $xmlref = \%{$$xmlref{nxt}{$temp[$i]}};
                $tempCnt = $i;
            }
        }
        if (defined($$xmlref{instance})) {
            foreach my $key (keys %{$$xmlref{instance}}) {
                 update_local_dbase($status_fld, $status_val);
                 $array_index{index}[0] = $key;
                 $array_index{flag}[0] = $$xmlref{instance}{$key}{updflag};
                 $result = update_xml_dbase_with_localdb(1);
                 delete_local_dbase();
                 if ($result != $NOOP_CLI_RETURN_OPTION) {
                     return $result;
                 }
            }
        }
    }
    return $result;
}

sub set_wlan_interfacename_with_LAG_flag
{
    my $input = $_[0];
    my $xmlref = \%digit_to_tag_actual;
    my $result = $NOOP_CLI_RETURN_OPTION;
    my $actdisable_lag_fld;
    my $disable_lag_fld;
    my $actifname_fld;
    my $ifname_fld;
    my $actifname;
    my $ifname;
    my $fldval;
    my $found_flag =0;
    ($actdisable_lag_fld, $actifname_fld, $actifname) = split(/$nodeparamconnector/, $input, 3);
    $result = param_value_return($actifname_fld, \$ifname_fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actifname, \$ifname);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actdisable_lag_fld, \$disable_lag_fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    if($disable_lag_fld eq "enable") {
        my @temp = split(/\./, $ifname_fld);
        my $tempCnt;
        for (my $i = 0; $i <= $#temp; $i++) {
            if (defined($$xmlref{nxt}{$temp[$i]})) {
                $xmlref = \%{$$xmlref{nxt}{$temp[$i]}};
                $tempCnt = $i;
            }
        }
        if (defined($$xmlref{instance})) {
            foreach my $key (keys %{$$xmlref{instance}}) {
                 update_local_dbase($ifname_fld, $ifname);
                 $array_index{index}[0] = $key;
                 $array_index{flag}[0] = $$xmlref{instance}{$key}{updflag};
                 $result = update_xml_dbase_with_localdb(1);
                 delete_local_dbase();
                 if ($result != $NOOP_CLI_RETURN_OPTION) {
                     return $result;
                 }
            }
        }
    }
    return $result;
}
#Action to enable disable all instances.
sub update_field_for_all
{
    my $input = $_[0];
    my $actfld,
    my $actval;
    my $actmap;
    my $fld,
    my $val;
    my $map;
    my $str;
    my $xmlref = \%digit_to_tag_actual;
    my $result = $NOOP_CLI_RETURN_OPTION;

    my ($actfld, $actval, $actmap) = split(/\,/, $input, 3);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval, \$val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actmap, \$map);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $str = $val;
    $result = get_value_from_string($map, $str, \$val);
# print "update_field_for_all $map, $str, $val, $fld, $result\n";
    if ($result != $PARAM_UPDATE_SUCCESS) {
        $clitoxmldb1_index += 1;
        return $result;
    }

    my @temp = split(/\./, $fld);
    my $tempCnt;
    for (my $i = 0; $i <= $#temp; $i++) {
        if (defined($$xmlref{nxt}{$temp[$i]})) {
            $xmlref = \%{$$xmlref{nxt}{$temp[$i]}};
            $tempCnt = $i;
        }
    }
    if (defined($$xmlref{instance})) {
        foreach my $key (keys %{$$xmlref{instance}}) {
             update_local_dbase($fld, $val);
             $array_index{index}[0] = $key;
             $array_index{flag}[0] = $$xmlref{instance}{$key}{updflag};
             $result = update_xml_dbase_with_localdb(1);
             delete_local_dbase();
             if ($result != $NOOP_CLI_RETURN_OPTION) {
                 return $result;
             }
        }
    }
    return $result;
}

sub ignore_node_conditional_string
{
    my $input = $_[0];
    my $actfld;
    my $fld;
    my $fldval;
    my $comp_val;
    my $actcomp_val;
    my $result = $NOOP_CLI_RETURN_OPTION;
    ($actfld, $actcomp_val) = split(/$nodeparamconnector/, $input, 2);
    $result = param_value_return($actcomp_val, \$comp_val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    if (get_value_from_xml_dbase($fld, \$fldval)) {
        if($comp_val eq $fldval) {
            return $INVALID_CLI_OPTION;
        }
    }
    return $result;
}

sub ignore_node_conditional
{
    my $input = $_[0];
    my $actfld;
    my $fld;
    my $fldval;
    my $comp_val;
    my $actcomp_val;
    my $result = $NOOP_CLI_RETURN_OPTION;
    ($actfld, $actcomp_val) = split(/$nodeparamconnector/, $input, 2);
    $result = param_value_return($actcomp_val, \$comp_val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    if (get_value_from_xml_dbase($fld, \$fldval)) {
        if($comp_val == $fldval) {
            return $INVALID_CLI_OPTION;
        }
    }
    return $result;

}

sub set_arraySize
{
    my $input = $_[0];
    my $actfld;
    my $actvalue;
    my $fld;
    my $value;
    my $result = $NOOP_CLI_RETURN_OPTION;
    my $arrsize;
    my $href = \%digit_to_tag;
    my $xmlref = \%digit_to_tag_actual;
    my $level = 0;
    my @local_var;

    ($actfld, $actvalue ) = split(/$nodeparamconnector/, $input, 2);
    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actvalue, \$value);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    @local_var = split('\.',$actvalue);
    if ($local_var[0] == 9){
#9 denotes node_action_field
        if (get_value_from_xml_dbase($value, \$arrsize)) {
        } else {
            print "Field $actvalue doesn't have value defined ";
            $result = $VALUE_NOT_FOUND_IN_LOCALDBASE;
        }
    } elsif($local_var[0] == 6 ) {
#6 denotes node_action_value
        $arrsize = $value;
    }
    my @temp = split(/\./, $fld);
    for (my $i = 0; $i <= $#temp; $i++) {
        if ($i == 0) {
            $str = $temp[$i];
        } else {
            $str = $str . "." . $temp[$i];
        }
        if (defined($$href{nxt}{$temp[$i]})) {
#print "arrSize1 $$href{nxt}{$temp[$i]} $temp[$i]\n";
            $href = \%{$$href{nxt}{$temp[$i]}};
            $xmlref = \%{$$xmlref{nxt}{$temp[$i]}};
            if (defined($$href{array})) {
#print "arrSize2 $$href{array}\n";
                if (!defined($array_index{index}[$level])) {
                    if ($i != $#temp || !defined($create_index_hash{$created_input_index}) || !defined($create_index_hash{$created_input_index}{$str})) {
                        print "Index not defined for array base $str in field $fld in update_xml_dbase\n";
                        die;
                    }
                } else {
                    $xmlref = \%{$$xmlref{instance}{$array_index{index}[$level]}};
#print "arrSize3 $arrsize\n";
                    $$xmlref{arraysize} = $arrsize;
                }
                $level += 1;
            }
        } else {
            print "Field $fld is not defined in update_xml_dbase\n";
            die;
        }
    }
    return $result;
}

sub set_arraySize_everywhere_in_userDatabase
{
    my $input = $_[0];
    my $actfld;
    my $actvalue;
    my $extra_field;
    my $actextra_field;
    my $fld;
    my $value;
    my $result = $NOOP_CLI_RETURN_OPTION;
    my $href = \%digit_to_tag;
    my $xmlref = \%digit_to_tag_actual;
    my $LOWER_MAX_USER_ENTRIES = 512;
    my $UPPER_MAX_USER_ENTRIES;

    if (($is_ambassador == 1) || ($is_saber == 1) ||
            ($is_pata == 1) || ($is_khanda == 1) || ($is_kukri == 1)) {
        $UPPER_MAX_USER_ENTRIES =  12000;
    } else {
        $UPPER_MAX_USER_ENTRIES =  2048;
    }
#print "set_arraySize_everywhere_in_userDatabase - UPPER_MAX_USER_ENTRIES = $UPPER_MAX_USER_ENTRIES\n";

    ($actfld, $actextra_field, $actvalue ) = split(/$nodeparamconnector/, $input, 3);
    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actextra_field, \$extra_field);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actvalue, \$value);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

#print "set_arraySize_everywhere_in_userDatabase1 $actfld,$fld, $value\n";
    if (($value > $UPPER_MAX_USER_ENTRIES) ||($value< $LOWER_MAX_USER_ENTRIES)) {
        $value = $UPPER_MAX_USER_ENTRIES;
        $result = $USERDB_SIZE_OUT_OF_RANGE;#added to push database size CLI to ignore list if its out of range.
    }
#print "set_arraySize_everywhere_in_userDatabase2 $actextra_field, $value\n";
    update_local_dbase($extra_field, $value);
#print "set_arraySize_everywhere_in_userDatabase3 $fld, $value\n";
    my @temp = split(/\./, $fld);
    for (my $i = 0; $i <= $#temp; $i++) {
        if (defined($$xmlref{nxt}{$temp[$i]})) {
            $xmlref = \%{$$xmlref{nxt}{$temp[$i]}};
        }
    }
    if (defined($$xmlref{instance})) {
        foreach my $key (keys %{$$xmlref{instance}}) {
            $$xmlref{instance}{$key}{arraysize} = $value;
#print "set_arraySize_everywhere_in_userDatabase4 $fld, $value,$$xmlref{instance}{$key}{arraysize}\n";
        }
    }
    return $result;
}

sub ignore_node
{
# print "ignore_node called $clitoxmldb1_index\n";
    return $INVALID_CLI_OPTION;
}

sub update_reverse
{
    my $actfld = $_[0];
    my $result = $NOOP_CLI_RETURN_OPTION;

    return $result;
}

sub update_reverse_with_map
{
    my $actfld = $_[0];
    my $result = $NOOP_CLI_RETURN_OPTION;

    return $result;
}

sub multiply
{
    return  $NOOP_CLI_RETURN_OPTION;
}
sub get_max_port_number_for_platform
{
    for(my $i=0; $i<=$#platform_database; $i++) {
        if ($platform_type eq $platform_database[$i]{model_name}) {
            return ($platform_database[$i]{max_port_mumber});
        }
    }
    return -1;
}

sub generate_platform_info_database
{

    $platform_database[0]{model_name} = "AIR-WLC2106-K9"; 
    $platform_database[0]{max_port_mumber} = 8; 
    $platform_database[1]{model_name} = "AIR-WLC4402-25-K9";
    $platform_database[1]{max_port_mumber} = 2; 
    $platform_database[2]{model_name} = "AIR-WLC4402-50-K9";
    $platform_database[2]{max_port_mumber} = 2; 
    $platform_database[3]{model_name} = "AIR-WLC4404-100-K9";
    $platform_database[3]{max_port_mumber} = 4; 
    $platform_database[4]{model_name} = "WS-SVC-WISM-1-K9";
    $platform_database[4]{max_port_mumber} = -1; 
    $platform_database[5]{model_name} = "WS-C3750G-24WS-S25";
    $platform_database[5]{max_port_mumber} = 2; 
    $platform_database[6]{model_name} = "WS-C3750G-24WS-S50";
    $platform_database[6]{max_port_mumber} = 2; 
    $platform_database[7]{model_name} = "NME-AIR-WLC8-K9";
    $platform_database[7]{max_port_mumber} = 1; 
    $platform_database[8]{model_name} = "NME-AIR-WLC12-K9";
    $platform_database[8]{max_port_mumber} = 1; 
    $platform_database[9]{model_name} = "AIR-WLC2006-K9";
    $platform_database[9]{max_port_mumber} = -1; #check 
    $platform_database[10]{model_name} = "AIR-WLC4402-12-K9";
    $platform_database[10]{max_port_mumber} = 2;  
    $platform_database[11]{model_name} = "AIR-WLC4402-50";
    $platform_database[11]{max_port_mumber} = 2;  
    $platform_database[12]{model_name} = "AIR-WLC4404-100";
    $platform_database[12]{max_port_mumber} = 4; 
    $platform_database[13]{model_name} = "NM-AIR-WLC6-K9";
    $platform_database[13]{max_port_mumber} = 1; #check 
    $platform_database[14]{model_name} = "NME-AIR-WLC6-K9";
    $platform_database[14]{max_port_mumber} = 1; #check 
    $platform_database[15]{model_name} = "NME-AIR-WLC25-K9";
    $platform_database[15]{max_port_mumber} = 1; #check 
    $platform_database[16]{model_name} = "AIR-CT2504-K9";
    $platform_database[16]{max_port_mumber} = 4;
    $platform_database[17]{model_name} = "AIR-CTVM-K9";
    $platform_database[17]{max_port_mumber} = 1;
}

sub initialize_szabla_platform
{
    if ($platform_type eq $platform_Szabla) {
        $is_szabla = 1;
    }
}

sub initialize_kukri_platform
{
    if ($platform_type eq $platform_Kukri) {
        $is_kukri = 1;
    }
}

sub initialize_ambassador_platform
{
    if ($platform_type eq $platform_ambassador) {
        $is_ambassador = 1;
    }
}

sub initialize_ME_platform
{
    for my $i (0 .. $#me_platform)
    {
      if (index($platform_type, $me_platform[$i]) != -1) {
          #print "Platform Found\n";
          $maxhreapacl = 32;
          $maxhreapipv6acl = 32;
          $maxXferSchedPolicy = 1;
          last;
      } 
    }
}

sub initialize_saber_platform
{
    if (($platform_type  =~ m/^($platform_saber1)/) || ($platform_type  =~ m/^($platform_saber2)/)) {
	    $is_saber = 1;
    }
}

sub initialize_pata_platform
{
    if ($platform_type  =~ m/^($platform_pata)/) {
	    $is_pata = 1;
    }
}
sub initialize_khanda_platform
{
    if ($platform_type  =~ m/^($platform_khanda)/) {
	    $is_khanda = 1;
    }
}

sub initialize_vm_platform
{
    if ($platform_type eq $platform_vm) {
        $is_vm = 1;
    }
}

sub initialize_foxhound_platform
{
    if (($platform_type eq $platform_C3750G_24WS_25) || ($platform_type eq $platform_C3750G_24WS_50)) {
        $upd_foxhound_intf = 1;
    }
}
    if(!close(IGNORED) || !close(RESULTFILE))
    {
      remove_xml_files();
      die "Error: File System is out of Disk Space. Config is too big to save on the disk space:$!";
    }


sub check_masterkey_not_configured
{
    if ( $local_debug == 1 ) {
        return (system("/bin/ls master_key >> /dev/null 2>&1"));
    } else {
        return (system("/bin/ls /mnt/application/master_key >> /dev/null 2>&1"));
    }
}
    
sub remove_xml_files
{
    system("/bin/rm /mnt/application/xml_tmp/*.xml");
    seek(RESULTFILE,0,0);
    print RESULTFILE "Error: File System is out of Disk Space\r\n.";
}
sub update_field_with_mac_delimiter
{
    my $input = $_[0];
    my $result;
    my $fld,
    my $val;

    my ($actfld, $actval) = split(/\,/, $input, 2);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval, \$val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    my @temp1 = split(':', $val);
    if($#temp1 == 0) {
        my @temp2 = split('', $val);
        for(my $i=0; $i<=$#temp2; $i++) {
            if($i==0) {
                $val = $temp2[$i];
            } else {
                $val .= $temp2[$i];
                if(($i%2==1)&&($i<$#temp2)) {
                    $val .= ':';
                }
            }
        }
    }
#print "update_field_with_mac $fld, $val\n";
    update_local_dbase($fld, $val);
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}

sub do_mac_add_validation
{
    my $pmacadd = $_[0];
    my @temp;
    my $dec_val;
    my $hexchars = "";
    $$pmacadd =~ tr/[A-Z]/[a-z]/;
    @temp = split(':',$$pmacadd);
    if($#temp != 5) {
       return $INVALID_MAC_ADRESS;
    }
    else
    {
        for(my $i=0; $i<=5; $i++) {
            $dec_val = hex($temp[$i]);
            foreach my $c (split(//,$temp[$i])) {
                $hexchars = sprintf "%x", ord($c);
                if($hexchars > 66 ) {
                    return $INVALID_MAC_ADRESS;
                }
            }

            if($dec_val < 0 || $dec_val > 255) {
                return $INVALID_MAC_ADRESS;
            }
        }
    }
    $$pmacadd =~ s/://g;
    return $PARAM_UPDATE_SUCCESS;
}

sub flush_local_dbase
{
    $result = update_xml_dbase_with_localdb(1);
    delete_local_dbase();
    return $result;
#print "flush_local_dbase $result\n";
}

sub print_to_console
{
   my $tempStr = $_[0];
print "$tempStr";
}

sub shift_old_to_new
{
    my $href = $_[0];
    my $xmlref = $_[1];
    my $old, $new;

#print "shift_old_to_new1 $href, $xmlref\n";
    if (defined($$href{val})) {
        $$xmlref{val} = $$href{val};
#print "shift_old_to_new2 $$xmlref{val}\n";
    } elsif (defined($$href{instance})) {
        foreach my $index ( keys %{$$href{instance}}) {
#print "shift_old_to_new3 $index\n";
            $old = \%{$$href{instance}{$index}};
            $new = \%{$$xmlref{instance}{$index}};
            if (defined($$old{arraysize})) {
                $$new{arraysize} = $$old{arraysize};
            }
            if (defined($$old{updflag})) {
                $$new{updflag} = $$old{updflag};
            }
#print "shift_old_to_new7 $$href{instance}{$index}, $$xmlref{instance}{$index}\n";
            shift_old_to_new($old, $new);
        }
    } elsif (defined($$href{nxt})) {
        foreach my $digit ( keys %{$$href{nxt}}) {
            $old = \%{$$href{nxt}{$digit}};
            $new = \%{$$xmlref{nxt}{$digit}};
#print "shift_old_to_new6 $$href{nxt}{$digit}, $$xmlref{nxt}{$digit}, $digit\n";
            shift_old_to_new($old, $new);
        }
    }
}

sub copy_old_to_new
{
    my $oldref = $_[0];
    my $oldkey = $_[1];
    my $newref = $_[2];
    my $newkey = $_[3];
    my $pold, $pnew;
#print "copy_old_to_new1 $oldkey, $newkey\n";
    foreach my $key (keys %{$$oldref{$oldkey}}) {
#print "copy_old_to_new2--$key\n";
       $pold = \% {$$oldref{$oldkey}};
       $pnew = \% {$$newref{$newkey}};
       copy_old_to_new($pold, $key, $pnew,$key);
    }
}

#Added for wlanAnchorStatus in mmCfgData for guest-lan
sub set_key_field_operated_index_last_array
{
    my $input = $_[0];
    my $actfld;
    my $actval;
    my $actoffset;
    my $actop;
    my $fld;
    my $val;
    my $offset;
    my $op;
    my $result;

    ($actfld, $actval, $actoffset, $actop) = split(/$nodeparamconnector/, $input, 4);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actval, \$val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actoffset, \$offset);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actop, \$op);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    if ($op == $add_op) {
        $val = $val + $offset;
    } elsif ($op == $sub_op) {
        $val = $val - $offset;
    } elsif ($op == $mul_op) {
        $val = $val * $offset;
    } elsif ($op == $div_op) {
        $val = $val / $offset;
    } else {
        print_to_console("Error: Wrong operator entered in database should be 1 = add, 2 = sub, 3 = mul or 4 = div\n");
        seek(RESULTFILE,0,0);
        print RESULTFILE "Error: Wrong operator entered in database should be 1 = add, 2 = sub, 3 = mul or 4 = div\r\n";
        exit;
    }

    $input_index_type = $useasis_input_index;
    $last_array_flag = 1;
    $xml_dbase_index_update_reqd = $xmldbase_index_updated;
    $xml_dbase_update_reqd = 1;
#print "set_key_field_operated_index_last_array $input_command, $input\n";
    $result = check_and_get_array_dbase_level($fld, $input_index_type, \$dim);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $index = $val;
    if ($input_index_type == $useasis_input_index) {
        $result = check_for_digits($val);
#print "set_key_field_operated_index_last_array $input_command, $val\n";
        if ($result != $PARAM_UPDATE_SUCCESS) {
            return $result;
        }
    }
    $array_index{index}[$dim] = $index;
    $array_index{flag}[$dim] = $xml_dbase_index_update_reqd;
    if ($xml_dbase_update_reqd) {
        update_local_dbase($fld, $val);
    }
    $result = $NOOP_CLI_RETURN_OPTION;
    $last_array_flag = 0;
    return $result;    
}

#Action added specially when double maps is used for bit set/reset e.g. ckip kp,mmh enable.
sub update_bit_field_with_setreset_double_map
{
    my $input = $_[0];
    my $result;
    my $fld,
    my $bitval;
    my $setreset;
    my $map;
    my $val;
    my $str;
    my $remap;
    my $new_val;
    my $local_val;

    my ($actfld, $actval, $actsetreset, $actmap, $actremap) = split(/\,/, $input, 5);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actval, \$bitval);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actsetreset, \$setreset);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actmap, \$map);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actremap, \$remap);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $str = $setreset;
    $result = get_value_from_string($map, $str, \$setreset);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        $clitoxmldb1_index += 1;
        return $result;
    }

    if (get_value_from_xml_dbase($fld, \$local_val)) {
        $result = get_reverse_value_from_string($remap, $local_val, \$val);
        if ($result != $PARAM_UPDATE_SUCCESS) {
            $clitoxmldb1_index += 1;
            return $result;
        }
        if ($setreset) {
            $val |= $bitval;
        } else {
            $val  &= (~$bitval);
        }
    } else {
        if ($setreset) {
            $val = $bitval;
        } else {
            $val  = 0;
        }
    }

    $result = get_value_from_string($remap, $val, \$new_val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        $clitoxmldb1_index += 1;
        return $result;
    }
    update_local_dbase($fld, $new_val);
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}

#Action added specially when double maps is used for bit set/reset e.g. ckip kp,mmh enable.
sub get_reverse_value_from_string
{
    my $map = $_[0];
    my $string = $_[1];
    my $pval = $_[2];

    my @temp = split(/\t/, $map);
    for (my $i = 0; $i <= $#temp; $i++) {
        (my $t1, my $t2) = split(/=/, $temp[$i]);
        if ($t2 eq $string) {
            $$pval = $t1;
            return $PARAM_UPDATE_SUCCESS;
        }
    }
    return $STRVALMAP_NO_STRING_FOUND;
}

#Special function added to upate timestamp for accountCreationTimeStamp in aaaapiFileDbCfgData
sub update_field_with_current_timestamp
{
    my $input = $_[0];
    my $fld;
    my $result;
    my $current_time;
    my $actfld = $input;

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $curremt_time = time();
#print"update_field_with_current_timestamp2$fld, $curremt_time\n";
    update_local_dbase($fld, $curremt_time);
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}

sub move_rogue_rule_add_up
{
   system("grep \"$prefix_config_policy_cli\" $clixmlConfigfile > $clifile_policy_add");
   system("grep -v \"$prefix_config_policy_cli\" $clixmlConfigfile > $clifile_no_policy");
   system("cat $clifile_policy_add $clifile_no_policy > $clixmlConfigfile");
   system("rm -f $clifile_policy_add $clifile_no_policy");
   system("grep \"$prefix_config_interface_cli\" $clixmlConfigfile > $clifile_interface_add");
   system("grep -v \"$prefix_config_interface_cli\" $clixmlConfigfile > $clifile_no_interface");
   system("cat $clifile_interface_add $clifile_no_interface > $clixmlConfigfile");
   system("rm -f $clifile_interface_add $clifile_no_interface");
   system("grep \"$prefix_rogue_rule_cli\" $clixmlConfigfile > $clifile_rogue_add");
   system("grep -v \"$prefix_rogue_rule_cli\" $clixmlConfigfile > $clifile_no_rogue");
   system("cat $clifile_rogue_add $clifile_no_rogue > $clixmlConfigfile");
   system("rm -f $clifile_rogue_add $clifile_no_rogue");
   system("grep \"$prefix_config_country_cli\" $clixmlConfigfile > $clifile_country_add");
   system("grep -v \"$prefix_config_country_cli\" $clixmlConfigfile > $clifile_no_country");
   system("cat $clifile_country_add $clifile_no_country > $clixmlConfigfile");
   system("rm -f $clifile_country_add $clifile_no_country");
}

sub update_field_remove_colon
{
    my $input = $_[0];
    my $fld;
    my $result;
    my $actfld;
    my $fld;
    my $actval;
    my $val;

    my ($actfld, $actval) = split(/\,/, $input, 2);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval, \$val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $val =~ s/://g;
    update_local_dbase($fld, $val);
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}

sub update_field_if_ipv4
{
    my $input = $_[0];
    my $actfld;
    my $actval;
    my $fld;
    my $val;
    my $val1;

    ($actfld, $actval) = split(/\,/, $input, 2);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    
    $result = param_value_return($actval, \$val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    if ($val !~ m/:/) {
        update_local_dbase($fld, $val);
    }
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}

sub update_field_if_url
{
    my $input = $_[0];
    my $actfld;
    my $actval;
    my $fld;
    my $val;
    my $val1;

    ($actfld, $actval) = split(/\,/, $input, 2);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    
    $result = param_value_return($actval, \$val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    if ($val =~ m/[^g-zG-Z]/) {
        return $result;
    }
    else {
        update_local_dbase($fld, $val);
    }
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}

sub update_field_if_url
{
    my $input = $_[0];
    my $actfld;
    my $actval;
    my $fld;
    my $val;
    my $val1;

    ($actfld, $actval) = split(/\,/, $input, 2);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    
    $result = param_value_return($actval, \$val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    if ($val =~ m/[^g-zG-Z]/) {
        return $result;
    }
    else {
        update_local_dbase($fld, $val);
    }
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}

sub set_reset_bit_for_sig_state
{
    my $input = $_[0];
    my $result;
    my $bitval;
    my $actfld;
    my $actsigid;
    my $actsetreset;
    my $fld;
    my $fldval;
    my $sigid;
    my $setreset;

    my ($actfld, $actsigid, $actsetreset) = split(/\,/, $input, 3);
    $result = param_value_return($actfld, \$fldval);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actsigid, \$sigid);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($actsetreset, \$setreset);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    my $idx         = $sigid / 8;
    my $bitoffset   = $sigid % 8;
    my $bitval      = 1 << $bitoffset;
    my $sigStateInt;
    my @sigState;
    my $val;

    if(get_value_from_xml_dbase($fldval, \$fld)) {
        my @tmp = split(//, $fld);
        for(my $i=0, my $j=0; $i <= $#tmp;) {
            $sigState[$j] = hex($tmp[$i] . $tmp[$i+1]);
            $j++;
            $i += 2;
        }
        $sigStateInt = $sigState[$idx];

        if ($setreset) {
            $sigStateInt |= $bitval;
        } else {
            $sigStateInt  &= (~$bitval);
        }
    } else {
        my $sigCnt = 13;
        for (my $i=0;$i < $sigCnt;$i++){
            $sigState[$i] = 0xff;
        }
        $sigStateInt = $sigState[$idx];

        if ($setreset) {
            $sigStateInt |= $bitval;
        } else {
            $sigStateInt  &= (~$bitval);
        }
    }
    $sigState[$idx] =  $sigStateInt;
    if ($idx !=0){
        $val = sprintf("%x",$sigState[0]);
    }
    else {
        $val = $sigState[0];
    }
    for(my $j=1; $j <= $#sigState; $j++) {
        $val .= sprintf("%x",$sigState[$j]);
    }
    update_local_dbase($fldval, $val);

    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}

sub set_key_field_create_index_hreapacl
{
    my $input = $_[0];
    my $result;
    my $actval;
    my $val;

    my @temp = split(/\,/, $input);
    $actval = $temp[1];
    $result = param_value_return($actval, \$val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
# print "set_search_key_field_internal3 $input, $result\n";
        return $result;
    }

    if ($hreapacl < $maxhreapacl) {
        $input_index_type = $created_input_index;
        $xml_dbase_index_update_reqd = $xmldbase_index_updated;
        $xml_dbase_update_reqd = 1;
        $result = set_search_key_field_internal($input);

#print "search_key_field_create_index_:IPV4 Result $result count =$hreapacl value=$val\n";
        if ($result == $NOOP_CLI_RETURN_OPTION  && (!( grep { $_ eq $val} @hreapAclName))) 
        {
          push @hreapAclName, $val;
          $hreapacl+=1;
#          print "pushing in array $val $hreapacl\n";
  	    }
        return $result;
    }
    else {
	    return $INVALID_CLI_OPTION;
    }
}

sub set_key_field_create_index_hreapipv6acl
{
    my $input = $_[0];
    my $result;
    my $actval;
    my $val;

    my @temp = split(/\,/, $input);
    $actval = $temp[1];
    $result = param_value_return($actval, \$val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
# print "set_search_key_field_internal3 $input, $result\n";
        return $result;
    }

    if ($hreapipv6acl < $maxhreapipv6acl) {
        $input_index_type = $created_input_index;
        $xml_dbase_index_update_reqd = $xmldbase_index_updated;
        $xml_dbase_update_reqd = 1;
        $result = set_search_key_field_internal($input);
#print "search_key_field_create_index_:IPV6 Result $result count =$hreapipv6acl value=$val\n";
        if ($result == $NOOP_CLI_RETURN_OPTION  && (!( grep { $_ eq $val} @hreapAclName))) 
        {
          push @hreapAclName, $val;
          $hreapipv6acl+=1;
#          print "IPV6 pushing in array $val $hreapipv6acl\n";
  	    }
        return $result;
    }
    else {
	    return $INVALID_CLI_OPTION;
    }
}

sub set_key_field_create_index_xfer_sched_policy
{
    my $input = $_[0];
    my $result;
    my $actval;
    my $val;

    my @temp = split(/\,/, $input);
    $actval = $temp[1];
    $result = param_value_return($actval, \$val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
# print "set_search_key_field_internal3 $input, $result\n";
        return $result;
    }

    if ($xferSchedPolicy < $maxXferSchedPolicy) {
        $input_index_type = $created_input_index;
        $xml_dbase_index_update_reqd = $xmldbase_index_updated;
        $xml_dbase_update_reqd = 1;
        $result = set_search_key_field_internal($input);

#print "search_key_field_create_index_:Xfer Sched Policy result $result count = $xferSchedPolicy value=$val\n";
        if ($result == $NOOP_CLI_RETURN_OPTION  && (!( grep { $_ eq $val} @xferSchedPolicyName))) 
        {
          push @xferSchedPolicyName, $val;
          $xferSchedPolicy+=1;
#          print "pushing in array $val $xferSchedPolicy\n";
  	    }
        return $result;
    }
    else {
	    return $INVALID_CLI_OPTION;
    }
}

sub search_key_field_create_index_if_service_port_supp
{
    my $input = $_[0];
    my $result;

#print "search_key_field_create_index_if_service_port_supp: servicePortSupp: $servicePortSupp\n";
    if ($servicePortSupp eq "1") {
	    $input_index_type = $created_input_index;
    	$xml_dbase_index_update_reqd = $xmldbase_index_not_updated;
	    $xml_dbase_update_reqd = 1;
    	$result = set_search_key_field_internal($input);
	    return $result;
	}
	else {
		return $INVALID_CLI_OPTION;
	}
}

sub update_field_with_mgmtIp
{
    my $input = $_[0];
    my $result;
    my $fld,
    my $val;

    my $actfld = $input;

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    update_local_dbase($fld, $mgmt_ip_addr);
    return $result;
}

sub is_node_unsupported_on_platform
{
	if ($is_szabla == 1) {
		return $INVALID_CLI_OPTION;
	}
	return $NOOP_CLI_RETURN_OPTION;
}

sub is_node_unsupported_on_platform_vwlc
{
	if ($is_vm == 1) {
		return $INVALID_CLI_OPTION;
	}
	return $NOOP_CLI_RETURN_OPTION;
}
sub is_node_supported_on_ucs
{
      if ( ($is_ambassador == 1) || ($is_saber == 1) ||
           ($is_pata == 1) || ($is_khanda == 1) || ($is_kukri == 1) ) {
         return $NOOP_CLI_RETURN_OPTION;
      }
      return $INVALID_CLI_OPTION;
}
sub is_node_unsupported_on_ambassador_vwlc
{
	if ($is_ambassador ==  1 || $is_vm == 1) {
		return $INVALID_CLI_OPTION;
	}
	return $NOOP_CLI_RETURN_OPTION;
}

sub is_smart_lic_supported
{
	if (($is_vm == 1) || ($is_pata == 1) || ($is_khanda == 1) || ($is_kukri == 1)) {
	    return $NOOP_CLI_RETURN_OPTION;
	}
	return $INVALID_CLI_OPTION;
}	
sub is_node_only_on_vm
{
	if ($is_vm == 1) {
		return $NOOP_CLI_RETURN_OPTION;
	}
	return $INVALID_CLI_OPTION;
}


sub check_wlan_id_boundary
{
	my $input = $_[0];
	my $val;

	if ($is_szabla == 1) {
		param_value_return($input, \$val);
		if ($val > $szabla_max_wlan) {
			return $INVALID_CLI_OPTION;
		}
		else {
			return $NOOP_CLI_RETURN_OPTION;
		}
	}
	return $NOOP_CLI_RETURN_OPTION;
}

sub check_default_group
{
    my $input = $_[0];
    my $result;
    my $fld,
    my $val;
    my $nonevar = "default-group";

    my ($actfld, $actval) = split(/\,/, $input, 2);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval, \$val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    if($val eq "default-group") {
#print "check_default_group1: $val\n";
        return INVALID_CLI_OPTION;
    }

#print "check_default_group2: $val\n";
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}
#11u related subroutines
sub update_field_dot11u_ouilength 
{
    my $input = $_[0];
    my $result;
    my $fld,
    my $val;
    my $len;

    my ($actfld, $actval) = split(/\,/, $input, 2);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval, \$val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $len = length($val)/2;

    update_local_dbase($fld, $len);
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}
sub is_supported_on_ucs
{
      if ( ($is_ambassador == 1) || ($is_saber == 1) ||
           ($is_pata == 1) || ($is_khanda == 1) || ($is_vm == 1) ) {
         return $INVALID_CLI_OPTION;
      }
      return $NOOP_CLI_RETURN_OPTION;
} 
sub update_globalhash_policy
{
    my $input = $_[0];
    my $result;
    my $name,
    my $id;
    my $val;
    my $len;

    my ($policyname, $policyid) = split(/\,/, $input, 2);

    $result = param_value_return($policyname, \$name);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($policyid, \$id);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    if (get_value_from_xml_dbase($id, \$val)) {
    }
#    print "policyname is $name\n";
#    print "policyid is $val\n";
    $policy_name_id_mapping{$name} = $val;
    $result = $NOOP_CLI_RETURN_OPTION;
}

sub update_profiler_id_based_onname
{
    my $input = $_[0];
    my $result;
    my $fld,
    my $name,
    my $id,

    my ($actfld, $policyname) = split(/\,/, $input, 2);

    $result = param_value_return($policyname, \$name);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
#print "policyname is $name\n";
    if(defined($policy_name_id_mapping{$name})) {
        $id = $policy_name_id_mapping{$name};
#print "id is $id\n";
    } else {
#print " Error id is $id\n";
		return $INVALID_CLI_OPTION;
    }
    update_local_dbase($fld, $id);
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}

sub update_profiler_id_based_onname_in_range
{
    my $input = $_[0];
    my $result;
    my $fld,
    my $useld,
    my $name,
    my $id,
    my $range,
    my ($actfld, $actuseld, $policyname, $idrange) = split(/\,/, $input, 4);

    $result = param_value_return($policyname, \$name);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
#print "policyname is $name\n";
    if(defined($policy_name_id_mapping{$name})) {
        $id = $policy_name_id_mapping{$name};
#print "id is $id\n";
    } else {
#print " Error id is $id\n";
		return $INVALID_CLI_OPTION;
    }
    $result = param_value_return($actuseld, \$useld);
#print "actfld is $actfld, $fld , $actuseld, $useld\n";
    $result = param_value_return($idrange, \$range);
    if($id > $range) {
        $id = 0;
#print "setting id is $id as $range\n";
    }
    else {
        update_local_dbase($useld, 1);
    }
    update_local_dbase($fld, $id);
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}

sub update_tunnel_eogre_string_dhcpopt
{
    my $input = $_[0];
    my $result = $NOOP_CLI_RETURN_OPTION;
    my $node;
    my $first;
    my $second;
    my $finalVal;

    my ($node, $first, $second, $third, $fourth, $fifth) = split(/\,/, $input, 6);

    $result = param_value_return($node, \$nodeval);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($first, \$firstval);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $finalVal = $firstval;

    if($second) {
      $result = param_value_return($second, \$secondval);
      if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
      }
      $finalVal = join "", $finalVal, " ", $secondval;
    }

    if($third) {
      $result = param_value_return($third, \$thirdval);
      if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
      }
      $finalVal = join "", $finalVal, " ", $thirdval;
    }

    if($fourth) {
      $result = param_value_return($fourth, \$fourthval);
      if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
      }
      $finalVal = join "", $finalVal, " ", $fourthval;
    }

    if($fifth) {
      $result = param_value_return($fifth, \$fifthval);
      if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
      }
      $finalVal = join "", $finalVal, " ", $fifthval;
    }

    update_local_dbase($nodeval, $finalVal);
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}

sub update_fields_with_startend_time
{
    my $input = $_[0];
    my $result;
    my $fldsttime,
    my $fldendtime,
    my $fldactualtime,
    my $valsttime,
    my $valendtime,

    my ($fldst, $fldend, $fldact, $valst, $valend) = split(/\,/, $input, 5);
#print "$fldst, $fldend, $fldact, $valst, $valend\n";

    $result = param_value_return($fldst, \$fldsttime);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($fldend, \$fldendtime);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($fldact, \$fldactualtime);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($valst, \$valsttime);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $result = param_value_return($valend, \$valendtime);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }
    $actualtime = $valsttime . " " . $valendtime;
#print "fldsttime: $fldsttime, fldendtime: $fldendtime, fldactualtime: $fldactualtime , valsttime: $valsttime, valendtime: $valendtime, actualtime: $actualtime\n";

    @start_array = split (/:/, $valsttime);
    @end_array = split (/:/, $valendtime);
#print "st_ar: @start_array, end_ar: @end_array\n";

    $sttime = $start_array[0]*3600 + $start_array[1]*60;
    $duration = ($end_array[0]-$start_array[0])*3600 + ($end_array[1]-$start_array[1])*60;
#print "sttime: $sttime, endtime: $duration\n";
    
    update_local_dbase($fldsttime, $sttime);
    update_local_dbase($fldendtime, $duration);
    update_local_dbase($fldactualtime, $actualtime);
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}

sub update_field_with_ssh_legacy_status
{
    my $input = $_[0];
    my $result;
    my $actfld,
    my $actval;
    my $actmap;
    my $fld,
    my $val;
    my $map;
    my $str;
    my $fd;

    my ($actfld, $actval, $actmap) = split(/\,/, $input, 3);

    $result = param_value_return($actfld, \$fld);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actval, \$val);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $result = param_value_return($actmap, \$map);
    if ($result != $PARAM_UPDATE_SUCCESS) {
        return $result;
    }

    $str = $val;
    $result = get_value_from_string($map, $str, \$val);
# print "update_field_with_map1 $map, $str, $val, $fld, $result\n";
    if ($result != $PARAM_UPDATE_SUCCESS) {
        $clitoxmldb1_index += 1;
        return $result;
    }

    if($val) {
        if(open($fd, ">/mnt/application/use_legacy_ssh")) {
            close($fd);
        }
    }

    update_local_dbase($fld, $val);
    $result = $NOOP_CLI_RETURN_OPTION;
    return $result;
}


