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