Fix BGPCEP userfeatures
[integration/test.git] / csit / suites / bgpcep / bgpfunct / 090_bgp_functional_rt_constrain_validation.robot
1 *** Settings ***
2 Documentation     Functional test for bgp - route-target-constrain safi
3 ...
4 ...               Copyright (c) 2018 AT&T Intellectual Property. 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 distbmution,
8 ...               and is available at http://www.eclipse.org/legal/epl-v10.html
9 ...
10 ...               This suite tests advertising rt-constrain routes to odl. For advertising from peer,
11 ...               play.py is used, sending hex messages to odl.
12 ...               There are 3 peers: ebgp and two ibgps. First peer sends l3vpn route with specific RT to odl, second peer
13 ...               sends RT route and third peer only establishes connection. Then it is checked that odl advertizes l3vpn route
14 ...               to second peer. Third peer sends wildcard RT route and it is checked that odl doesn't advertize l3vpn route
15 ...               to it. Then second peer removes RT and it is checked that second peer withdrew RT route and that odl withdrew
16 ...               l3vpn route from it.
17 Suite Setup       Start_Suite
18 Suite Teardown    Stop_Suite
19 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
20 Library           RequestsLibrary
21 Library           SSHLibrary
22 Library           String
23 Library           ../../../libraries/BgpRpcClient.py    ${ODL_SYSTEM_IP}    8002    WITH NAME    BgpRpcClient2
24 Library           ../../../libraries/BgpRpcClient.py    ${ODL_SYSTEM_IP}    8003    WITH NAME    BgpRpcClient3
25 Library           ../../../libraries/BgpRpcClient.py    ${ODL_SYSTEM_IP}    8004    WITH NAME    BgpRpcClient4
26 Resource          ../../../libraries/BGPcliKeywords.robot
27 Resource          ../../../libraries/BgpOperations.robot
28 Resource          ../../../libraries/BGPSpeaker.robot
29 Resource          ../../../libraries/SetupUtils.robot
30 Resource          ../../../libraries/SSHKeywords.robot
31 Resource          ../../../libraries/TemplatedRequests.robot
32 Resource          ../../../libraries/TemplatedRequests.robot
33 Resource          ../../../variables/Variables.robot
34
35 *** Variables ***
36 ${HOLDTIME}       180
37 ${CONFIG_SESSION}    config-session
38 ${RT_CONSTRAIN_DIR}    ${CURDIR}/../../../variables/bgpfunctional/rt_constrain
39 ${EBGP_DIR}       ${CURDIR}/../../../variables/bgpfunctional/ebgp_peer
40 ${PLAY_SCRIPT}    ${CURDIR}/../../../../tools/fastbgp/play.py
41 ${RIB_NAME}       example-bgp-rib
42 ${ODL_2_IP}       127.0.0.2
43 ${ODL_3_IP}       127.0.0.3
44 ${ODL_4_IP}       127.0.0.4
45 ${OLD_AS_PATH}    \n"as-path": {},
46 ${NEW_AS_PATH}    ${EMPTY}
47 @{BGP_PEER_TYPES}    external    internal    internal
48 @{BGP_PEER_AS_NUMBERS}    65000    64496    64496
49 @{ODL_IP_INDICES_ALL}    2    3    4
50 @{L3VPN_RT_CHECK}    false    true    false
51 &{RT_CONSTRAIN_APP_PEER}    IP=${ODL_SYSTEM_IP}    BGP_RIB=${RIB_NAME}
52 &{ADJ_RIB_OUT}    PATH=peer/bgp:%2F%2F${ODL_3_IP}/adj-rib-out    BGP_RIB=${RIB_NAME}
53
54 *** Test Cases ***
55 Reconfigure_ODL_To_Accept_Connection
56     [Documentation]    Configures BGP peer module with initiate-connection set to false.
57     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
58     : FOR    ${i}    ${type}    IN ZIP    ${ODL_IP_INDICES_ALL}    ${BGP_PEER_TYPES}
59     \    &{ODL_CONFIG}=    BuiltIn.Create_Dictionary    IP=${ODL_${i}_IP}    TYPE=${type}    HOLDTIME=${HOLDTIME}    PEER_PORT=${BGP_TOOL_PORT}
60     \    ...    INITIATE=false    BGP_RIB=${RIB_NAME}    PASSIVE_MODE=true
61     \    TemplatedRequests.Put_As_Xml_Templated    ${EBGP_DIR}    mapping=${ODL_CONFIG}    session=${CONFIG_SESSION}
62
63 Start_Bgp_Peers
64     [Documentation]    Start Python speaker to connect to ODL. We give each speaker time until odl really starts to accept incoming
65     ...    bgp connection. The failure happens if the incoming connection comes too quickly after configuring the peer.
66     [Tags]    local_run
67     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
68     : FOR    ${i}    ${as_number}    IN ZIP    ${ODL_IP_INDICES_ALL}    ${BGP_PEER_AS_NUMBERS}
69     \    BuiltIn.Log_Many    IP: ${ODL_${i}_IP}    as_number: ${as_number}
70     \    Start_Bgp_Peer    ${ODL_${i}_IP}    ${as_number}    800${i}    play.py.090.${i}
71
72 Play_To_Odl_ext_l3vpn_rt_arg
73     [Documentation]    This TC sends route-target route containing route-target argument from node 1 to odl
74     ...    so odl can identify this peer as appropriate for advertizement when it recieves such route.
75     Play_To_Odl_Non_Removal_BgpRpcClient2    ext_l3vpn_rt_arg    ${RT_CONSTRAIN_DIR}
76     &{effective_rib_in}    BuiltIn.Create_Dictionary    PATH=peer/bgp:%2F%2F${ODL_2_IP}/effective-rib-in    BGP_RIB=${RIB_NAME}    AS_PATH=${AS_PATH}
77     BuiltIn.Wait_Until_Keyword_Succeeds    3x    2s    TemplatedRequests.Get_As_Json_Templated    ${RT_CONSTRAIN_DIR}/ext_l3vpn_rt_arg/rib    mapping=${effective_rib_in}    session=${CONFIG_SESSION}
78     ...    verify=True
79
80 Play_To_Odl_rt_constrain_type_0
81     [Documentation]    Sends RT route from node 2 to odl and then checks that odl advertizes l3vpn route from previous TC.
82     Play_To_Odl_Non_Removal_BgpRpcClient3    rt_constrain_type_0    ${RT_CONSTRAIN_DIR}
83     &{loc_rib}    BuiltIn.Create_Dictionary    PATH=loc-rib    BGP_RIB=${RIB_NAME}    AS_PATH=${AS_PATH}
84     BuiltIn.Wait_Until_Keyword_Succeeds    3x    2s    TemplatedRequests.Get_As_Json_Templated    ${RT_CONSTRAIN_DIR}/rt_constrain_type_0/rib    mapping=${loc_rib}    session=${CONFIG_SESSION}
85     ...    verify=True
86
87 Check_Presence_Of_l3vpn_Route_In_Node_2_Effective_Rib_In_Table
88     [Documentation]    Checks l3vpn route is present in node 2 effective-rib-in table.
89     BuiltIn.Wait_Until_Keyword_Succeeds    3x    2s    TemplatedRequests.Get_As_Json_Templated    ${RT_CONSTRAIN_DIR}/ext_l3vpn_rt_arg/rib    mapping=${ADJ_RIB_OUT}    session=${CONFIG_SESSION}
90     ...    verify=True
91
92 Check_l3vpn_Route_Advertisement_On_Each_Node
93     [Documentation]    Checks that each node received or did not receive update message containing given hex message.
94     ${announce} =    OperatingSystem.Get_File    ${RT_CONSTRAIN_DIR}/ext_l3vpn_rt_arg/announce_ext_l3vpn_rt_arg.hex
95     ${announce_hex} =    String.Remove_String    ${announce}    \n
96     Check_For_L3VPN_Odl_Avertisement    ${announce_hex}
97
98 Play_To_Odl_rt_constrain_type_1
99     [Documentation]    Sends RT route from node 3 to odl and then checks that odl does not advertize l3vpn route from previous TC,
100     ...    that is that update message is empty.
101     Play_To_Odl_Non_Removal_BgpRpcClient4    rt_constrain_type_1    ${RT_CONSTRAIN_DIR}
102     &{effective_rib_in} =    BuiltIn.Create_Dictionary    PATH=peer/bgp:%2F%2F${ODL_4_IP}/effective-rib-in    BGP_RIB=${RIB_NAME}    AS_PATH=${AS_PATH}
103     BuiltIn.Wait_Until_Keyword_Succeeds    3x    2s    TemplatedRequests.Get_As_Json_Templated    ${RT_CONSTRAIN_DIR}/rt_constrain_type_1/rib    mapping=${effective_rib_in}    session=${CONFIG_SESSION}
104     ...    verify=True
105     ${update} =    BgpRpcClient4.play_get
106     Comment    From neon onwards there is extra BGP End-Of-RIB message
107     CompareStream.Run_Keyword_If_At_Most_Fluorine    BuiltIn.Should_Be_Equal    ${update}    ${Empty}
108
109 Play_To_Odl_remove_rt
110     [Documentation]    Removes RT from odl and then checks that second node withdrew l3vpn route and third node did not receive any message.
111     BgpRpcClient3.play_clean
112     Play_To_Odl_Routes_Removal_Template_BgpRpcClient3    rt_constrain_type_0    ${RT_CONSTRAIN_DIR}
113     Comment    From neon onwards there is extra BGP End-Of-RIB message
114     CompareStream.Run_Keyword_If_At_Most_Fluorine    BuiltIn.Wait_Until_Keyword_Succeeds    3x    2s    Verify_Empty_Reported_Data
115     ${update} =    BgpRpcClient4.play_get
116     Comment    From neon onwards there is extra BGP End-Of-RIB message
117     CompareStream.Run_Keyword_If_At_Most_Fluorine    BuiltIn.Should_Be_Equal    ${update}    ${Empty}
118
119 Play_To_Odl_remove_routes
120     [Documentation]    Removes rt arguments from odl.
121     Play_To_Odl_Routes_Removal_Template_BgpRpcClient2    ext_l3vpn_rt_arg    ${RT_CONSTRAIN_DIR}
122     Play_To_Odl_Routes_Removal_Template_BgpRpcClient4    rt_constrain_type_1    ${RT_CONSTRAIN_DIR}
123
124 Kill_Talking_BGP_Speakers
125     [Documentation]    Abort all Python speakers.
126     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
127     BGPcliKeywords.Store_File_To_Workspace    play.py.090.2    090_rt_constrain_play_1.log
128     BGPcliKeywords.Store_File_To_Workspace    play.py.090.3    090_rt_constrain_play_2.log
129     BGPcliKeywords.Store_File_To_Workspace    play.py.090.4    090_rt_constrain_play_3.log
130     BGPSpeaker.Kill_All_BGP_Speakers
131
132 Delete_Bgp_Peers_Configuration
133     [Documentation]    Revert the BGP configuration to the original state: without any configured peers.
134     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
135     : FOR    ${i}    ${type}    IN ZIP    ${ODL_IP_INDICES_ALL}    ${BGP_PEER_TYPES}
136     \    &{ODL_CONFIG} =    BuiltIn.Create_Dictionary    IP=${ODL_${i}_IP}    TYPE=${type}    HOLDTIME=${HOLDTIME}    PEER_PORT=${BGP_TOOL_PORT}
137     \    ...    INITIATE=false    BGP_RIB=${RIB_NAME}    PASSIVE_MODE=true
138     \    TemplatedRequests.Delete_Templated    ${EBGP_DIR}    mapping=${ODL_CONFIG}    session=${CONFIG_SESSION}
139
140 *** Keywords ***
141 Start_Suite
142     [Documentation]    Initialize SetupUtils. Suite setup keyword.
143     SetupUtils.Setup_Utils_For_Setup_And_Teardown
144     ${conn_id} =    SSHLibrary.Open Connection    ${ODL_SYSTEM_IP}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=6s
145     Builtin.Set_Suite_Variable    ${conn_id}
146     SSHKeywords.Flexible_Controller_Login
147     RequestsLibrary.Create_Session    ${CONFIG_SESSION}    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
148     SSHLibrary.Put_File    ${PLAY_SCRIPT}    .
149     SSHKeywords.Assure_Library_Ipaddr    target_dir=.
150     ${AS_PATH} =    CompareStream.Set_Variable_If_At_Least_Neon    ${NEW_AS_PATH}    ${OLD_AS_PATH}
151     BuiltIn.Set_Suite_Variable    ${AS_PATH}
152
153 Stop_Suite
154     [Documentation]    Suite teardown keyword
155     SSHLibrary.Close_All_Connections
156     RequestsLibrary.Delete_All_Sessions
157
158 Start_Bgp_Peer
159     [Arguments]    ${ip}    ${as_number}    ${port}    ${filename}
160     [Documentation]    Starts bgp peer.
161     ${command} =    BuiltIn.Set_Variable    python play.py --amount 0 --myip=${ip} --myport=${BGP_TOOL_PORT} --peerip=${ODL_SYSTEM_IP} --asnumber=${as_number} --peerport=${ODL_BGP_PORT} --port=${port} --usepeerip --debug --allf --wfr 1 &> ${filename} &
162     BuiltIn.Log    ${command}
163     ${output} =    SSHLibrary.Write    ${command}
164
165 Play_To_Odl_Non_Removal_BgpRpcClient2
166     [Arguments]    ${totest}    ${dir}    ${ipv}=ipv4
167     [Documentation]    Read contents of file ${dir}/${totest}/announce_${totest}.hex and send it to odl.
168     ${announce_hex} =    OperatingSystem.Get_File    ${dir}/${totest}/announce_${totest}.hex
169     BgpRpcClient2.play_send    ${announce_hex}
170
171 Play_To_Odl_Non_Removal_BgpRpcClient3
172     [Arguments]    ${totest}    ${dir}    ${ipv}=ipv4
173     [Documentation]    Read contents of file ${dir}/${totest}/announce_${totest}.hex and send it to odl.
174     ${announce_hex} =    OperatingSystem.Get_File    ${dir}/${totest}/announce_${totest}.hex
175     BgpRpcClient3.play_send    ${announce_hex}
176
177 Play_To_Odl_Non_Removal_BgpRpcClient4
178     [Arguments]    ${totest}    ${dir}    ${ipv}=ipv4
179     [Documentation]    Read contents of file ${dir}/${totest}/announce_${totest}.hex and send it to odl.
180     ${announce_hex} =    OperatingSystem.Get_File    ${dir}/${totest}/announce_${totest}.hex
181     BgpRpcClient4.play_send    ${announce_hex}
182
183 Play_To_Odl_Routes_Removal_Template_BgpRpcClient2
184     [Arguments]    ${totest}    ${dir}    ${ipv}=ipv4
185     [Documentation]    Read contents of file ${dir}/${totest}/withdraw_${totest}.hex and send it to odl to remove rt argument from odl.
186     ${withdraw_hex} =    OperatingSystem.Get_File    ${dir}/${totest}/withdraw_${totest}.hex
187     BgpRpcClient2.play_clean
188     BgpRpcClient2.play_send    ${withdraw_hex}
189
190 Play_To_Odl_Routes_Removal_Template_BgpRpcClient3
191     [Arguments]    ${totest}    ${dir}    ${ipv}=ipv4
192     [Documentation]    Read contents of file ${dir}/${totest}/withdraw_${totest}.hex and send it to odl to remove rt argument from odl.
193     ${withdraw_hex} =    OperatingSystem.Get_File    ${dir}/${totest}/withdraw_${totest}.hex
194     BgpRpcClient3.play_clean
195     BgpRpcClient3.play_send    ${withdraw_hex}
196
197 Play_To_Odl_Routes_Removal_Template_BgpRpcClient4
198     [Arguments]    ${totest}    ${dir}    ${ipv}=ipv4
199     [Documentation]    Read contents of file ${dir}/${totest}/withdraw_${totest}.hex and send it to odl to remove rt argument from odl.
200     ${withdraw_hex} =    OperatingSystem.Get_File    ${dir}/${totest}/withdraw_${totest}.hex
201     BgpRpcClient4.play_clean
202     BgpRpcClient4.play_send    ${withdraw_hex}
203
204 Get_Update_Message_And_Compare_With_Hex_BgpRpcClient2
205     [Arguments]    ${hex}    ${option}
206     [Documentation]    Returns hex update message and compares it to hex.
207     ${update} =    BgpRpcClient2.play_get
208     BuiltIn.Run_Keyword_If    "${option}" == "true"    BuiltIn.Should_Be_Equal_As_Strings    ${update}    ${hex}
209     BuiltIn.Run_Keyword_If    "${option}" == "false"    BuiltIn.Should_Not_Be_Equal_As_Strings    ${update}    ${hex}
210
211 Get_Update_Message_And_Compare_With_Hex_BgpRpcClient3
212     [Arguments]    ${hex}    ${option}
213     [Documentation]    Returns hex update message and compares it to hex.
214     ${update} =    BgpRpcClient3.play_get
215     BuiltIn.Run_Keyword_If    "${option}" == "true"    BuiltIn.Should_Be_Equal_As_Strings    ${update}    ${hex}
216     BuiltIn.Run_Keyword_If    "${option}" == "false"    BuiltIn.Should_Not_Be_Equal_As_Strings    ${update}    ${hex}
217
218 Get_Update_Message_And_Compare_With_Hex_BgpRpcClient4
219     [Arguments]    ${hex}    ${option}
220     [Documentation]    Returns hex update message and compares it to hex.
221     ${update} =    BgpRpcClient4.play_get
222     BuiltIn.Run_Keyword_If    "${option}" == "true"    BuiltIn.Should_Be_Equal_As_Strings    ${update}    ${hex}
223     BuiltIn.Run_Keyword_If    "${option}" == "false"    BuiltIn.Should_Not_Be_Equal_As_Strings    ${update}    ${hex}
224
225 Check_For_L3VPN_Odl_Avertisement
226     [Arguments]    ${announce_hex}
227     [Documentation]    Checks that each node received or did not receive update message containing given hex message.
228     : FOR    ${i}    ${option}    IN ZIP    ${ODL_IP_INDICES_ALL}    ${L3VPN_RT_CHECK}
229     \    ${keyword_name}=    BuiltIn.Set_Variable    Get_Update_Message_And_Compare_With_Hex_BgpRpcClient${i}
230     \    BuiltIn.Run_Keyword    ${keyword_name}    ${announce_hex}    ${option}
231
232 Verify_Reported_Data
233     [Arguments]    ${url}    ${exprspfile}
234     [Documentation]    Verifies expected response
235     ${expresponse} =    OperatingSystem.Get File    ${exprspfile}
236     BuiltIn.Log    expected_response: ${expresponse}
237     ${rsp} =    RequestsLibrary.Get_Request    ${CONFIG_SESSION}    ${url}
238     BuiltIn.Log    actual_response: ${rsp}
239     BuiltIn.Log    actual_response_content: ${rsp.content}
240     TemplatedRequests.Normalize_Jsons_And_Compare    ${expresponse}    ${rsp.content}
241
242 Verify_Empty_Reported_Data
243     [Documentation]    Verify empty data response
244     TemplatedRequests.Get_As_Json_Templated    ${RT_CONSTRAIN_DIR}${/}empty_l3vpn    session=${CONFIG_SESSION}    mapping=${ADJ_RIB_OUT}    verify=True
245
246 Verify_Empty_Data_Neon
247     [Documentation]    Verify empty data on neon
248     TemplatedRequests.Get_As_Json_Templated    ${RT_CONSTRAIN_DIR}${/}empty_route    session=${CONFIG_SESSION}    mapping=${ADJ_RIB_OUT}    verify=True