46714354acad12ee8f1af0d9b7800de232d4a9b2
[integration/test.git] / csit / suites / openflowplugin / Clustered_Reconciliation / 010_Group_Flows.robot
1 *** Settings ***
2 Documentation     Switch connections and cluster are restarted.
3 Suite Setup       Initialization Phase
4 Suite Teardown    Final Phase
5 Library           RequestsLibrary
6 Resource          ../../../libraries/ClusterManagement.robot
7 Resource          ../../../libraries/ClusterOpenFlow.robot
8 Resource          ../../../libraries/TemplatedRequests.robot
9 Resource          ../../../libraries/MininetKeywords.robot
10 Resource          ../../../libraries/Utils.robot
11 Resource          ../../../variables/Variables.robot
12
13 *** Variables ***
14 ${SWITCHES}       3
15 ${ITER}           100
16 ${VAR_DIR}        ${CURDIR}/../../../variables/openflowplugin
17
18 *** Test Cases ***
19 Enable Stale Flow Entry
20     [Documentation]    Enable stale flow entry feature.
21     # Stale flows/groups feature is only available in Boron onwards.
22     CompareStream.Run Keyword If At Least Boron    TemplatedRequests.Put As Json Templated    folder=${VAR_DIR}/frm-config    mapping={"STALE":"true"}    session=session
23
24 Add Groups And Flows
25     [Documentation]    Add ${ITER} groups 1&2 and flows in every switch.
26     Add Groups And Flows    ${ITER}
27
28 Start Mininet Multiple Connections
29     [Documentation]    Start mininet linear with connection to all cluster instances.
30     ${mininet_conn_id}=    MininetKeywords.Start Mininet Multiple Controllers    ${TOOLS_SYSTEM_IP}    ${ClusterManagement__member_index_list}    --topo linear,${SWITCHES} --switch ovsk,protocols=OpenFlow13
31     BuiltIn.Set Suite Variable    ${mininet_conn_id}
32     BuiltIn.Wait Until Keyword Succeeds    10s    1s    OVSDB.Check OVS OpenFlow Connections    ${TOOLS_SYSTEM_IP}    ${SWITCHES*3}
33
34 Check Linear Topology
35     [Documentation]    Check Linear Topology.
36     BuiltIn.Wait Until Keyword Succeeds    30s    1s    Check Linear Topology    ${SWITCHES}
37
38 Check Flows In Operational DS
39     [Documentation]    Check Groups after mininet starts.
40     BuiltIn.Wait Until Keyword Succeeds    30s    1s    Check Number Of Flows    ${all_flows}
41
42 Check Groups In Operational DS
43     [Documentation]    Check Flows after mininet starts.
44     Check Number Of Groups    ${all_groups}
45
46 Check Flows In Switch
47     [Documentation]    Check Flows in switch after mininet starts.
48     MininetKeywords.Check Flows In Mininet    ${mininet_conn_id}    ${all_flows}
49
50 Check Entity Owner Status And Find Owner and Successor Before Fail
51     [Documentation]    Check Entity Owner Status and identify owner and successor for first switch s1.
52     ${original_owner}    ${original_successor_list}    ClusterOpenFlow.Get OpenFlow Entity Owner Status For One Device    openflow:1    1
53     BuiltIn.Set Suite Variable    ${original_owner}
54
55 Disconnect Mininet From Owner
56     [Documentation]    Disconnect mininet from the owner
57     ${owner_list}    BuiltIn.Create List    ${original_owner}
58     Disconnect Cluster Mininet    break    ${owner_list}
59     BuiltIn.Set Suite Variable    ${owner_list}
60
61 Check Entity Owner Status And Find Owner and Successor After Fail
62     [Documentation]    Check Entity Owner Status and identify owner and successor for first switch s1.
63     ${new_owner}    ${new_successor_list}    ClusterOpenFlow.Get OpenFlow Entity Owner Status For One Device    openflow:1    1
64
65 Check Linear Topology After Disconnect
66     [Documentation]    Check Linear Topology After Disconnecting mininet from owner.
67     BuiltIn.Wait Until Keyword Succeeds    30s    1s    Check Linear Topology    ${SWITCHES}
68
69 Remove Flows And Groups After Mininet Is Disconnected
70     [Documentation]    Remove 1 group 1&2 and 1 flow in every switch after mininet is disconnected.
71     Remove Single Group And Flow
72
73 Check Flows In Operational DS After Mininet Is Disconnected
74     [Documentation]    Check Flows in Operational DS after mininet is disconnected.
75     BuiltIn.Wait Until Keyword Succeeds    30s    1s    Check Number Of Flows    ${less_flows}
76
77 Check Groups In Operational DS After Mininet Is Disconnected
78     [Documentation]    Check Groups in Operational DS after mininet is disconnected.
79     Check Number Of Groups    ${less_groups}
80
81 Check Flows In Switch After Mininet Is Disconnected
82     [Documentation]    Check Flows in switch after mininet is disconnected
83     MininetKeywords.Check Flows In Mininet    ${mininet_conn_id}    ${less_flows}
84
85 Reconnect Mininet To Owner
86     [Documentation]    Reconnect mininet to switch 1 owner.
87     Disconnect Cluster Mininet    restore    ${owner_list}
88
89 Check Linear Topology After Reconnect
90     [Documentation]    Check Linear Topology After Reconnect.
91     BuiltIn.Wait Until Keyword Succeeds    30s    1s    Check Linear Topology    ${SWITCHES}
92
93 Add Flows And Groups After Reconnect
94     [Documentation]    Add 1 group type 1&2 and 1 flow in every switch.
95     Add Single Group And Flow
96
97 Check Flows After Reconnect In Operational DS
98     [Documentation]    Check Flows in Operational DS after mininet is reconnected.
99     BuiltIn.Wait Until Keyword Succeeds    30s    1s    Check Number Of Flows    ${all_flows}
100
101 Check Groups After Reconnect In Operational DS
102     [Documentation]    Check Groups in Operational DS after mininet is reconnected.
103     Check Number Of Groups    ${all_groups}
104
105 Check Flows After Reconnect In Switch
106     [Documentation]    Check Flows in switch after mininet is reconnected.
107     MininetKeywords.Check Flows In Mininet    ${mininet_conn_id}    ${all_flows}
108
109 Disconnect Mininet From Cluster
110     [Documentation]    Disconnect Mininet from Cluster.
111     Disconnect Cluster Mininet
112
113 Check No Switches After Disconnect
114     [Documentation]    Check no switches in topology after disconnecting mininet from cluster.
115     BuiltIn.Wait Until Keyword Succeeds    30s    1s    Check No Switches In Topology    ${SWITCHES}
116
117 Remove Flows And Groups While Mininet Is Disconnected
118     [Documentation]    Remove a group and flow while mininet Is Disconnected from cluster.
119     Remove Single Group And Flow
120
121 Reconnect Mininet To Cluster
122     [Documentation]    Reconnect mininet to cluster by removing Iptables drop rules that were used to disconnect
123     Disconnect Cluster Mininet    restore
124
125 Check Linear Topology After Mininet Reconnects
126     [Documentation]    Check Linear Topology after reconnect.
127     BuiltIn.Wait Until Keyword Succeeds    30s    1s    Check Linear Topology    ${SWITCHES}
128
129 Check Flows In Operational DS After Mininet Reconnects
130     [Documentation]    Check Flows in Operational DS after mininet is reconnected.
131     BuiltIn.Wait Until Keyword Succeeds    30s    1s    Check Number Of Flows    ${less_flows}
132
133 Check Groups In Operational DS After Mininet Reconnects
134     [Documentation]    Check Groups in Operational DS after mininet is reconnected to cluster.
135     Check Number Of Groups    ${less_groups}
136
137 Check Flows In Switch After Mininet Reconnects
138     [Documentation]    Check Flows in switch after mininet is reconnected to cluster.
139     MininetKeywords.Check Flows In Mininet    ${mininet_conn_id}    ${less_flows}
140
141 Check Entity Owner Status And Find Owner and Successor Before Stop
142     [Documentation]    Check Entity Owner Status and identify owner and successor for first switch s1.
143     ${original_owner}    ${original_successor_list}    ClusterOpenFlow.Get OpenFlow Entity Owner Status For One Device    openflow:1    1
144     ${original_successor}=    Collections.Get From List    ${original_successor_list}    0
145     BuiltIn.Set Suite Variable    ${original_owner}
146     BuiltIn.Set Suite Variable    ${original_successor_list}
147     BuiltIn.Set Suite Variable    ${original_successor}
148
149 Check Shards Status before Stop
150     [Documentation]    Check Status for all shards in OpenFlow application.
151     ClusterOpenFlow.Check OpenFlow Shards Status
152
153 Stop Owner Instance
154     [Documentation]    Stop Owner Instance and verify it is shutdown
155     ClusterManagement.Stop Single Member    ${original_owner}
156     BuiltIn.Set Suite Variable    ${new_cluster_list}    ${original_successor_list}
157
158 Check Shards Status After Stop
159     [Documentation]    Check Status for all shards in OpenFlow application.
160     ClusterOpenFlow.Check OpenFlow Shards Status After Cluster Event    ${new_cluster_list}
161
162 Check Entity Owner Status And Find Owner and Successor After Stop
163     [Documentation]    Check Entity Owner Status and identify owner and successor.
164     ${new_owner}    ${new_successor_list}    ClusterOpenFlow.Get OpenFlow Entity Owner Status For One Device    openflow:1    ${original_successor}    ${new_cluster_list}    after_stop=True
165     BuiltIn.Set Suite Variable    ${new_owner}
166
167 Check Linear Topology After Owner Stop
168     [Documentation]    Check Linear Topology.
169     BuiltIn.Wait Until Keyword Succeeds    30s    1s    Check Linear Topology    ${SWITCHES}    ${new_owner}
170
171 Add Configuration In Owner and Verify After Fail
172     [Documentation]    Add Flow in Owner and verify it gets applied from all instances.
173     Add Single Group And Flow    ${new_owner}
174
175 Check Flows In Operational DS After Owner Is Stopped
176     [Documentation]    Check Flows in Operational DS after Owner is Stopped.
177     BuiltIn.Wait Until Keyword Succeeds    30s    1s    Check Number Of Flows    ${all_flows}    ${new_owner}
178
179 Check Groups In Operational DS After Owner Is Stopped
180     [Documentation]    Check Groups in Operational DS after Owner is Stopped.
181     Check Number Of Groups    ${all_groups}    ${new_owner}
182
183 Check Flows In Switch After Owner Is Stopped
184     [Documentation]    Check Flows in switch after Owner is Stopped
185     MininetKeywords.Check Flows In Mininet    ${mininet_conn_id}    ${all_flows}
186
187 Start Old Owner Instance
188     [Documentation]    Start old Owner Instance and verify it is up
189     ClusterManagement.Start Single Member    ${original_owner}
190
191 Check Linear Topology After Owner Restart
192     [Documentation]    Check Linear Topology.
193     BuiltIn.Wait Until Keyword Succeeds    30s    1s    Check Linear Topology    ${SWITCHES}
194
195 Remove Configuration In Owner and Verify After Owner Restart
196     [Documentation]    Add Flow in Owner and verify it gets applied from all instances.
197     Remove Single Group And Flow    ${new_owner}
198
199 Check Flows After Owner Restart In Operational DS
200     [Documentation]    Check Flows in Operational DS after owner is restarted.
201     BuiltIn.Wait Until Keyword Succeeds    30s    1s    Check Number Of Flows    ${less_flows}
202
203 Check Groups After Owner Restart In Operational DS
204     [Documentation]    Check Groups in Operational DS after owner is restarted.
205     Check Number Of Groups    ${less_groups}
206
207 Check Flows In Switch After Owner Is Restarted
208     [Documentation]    Check Flows in switch after Owner is restarted
209     MininetKeywords.Check Flows In Mininet    ${mininet_conn_id}    ${less_flows}
210
211 Restart Cluster
212     [Documentation]    Stop and Start cluster.
213     # Try to stop contoller, if stop does not work or takes too long, kill controller.
214     ${status}    ${result}=    BuiltIn.Run Keyword And Ignore Error    ClusterManagement.Stop_Members_From_List_Or_All
215     BuiltIn.Run Keyword If    '${status}' != 'PASS'    ClusterManagement.Kill_Members_From_List_Or_All
216     ClusterManagement.Start_Members_From_List_Or_All    wait_for_sync=False
217
218 Check Linear Topology After Controller Restarts
219     [Documentation]    Check Linear Topology after controller restarts.
220     BuiltIn.Wait Until Keyword Succeeds    300s    2s    Check Linear Topology    ${SWITCHES}
221
222 Add Flow And Group After Restart
223     [Documentation]    Add 1 group type 1&2 and 1 flow in every switch.
224     Add Single Group And Flow
225
226 Check Flows In Operational DS After Controller Restarts
227     [Documentation]    Check Flows in Operational DS after controller is restarted.
228     BuiltIn.Wait Until Keyword Succeeds    300s    2s    Check Number Of Flows    ${all_flows}
229
230 Check Groups In Operational DS After Controller Restarts
231     [Documentation]    Check Groups in Operational DS after controller is restarted.
232     Check Number Of Groups    ${all_groups}
233
234 Check Flows In Switch After Controller Restarts
235     [Documentation]    Check Flows in switch after controller is restarted..
236     MininetKeywords.Check Flows In Mininet    ${mininet_conn_id}    ${all_flows}
237
238 Stop Mininet
239     [Documentation]    Stop Mininet.
240     MininetKeywords.Stop Mininet And Exit
241
242 Check No Switches
243     [Documentation]    Check no switches in topology.
244     BuiltIn.Wait Until Keyword Succeeds    5s    1s    Check No Switches In Topology    ${SWITCHES}
245
246 *** Keywords ***
247 Initialization Phase
248     [Documentation]    Create controller session and set variables.
249     ClusterManagement.ClusterManagement_Setup
250     RequestsLibrary.Create Session    session    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
251     ${switches}    Convert To Integer    ${SWITCHES}
252     ${iter}    Convert To Integer    ${ITER}
253     ${all_groups}=    BuiltIn.Evaluate    ${switches} * ${iter} * 2
254     ${less_groups}=    BuiltIn.Evaluate    ${all_groups} - ${switches} * 2
255     # Stale flows/groups feature enabled in Boron onwards.
256     ${less_groups}=    CompareStream.Set Variable If At Least Boron    ${less_groups}    ${all_groups}
257     ${all_flows}=    BuiltIn.Evaluate    ${switches} * ${iter+1}
258     ${less_flows}=    BuiltIn.Evaluate    ${all_flows} - ${switches}
259     # Stale flows/groups feature enabled in Boron onwards.
260     ${less_flows}=    CompareStream.Set Variable If At Least Boron    ${less_flows}    ${all_flows}
261     BuiltIn.Set Suite Variable    ${switches}
262     BuiltIn.Set Suite Variable    ${iter}
263     BuiltIn.Set Suite Variable    ${all_groups}
264     BuiltIn.Set Suite Variable    ${less_groups}
265     BuiltIn.Set Suite Variable    ${all_flows}
266     BuiltIn.Set Suite Variable    ${less_flows}
267     BuiltIn.Set Suite Variable    ${no_flows}    ${SWITCHES}
268
269 Final Phase
270     [Documentation]    Delete all sessions.
271     ${command} =    BuiltIn.Set Variable    sudo iptables -v -F
272     Utils.Run Command On Controller    cmd=${command}
273     CompareStream.Run Keyword If At Least Boron    TemplatedRequests.Put As Json Templated    folder=${VAR_DIR}/frm-config    mapping={"STALE":"false"}    session=session
274     BuiltIn.Run Keyword And Ignore Error    RequestsLibrary.Delete Request    session    ${CONFIG_NODES_API}
275     RequestsLibrary.Delete All Sessions
276
277 Disconnect Cluster Mininet
278     [Arguments]    ${action}=break    ${member_index_list}=${EMPTY}
279     [Documentation]    Break and restore controller to mininet connection via iptables.
280     ${index_list} =    ClusterManagement.List_Indices_Or_All    given_list=${member_index_list}
281     : FOR    ${index}    IN    @{index_list}
282     \    ${rule} =    BuiltIn.Set Variable    OUTPUT -p all --source ${ODL_SYSTEM_${index}_IP} --destination ${TOOLS_SYSTEM_IP} -j DROP
283     \    ${command} =    BuiltIn.Set Variable If    '${action}'=='restore'    sudo /sbin/iptables -D ${rule}    sudo /sbin/iptables -I ${rule}
284     \    Log To Console    ${ODL_SYSTEM_${index}_IP}
285     \    Utils.Run Command On Controller    ${ODL_SYSTEM_${index}_IP}    cmd=${command}
286     \    ${command} =    BuiltIn.Set Variable    sudo /sbin/iptables -L -n
287     \    ${output} =    Utils.Run Command On Controller    cmd=${command}
288     \    BuiltIn.Log    ${output}
289
290 Add Groups And Flows
291     [Arguments]    ${iter}=1    ${member_index}=1
292     [Documentation]    Add ${ITER} groups type 1 & 2 and flows in every switch.
293     ${session} =    Resolve_Http_Session_For_Member    member_index=${member_index}
294     : FOR    ${switch}    IN RANGE    1    ${switches+1}
295     \    TemplatedRequests.Post As Json Templated    folder=${VAR_DIR}/add-group-1    mapping={"SWITCH":"${switch}"}    session=${session}    iterations=${iter}
296     \    TemplatedRequests.Post As Json Templated    folder=${VAR_DIR}/add-group-2    mapping={"SWITCH":"${switch}"}    session=${session}    iterations=${iter}
297     \    TemplatedRequests.Post As Json Templated    folder=${VAR_DIR}/add-flow    mapping={"SWITCH":"${switch}"}    session=${session}    iterations=${iter}
298
299 Add Single Group And Flow
300     [Arguments]    ${member_index}=1
301     [Documentation]    Add 1 group 1&2 and 1 flow in every switch.
302     Add Groups And Flows    1    ${member_index}
303
304 Remove Single Group And Flow
305     [Arguments]    ${member_index}=1
306     [Documentation]    Remove 1 group 1&2 and 1 flow in every switch.
307     ${session} =    Resolve_Http_Session_For_Member    member_index=${member_index}
308     : FOR    ${switch}    IN RANGE    1    ${switches+1}
309     \    RequestsLibrary.Delete Request    ${session}    ${CONFIG_NODES_API}/node/openflow:${switch}/table/0/flow/1
310     \    RequestsLibrary.Delete Request    ${session}    ${CONFIG_NODES_API}/node/openflow:${switch}/group/1
311     \    RequestsLibrary.Delete Request    ${session}    ${CONFIG_NODES_API}/node/openflow:${switch}/group/1000
312
313 Check Linear Topology
314     [Arguments]    ${switches}    ${member_index}=1
315     [Documentation]    Check Linear topology.
316     ${session} =    Resolve_Http_Session_For_Member    member_index=${member_index}
317     ${resp}    RequestsLibrary.Get Request    ${session}    ${OPERATIONAL_TOPO_API}
318     Log    ${resp.content}
319     Should Be Equal As Strings    ${resp.status_code}    200
320     : FOR    ${switch}    IN RANGE    1    ${switches+1}
321     \    Should Contain    ${resp.content}    "node-id":"openflow:${switch}"
322     \    Should Contain    ${resp.content}    "tp-id":"openflow:${switch}:1"
323     \    Should Contain    ${resp.content}    "tp-id":"openflow:${switch}:2"
324     \    Should Contain    ${resp.content}    "source-tp":"openflow:${switch}:2"
325     \    Should Contain    ${resp.content}    "dest-tp":"openflow:${switch}:2"
326     \    ${edge}    Evaluate    ${switch}==1 or ${switch}==${switches}
327     \    Run Keyword Unless    ${edge}    Should Contain    ${resp.content}    "tp-id":"openflow:${switch}:3"
328     \    Run Keyword Unless    ${edge}    Should Contain    ${resp.content}    "source-tp":"openflow:${switch}:3"
329     \    Run Keyword Unless    ${edge}    Should Contain    ${resp.content}    "dest-tp":"openflow:${switch}:3
330
331 Check No Switches In Inventory
332     [Arguments]    ${switches}    ${member_index}=1
333     [Documentation]    Check no switch is in inventory
334     ${session} =    Resolve_Http_Session_For_Member    member_index=${member_index}
335     ${resp}    RequestsLibrary.Get Request    ${session}    ${OPERATIONAL_NODES_API}
336     Log    ${resp.content}
337     Should Be Equal As Strings    ${resp.status_code}    200
338     : FOR    ${switch}    IN RANGE    1    ${switches+1}
339     \    Should Not Contain    ${resp.content}    "openflow:${switch}"
340
341 Check Number Of Flows
342     [Arguments]    ${flows}    ${member_index}=1
343     [Documentation]    Check number of flows in the inventory.
344     ${session} =    Resolve_Http_Session_For_Member    member_index=${member_index}
345     ${resp}=    RequestsLibrary.Get Request    ${session}    ${OPERATIONAL_NODES_API}
346     Log    ${resp.content}
347     Should Be Equal As Strings    ${resp.status_code}    200
348     ${count}=    Get Count    ${resp.content}    "priority"
349     Should Be Equal As Integers    ${count}    ${flows}
350
351 Check Number Of Groups
352     [Arguments]    ${groups}    ${member_index}=1
353     [Documentation]    Check number of groups in the inventory.
354     ${session} =    Resolve_Http_Session_For_Member    member_index=${member_index}
355     ${resp}=    RequestsLibrary.Get Request    ${session}    ${OPERATIONAL_NODES_API}
356     Log    ${resp.content}
357     Should Be Equal As Strings    ${resp.status_code}    200
358     ${group_count}=    Get Count    ${resp.content}    "group-type"
359     ${count}=    CompareStream.Set_Variable_If_At Least_Boron    ${group_count}    ${group_count/2}
360     Should Be Equal As Integers    ${count}    ${groups}
361
362 Check No Switches In Topology
363     [Arguments]    ${switches}    ${member_index}=1
364     [Documentation]    Check no switch is in topology
365     ${session} =    Resolve_Http_Session_For_Member    member_index=${member_index}
366     ${resp}    RequestsLibrary.Get Request    ${session}    ${OPERATIONAL_TOPO_API}
367     Log    ${resp.content}
368     Should Be Equal As Strings    ${resp.status_code}    200
369     : FOR    ${switch}    IN RANGE    1    ${switches+1}
370     \    Should Not Contain    ${resp.content}    openflow:${switch}