update odltools cli to use netvirt subcommand
[integration/test.git] / csit / libraries / BgpOperations.robot
index 8929146633951bd3996beb31709201c97b6359f7..c16b4bb57776c4aa2484d6d54157ba9fee4d0006 100644 (file)
@@ -1,6 +1,7 @@
 *** Settings ***
 Documentation     This library contains keywords related to the BGP functionality.
 Library           SSHLibrary
+Library           String
 Library           BgpRpcClient.py    ${TOOLS_SYSTEM_IP}
 Resource          ../variables/Variables.robot
 Resource          Utils.robot
@@ -306,25 +307,25 @@ Bmp_Monitor_Postcondition
     BuiltIn.Log    ${output}
 
 Odl_To_Play_Template
-    [Arguments]    ${totest}    ${dir}
+    [Arguments]    ${totest}    ${dir}    ${remove}=True
     ${announce_hex} =    OperatingSystem.Get_File    ${dir}/${totest}/announce_${totest}.hex
     ${announce_hex} =    String.Remove_String    ${announce_hex}    \n
     ${withdraw_hex} =    OperatingSystem.Get_File    ${dir}/${totest}/withdraw_${totest}.hex
     ${withdraw_hex} =    String.Remove_String    ${withdraw_hex}    \n
-    BgpRpcClient.play_clean
+    BuiltIn.Run_Keyword_If    '${remove}' == 'True'    BgpRpcClient.play_clean
     TemplatedRequests.Post_As_Xml_Templated    ${dir}/${totest}/app    mapping=${APP_PEER}    session=${CONFIG_SESSION}
     ${update}    BuiltIn.Wait_Until_Keyword_Succeeds    3x    2s    Get_Update_Message
-    BuiltIn.Should_Be_Equal_As_Strings    ${update}    ${announce_hex}
+    Verify_Two_Hex_Messages_Are_Equal    ${update}    ${announce_hex}
     BgpRpcClient.play_clean
     Remove_Configured_Routes    ${totest}    ${dir}
     ${update}    BuiltIn.Wait_Until_Keyword_Succeeds    3x    2s    Get_Update_Message
-    BuiltIn.Should_Be_Equal_As_Strings    ${update}    ${withdraw_hex}
+    Verify_Two_Hex_Messages_Are_Equal    ${update}    ${withdraw_hex}
     [Teardown]    Remove_Configured_Routes    ${totest}    ${dir}
 
 Play_To_Odl_Template
     [Arguments]    ${totest}    ${dir}    ${ipv}=ipv4
-    ${announce_hex} =    OperatingSystem.Get_File    ${dir}/${totest}/announce_${totest}.hex
-    ${withdraw_hex} =    OperatingSystem.Get_File    ${dir}/${totest}/withdraw_${totest}.hex
+    ${announce_hex}=    OperatingSystem.Get_File    ${dir}/${totest}/announce_${totest}.hex
+    ${withdraw_hex}=    OperatingSystem.Get_File    ${dir}/${totest}/withdraw_${totest}.hex
     BgpRpcClient.play_clean
     BgpRpcClient.play_send    ${announce_hex}
     BuiltIn.Wait_Until_Keyword_Succeeds    3x    2s    TemplatedRequests.Get_As_Json_Templated    ${dir}/${totest}/rib    mapping=${ADJ_RIB_IN}    session=${CONFIG_SESSION}
@@ -338,6 +339,14 @@ Play_To_Odl_Template
     ...    verify=True
     [Teardown]    BgpRpcClient.play_send    ${withdraw_hex}
 
+Play_To_Odl_Non_Removal_Template
+    [Arguments]    ${totest}    ${dir}    ${ipv}=ipv4
+    ${announce_hex}=    OperatingSystem.Get_File    ${dir}/${totest}/announce_${totest}.hex
+    BgpRpcClient.play_clean
+    BgpRpcClient.play_send    ${announce_hex}
+    BuiltIn.Wait_Until_Keyword_Succeeds    3x    2s    TemplatedRequests.Get_As_Json_Templated    ${dir}/${totest}/rib    mapping=${LOC_RIB}    session=${CONFIG_SESSION}
+    ...    verify=True
+
 Get_Update_Message
     [Documentation]    Returns hex update message.
     ${update} =    BgpRpcClient.play_get
@@ -348,3 +357,27 @@ Remove_Configured_Routes
     [Arguments]    ${totest}    ${dir}
     [Documentation]    Removes the route if present.
     BuiltIn.Run_Keyword_And_Ignore_Error    TemplatedRequests.Delete_Templated    ${dir}/${totest}/app    mapping=${APP_PEER}    session=${CONFIG_SESSION}
+
+Verify_Two_Hex_Messages_Are_Equal
+    [Arguments]    ${hex_1}    ${hex_2}
+    [Documentation]    Verifies two hex messages are equal even in case, their arguments are misplaced.
+    ...    Compares length of the hex messages and sums hex messages arguments as integers and compares results.
+    ${len_1}=    BuiltIn.Get_Length    ${hex_1}
+    ${len_2}=    BuiltIn.Get_Length    ${hex_2}
+    BuiltIn.Should_Be_Equal    ${len_1}    ${len_2}
+    ${sum_1}=    Sum_Hex_Message_Arguments_To_Integer    ${hex_1}
+    ${sum_2}=    Sum_Hex_Message_Arguments_To_Integer    ${hex_2}
+    BuiltIn.Should_Be_Equal    ${sum_1}    ${sum_2}
+
+Sum_Hex_Message_Arguments_To_Integer
+    [Arguments]    ${hex_string}
+    [Documentation]    Converts hex message arguments to integers and sums them up and returns the sum.
+    ${partial_results}=    BuiltIn.Create_List
+    ${string}=    String.Get_Substring    ${hex_string}    32
+    @{list}=    String.Get_Regexp_Matches    ${string}    [a-f0-9][a-f0-9]
+    : FOR    ${i}    IN    @{list}
+    \    ${item_int}=    BuiltIn.Convert_To_Integer    ${i}    16
+    \    Collections.Append_To_List    ${partial_results}    ${item_int}
+    \    BuiltIn.Log    ${partial_results}
+    ${final_sum}=    BuiltIn.Evaluate    sum(${partial_results})
+    [Return]    ${final_sum}