Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 1 | # 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. |
Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 14 | # onos common functions |
| 15 | |
| 16 | *** Settings *** |
| 17 | Documentation Library for various utilities |
| 18 | Library SSHLibrary |
Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 19 | Library String |
| 20 | Library DateTime |
| 21 | Library Process |
| 22 | Library Collections |
| 23 | Library RequestsLibrary |
| 24 | Library OperatingSystem |
| 25 | |
| 26 | *** Keywords *** |
Kailash | 30c418f | 2019-09-11 13:50:10 -0700 | [diff] [blame] | 27 | Execute ONOS CLI Command |
Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 28 | [Arguments] ${host} ${port} ${cmd} |
| 29 | [Documentation] Establishes an ssh connection to the onos contoller and executes a command |
Matteo Scandolo | 8c2be8e | 2020-01-09 13:53:51 -0800 | [diff] [blame] | 30 | ${conn_id}= SSHLibrary.Open Connection ${host} port=${port} timeout=300s |
Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 31 | SSHLibrary.Login karaf karaf |
otti | 981bcb4 | 2020-02-06 09:11:55 +0000 | [diff] [blame^] | 32 | @{result_values} SSHLibrary.Execute Command ${cmd} return_rc=True |
| 33 | ... return_stderr=True return_stdout=True |
| 34 | ${output} Set Variable @{result_values}[0] |
Kailash | fa025ea | 2019-09-11 11:12:54 -0700 | [diff] [blame] | 35 | Log ${output} |
otti | 981bcb4 | 2020-02-06 09:11:55 +0000 | [diff] [blame^] | 36 | Should Be Empty @{result_values}[1] |
| 37 | Should Be Equal As Integers @{result_values}[2] 0 |
Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 38 | SSHLibrary.Close Connection |
| 39 | [Return] ${output} |
| 40 | |
| 41 | Validate OLT Device in ONOS |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 42 | # FIXME use volt-olts to check that the OLT is ONOS |
Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 43 | [Arguments] ${serial_number} |
Zack Williams | ec53a1b | 2019-09-16 15:50:52 -0700 | [diff] [blame] | 44 | [Documentation] Checks if olt has been connected to ONOS |
Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 45 | ${resp}= Get Request ONOS onos/v1/devices |
| 46 | ${jsondata}= To Json ${resp.content} |
| 47 | Should Not Be Empty ${jsondata['devices']} |
| 48 | ${length}= Get Length ${jsondata['devices']} |
| 49 | @{serial_numbers}= Create List |
Zack Williams | ec53a1b | 2019-09-16 15:50:52 -0700 | [diff] [blame] | 50 | FOR ${INDEX} IN RANGE 0 ${length} |
| 51 | ${value}= Get From List ${jsondata['devices']} ${INDEX} |
| 52 | ${of_id}= Get From Dictionary ${value} id |
| 53 | ${sn}= Get From Dictionary ${value} serial |
| 54 | Run Keyword If '${sn}' == '${serial_number}' Exit For Loop |
| 55 | END |
Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 56 | Should Be Equal As Strings ${sn} ${serial_number} |
Kailash | 57210eb | 2019-08-30 13:27:19 -0700 | [diff] [blame] | 57 | [Return] ${of_id} |
Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 58 | |
Suchitra Vemuri | 102912a | 2019-09-24 00:35:42 -0700 | [diff] [blame] | 59 | Get ONU Port in ONOS |
Zack Williams | ec53a1b | 2019-09-16 15:50:52 -0700 | [diff] [blame] | 60 | [Arguments] ${onu_serial_number} ${olt_of_id} |
Suchitra Vemuri | 102912a | 2019-09-24 00:35:42 -0700 | [diff] [blame] | 61 | [Documentation] Retrieves ONU port for the ONU in ONOS |
Suchitra Vemuri | a50c1c1 | 2019-09-30 19:54:26 -0700 | [diff] [blame] | 62 | ${onu_serial_number}= Catenate SEPARATOR=- ${onu_serial_number} 1 |
Suchitra Vemuri | 102912a | 2019-09-24 00:35:42 -0700 | [diff] [blame] | 63 | ${resp}= Get Request ONOS onos/v1/devices/${olt_of_id}/ports |
| 64 | ${jsondata}= To Json ${resp.content} |
| 65 | Should Not Be Empty ${jsondata['ports']} |
| 66 | ${length}= Get Length ${jsondata['ports']} |
| 67 | @{ports}= Create List |
Zack Williams | ec53a1b | 2019-09-16 15:50:52 -0700 | [diff] [blame] | 68 | FOR ${INDEX} IN RANGE 0 ${length} |
| 69 | ${value}= Get From List ${jsondata['ports']} ${INDEX} |
| 70 | ${annotations}= Get From Dictionary ${value} annotations |
| 71 | ${onu_port}= Get From Dictionary ${value} port |
| 72 | ${portName}= Get From Dictionary ${annotations} portName |
| 73 | Run Keyword If '${portName}' == '${onu_serial_number}' Exit For Loop |
| 74 | END |
Suchitra Vemuri | 102912a | 2019-09-24 00:35:42 -0700 | [diff] [blame] | 75 | Should Be Equal As Strings ${portName} ${onu_serial_number} |
| 76 | [Return] ${onu_port} |
| 77 | |
Suchitra Vemuri | 532f67a | 2019-09-25 11:50:42 -0700 | [diff] [blame] | 78 | Get FabricSwitch in ONOS |
| 79 | [Documentation] Returns of_id of the Fabric Switch in ONOS |
| 80 | ${resp}= Get Request ONOS onos/v1/devices |
| 81 | ${jsondata}= To Json ${resp.content} |
| 82 | Should Not Be Empty ${jsondata['devices']} |
| 83 | ${length}= Get Length ${jsondata['devices']} |
| 84 | FOR ${INDEX} IN RANGE 0 ${length} |
| 85 | ${value}= Get From List ${jsondata['devices']} ${INDEX} |
| 86 | ${of_id}= Get From Dictionary ${value} id |
| 87 | ${type}= Get From Dictionary ${value} type |
| 88 | Run Keyword If '${type}' == "SWITCH" Exit For Loop |
| 89 | END |
| 90 | [Return] ${of_id} |
| 91 | |
Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 92 | Verify Eapol Flows Added |
Andy Bavier | b0c0623 | 2019-08-29 12:58:53 -0700 | [diff] [blame] | 93 | [Arguments] ${ip} ${port} ${expected_flows} |
Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 94 | [Documentation] Matches for number of eapol flows based on number of onus |
Gilles Depatie | 675a206 | 2019-10-22 12:44:42 -0400 | [diff] [blame] | 95 | ${eapol_flows_added}= Execute ONOS CLI Command ${ip} ${port} |
| 96 | ... flows -s -f ADDED | grep eapol | grep IN_PORT | wc -l |
Andy Bavier | b0c0623 | 2019-08-29 12:58:53 -0700 | [diff] [blame] | 97 | Should Contain ${eapol_flows_added} ${expected_flows} |
Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 98 | |
Suchitra Vemuri | 3dd2f83 | 2019-10-18 13:14:54 -0700 | [diff] [blame] | 99 | Verify Eapol Flows Added For ONU |
| 100 | [Arguments] ${ip} ${port} ${onu_port} |
| 101 | [Documentation] Verifies if the Eapol Flows are added in ONOS for the ONU |
Gilles Depatie | 675a206 | 2019-10-22 12:44:42 -0400 | [diff] [blame] | 102 | ${eapol_flows_added}= Execute ONOS CLI Command ${ip} ${port} |
| 103 | ... flows -s -f ADDED | grep eapol | grep IN_PORT:${onu_port} |
Suchitra Vemuri | 3dd2f83 | 2019-10-18 13:14:54 -0700 | [diff] [blame] | 104 | Should Not Be Empty ${eapol_flows_added} |
| 105 | |
Suchitra Vemuri | 8078b97 | 2020-02-06 19:07:41 -0800 | [diff] [blame] | 106 | Verify ONU Port Is Enabled |
| 107 | [Arguments] ${ip} ${port} ${onu_port} |
| 108 | [Documentation] Verifies if the ONU port is enabled in ONOS |
| 109 | ${onu_port_enabled}= Execute ONOS CLI Command ${ip} ${port} |
Suchitra Vemuri | 8e15ead | 2020-02-07 14:41:50 -0800 | [diff] [blame] | 110 | ... ports -e | grep port=${onu_port} |
Suchitra Vemuri | 8078b97 | 2020-02-06 19:07:41 -0800 | [diff] [blame] | 111 | Log ${onu_port_enabled} |
| 112 | Should Not Be Empty ${onu_port_enabled} |
| 113 | |
Suchitra Vemuri | 8a9c378 | 2019-10-23 12:43:01 -0700 | [diff] [blame] | 114 | Verify ONU in AAA-Users |
| 115 | [Arguments] ${ip} ${port} ${onu_port} |
| 116 | [Documentation] Verifies that the specified onu_port exists in aaa-users output |
| 117 | ${aaa_users}= Execute ONOS CLI Command ${ip} ${port} aaa-users | grep AUTHORIZED | grep ${onu_port} |
| 118 | Should Not Be Empty ${aaa_users} ONU port ${onu_port} not found in aaa-users |
| 119 | |
Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 120 | Verify Number of AAA-Users |
Kailash | 2b963f0 | 2019-08-28 22:46:33 -0700 | [diff] [blame] | 121 | [Arguments] ${ip} ${port} ${expected_onus} |
Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 122 | [Documentation] Matches for number of aaa-users authorized based on number of onus |
Kailash | 57210eb | 2019-08-30 13:27:19 -0700 | [diff] [blame] | 123 | ##TODO: filter by onu serial number instead of count |
Kailash | 30c418f | 2019-09-11 13:50:10 -0700 | [diff] [blame] | 124 | ${aaa_users}= Execute ONOS CLI Command ${ip} ${port} aaa-users | grep AUTHORIZED | wc -l |
Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 125 | Should Contain ${aaa_users} ${expected_onus} |
| 126 | |
| 127 | Validate DHCP Allocations |
Kailash | 2b963f0 | 2019-08-28 22:46:33 -0700 | [diff] [blame] | 128 | [Arguments] ${ip} ${port} ${expected_onus} |
Kailash | 6f5acb6 | 2019-08-28 14:38:45 -0700 | [diff] [blame] | 129 | [Documentation] Matches for number of dhcpacks based on number of onus |
Kailash | 57210eb | 2019-08-30 13:27:19 -0700 | [diff] [blame] | 130 | ##TODO: filter by onu serial number instead of count |
Kailash | 30c418f | 2019-09-11 13:50:10 -0700 | [diff] [blame] | 131 | ${allocations}= Execute ONOS CLI Command ${ip} ${port} dhcpl2relay-allocations | grep DHCPACK | wc -l |
Suchitra Vemuri | 58766c9 | 2019-09-10 11:56:47 -0700 | [diff] [blame] | 132 | Should Contain ${allocations} ${expected_onus} |
Suchitra Vemuri | 8a9c378 | 2019-10-23 12:43:01 -0700 | [diff] [blame] | 133 | |
| 134 | Validate Subscriber DHCP Allocation |
| 135 | [Arguments] ${ip} ${port} ${onu_port} |
| 136 | [Documentation] Verifies that the specified subscriber is found in DHCP allocations |
| 137 | ##TODO: Enhance the keyword to include DHCP allocated address is not 0.0.0.0 |
Gilles Depatie | 675a206 | 2019-10-22 12:44:42 -0400 | [diff] [blame] | 138 | ${allocations}= Execute ONOS CLI Command ${ip} ${port} |
| 139 | ... dhcpl2relay-allocations | grep DHCPACK | grep ${onu_port} |
| 140 | Should Not Be Empty ${allocations} ONU port ${onu_port} not found in dhcpl2relay-allocations |
David Bainbridge | f81cd64 | 2019-11-20 00:14:47 +0000 | [diff] [blame] | 141 | |
| 142 | Device Is Available In ONOS |
| 143 | [Arguments] ${url} ${dpid} |
| 144 | [Documentation] Validates the device exists and it available in ONOS |
| 145 | ${rc} ${json} Run And Return Rc And Output curl --fail -sSL ${url}/onos/v1/devices/${dpid} |
| 146 | Should Be Equal As Integers 0 ${rc} |
| 147 | ${rc} ${value} Run And Return Rc And Output echo '${json}' | jq -r .available |
| 148 | Should Be Equal As Integers 0 ${rc} |
| 149 | Should Be Equal 'true' '${value}' |
| 150 | |
| 151 | Remove All Devices From ONOS |
| 152 | [Arguments] ${url} |
| 153 | [Documentation] Executes the device-remove command on each device in ONOS |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 154 | ${rc} @{dpids} Run And Return Rc And Output |
| 155 | ... curl --fail -sSL ${url}/onos/v1/devices | jq -r '.devices[].id' |
David Bainbridge | f81cd64 | 2019-11-20 00:14:47 +0000 | [diff] [blame] | 156 | Should Be Equal As Integers ${rc} 0 |
| 157 | ${count}= Get length ${dpids} |
Zack Williams | a8fe75a | 2020-01-10 14:25:27 -0700 | [diff] [blame] | 158 | FOR ${dpid} IN @{dpids} |
| 159 | ${rc}= Run Keyword If '${dpid}' != '' |
| 160 | ... Run And Return Rc curl -XDELETE --fail -sSL ${url}/onos/v1/devices/${dpid} |
| 161 | Run Keyword If '${dpid}' != '' |
| 162 | ... Should Be Equal As Integers ${rc} 0 |
| 163 | END |