Modification on SFC test Cases
[integration/test.git] / csit / libraries / BgpOperations.robot
index 8929146633951bd3996beb31709201c97b6359f7..97ba03c3e91052b0751968b8ac66aa608134bebd 100644 (file)
@@ -1,8 +1,10 @@
 *** 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          CompareStream.robot
 Resource          Utils.robot
 Resource          KillPythonTool.robot
 Resource          TemplatedRequests.robot
@@ -14,10 +16,12 @@ ${BGP_RIB_URI}    ${OPERATIONAL_API}/bgp-rib:bgp-rib/rib/example-bgp-rib
 ${BGP_TOPOLOGY_URI}    ${OPERATIONAL_TOPO_API}/topology/example-ipv4-topology
 ${VAR_BASE_BGP}    ${CURDIR}/../variables/bgpfunctional
 ${RIB_NAME}       example-bgp-rib
-&{ADJ_RIB_IN}     PATH=peer/bgp:%2F%2F${TOOLS_SYSTEM_IP}/adj-rib-in    BGP_RIB=${RIB_NAME}
+${OLD_AS_PATH}    \n"as-path": {},
+${NEW_AS_PATH}    ${EMPTY}
 &{APP_PEER}       IP=${ODL_SYSTEM_IP}    BGP_RIB=${RIB_NAME}
-&{EFFECTIVE_RIB_IN}    PATH=peer/bgp:%2F%2F${TOOLS_SYSTEM_IP}/effective-rib-in    BGP_RIB=${RIB_NAME}
-&{LOC_RIB}        PATH=loc-rib    BGP_RIB=${RIB_NAME}
+${NEW_IPV4_ROUTES_LINE}    ${EMPTY}
+${OLD_IPV4_ROUTES_LINE}    \n"bgp-inet:ipv4-routes": {},
+${BGP_CONFIG_SERVER_CMD}    bgp-connect -h ${ODL_SYSTEM_IP} -p 7644 add
 
 *** Keywords ***
 Start Quagga Processes On ODL
@@ -62,12 +66,18 @@ Start Quagga Processes On DCGW
 
 Restart BGP Processes On DCGW
     [Arguments]    ${dcgw_ip}
-    [Documentation]    To Restart the zrpcd, bgpd,and zebra processes on DCGW
+    [Documentation]    To Restart the zrpcd, bgpd and zebra processes on DCGW
     ${dcgw_conn_id} =    Open_Connection_To_Tools_System    ip_address=${dcgw_ip}
     Switch Connection    ${dcgw_conn_id}
     Write Commands Until Expected Prompt    sudo pkill -f bgpd    ${DEFAULT_LINUX_PROMPT_STRICT}
     Start Quagga Processes On DCGW    ${dcgw_ip}
 
+Stop BGP Processes On Node
+    [Arguments]    ${node_ip}
+    [Documentation]    To stop the bgpd , qthriftd processes on specific node given by user.
+    Utils.Run Command On Remote System    ${node_ip}    sudo pkill -f bgpd
+    Utils.Run Command On Remote System    ${node_ip}    sudo pkill -f zrpcd
+
 Show Quagga Configuration On ODL
     [Arguments]    ${odl_ip}    ${rd}
     [Documentation]    Show quagga config from ODL
@@ -151,6 +161,26 @@ Verify BGP Neighbor Status On Quagga
     Log    ${output}
     Should Contain    ${output}    BGP state = Established
 
+Setup BGP Peering On ODL
+    [Arguments]    ${odl_ip}    ${as_id}    ${nbr_ip}
+    [Documentation]    Setup BGP peering between ODL and given neighbor IP.
+    ...    Configuring and starting BGP on ODL node with given AS number
+    ...    Adding and verifying BGP neighbor
+    KarafKeywords.Issue Command On Karaf Console    ${BGP_CONFIG_SERVER_CMD}
+    BgpOperations.Create BGP Configuration On ODL    localas=${as_id}    routerid=${odl_ip}
+    BgpOperations.AddNeighbor To BGP Configuration On ODL    remoteas=${as_id}    neighborAddr=${nbr_ip}
+    ${output} =    BgpOperations.Get BGP Configuration On ODL    session
+    BuiltIn.Should Contain    ${output}    ${nbr_ip}
+
+Setup BGP Peering On DCGW
+    [Arguments]    ${dcgw_ip}    ${as_id}    ${nbr_ip}    ${vrf_name}    ${rd}    ${loopback_ip}
+    [Documentation]    Setup BGP peering between DCGW and given neighbor IP.
+    ...    Configuring,adding neighbor on DCGW node and verifying BGP neighbor.
+    BgpOperations.Configure BGP And Add Neighbor On DCGW    ${dcgw_ip}    ${as_id}    ${dcgw_ip}    ${nbr_ip}    ${vrf_name}    ${rd}
+    ...    ${loopback_ip}
+    ${output} =    BgpOperations.Execute Show Command On Quagga    ${dcgw_ip}    ${RUN_CONFIG}
+    BuiltIn.Should Contain    ${output}    ${nbr_ip}
+
 Verify Routes On Quagga
     [Arguments]    ${dcgw_ip}    ${rd}    ${ip_list}
     [Documentation]    Verify routes on quagga
