73b267b21f6a9114a6a28d8e3860279c685ff187
[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 Variables         ${CURDIR}/../../../variables/Variables.py
14 Variables         ${CURDIR}/../../../variables/bgpuser/variables.py    ${TOOLS_SYSTEM_IP}    ${ODL_STREAM}
15 Resource          ${CURDIR}/../../../libraries/ExaBgpLib.robot
16 Resource          ${CURDIR}/../../../libraries/SSHKeywords.robot
17 Resource          ${CURDIR}/../../../libraries/SetupUtils.robot
18 Resource          ${CURDIR}/../../../libraries/TemplatedRequests.robot
19
20 *** Variables ***
21 ${HOLDTIME}       180
22 ${BGP_VARIABLES_FOLDER}    ${CURDIR}/../../../variables/bgpflowspec
23 ${CMD}            env exabgp.tcp.port=1790 exabgp --debug
24 ${EXP0}           empty-flowspec.json
25 ${CFG1}           bgp-flowspec.cfg
26 ${EXP1}           bgp-flowspec.json
27 ${CFG2}           bgp-flowspec-redirect.cfg
28 ${EXP2}           bgp-flowspec-redirect.json
29 ${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
30 ${CONFIG_SESSION}    session
31 ${DEVICE_NAME}    controller-config
32 ${BGP_PEER_NAME}    example-bgp-peer
33 ${RIB_INSTANCE}    example-bgp-rib
34 ${PROTOCOL_OPENCONFIG}    ${RIB_INSTANCE}
35
36 *** Test Cases ***
37 Check_For_Empty_Topology_Before_Talking
38     [Documentation]    Sanity check bgp-flowspec:flowspec-routes is up but empty.
39     [Tags]    critical
40     BuiltIn.Wait Until Keyword Succeeds    60s    3s    Verify Empty Flowspec Data
41
42 Reconfigure_ODL_To_Accept_Connection
43     [Documentation]    Configure BGP peer module with initiate-connection set to false.
44     &{mapping}    BuiltIn.Create_Dictionary    DEVICE_NAME=${DEVICE_NAME}    NAME=${BGP_PEER_NAME}    IP=${TOOLS_SYSTEM_IP}    HOLDTIME=${HOLDTIME}    PEER_PORT=${BGP_TOOL_PORT}
45     ...    INITIATE=false    RIB_INSTANCE_NAME=${RIB_INSTANCE}    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}    PASSIVE_MODE=true
46     TemplatedRequests.Put_As_Xml_Templated    ${BGP_VARIABLES_FOLDER}/bgp_peer    mapping=${mapping}    session=${CONFIG_SESSION}
47
48 FlowSpec Test 1
49     [Documentation]    Testing flowspec values for ${CFG1}
50     [Setup]    Setup Testcase    ${CFG1}
51     BuiltIn.Wait Until Keyword Succeeds    15s    1s    Verify Flowspec Data    ${EXP1}
52     [Teardown]    ExaBgpLib.Stop_ExaBgp
53
54 FlowSpec Test 2
55     [Documentation]    Testing flowspec values for ${CFG2}
56     [Setup]    Setup Testcase    ${CFG2}
57     BuiltIn.Wait Until Keyword Succeeds    15s    1s    Verify Flowspec Data    ${EXP2}
58     [Teardown]    ExaBgpLib.Stop_ExaBgp
59
60 Deconfigure_ODL_To_Accept_Connection
61     [Documentation]    Deconfigure BGP peer.
62     &{mapping}    BuiltIn.Create_Dictionary    DEVICE_NAME=${DEVICE_NAME}    NAME=${BGP_PEER_NAME}    IP=${TOOLS_SYSTEM_IP}    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
63     TemplatedRequests.Delete_Templated    ${BGP_VARIABLES_FOLDER}/bgp_peer    mapping=${mapping}    session=${CONFIG_SESSION}
64
65 *** Keywords ***
66 Start Suite
67     [Documentation]    Suite setup keyword
68     ${mininet_conn_id}=    SSHLibrary.Open Connection    ${TOOLS_SYSTEM_IP}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=6s
69     Builtin.Set Suite Variable    ${mininet_conn_id}
70     SSHKeywords.Flexible Mininet Login    ${TOOLS_SYSTEM_USER}
71     ${stdout}    ${stderr}    ${rc}=    SSHLibrary.Execute Command    ls    return_stdout=True    return_stderr=True
72     ...    return_rc=True
73     ${stdout}    ${stderr}    ${rc}=    SSHLibrary.Execute Command    sudo apt-get install -y python-pip    return_stdout=True    return_stderr=True
74     ...    return_rc=True
75     ${stdout}    ${stderr}    ${rc}=    SSHLibrary.Execute Command    sudo pip install exabgp    return_stdout=True    return_stderr=True
76     ...    return_rc=True
77     RequestsLibrary.Create Session    ${CONFIG_SESSION}    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
78     Upload Config Files    ${CURDIR}/../../../variables/bgpflowspec/
79
80 Stop Suite
81     [Documentation]    Suite teardown keyword
82     SSHLibrary.Close All Connections
83     RequestsLibrary.Delete All Sessions
84
85 Upload Config Files
86     [Arguments]    ${dir_name}
87     [Documentation]    Uploads exabgp config files
88     SSHLibrary.Put Directory    ${CURDIR}/../../../variables/bgpflowspec/    .
89     @{cfgfiles}=    SSHLibrary.List Files In Directory    .    *.cfg
90     : FOR    ${cfgfile}    IN    @{cfgfiles}
91     \    SSHLibrary.Execute Command    sed -i -e 's/EXABGPIP/${TOOLS_SYSTEM_IP}/g' ${cfgfile}
92     \    SSHLibrary.Execute Command    sed -i -e 's/ODLIP/${ODL_SYSTEM_IP}/g' ${cfgfile}
93     \    ${stdout}=    SSHLibrary.Execute Command    cat ${cfgfile}
94     \    Log    ${stdout}
95
96 Setup Testcase
97     [Arguments]    ${cfg_file}
98     Verify Empty Flowspec Data
99     ExaBgpLib.Start_ExaBgp_And_Verify_Connected    ${cfg_file}    ${CONFIG_SESSION}    ${TOOLS_SYSTEM_IP}    connection_retries=${3}
100
101 Verify Empty Flowspec Data
102     [Documentation]    Verify expected response.
103     Verify Flowspec Data    ${EXP0}
104
105 Verify Flowspec Data
106     [Arguments]    ${exprspfile}
107     [Documentation]    Verify expected response
108     ${keys_with_bits}=    BuiltIn.Create_List
109     ${expected_rsp}=    Get Expected Response From File    ${exprspfile}
110     ${rsp}=    RequestsLibrary.Get Request    ${CONFIG_SESSION}    ${FLOWSPEC_URL}
111     TemplatedRequests.Normalize_Jsons_With_Bits_And_Compare    ${expected_rsp}    ${rsp.content}    keys_with_bits=${keys_with_bits}
112
113 Get Expected Response From File
114     [Arguments]    ${exprspfile}
115     [Documentation]    Looks for release specific response first, then take default.
116     ${status}    ${expresponse}=    BuiltIn.Run_Keyword_And_Ignore_Error    OperatingSystem.Get File    ${CURDIR}/../../../variables/bgpflowspec/${exprspfile}.${ODL_STREAM}
117     Return From Keyword If    '${status}' == 'PASS'    ${expresponse}
118     ${expresponse}=    OperatingSystem.Get File    ${CURDIR}/../../../variables/bgpflowspec/${exprspfile}
119     [Return]    ${expresponse}