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} ${ofversion}=13 ${disconnected}=${False}
52 [Documentation] Adds controller to the bridge
53 ${cmd}= BuiltIn.Set Variable ${lcmd_prefix} ovs-vsctl set bridge ${bridge} protocols=OpenFlow${ofversion}
54 SSHLibrary.Write ${cmd}
55 ${output}= SSHLibrary.Read_Until ${lprompt}
57 ${cmd}= BuiltIn.Set Variable ${lcmd_prefix} ovs-vsctl set-controller ${bridge}
58 : FOR ${cntl} IN @{controllers}
59 \ ${cmd}= BuiltIn.Set Variable If ${disconnected}==${False} ${cmd} tcp:${cntl}:6653 ${cmd} tcp:${cntl}:6654
61 SSHLibrary.Write ${cmd}
62 ${output}= SSHLibrary.Read_Until ${lprompt}
65 Disconnect Switch From Controller And Verify Disconnected
66 [Arguments] ${switch} ${controller} ${update_data}=${False} ${verify_disconnected}=${True}
67 [Documentation] Disconnects the switch from the controller by setting the incorrect port
68 Run Keyword If ${update_data}==${True} Get Ovsdb Data
69 ${uuid}= Get Controllers Uuid ${switch} ${controller}
70 ${cmd}= BuiltIn.Set Variable ${lcmd_prefix} ovs-vsctl set Controller ${uuid} target="tcp\\:${controller}\\:6654"
71 SSHLibrary.Write ${cmd}
72 ${output}= SSHLibrary.Read_Until ${lprompt}
74 Return From Keyword If ${verify_disconnected}==${False}
75 BuiltIn.Wait Until Keyword Succeeds 5x 2s Should Be Disconnected ${switch} ${controller} update_data=${True}
76 [Teardown] Execute OvsVsctl Show Command
78 Reconnect Switch To Controller And Verify Connected
79 [Arguments] ${switch} ${controller} ${update_data}=${False} ${verify_connected}=${True}
80 [Documentation] Reconnects the switch back to the controller by setting the correct port
81 Run Keyword If ${update_data}==${True} Get Ovsdb Data
82 ${uuid}= Get Controllers Uuid ${switch} ${controller}
83 ${cmd}= BuiltIn.Set Variable ${lcmd_prefix} ovs-vsctl set Controller ${uuid} target="tcp\\:${controller}\\:6653"
84 SSHLibrary.Write ${cmd}
85 ${output}= SSHLibrary.Read_Until ${lprompt}
87 Return From Keyword If ${verify_connected}==${False}
88 BuiltIn.Wait Until Keyword Succeeds 5x 2s Should Be Connected ${switch} ${controller} update_data=${True}
89 [Teardown] Execute OvsVsctl Show Command
92 [Arguments] ${switch} ${controller} ${update_data}=${False}
93 [Documentation] Check if the switch is connected
94 ${connected}= OvsManager__Is_Connected ${switch} ${controller} update_data=${update_data}
95 BuiltIn.Should Be True ${connected}
97 Should Be Disconnected
98 [Arguments] ${switch} ${controller} ${update_data}=${False}
99 [Documentation] Check if the switch is disconnected
100 ${connected}= OvsManager__Is_Connected ${switch} ${controller} update_data=${update_data}
101 BuiltIn.Should Be Equal ${connected} ${False}
103 OvsManager__Is_Connected
104 [Arguments] ${switch} ${controller} ${update_data}=${False}
105 [Documentation] Return is_connected boolean value
106 Run Keyword If ${update_data}==${True} Get Ovsdb Data
107 ${bridge}= Collections.Get From Dictionary ${ovs_switch_data} ${switch}
108 ${cntls}= Collections.Get From Dictionary ${bridge} controller
109 ${cntl}= Collections.Get From Dictionary ${cntls} ${controller}
110 ${connected}= Collections.Get From Dictionary ${cntl} is_connected
111 [Teardown] Execute OvsVsctl Show Command
112 [Return] ${connected}
115 [Arguments] ${switch} ${controller} ${update_data}=${False}
116 [Documentation] Verifies the master role
117 ${role} Get Node Role ${switch} ${controller} update_data=${update_data}
118 BuiltIn.Should Be Equal ${role} master
121 [Arguments] ${switch} ${controller} ${update_data}=${False}
122 [Documentation] Verifies the slave role
123 ${role} Get Node Role ${switch} ${controller} update_data=${update_data}
124 BuiltIn.Should Be Equal ${role} slave
127 [Arguments] ${switch} ${controller} ${update_data}=${False}
128 [Documentation] Returns the controllers role
129 Run Keyword If ${update_data}==${True} Get Ovsdb Data
130 ${bridge}= Collections.Get From Dictionary ${ovs_switch_data} ${switch}
131 ${cntls}= Collections.Get From Dictionary ${bridge} controller
132 ${cntl}= Collections.Get From Dictionary ${cntls} ${controller}
133 ${role}= Collections.Get From Dictionary ${cntl} role
134 Return From Keyword ${role}
137 [Arguments] ${switch} ${update_data}=${False}
138 [Documentation] Gets controller which is a master
139 ${master}= BuiltIn.Set Variable ${None}
140 Run Keyword If ${update_data}==${True} Get Ovsdb Data
141 ${bridge}= Collections.Get From Dictionary ${ovs_switch_data} ${switch}
142 ${cntls_dict}= Collections.Get From Dictionary ${bridge} controller
143 ${cntls_items}= Collections.Get Dictionary Items ${cntls_dict}
144 : FOR ${key} ${value} IN @{cntls_items}
145 \ Log ${key} : ${value}
146 \ ${role}= Collections.Get From Dictionary ${value} role
147 \ Run Keyword If "${role}"=="master" BuiltIn.Should Be Equal ${master} ${None}
148 \ ${master}= BuiltIn.Set Variable If "${role}"=="master" ${key} ${master}
149 BuiltIn.Should Not Be Equal ${master} ${None}
150 Return From Keyword ${master}
153 [Arguments] ${switch} ${update_data}=${False}
154 [Documentation] Returns a list of ips of slave nodes for particular switch
155 ${slaves}= BuiltIn.Create List
156 Run Keyword If ${update_data}==${True} Get Ovsdb Data
157 ${bridge}= Collections.Get From Dictionary ${ovs_switch_data} ${switch}
158 ${cntls_dict}= Collections.Get From Dictionary ${bridge} controller
159 ${cntls_items}= Collections.Get Dictionary Items ${cntls_dict}
160 : FOR ${key} ${value} IN @{cntls_items}
161 \ Log ${key} : ${value}
162 \ ${role}= Collections.Get From Dictionary ${value} role
163 \ Run Keyword If "${role}"=="slave" Collections.Append To List ${slaves} ${key}
164 Return From Keyword ${slaves}
166 Setup Clustered Controller For Switches
167 [Arguments] ${switches} ${controller_ips} ${verify_connected}=${False}
168 [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
169 ... 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.
170 ... Now we set disconnected controllers and we will connect them expecting that the first connected controller will be master.
171 : FOR ${switch_name} IN @{switches}
172 \ Set Bridge Controllers ${switch_name} ${controller_ips} disconnected=${True}
173 # now we need to enable one node which will be master
174 OvsManager.Get Ovsdb Data
175 : FOR ${switch_name} IN @{switches}
176 \ ${own}= Collections.Get From List ${controller_ips} 0
177 \ Reconnect Switch To Controller And Verify Connected ${switch_name} ${own} verify_connected=${False}
178 # now we need to wait till master controllers are connected
179 BuiltIn.Wait Until Keyword Succeeds 5x 2s OvsManager__Verify_Masters_Connected ${switches} update_data=${True}
180 # now we can enable slaves
181 OvsManager__Enable_Slaves ${switches} verify_connected=${verify_connected}
183 OvsManager__Verify_Masters_Connected
184 [Arguments] ${switches} ${update_data}=${False}
185 [Documentation] Private keyword, the existence of master means it is verified
186 Run Keyword If ${update_data}==${True} Get Ovsdb Data
187 : FOR ${switch_name} IN @{switches}
188 \ Get Master Node ${switch_name}
190 OvsManager__Enable_Slaves
191 [Arguments] ${switches} ${update_data}=${False} ${verify_connected}=${False}
192 [Documentation] This is a private keyword to enable diconnected controllers
193 Run Keyword If ${update_data}==${True} Get Ovsdb Data
194 : FOR ${switch_name} IN @{switches}
195 \ OvsManager__Enable_Slaves_For_Switch ${switch_name} verify_connected=${verify_connected}
197 OvsManager__Enable_Slaves_For_Switch
198 [Arguments] ${switch} ${update_data}=${False} ${verify_connected}=${False}
199 [Documentation] This is a private keyword, verification is not reliable yet, enables disconnected controllers
200 Run Keyword If ${update_data}==${True} Get Ovsdb Data
201 ${bridge}= Collections.Get From Dictionary ${ovs_switch_data} ${switch}
202 ${cntls_dict}= Collections.Get From Dictionary ${bridge} controller
203 ${cntls_items}= Collections.Get Dictionary Items ${cntls_dict}
204 : FOR ${cntl_id} ${cntl_value} IN @{cntls_items}
205 \ Log ${cntl_id} : ${cntl_value}
206 \ ${role}= Collections.Get From Dictionary ${cntl_value} role
207 \ ${connected}= Collections.Get From Dictionary ${cntl_value} is_connected
208 \ Run Keyword If ${connected}==${False} Reconnect Switch To Controller And Verify Connected ${switch} ${cntl_id} verify_connected=${verify_connected}