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; |
| 20 | import org.onosproject.drivers.p4runtime.P4RuntimeDeviceDescriptionDiscovery; |
| 21 | import org.onosproject.net.AnnotationKeys; |
| 22 | import org.onosproject.net.DefaultAnnotations; |
| 23 | import org.onosproject.net.Device; |
| 24 | import org.onosproject.net.device.DefaultDeviceDescription; |
| 25 | import org.onosproject.net.device.DeviceDescription; |
| 26 | import org.onosproject.net.device.DeviceDescriptionDiscovery; |
| 27 | import org.onosproject.net.device.PortDescription; |
| 28 | |
| 29 | import java.util.List; |
| 30 | |
| 31 | import static java.lang.String.format; |
| 32 | |
| 33 | /** |
| 34 | * Implementation of DeviceDescriptionDiscovery for Stratum devices. |
| 35 | */ |
| 36 | public class StratumDeviceDescriptionDiscovery |
| 37 | extends AbstractStratumBehaviour<DeviceDescriptionDiscovery> |
| 38 | implements DeviceDescriptionDiscovery { |
| 39 | |
| 40 | private static final String UNKNOWN = "unknown"; |
| 41 | |
| 42 | |
| 43 | public StratumDeviceDescriptionDiscovery() { |
| 44 | super(new P4RuntimeDeviceDescriptionDiscovery(), |
| 45 | new OpenConfigGnmiDeviceDescriptionDiscovery()); |
| 46 | } |
| 47 | |
| 48 | @Override |
| 49 | public DeviceDescription discoverDeviceDetails() { |
| 50 | final DeviceDescription p4Descr = p4runtime.discoverDeviceDetails(); |
| 51 | final DeviceDescription gnmiDescr = gnmi.discoverDeviceDetails(); |
| 52 | return new DefaultDeviceDescription( |
| 53 | data().deviceId().uri(), |
| 54 | Device.Type.SWITCH, |
| 55 | data().driver().manufacturer(), |
| 56 | data().driver().hwVersion(), |
| 57 | data().driver().swVersion(), |
| 58 | UNKNOWN, |
| 59 | p4Descr.chassisId(), |
| 60 | // Availability is mandated by P4Runtime. |
| 61 | p4Descr.isDefaultAvailable(), |
| 62 | DefaultAnnotations.builder() |
| 63 | .set(AnnotationKeys.PROTOCOL, format( |
| 64 | "%s, %s", |
| 65 | p4Descr.annotations().value(AnnotationKeys.PROTOCOL), |
| 66 | gnmiDescr.annotations().value(AnnotationKeys.PROTOCOL))) |
| 67 | .build()); |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public List<PortDescription> discoverPortDetails() { |
| 72 | return gnmi.discoverPortDetails(); |
| 73 | } |
| 74 | } |