a02926be5e1b99bc4ddfc3069b3b77a78e67bfc6
[integration/test.git] / csit / libraries / WorkflowsOpenFlow.robot
1 *** Settings ***
2 Documentation     Resource for OpenFlow workflows. This library can be used for scalability and longevity tests.
3 Library           SSHLibrary
4 Library           DateTime
5 Library           RequestsLibrary
6 Library           ScaleClient.py
7 Library           SwitchClasses/BaseSwitch.py
8 Resource          Utils.robot
9 Resource          FlowLib.robot
10 Resource          CompareStream.robot
11 Resource          MininetKeywords.robot
12 Resource          KarafKeywords.robot
13 Resource          ../variables/Variables.robot
14
15 *** Variables ***
16 ${flow_count}     10000
17 ${swspread}       linear
18 ${tables}         10
19 ${tabspread}      linear
20 ${nrthreads}      1
21
22 *** Keywords ***
23 Workflow Linear Topology
24     [Arguments]    ${switches}    ${sustain_time}=0
25     [Documentation]    Workflow to bring a Linear topology of ${switches} switches, push flows, hold for ${sustain_time} seconds, delete flows and stop topology.
26     ...    This KW returns workflow state (PASS/FAIL), error message and topology discover time.
27     # Define required variables
28     ${error_message}=    Set Variable    Test has completed
29     ${topology_discover_time}=    Set Variable    ${0}
30     ${controller_list}=    Create List    ${ODL_SYSTEM_IP}
31     ${flow_count}=    Convert to Integer    ${flow_count}
32     ${flows_ovs_25}=    Evaluate    ${flow_count} + ${switches}
33     ${flows_before}=    CompareStream.Set_Variable_If_At_Least_Boron    ${switches}    ${0}
34     ${flows_after}=    CompareStream.Set_Variable_If_At_Least_Boron    ${flows_ovs_25}    ${flow_count}
35     ${flows}    ${notes}    ScaleClient.Generate New Flow Details    flows=${flow_count}    switches=${switches}    swspread=${swspread}    tables=${tables}
36     ...    tabspread=${tabspread}
37     # Workflow starts
38     Log to console    ${\n}
39     Log To Console    Starting mininet linear ${switches} switches
40     ${status}    ${result}    Run Keyword And Ignore Error    MininetKeywords.Start Mininet Linear    ${switches}    mininet_timeout=${switches*4}
41     Return From Keyword If    '${status}' == 'FAIL'    ${status}    Fail starting mininet    ${topology_discover_time}
42     ${start_time}=    DateTime.Get Current Date    result_format=timestamp
43     Log To Console    Verify controller is OK
44     ${status}    ${result}    Run Keyword And Ignore Error    Utils.Verify Controller Is Not Dead    ${ODL_SYSTEM_IP}
45     Return From Keyword If    '${status}' == 'FAIL'    ${status}    Controller is dead    ${topology_discover_time}
46     ${status}    ${result}    Run Keyword And Ignore Error    Utils.Verify Controller Has No Null Pointer Exceptions    ${ODL_SYSTEM_IP}
47     Return From Keyword If    '${status}' == 'FAIL'    ${status}    Controller has NPE    ${topology_discover_time}
48     Log To Console    Checking ${switches} switches
49     ${status}    ${result}    Run Keyword And Ignore Error    Wait Until Keyword Succeeds    ${switches*2}    2s    FlowLib.Check Switches In Inventory
50     ...    ${switches}
51     Return From Keyword If    '${status}' == 'FAIL'    ${status}    Fail checking switch    ${topology_discover_time}
52     Log To Console    Add table miss flows
53     ${status}    ${result}    Run Keyword And Ignore Error    FlowLib.Add Table Miss Flows    ${switches}
54     Return From Keyword If    '${status}' == 'FAIL'    ${status}    Fail adding table Miss flows    ${topology_discover_time}
55     Log To Console    Checking Table Miss Flows
56     ${status}    ${result}    Run Keyword And Ignore Error    Wait Until Keyword Succeeds    ${switches}    2s    FlowLib.Check Table Miss Flows
57     ...    ${switches}
58     Return From Keyword If    '${status}' == 'FAIL'    ${status}    Fail checking table miss flows    ${topology_discover_time}
59     Log To Console    Checking Linear Topology
60     ${status}    ${result}    Run Keyword And Ignore Error    Wait Until Keyword Succeeds    ${switches}    2s    FlowLib.Check Linear Topology
61     ...    ${switches}
62     Return From Keyword If    '${status}' == 'FAIL'    ${status}    Fail checking topology    ${topology_discover_time}
63     ${end_time}=    DateTime.Get Current Date    result_format=timestamp
64     ${topology_discover_time}=    DateTime.Subtract Date From Date    ${end_time}    ${start_time}
65     Log To Console    Topology Discovery Time = ${topology_discover_time} seconds
66     Log To Console    Adding ${flow_count} flows
67     ${status}    ${result}    Run Keyword And Ignore Error    ScaleClient.Configure Flows    flow_details=${flows}    controllers=${controller_list}    nrthreads=${nrthreads}
68     Return From Keyword If    '${status}' == 'FAIL'    ${status}    Fail configuring flows    ${topology_discover_time}
69     Log To Console    Checking ${flow_count} flows in Mininet
70     ${status}    ${result}    Run Keyword And Ignore Error    MininetKeywords.Verify Aggregate Flow From Mininet Session    ${mininet_conn_id}    ${flows_after}    ${switches}
71     Return From Keyword If    '${status}' == 'FAIL'    ${status}    Fail checking flows in mininet    ${topology_discover_time}
72     Log To Console    Checking ${flow_count} flows in Operational DS
73     ${status}    ${result}    Run Keyword And Ignore Error    Wait Until Keyword Succeeds    ${switches*4}    2s    FlowLib.Check Flows Operational Datastore
74     ...    ${flows_after}
75     Return From Keyword If    '${status}' == 'FAIL'    ${status}    Fail checking flows in operational DS    ${topology_discover_time}
76     Log To Console    Sleep for ${sustain_time} seconds
77     Sleep    ${sustain_time}
78     Log To Console    Deleting ${flow_count} flows
79     ${status}    ${result}    Run Keyword And Ignore Error    ScaleClient.Deconfigure Flows    flow_details=${flows}    controllers=${controller_list}    nrthreads=${nrthreads}
80     Return From Keyword If    '${status}' == 'FAIL'    ${status}    Fail deconfiguring flows    ${topology_discover_time}
81     Log To Console    Checking no flows in Mininet
82     ${status}    ${result}    Run Keyword And Ignore Error    MininetKeywords.Verify Aggregate Flow From Mininet Session    ${mininet_conn_id}    ${flows_before}    ${switches}
83     Return From Keyword If    '${status}' == 'FAIL'    ${status}    Fail checking no flows in mininet    ${topology_discover_time}
84     Log To Console    Checking no flows in Operational DS
85     ${status}    ${result}    Run Keyword And Ignore Error    Wait Until Keyword Succeeds    ${switches*4}    2s    FlowLib.Check Flows Operational Datastore
86     ...    ${flows_before}
87     Return From Keyword If    '${status}' == 'FAIL'    ${status}    Fail checking no flows in operational DS    ${topology_discover_time}
88     Log To Console    Stopping Mininet
89     ${status}    ${result}    Run Keyword And Ignore Error    MininetKeywords.Stop Mininet And Exit
90     Return From Keyword If    '${status}' == 'FAIL'    ${status}    Fail stopping mininet    ${topology_discover_time}
91     Log To Console    Checking No Switches
92     ${status}    ${result}    Run Keyword And Ignore Error    Wait Until Keyword Succeeds    10s    2s    FlowLib.Check No Switches In Inventory
93     ...    ${switches}
94     Return From Keyword If    '${status}' == 'FAIL'    ${status}    Fail checking no switch    ${topology_discover_time}
95     Log To Console    Checking No Topology
96     ${status}    ${result}    Run Keyword And Ignore Error    Wait Until Keyword Succeeds    10s    2s    FlowLib.Check No Switches In Topology
97     ...    ${switches}
98     Return From Keyword If    '${status}' == 'FAIL'    ${status}    Fail checking no topology    ${topology_discover_time}
99     [Return]    PASS    ${error_message}    ${topology_discover_time}
100
101 Workflow Full Mesh Topology
102     [Arguments]    ${switches}    ${sustain_time}=0
103     [Documentation]    Workflow to bring a Full mesh topology of ${switches} switches, push some flows, delete flows and stop topology.
104     ...    This KW returns workflow state (PASS/FAIL), error message and topology discover time.
105     # Define required variables
106     ${error_message}=    Set Variable    Test has completed
107     ${topology_discover_time}=    Set Variable    ${0}
108     ${mininet_timeout}=    Evaluate    ${switches} * ${switches}
109     ${links}=    Evaluate    ${switches} * ${switches-1}
110     ${controller_list}=    Create List    ${ODL_SYSTEM_IP}
111     ${flow_count}=    Convert to Integer    ${flow_count}
112     ${flows_ovs_25}=    Evaluate    ${flow_count} + ${switches}
113     ${flows_before}=    CompareStream.Set_Variable_If_At_Least_Boron    ${switches}    ${0}
114     ${flows_after}=    CompareStream.Set_Variable_If_At_Least_Boron    ${flows_ovs_25}    ${flow_count}
115     ${flows}    ${notes}    ScaleClient.Generate New Flow Details    flows=${flow_count}    switches=${switches}    swspread=${swspread}    tables=${tables}
116     ...    tabspread=${tabspread}
117     # Workflow starts
118     Log to console    ${\n}
119     Log To Console    Start a mininet full mesh ${switches} switches
120     ${status}    ${result}    Run Keyword And Ignore Error    MininetKeywords.Start Mininet Full Mesh    ${switches}    mininet_timeout=${mininet_timeout}
121     Return From Keyword If    '${status}' == 'FAIL'    ${status}    Fail starting mininet    ${topology_discover_time}
122     ${start_time}=    DateTime.Get Current Date    result_format=timestamp
123     Log To Console    Verify controller is OK
124     ${status}    ${result}    Run Keyword And Ignore Error    Utils.Verify Controller Is Not Dead    ${ODL_SYSTEM_IP}
125     Return From Keyword If    '${status}' == 'FAIL'    ${status}    Controller is dead    ${topology_discover_time}
126     ${status}    ${result}    Run Keyword And Ignore Error    Utils.Verify Controller Has No Null Pointer Exceptions    ${ODL_SYSTEM_IP}
127     Return From Keyword If    '${status}' == 'FAIL'    ${status}    Controller has NPE    ${topology_discover_time}
128     Log To Console    Checking ${switches} switches
129     ${status}    ${result}    Run Keyword And Ignore Error    Wait Until Keyword Succeeds    10s    2s    FlowLib.Check Switches In Inventory
130     ...    ${switches}
131     Return From Keyword If    '${status}' == 'FAIL'    ${status}    Fail checking switch    ${topology_discover_time}
132     Log To Console    Check number of links in inventory is ${links}
133     ${status}    ${result}    Run Keyword And Ignore Error    Wait Until Keyword Succeeds    10s    2s    FlowLib.Check Number Of Links
134     ...    ${links}
135     Return From Keyword If    '${status}' == 'FAIL'    ${status}    Fail checking topology    ${topology_discover_time}
136     ${end_time}=    DateTime.Get Current Date    result_format=timestamp
137     ${topology_discover_time}=    DateTime.Subtract Date From Date    ${end_time}    ${start_time}
138     Log To Console    Topology Discovery Time = ${topology_discover_time} seconds
139     Log To Console    Adding ${flow_count} flows
140     ${status}    ${result}    Run Keyword And Ignore Error    ScaleClient.Configure Flows    flow_details=${flows}    controllers=${controller_list}    nrthreads=${nrthreads}
141     Return From Keyword If    '${status}' == 'FAIL'    ${status}    Fail configuring flows    ${topology_discover_time}
142     Log To Console    Checking ${flow_count} flows in Mininet
143     ${status}    ${result}    Run Keyword And Ignore Error    MininetKeywords.Verify Aggregate Flow From Mininet Session    ${mininet_conn_id}    ${flows_after}    ${switches}
144     Return From Keyword If    '${status}' == 'FAIL'    ${status}    Fail checking flows in mininet    ${topology_discover_time}
145     Log To Console    Checking ${flow_count} flows in Operational DS
146     ${status}    ${result}    Run Keyword And Ignore Error    Wait Until Keyword Succeeds    ${switches*4}    2s    FlowLib.Check Flows Operational Datastore
147     ...    ${flows_after}
148     Return From Keyword If    '${status}' == 'FAIL'    ${status}    Fail checking flows in operational DS    ${topology_discover_time}
149     Log To Console    Sleep for ${sustain_time} seconds
150     Sleep    ${sustain_time}
151     Log To Console    Deleting ${flow_count} flows
152     ${status}    ${result}    Run Keyword And Ignore Error    ScaleClient.Deconfigure Flows    flow_details=${flows}    controllers=${controller_list}    nrthreads=${nrthreads}
153     Return From Keyword If    '${status}' == 'FAIL'    ${status}    Fail deconfiguring flows    ${topology_discover_time}
154     Log To Console    Checking no flows in Mininet
155     ${status}    ${result}    Run Keyword And Ignore Error    MininetKeywords.Verify Aggregate Flow From Mininet Session    ${mininet_conn_id}    ${flows_before}    ${switches}
156     Return From Keyword If    '${status}' == 'FAIL'    ${status}    Fail checking no flows in mininet    ${topology_discover_time}
157     Log To Console    Checking no flows in Operational DS
158     ${status}    ${result}    Run Keyword And Ignore Error    Wait Until Keyword Succeeds    ${switches*4}    2s    FlowLib.Check Flows Operational Datastore
159     ...    ${flows_before}
160     Return From Keyword If    '${status}' == 'FAIL'    ${status}    Fail checking no flows in operational DS    ${topology_discover_time}
161     Log To Console    Stopping Mininet
162     ${status}    ${result}    Run Keyword And Ignore Error    MininetKeywords.Stop Mininet And Exit
163     Return From Keyword If    '${status}' == 'FAIL'    ${status}    Fail stopping mininet    ${topology_discover_time}
164     Log To Console    Checking No Switches
165     ${status}    ${result}    Run Keyword And Ignore Error    Wait Until Keyword Succeeds    10s    2s    FlowLib.Check No Switches In Inventory
166     ...    ${switches}
167     Return From Keyword If    '${status}' == 'FAIL'    ${status}    Fail checking no switch    ${topology_discover_time}
168     Log To Console    Checking No Topology
169     ${status}    ${result}    Run Keyword And Ignore Error    Wait Until Keyword Succeeds    10s    2s    FlowLib.Check No Switches In Topology
170     ...    ${switches}
171     Return From Keyword If    '${status}' == 'FAIL'    ${status}    Fail checking no topology    ${topology_discover_time}
172     [Return]    PASS    ${error_message}    ${topology_discover_time}
173
174 Workflow Setup
175     RequestsLibrary.Create Session    session    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}    headers=${HEADERS_XML}
176     Wait Until Keyword Succeeds    3x    1s    KarafKeywords.Issue Command On Karaf Console    log:set ERROR
177
178 Workflow Teardown
179     [Documentation]    Cleanup when workflow is interrupt
180     Run Keyword And Ignore Error    RequestsLibrary.Delete Request    session    ${CONFIG_NODES_API}
181     Utils.Clean Mininet System
182     RequestsLibrary.Delete All Sessions