Upgrade RF syntax for v3.2 compatibility
[integration/test.git] / csit / suites / bgpcep / bgpflowspec / 010_bgp_flowspec.robot
1 *** Settings ***
2 Documentation     Functional test for bgp flowspec.
3 ...
4 ...               Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
5 ...
6 ...               This program and the accompanying materials are made available under the
7 ...               terms of the Eclipse Public License v1.0 which accompanies this distribution,
8 ...               and is available at http://www.eclipse.org/legal/epl-v10.html
9 Suite Setup       Start_Suite
10 Suite Teardown    Stop_Suite
11 Library           RequestsLibrary
12 Library           SSHLibrary
13 Resource          ../../../libraries/CompareStream.robot
14 Resource          ../../../libraries/ExaBgpLib.robot
15 Resource          ../../../libraries/SSHKeywords.robot
16 Resource          ../../../libraries/TemplatedRequests.robot
17 Resource          ../../../variables/Variables.robot
18
19 *** Variables ***
20 ${BGP_VARIABLES_FOLDER}    ${CURDIR}/../../../variables/bgpflowspec/
21 ${CMD}            env exabgp.tcp.port=1790 exabgp --debug
22 ${HOLDTIME}       180
23 ${OLD_AS_PATH}    \n"as-path": {},
24 ${NEW_AS_PATH}    ${EMPTY}
25 ${EXP0}           {"bgp-flowspec:flowspec-routes": {}}
26 ${CFG1}           bgp-flowspec.cfg
27 ${EXP1}           bgp_flowspec
28 ${CFG2}           bgp-flowspec-redirect.cfg
29 ${EXP2}           bgp_flowspec_redirect
30 ${FLOWSPEC_URL}    /restconf/operational/bgp-rib:bgp-rib/rib/example-bgp-rib/loc-rib/tables/bgp-types:ipv4-address-family/bgp-flowspec:flowspec-subsequent-address-family/bgp-flowspec:flowspec-routes
31 ${CONFIG_SESSION}    session
32 ${DEVICE_NAME}    controller-config
33 ${RIB_INSTANCE}    example-bgp-rib
34 ${PROTOCOL_OPENCONFIG}    ${RIB_INSTANCE}
35 @{EMPTY_LIST}
36
37 *** Test Cases ***
38 Check_For_Empty_Topology_Before_Talking
39     [Documentation]    Sanity check bgp-flowspec:flowspec-routes is up but empty.
40     [Tags]    critical
41     BuiltIn.Wait_Until_Keyword_Succeeds    60s    3s    Verify_Empty_Flowspec_Data
42
43 Reconfigure_ODL_To_Accept_Connection
44     [Documentation]    Configure BGP peer module with initiate-connection set to false.
45     &{mapping}    BuiltIn.Create_Dictionary    IP=${TOOLS_SYSTEM_IP}    HOLDTIME=${HOLDTIME}    PEER_PORT=${BGP_TOOL_PORT}    INITIATE=false    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
46     ...    PASSIVE_MODE=true
47     TemplatedRequests.Put_As_Xml_Templated    ${BGP_VARIABLES_FOLDER}/bgp_peer    mapping=${mapping}    session=${CONFIG_SESSION}
48
49 FlowSpec_Test_1
50     [Documentation]    Testing flowspec values for ${CFG1}
51     [Setup]    Setup_Testcase    ${CFG1}
52     BuiltIn.Wait_Until_Keyword_Succeeds    15s    1s    Verify_Flowspec_Data    ${EXP1}
53     [Teardown]    ExaBgpLib.Stop_ExaBgp
54
55 FlowSpec_Test_2
56     [Documentation]    Testing flowspec values for ${CFG2}
57     [Setup]    Setup_Testcase    ${CFG2}
58     BuiltIn.Wait_Until_Keyword_Succeeds    15s    1s    Verify_Flowspec_Data    ${EXP2}
59     [Teardown]    ExaBgpLib.Stop_ExaBgp
60
61 Deconfigure_ODL_To_Accept_Connection
62     [Documentation]    Deconfigure BGP peer.
63     &{mapping}    BuiltIn.Create_Dictionary    IP=${TOOLS_SYSTEM_IP}    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
64     TemplatedRequests.Delete_Templated    ${BGP_VARIABLES_FOLDER}/bgp_peer    mapping=${mapping}    session=${CONFIG_SESSION}
65
66 *** Keywords ***
67 Start_Suite
68     [Documentation]    Suite setup keyword
69     SSHLibrary.Open_Connection    ${TOOLS_SYSTEM_IP}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=6s
70     SSHKeywords.Flexible_Mininet_Login    ${TOOLS_SYSTEM_USER}
71     SSHKeywords.Virtual_Env_Create
72     SSHKeywords.Virtual_Env_Install_Package    exabgp==3.4.16
73     RequestsLibrary.Create_Session    ${CONFIG_SESSION}    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
74     Upload_Config_Files    ${BGP_VARIABLES_FOLDER}
75     ${AS_PATH} =    CompareStream.Set_Variable_If_At_Least_Neon    ${NEW_AS_PATH}    ${OLD_AS_PATH}
76     BuiltIn.Set_Suite_Variable    ${AS_PATH}
77
78 Stop_Suite
79     [Documentation]    Suite teardown keyword
80     SSHLibrary.Close_All_Connections
81     RequestsLibrary.Delete_All_Sessions
82
83 Upload_Config_Files
84     [Arguments]    ${dir_name}
85     [Documentation]    Uploads exabgp config files
86     SSHLibrary.Put_Directory    ${BGP_VARIABLES_FOLDER}    .
87     @{cfgfiles} =    SSHLibrary.List_Files_In_Directory    .    *.cfg
88     FOR    ${cfgfile}    IN    @{cfgfiles}
89         SSHLibrary.Execute_Command    sed -i -e 's/EXABGPIP/${TOOLS_SYSTEM_IP}/g' ${cfgfile}
90         SSHLibrary.Execute_Command    sed -i -e 's/ODLIP/${ODL_SYSTEM_IP}/g' ${cfgfile}
91         ${stdout}=    SSHLibrary.Execute_Command    cat ${cfgfile}
92         Log    ${stdout}
93     END
94
95 Setup_Testcase
96     [Arguments]    ${cfg_file}
97     Verify_Empty_Flowspec_Data
98     ExaBgpLib.Start_ExaBgp_And_Verify_Connected    ${cfg_file}    ${CONFIG_SESSION}    ${TOOLS_SYSTEM_IP}    connection_retries=${3}
99
100 Verify_Empty_Flowspec_Data
101     [Documentation]    Verify expected response.
102     CompareStream.Run_Keyword_If_At_Most_Fluorine    Normalize_And_Compare
103     CompareStream.Run_Keyword_If_At_Least_Neon    Verify_Empty_Flowspec_Data_Neon
104
105 Verify_Flowspec_Data
106     [Arguments]    ${exprspdir}
107     [Documentation]    Verify expected response
108     &{mapping}    BuiltIn.Create_Dictionary    AS_PATH=${AS_PATH}
109     TemplatedRequests.Get_As_Json_Templated    ${BGP_VARIABLES_FOLDER}${/}${exprspdir}    session=${CONFIG_SESSION}    mapping=${mapping}    verify=True
110
111 Normalize_And_Compare
112     [Documentation]    Verify empty flowspec data
113     ${rsp} =    RequestsLibrary.Get_Request    ${CONFIG_SESSION}    ${FLOWSPEC_URL}
114     TemplatedRequests.Normalize_Jsons_With_Bits_And_Compare    ${EXP0}    ${rsp.content}    keys_with_bits=${EMPTY_LIST}
115
116 Verify_Empty_Flowspec_Data_Neon
117     [Documentation]    Verify empty flowspec data on neon
118     TemplatedRequests.Get_As_Json_Templated    ${BGP_VARIABLES_FOLDER}${/}empty_route    session=${CONFIG_SESSION}    verify=True