SXP: Fix 020_Sxp_Node_Switching.robot
[integration/test.git] / csit / libraries / BgpOperations.robot
index 78c9977bddc9c824600f088570c33a4fdad89608..45342ff1100bcb2baadac62e46b838a9834eaf2e 100644 (file)
@@ -1,10 +1,12 @@
 *** Settings ***
 Documentation     This library contains keywords related to the BGP functionality.
 Library           SSHLibrary
-Resource          Utils.robot
+Library           String
+Library           BgpRpcClient.py    ${TOOLS_SYSTEM_IP}
 Resource          ../variables/Variables.robot
-Resource          TemplatedRequests.robot
+Resource          Utils.robot
 Resource          KillPythonTool.robot
+Resource          TemplatedRequests.robot
 
 *** Variables ***
 ${BGP_BMP_DIR}    ${CURDIR}/../variables/bgpfunctional/bmp_basic/filled_structure
@@ -12,6 +14,11 @@ ${BGP_BMP_FEAT_DIR}    ${CURDIR}/../variables/bgpfunctional/bmp_basic/empty_stru
 ${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}
+&{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}
 
 *** Keywords ***
 Start Quagga Processes On ODL
@@ -26,6 +33,14 @@ Start Quagga Processes On ODL
     Write Commands Until Expected Prompt    netstat -nap | grep 7644    ${DEFAULT_LINUX_PROMPT_STRICT}
     Close Connection
 
+Restart BGP Processes On ODL
+    [Arguments]    ${odl_ip}
+    [Documentation]    To restart the bgpd , qthriftd processes on ODL VM
+    ${conn_id} =    Open_Connection_To_ODL_System    ip_address=${odl_ip}
+    Switch Connection    ${conn_id}
+    Write Commands Until Expected Prompt    sudo pkill -f bgpd    ${DEFAULT_LINUX_PROMPT_STRICT}
+    Start Quagga Processes On ODL    ${odl_ip}
+
 Start Quagga Processes On DCGW
     [Arguments]    ${dcgw_ip}
     [Documentation]    To start the zrpcd, bgpd,and zebra processes on DCGW
@@ -46,6 +61,14 @@ Start Quagga Processes On DCGW
     Write Commands Until Expected Prompt    ps -ef | grep zebra    ${DEFAULT_LINUX_PROMPT_STRICT}
     Write Commands Until Expected Prompt    netstat -nap | grep 7644    ${DEFAULT_LINUX_PROMPT_STRICT}
 
+Restart BGP Processes On DCGW
+    [Arguments]    ${dcgw_ip}
+    [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}
+
 Show Quagga Configuration On ODL
     [Arguments]    ${odl_ip}    ${rd}
     [Documentation]    Show quagga config from ODL
@@ -148,6 +171,45 @@ Delete BGP Config On Quagga
     Execute Command On Quagga Telnet Session    exit
     [Return]    ${output}
 
+Create L3VPN on DCGW
+    [Arguments]    ${dcgw_ip}    ${as_id}    ${vpn_name}    ${rd}
+    [Documentation]    Creating L3VPN on DCGW
+    BgpOperations.Create Quagga Telnet Session    ${dcgw_ip}    bgpd    sdncbgpc
+    BgpOperations.Execute Command On Quagga Telnet Session    configure terminal
+    BgpOperations.Execute Command On Quagga Telnet Session    router bgp ${as_id}
+    BgpOperations.Execute Command On Quagga Telnet Session    vrf ${vpn_name}
+    BgpOperations.Execute Command On Quagga Telnet Session    rd ${rd}
+    BgpOperations.Execute Command On Quagga Telnet Session    rt export ${rd}
+    BgpOperations.Execute Command On Quagga Telnet Session    rt import ${rd}
+    BgpOperations.Execute Command On Quagga Telnet Session    end
+
+Delete L3VPN on DCGW
+    [Arguments]    ${dcgw_ip}    ${as_id}    @{vpns}
+    [Documentation]    Deleting L3VPN on DCGW
+    BgpOperations.Create Quagga Telnet Session    ${dcgw_ip}    bgpd    sdncbgpc
+    BgpOperations.Execute Command On Quagga Telnet Session    configure terminal
+    BgpOperations.Execute Command On Quagga Telnet Session    router bgp ${as_id}
+    : FOR    ${vpn}    IN    @{vpns}
+    \    BgpOperations.Execute Command On Quagga Telnet Session    no vrf ${vpn}
+    BgpOperations.Execute Command On Quagga Telnet Session    end
+
+Verify L3VPN On DCGW
+    [Arguments]    ${dcgw_ip}    ${vpn_name}    ${rd}
+    [Documentation]    Verify L3VPN vrf name and rd value on DCGW
+    ${output} =    BgpOperations.Execute Show Command On Quagga    ${dcgw_ip}    show running-config
+    BuiltIn.Should Contain    ${output}    vrf ${vpn_name}
+    BuiltIn.Should Contain    ${output}    rd ${rd}
+
+Add Routes On DCGW
+    [Arguments]    ${dcgw_ip}    ${rd}    ${network_ip}    ${label}
+    [Documentation]    Add routes on DCGW
+    BgpOperations.Create Quagga Telnet Session    ${dcgw_ip}    bgpd    sdncbgpc
+    BgpOperations.Execute Command On Quagga Telnet Session    configure terminal
+    BgpOperations.Execute Command On Quagga Telnet Session    router bgp ${AS_ID}
+    BgpOperations.Execute Command On Quagga Telnet Session    address-family vpnv4 unicast
+    BgpOperations.Execute Command On Quagga Telnet Session    network ${network_ip}/32 rd ${rd} tag ${label}
+    BgpOperations.Execute Command On Quagga Telnet Session    end
+
 Create BGP Configuration On ODL
     [Arguments]    &{Kwargs}
     [Documentation]    Associate the created L3VPN to a network-id received as dictionary argument
@@ -243,3 +305,55 @@ Bmp_Monitor_Postcondition
     ${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}    ${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
+    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}
+    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}
+    [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
+    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}
+    ...    verify=True
+    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}
+    ...    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}
+    ...    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
+    BuiltIn.Should_Not_Be_Equal    ${update}    ${Empty}
+    [Return]    ${update}
+
+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}