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