blob: 6f2347ff7135fffcb163610906e8803bad143c9b [file] [log] [blame]
Jonathan Hart249b4cf2017-02-03 18:02:58 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Jonathan Hart249b4cf2017-02-03 18:02:58 -08003 *
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.routing;
18
19import com.google.common.collect.ImmutableSet;
20import org.onosproject.net.ConnectPoint;
21import org.onosproject.net.DeviceId;
22import org.onosproject.routing.config.RoutersConfig;
23
24import java.util.Set;
25
26import static com.google.common.base.Preconditions.checkNotNull;
27
28/**
29 * Stores configuration information about a router.
30 */
31public class RouterInfo {
32
33 private final ConnectPoint controlPlaneConnectPoint;
34 private final boolean ospfEnabled;
35 private final Set<String> interfaces;
36
37 /**
38 * Creates a new router info.
39 *
40 * @param controlPlaneConnectPoint control plane connect point
41 * @param ospfEnabled whether OSPF is enabled
42 * @param interfaces set of interface names
43 */
44 public RouterInfo(ConnectPoint controlPlaneConnectPoint, boolean ospfEnabled, Set<String> interfaces) {
45 this.controlPlaneConnectPoint = checkNotNull(controlPlaneConnectPoint);
Yuta HIGUCHI1edc36b2018-01-24 23:39:06 -080046 this.ospfEnabled = ospfEnabled;
Jonathan Hart249b4cf2017-02-03 18:02:58 -080047 this.interfaces = ImmutableSet.copyOf(checkNotNull(interfaces));
48 }
49
50 /**
51 * Returns the control plane connect point.
52 *
53 * @return connect point
54 */
55 public ConnectPoint controlPlaneConnectPoint() {
56 return controlPlaneConnectPoint;
57 }
58
59 /**
60 * Returns the router device ID.
61 *
62 * @return device ID
63 */
64 public DeviceId deviceId() {
65 return controlPlaneConnectPoint.deviceId();
66 }
67
68 /**
69 * Returns whether OSPF is enabled on the router.
70 *
71 * @return OSPF enabled
72 */
73 public boolean ospfEnabled() {
74 return ospfEnabled;
75 }
76
77 /**
78 * Returns the set of interfaces belonging to the router.
79 *
80 * @return set of interface names
81 */
82 public Set<String> interfaces() {
83 return interfaces;
84 }
85
86 /**
87 * Creates a router info from a router config.
88 *
89 * @param config router config
90 * @return new router info object
91 */
92 public static RouterInfo from(RoutersConfig.Router config) {
93 return new RouterInfo(config.controlPlaneConnectPoint(), config.isOspfEnabled(), config.interfaces());
94 }
95}