blob: 3160c6c4cc36a8aad49d8d0e80d9b578197a9b5e [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
Zack Williamsec53a1b2019-09-16 15:50:52 -070036 FOR ${INDEX} IN RANGE 0 ${length}
37 ${value}= Get From List ${jsondata['devices']} ${INDEX}
38 ${of_id}= Get From Dictionary ${value} id
39 ${sn}= Get From Dictionary ${value} serial
40 Run Keyword If '${sn}' == '${serial_number}' Exit For Loop
41 END
Kailash6f5acb62019-08-28 14:38:45 -070042 Should Be Equal As Strings ${sn} ${serial_number}
Kailash57210eb2019-08-30 13:27:19 -070043 [Return] ${of_id}
Kailash6f5acb62019-08-28 14:38:45 -070044
Suchitra Vemuri102912a2019-09-24 00:35:42 -070045Get ONU Port in ONOS
Zack Williamsec53a1b2019-09-16 15:50:52 -070046 [Arguments] ${onu_serial_number} ${olt_of_id}
Suchitra Vemuri102912a2019-09-24 00:35:42 -070047 [Documentation] Retrieves ONU port for the ONU in ONOS
Suchitra Vemuria50c1c12019-09-30 19:54:26 -070048 ${onu_serial_number}= Catenate SEPARATOR=- ${onu_serial_number} 1
Suchitra Vemuri102912a2019-09-24 00:35:42 -070049 ${resp}= Get Request ONOS onos/v1/devices/${olt_of_id}/ports
50 ${jsondata}= To Json ${resp.content}
51 Should Not Be Empty ${jsondata['ports']}
52 ${length}= Get Length ${jsondata['ports']}
53 @{ports}= Create List
Zack Williamsec53a1b2019-09-16 15:50:52 -070054 FOR ${INDEX} IN RANGE 0 ${length}
55 ${value}= Get From List ${jsondata['ports']} ${INDEX}
56 ${annotations}= Get From Dictionary ${value} annotations
57 ${onu_port}= Get From Dictionary ${value} port
58 ${portName}= Get From Dictionary ${annotations} portName
59 Run Keyword If '${portName}' == '${onu_serial_number}' Exit For Loop
60 END
Suchitra Vemuri102912a2019-09-24 00:35:42 -070061 Should Be Equal As Strings ${portName} ${onu_serial_number}
62 [Return] ${onu_port}
63
Suchitra Vemuri532f67a2019-09-25 11:50:42 -070064Get FabricSwitch in ONOS
65 [Documentation] Returns of_id of the Fabric Switch in ONOS
66 ${resp}= Get Request ONOS onos/v1/devices
67 ${jsondata}= To Json ${resp.content}
68 Should Not Be Empty ${jsondata['devices']}
69 ${length}= Get Length ${jsondata['devices']}
70 FOR ${INDEX} IN RANGE 0 ${length}
71 ${value}= Get From List ${jsondata['devices']} ${INDEX}
72 ${of_id}= Get From Dictionary ${value} id
73 ${type}= Get From Dictionary ${value} type
74 Run Keyword If '${type}' == "SWITCH" Exit For Loop
75 END
76 [Return] ${of_id}
77
Kailash6f5acb62019-08-28 14:38:45 -070078Verify Eapol Flows Added
Andy Bavierb0c06232019-08-29 12:58:53 -070079 [Arguments] ${ip} ${port} ${expected_flows}
Kailash6f5acb62019-08-28 14:38:45 -070080 [Documentation] Matches for number of eapol flows based on number of onus
Gilles Depatie675a2062019-10-22 12:44:42 -040081 ${eapol_flows_added}= Execute ONOS CLI Command ${ip} ${port}
82 ... flows -s -f ADDED | grep eapol | grep IN_PORT | wc -l
Andy Bavierb0c06232019-08-29 12:58:53 -070083 Should Contain ${eapol_flows_added} ${expected_flows}
Kailash6f5acb62019-08-28 14:38:45 -070084
Suchitra Vemuri9da44302020-03-04 14:24:49 -080085Verify No Pending Flows For ONU
86 [Arguments] ${ip} ${port} ${onu_port}
87 [Documentation] Verifies that there are no flows "PENDING" state for the ONU in ONOS
88 ${pending_flows}= Execute ONOS CLI Command ${ip} ${port}
89 ... flows -s | grep IN_PORT:${onu_port} | grep PENDING
90 Should Be Empty ${pending_flows}
91
Suchitra Vemuri3dd2f832019-10-18 13:14:54 -070092Verify Eapol Flows Added For ONU
93 [Arguments] ${ip} ${port} ${onu_port}
94 [Documentation] Verifies if the Eapol Flows are added in ONOS for the ONU
Gilles Depatie675a2062019-10-22 12:44:42 -040095 ${eapol_flows_added}= Execute ONOS CLI Command ${ip} ${port}
96 ... flows -s -f ADDED | grep eapol | grep IN_PORT:${onu_port}
Suchitra Vemuri3dd2f832019-10-18 13:14:54 -070097 Should Not Be Empty ${eapol_flows_added}
98
Suchitra Vemuri8078b972020-02-06 19:07:41 -080099Verify ONU Port Is Enabled
100 [Arguments] ${ip} ${port} ${onu_port}
101 [Documentation] Verifies if the ONU port is enabled in ONOS
102 ${onu_port_enabled}= Execute ONOS CLI Command ${ip} ${port}
Suchitra Vemuri8e15ead2020-02-07 14:41:50 -0800103 ... ports -e | grep port=${onu_port}
Suchitra Vemuri8078b972020-02-06 19:07:41 -0800104 Log ${onu_port_enabled}
105 Should Not Be Empty ${onu_port_enabled}
106
Hardik Windlass63d5e002020-03-06 21:07:09 +0530107Verify ONU Port Is Disabled
108 [Arguments] ${ip} ${port} ${onu_port}
109 [Documentation] Verifies if the ONU port is disabled in ONOS
110 ${onu_port_disabled}= Execute ONOS CLI Command ${ip} ${port}
111 ... ports -e | grep port=${onu_port}
112 Log ${onu_port_disabled}
113 Should Be Empty ${onu_port_disabled}
114
Suchitra Vemuri8a9c3782019-10-23 12:43:01 -0700115Verify ONU in AAA-Users
116 [Arguments] ${ip} ${port} ${onu_port}
117 [Documentation] Verifies that the specified onu_port exists in aaa-users output
118 ${aaa_users}= Execute ONOS CLI Command ${ip} ${port} aaa-users | grep AUTHORIZED | grep ${onu_port}
119 Should Not Be Empty ${aaa_users} ONU port ${onu_port} not found in aaa-users
120
Kailash6f5acb62019-08-28 14:38:45 -0700121Verify Number of AAA-Users
Kailash2b963f02019-08-28 22:46:33 -0700122 [Arguments] ${ip} ${port} ${expected_onus}
Kailash6f5acb62019-08-28 14:38:45 -0700123 [Documentation] Matches for number of aaa-users authorized based on number of onus
Kailash57210eb2019-08-30 13:27:19 -0700124 ##TODO: filter by onu serial number instead of count
Kailash30c418f2019-09-11 13:50:10 -0700125 ${aaa_users}= Execute ONOS CLI Command ${ip} ${port} aaa-users | grep AUTHORIZED | wc -l
Kailash6f5acb62019-08-28 14:38:45 -0700126 Should Contain ${aaa_users} ${expected_onus}
127
128Validate DHCP Allocations
Kailash2b963f02019-08-28 22:46:33 -0700129 [Arguments] ${ip} ${port} ${expected_onus}
Kailash6f5acb62019-08-28 14:38:45 -0700130 [Documentation] Matches for number of dhcpacks based on number of onus
Kailash57210eb2019-08-30 13:27:19 -0700131 ##TODO: filter by onu serial number instead of count
Kailash30c418f2019-09-11 13:50:10 -0700132 ${allocations}= Execute ONOS CLI Command ${ip} ${port} dhcpl2relay-allocations | grep DHCPACK | wc -l
Suchitra Vemuri58766c92019-09-10 11:56:47 -0700133 Should Contain ${allocations} ${expected_onus}
Suchitra Vemuri8a9c3782019-10-23 12:43:01 -0700134
135Validate Subscriber DHCP Allocation
136 [Arguments] ${ip} ${port} ${onu_port}
137 [Documentation] Verifies that the specified subscriber is found in DHCP allocations
138 ##TODO: Enhance the keyword to include DHCP allocated address is not 0.0.0.0
Gilles Depatie675a2062019-10-22 12:44:42 -0400139 ${allocations}= Execute ONOS CLI Command ${ip} ${port}
140 ... dhcpl2relay-allocations | grep DHCPACK | grep ${onu_port}
141 Should Not Be Empty ${allocations} ONU port ${onu_port} not found in dhcpl2relay-allocations
David Bainbridgef81cd642019-11-20 00:14:47 +0000142
143Device Is Available In ONOS
144 [Arguments] ${url} ${dpid}
145 [Documentation] Validates the device exists and it available in ONOS
146 ${rc} ${json} Run And Return Rc And Output curl --fail -sSL ${url}/onos/v1/devices/${dpid}
147 Should Be Equal As Integers 0 ${rc}
148 ${rc} ${value} Run And Return Rc And Output echo '${json}' | jq -r .available
149 Should Be Equal As Integers 0 ${rc}
150 Should Be Equal 'true' '${value}'
151
152Remove All Devices From ONOS
153 [Arguments] ${url}
154 [Documentation] Executes the device-remove command on each device in ONOS
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700155 ${rc} @{dpids} Run And Return Rc And Output
156 ... curl --fail -sSL ${url}/onos/v1/devices | jq -r '.devices[].id'
David Bainbridgef81cd642019-11-20 00:14:47 +0000157 Should Be Equal As Integers ${rc} 0
158 ${count}= Get length ${dpids}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700159 FOR ${dpid} IN @{dpids}
160 ${rc}= Run Keyword If '${dpid}' != ''
161 ... Run And Return Rc curl -XDELETE --fail -sSL ${url}/onos/v1/devices/${dpid}
162 Run Keyword If '${dpid}' != ''
163 ... Should Be Equal As Integers ${rc} 0
164 END