Jonathan Hart | 6344f57 | 2015-12-15 08:26:25 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Jonathan Hart | 6344f57 | 2015-12-15 08:26:25 -0800 | [diff] [blame] | 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.config; |
| 18 | |
Jonathan Hart | 883fd37 | 2016-02-10 14:36:15 -0800 | [diff] [blame] | 19 | import com.fasterxml.jackson.databind.JsonNode; |
| 20 | import com.fasterxml.jackson.databind.node.ArrayNode; |
Jonathan Hart | 6344f57 | 2015-12-15 08:26:25 -0800 | [diff] [blame] | 21 | import org.onosproject.core.ApplicationId; |
| 22 | import org.onosproject.net.ConnectPoint; |
| 23 | import org.onosproject.net.config.Config; |
| 24 | |
Jonathan Hart | 883fd37 | 2016-02-10 14:36:15 -0800 | [diff] [blame] | 25 | import java.util.ArrayList; |
| 26 | import java.util.Collections; |
| 27 | import java.util.List; |
| 28 | |
Jonathan Hart | 6344f57 | 2015-12-15 08:26:25 -0800 | [diff] [blame] | 29 | /** |
| 30 | * Routing configuration. |
Jonathan Hart | a7a24cf | 2017-02-02 16:13:57 -0800 | [diff] [blame] | 31 | * |
| 32 | * @deprecated in Junco release. Use RoutersConfig instead. |
Jonathan Hart | 6344f57 | 2015-12-15 08:26:25 -0800 | [diff] [blame] | 33 | */ |
Jonathan Hart | a7a24cf | 2017-02-02 16:13:57 -0800 | [diff] [blame] | 34 | @Deprecated |
Jonathan Hart | 6344f57 | 2015-12-15 08:26:25 -0800 | [diff] [blame] | 35 | public class RouterConfig extends Config<ApplicationId> { |
| 36 | |
Jonathan Hart | ea49238 | 2016-01-13 09:33:13 -0800 | [diff] [blame] | 37 | private static final String CP_CONNECT_POINT = "controlPlaneConnectPoint"; |
| 38 | private static final String OSPF_ENABLED = "ospfEnabled"; |
| 39 | private static final String PIM_ENABLED = "pimEnabled"; |
Jonathan Hart | 883fd37 | 2016-02-10 14:36:15 -0800 | [diff] [blame] | 40 | private static final String INTERFACES = "interfaces"; |
Jonathan Hart | 6344f57 | 2015-12-15 08:26:25 -0800 | [diff] [blame] | 41 | |
| 42 | /** |
| 43 | * Returns the routing control plane connect point. |
| 44 | * |
| 45 | * @return control plane connect point |
| 46 | */ |
| 47 | public ConnectPoint getControlPlaneConnectPoint() { |
| 48 | return ConnectPoint.deviceConnectPoint(object.path(CP_CONNECT_POINT).asText()); |
| 49 | } |
Jonathan Hart | ea49238 | 2016-01-13 09:33:13 -0800 | [diff] [blame] | 50 | |
| 51 | /** |
| 52 | * Returns whether OSPF is enabled on this router. |
| 53 | * |
| 54 | * @return true if OSPF is enabled, otherwise false |
| 55 | */ |
| 56 | public boolean getOspfEnabled() { |
| 57 | return object.path(OSPF_ENABLED).asBoolean(false); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Returns whether PIM is enabled on this router. |
| 62 | * |
| 63 | * @return true if PIM is enabled, otherwise false |
| 64 | */ |
| 65 | public boolean pimEnabled() { |
| 66 | return object.path(PIM_ENABLED).asBoolean(false); |
| 67 | } |
Jonathan Hart | 883fd37 | 2016-02-10 14:36:15 -0800 | [diff] [blame] | 68 | |
| 69 | /** |
| 70 | * Returns the list of interfaces enabled on this router. |
| 71 | * |
| 72 | * @return list of interface names that are enabled, or an empty list if |
| 73 | * all available interfaces should be used |
| 74 | */ |
| 75 | public List<String> getInterfaces() { |
| 76 | JsonNode intfNode = object.path(INTERFACES); |
| 77 | if (intfNode.isMissingNode() || !intfNode.isArray()) { |
| 78 | return Collections.emptyList(); |
| 79 | } |
| 80 | ArrayNode array = (ArrayNode) intfNode; |
| 81 | List<String> interfaces = new ArrayList<>(array.size()); |
| 82 | for (JsonNode intf : array) { |
| 83 | interfaces.add(intf.asText()); |
| 84 | } |
| 85 | return interfaces; |
| 86 | } |
| 87 | |
Jonathan Hart | 9eb45bb | 2016-02-12 10:59:11 -0800 | [diff] [blame] | 88 | @Override |
| 89 | public boolean isValid() { |
| 90 | if (!hasOnlyFields(INTERFACES, CP_CONNECT_POINT, OSPF_ENABLED, PIM_ENABLED)) { |
| 91 | return false; |
| 92 | } |
| 93 | |
| 94 | JsonNode intfNode = object.path(INTERFACES); |
| 95 | if (!intfNode.isMissingNode() && !intfNode.isArray()) { |
| 96 | return false; |
| 97 | } |
| 98 | |
| 99 | return isConnectPoint(CP_CONNECT_POINT, FieldPresence.MANDATORY) && |
| 100 | isBoolean(OSPF_ENABLED, FieldPresence.OPTIONAL) && |
| 101 | isBoolean(PIM_ENABLED, FieldPresence.OPTIONAL); |
| 102 | } |
Jonathan Hart | 6344f57 | 2015-12-15 08:26:25 -0800 | [diff] [blame] | 103 | } |