blob: 1b26fceb111f3ffb2713f34e85c428a036977bc7 [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 ***
Kailash30c418f2019-09-11 13:50:10 -070027Execute ONOS CLI Command
Kailash6f5acb62019-08-28 14:38:45 -070028 [Arguments] ${host} ${port} ${cmd}
29 [Documentation] Establishes an ssh connection to the onos contoller and executes a command
Matteo Scandolo8c2be8e2020-01-09 13:53:51 -080030 ${conn_id}= SSHLibrary.Open Connection ${host} port=${port} timeout=300s
Kailash6f5acb62019-08-28 14:38:45 -070031 SSHLibrary.Login karaf karaf
32 ${output}= SSHLibrary.Execute Command ${cmd}
Kailashfa025ea2019-09-11 11:12:54 -070033 Log ${output}
Kailash6f5acb62019-08-28 14:38:45 -070034 SSHLibrary.Close Connection
35 [Return] ${output}
36
37Validate OLT Device in ONOS
Zack Williamsa8fe75a2020-01-10 14:25:27 -070038 # FIXME use volt-olts to check that the OLT is ONOS
Kailash6f5acb62019-08-28 14:38:45 -070039 [Arguments] ${serial_number}
Zack Williamsec53a1b2019-09-16 15:50:52 -070040 [Documentation] Checks if olt has been connected to ONOS
Kailash6f5acb62019-08-28 14:38:45 -070041 ${resp}= Get Request ONOS onos/v1/devices
42 ${jsondata}= To Json ${resp.content}
43 Should Not Be Empty ${jsondata['devices']}
44 ${length}= Get Length ${jsondata['devices']}
45 @{serial_numbers}= Create List
Zack Williamsec53a1b2019-09-16 15:50:52 -070046 FOR ${INDEX} IN RANGE 0 ${length}
47 ${value}= Get From List ${jsondata['devices']} ${INDEX}
48 ${of_id}= Get From Dictionary ${value} id
49 ${sn}= Get From Dictionary ${value} serial
50 Run Keyword If '${sn}' == '${serial_number}' Exit For Loop
51 END
Kailash6f5acb62019-08-28 14:38:45 -070052 Should Be Equal As Strings ${sn} ${serial_number}
Kailash57210eb2019-08-30 13:27:19 -070053 [Return] ${of_id}
Kailash6f5acb62019-08-28 14:38:45 -070054
Suchitra Vemuri102912a2019-09-24 00:35:42 -070055Get ONU Port in ONOS
Zack Williamsec53a1b2019-09-16 15:50:52 -070056 [Arguments] ${onu_serial_number} ${olt_of_id}
Suchitra Vemuri102912a2019-09-24 00:35:42 -070057 [Documentation] Retrieves ONU port for the ONU in ONOS
Suchitra Vemuria50c1c12019-09-30 19:54:26 -070058 ${onu_serial_number}= Catenate SEPARATOR=- ${onu_serial_number} 1
Suchitra Vemuri102912a2019-09-24 00:35:42 -070059 ${resp}= Get Request ONOS onos/v1/devices/${olt_of_id}/ports
60 ${jsondata}= To Json ${resp.content}
61 Should Not Be Empty ${jsondata['ports']}
62 ${length}= Get Length ${jsondata['ports']}
63 @{ports}= Create List
Zack Williamsec53a1b2019-09-16 15:50:52 -070064 FOR ${INDEX} IN RANGE 0 ${length}
65 ${value}= Get From List ${jsondata['ports']} ${INDEX}
66 ${annotations}= Get From Dictionary ${value} annotations
67 ${onu_port}= Get From Dictionary ${value} port
68 ${portName}= Get From Dictionary ${annotations} portName
69 Run Keyword If '${portName}' == '${onu_serial_number}' Exit For Loop
70 END
Suchitra Vemuri102912a2019-09-24 00:35:42 -070071 Should Be Equal As Strings ${portName} ${onu_serial_number}
72 [Return] ${onu_port}
73
Suchitra Vemuri532f67a2019-09-25 11:50:42 -070074Get FabricSwitch in ONOS
75 [Documentation] Returns of_id of the Fabric Switch in ONOS
76 ${resp}= Get Request ONOS onos/v1/devices
77 ${jsondata}= To Json ${resp.content}
78 Should Not Be Empty ${jsondata['devices']}
79 ${length}= Get Length ${jsondata['devices']}
80 FOR ${INDEX} IN RANGE 0 ${length}
81 ${value}= Get From List ${jsondata['devices']} ${INDEX}
82 ${of_id}= Get From Dictionary ${value} id
83 ${type}= Get From Dictionary ${value} type
84 Run Keyword If '${type}' == "SWITCH" Exit For Loop
85 END
86 [Return] ${of_id}
87
Kailash6f5acb62019-08-28 14:38:45 -070088Verify Eapol Flows Added
Andy Bavierb0c06232019-08-29 12:58:53 -070089 [Arguments] ${ip} ${port} ${expected_flows}
Kailash6f5acb62019-08-28 14:38:45 -070090 [Documentation] Matches for number of eapol flows based on number of onus
Gilles Depatie675a2062019-10-22 12:44:42 -040091 ${eapol_flows_added}= Execute ONOS CLI Command ${ip} ${port}
92 ... flows -s -f ADDED | grep eapol | grep IN_PORT | wc -l
Andy Bavierb0c06232019-08-29 12:58:53 -070093 Should Contain ${eapol_flows_added} ${expected_flows}
Kailash6f5acb62019-08-28 14:38:45 -070094
Suchitra Vemuri3dd2f832019-10-18 13:14:54 -070095Verify Eapol Flows Added For ONU
96 [Arguments] ${ip} ${port} ${onu_port}
97 [Documentation] Verifies if the Eapol Flows are added in ONOS for the ONU
Gilles Depatie675a2062019-10-22 12:44:42 -040098 ${eapol_flows_added}= Execute ONOS CLI Command ${ip} ${port}
99 ... flows -s -f ADDED | grep eapol | grep IN_PORT:${onu_port}
Suchitra Vemuri3dd2f832019-10-18 13:14:54 -0700100 Should Not Be Empty ${eapol_flows_added}
101
Suchitra Vemuri8078b972020-02-06 19:07:41 -0800102Verify ONU Port Is Enabled
103 [Arguments] ${ip} ${port} ${onu_port}
104 [Documentation] Verifies if the ONU port is enabled in ONOS
105 ${onu_port_enabled}= Execute ONOS CLI Command ${ip} ${port}
Suchitra Vemuri8e15ead2020-02-07 14:41:50 -0800106 ... ports -e | grep port=${onu_port}
Suchitra Vemuri8078b972020-02-06 19:07:41 -0800107 Log ${onu_port_enabled}
108 Should Not Be Empty ${onu_port_enabled}
109
Suchitra Vemuri8a9c3782019-10-23 12:43:01 -0700110Verify ONU in AAA-Users
111 [Arguments] ${ip} ${port} ${onu_port}
112 [Documentation] Verifies that the specified onu_port exists in aaa-users output
113 ${aaa_users}= Execute ONOS CLI Command ${ip} ${port} aaa-users | grep AUTHORIZED | grep ${onu_port}
114 Should Not Be Empty ${aaa_users} ONU port ${onu_port} not found in aaa-users
115
Kailash6f5acb62019-08-28 14:38:45 -0700116Verify Number of AAA-Users
Kailash2b963f02019-08-28 22:46:33 -0700117 [Arguments] ${ip} ${port} ${expected_onus}
Kailash6f5acb62019-08-28 14:38:45 -0700118 [Documentation] Matches for number of aaa-users authorized based on number of onus
Kailash57210eb2019-08-30 13:27:19 -0700119 ##TODO: filter by onu serial number instead of count
Kailash30c418f2019-09-11 13:50:10 -0700120 ${aaa_users}= Execute ONOS CLI Command ${ip} ${port} aaa-users | grep AUTHORIZED | wc -l
Kailash6f5acb62019-08-28 14:38:45 -0700121 Should Contain ${aaa_users} ${expected_onus}
122
123Validate DHCP Allocations
Kailash2b963f02019-08-28 22:46:33 -0700124 [Arguments] ${ip} ${port} ${expected_onus}
Kailash6f5acb62019-08-28 14:38:45 -0700125 [Documentation] Matches for number of dhcpacks based on number of onus
Kailash57210eb2019-08-30 13:27:19 -0700126 ##TODO: filter by onu serial number instead of count
Kailash30c418f2019-09-11 13:50:10 -0700127 ${allocations}= Execute ONOS CLI Command ${ip} ${port} dhcpl2relay-allocations | grep DHCPACK | wc -l
Suchitra Vemuri58766c92019-09-10 11:56:47 -0700128 Should Contain ${allocations} ${expected_onus}
Suchitra Vemuri8a9c3782019-10-23 12:43:01 -0700129
130Validate Subscriber DHCP Allocation
131 [Arguments] ${ip} ${port} ${onu_port}
132 [Documentation] Verifies that the specified subscriber is found in DHCP allocations
133 ##TODO: Enhance the keyword to include DHCP allocated address is not 0.0.0.0
Gilles Depatie675a2062019-10-22 12:44:42 -0400134 ${allocations}= Execute ONOS CLI Command ${ip} ${port}
135 ... dhcpl2relay-allocations | grep DHCPACK | grep ${onu_port}
136 Should Not Be Empty ${allocations} ONU port ${onu_port} not found in dhcpl2relay-allocations
David Bainbridgef81cd642019-11-20 00:14:47 +0000137
138Device Is Available In ONOS
139 [Arguments] ${url} ${dpid}
140 [Documentation] Validates the device exists and it available in ONOS
141 ${rc} ${json} Run And Return Rc And Output curl --fail -sSL ${url}/onos/v1/devices/${dpid}
142 Should Be Equal As Integers 0 ${rc}
143 ${rc} ${value} Run And Return Rc And Output echo '${json}' | jq -r .available
144 Should Be Equal As Integers 0 ${rc}
145 Should Be Equal 'true' '${value}'
146
147Remove All Devices From ONOS
148 [Arguments] ${url}
149 [Documentation] Executes the device-remove command on each device in ONOS
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700150 ${rc} @{dpids} Run And Return Rc And Output
151 ... curl --fail -sSL ${url}/onos/v1/devices | jq -r '.devices[].id'
David Bainbridgef81cd642019-11-20 00:14:47 +0000152 Should Be Equal As Integers ${rc} 0
153 ${count}= Get length ${dpids}
Zack Williamsa8fe75a2020-01-10 14:25:27 -0700154 FOR ${dpid} IN @{dpids}
155 ${rc}= Run Keyword If '${dpid}' != ''
156 ... Run And Return Rc curl -XDELETE --fail -sSL ${url}/onos/v1/devices/${dpid}
157 Run Keyword If '${dpid}' != ''
158 ... Should Be Equal As Integers ${rc} 0
159 END