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