blob: 4b3dba9aa844b4f2bc0d8de892f6b21302da509f [file] [log] [blame]
Carmelo Cascone3977ea42019-02-28 13:43:42 -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.p4runtime;
18
19import org.onlab.packet.ChassisId;
20import org.onosproject.net.AnnotationKeys;
21import org.onosproject.net.DefaultAnnotations;
22import org.onosproject.net.Device;
23import org.onosproject.net.device.DefaultDeviceDescription;
24import org.onosproject.net.device.DeviceDescription;
25import org.onosproject.net.device.DeviceDescriptionDiscovery;
26import org.onosproject.net.device.PortDescription;
Carmelo Cascone3977ea42019-02-28 13:43:42 -080027
28import java.util.Collections;
29import java.util.List;
30
Carmelo Casconec2be50a2019-04-10 00:15:39 -070031import static org.onosproject.drivers.p4runtime.P4RuntimeDriverUtils.extractP4DeviceId;
32
Carmelo Cascone3977ea42019-02-28 13:43:42 -080033/**
34 * Implementation of DeviceDescriptionDiscovery for P4Runtime devices.
35 */
36public class P4RuntimeDeviceDescriptionDiscovery
Carmelo Casconec2be50a2019-04-10 00:15:39 -070037 extends AbstractP4RuntimeHandlerBehaviour
38 implements DeviceDescriptionDiscovery {
Carmelo Cascone3977ea42019-02-28 13:43:42 -080039
40 private static final String UNKNOWN = "unknown";
Carmelo Casconec2be50a2019-04-10 00:15:39 -070041 private static final String P4_DEVICE_ID = "p4DeviceId";
Carmelo Cascone3977ea42019-02-28 13:43:42 -080042
43 @Override
44 public DeviceDescription discoverDeviceDetails() {
Carmelo Casconec2be50a2019-04-10 00:15:39 -070045 final Long p4DeviceId = extractP4DeviceId(mgmtUriFromNetcfg());
Carmelo Cascone3977ea42019-02-28 13:43:42 -080046 return new DefaultDeviceDescription(
47 data().deviceId().uri(),
48 Device.Type.SWITCH,
49 data().driver().manufacturer(),
50 data().driver().hwVersion(),
51 data().driver().swVersion(),
52 UNKNOWN,
53 new ChassisId(),
54 false,
55 DefaultAnnotations.builder()
Carmelo Casconec2be50a2019-04-10 00:15:39 -070056 .set(P4_DEVICE_ID, p4DeviceId == null
57 ? UNKNOWN : String.valueOf(p4DeviceId))
Carmelo Cascone3977ea42019-02-28 13:43:42 -080058 .set(AnnotationKeys.PROTOCOL, "P4Runtime")
59 .build());
60 }
61
62 @Override
63 public List<PortDescription> discoverPortDetails() {
64 return Collections.emptyList();
65 }
66}