Replace deprecated variables in csit/libraries (2).
[integration/test.git] / csit / libraries / Scalability.robot
1 *** Settings ***
2 Library           SSHLibrary
3 Resource          Utils.robot
4 Library           String
5 Library           Collections
6 Variables         ../variables/Variables.py
7 Library           RequestsLibrary
8 Library           SwitchClasses/BaseSwitch.py
9
10 *** Keywords ***
11 Find Max Switches
12     [Arguments]    ${start}    ${stop}    ${step}
13     [Documentation]    Will find out max switches starting from ${start} till reaching ${stop} and in steps defined by ${step}
14     ${max-switches}    Set Variable    ${0}
15     Set Suite Variable    ${max-switches}
16     ${start}    Convert to Integer    ${start}
17     ${stop}    Convert to Integer    ${stop}
18     ${step}    Convert to Integer    ${step}
19     : FOR    ${switches}    IN RANGE    ${start}    ${stop+1}    ${step}
20     \    ${status}    ${result}    Run Keyword And Ignore Error    Start Mininet Linear    ${switches}
21     \    Exit For Loop If    '${status}' == 'FAIL'
22     \    ${status}    ${result}    Run Keyword And Ignore Error    Verify Controller Is Not Dead    ${ODL_SYSTEM_IP}
23     \    Exit For Loop If    '${status}' == 'FAIL'
24     \    ${status}    ${result}    Run Keyword And Ignore Error    Wait Until Keyword Succeeds    ${switches*2}    10s
25     \    ...    Check Every Switch    ${switches}
26     \    Exit For Loop If    '${status}' == 'FAIL'
27     \    ${status}    ${result}    Run Keyword And Ignore Error    Wait Until Keyword Succeeds    ${switches*2}    10s
28     \    ...    Check Linear Topology    ${switches}
29     \    Exit For Loop If    '${status}' == 'FAIL'
30     \    ${status}    ${result}    Run Keyword And Ignore Error    Stop Mininet Simulation
31     \    Exit For Loop If    '${status}' == 'FAIL'
32     \    ${status}    ${result}    Run Keyword And Ignore Error    Wait Until Keyword Succeeds    ${switches*2}    10s
33     \    ...    Check No Switches    ${switches}
34     \    Exit For Loop If    '${status}' == 'FAIL'
35     \    ${status}    ${result}    Run Keyword And Ignore Error    Wait Until Keyword Succeeds    ${switches*2}    10s
36     \    ...    Check No Topology    ${switches}
37     \    Exit For Loop If    '${status}' == 'FAIL'
38     \    ${max-switches}    Convert To String    ${switches}
39     [Return]    ${max-switches}
40
41 Find Max Links
42     [Arguments]    ${begin}    ${stop}    ${step}
43     [Documentation]    Will find out max switches in fully mesh topology starting from ${start} till reaching ${stop} and in steps defined by ${step}
44     ${max_switches}    Set Variable    ${0}
45     ${stop}    Convert to Integer    ${stop}
46     ${step}    Convert to Integer    ${step}
47     : FOR    ${switches}    IN RANGE    ${begin}    ${stop+1}    ${step}
48     \    ${status}    ${result}    Run Keyword And Ignore Error    Start Mininet With Custom Topology    ${CREATE_FULLYMESH_TOPOLOGY_FILE}    ${switches}
49     \    ...    ${BASE_MAC_1}    ${BASE_IP_1}    ${0}    ${switches*20}
50     \    Exit For Loop If    '${status}' == 'FAIL'
51     \    ${status}    ${result}    Run Keyword And Ignore Error    Verify Controller Is Not Dead    ${ODL_SYSTEM_IP}
52     \    Exit For Loop If    '${status}' == 'FAIL'
53     \    ${status}    ${result}    Run Keyword And Ignore Error    Verify Controller Has No Null Pointer Exceptions    ${ODL_SYSTEM_IP}
54     \    Exit For Loop If    '${status}' == 'FAIL'
55     \    ${status}    ${result}    Run Keyword And Ignore Error    Wait Until Keyword Succeeds    120    10s
56     \    ...    Check Every Switch    ${switches}    ${BASE_MAC_1}
57     \    Exit For Loop If    '${status}' == 'FAIL'
58     \    ${max-links}=    Evaluate    ${switches}*${switches-1}
59     \    ${status}    ${result}    Run Keyword And Ignore Error    Wait Until Keyword Succeeds    120    10s
60     \    ...    Check Number Of Links    ${max-links}
61     \    Exit For Loop If    '${status}' == 'FAIL'
62     \    ${status}    ${result}    Run Keyword And Ignore Error    Stop Mininet Simulation
63     \    Exit For Loop If    '${status}' == 'FAIL'
64     \    ${status}    ${result}    Run Keyword And Ignore Error    Wait Until Keyword Succeeds    120    10s
65     \    ...    Check No Switches    ${switches}
66     \    Exit For Loop If    '${status}' == 'FAIL'
67     \    ${status}    ${result}    Run Keyword And Ignore Error    Wait Until Keyword Succeeds    120    10s
68     \    ...    Check No Topology    ${switches}
69     \    Exit For Loop If    '${status}' == 'FAIL'
70     \    ${max_switches}    Set Variable    ${switches}
71     ${max-links}=    Evaluate    ${max_switches}*${max_switches-1}
72     [Return]    ${max-links}
73
74 Find Max Hosts
75     [Arguments]    ${begin}    ${stop}    ${step}
76     [Documentation]    Will find out max hosts starting from ${begin} till reaching ${stop} and in steps defined by ${step}
77     ${max-hosts}    Set Variable    ${0}
78     ${stop}    Convert to Integer    ${stop}
79     ${step}    Convert to Integer    ${step}
80     : FOR    ${hosts}    IN RANGE    ${begin}    ${stop+1}    ${step}
81     \    ${status}    ${result}    Run Keyword And Ignore Error    Start Mininet With One Switch And ${hosts} hosts
82     \    Exit For Loop If    '${status}' == 'FAIL'
83     \    ${status}    ${result}    Run Keyword And Ignore Error    Wait Until Keyword Succeeds    120s    30s
84     \    ...    Check Every Switch    ${1}
85     \    Exit For Loop If    '${status}' == 'FAIL'
86     \    @{host_list}=    Get Mininet Hosts
87     \    ${status}=    Ping All Hosts    @{host_list}
88     \    Exit For Loop If    ${status} != ${0}
89     \    ${status}    ${result}    Run Keyword And Ignore Error    Verify Controller Is Not Dead    ${ODL_SYSTEM_IP}
90     \    Exit For Loop If    '${status}' == 'FAIL'
91     \    ${status}    ${result}    Run Keyword And Ignore Error    Wait Until Keyword Succeeds    120s    30s
92     \    ...    Check Number Of Hosts    ${hosts}
93     \    Exit For Loop If    '${status}' == 'FAIL'
94     \    ${status}    ${result}    Run Keyword And Ignore Error    Stop Mininet Simulation
95     \    Exit For Loop If    '${status}' == 'FAIL'
96     \    ${status}    ${result}    Run Keyword And Ignore Error    Check No Switches    ${1}
97     \    Exit For Loop If    '${status}' == 'FAIL'
98     \    ${status}    ${result}    Run Keyword And Ignore Error    Check No Hosts
99     \    Exit For Loop If    '${status}' == 'FAIL'
100     \    ${max-hosts}    Convert To String    ${hosts}
101     [Return]    ${max-hosts}
102
103 Get Mininet Hosts
104     [Documentation]    Get all the hosts from mininet
105     ${host_list}=    Create List
106     Write    nodes
107     ${out}=    Read Until    mininet>
108     @{words}=    Split String    ${out}    ${SPACE}
109     : FOR    ${item}    IN    @{words}
110     \    ${h}=    Get Lines Matching Regexp    ${item.rstrip()}    .*h[0-9]*s.
111     \    Run Keyword If    '${h}' != '${EMPTY}'    Append To List    ${host_list}    ${h}
112     [Return]    ${host_list}
113
114 Ping All Hosts
115     [Arguments]    @{host_list}
116     [Documentation]    Do one round of ping from one host to all other hosts in mininet
117     ${source}=    Get From List    ${host_list}    ${0}
118     : FOR    ${h}    IN    @{host_list}
119     \    ${status}=    Ping Two Hosts    ${source}    ${h}    1
120     \    Exit For Loop If    ${status}!=${0}
121     [Return]    ${status}
122
123 Start Mininet With One Switch And ${hosts} hosts
124     [Documentation]    Start mininet with one switch and ${hosts} hosts
125     Log    Starting mininet with one switch and ${hosts} hosts
126     Log To Console    Starting mininet with one switch and ${hosts} hosts
127     ${mininet_conn_id}=    Open Connection    ${TOOLS_SYSTEM_IP}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=${hosts*3}
128     Set Suite Variable    ${mininet_conn_id}
129     Login With Public Key    ${TOOLS_SYSTEM_USER}    ${USER_HOME}/.ssh/${SSH_KEY}    any
130     Write    sudo mn --controller=remote,ip=${ODL_SYSTEM_IP} --topo linear,1,${hosts} --switch ovsk,protocols=OpenFlow13
131     Read Until    mininet>
132
133 Check Number Of Hosts
134     [Arguments]    ${hosts}
135     [Documentation]    Check number of hosts in inventory
136     ${resp}=    RequestsLibrary.Get Request    session    ${OPERATIONAL_TOPO_API}
137     Log    Check number of hosts in inventory
138     Log To Console    Check number of hosts in inventory
139     Should Be Equal As Strings    ${resp.status_code}    200
140     ${count}=    Get Count    ${resp.content}    "node-id":"host:
141     Should Be Equal As Integers    ${count}    ${hosts}
142
143 Check Number Of Links
144     [Arguments]    ${links}
145     [Documentation]    Check number of links in inventory is ${links}
146     ${resp}=    RequestsLibrary.Get Request    session    ${OPERATIONAL_TOPO_API}
147     Log    Check number of links in inventory is ${links}
148     Log To Console    Check number of links in inventory is ${links}
149     Should Be Equal As Strings    ${resp.status_code}    200
150     ${count}=    Get Count    ${resp.content}    "link-id":"openflow:
151     Should Be Equal As Integers    ${count}    ${links}
152
153 Ping Two Hosts
154     [Arguments]    ${host1}    ${host2}    ${pingcount}=2    ${connection_index}=${EMPTY}    ${connection_alias}=${EMPTY}
155     [Documentation]    Ping between mininet hosts. Must be used only after a mininet session is in place.Returns non zero value if there is 100% packet loss.
156     Run Keyword If    '${connection_index}'    !=    '${EMPTY}'    Switch Connection    ${connection_index}
157     Run Keyword If    '${connection_alias}'    !=    '${EMPTY}'    Switch Connection    ${connection_alias}
158     Write    ${host1} ping -c ${pingcount} ${host2}
159     ${out}=    Read Until    mininet>
160     ${ret}=    Get Lines Matching Regexp    ${out}    .*100% packet loss.*
161     ${len}=    Get Length    ${ret}
162     [Return]    ${len}
163
164 Check No Hosts
165     [Documentation]    Check if all hosts are deleted from inventory
166     ${resp}=    RequestsLibrary.Get Request    session    ${OPERATIONAL_TOPO_API}
167     Log To Console    Checking no hosts are present in operational database
168     Log    Checking no hosts are present in operational database
169     Should Be Equal As Strings    ${resp.status_code}    200
170     Should Not Contain    ${resp.content}    "node-id":"host:
171
172 Start Mininet Linear
173     [Arguments]    ${switches}
174     [Documentation]    Start mininet linear topology with ${switches} nodes
175     Log To Console    Starting mininet linear ${switches}
176     ${mininet_conn_id}=    Open Connection    ${TOOLS_SYSTEM_IP}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=${switches*3}
177     Set Suite Variable    ${mininet_conn_id}
178     Login With Public Key    ${TOOLS_SYSTEM_USER}    ${USER_HOME}/.ssh/${SSH_KEY}    any
179     Write    sudo mn --controller=remote,ip=${ODL_SYSTEM_IP} --topo linear,${switches} --switch ovsk,protocols=OpenFlow13
180     Read Until    mininet>
181     Sleep    6
182
183 Start Mininet With Custom Topology
184     [Arguments]    ${topology_file}    ${switches}    ${base_mac}=00:00:00:00:00:00    ${base_ip}=1.1.1.1    ${hosts}=0    ${mininet_start_time}=100
185     [Documentation]    Start a custom mininet topology.
186     Log To Console    Start a custom mininet topology with ${switches} nodes
187     ${mininet_conn_id}=    Open Connection    ${TOOLS_SYSTEM_IP}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=${mininet_start_time}
188     Set Suite Variable    ${mininet_conn_id}
189     Login With Public Key    ${TOOLS_SYSTEM_USER}    ${USER_HOME}/.ssh/${SSH_KEY}    any
190     Write    python ${topology_file} ${switches} ${hosts} ${base_mac} ${base_ip}
191     Read Until    ${DEFAULT_LINUX_PROMPT}
192     Write    sudo mn --controller=remote,ip=${ODL_SYSTEM_IP} --custom switch.py --topo demotopo --switch ovsk,protocols=OpenFlow13
193     Read Until    mininet>
194     Write    sh ovs-vsctl show
195     ${output}=    Read Until    mininet>
196     # Ovsdb connection is sometimes lost after mininet is started. Checking if the connection is alive before proceeding.
197     Should Not Contain    ${output}    database connection failed
198     Log To Console    Mininet Started with ${switches} nodes
199
200 Check Every Switch
201     [Arguments]    ${switches}    ${base_mac}=00:00:00:00:00:00
202     [Documentation]    Check all switches and stats in operational inventory
203     ${mac}=    Replace String Using Regexp    ${base_mac}    :    ${EMPTY}
204     ${mac}=    Convert Hex To Decimal As String    ${mac}
205     ${mac}=    Convert To Integer    ${mac}
206     : FOR    ${switch}    IN RANGE    1    ${switches+1}
207     \    ${dpid_decimal}=    Evaluate    ${mac}+${switch}
208     \    ${resp}    RequestsLibrary.Get Request    session    ${OPERATIONAL_NODES_API}/node/openflow:${dpid_decimal}
209     \    Should Be Equal As Strings    ${resp.status_code}    200
210     \    Log To Console    Checking Switch ${switch}
211     \    Should Contain    ${resp.content}    flow-capable-node-connector-statistics
212     \    Should Contain    ${resp.content}    flow-table-statistics
213
214 Check Linear Topology
215     [Arguments]    ${switches}
216     [Documentation]    Check Linear topology given ${switches}
217     ${resp}    RequestsLibrary.Get Request    session    ${OPERATIONAL_TOPO_API}
218     Log To Console    Checking Topology
219     Should Be Equal As Strings    ${resp.status_code}    200
220     : FOR    ${switch}    IN RANGE    1    ${switches+1}
221     \    Should Contain    ${resp.content}    "node-id":"openflow:${switch}"
222     \    Should Contain    ${resp.content}    "tp-id":"openflow:${switch}:1"
223     \    Should Contain    ${resp.content}    "tp-id":"openflow:${switch}:2"
224     \    Should Contain    ${resp.content}    "source-tp":"openflow:${switch}:2"
225     \    Should Contain    ${resp.content}    "dest-tp":"openflow:${switch}:2"
226     \    ${edge}    Evaluate    ${switch}==1 or ${switch}==${switches}
227     \    Run Keyword Unless    ${edge}    Should Contain    ${resp.content}    "tp-id":"openflow:${switch}:3"
228     \    Run Keyword Unless    ${edge}    Should Contain    ${resp.content}    "source-tp":"openflow:${switch}:3"
229     \    Run Keyword Unless    ${edge}    Should Contain    ${resp.content}    "dest-tp":"openflow:${switch}:3"
230
231 Check No Switches
232     [Arguments]    ${switches}
233     [Documentation]    Check no switch is in inventory
234     ${resp}    RequestsLibrary.Get Request    session    ${OPERATIONAL_NODES_API}
235     Log To Console    Checking No Switches
236     Should Be Equal As Strings    ${resp.status_code}    200
237     : FOR    ${switch}    IN RANGE    1    ${switches+1}
238     \    Should Not Contain    ${resp.content}    openflow:${switch}
239
240 Check No Topology
241     [Arguments]    ${switches}
242     [Documentation]    Check no switch is in topology
243     ${resp}    RequestsLibrary.Get Request    session    ${OPERATIONAL_TOPO_API}
244     Log To Console    Checking No Topology
245     Should Be Equal As Strings    ${resp.status_code}    200
246     : FOR    ${switch}    IN RANGE    1    ${switches+1}
247     \    Should Not Contain    ${resp.content}    openflow:${switch}
248
249 Stop Mininet Simulation
250     [Documentation]    Stop mininet
251     Log To Console    Stopping Mininet
252     Switch Connection    ${mininet_conn_id}
253     Read
254     Write    exit
255     Read Until    ${DEFAULT_LINUX_PROMPT}
256     Close Connection
257
258 Scalability Suite Teardown
259     Delete All Sessions
260     Clean Mininet System