SXP Domain Filtering
[integration/test.git] / csit / libraries / SxpLib.robot
1 *** Settings ***
2 Documentation     Library containing Keywords used for SXP testing
3 Library           Collections
4 Library           RequestsLibrary
5 Library           SSHLibrary
6 Library           String
7 Library           ./Sxp.py
8 Resource          KarafKeywords.robot
9 Resource          Utils.robot
10 Variables         ../variables/Variables.py
11
12 *** Variables ***
13 ${REST_CONTEXT}    /restconf/operations/sxp-controller
14
15 *** Keywords ***
16 Add Node
17     [Arguments]    ${node}    ${password}=password    ${version}=version4    ${port}=64999    ${session}=session
18     [Documentation]    Add node via RPC to ODL
19     ${DATA}    Add Node Xml    ${node}    ${port}    ${password}    ${version}
20     ${resp}    Post Request    ${session}    ${REST_CONTEXT}:add-node    data=${DATA}    headers=${HEADERS_XML}
21     Should be Equal As Strings    ${resp.status_code}    200
22
23 Delete Node
24     [Arguments]    ${node}    ${session}=session
25     [Documentation]    Delete connection via RPC from node
26     ${DATA}    Delete Node Xml    ${node}
27     ${resp}    Post Request    ${session}    ${REST_CONTEXT}:delete-node    data=${DATA}    headers=${HEADERS_XML}
28     Should be Equal As Strings    ${resp.status_code}    200
29
30 Add Connection
31     [Arguments]    ${version}    ${mode}    ${ip}    ${port}    ${node}=127.0.0.1    ${password}=none
32     ...    ${session}=session    ${domain}=global
33     [Documentation]    Add connection via RPC to node
34     ${DATA}    Add Connection Xml    ${version}    ${mode}    ${ip}    ${port}    ${node}
35     ...    ${password}    ${domain}
36     ${resp}    Post Request    ${session}    ${REST_CONTEXT}:add-connection    data=${DATA}    headers=${HEADERS_XML}
37     Should be Equal As Strings    ${resp.status_code}    200
38
39 Get Connections
40     [Arguments]    ${node}=127.0.0.1    ${session}=session    ${domain}=global
41     [Documentation]    Gets all connections via RPC from node
42     ${DATA}    Get Connections From Node Xml    ${node}    ${domain}
43     ${resp}    Post Request    ${session}    ${REST_CONTEXT}:get-connections    data=${DATA}    headers=${HEADERS_XML}
44     Should be Equal As Strings    ${resp.status_code}    200
45     [Return]    ${resp.content}
46
47 Delete Connections
48     [Arguments]    ${ip}    ${port}    ${node}=127.0.0.1    ${session}=session    ${domain}=global
49     [Documentation]    Delete connection via RPC from node
50     ${DATA}    Delete Connections Xml    ${ip}    ${port}    ${node}    ${domain}
51     ${resp}    Post Request    ${session}    ${REST_CONTEXT}:delete-connection    data=${DATA}    headers=${HEADERS_XML}
52     Should be Equal As Strings    ${resp.status_code}    200
53
54 Clean Connections
55     [Arguments]    ${node}=127.0.0.1    ${session}=session    ${domain}=global
56     [Documentation]    Delete all connections via RPC from node
57     ${resp}    Get Connections    ${node}    ${session}    ${domain}
58     @{connections}    Parse Connections    ${resp}
59     : FOR    ${connection}    IN    @{connections}
60     \    delete connections    ${connection['peer-address']}    ${connection['tcp-port']}    ${node}    ${session}
61
62 Verify Connection
63     [Arguments]    ${version}    ${mode}    ${ip}    ${port}=64999    ${node}=127.0.0.1    ${state}=on
64     ...    ${session}=session    ${domain}=global
65     [Documentation]    Verify that connection is ON
66     ${resp}    Get Connections    ${node}    ${session}    ${domain}
67     Should Contain Connection    ${resp}    ${ip}    ${port}    ${mode}    ${version}    ${state}
68
69 Add Binding
70     [Arguments]    ${sgt}    ${prefix}    ${node}=127.0.0.1    ${domain}=global    ${session}=session
71     [Documentation]    Add binding via RPC to Master DB of node
72     ${DATA}    Add Entry Xml    ${sgt}    ${prefix}    ${node}    ${domain}
73     ${resp}    Post Request    ${session}    ${REST_CONTEXT}:add-entry    data=${DATA}    headers=${HEADERS_XML}
74     Should be Equal As Strings    ${resp.status_code}    200
75
76 Get Bindings
77     [Arguments]    ${node}=127.0.0.1    ${session}=session    ${domain}=global
78     [Documentation]    Gets all binding via RPC from Master DB of node
79     ${DATA}    Get Bindings From Node Xml    ${node}    all    ${domain}
80     ${resp}    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Post Request    ${session}    ${REST_CONTEXT}:get-node-bindings    data=${DATA}
81     ...    headers=${HEADERS_XML}
82     ...    ELSE    Get Request    ${session}    /restconf/operational/network-topology:network-topology/topology/sxp/node/${node}/master-database/    headers=${HEADERS_XML}
83     Should be Equal As Strings    ${resp.status_code}    200
84     [Return]    ${resp.content}
85
86 Clean Bindings
87     [Arguments]    ${node}=127.0.0.1    ${session}=session    ${domain}=global
88     [Documentation]    Delete all bindings via RPC from Master DB of node
89     ${resp}    Get Bindings    ${node}    ${session}    ${domain}
90     @{bindings}    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Parse Bindings    ${resp}
91     ...    ELSE    Parse Prefix Groups    ${resp}    local
92     : FOR    ${binding}    IN    @{bindings}
93     \    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Clean Binding    ${binding['sgt']}    ${binding['ip-prefix']}    ${node}
94     \    ...    ${session}    ${domain}
95     \    ...    ELSE    Clean Binding    ${binding}    ${binding['binding']}    ${node}
96     \    ...    ${session}    ${domain}
97
98 Clean Binding
99     [Arguments]    ${sgt}    ${prefixes}    ${node}    ${session}    ${domain}=global
100     [Documentation]    Used for nester FOR loop
101     : FOR    ${prefix}    IN    @{prefixes}
102     \    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Delete Binding    ${sgt}    ${prefix}    ${node}
103     \    ...    ${domain}    ${session}
104     \    ...    ELSE    Delete Binding    ${sgt['sgt']}    ${prefix['ip-prefix']}    ${node}
105     \    ...    ${domain}    ${session}
106
107 Update Binding
108     [Arguments]    ${sgtOld}    ${prefixOld}    ${sgtNew}    ${prefixNew}    ${node}=127.0.0.1    ${session}=session
109     ...    ${domain}=global
110     [Documentation]    Updates value of binding via RPC in Master DB of node
111     ${DATA}    Update Binding Xml    ${sgtOld}    ${prefixOld}    ${sgtNew}    ${prefixNew}    ${node}
112     ...    ${domain}
113     ${resp}    Post Request    ${session}    ${REST_CONTEXT}:update-entry    data=${DATA}    headers=${HEADERS_XML}
114     Should be Equal As Strings    ${resp.status_code}    200
115
116 Delete Binding
117     [Arguments]    ${sgt}    ${prefix}    ${node}=127.0.0.1    ${domain}=global    ${session}=session
118     [Documentation]    Delete binding via RPC from Master DB of node
119     ${DATA}    Delete Binding Xml    ${sgt}    ${prefix}    ${node}    ${domain}
120     ${resp}    Post Request    ${session}    ${REST_CONTEXT}:delete-entry    data=${DATA}    headers=${HEADERS_XML}
121     Should be Equal As Strings    ${resp.status_code}    200
122
123 Add PeerGroup
124     [Arguments]    ${name}    ${peers}=    ${node}=127.0.0.1    ${session}=session
125     [Documentation]    Adds new PeerGroup via RPC to Node
126     ${DATA}    Add Peer Group Xml    ${name}    ${peers}    ${node}
127     ${resp}    Post Request    ${session}    ${REST_CONTEXT}:add-peer-group    data=${DATA}    headers=${HEADERS_XML}
128     Should be Equal As Strings    ${resp.status_code}    200
129
130 Delete Peer Group
131     [Arguments]    ${name}    ${node}=127.0.0.1    ${session}=session
132     [Documentation]    Delete PeerGroup via RPC from Node
133     ${DATA}    Delete Peer Group Xml    ${name}    ${node}
134     ${resp}    Post Request    ${session}    ${REST_CONTEXT}:delete-peer-group    data=${DATA}    headers=${HEADERS_XML}
135     Should be Equal As Strings    ${resp.status_code}    200
136
137 Get Peer Groups
138     [Arguments]    ${node}=127.0.0.1    ${session}=session
139     [Documentation]    Gets all PeerGroups via RPC from node
140     ${DATA}    Get Peer Groups From Node Xml    ${node}
141     ${resp}    Post Request    ${session}    ${REST_CONTEXT}:get-peer-groups    data=${DATA}    headers=${HEADERS_XML}
142     Should be Equal As Strings    ${resp.status_code}    200
143     [Return]    ${resp.content}
144
145 Clean Peer Groups
146     [Arguments]    ${node}=127.0.0.1    ${session}=session
147     [Documentation]    Delete all PeerGroups via RPC from node
148     ${resp}    Get Peer Groups    ${node}    ${session}
149     @{prefixes}    Parse Peer Groups    ${resp}
150     : FOR    ${group}    IN    @{prefixes}
151     \    Delete Peer Group    ${group['name']}    ${node}    ${session}
152
153 Add Filter
154     [Arguments]    ${name}    ${type}    ${entries}    ${node}=127.0.0.1    ${session}=session
155     [Documentation]    Add Filter via RPC from Node
156     ${DATA}    Add Filter Xml    ${name}    ${type}    ${entries}    ${node}
157     ${resp}    Post Request    ${session}    ${REST_CONTEXT}:add-filter    data=${DATA}    headers=${HEADERS_XML}
158     Should be Equal As Strings    ${resp.status_code}    200
159
160 Add Domain Filter
161     [Arguments]    ${name}    ${domains}    ${entries}    ${node}=127.0.0.1    ${filter_name}=base-domain-filter    ${session}=session
162     [Documentation]    Add Domain Filter via RPC from Node
163     ${DATA}    Add Domain Filter Xml    ${name}    ${domains}    ${entries}    ${node}    ${filter_name}
164     ${resp}    Post Request    ${session}    ${REST_CONTEXT}:add-domain-filter    data=${DATA}    headers=${HEADERS_XML}
165     Should be Equal As Strings    ${resp.status_code}    200
166
167 Delete Filter
168     [Arguments]    ${name}    ${type}    ${node}=127.0.0.1    ${session}=session
169     [Documentation]    Delete Filter via RPC from Node
170     ${DATA}    Delete Filter Xml    ${name}    ${type}    ${node}
171     ${resp}    Post Request    ${session}    ${REST_CONTEXT}:delete-filter    data=${DATA}    headers=${HEADERS_XML}
172     Should be Equal As Strings    ${resp.status_code}    200
173
174 Delete Domain Filter
175     [Arguments]    ${name}    ${node}=127.0.0.1    ${filter_name}=base-domain-filter    ${session}=session
176     [Documentation]    Delete Filter via RPC from Node
177     ${DATA}    Delete Domain Filter Xml    ${name}    ${node}    ${filter_name}
178     ${resp}    Post Request    ${session}    ${REST_CONTEXT}:delete-domain-filter    data=${DATA}    headers=${HEADERS_XML}
179     Should be Equal As Strings    ${resp.status_code}    200
180
181 Should Contain Binding
182     [Arguments]    ${resp}    ${sgt}    ${prefix}    ${db_source}=any
183     [Documentation]    Tests if data contains specified binding
184     ${out}    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Find Binding    ${resp}    ${sgt}    ${prefix}
185     ...    ELSE    Find Binding Legacy    ${resp}    ${sgt}    ${prefix}    ${db_source}
186     ...    add
187     Should Be True    ${out}    Doesn't have ${sgt} ${prefix}
188
189 Should Not Contain Binding
190     [Arguments]    ${resp}    ${sgt}    ${prefix}    ${db_source}=any
191     [Documentation]    Tests if data doesn't contains specified binding
192     ${out}    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Find Binding    ${resp}    ${sgt}    ${prefix}
193     ...    ELSE    Find Binding Legacy    ${resp}    ${sgt}    ${prefix}    ${db_source}
194     ...    add
195     Should Not Be True    ${out}    Should't have ${sgt} ${prefix}
196
197 Should Contain Connection
198     [Arguments]    ${resp}    ${ip}    ${port}    ${mode}    ${version}    ${state}=none
199     [Documentation]    Test if data contains specified connection
200     ${out}    Find Connection    ${resp}    ${version}    ${mode}    ${ip}    ${port}
201     ...    ${state}
202     Should Be True    ${out}    Doesn't have ${ip}:${port} ${mode} ${version}
203
204 Should Not Contain Connection
205     [Arguments]    ${resp}    ${ip}    ${port}    ${mode}    ${version}    ${state}=none
206     [Documentation]    Test if data doesn't contains specified connection
207     ${out}    Find Connection    ${resp}    ${version}    ${mode}    ${ip}    ${port}
208     ...    ${state}
209     Should Not Be True    ${out}    Shouldn't have ${ip}:${port} ${mode} ${version}
210
211 Setup Topology Complex
212     [Arguments]    ${version}=version4    ${PASSWORD}=none
213     : FOR    ${node}    IN RANGE    2    6
214     \    Add Connection    ${version}    both    127.0.0.1    64999    127.0.0.${node}
215     \    ...    ${PASSWORD}
216     \    Add Connection    ${version}    both    127.0.0.${node}    64999    127.0.0.1
217     \    ...    ${PASSWORD}
218     \    Wait Until Keyword Succeeds    15    1    Verify Connection    ${version}    both
219     \    ...    127.0.0.${node}
220     \    Add Binding    ${node}0    10.10.10.${node}0/32    127.0.0.${node}
221     \    Add Binding    ${node}0    10.10.${node}0.0/24    127.0.0.${node}
222     \    Add Binding    ${node}0    10.${node}0.0.0/16    127.0.0.${node}
223     \    Add Binding    ${node}0    ${node}0.0.0.0/8    127.0.0.${node}
224     Add Binding    10    10.10.10.10/32    127.0.0.1
225     Add Binding    10    10.10.10.0/24    127.0.0.1
226     Add Binding    10    10.10.0.0/16    127.0.0.1
227     Add Binding    10    10.0.0.0/8    127.0.0.1
228
229 Setup SXP Session
230     [Documentation]    Create session to Controller
231     Verify Feature Is Installed    odl-sxp-controller
232     Wait Until Keyword Succeeds    20    10    Check Karaf Log Has Messages    Successfully pushed configuration snapshot 22-sxp-controller-one-node.xml
233     Create Session    session    url=http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}    headers=${HEADERS_XML}
234     ${resp}    RequestsLibrary.Get Request    session    ${MODULES_API}
235     Should Be Equal As Strings    ${resp.status_code}    200
236     Should Contain    ${resp.content}    ietf-restconf
237
238 Clean SXP Session
239     [Documentation]    Destroy created sessions
240     Delete All Sessions
241
242 Add Domain
243     [Arguments]    ${domain_name}    ${node}=127.0.0.1    ${session}=session
244     [Documentation]    Add Domain via RPC
245     ${DATA}    Add Domain Xml    ${node}    ${domain_name}
246     ${resp}    Post Request    ${session}    ${REST_CONTEXT}:add-domain    data=${DATA}    headers=${HEADERS_XML}
247     Should be Equal As Strings    ${resp.status_code}    200
248
249 Delete Domain
250     [Arguments]    ${domain_name}    ${node}=127.0.0.1    ${session}=session
251     [Documentation]    Delete Domain via RPC
252     ${DATA}    Delete Domain Xml    ${node}    ${domain_name}
253     ${resp}    Post Request    ${session}    ${REST_CONTEXT}:delete-domain    data=${DATA}    headers=${HEADERS_XML}
254     Should be Equal As Strings    ${resp.status_code}    200
255
256 Add Bindings
257     [Arguments]    ${sgt}    ${prefixes}    ${node}=127.0.0.1    ${session}=session    ${domain}=global
258     [Documentation]    Add bindings via RPC to Master DB of node
259     ${DATA}    Add Bindings Xml    ${node}    ${domain}    ${sgt}    ${prefixes}
260     ${resp}    Post Request    ${session}    ${REST_CONTEXT}:add-bindings    data=${DATA}    headers=${HEADERS_XML}
261     Should be Equal As Strings    ${resp.status_code}    200
262
263 Delete Bindings
264     [Arguments]    ${sgt}    ${prefixes}    ${node}=127.0.0.1    ${session}=session    ${domain}=global
265     [Documentation]    Delete bindings via RPC from Master DB of node
266     ${DATA}    Delete Bindings Xml    ${node}    ${domain}    ${sgt}    ${prefixes}
267     ${resp}    Post Request    ${session}    ${REST_CONTEXT}:delete-bindings    data=${DATA}    headers=${HEADERS_XML}
268     Should be Equal As Strings    ${resp.status_code}    200
269
270 Add Bindings Range
271     [Arguments]    ${sgt}    ${start}    ${size}    ${node}
272     [Documentation]    Add Bindings to Node specified by range
273     ${prefixes}    Prefix Range    ${start}    ${size}
274     Add Bindings    ${sgt}    ${prefixes}    ${node}
275
276 Delete Bindings Range
277     [Arguments]    ${sgt}    ${start}    ${size}    ${node}
278     [Documentation]    Delete Bindings to Node specified by range
279     ${prefixes}    Prefix Range    ${start}    ${size}
280     Delete Bindings    ${sgt}    ${prefixes}    ${node}
281
282 Check Binding Range
283     [Arguments]    ${sgt}    ${start}    ${end}    ${node}
284     [Documentation]    Check if Node contains Bindings specified by range
285     ${resp}    Get Bindings    ${node}
286     : FOR    ${num}    IN RANGE    ${start}    ${end}
287     \    ${ip}    Get Ip From Number    ${num}
288     \    Should Contain Binding    ${resp}    ${sgt}    ${ip}/32
289
290 Check Binding Range Negative
291     [Arguments]    ${sgt}    ${start}    ${end}    ${node}
292     [Documentation]    Check if Node does not contains Bindings specified by range
293     ${resp}    Get Bindings    ${node}
294     : FOR    ${num}    IN RANGE    ${start}    ${end}
295     \    ${ip}    Get Ip From Number    ${num}
296     \    Should Not Contain Binding    ${resp}    ${sgt}    ${ip}/32
297
298 Setup SXP Environment
299     [Arguments]    ${node_range}=2
300     [Documentation]    Create session to Controller, node_range parameter specifies number of nodes to be created plus one
301     Setup SXP Session
302     : FOR    ${num}    IN RANGE    1    ${node_range}
303     \    ${ip}    Get Ip From Number    ${num}
304     \    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Add Node    ${ip}
305     \    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Wait Until Keyword Succeeds    20    1    Check Node Started
306     \    ...    ${ip}
307
308 Check Node Started
309     [Arguments]    ${node}    ${port}=64999    ${system}=${ODL_SYSTEM_IP}
310     [Documentation]    Verify that SxpNode has data writed to Operational datastore
311     ${resp}    RequestsLibrary.Get Request    session    /restconf/operational/network-topology:network-topology/topology/sxp/node/${node}/
312     Should Be Equal As Strings    ${resp.status_code}    200
313     ${rc}    Run Command On Remote System    ${system}    netstat -tln | grep -q ${node}:${port} && echo 0 || echo 1    ${ODL_SYSTEM_USER}    ${ODL_SYSTEM_PASSWORD}    prompt=${ODL_SYSTEM_PROMPT}
314     Should Be Equal As Strings    ${rc}    0
315
316 Clean SXP Environment
317     [Arguments]    ${node_range}=2
318     [Documentation]    Destroy created sessions
319     : FOR    ${num}    IN RANGE    1    ${node_range}
320     \    ${ip}    Get Ip From Number    ${num}
321     \    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Delete Node    ${ip}
322     Clean SXP Session