adba040d3bbe349f39dc0ac4df0d1caadeca1f38
[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_EMPTY}      {"bgp-flowspec:flowspec-routes": {}}
24 ${NEW_EMPTY}      {}
25 ${OLD_AS_PATH}    \n"as-path": {},
26 ${NEW_AS_PATH}    ${EMPTY}
27 ${CFG1}           bgp-flowspec.cfg
28 ${EXP1}           bgp-flowspec.json
29 ${CFG2}           bgp-flowspec-redirect.cfg
30 ${EXP2}           bgp-flowspec-redirect.json
31 ${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
32 ${CONFIG_SESSION}    session
33 ${DEVICE_NAME}    controller-config
34 ${BGP_PEER_NAME}    example-bgp-peer
35 ${RIB_INSTANCE}    example-bgp-rib
36 ${PROTOCOL_OPENCONFIG}    ${RIB_INSTANCE}
37 @{EMPTY_LIST}
38
39 *** Test Cases ***
40 Check_For_Empty_Topology_Before_Talking
41     [Documentation]    Sanity check bgp-flowspec:flowspec-routes is up but empty.
42     [Tags]    critical
43     BuiltIn.Wait_Until_Keyword_Succeeds    60s    3s    Verify_Empty_Flowspec_Data
44
45 Reconfigure_ODL_To_Accept_Connection
46     [Documentation]    Configure BGP peer module with initiate-connection set to false.
47     &{mapping}    BuiltIn.Create_Dictionary    DEVICE_NAME=${DEVICE_NAME}    NAME=${BGP_PEER_NAME}    IP=${TOOLS_SYSTEM_IP}    HOLDTIME=${HOLDTIME}    PEER_PORT=${BGP_TOOL_PORT}
48     ...    INITIATE=false    RIB_INSTANCE_NAME=${RIB_INSTANCE}    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}    PASSIVE_MODE=true
49     TemplatedRequests.Put_As_Xml_Templated    ${BGP_VARIABLES_FOLDER}/bgp_peer    mapping=${mapping}    session=${CONFIG_SESSION}
50
51 FlowSpec_Test_1
52     [Documentation]    Testing flowspec values for ${CFG1}
53     [Setup]    Setup_Testcase    ${CFG1}
54     BuiltIn.Wait_Until_Keyword_Succeeds    15s    1s    Verify_Flowspec_Data    ${EXP1}
55     [Teardown]    ExaBgpLib.Stop_ExaBgp
56
57 FlowSpec_Test_2
58     [Documentation]    Testing flowspec values for ${CFG2}
59     [Setup]    Setup_Testcase    ${CFG2}
60     BuiltIn.Wait_Until_Keyword_Succeeds    15s    1s    Verify_Flowspec_Data    ${EXP2}
61     [Teardown]    ExaBgpLib.Stop_ExaBgp
62
63 Deconfigure_ODL_To_Accept_Connection
64     [Documentation]    Deconfigure BGP peer.
65     &{mapping}    BuiltIn.Create_Dictionary    DEVICE_NAME=${DEVICE_NAME}    NAME=${BGP_PEER_NAME}    IP=${TOOLS_SYSTEM_IP}    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
66     TemplatedRequests.Delete_Templated    ${BGP_VARIABLES_FOLDER}/bgp_peer    mapping=${mapping}    session=${CONFIG_SESSION}
67
68 *** Keywords ***
69 Start_Suite
70     [Documentation]    Suite setup keyword
71     SSHLibrary.Open_Connection    ${TOOLS_SYSTEM_IP}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=6s
72     SSHKeywords.Flexible_Mininet_Login    ${TOOLS_SYSTEM_USER}
73     SSHKeywords.Virtual_Env_Create
74     SSHKeywords.Virtual_Env_Install_Package    exabgp==3.4.16
75     RequestsLibrary.Create_Session    ${CONFIG_SESSION}    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
76     Upload_Config_Files    ${BGP_VARIABLES_FOLDER}
77     ${EXP0} =    CompareStream.Set_Variable_If_At_Least_Neon    ${NEW_EMPTY}    ${OLD_EMPTY}
78     BuiltIn.Set_Suite_Variable    ${EXP0}
79     ${AS_PATH} =    CompareStream.Set_Variable_If_At_Least_Neon    ${NEW_AS_PATH}    ${OLD_AS_PATH}
80     BuiltIn.Set_Suite_Variable    ${AS_PATH}
81
82 Stop_Suite
83     [Documentation]    Suite teardown keyword
84     SSHLibrary.Close_All_Connections
85     RequestsLibrary.Delete_All_Sessions
86
87 Upload_Config_Files
88     [Arguments]    ${dir_name}
89     [Documentation]    Uploads exabgp config files
90     SSHLibrary.Put_Directory    ${BGP_VARIABLES_FOLDER}    .
91     @{cfgfiles} =    SSHLibrary.List_Files_In_Directory    .    *.cfg
92     : FOR    ${cfgfile}    IN    @{cfgfiles}
93     \    SSHLibrary.Execute_Command    sed -i -e 's/EXABGPIP/${TOOLS_SYSTEM_IP}/g' ${cfgfile}
94     \    SSHLibrary.Execute_Command    sed -i -e 's/ODLIP/${ODL_SYSTEM_IP}/g' ${cfgfile}
95     \    ${stdout}=    SSHLibrary.Execute_Command    cat ${cfgfile}
96     \    Log    ${stdout}
97
98 Setup_Testcase
99     [Arguments]    ${cfg_file}
100     Verify_Empty_Flowspec_Data
101     ExaBgpLib.Start_ExaBgp_And_Verify_Connected    ${cfg_file}    ${CONFIG_SESSION}    ${TOOLS_SYSTEM_IP}    connection_retries=${3}
102
103 Verify_Empty_Flowspec_Data
104     [Documentation]    Verify expected response.
105     ${rsp} =    RequestsLibrary.Get_Request    ${CONFIG_SESSION}    ${FLOWSPEC_URL}
106     TemplatedRequests.Normalize_Jsons_With_Bits_And_Compare    ${EXP0}    ${rsp.content}    keys_with_bits=${EMPTY_LIST}
107
108 Verify_Flowspec_Data
109     [Arguments]    ${exprspfile}
110     [Documentation]    Verify expected response
111     &{mapping}    BuiltIn.Create_Dictionary    AS_PATH=${AS_PATH}
112     ${expected_rsp} =    TemplatedRequests.Resolve_Text_From_Template_File    ${BGP_VARIABLES_FOLDER}    ${exprspfile}    mapping=${mapping}
113     ${rsp} =    RequestsLibrary.Get_Request    ${CONFIG_SESSION}    ${FLOWSPEC_URL}
114     TemplatedRequests.Normalize_Jsons_With_Bits_And_Compare    ${expected_rsp}    ${rsp.content}    keys_with_bits=${EMPTY_LIST}