blob: 9250ab895078183173ce5eb648495cf9d62a1013 [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.
14
15# onos common functions
16
17*** Settings ***
18Documentation Library for various utilities
19Library SSHLibrary
20Library HttpLibrary.HTTP
21Library String
22Library DateTime
23Library Process
24Library Collections
25Library RequestsLibrary
26Library OperatingSystem
27
28*** Keywords ***
Kailash30c418f2019-09-11 13:50:10 -070029Execute ONOS CLI Command
Kailash6f5acb62019-08-28 14:38:45 -070030 [Arguments] ${host} ${port} ${cmd}
31 [Documentation] Establishes an ssh connection to the onos contoller and executes a command
32 ${conn_id}= SSHLibrary.Open Connection ${host} port=${port} prompt=onos> timeout=300s
33 SSHLibrary.Login karaf karaf
34 ${output}= SSHLibrary.Execute Command ${cmd}
Kailashfa025ea2019-09-11 11:12:54 -070035 Log ${output}
Kailash6f5acb62019-08-28 14:38:45 -070036 SSHLibrary.Close Connection
37 [Return] ${output}
38
39Validate OLT Device in ONOS
Kailash6f5acb62019-08-28 14:38:45 -070040 [Arguments] ${serial_number}
Zack Williamsec53a1b2019-09-16 15:50:52 -070041 [Documentation] Checks if olt has been connected to ONOS
Kailash6f5acb62019-08-28 14:38:45 -070042 ${resp}= Get Request ONOS onos/v1/devices
43 ${jsondata}= To Json ${resp.content}
44 Should Not Be Empty ${jsondata['devices']}
45 ${length}= Get Length ${jsondata['devices']}
46 @{serial_numbers}= Create List
Zack Williamsec53a1b2019-09-16 15:50:52 -070047 FOR ${INDEX} IN RANGE 0 ${length}
48 ${value}= Get From List ${jsondata['devices']} ${INDEX}
49 ${of_id}= Get From Dictionary ${value} id
50 ${sn}= Get From Dictionary ${value} serial
51 Run Keyword If '${sn}' == '${serial_number}' Exit For Loop
52 END
Kailash6f5acb62019-08-28 14:38:45 -070053 Should Be Equal As Strings ${sn} ${serial_number}
Kailash57210eb2019-08-30 13:27:19 -070054 [Return] ${of_id}
Kailash6f5acb62019-08-28 14:38:45 -070055
Suchitra Vemuri102912a2019-09-24 00:35:42 -070056Get ONU Port in ONOS
Zack Williamsec53a1b2019-09-16 15:50:52 -070057 [Arguments] ${onu_serial_number} ${olt_of_id}
Suchitra Vemuri102912a2019-09-24 00:35:42 -070058 [Documentation] Retrieves ONU port for the ONU in ONOS
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
Kailash6f5acb62019-08-28 14:38:45 -070074Verify Eapol Flows Added
Andy Bavierb0c06232019-08-29 12:58:53 -070075 [Arguments] ${ip} ${port} ${expected_flows}
Kailash6f5acb62019-08-28 14:38:45 -070076 [Documentation] Matches for number of eapol flows based on number of onus
Kailash30c418f2019-09-11 13:50:10 -070077 ${eapol_flows_added}= Execute ONOS CLI Command ${ip} ${port} flows -s -f ADDED | grep eapol | grep IN_PORT | wc -l
Andy Bavierb0c06232019-08-29 12:58:53 -070078 Should Contain ${eapol_flows_added} ${expected_flows}
Kailash6f5acb62019-08-28 14:38:45 -070079
80Verify Number of AAA-Users
Kailash2b963f02019-08-28 22:46:33 -070081 [Arguments] ${ip} ${port} ${expected_onus}
Kailash6f5acb62019-08-28 14:38:45 -070082 [Documentation] Matches for number of aaa-users authorized based on number of onus
Kailash57210eb2019-08-30 13:27:19 -070083 ##TODO: filter by onu serial number instead of count
Kailash30c418f2019-09-11 13:50:10 -070084 ${aaa_users}= Execute ONOS CLI Command ${ip} ${port} aaa-users | grep AUTHORIZED | wc -l
Kailash6f5acb62019-08-28 14:38:45 -070085 Should Contain ${aaa_users} ${expected_onus}
86
87Validate DHCP Allocations
Kailash2b963f02019-08-28 22:46:33 -070088 [Arguments] ${ip} ${port} ${expected_onus}
Kailash6f5acb62019-08-28 14:38:45 -070089 [Documentation] Matches for number of dhcpacks based on number of onus
Kailash57210eb2019-08-30 13:27:19 -070090 ##TODO: filter by onu serial number instead of count
Kailash30c418f2019-09-11 13:50:10 -070091 ${allocations}= Execute ONOS CLI Command ${ip} ${port} dhcpl2relay-allocations | grep DHCPACK | wc -l
Suchitra Vemuri58766c92019-09-10 11:56:47 -070092 Should Contain ${allocations} ${expected_onus}