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