blob: f24668f9a2d2582d3fc48cc63d1337dfa72a4287 [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.ConnectPoint;
21import org.onosproject.net.DeviceId;
22
23import java.util.Map;
24import java.util.Set;
25
26/**
27 * Represents Network Information Base (NIB) for edge ports
28 * and supports alternative functions to
29 * {@link org.onosproject.net.edge.EdgePortService} for offline data.
30 */
31public class EdgePortNib {
32
33 private Map<DeviceId, Set<ConnectPoint>> edgePorts;
34
35 // use the singleton helper to create the instance
36 protected EdgePortNib() {
37 }
38
39 /**
40 * Sets a map of device id : edge ports of the device.
41 *
42 * @param edgePorts device-edge ports map
43 */
44 public void setEdgePorts(Map<DeviceId, Set<ConnectPoint>> edgePorts) {
45 this.edgePorts = edgePorts;
46 }
47
48 /**
49 * Returns the device-edge ports map.
50 * @return device-edge ports map
51 */
52 public Map<DeviceId, Set<ConnectPoint>> getEdgePorts() {
53 return ImmutableMap.copyOf(edgePorts);
54 }
55
56 /**
57 * Indicates whether or not the specified connection point is an edge point.
58 *
59 * @param point connection point
60 * @return true if edge point
61 */
62 public boolean isEdgePoint(ConnectPoint point) {
63 Set<ConnectPoint> connectPoints = edgePorts.get(point.deviceId());
64 return connectPoints != null && connectPoints.contains(point);
65 }
66
67 /**
68 * Returns the singleton instance of edge ports NIB.
69 *
70 * @return instance of edge ports NIB
71 */
72 public static EdgePortNib getInstance() {
73 return EdgePortNib.SingletonHelper.INSTANCE;
74 }
75
76 private static class SingletonHelper {
77 private static final EdgePortNib INSTANCE = new EdgePortNib();
78 }
79
80}