@@ -300,44 +330,59 @@ Bmp_Monitor_Precondition
 Bmp_Monitor_Postcondition
     [Arguments]    ${session}
     [Documentation]    Verifies if example-bmp-monitor data contains one peer.
-    &{mapping}    BuiltIn.Create_Dictionary    TOOL_IP=${TOOLS_SYSTEM_IP}
+    ${routes_line} =    CompareStream.Set_Variable_If_At_Least_Neon    ${NEW_IPV4_ROUTES_LINE}    ${OLD_IPV4_ROUTES_LINE}
+    &{mapping}    BuiltIn.Create_Dictionary    TOOL_IP=${TOOLS_SYSTEM_IP}    ROUTES_LINE=${routes_line}
     ${output}    BuiltIn.Wait_Until_Keyword_Succeeds    10x    5s    TemplatedRequests.Get_As_Json_Templated    folder=${BGP_BMP_DIR}    mapping=${mapping}
     ...    session=${session}    verify=True
     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
+    ${as_path} =    CompareStream.Set_Variable_If_At_Least_Neon    ${NEW_AS_PATH}    ${OLD_AS_PATH}
+    &{adj_rib_in}    BuiltIn.Create_Dictionary    PATH=peer/bgp:%2F%2F${TOOLS_SYSTEM_IP}/adj-rib-in    BGP_RIB=${RIB_NAME}    AS_PATH=${as_path}
+    &{effective_rib_in}    BuiltIn.Create_Dictionary    PATH=peer/bgp:%2F%2F${TOOLS_SYSTEM_IP}/effective-rib-in    BGP_RIB=${RIB_NAME}    AS_PATH=${as_path}
+    &{loc_rib}    BuiltIn.Create_Dictionary    PATH=loc-rib    BGP_RIB=${RIB_NAME}    AS_PATH=${as_path}
     ${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}
+    BuiltIn.Wait_Until_Keyword_Succeeds    3x    2s    TemplatedRequests.Get_As_Json_Templated    ${dir}/${totest}/rib    mapping=${adj_rib_in}    session=${CONFIG_SESSION}
     ...    verify=True
-    BuiltIn.Wait_Until_Keyword_Succeeds    3x    2s    TemplatedRequests.Get_As_Json_Templated    ${dir}/${totest}/rib    mapping=${EFFECTIVE_RIB_IN}    session=${CONFIG_SESSION}
+    BuiltIn.Wait_Until_Keyword_Succeeds    3x    2s    TemplatedRequests.Get_As_Json_Templated    ${dir}/${totest}/rib    mapping=${effective_rib_in}    session=${CONFIG_SESSION}
     ...    verify=True
-    BuiltIn.Wait_Until_Keyword_Succeeds    3x    2s    TemplatedRequests.Get_As_Json_Templated    ${dir}/${totest}/rib    mapping=${LOC_RIB}    session=${CONFIG_SESSION}
+    BuiltIn.Wait_Until_Keyword_Succeeds    3x    2s    TemplatedRequests.Get_As_Json_Templated    ${dir}/${totest}/rib    mapping=${loc_rib}    session=${CONFIG_SESSION}
     ...    verify=True
     BgpRpcClient.play_send    ${withdraw_hex}
-    BuiltIn.Wait_Until_Keyword_Succeeds    3x    2s    TemplatedRequests.Get_As_Json_Templated    ${dir}/empty_routes/${ipv}    mapping=${LOC_RIB}    session=${CONFIG_SESSION}
+    BuiltIn.Wait_Until_Keyword_Succeeds    3x    2s    TemplatedRequests.Get_As_Json_Templated    ${dir}/empty_routes/${ipv}    mapping=${loc_rib}    session=${CONFIG_SESSION}
     ...    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}
+    ${as_path} =    CompareStream.Set_Variable_If_At_Least_Neon    ${NEW_AS_PATH}    ${OLD_AS_PATH}
+    &{loc_rib}    BuiltIn.Create_Dictionary    PATH=loc-rib    BGP_RIB=${RIB_NAME}    AS_PATH=${as_path}
+    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 +393,20 @@ 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.
+    ${final_sum} =    BuiltIn.Evaluate    sum(map(lambda x: int(x, 16), re.compile('[a-f\d]{2}').findall('${hex_string}'[32:])))    modules=re
+    [Return]    ${final_sum}