2 Documentation Mininet library. This library is useful for tests using mininet tool to simulate devices.
4 Resource SSHKeywords.robot
7 Resource ClusterManagement.robot
8 Variables ../variables/Variables.py
11 ${topology_file} create_fullymesh.py
12 ${topology_file_path} MininetTopo/${topology_file}
15 Start Mininet Single Controller
16 [Arguments] ${mininet}=${TOOLS_SYSTEM_IP} ${controller}=${ODL_SYSTEM_IP} ${options}=--topo tree,1 ${custom}=${EMPTY} ${ofversion}=13 ${ofport}=${ODL_OF_PORT}
17 ... ${timeout}=${DEFAULT_TIMEOUT}
18 [Documentation] Start Mininet with custom topology and connect to controller.
19 Log Clear any existing mininet
20 Utils.Clean Mininet System ${mininet}
21 ${mininet_conn_id}= SSHLibrary.Open Connection ${mininet} prompt=${TOOLS_SYSTEM_PROMPT} timeout=${timeout}
22 Set Suite Variable ${mininet_conn_id}
23 SSHKeywords.Flexible Mininet Login
24 Run Keyword If '${custom}' != '${EMPTY}' Put File ${custom}
25 Log Start mininet ${options} to ${controller}
26 SSHLibrary.Write sudo mn --controller 'remote,ip=${controller},port=${ofport}' ${options} --switch ovsk,protocols=OpenFlow${ofversion}
27 SSHLibrary.Read Until mininet>
28 Log Check OVS configuratiom
29 SSHLibrary.Write sh ovs-vsctl show
30 SSHLibrary.Read Until mininet>
31 [Return] ${mininet_conn_id}
33 Start Mininet Multiple Controllers
34 [Arguments] ${mininet} ${controller_index_list}=${EMPTY} ${options}=--topo tree,1 ${custom}=${EMPTY} ${ofversion}=13 ${ofport}=${ODL_OF_PORT}
35 ... ${timeout}=${DEFAULT_TIMEOUT}
36 [Documentation] Start Mininet with custom topology and connect to list of controllers in ${controller_index_list} or all if no list is provided.
37 ${index_list} = ClusterManagement.List Indices Or All given_list=${controller_index_list}
38 Log Clear any existing mininet
39 Utils.Clean Mininet System ${mininet}
40 ${mininet_conn_id}= SSHLibrary.Open Connection ${mininet} prompt=${TOOLS_SYSTEM_PROMPT} timeout=${timeout}
41 Set Suite Variable ${mininet_conn_id}
42 SSHKeywords.Flexible Mininet Login
43 Run Keyword If '${custom}' != '${EMPTY}' Put File ${custom}
44 Log Start mininet ${options}
45 SSHLibrary.Write sudo mn ${options}
46 SSHLibrary.Read Until mininet>
47 Log Create controller configuration
48 ${controller_opt}= Set Variable
49 : FOR ${index} IN @{index_list}
50 \ ${controller_opt}= Catenate ${controller_opt} ${SPACE}tcp:${ODL_SYSTEM_${index}_IP}:${ofport}
51 \ Log ${controller_opt}
52 Log Find Number of OVS bridges
53 ${num_bridges} Utils.Run Command On Mininet ${mininet} sudo ovs-vsctl show | grep Bridge | wc -l
54 ${num_bridges}= Convert To Integer ${num_bridges}
55 Log Configure OVS controllers ${controller_opt} in all bridges
56 : FOR ${i} IN RANGE 1 ${num_bridges+1}
57 \ ${bridge}= Utils.Run Command On Mininet ${mininet} sudo ovs-vsctl show | grep Bridge | cut -c 12- | sort | head -${i} | tail -1
58 \ OVSDB.Set Controller In OVS Bridge ${mininet} ${bridge} ${controller_opt} ${ofversion}
59 Log Check OVS configuratiom
60 SSHLibrary.Write sh ovs-vsctl show
61 SSHLibrary.Read Until mininet>
62 [Return] ${mininet_conn_id}
64 Start Mininet Multiple Hosts
65 [Arguments] ${hosts} ${mininet}=${TOOLS_SYSTEM_IP} ${controller}=${ODL_SYSTEM_IP} ${ofversion}=13 ${ofport}=${ODL_OF_PORT} ${mininet_timeout}=${DEFAULT_TIMEOUT}
66 [Documentation] Start mininet 1 switch with ${hosts} hosts attached.
67 Log Start Mininet Linear
68 MininetKeywords.StartMininet Single Controller options=--topo single,${hosts} --mac ofversion=${ofversion} ofport=${ofport} timeout=${mininet_timeout}
71 [Arguments] ${switches} ${mininet}=${TOOLS_SYSTEM_IP} ${controller}=${ODL_SYSTEM_IP} ${ofversion}=13 ${ofport}=${ODL_OF_PORT} ${mininet_timeout}=${DEFAULT_TIMEOUT}
72 [Documentation] Start mininet linear topology with ${switches} nodes.
73 Log Start Mininet Linear
74 MininetKeywords.StartMininet Single Controller options=--topo linear,${switches} ofversion=${ofversion} ofport=${ofport} timeout=${mininet_timeout}
76 Start Mininet Full Mesh
77 [Arguments] ${switches} ${mininet}=${TOOLS_SYSTEM_IP} ${controller}=${ODL_SYSTEM_IP} ${ofversion}=13 ${ofport}=${ODL_OF_PORT} ${hosts}=0
78 ... ${mininet_timeout}=${DEFAULT_TIMEOUT}
79 [Documentation] Start a custom mininet topology.
80 ${mininet_conn_id}= SSHLibrary.Open Connection ${mininet} prompt=${TOOLS_SYSTEM_PROMPT} timeout=${mininet_timeout}
81 Set Suite Variable ${mininet_conn_id}
82 SSHKeywords.Flexible_Mininet_Login
83 Log Copying ${topology_file_path} file to Mininet VM and Creating Full Mesh topology
84 SSHLibrary.Put File ${CURDIR}/${topology_file_path}
85 SSHLibrary.Write python ${topology_file} ${switches} ${hosts} 00:00:00:00:00:00 10.0.0.0
86 SSHLibrary.Read Until ${TOOLS_SYSTEM_PROMPT}
87 Log Start Mininet Full Mesh
88 SSHLibrary.Write sudo mn --controller=remote,ip=${controller},port=${ofport} --custom switch.py --topo demotopo --switch ovsk,protocols=OpenFlow${ofversion}
89 SSHLibrary.Read Until mininet>
90 Log Check OVS configuratiom
91 SSHLibrary.Write sh ovs-vsctl show
92 ${output}= Read Until mininet>
93 # Ovsdb connection is sometimes lost after mininet is started. Checking if the connection is alive before proceeding.
94 Should Not Contain ${output} database connection failed
97 [Arguments] ${mininet_conn}=${EMPTY} ${cmd}=help
98 [Documentation] Sends Command ${cmd} to Mininet session ${mininet_conn} and returns read buffer response.
99 Run Keyword If """${mininet_conn}""" != "" SSHLibrary.Switch Connection ${mininet_conn}
100 SSHLibrary.Write ${cmd}
101 ${output}= SSHLibrary.Read Until mininet>
104 Send Mininet Command Multiple Sessions
105 [Arguments] ${mininet_conn_list} ${cmd}=help
106 [Documentation] Sends Command ${cmd} to Mininet sessions in ${mininet_conn_list} and returns list of read buffer responses.
107 ${output_list}= Create List
108 : FOR ${mininet_conn} IN @{mininet_conn_list}
109 \ ${output}= Utils.Send Mininet Command ${mininet_conn} ${cmd}
110 \ Append To List ${output_list} ${output}
111 [Return] ${output_list}
113 Stop Mininet And Exit
114 [Arguments] ${mininet_conn}=${EMPTY}
115 [Documentation] Stops Mininet and exits session ${mininet_conn}
116 Run Keyword If """${mininet_conn}""" != "" SSHLibrary.Switch Connection ${mininet_conn}
117 SSHLibrary.Write exit
118 SSHLibrary.Read Until ${TOOLS_SYSTEM_PROMPT}
119 SSHLibrary.Close Connection
121 Stop Mininet And Exit Multiple Sessions
122 [Arguments] ${mininet_conn_list}
123 [Documentation] Stops Mininet and exits sessions in ${mininet_conn_list}.
124 : FOR ${mininet_conn} IN @{mininet_conn_list}
125 \ MininetKeywords.Stop Mininet And Exit ${mininet_conn}
127 Disconnect Cluster Mininet
128 [Arguments] ${action}=break ${member_index_list}=${EMPTY}
129 [Documentation] Break and restore controller to mininet connection via iptables.
130 ${index_list} = ClusterManagement.List_Indices_Or_All given_list=${member_index_list}
131 : FOR ${index} IN @{index_list}
132 \ ${rule} = BuiltIn.Set Variable OUTPUT -p all --source ${ODL_SYSTEM_${index}_IP} --destination ${TOOLS_SYSTEM_IP} -j DROP
133 \ ${command} = BuiltIn.Set Variable If '${action}'=='restore' sudo /sbin/iptables -D ${rule} sudo /sbin/iptables -I ${rule}
134 \ Log To Console ${ODL_SYSTEM_${index}_IP}
135 \ Utils.Run Command On Controller ${ODL_SYSTEM_${index}_IP} cmd=${command}
136 \ ${command} = BuiltIn.Set Variable sudo /sbin/iptables -L -n
137 \ ${output} = Utils.Run Command On Controller cmd=${command}
138 \ BuiltIn.Log ${output}
140 Verify Aggregate Flow From Mininet Session
141 [Arguments] ${mininet_conn}=${EMPTY} ${flow_count}=0 ${time_out}=0s
142 [Documentation] Verify flow count per switch
143 Wait Until Keyword Succeeds ${time_out} 2s MininetKeywords.Check Flows In Mininet ${mininet_conn} ${flow_count}
145 Check Flows In Mininet
146 [Arguments] ${mininet_conn}=${EMPTY} ${flow_count}=0
147 [Documentation] Sync with mininet to match exact number of flows
148 Run Keyword If """${mininet_conn}""" != "" SSHLibrary.Switch Connection ${mininet_conn}
149 ${cmd} = Set Variable dpctl dump-aggregate -O OpenFlow13
150 ${output}= MininetKeywords.Send Mininet Command ${mininet_conn} ${cmd}
151 ${flows}= String.Get RegExp Matches ${output} (?<=flow_count\=).*?(?=\r)
152 ${total_flows}= BuiltIn.Evaluate sum(map(int, ${flows}))
153 Should Be Equal As Numbers ${total_flows} ${flow_count}
156 [Arguments] ${host1} ${host2}
157 [Documentation] Send ping from mininet and verify connectivity.
158 SSHLibrary.Write ${host1} ping -w 3 ${host2}
159 ${result}= SSHLibrary.Read Until mininet>
160 Should Contain ${result} 64 bytes
162 Verify Mininet No Ping
163 [Arguments] ${host1} ${host2}
164 [Documentation] Send ping from mininet and verify no conectivity.
165 SSHLibrary.Write ${host1} ping -w 3 ${host2}
166 ${result}= SSHLibrary.Read Until mininet>
167 Should Contain ${result} 100% packet loss
170 [Arguments] @{host_list}
171 [Documentation] Do one round of ping from one host to all other hosts in mininet.
172 ... Note that a single ping failure will exit the loop and return a non zero value.
173 ${source}= Get From List ${host_list} ${0}
174 : FOR ${h} IN @{host_list}
175 \ ${status}= Ping Two Hosts ${source} ${h} 1
176 \ Exit For Loop If ${status}!=${0}
180 [Arguments] ${host1} ${host2} ${pingcount}=2
181 [Documentation] Ping between mininet hosts. Must be used only after a mininet session is in place.
182 ... Returns non zero value if there is 100% packet loss.
183 SSHLibrary.Write ${host1} ping -c ${pingcount} ${host2}
184 ${out}= SSHLibrary.Read Until mininet>
185 ${ret}= String.Get Lines Matching Regexp ${out} .*100% packet loss.*
186 ${len}= Get Length ${ret}
190 [Documentation] Get all the hosts from mininet
191 ${host_list}= Create List
192 SSHLibrary.Write nodes
193 ${out}= SSHLibrary.Read Until mininet>
194 @{words}= String.Split String ${out} ${SPACE}
195 : FOR ${item} IN @{words}
196 \ ${h}= String.Get Lines Matching Regexp ${item} h[0-9]*
197 \ Run Keyword If '${h}' != '${EMPTY}' Append To List ${host_list} ${h}
198 [Return] ${host_list}