Jonathan Hart | 249b4cf | 2017-02-03 18:02:58 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Laboratory |
| 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 | |
| 17 | package org.onosproject.routing; |
| 18 | |
| 19 | import com.google.common.collect.ImmutableSet; |
| 20 | import org.onosproject.net.ConnectPoint; |
| 21 | import org.onosproject.net.DeviceId; |
| 22 | import org.onosproject.routing.config.RoutersConfig; |
| 23 | |
| 24 | import java.util.Set; |
| 25 | |
| 26 | import static com.google.common.base.Preconditions.checkNotNull; |
| 27 | |
| 28 | /** |
| 29 | * Stores configuration information about a router. |
| 30 | */ |
| 31 | public 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); |
| 46 | this.ospfEnabled = checkNotNull(ospfEnabled); |
| 47 | 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 | } |