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