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 Start Mininet Single Controller
11 [Arguments] ${mininet}=${TOOLS_SYSTEM_IP} ${controller}=${ODL_SYSTEM_IP} ${options}=--topo tree,1 --switch ovsk,protocols=OpenFlow13 ${custom}=${EMPTY} ${ofport}=${ODL_OF_PORT}
12 [Documentation] Start Mininet with custom topology and connect to controller.
13 Log Clear any existing mininet
14 Utils.Clean Mininet System ${mininet}
15 ${mininet_conn_id}= SSHLibrary.Open Connection ${mininet} prompt=${TOOLS_SYSTEM_PROMPT} timeout=${DEFAULT_TIMEOUT}
16 Set Suite Variable ${mininet_conn_id}
17 Utils.Flexible Mininet Login
18 Run Keyword If '${custom}' != '${EMPTY}' Put File ${custom}
19 Log Start mininet ${options} to ${controller}
20 SSHLibrary.Write sudo mn --controller 'remote,ip=${controller},port=${ofport}' ${options}
21 SSHLibrary.Read Until mininet>
22 ${output}= Utils.Run Command On Mininet ${mininet} sudo ovs-vsctl show
24 [Return] ${mininet_conn_id}
26 Start Mininet Multiple Controllers
27 [Arguments] ${mininet}=${TOOLS_SYSTEM_IP} ${controller_index_list}=${EMPTY} ${options}=--topo tree,1 --switch ovsk,protocols=OpenFlow13 ${custom}=${EMPTY} ${ofport}=${ODL_OF_PORT}
28 [Documentation] Start Mininet with custom topology and connect to list of controllers in ${controller_index_list} or all if no list is provided.
29 ${index_list} = ClusterManagement__Given_Or_Internal_Index_List given_list=${controller_index_list}
30 Log Clear any existing mininet
31 Utils.Clean Mininet System ${mininet}
32 ${mininet_conn_id}= SSHLibrary.Open Connection ${mininet} prompt=${TOOLS_SYSTEM_PROMPT} timeout=${DEFAULT_TIMEOUT}
33 Set Suite Variable ${mininet_conn_id}
34 Utils.Flexible Mininet Login
35 Run Keyword If '${custom}' != '${EMPTY}' Put File ${custom}
36 Log Start mininet ${options}
37 SSHLibrary.Write sudo mn ${options}
38 SSHLibrary.Read Until mininet>
39 Log Create controller configuration
40 ${controller_opt}= Set Variable
41 : FOR ${index} IN @{index_list}
42 \ ${controller_opt}= Catenate ${controller_opt} ${SPACE}tcp:${ODL_SYSTEM_${index}_IP}:${ofport}
43 \ Log ${controller_opt}
44 Log Find Number of OVS bridges
45 ${num_bridges} Utils.Run Command On Mininet ${mininet} sudo ovs-vsctl show | grep Bridge | wc -l
46 ${num_bridges}= Convert To Integer ${num_bridges}
47 Log Configure OVS controllers ${controller_opt} in all bridges
48 : FOR ${i} IN RANGE 1 ${num_bridges+1}
49 \ ${bridge}= Utils.Run Command On Mininet ${mininet} sudo ovs-vsctl show | grep Bridge | cut -c 12- | sort | head -${i} | tail -1
50 \ OVSDB.Set Controller In OVS Bridge ${mininet} ${bridge} ${controller_opt}
51 Log Check OVS configuratiom
52 ${output}= Utils.Run Command On Mininet ${mininet} sudo ovs-vsctl show
54 [Return] ${mininet_conn_id}
57 [Arguments] ${mininet_conn}=${EMPTY} ${cmd}=help
58 [Documentation] Sends Command ${cmd} to Mininet session ${mininet_conn} and returns read buffer response.
59 Run Keyword If """${mininet_conn}""" != "" SSHLibrary.Switch Connection ${mininet_conn}
60 SSHLibrary.Write ${cmd}
61 ${output}= SSHLibrary.Read Until mininet>
64 Send Mininet Command Multiple Sessions
65 [Arguments] ${mininet_conn_list} ${cmd}=help
66 [Documentation] Sends Command ${cmd} to Mininet sessions in ${mininet_conn_list} and returns list of read buffer responses.
67 ${output_list}= Create List
68 : FOR ${mininet_conn} IN @{mininet_conn_list}
69 \ ${output}= Utils.Send Mininet Command ${mininet_conn} ${cmd}
70 \ Append To List ${output_list} ${output}
71 [Return] ${output_list}
74 [Arguments] ${mininet_conn}=${EMPTY}
75 [Documentation] Stops Mininet and exits session ${mininet_conn}
76 Run Keyword If """${mininet_conn}""" != "" SSHLibrary.Switch Connection ${mininet_conn}
78 SSHLibrary.Read Until ${TOOLS_SYSTEM_PROMPT}
81 Stop Mininet And Exit Multiple Sessions
82 [Arguments] ${mininet_conn_list}
83 [Documentation] Stops Mininet and exits sessions in ${mininet_conn_list}.
84 : FOR ${mininet_conn} IN @{mininet_conn_list}
85 \ MininetKeywords.Stop Mininet And Exit ${mininet_conn}
87 Verify Aggregate Flow From Mininet Session
88 [Arguments] ${mininet_conn}=${EMPTY} ${flow_count}=0 ${time_out}=0s
89 [Documentation] Verify flow count per switch
90 Wait Until Keyword Succeeds ${time_out} 2s MininetKeywords.Mininet Sync Status ${mininet_conn} ${flow_count}
93 [Arguments] ${mininet_conn}=${EMPTY} ${flow_count}=0
94 [Documentation] Sync with mininet to match exact number of flows
95 ${cmd} = Set Variable dpctl dump-aggregate -O OpenFlow13
96 ${output}= MininetKeywords.Send Mininet Command ${mininet_conn} ${cmd}
97 ${flows}= String.Get RegExp Matches ${output} (?<=flow_count\=).*?(?=\r)
98 ${total_flows}= BuiltIn.Evaluate sum(map(int, ${flows}))
99 Should Be Equal As Numbers ${total_flows} ${flow_count}