*copyc osd$default_pragmats
MODULE rfm$change_state_commands_r3;
?? TITLE := 'RHFAM_CHANGE_STATE_COMMANDS' ??
?? NEWTITLE := '  RING BRACKETS 23D' ??
?? NEWTITLE := '    XREF procedures', EJECT ??
*copyc osp$set_status_abnormal
*copyc osp$append_status_parameter
*copyc rfp$change_nad_status
*copyc rfp$lock_table
*copyc rfp$unlock_table
?? TITLE := '    INLINE procedures', EJECT ??
*copyc rfp$verify_caller_capability
?? TITLE := '    TYPE/CONST Definitions', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc rfe$condition_codes
*copyc rfv$status_table
?? POP ??
?? TITLE := '    rfp$change_nad_or_trunk_state', EJECT ??
  PROCEDURE [XDCL, #GATE] rfp$change_nad_or_trunk_state (nad_names_p: ^ARRAY[1 .. *] OF rft$component_name;
    trunk_names_p: ^ARRAY[1 .. *] OF rft$component_name;
    state: rft$element_state;
    VAR status: ost$status);

*copyc rfh$change_nad_or_trunk_state

    VAR
      nad_name_index,
      trunk_name_index: INTEGER,
      local_nad_index: rft$local_nads,
      remote_nad_index: rft$remote_nads,
      tcu_index: rfc$min_tcu..rfc$max_tcu,
      trunk_found_p: ^ARRAY[1..*] OF BOOLEAN,
      capabilities: ARRAY[1..1] OF ost$name;

    status.normal := TRUE;

    capabilities [1] := avc$network_operation;

    rfp$verify_caller_capability (^capabilities, 'change NAD or trunk status', status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    IF trunk_names_p <> NIL THEN
      PUSH trunk_found_p: [1 .. UPPERBOUND(trunk_names_p^)];
      FOR trunk_name_index := LOWERBOUND(trunk_found_p^) TO UPPERBOUND(trunk_found_p^) DO
        trunk_found_p^[trunk_name_index] := FALSE;
      FOREND;
    IFEND;

    rfp$lock_table (rfv$status_table.lock);
    IF NOT rfv$status_table.system_task_is_up THEN
      rfp$unlock_table (rfv$status_table.lock);
      IF trunk_names_p = NIL THEN
        osp$set_status_abnormal (rfc$product_id, rfe$system_task_not_active, 'CHANGE_NAD_STATUS', status);
      ELSE
        osp$set_status_abnormal (rfc$product_id, rfe$system_task_not_active, 'CHANGE_TRUNK_STATUS', status);
      IFEND;
      RETURN;
    IFEND;

  /scan_nad_names/
    FOR nad_name_index := LOWERBOUND(nad_names_p^) TO UPPERBOUND(nad_names_p^) DO
      FOR local_nad_index := LOWERBOUND(rfv$status_table.local_nads^) TO
            UPPERBOUND(rfv$status_table.local_nads^) DO
        IF (rfv$status_table.local_nads^[local_nad_index].name = nad_names_p^[nad_name_index]) OR
              (nad_names_p^[nad_name_index] = 'ALL') THEN
          IF trunk_names_p <> NIL THEN
            FOR trunk_name_index := LOWERBOUND(trunk_names_p^) TO UPPERBOUND(trunk_names_p^) DO
              FOR tcu_index := LOWERBOUND(rfv$status_table.local_nads^[local_nad_index].trunk_control_units)
                    TO UPPERBOUND(rfv$status_table.local_nads^[local_nad_index].trunk_control_units) DO
                IF trunk_names_p^[trunk_name_index] =
                      rfv$status_table.local_nads^[local_nad_index].trunk_control_units[tcu_index] THEN
                  IF rfv$status_table.local_nads^[local_nad_index].current_status.tcu_status[tcu_index] =
                        rfc$es_down THEN
                    osp$set_status_abnormal (rfc$product_id, rfe$down_trunk_not_changeable,
                          trunk_names_p^[trunk_name_index], status);
                    osp$append_status_parameter (osc$status_parameter_delimiter, nad_names_p^[nad_name_index],
                          status);
                    EXIT /scan_nad_names/;
                  IFEND;
                  rfv$status_table.local_nads^[local_nad_index].current_status.tcu_status[tcu_index] := state;
                  trunk_found_p^[trunk_name_index] := TRUE;
                IFEND;
              FOREND;
            FOREND;
          ELSE
            IF (rfv$status_table.local_nads^[local_nad_index].current_status.device_status = rfc$es_down) AND
                  (state <> rfc$es_down) THEN
              osp$set_status_abnormal (rfc$product_id, rfe$down_nad_not_changable,
                    nad_names_p^[nad_name_index], status);
              EXIT /scan_nad_names/;
            ELSEIF (rfv$status_table.local_nads^[local_nad_index].current_status.device_status = rfc$es_off)
                  AND ((state = rfc$es_down) OR (state = rfc$es_on)) THEN
              rfv$status_table.local_nads^[local_nad_index].maintenance_status.reloads_performed := 0;
              rfv$status_table.local_nads^[local_nad_index].maintenance_status.reload_failed := FALSE;
              IF state = rfc$es_on THEN
                rfp$change_nad_status (rfv$status_table.local_nads^[local_nad_index].logical_unit_number,
                      rfc$es_on);
              IFEND;
            IFEND;
            rfv$status_table.local_nads^[local_nad_index].current_status.device_status := state;
          IFEND;
          IF nad_names_p^[nad_name_index] <> 'ALL' THEN
            CYCLE /scan_nad_names/;
          IFEND;
        IFEND;
      FOREND;
      IF rfv$status_table.remote_nads <> NIL THEN
        FOR remote_nad_index := LOWERBOUND(rfv$status_table.remote_nads^) TO
              UPPERBOUND(rfv$status_table.remote_nads^) DO
          IF (rfv$status_table.remote_nads^[remote_nad_index].name = nad_names_p^[nad_name_index]) OR
                (nad_names_p^[nad_name_index] = 'ALL') THEN
            IF trunk_names_p <> NIL THEN
              FOR trunk_name_index := LOWERBOUND(trunk_names_p^) TO UPPERBOUND(trunk_names_p^) DO
                FOR tcu_index :=
                      LOWERBOUND(rfv$status_table.remote_nads^[remote_nad_index].trunk_control_units) TO
                      UPPERBOUND(rfv$status_table.remote_nads^[remote_nad_index].trunk_control_units) DO
                  IF trunk_names_p^[trunk_name_index] =
                        rfv$status_table.remote_nads^[remote_nad_index].trunk_control_units[tcu_index] THEN
                    IF rfv$status_table.remote_nads^[remote_nad_index].current_status.tcu_status[tcu_index] =
                          rfc$es_down THEN
                      osp$set_status_abnormal (rfc$product_id, rfe$down_trunk_not_changeable,
                            trunk_names_p^[trunk_name_index], status);
                      osp$append_status_parameter (osc$status_parameter_delimiter,
                           nad_names_p^[nad_name_index], status);
                      EXIT /scan_nad_names/;
                    IFEND;
                    rfv$status_table.remote_nads^[remote_nad_index].current_status.tcu_status[tcu_index] :=
                          state;
                    trunk_found_p^[trunk_name_index] := TRUE;
                  IFEND;
                FOREND;
              FOREND;
            ELSE
              IF rfv$status_table.remote_nads^[remote_nad_index].current_status.device_status =
                    rfc$es_down THEN
                osp$set_status_abnormal (rfc$product_id, rfe$down_nad_not_changable,
                      nad_names_p^[nad_name_index], status);
                EXIT /scan_nad_names/;
              ELSEIF state = rfc$es_down THEN
                osp$set_status_abnormal (rfc$product_id, rfe$cannot_down_remote_nad, '', status);
                EXIT /scan_nad_names/;
              IFEND;
              rfv$status_table.remote_nads^[remote_nad_index].current_status.device_status := state;
            IFEND;
            IF nad_names_p^[nad_name_index] <> 'ALL' THEN
              CYCLE /scan_nad_names/;
            IFEND;
          IFEND;
        FOREND;
      IFEND;
      IF nad_names_p^[nad_name_index] <> 'ALL' THEN
        osp$set_status_abnormal (rfc$product_id, rfe$element_not_found, nad_names_p^[nad_name_index],
              status);
        EXIT /scan_nad_names/;
      IFEND;
    FOREND /scan_nad_names/;

    rfp$unlock_table (rfv$status_table.lock);

    IF status.normal AND (trunk_names_p <> NIL) THEN
      FOR trunk_name_index := LOWERBOUND(trunk_found_p^) TO UPPERBOUND(trunk_found_p^) DO
        IF NOT trunk_found_p^[trunk_name_index] THEN
          osp$set_status_abnormal (rfc$product_id, rfe$element_not_found, trunk_names_p^[trunk_name_index],
                status);
          RETURN;
        IFEND;
      FOREND;
    IFEND;

  PROCEND rfp$change_nad_or_trunk_state;
?? TITLE := '    rfp$change_host_or_lid_state', EJECT ??
  PROCEDURE [XDCL, #GATE] rfp$change_host_or_lid_state (
    physical_id_list_p: ^ARRAY [1 .. *] OF rft$physical_identifier;
    logical_id_list_p: ^ARRAY [1 .. *] OF rft$logical_identifier;
    all_pids_specified: BOOLEAN;
    state: BOOLEAN;
    VAR status: ost$status);

*copyc rfh$change_host_or_lid_state

    VAR
      lid_index: rft$logical_ids_per_host,
      lid_list_index,
      pid_list_index: INTEGER,
      pid_found_p,
      lid_found_p: ^ARRAY[1 .. *] OF BOOLEAN,
      local_pid_specified: BOOLEAN,
      remote_host_entry_p: ^rft$remote_host_definition,
      capabilities: ARRAY[1..1] OF ost$name;

    status.normal := TRUE;

    capabilities [1] := avc$network_operation;

    rfp$verify_caller_capability (^capabilities, 'change host or LID status', status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    rfp$lock_table (rfv$status_table.lock);
    IF NOT rfv$status_table.system_task_is_up THEN
      rfp$unlock_table (rfv$status_table.lock);
      IF logical_id_list_p = NIL THEN
        osp$set_status_abnormal (rfc$product_id, rfe$system_task_not_active, 'CHANGE_HOST_STATUS', status);
      ELSE
        osp$set_status_abnormal (rfc$product_id, rfe$system_task_not_active, 'CHANGE_LID_STATUS', status);
      IFEND;
      RETURN;
    IFEND;

    local_pid_specified := all_pids_specified;

    FOR pid_list_index := LOWERBOUND(physical_id_list_p^) TO UPPERBOUND(physical_id_list_p^) DO
      IF physical_id_list_p^[pid_list_index] = rfv$status_table.local_host^.physical_identifier THEN
        local_pid_specified := TRUE;
      IFEND;
    FOREND;

    IF logical_id_list_p <> NIL THEN
      PUSH lid_found_p: [1 .. UPPERBOUND(logical_id_list_p^)];
      FOR lid_list_index := LOWERBOUND(lid_found_p^) TO UPPERBOUND(lid_found_p^) DO
        lid_found_p^[lid_list_index] := FALSE;
      FOREND;
    IFEND;

    IF local_pid_specified THEN
      IF logical_id_list_p <> NIL THEN
        FOR lid_list_index := LOWERBOUND(logical_id_list_p^) TO UPPERBOUND(logical_id_list_p^) DO
        /scan_lids/
          FOR lid_index := LOWERBOUND(rfv$status_table.local_host^.logical_identifiers) TO
                    UPPERBOUND(rfv$status_table.local_host^.logical_identifiers) DO
            IF logical_id_list_p^[lid_list_index] =
                  rfv$status_table.local_host^.logical_identifiers[lid_index].logical_id THEN
              rfv$status_table.local_host^.logical_identifiers[lid_index].disabled := state;
              lid_found_p^[lid_list_index] := TRUE;
              EXIT /scan_lids/;
            IFEND;
          FOREND /scan_lids/;
        FOREND;
      ELSE;
        rfv$status_table.local_host^.disabled := state;
      IFEND;
    IFEND;

  /scan_remote_pids/
    FOR pid_list_index := LOWERBOUND(physical_id_list_p^) TO UPPERBOUND(physical_id_list_p^) DO
      remote_host_entry_p := rfv$status_table.remote_hosts;
      IF remote_host_entry_p <> NIL THEN
        REPEAT
          IF (physical_id_list_p^[pid_list_index] = remote_host_entry_p^.physical_identifier) OR
                all_pids_specified THEN
            IF logical_id_list_p <> NIL THEN
              FOR lid_list_index := LOWERBOUND(logical_id_list_p^) TO UPPERBOUND(logical_id_list_p^) DO
              /scan_remote_lids/
                FOR lid_index := LOWERBOUND(remote_host_entry_p^.logical_identifiers) TO
                      UPPERBOUND(remote_host_entry_p^.logical_identifiers) DO
                  IF logical_id_list_p^[lid_list_index] =
                        remote_host_entry_p^.logical_identifiers[lid_index].logical_id THEN
                    remote_host_entry_p^.logical_identifiers[lid_index].disabled := state;
                    lid_found_p^[lid_list_index] := TRUE;
                    EXIT /scan_remote_lids/;
                  IFEND;
                FOREND /scan_remote_lids/;
              FOREND;
            ELSE
              remote_host_entry_p^.disabled := state;
            IFEND;
            IF NOT all_pids_specified THEN
              CYCLE /scan_remote_pids/;
            IFEND;
          IFEND;
          remote_host_entry_p := remote_host_entry_p^.next_entry;
        UNTIL remote_host_entry_p = NIL;
      IFEND;
      IF NOT ((physical_id_list_p^[pid_list_index] = rfv$status_table.local_host^.physical_identifier) OR
            (physical_id_list_p^[pid_list_index] = '')) THEN
        osp$set_status_abnormal (rfc$product_id, rfe$physical_id_not_found,
              physical_id_list_p^[pid_list_index], status);
        EXIT /scan_remote_pids/;
      IFEND;
    FOREND /scan_remote_pids/;

    rfp$unlock_table (rfv$status_table.lock);

    IF status.normal AND (logical_id_list_p <> NIL) THEN
      FOR lid_list_index := LOWERBOUND(lid_found_p^) TO UPPERBOUND(lid_found_p^) DO
        IF lid_found_p^[lid_list_index] = FALSE THEN
          osp$set_status_abnormal (rfc$product_id, rfe$logical_id_not_found,
                logical_id_list_p^[lid_list_index], status);
          RETURN;
        IFEND;
      FOREND;
    IFEND;

  PROCEND rfp$change_host_or_lid_state;
?? TITLE := '    rfp$check_local_nad_test', EJECT ??
  PROCEDURE [XDCL, #GATE] rfp$check_local_nad_test (
    nad_name: rft$component_name;
    VAR local_nad_test_complete: BOOLEAN;
    VAR status: ost$status);

*copyc rfh$check_local_nad_test

    VAR
      user_attribute: ARRAY[1..1] OF ost$name,
      local_nad_index: rft$local_nads;

    status.normal := TRUE;
    local_nad_test_complete := FALSE;

    user_attribute[1] := avc$network_operation;

    rfp$verify_caller_capability (^user_attribute, 'check_local_NAD_test', status);

    IF NOT status.normal THEN
      RETURN;
    IFEND;

    rfp$lock_table (rfv$status_table.lock);
    IF NOT rfv$status_table.system_task_is_up THEN
      rfp$unlock_table (rfv$status_table.lock);
      osp$set_status_abnormal (rfc$product_id, rfe$system_task_not_active, 'TEST_LOCAL_NAD', status);
      RETURN;
    IFEND;

  /scan_nad_names/
    BEGIN
      FOR local_nad_index := LOWERBOUND(rfv$status_table.local_nads^) TO
            UPPERBOUND(rfv$status_table.local_nads^) DO
        IF (rfv$status_table.local_nads^[local_nad_index].name = nad_name) THEN
          IF (rfv$status_table.local_nads^[local_nad_index].maintenance_status.test_requested =FALSE) THEN
            local_nad_test_complete := TRUE;
            IF (rfv$status_table.local_nads^[local_nad_index].current_status.device_status <> rfc$es_on) THEN
              osp$set_status_abnormal (rfc$product_id, rfe$test_nad_failure,
                    nad_name, status);
            IFEND;
          IFEND;
          EXIT /scan_nad_names/;
        IFEND;
      FOREND;
      osp$set_status_abnormal (rfc$product_id, rfe$element_not_found, nad_name,
              status);

    END /scan_nad_names/;
    rfp$unlock_table (rfv$status_table.lock);

  PROCEND rfp$check_local_nad_test;
?? TITLE := '    rfp$initiate_local_nad_test', EJECT ??
  PROCEDURE [XDCL, #GATE] rfp$initiate_local_nad_test (
    nad_name: rft$component_name;
    VAR status: ost$status);

*copyc rfh$initiate_local_nad_test

    VAR
      user_attribute: ARRAY[1..1] OF ost$name,
      local_nad_index: rft$local_nads;

    status.normal := TRUE;

    user_attribute[1] := avc$network_operation;

    rfp$verify_caller_capability (^user_attribute, 'check_local_NAD_test', status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    rfp$lock_table (rfv$status_table.lock);
    IF NOT rfv$status_table.system_task_is_up THEN
      rfp$unlock_table (rfv$status_table.lock);
      osp$set_status_abnormal (rfc$product_id, rfe$system_task_not_active, 'TEST_LOCAL_NADS', status);
      RETURN;
    IFEND;

  /scan_nad_names/
    BEGIN
      FOR local_nad_index := LOWERBOUND(rfv$status_table.local_nads^) TO
            UPPERBOUND(rfv$status_table.local_nads^) DO
        IF (rfv$status_table.local_nads^[local_nad_index].name = nad_name) THEN
          IF (rfv$status_table.local_nads^[local_nad_index].current_status.device_status <> rfc$es_off) THEN
            osp$set_status_abnormal (rfc$product_id, rfe$improper_nad_state_for_test,
                  nad_name, status);
          ELSEIF (rfv$status_table.local_nads^[local_nad_index].maintenance_status.test_requested = TRUE) THEN
            osp$set_status_abnormal (rfc$product_id, rfe$test_already_in_process,
                  nad_name, status);
          ELSE
            rfv$status_table.local_nads^[local_nad_index].maintenance_status.test_requested := TRUE;
            rfv$status_table.local_nads^[local_nad_index].maintenance_status.reloads_performed := 0;
            rfv$status_table.local_nads^[local_nad_index].maintenance_status.reload_failed := FALSE;
            rfv$status_table.local_nads^[local_nad_index].current_status.device_status := rfc$es_down;
          IFEND;
          EXIT /scan_nad_names/;
        IFEND;
      FOREND;
      osp$set_status_abnormal (rfc$product_id, rfe$element_not_found, nad_name,
              status);
    END /scan_nad_names/;
    rfp$unlock_table (rfv$status_table.lock);

  PROCEND rfp$initiate_local_nad_test;
?? OLDTITLE ??

MODEND rfm$change_state_commands_r3
