blob: 4c88a20a87fef7d050297976a7c8ee65f395c083 [file] [log] [blame]
Seyeon Jeong357bcec2020-02-28 01:17:34 -08001/*
2 * Copyright 2020-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.t3.api;
18
19import com.google.common.collect.ImmutableMap;
20import org.onosproject.net.DeviceId;
21
22import java.util.Map;
23
24/**
25 * Represents Network Information Base (NIB) for drivers
26 * and supports alternative functions to
27 * {@link org.onosproject.net.driver.DriverService} for offline data.
28 */
29public class DriverNib {
30
31 private Map<DeviceId, String> deviceDriverMap;
32
33 // use the singleton helper to create the instance
34 protected DriverNib() {
35 }
36
37 /**
38 * Sets a map of device id : driver name.
39 *
40 * @param deviceDriverMap device-driver map
41 */
42 public void setDeviceDriverMap(Map<DeviceId, String> deviceDriverMap) {
43 this.deviceDriverMap = deviceDriverMap;
44 }
45
46 /**
47 * Returns the device-driver map.
48 *
49 * @return device-driver map
50 */
51 public Map<DeviceId, String> getDeviceDriverMap() {
52 return ImmutableMap.copyOf(deviceDriverMap);
53 }
54
55 /**
56 * Returns a driver name of the given device.
57 *
58 * @param deviceId the device id
59 * @return the driver name
60 */
61 public String getDriverName(DeviceId deviceId) {
62 return deviceDriverMap.get(deviceId);
63 }
64
65 /**
66 * Returns the singleton instance of drivers NIB.
67 *
68 * @return instance of drivers NIB
69 */
70 public static DriverNib getInstance() {
71 return DriverNib.SingletonHelper.INSTANCE;
72 }
73
74 private static class SingletonHelper {
75 private static final DriverNib INSTANCE = new DriverNib();
76 }
77
78}