Jonathan Hart
Committed by Gerrit Code Review

Add config validation for vRouter and PIM configs

Change-Id: I97ddf4f745a19df6998b15ae47ebde5aa5f46238
...@@ -112,4 +112,20 @@ public class PimInterfaceConfig extends Config<ConnectPoint> { ...@@ -112,4 +112,20 @@ public class PimInterfaceConfig extends Config<ConnectPoint> {
112 } 112 }
113 return Optional.of(Short.parseShort(node.path(OVERRIDE_INTERVAL).asText())); 113 return Optional.of(Short.parseShort(node.path(OVERRIDE_INTERVAL).asText()));
114 } 114 }
115 +
116 + @Override
117 + public boolean isValid() {
118 + if (!hasOnlyFields(INTERFACE_NAME, ENABLED, HELLO_INTERVAL, HOLD_TIME,
119 + PRIORITY, PROPAGATION_DELAY, OVERRIDE_INTERVAL)) {
120 + return false;
121 + }
122 +
123 + return isString(INTERFACE_NAME, FieldPresence.MANDATORY) &&
124 + isBoolean(ENABLED, FieldPresence.MANDATORY) &&
125 + isIntegralNumber(HELLO_INTERVAL, FieldPresence.OPTIONAL) &&
126 + isIntegralNumber(HOLD_TIME, FieldPresence.OPTIONAL) &&
127 + isIntegralNumber(PRIORITY, FieldPresence.OPTIONAL) &&
128 + isIntegralNumber(PROPAGATION_DELAY, FieldPresence.OPTIONAL) &&
129 + isIntegralNumber(OVERRIDE_INTERVAL, FieldPresence.OPTIONAL);
130 + }
115 } 131 }
......
...@@ -82,4 +82,19 @@ public class RouterConfig extends Config<ApplicationId> { ...@@ -82,4 +82,19 @@ public class RouterConfig extends Config<ApplicationId> {
82 return interfaces; 82 return interfaces;
83 } 83 }
84 84
85 + @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 + }
85 } 100 }
......
...@@ -22,6 +22,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode; ...@@ -22,6 +22,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
22 import com.google.common.annotations.Beta; 22 import com.google.common.annotations.Beta;
23 import com.google.common.collect.Lists; 23 import com.google.common.collect.Lists;
24 import com.google.common.collect.Sets; 24 import com.google.common.collect.Sets;
25 +import org.onlab.packet.IpPrefix;
25 import org.onlab.packet.MacAddress; 26 import org.onlab.packet.MacAddress;
26 import org.onlab.packet.VlanId; 27 import org.onlab.packet.VlanId;
27 import org.onosproject.incubator.net.intf.Interface; 28 import org.onosproject.incubator.net.intf.Interface;
...@@ -50,6 +51,31 @@ public class InterfaceConfig extends Config<ConnectPoint> { ...@@ -50,6 +51,31 @@ public class InterfaceConfig extends Config<ConnectPoint> {
50 private static final String INTF_NULL_ERROR = "Interface cannot be null"; 51 private static final String INTF_NULL_ERROR = "Interface cannot be null";
51 private static final String INTF_NAME_ERROR = "Interface must have a valid name"; 52 private static final String INTF_NAME_ERROR = "Interface must have a valid name";
52 53
54 + @Override
55 + public boolean isValid() {
56 + for (JsonNode node : array) {
57 + if (!hasOnlyFields((ObjectNode) node, NAME, IPS, MAC, VLAN)) {
58 + return false;
59 + }
60 +
61 + ObjectNode obj = (ObjectNode) node;
62 +
63 + if (!(isString(obj, NAME, FieldPresence.OPTIONAL) &&
64 + isMacAddress(obj, MAC, FieldPresence.OPTIONAL) &&
65 + isIntegralNumber(obj, VLAN, FieldPresence.OPTIONAL, 0, VlanId.MAX_VLAN))) {
66 + return false;
67 + }
68 +
69 +
70 + for (JsonNode ipNode : node.path(IPS)) {
71 + if (!ipNode.isTextual() || IpPrefix.valueOf(ipNode.asText()) == null) {
72 + return false;
73 + }
74 + }
75 + }
76 + return true;
77 + }
78 +
53 /** 79 /**
54 * Retrieves all interfaces configured on this port. 80 * Retrieves all interfaces configured on this port.
55 * 81 *
......