blob: 622a1875d17a74287e324710b4867dc8b9d33b61 [file] [log] [blame]
Seyeon Jeong8d3cad22020-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.ImmutableSet;
20import org.onosproject.net.ConnectPoint;
21import org.onosproject.net.Link;
22
23import java.util.Set;
24import java.util.stream.Collectors;
25
26/**
27 * Represents Network Information Base (NIB) for links
28 * and supports alternative functions to
29 * {@link org.onosproject.net.link.LinkService} for offline data.
30 */
Seyeon Jeongac129562020-02-28 01:17:34 -080031public class LinkNib extends AbstractNib {
Seyeon Jeong8d3cad22020-02-28 01:17:34 -080032
33 // TODO with method optimization, store into subdivided structures at the first load
34 private Set<Link> links;
35
36 // use the singleton helper to create the instance
37 protected LinkNib() {
38 }
39
40 /**
41 * Sets a set of links.
42 *
43 * @param links link set
44 */
45 public void setLinks(Set<Link> links) {
46 this.links = links;
47 }
48
49 /**
50 * Returns the set of links.
51 *
52 * @return link set
53 */
54 public Set<Link> getLinks() {
55 return ImmutableSet.copyOf(links);
56 }
57
58 /**
59 * Returns set of all infrastructure links leading from the specified
60 * connection point.
61 *
62 * @param connectPoint connection point
63 * @return set of device egress links
64 */
65 public Set<Link> getEgressLinks(ConnectPoint connectPoint) {
66 Set<Link> egressLinks = links.stream()
67 .filter(link -> connectPoint.equals(link.src()))
68 .collect(Collectors.toSet());
69 return egressLinks != null ? ImmutableSet.copyOf(egressLinks) : ImmutableSet.of();
70 }
71
72 /**
73 * Returns the singleton instance of links NIB.
74 *
75 * @return instance of links NIB
76 */
77 public static LinkNib getInstance() {
78 return LinkNib.SingletonHelper.INSTANCE;
79 }
80
81 private static class SingletonHelper {
82 private static final LinkNib INSTANCE = new LinkNib();
83 }
84
85}