2 Documentation Library to provide ovsdb access to mininet topologies
4 Library ${CURDIR}/VsctlListParser.py
8 ${SH_BR_CMD} ovs-vsctl list Bridge
9 ${SH_CNTL_CMD} ovs-vsctl list Controller
10 ${ovs_switch_data} ${None}
15 Initialize If Shell Used
16 [Arguments] ${prompt} ${cmd_prefix}
17 BuiltIn.Set Suite variable ${lprompt} ${prompt}
18 BuiltIn.Set Suite variable ${lcmd_prefix} ${cmd_prefix}
21 [Arguments] ${prompt}=mininet>
22 [Documentation] Gets ovs data and parse them.
23 SSHLibrary.Write ${lcmd_prefix} ${SH_BR_CMD}
24 ${brstdout}= SSHLibrary.Read_Until ${lprompt}
26 SSHLibrary.Write ${lcmd_prefix} ${SH_CNTL_CMD}
27 ${cntlstdout}= SSHLibrary.Read_Until ${lprompt}
29 ${data} ${bridegs} ${controllers}= VsctlListParser.Parse ${brstdout} ${cntlstdout}
31 BuiltIn.Set Suite Variable ${ovs_switch_data} ${data}
32 BuiltIn.Return From Keyword ${data}
35 [Arguments] ${switch} ${controller} ${update_data}=${False}
36 [Documentation] Returns controllers uuid
37 Run Keyword If ${update_data}==${True} Get Ovsdb Data
38 ${bridge}= Collections.Get From Dictionary ${ovs_switch_data} ${switch}
39 ${cntls}= Collections.Get From Dictionary ${bridge} controller
40 ${cntl}= Collections.Get From Dictionary ${cntls} ${controller}
41 ${uuid}= Collections.Get From Dictionary ${cntl} _uuid
42 BuiltIn.Return From Keyword ${uuid}
44 Execute OvsVsctl Show Command
45 [Documentation] Executes ovs-vsctl show command and returns stdout, no check nor change is performed
46 SSHLibrary.Write ${lcmd_prefix} ovs-vsctl show
47 ${output}= SSHLibrary.Read_Until ${lprompt}
50 Set Bridge Controllers
51 [Arguments] ${bridge} ${controllers} ${disconnected}=${False}
52 [Documentation] Adds controller to the bridge
53 ${cmd}= BuiltIn.Set Variable ${lcmd_prefix} ovs-vsctl set-controller ${bridge}
54 : FOR ${cntl} IN @{controllers}
55 \ ${cmd}= BuiltIn.Set Variable If ${disconnected}==${False} ${cmd} tcp:${cntl}:6653 ${cmd} tcp:${cntl}:6654
57 SSHLibrary.Write ${cmd}
58 ${output}= SSHLibrary.Read_Until ${lprompt}
61 Disconnect Switch From Controller And Verify Disconnected
62 [Arguments] ${switch} ${controller} ${update_data}=${False} ${verify_disconnected}=${True}
63 [Documentation] Disconnects the switch from the controller by setting the incorrect port
64 Run Keyword If ${update_data}==${True} Get Ovsdb Data
65 ${uuid}= Get Controllers Uuid ${switch} ${controller}
66 ${cmd}= BuiltIn.Set Variable ${lcmd_prefix} ovs-vsctl set Controller ${uuid} target="tcp\\:${controller}\\:6654"
67 SSHLibrary.Write ${cmd}
68 ${output}= SSHLibrary.Read_Until ${lprompt}
70 Return From Keyword If ${verify_disconnected}==${False}
71 BuiltIn.Wait Until Keyword Succeeds 5x 2s Should Be Disconnected ${switch} ${controller} update_data=${True}
72 [Teardown] Execute OvsVsctl Show Command
74 Reconnect Switch To Controller And Verify Connected
75 [Arguments] ${switch} ${controller} ${update_data}=${False} ${verify_connected}=${True}
76 [Documentation] Reconnects the switch back to the controller by setting the correct port
77 Run Keyword If ${update_data}==${True} Get Ovsdb Data
78 ${uuid}= Get Controllers Uuid ${switch} ${controller}
79 ${cmd}= BuiltIn.Set Variable ${lcmd_prefix} ovs-vsctl set Controller ${uuid} target="tcp\\:${controller}\\:6653"
80 SSHLibrary.Write ${cmd}
81 ${output}= SSHLibrary.Read_Until ${lprompt}
83 Return From Keyword If ${verify_connected}==${False}
84 BuiltIn.Wait Until Keyword Succeeds 5x 2s Should Be Connected ${switch} ${controller} update_data=${True}
85 [Teardown] Execute OvsVsctl Show Command
88 [Arguments] ${switch} ${controller} ${update_data}=${False}
89 [Documentation] Check if the switch is connected
90 ${connected}= OvsManager__Is_Connected ${switch} ${controller} update_data=${update_data}
91 BuiltIn.Should Be True ${connected}
93 Should Be Disconnected
94 [Arguments] ${switch} ${controller} ${update_data}=${False}
95 [Documentation] Check if the switch is disconnected
96 ${connected}= OvsManager__Is_Connected ${switch} ${controller} update_data=${update_data}
97 BuiltIn.Should Be Equal ${connected} ${False}
99 OvsManager__Is_Connected
100 [Arguments] ${switch} ${controller} ${update_data}=${False}
101 [Documentation] Return is_connected boolean value
102 Run Keyword If ${update_data}==${True} Get Ovsdb Data
103 ${bridge}= Collections.Get From Dictionary ${ovs_switch_data} ${switch}
104 ${cntls}= Collections.Get From Dictionary ${bridge} controller
105 ${cntl}= Collections.Get From Dictionary ${cntls} ${controller}
106 ${connected}= Collections.Get From Dictionary ${cntl} is_connected
107 [Teardown] Execute OvsVsctl Show Command
108 [Return] ${connected}
111 [Arguments] ${switch} ${controller} ${update_data}=${False}
112 [Documentation] Verifies the master role
113 ${role} Get Node Role ${switch} ${controller} update_data=${update_data}
114 BuiltIn.Should Be Equal ${role} master
117 [Arguments] ${switch} ${controller} ${update_data}=${False}
118 [Documentation] Verifies the slave role
119 ${role} Get Node Role ${switch} ${controller} update_data=${update_data}
120 BuiltIn.Should Be Equal ${role} slave
123 [Arguments] ${switch} ${controller} ${update_data}=${False}
124 [Documentation] Returns the controllers role
125 Run Keyword If ${update_data}==${True} Get Ovsdb Data
126 ${bridge}= Collections.Get From Dictionary ${ovs_switch_data} ${switch}
127 ${cntls}= Collections.Get From Dictionary ${bridge} controller
128 ${cntl}= Collections.Get From Dictionary ${cntls} ${controller}
129 ${role}= Collections.Get From Dictionary ${cntl} role
130 Return From Keyword ${role}
133 [Arguments] ${switch} ${update_data}=${False}
134 [Documentation] Gets controller which is a master
135 ${master}= BuiltIn.Set Variable ${None}
136 Run Keyword If ${update_data}==${True} Get Ovsdb Data
137 ${bridge}= Collections.Get From Dictionary ${ovs_switch_data} ${switch}
138 ${cntls_dict}= Collections.Get From Dictionary ${bridge} controller
139 ${cntls_items}= Collections.Get Dictionary Items ${cntls_dict}
140 : FOR ${key} ${value} IN @{cntls_items}
141 \ Log ${key} : ${value}
142 \ ${role}= Collections.Get From Dictionary ${value} role
143 \ Run Keyword If "${role}"=="master" BuiltIn.Should Be Equal ${master} ${None}
144 \ ${master}= BuiltIn.Set Variable If "${role}"=="master" ${key} ${master}
145 BuiltIn.Should Not Be Equal ${master} ${None}
146 Return From Keyword ${master}
149 [Arguments] ${switch} ${update_data}=${False}
150 [Documentation] Returns a list of ips of slave nodes for particular switch
151 ${slaves}= BuiltIn.Create List
152 Run Keyword If ${update_data}==${True} Get Ovsdb Data
153 ${bridge}= Collections.Get From Dictionary ${ovs_switch_data} ${switch}
154 ${cntls_dict}= Collections.Get From Dictionary ${bridge} controller
155 ${cntls_items}= Collections.Get Dictionary Items ${cntls_dict}
156 : FOR ${key} ${value} IN @{cntls_items}
157 \ Log ${key} : ${value}
158 \ ${role}= Collections.Get From Dictionary ${value} role
159 \ Run Keyword If "${role}"=="slave" Collections.Append To List ${slaves} ${key}
160 Return From Keyword ${slaves}
162 Setup Clustered Controller For Switches
163 [Arguments] ${switches} ${controller_ips} ${verify_connected}=${False}
164 [Documentation] The idea of this keyword is to setup clustered controller and to be more or less sure that the role is filled correctly. The problem is when
165 ... more controllers are being set up at once, the role shown in Controller ovsdb table is not the same as we can see from wireshark traces.
166 ... Now we set disconnected controllers and we will connect them expecting that the first connected controller will be master.
167 : FOR ${switch_name} IN @{switches}
168 \ Set Bridge Controllers ${switch_name} ${controller_ips} disconnected=${True}
169 # now we need to enable one node which will be master
170 OvsManager.Get Ovsdb Data
171 : FOR ${switch_name} IN @{switches}
172 \ ${own}= Collections.Get From List ${controller_ips} 0
173 \ Reconnect Switch To Controller And Verify Connected ${switch_name} ${own} verify_connected=${False}
174 # now we need to wait till master controllers are connected
175 BuiltIn.Wait Until Keyword Succeeds 5x 2s OvsManager__Verify_Masters_Connected ${switches} update_data=${True}
176 # now we can enable slaves
177 OvsManager__Enable_Slaves ${switches} verify_connected=${verify_connected}
179 OvsManager__Verify_Masters_Connected
180 [Arguments] ${switches} ${update_data}=${False}
181 [Documentation] Private keyword, the existence of master means it is verified
182 Run Keyword If ${update_data}==${True} Get Ovsdb Data
183 : FOR ${switch_name} IN @{switches}
184 \ Get Master Node ${switch_name}
186 OvsManager__Enable_Slaves
187 [Arguments] ${switches} ${update_data}=${False} ${verify_connected}=${False}
188 [Documentation] This is a private keyword to enable diconnected controllers
189 Run Keyword If ${update_data}==${True} Get Ovsdb Data
190 : FOR ${switch_name} IN @{switches}
191 \ OvsManager__Enable_Slaves_For_Switch ${switch_name} verify_connected=${verify_connected}
193 OvsManager__Enable_Slaves_For_Switch
194 [Arguments] ${switch} ${update_data}=${False} ${verify_connected}=${False}
195 [Documentation] This is a private keyword, verification is not reliable yet, enables disconnected controllers
196 Run Keyword If ${update_data}==${True} Get Ovsdb Data
197 ${bridge}= Collections.Get From Dictionary ${ovs_switch_data} ${switch}
198 ${cntls_dict}= Collections.Get From Dictionary ${bridge} controller
199 ${cntls_items}= Collections.Get Dictionary Items ${cntls_dict}
200 : FOR ${cntl_id} ${cntl_value} IN @{cntls_items}
201 \ Log ${cntl_id} : ${cntl_value}
202 \ ${role}= Collections.Get From Dictionary ${cntl_value} role
203 \ ${connected}= Collections.Get From Dictionary ${cntl_value} is_connected
204 \ Run Keyword If ${connected}==${False} Reconnect Switch To Controller And Verify Connected ${switch} ${cntl_id} verify_connected=${verify_connected}