Added MAC verify on fwenv testcases

Changes:
     -Configure Valid MAC And Verify
     -Configure Invalid MAC And Verify on FW_Env
     -Configure Valid MAC And Verify Persistency
     -Configure Invalid MAC And Verify Persistency On FW_Env
     -Added Validate MAC On FW_Env in test teardown
     -Configure Out Of Range MAC And Verify
     -Configure More Byte MAC And Verify

Keywords added:
     -Get FW_Env MAC Address
     -Truncate MAC Address
     -Truncate MAC bits
     -Validate MAC On FW_Env
     -Verify MAC Address via FW_Env

Change-Id: Ie72fa551497bd27c9d1befb04f33e5b213e989c5
Signed-off-by: shrsuman123 <shrsuman@in.ibm.com>
diff --git a/lib/bmc_network_utils.robot b/lib/bmc_network_utils.robot
index 0bd6403..4a7d7ea 100644
--- a/lib/bmc_network_utils.robot
+++ b/lib/bmc_network_utils.robot
@@ -153,6 +153,24 @@
 
     [Return]  ${output}
 
+Get FW_Env MAC Address
+    [Documentation]  Get FW_Env MAC address.
+
+    # Sample output of "fw_printenv | grep ethaddr"
+    # ethaddr=xx:xx:xx:xx:xx:xx:xx
+
+    ${cmd_output}  ${stderr}  ${rc}=  BMC Execute Command
+    ...  /sbin/fw_printenv | grep ethaddr
+
+    # Split the line and return MAC address.
+    # Split list data:
+    # ethaddr | xx:xx:xx:xx:xx:xx:xx
+
+    @{words}=  Split String  ${cmd_output}  =
+
+    [Return]  ${words[1]}
+
+
 Get List Of IP Address Via REST
     [Documentation]  Get list of IP address via REST.
     [Arguments]  @{ip_uri_list}
@@ -249,10 +267,63 @@
     # mac_addr  MAC address of the BMC.
 
     ${system_mac}=  Get BMC MAC Address
+    ${mac_new_addr}=  Truncate MAC Address  ${system_mac}  ${mac_addr}
 
-    ${status}=  Compare MAC Address  ${system_mac}  ${mac_addr}
+    ${status}=  Compare MAC Address  ${system_mac}  ${mac_new_addr}
     Should Be True  ${status}
-    ...  msg=MAC address ${system_mac} does not match ${mac_addr}.
+    ...  msg=MAC address ${system_mac} does not match ${mac_new_addr}.
+
+Validate MAC On FW_Env
+    [Documentation]  Validate MAC on FW_Env.
+    [Arguments]  ${mac_addr}
+
+    # Description of argument(s):
+    # mac_addr  MAC address of the BMC.
+
+    ${fw_env_addr}=  Get FW_Env MAC Address
+    ${mac_new_addr}=  Truncate MAC Address  ${fw_env_addr}  ${mac_addr}
+
+    ${status}=  Compare MAC Address  ${fw_env_addr}  ${mac_new_addr}
+    Should Be True  ${status}
+    ...  msg=MAC address ${fw_env_addr} does not match ${mac_new_addr}.
+
+Truncate MAC Address
+    [Arguments]    ${sys_mac_addr}  ${user_mac_addr}
+    # Description of argument(s):
+    # sys_mac_addr  MAC address of the BMC.
+    # user_mac_addr user provided MAC address.
+
+    ${mac_byte}=  Set Variable  ${0}
+    @{user_mac_list}=  Split String  ${user_mac_addr}  :
+    @{sys_mac_list}=  Split String  ${sys_mac_addr}  :
+    ${user_new_mac_list}  Create List
+
+    # Truncate extra bytes and bits from MAC address
+    FOR  ${mac_item}  IN  @{sys_mac_list}
+        ${invalid_mac_byte} =  Get Regexp Matches  ${user_mac_list}[${mac_byte}]  [^A-Za-z0-9]+
+        Return From Keyword If  ${invalid_mac_byte}  ${user_mac_addr}
+        ${mac_int} =    Convert To Integer      ${user_mac_list}[${mac_byte}]   16
+        ${user_mac_len} =  Get Length  ${user_mac_list}
+        ${user_mac_byte}=  Run Keyword IF  ${mac_int} >= ${256}  Truncate MAC Bits  ${user_mac_list}[${mac_byte}]
+                                      ...  ELSE  Set Variable  ${user_mac_list}[${mac_byte}]
+
+        Append To List  ${user_new_mac_list}  ${user_mac_byte}
+        ${mac_byte} =    Set Variable    ${mac_byte + 1}
+        Exit For Loop If  '${mac_byte}' == '${user_mac_len}'
+
+    END
+    ${user_new_mac_string}=   Evaluate  ":".join(${user_new_mac_list})
+    [Return]  ${user_new_mac_string}
+
+Truncate MAC Bits
+    [Arguments]    ${user_mac_addr_byte}
+    # Description of argument(s):
+    # user_mac_addr_byte user provided MAC address byte to truncate bits
+
+    ${user_mac_addr_int}=   Convert To List  ${user_mac_addr_byte}
+    ${user_mac_addr_byte}=  Get Slice From List  ${user_mac_addr_int}  0  2
+    ${user_mac_addr_byte_string}=  Evaluate  "".join(${user_mac_addr_byte})
+    [Return]  ${user_mac_addr_byte_string}
 
 
 Run Build Net