blob: 472d56a849e8f9bf8a06bb3cb090d363eeb68ff8 [file] [log] [blame]
Kailash6f5acb62019-08-28 14:38:45 -07001# Copyright 2017-present Open Networking Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
Kailash6f5acb62019-08-28 14:38:45 -070014# onos common functions
15
16*** Settings ***
17Documentation Library for various utilities
18Library SSHLibrary
Kailash6f5acb62019-08-28 14:38:45 -070019Library String
20Library DateTime
21Library Process
22Library Collections
23Library RequestsLibrary
24Library OperatingSystem
25
26*** Keywords ***
Kailash6f5acb62019-08-28 14:38:45 -070027Validate OLT Device in ONOS
Zack Williamsa8fe75a2020-01-10 14:25:27 -070028 # FIXME use volt-olts to check that the OLT is ONOS
Kailash6f5acb62019-08-28 14:38:45 -070029 [Arguments] ${serial_number}
Zack Williamsec53a1b2019-09-16 15:50:52 -070030 [Documentation] Checks if olt has been connected to ONOS
Kailash6f5acb62019-08-28 14:38:45 -070031 ${resp}= Get Request ONOS onos/v1/devices
32 ${jsondata}= To Json ${resp.content}
33 Should Not Be Empty ${jsondata['devices']}
34 ${length}= Get Length ${jsondata['devices']}
35 @{serial_numbers}= Create List
Andy Bavierb63f6d22020-03-12 15:34:37 -070036 ${matched}= Set Variable False
Zack Williamsec53a1b2019-09-16 15:50:52 -070037 FOR ${INDEX} IN RANGE 0 ${length}
38 ${value}= Get From List ${jsondata['devices']} ${INDEX}
39 ${of_id}= Get From Dictionary ${value} id
40 ${sn}= Get From Dictionary ${value} serial
Andy Bavierb63f6d22020-03-12 15:34:37 -070041 ${matched}= Set Variable If '${sn}' == '${serial_number}' True False
42 Exit For Loop If ${matched}
Zack Williamsec53a1b2019-09-16 15:50:52 -070043 END
Andy Bavierb63f6d22020-03-12 15:34:37 -070044 Should Be True ${matched} No match for ${serial_number} found
Kailash57210eb2019-08-30 13:27:19 -070045 [Return] ${of_id}
Kailash6f5acb62019-08-28 14:38:45 -070046
Suchitra Vemuri102912a2019-09-24 00:35:42 -070047Get ONU Port in ONOS
Zack Williamsec53a1b2019-09-16 15:50:52 -070048 [Arguments] ${onu_serial_number} ${olt_of_id}
Suchitra Vemuri102912a2019-09-24 00:35:42 -070049 [Documentation] Retrieves ONU port for the ONU in ONOS
Suchitra Vemuria50c1c12019-09-30 19:54:26 -070050 ${onu_serial_number}= Catenate SEPARATOR=- ${onu_serial_number} 1
Suchitra Vemuri102912a2019-09-24 00:35:42 -070051 ${resp}= Get Request ONOS onos/v1/devices/${olt_of_id}/ports
52 ${jsondata}= To Json ${resp.content}
53 Should Not Be Empty ${jsondata['ports']}
54 ${length}= Get Length ${jsondata['ports']}
55 @{ports}= Create List
Andy Bavierb63f6d22020-03-12 15:34:37 -070056 ${matched}= Set Variable False
Zack Williamsec53a1b2019-09-16 15:50:52 -070057 FOR ${INDEX} IN RANGE 0 ${length}
58 ${value}= Get From List ${jsondata['ports']} ${INDEX}
59 ${annotations}= Get From Dictionary ${value} annotations
60 ${onu_port}= Get From Dictionary ${value} port
61 ${portName}= Get From Dictionary ${annotations} portName
Andy Bavierb63f6d22020-03-12 15:34:37 -070062 ${matched}= Set Variable If '${portName}' == '${onu_serial_number}' True False
63 Exit For Loop If ${matched}
Zack Williamsec53a1b2019-09-16 15:50:52 -070064 END
Andy Bavierb63f6d22020-03-12 15:34:37 -070065 Should Be True ${matched} No match for ${onu_serial_number} found
Suchitra Vemuri102912a2019-09-24 00:35:42 -070066 [Return] ${onu_port}
67
Hardik Windlassfb5eace2020-03-26 14:49:01 +053068Get NNI Port in ONOS
69 [Arguments] ${olt_of_id}
70 [Documentation] Retrieves NNI port for the OLT in ONOS
71 ${resp}= Get Request ONOS onos/v1/devices/${olt_of_id}/ports
72 ${jsondata}= To Json ${resp.content}
73 Should Not Be Empty ${jsondata['ports']}
74 ${length}= Get Length ${jsondata['ports']}
75 @{ports}= Create List
76 ${matched}= Set Variable False
77 FOR ${INDEX} IN RANGE 0 ${length}
78 ${value}= Get From List ${jsondata['ports']} ${INDEX}
79 ${annotations}= Get From Dictionary ${value} annotations
80 ${nni_port}= Get From Dictionary ${value} port
81 ${nniPortName}= Catenate SEPARATOR= nni- ${nni_port}
82 ${portName}= Get From Dictionary ${annotations} portName
83 ${matched}= Set Variable If '${portName}' == '${nniPortName}' True False
84 Exit For Loop If ${matched}
85 END
86 Should Be True ${matched} No match for NNI found for ${olt_of_id}
87 [Return] ${nni_port}
88
Suchitra Vemuri532f67a2019-09-25 11:50:42 -070089Get FabricSwitch in ONOS
90 [Documentation] Returns of_id of the Fabric Switch in ONOS
91 ${resp}= Get Request ONOS onos/v1/devices
92 ${jsondata}= To Json ${resp.content}
93 Should Not Be Empty ${jsondata['devices']}
94 ${length}= Get Length ${jsondata['devices']}
Andy Bavierb63f6d22020-03-12 15:34:37 -070095 ${matched}= Set Variable False
Suchitra Vemuri532f67a2019-09-25 11:50:42 -070096 FOR ${INDEX} IN RANGE 0 ${length}
97 ${value}= Get From List ${jsondata['devices']} ${INDEX}
98 ${of_id}= Get From Dictionary ${value} id
99 ${type}= Get From Dictionary ${value} type
Andy Bavierb63f6d22020-03-12 15:34:37 -0700100 ${matched}= Set Variable If '${type}' == "SWITCH" True False
101 Exit For Loop If ${matched}
Suchitra Vemuri532f67a2019-09-25 11:50:42 -0700102 END
Andy Bavierb63f6d22020-03-12 15:34:37 -0700103 Should Be True ${matched} No fabric switch found
Suchitra Vemuri532f67a2019-09-25 11:50:42 -0700104 [Return] ${of_id}
105
Hardik Windlass21807632020-04-14 16:24:55 +0530106Verify Subscriber Access Flows Added for ONU
107 [Arguments] ${ip} ${port} ${olt_of_id} ${onu_port} ${nni_port} ${c_tag} ${s_tag}
108 [Documentation] Verifies if the Subscriber Access Flows are added in ONOS for the ONU
109 # Verify upstream table=0 flow
110 ${upstream_flow_0_cmd}= Catenate SEPARATOR=
111 ... flows -s ADDED ${olt_of_id} | grep IN_PORT:${onu_port} | grep VLAN_VID:0 |
112 ... grep VLAN_ID:${c_tag} | grep transition=TABLE:1
113 ${upstream_flow_0_added}= Execute ONOS CLI Command ${ip} ${port}
114 ... ${upstream_flow_0_cmd}
115 Should Not Be Empty ${upstream_flow_0_added}
116 # Verify upstream table=1 flow
117 ${flow_vlan_push_cmd}= Catenate SEPARATOR=
118 ... flows -s ADDED ${olt_of_id} | grep IN_PORT:${onu_port} | grep VLAN_VID:${c_tag} |
119 ... grep VLAN_PUSH | grep VLAN_ID:${s_tag} | grep OUTPUT:${nni_port}
120 ${upstream_flow_1_added}= Execute ONOS CLI Command ${ip} ${port}
121 ... ${flow_vlan_push_cmd}
122 Should Not Be Empty ${upstream_flow_1_added}
123 # Verify downstream table=0 flow
124 ${flow_vlan_pop_cmd}= Catenate SEPARATOR=
125 ... flows -s ADDED ${olt_of_id} | grep IN_PORT:${nni_port} | grep VLAN_VID:${s_tag} |
126 ... grep VLAN_POP | grep transition=TABLE:1
127 ${downstream_flow_0_added}= Execute ONOS CLI Command ${ip} ${port}
128 ... ${flow_vlan_pop_cmd}
129 Should Not Be Empty ${downstream_flow_0_added}
130 # Verify downstream table=1 flow
131 ${downstream_flow_1_cmd}= Catenate SEPARATOR=
132 ... flows -s ADDED ${olt_of_id} | grep IN_PORT:${nni_port} | grep VLAN_VID:${c_tag} |
133 ... grep VLAN_ID:0 | grep OUTPUT:${onu_port}
134 ${downstream_flow_1_added}= Execute ONOS CLI Command ${ip} ${port}
135 ... ${downstream_flow_1_cmd}
136 Should Not Be Empty ${downstream_flow_1_added}
137 # Verify ipv4 dhcp upstream flow
138 ${upstream_flow_ipv4_cmd}= Catenate SEPARATOR=
139 ... flows -s ADDED ${olt_of_id} | grep IN_PORT:${onu_port} | grep ETH_TYPE=ipv4 |
140 ... grep VLAN_VID:${c_tag} | grep OUTPUT:CONTROLLER
141 ${upstream_flow_ipv4_added}= Execute ONOS CLI Command ${ip} ${port}
142 ... ${upstream_flow_ipv4_cmd}
143 # Verify ipv4 dhcp downstream flow
144 # Note: This flow will be one per nni per olt
145 ${downstream_flow_ipv4_cmd}= Catenate SEPARATOR=
146 ... flows -s ADDED ${olt_of_id} | grep IN_PORT:${nni_port} | grep ETH_TYPE=ipv4 |
147 ... grep OUTPUT:CONTROLLER
148 ${downstream_flow_ipv4_added}= Execute ONOS CLI Command ${ip} ${port}
149 ... ${downstream_flow_ipv4_cmd}
150
Hardik Windlassfb5eace2020-03-26 14:49:01 +0530151Verify Subscriber Access Flows Added for ONU DT
Hardik Windlass25e11702020-03-30 20:05:19 +0530152 [Arguments] ${ip} ${port} ${olt_of_id} ${onu_port} ${nni_port} ${s_tag}
Hardik Windlassfb5eace2020-03-26 14:49:01 +0530153 [Documentation] Verifies if the Subscriber Access Flows are added in ONOS for the ONU
154 # Verify upstream table=0 flow
155 ${upstream_flow_0_added}= Execute ONOS CLI Command ${ip} ${port}
Hardik Windlass25e11702020-03-30 20:05:19 +0530156 ... flows -s ADDED ${olt_of_id} | grep IN_PORT:${onu_port} | grep VLAN_VID:Any | grep transition=TABLE:1
Hardik Windlassfb5eace2020-03-26 14:49:01 +0530157 Should Not Be Empty ${upstream_flow_0_added}
158 # Verify upstream table=1 flow
159 ${flow_vlan_push_cmd}= Catenate SEPARATOR=
Hardik Windlass25e11702020-03-30 20:05:19 +0530160 ... flows -s ADDED ${olt_of_id} | grep IN_PORT:${onu_port} | grep VLAN_VID:Any |
Hardik Windlassfb5eace2020-03-26 14:49:01 +0530161 ... grep VLAN_PUSH | grep VLAN_ID:${s_tag} | grep OUTPUT:${nni_port}
162 ${upstream_flow_1_added}= Execute ONOS CLI Command ${ip} ${port}
163 ... ${flow_vlan_push_cmd}
164 Should Not Be Empty ${upstream_flow_1_added}
165 # Verify downstream table=0 flow
166 ${flow_vlan_pop_cmd}= Catenate SEPARATOR=
Hardik Windlass25e11702020-03-30 20:05:19 +0530167 ... flows -s ADDED ${olt_of_id} | grep IN_PORT:${nni_port} | grep VLAN_VID:${s_tag} |
Hardik Windlassfb5eace2020-03-26 14:49:01 +0530168 ... grep VLAN_POP | grep transition=TABLE:1
169 ${downstream_flow_0_added}= Execute ONOS CLI Command ${ip} ${port}
170 ... ${flow_vlan_pop_cmd}
171 Should Not Be Empty ${downstream_flow_0_added}
172 # Verify downstream table=1 flow
173 ${downstream_flow_1_added}= Execute ONOS CLI Command ${ip} ${port}
Hardik Windlass25e11702020-03-30 20:05:19 +0530174 ... flows -s ADDED ${olt_of_id} | grep IN_PORT:${nni_port} | grep VLAN_VID:Any | grep OUTPUT:${onu_port}
Hardik Windlassfb5eace2020-03-26 14:49:01 +0530175 Should Not Be Empty ${downstream_flow_1_added}
176
177Verify Subscriber Access Flows Added Count DT
Hardik Windlass25e11702020-03-30 20:05:19 +0530178 [Arguments] ${ip} ${port} ${olt_of_id} ${expected_flows}
Hardik Windlassfb5eace2020-03-26 14:49:01 +0530179 [Documentation] Matches for total number of subscriber access flows added for all onus
180 ${access_flows_added}= Execute ONOS CLI Command ${ip} ${port}
Hardik Windlass25e11702020-03-30 20:05:19 +0530181 ... flows -s ADDED ${olt_of_id} | grep -v deviceId | grep -v ETH_TYPE:lldp | wc -l
Hardik Windlassfb5eace2020-03-26 14:49:01 +0530182 Should Be Equal As Integers ${access_flows_added} ${expected_flows}
183
Hardik Windlass480f3e22020-04-02 20:14:14 +0530184Verify Device Flows Removed
185 [Arguments] ${ip} ${port} ${olt_of_id}
186 [Documentation] Verifies all flows are removed from the device
187 ${device_flows}= Execute ONOS CLI Command ${ip} ${port}
188 ... flows -s -f ${olt_of_id} | grep -v deviceId | wc -l
189 Should Be Equal As Integers ${device_flows} 0
190
Kailash6f5acb62019-08-28 14:38:45 -0700191Verify Eapol Flows Added
Andy Bavierb0c06232019-08-29 12:58:53 -0700192 [Arguments] ${ip} ${port} ${expected_flows}
Kailash6f5acb62019-08-28 14:38:45 -0700193 [Documentation] Matches for number of eapol flows based on number of onus
Gilles Depatie675a2062019-10-22 12:44:42 -0400194 ${eapol_flows_added}= Execute ONOS CLI Command ${ip} ${port}
195 ... flows -s -f ADDED | grep eapol | grep IN_PORT | wc -l
Andy Bavierb0c06232019-08-29 12:58:53 -0700196 Should Contain ${eapol_flows_added} ${expected_flows}
Kailash6f5acb62019-08-28 14:38:45 -0700197
Suchitra Vemuri9da44302020-03-04 14:24:49 -0800198Verify No Pending Flows For ONU
199 [Arguments] ${ip} ${port} ${onu_port}
200 [Documentation] Verifies that there are no flows "PENDING" state for the ONU in ONOS
201 ${pending_flows}= Execute ONOS CLI Command ${ip} ${port}
202 ... flows -s | grep IN_PORT:${onu_port} | grep PENDING
203 Should Be Empty ${pending_flows}
204
Suchitra Vemuri3dd2f832019-10-18 13:14:54 -0700205Verify Eapol Flows Added For ONU
206 [Arguments] ${ip} ${port} ${onu_port}
207 [Documentation] Verifies if the Eapol Flows are added in ONOS for the ONU
Gilles Depatie675a2062019-10-22 12:44:42 -0400208 ${eapol_flows_added}= Execute ONOS CLI Command ${ip} ${port}
209 ... flows -s -f ADDED | grep eapol | grep IN_PORT:${onu_port}
Suchitra Vemuri3dd2f832019-10-18 13:14:54 -0700210 Should Not Be Empty ${eapol_flows_added}
211
Suchitra Vemuri8078b972020-02-06 19:07:41 -0800212Verify ONU Port Is Enabled
213 [Arguments] ${ip} ${port} ${onu_port}
214 [Documentation] Verifies if the ONU port is enabled in ONOS
215 ${onu_port_enabled}= Execute ONOS CLI Command ${ip} ${port}
Suchitra Vemuri8e15ead2020-02-07 14:41:50 -0800216 ... ports -e | grep port=${onu_port}
Suchitra Vemuri8078b972020-02-06 19:07:41 -0800217 Log ${onu_port_enabled}
218 Should Not Be Empty ${onu_port_enabled}
219
Hardik Windlass63d5e002020-03-06 21:07:09 +0530220Verify ONU Port Is Disabled
221 [Arguments] ${ip} ${port} ${onu_port}
222 [Documentation] Verifies if the ONU port is disabled in ONOS
223 ${onu_port_disabled}= Execute ONOS CLI Command ${ip} ${port}
224 ... ports -e | grep port=${onu_port}
225 Log ${onu_port_disabled}
226 Should Be Empty ${onu_port_disabled}
227
Suchitra Vemuri8a9c3782019-10-23 12:43:01 -0700228Verify ONU in AAA-Users
229 [Arguments] ${ip} ${port} ${onu_port}
230 [Documentation] Verifies that the specified onu_port exists in aaa-users output
231 ${aaa_users}= Execute ONOS CLI Command ${ip} ${port} aaa-users | grep AUTHORIZED | grep ${onu_port}
232 Should Not Be Empty ${aaa_users} ONU port ${onu_port} not found in aaa-users
233
Kailash6f5acb62019-08-28 14:38:45 -0700234Verify Number of AAA-Users
Kailash2b963f02019-08-28 22:46:33 -0700235 [Arguments] ${ip} ${port} ${expected_onus}
Kailash6f5acb62019-08-28 14:38:45 -0700236 [Documentation] Matches for number of aaa-users authorized based on number of onus
Kailash57210eb2019-08-30 13:27:19 -0700237 ##TODO: filter by onu serial number instead of count
Kailash30c418f2019-09-11 13:50:10 -0700238 ${aaa_users}= Execute ONOS CLI Command ${ip} ${port} aaa-users | grep AUTHORIZED | wc -l
Kailash6f5acb62019-08-28 14:38:45 -0700239 Should Contain ${aaa_users} ${expected_onus}
240
241Validate DHCP Allocations
Kailash2b963f02019-08-28 22:46:33 -0700242 [Arguments] ${ip} ${port} ${expected_onus}
Kailash6f5acb62019-08-28 14:38:45 -0700243 [Documentation] Matches for number of dhcpacks based on number of onus
Kailash57210eb2019-08-30 13:27:19 -0700244 ##TODO: filter by onu serial number instead of count
Kailash30c418f2019-09-11 13:50:10 -0700245 ${allocations}= Execute ONOS CLI Command ${ip} ${port} dhcpl2relay-allocations | grep DHCPACK | wc -l
Suchitra Vemuri58766c92019-09-10 11:56:47 -0700246 Should Contain ${allocations} ${expected_onus}
Suchitra Vemuri8a9c3782019-10-23 12:43:01 -0700247
248Validate Subscriber DHCP Allocation
249 [Arguments] ${ip} ${port} ${onu_port}
250 [Documentation] Verifies that the specified subscriber is found in DHCP allocations
251 ##TODO: Enhance the keyword to include DHCP allocated address is not 0.0.0.0
Gilles Depatie675a2062019-10-22 12:44:42 -0400252 ${allocations}= Execute ONOS CLI Command ${ip} ${port}
253 ... dhcpl2relay-allocations | grep DHCPACK | grep ${onu_port}
254 Should Not Be Empty ${allocations} ONU port ${onu_port} not found in dhcpl2relay-allocations
David Bainbridgef81cd642019-11-20 00:14:47 +0000255
256Device Is Available In ONOS
257 [Arguments] ${url} ${dpid}
258 [Documentation] Validates the device exists and it available in ONOS
259 ${rc} ${json} Run And Return Rc And Output curl --fail -sSL ${url}/onos/v1/devices/${dpid}
260 Should Be Equal As Integers 0 ${rc}
261 ${rc} ${value} Run And Return Rc And Output echo '${json}' | jq -r .available
262 Should Be Equal As Integers 0 ${rc}
263 Should Be Equal 'true' '${value}'
264
265Remove All Devices From ONOS
266 [Arguments] ${url}
267 [Documentation] Executes the device-remove command on each device in ONOS
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700268 ${rc} @{dpids} Run And Return Rc And Output
269 ... curl --fail -sSL ${url}/onos/v1/devices | jq -r '.devices[].id'
David Bainbridgef81cd642019-11-20 00:14:47 +0000270 Should Be Equal As Integers ${rc} 0
271 ${count}= Get length ${dpids}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700272 FOR ${dpid} IN @{dpids}
273 ${rc}= Run Keyword If '${dpid}' != ''
274 ... Run And Return Rc curl -XDELETE --fail -sSL ${url}/onos/v1/devices/${dpid}
275 Run Keyword If '${dpid}' != ''
276 ... Should Be Equal As Integers ${rc} 0
277 END