blob: ae8c9fa868dfb82e3f1c8118867970e062ef6e1d [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.
31 */
32public class RouterConfig extends Config<ApplicationId> {
33
Jonathan Hartea492382016-01-13 09:33:13 -080034 private static final String CP_CONNECT_POINT = "controlPlaneConnectPoint";
35 private static final String OSPF_ENABLED = "ospfEnabled";
36 private static final String PIM_ENABLED = "pimEnabled";
Jonathan Hart883fd372016-02-10 14:36:15 -080037 private static final String INTERFACES = "interfaces";
Jonathan Hart6344f572015-12-15 08:26:25 -080038
39 /**
40 * Returns the routing control plane connect point.
41 *
42 * @return control plane connect point
43 */
44 public ConnectPoint getControlPlaneConnectPoint() {
45 return ConnectPoint.deviceConnectPoint(object.path(CP_CONNECT_POINT).asText());
46 }
Jonathan Hartea492382016-01-13 09:33:13 -080047
48 /**
49 * Returns whether OSPF is enabled on this router.
50 *
51 * @return true if OSPF is enabled, otherwise false
52 */
53 public boolean getOspfEnabled() {
54 return object.path(OSPF_ENABLED).asBoolean(false);
55 }
56
57 /**
58 * Returns whether PIM is enabled on this router.
59 *
60 * @return true if PIM is enabled, otherwise false
61 */
62 public boolean pimEnabled() {
63 return object.path(PIM_ENABLED).asBoolean(false);
64 }
Jonathan Hart883fd372016-02-10 14:36:15 -080065
66 /**
67 * Returns the list of interfaces enabled on this router.
68 *
69 * @return list of interface names that are enabled, or an empty list if
70 * all available interfaces should be used
71 */
72 public List<String> getInterfaces() {
73 JsonNode intfNode = object.path(INTERFACES);
74 if (intfNode.isMissingNode() || !intfNode.isArray()) {
75 return Collections.emptyList();
76 }
77 ArrayNode array = (ArrayNode) intfNode;
78 List<String> interfaces = new ArrayList<>(array.size());
79 for (JsonNode intf : array) {
80 interfaces.add(intf.asText());
81 }
82 return interfaces;
83 }
84
Jonathan Hart9eb45bb2016-02-12 10:59:11 -080085 @Override
86 public boolean isValid() {
87 if (!hasOnlyFields(INTERFACES, CP_CONNECT_POINT, OSPF_ENABLED, PIM_ENABLED)) {
88 return false;
89 }
90
91 JsonNode intfNode = object.path(INTERFACES);
92 if (!intfNode.isMissingNode() && !intfNode.isArray()) {
93 return false;
94 }
95
96 return isConnectPoint(CP_CONNECT_POINT, FieldPresence.MANDATORY) &&
97 isBoolean(OSPF_ENABLED, FieldPresence.OPTIONAL) &&
98 isBoolean(PIM_ENABLED, FieldPresence.OPTIONAL);
99 }
Jonathan Hart6344f572015-12-15 08:26:25 -0800100}