blob: f2e6e8dc7de5e16ba8fda7d761d0fcf49f242951 [file] [log] [blame]
Carmelo Casconeab5d41e2019-03-06 18:02:34 -08001/*
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
17package org.onosproject.drivers.stratum;
18
19import org.onosproject.drivers.gnmi.OpenConfigGnmiDeviceDescriptionDiscovery;
oleksandr.yashchuk@plvision.eu3dbcaaf2019-03-13 14:44:46 +020020import org.onosproject.drivers.gnoi.GnoiDeviceDescriptionDiscovery;
Carmelo Casconeab5d41e2019-03-06 18:02:34 -080021import org.onosproject.drivers.p4runtime.P4RuntimeDeviceDescriptionDiscovery;
22import org.onosproject.net.AnnotationKeys;
23import org.onosproject.net.DefaultAnnotations;
24import org.onosproject.net.Device;
25import org.onosproject.net.device.DefaultDeviceDescription;
26import org.onosproject.net.device.DeviceDescription;
27import org.onosproject.net.device.DeviceDescriptionDiscovery;
28import org.onosproject.net.device.PortDescription;
29
30import java.util.List;
31
32import static java.lang.String.format;
33
34/**
35 * Implementation of DeviceDescriptionDiscovery for Stratum devices.
36 */
37public 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.eu3dbcaaf2019-03-13 14:44:46 +020046 new OpenConfigGnmiDeviceDescriptionDiscovery(),
47 new GnoiDeviceDescriptionDiscovery());
Carmelo Casconeab5d41e2019-03-06 18:02:34 -080048 }
49
50 @Override
51 public DeviceDescription discoverDeviceDetails() {
52 final DeviceDescription p4Descr = p4runtime.discoverDeviceDetails();
oleksandr.yashchuk@plvision.eu3dbcaaf2019-03-13 14:44:46 +020053 final DeviceDescription gnoiDescr = gnoi.discoverDeviceDetails();
Carmelo Casconeab5d41e2019-03-06 18:02:34 -080054 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.eu3dbcaaf2019-03-13 14:44:46 +020067 "%s, %s, %s",
Carmelo Casconeab5d41e2019-03-06 18:02:34 -080068 p4Descr.annotations().value(AnnotationKeys.PROTOCOL),
oleksandr.yashchuk@plvision.eu3dbcaaf2019-03-13 14:44:46 +020069 gnoiDescr.annotations().value(AnnotationKeys.PROTOCOL),
Carmelo Casconeab5d41e2019-03-06 18:02:34 -080070 gnmiDescr.annotations().value(AnnotationKeys.PROTOCOL)))
71 .build());
72 }
73
74 @Override
75 public List<PortDescription> discoverPortDetails() {
76 return gnmi.discoverPortDetails();
77 }
78}