text: ##########################################################################
  # If not stated otherwise in this file or this component's Licenses.txt
  # file the following copyright and licenses apply:
  #
  # Copyright 2016 RDK Management
  #
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  #
  # http://www.apache.org/licenses/LICENSE-2.0
  #
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  ##########################################################################
  '''
  <?xml version="1.0" encoding="UTF-8"?><xml>
    <id/>
    <version>1</version>
    <name>TS_WIFIAGENT_5GHZ_RadioLastChange</name>
    <primitive_test_id/>
    <primitive_test_name>WIFIAgent_Get</primitive_test_name>
    <primitive_test_version>1</primitive_test_version>
    <status>FREE</status>
    <synopsis>Check if LastChange value change on enabling/disabling Radio.2</synopsis>
    <groups_id/>
    <execution_time>10</execution_time>
    <long_duration>false</long_duration>
    <advanced_script>false</advanced_script>
    <remarks/>
    <skip>false</skip>
    <box_types>
      <box_type>Broadband</box_type>
      <box_type>Emulator</box_type>
      <box_type>RPI</box_type>
    </box_types>
    <rdk_versions>
      <rdk_version>RDKB</rdk_version>
    </rdk_versions>
    <test_cases>
      <test_case_id>TC_WIFIAGENT_34</test_case_id>
      <test_objective>Check if LastChange value change on enabling/disabling Radio.2</test_objective>
      <test_type>Positive</test_type>
      <test_setup>XB3, Emulator, Rpi</test_setup>
      <pre_requisite>1.Ccsp Components in DUT should be in a running state that includes component under test Cable Modem
  2.TDK Agent should be in running state or invoke it through StartTdk.sh script</pre_requisite>
      <api_or_interface_used>WIFIAgent_Get
  WIFIAgent_Set</api_or_interface_used>
      <input_parameters>Device.WiFi.Radio.2.Enable
  Device.WiFi.Radio.2.LastChange</input_parameters>
      <automation_approch>1. Load wifiagent module
  2. Using WIFIAgent_Get, get and save Device.WiFi.Radio.2.Enable
  3. Using WIFIAgent_Get, get and save Device.WiFi.Radio.2.LastChange
  4. Using WIFIAgent_Set, toggle value of Device.WiFi.Radio.2.Enable
  5. Using WIFIAgent_Get, get  the value of Device.WiFi.Radio.2.LastChange and compare it with previous value
  6. Check if lastchange value is less than the previously saved value
  7. Restrore values of Device.WiFi.Radio.2.Enable, Device.WiFi.Radio.2.LastChange
  8. Unload wifiagent module</automation_approch>
      <except_output>LastChange value should change on enabling/disabling Radio.2</except_output>
      <priority>High</priority>
      <test_stub_interface>WifiAgent</test_stub_interface>
      <test_script>TS_WIFIAGENT_5GHZ_RadioLastChange</test_script>
      <skipped>No</skipped>
      <release_version/>
      <remarks/>
    </test_cases>
  </xml>
  
  '''
  # use tdklib library,which provides a wrapper for tdk testcase script 
  import tdklib; 
  
  #Test component to be tested
  obj = tdklib.TDKScriptingLibrary("wifiagent","1");
  
  #IP and Port of box, No need to change,
  #This will be replaced with correspoing Box Ip and port while executing script
  ip = <ipaddress>
  port = <port>
  obj.configureTestCase(ip,port,'TS_WIFIAGENT_5GHZ_RadioLastChange');
  
  #Get the result of connection with test component and DUT
  loadmodulestatus =obj.getLoadModuleResult();
  print "[LIB LOAD STATUS]  :  %s" %loadmodulestatus
  
  if "SUCCESS" in loadmodulestatus.upper():
      obj.setLoadModuleStatus("SUCCESS");
  
      #Prmitive test case which associated to this Script
      tdkTestObj = obj.createTestStep('WIFIAgent_Get');
      tdkTestObj.addParameter("paramName","Device.WiFi.Radio.2.Enable")
      expectedresult="SUCCESS";
  
      #Execute the test case in DUT
      tdkTestObj.executeTestCase(expectedresult);
      actualresult = tdkTestObj.getResult();
      details = tdkTestObj.getResultDetails();
  
      if expectedresult in actualresult:
          #Set the result status of execution
          tdkTestObj.setResultStatus("SUCCESS");
          print "TEST STEP 1: Get the state of SSID2";
          print "EXPECTED RESULT 1: Should get the state of SSID2"
          orgState = details.split("VALUE:")[1].split(' ')[0];
          print "ACTUAL RESULT 1: State is %s %s" %(details,orgState);
          #Get the result of execution
          print "[TEST EXECUTION RESULT] : SUCCESS";
  
          #Get and save the LastChange value
          tdkTestObj = obj.createTestStep('WIFIAgent_Get');
          tdkTestObj.addParameter("paramName","Device.WiFi.Radio.2.LastChange")
          tdkTestObj.executeTestCase(expectedresult);
          actualresult = tdkTestObj.getResult();
          details = tdkTestObj.getResultDetails();
  
          if expectedresult in actualresult:
              #Set the result status of execution
              tdkTestObj.setResultStatus("SUCCESS");
              print "TEST STEP 1: get LastChange value"
              print "EXPECTED RESULT 1: Should get LastChange value"
  	    lastChange = int(details.split("VALUE:")[1].split(' ')[0]);
              print "ACTUAL RESULT 1: value is %s " %details;
              #Get the result of execution
              print "[TEST EXECUTION RESULT] : SUCCESS";  
  
  	#toggle Device.WiFi.Radio.2.Enable value
  	    if orgState == "false":
  		toggle = "true"
  	    else:
  		toggle = "false"
              tdkTestObj = obj.createTestStep('WIFIAgent_Set');
              tdkTestObj.addParameter("paramName","Device.WiFi.Radio.2.Enable")
              tdkTestObj.addParameter("paramValue",toggle)
              tdkTestObj.addParameter("paramType","boolean")
              tdkTestObj.executeTestCase(expectedresult);
              actualresult = tdkTestObj.getResult();
              details = tdkTestObj.getResultDetails();
  
              if expectedresult in actualresult:
                  tdkTestObj.setResultStatus("SUCCESS");
                  print "TEST STEP 1: Toggle SSID2 state";
                  print "EXPECTED RESULT 1: SSID2 staus should be toggled";
                  print "ACTUAL RESULT 1: %s" %details;
                  #Get the result of execution
                  print "[TEST EXECUTION RESULT] : SUCCESS";
  
  		#check lastchange value after toggling
                  tdkTestObj = obj.createTestStep('WIFIAgent_Get');
                  tdkTestObj.addParameter("paramName","Device.WiFi.Radio.2.LastChange")
                  tdkTestObj.executeTestCase(expectedresult);
                  actualresult = tdkTestObj.getResult();
                  details = tdkTestObj.getResultDetails();
                  lastChange2 = int(details.split("VALUE:")[1].split(' ')[0]);
  
                  if expectedresult in actualresult and lastChange2 < lastChange:
                      tdkTestObj.setResultStatus("SUCCESS");
                      print "TEST STEP 1: Check lastchange value"
                      print "EXPECTED RESULT 1: lastchange should be less than its previous value"
                      print "ACTUAL RESULT 1: %s" %details;
                      #Get the result of execution
                      print "[TEST EXECUTION RESULT] : SUCCESS";
  		else:
                      tdkTestObj.setResultStatus("FAILURE");
                      print "TEST STEP 1: Check lastchange value"
                      print "EXPECTED RESULT 1: lastchange should be less than its previous value"
                      print "ACTUAL RESULT 1: %s" %details;
                      #Get the result of execution
                      print "[TEST EXECUTION RESULT] : FAILURE";
  
  		#Change the Radio.2 state to its previous value
                  tdkTestObj = obj.createTestStep('WIFIAgent_Set');
                  tdkTestObj.addParameter("paramName","Device.WiFi.Radio.2.Enable")
                  tdkTestObj.addParameter("paramValue",orgState)
                  tdkTestObj.addParameter("paramType","boolean")
                  tdkTestObj.executeTestCase(expectedresult);
                  actualresult = tdkTestObj.getResult();
                  details = tdkTestObj.getResultDetails();
  
                  if expectedresult in actualresult:
                      #Set the result status of execution
                      tdkTestObj.setResultStatus("SUCCESS");
                      print "TEST STEP 1: Restore Enable state of SSID2";
                      print "EXPECTED RESULT 1: Should Restore Enable state of SSID2";
                      print "ACTUAL RESULT 1: State is %s " %details;
                      #Get the result of execution
                      print "[TEST EXECUTION RESULT] : SUCCESS";
                  else:
                       #Set the result status of execution
                      tdkTestObj.setResultStatus("FAILURE");
                      print "TEST STEP 1: Restore Enable state of SSID2";
                      print "EXPECTED RESULT 1: Should Restore Enable state of SSID2";
                      print "ACTUAL RESULT 1: State is %s " %details;
                      #Get the result of execution
                      print "[TEST EXECUTION RESULT] : FAILURE";
  	    else:
                  tdkTestObj.setResultStatus("FAILURE");
                  print "TEST STEP 1: Toggle SSID2 state";
                  print "EXPECTED RESULT 1: SSID2 staus should be toggled";
                  print "ACTUAL RESULT 1: %s" %details;
                  #Get the result of execution
                  print "[TEST EXECUTION RESULT] : FAILURE";
  	else:
              #Set the result status of execution
              tdkTestObj.setResultStatus("FAILURE");
              print "TEST STEP 1: get LastChange value"
              print "EXPECTED RESULT 1: Should get LastChange value"
              print "ACTUAL RESULT 1: value is %s " %details;
              #Get the result of execution
              print "[TEST EXECUTION RESULT] : FAILURE";
      else:
          tdkTestObj.setResultStatus("FAILURE");
          print "TEST STEP 1: Get the state of SSID2"
          print "EXPECTED RESULT 1: Failure in getting the state of SSID2"
          print "ACTUAL RESULT 1: State is %s" %details;
          print "[TEST EXECUTION RESULT] : FAILURE";
  
      obj.unloadModule("wifiagent");
  
  else:
          print "Failed to load wifi module";
          obj.setLoadModuleStatus("FAILURE");
          print "Module loading failed";
  