blob: a089a342ff3ced311e75809cc6763573107c7720 [file] [log] [blame]
Jonathan Hart6344f572015-12-15 08:26:25 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Jonathan Hart6344f572015-12-15 08:26:25 -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.config;
18
Jonathan Hart883fd372016-02-10 14:36:15 -080019import com.fasterxml.jackson.databind.JsonNode;
20import com.fasterxml.jackson.databind.node.ArrayNode;
Jonathan Hart6344f572015-12-15 08:26:25 -080021import org.onosproject.core.ApplicationId;
22import org.onosproject.net.ConnectPoint;
23import org.onosproject.net.config.Config;
24
Jonathan Hart883fd372016-02-10 14:36:15 -080025import java.util.ArrayList;
26import java.util.Collections;
27import java.util.List;
28
Jonathan Hart6344f572015-12-15 08:26:25 -080029/**
30 * Routing configuration.
Jonathan Harta7a24cf2017-02-02 16:13:57 -080031 *
32 * @deprecated in Junco release. Use RoutersConfig instead.
Jonathan Hart6344f572015-12-15 08:26:25 -080033 */
Jonathan Harta7a24cf2017-02-02 16:13:57 -080034@Deprecated
Jonathan Hart6344f572015-12-15 08:26:25 -080035public class RouterConfig extends Config<ApplicationId> {
36
Jonathan Hartea492382016-01-13 09:33:13 -080037 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 Hart883fd372016-02-10 14:36:15 -080040 private static final String INTERFACES = "interfaces";
Jonathan Hart6344f572015-12-15 08:26:25 -080041
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 Hartea492382016-01-13 09:33:13 -080050
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 Hart883fd372016-02-10 14:36:15 -080068
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 Hart9eb45bb2016-02-12 10:59:11 -080088 @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 Hart6344f572015-12-15 08:26:25 -0800103}