Carmelo Cascone | ab5d41e | 2019-03-06 18:02:34 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.drivers.stratum; |
| 18 | |
| 19 | import org.onosproject.drivers.gnmi.OpenConfigGnmiDeviceDescriptionDiscovery; |
oleksandr.yashchuk@plvision.eu | 3dbcaaf | 2019-03-13 14:44:46 +0200 | [diff] [blame^] | 20 | import org.onosproject.drivers.gnoi.GnoiDeviceDescriptionDiscovery; |
Carmelo Cascone | ab5d41e | 2019-03-06 18:02:34 -0800 | [diff] [blame] | 21 | import org.onosproject.drivers.p4runtime.P4RuntimeDeviceDescriptionDiscovery; |
| 22 | import org.onosproject.net.AnnotationKeys; |
| 23 | import org.onosproject.net.DefaultAnnotations; |
| 24 | import org.onosproject.net.Device; |
| 25 | import org.onosproject.net.device.DefaultDeviceDescription; |
| 26 | import org.onosproject.net.device.DeviceDescription; |
| 27 | import org.onosproject.net.device.DeviceDescriptionDiscovery; |
| 28 | import org.onosproject.net.device.PortDescription; |
| 29 | |
| 30 | import java.util.List; |
| 31 | |
| 32 | import static java.lang.String.format; |
| 33 | |
| 34 | /** |
| 35 | * Implementation of DeviceDescriptionDiscovery for Stratum devices. |
| 36 | */ |
| 37 | public class StratumDeviceDescriptionDiscovery |
| 38 | extends AbstractStratumBehaviour<DeviceDescriptionDiscovery> |
| 39 | implements DeviceDescriptionDiscovery { |
| 40 | |
| 41 | private static final String UNKNOWN = "unknown"; |
| 42 | |
| 43 | |
| 44 | public StratumDeviceDescriptionDiscovery() { |
| 45 | super(new P4RuntimeDeviceDescriptionDiscovery(), |
oleksandr.yashchuk@plvision.eu | 3dbcaaf | 2019-03-13 14:44:46 +0200 | [diff] [blame^] | 46 | new OpenConfigGnmiDeviceDescriptionDiscovery(), |
| 47 | new GnoiDeviceDescriptionDiscovery()); |
Carmelo Cascone | ab5d41e | 2019-03-06 18:02:34 -0800 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public DeviceDescription discoverDeviceDetails() { |
| 52 | final DeviceDescription p4Descr = p4runtime.discoverDeviceDetails(); |
oleksandr.yashchuk@plvision.eu | 3dbcaaf | 2019-03-13 14:44:46 +0200 | [diff] [blame^] | 53 | final DeviceDescription gnoiDescr = gnoi.discoverDeviceDetails(); |
Carmelo Cascone | ab5d41e | 2019-03-06 18:02:34 -0800 | [diff] [blame] | 54 | final DeviceDescription gnmiDescr = gnmi.discoverDeviceDetails(); |
| 55 | return new DefaultDeviceDescription( |
| 56 | data().deviceId().uri(), |
| 57 | Device.Type.SWITCH, |
| 58 | data().driver().manufacturer(), |
| 59 | data().driver().hwVersion(), |
| 60 | data().driver().swVersion(), |
| 61 | UNKNOWN, |
| 62 | p4Descr.chassisId(), |
| 63 | // Availability is mandated by P4Runtime. |
| 64 | p4Descr.isDefaultAvailable(), |
| 65 | DefaultAnnotations.builder() |
| 66 | .set(AnnotationKeys.PROTOCOL, format( |
oleksandr.yashchuk@plvision.eu | 3dbcaaf | 2019-03-13 14:44:46 +0200 | [diff] [blame^] | 67 | "%s, %s, %s", |
Carmelo Cascone | ab5d41e | 2019-03-06 18:02:34 -0800 | [diff] [blame] | 68 | p4Descr.annotations().value(AnnotationKeys.PROTOCOL), |
oleksandr.yashchuk@plvision.eu | 3dbcaaf | 2019-03-13 14:44:46 +0200 | [diff] [blame^] | 69 | gnoiDescr.annotations().value(AnnotationKeys.PROTOCOL), |
Carmelo Cascone | ab5d41e | 2019-03-06 18:02:34 -0800 | [diff] [blame] | 70 | gnmiDescr.annotations().value(AnnotationKeys.PROTOCOL))) |
| 71 | .build()); |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public List<PortDescription> discoverPortDetails() { |
| 76 | return gnmi.discoverPortDetails(); |
| 77 | } |
| 78 | } |