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> {
}
return Optional.of(Short.parseShort(node.path(OVERRIDE_INTERVAL).asText()));
}
@Override
public boolean isValid() {
if (!hasOnlyFields(INTERFACE_NAME, ENABLED, HELLO_INTERVAL, HOLD_TIME,
PRIORITY, PROPAGATION_DELAY, OVERRIDE_INTERVAL)) {
return false;
}
return isString(INTERFACE_NAME, FieldPresence.MANDATORY) &&
isBoolean(ENABLED, FieldPresence.MANDATORY) &&
isIntegralNumber(HELLO_INTERVAL, FieldPresence.OPTIONAL) &&
isIntegralNumber(HOLD_TIME, FieldPresence.OPTIONAL) &&
isIntegralNumber(PRIORITY, FieldPresence.OPTIONAL) &&
isIntegralNumber(PROPAGATION_DELAY, FieldPresence.OPTIONAL) &&
isIntegralNumber(OVERRIDE_INTERVAL, FieldPresence.OPTIONAL);
}
}
......
......@@ -82,4 +82,19 @@ public class RouterConfig extends Config<ApplicationId> {
return interfaces;
}
@Override
public boolean isValid() {
if (!hasOnlyFields(INTERFACES, CP_CONNECT_POINT, OSPF_ENABLED, PIM_ENABLED)) {
return false;
}
JsonNode intfNode = object.path(INTERFACES);
if (!intfNode.isMissingNode() && !intfNode.isArray()) {
return false;
}
return isConnectPoint(CP_CONNECT_POINT, FieldPresence.MANDATORY) &&
isBoolean(OSPF_ENABLED, FieldPresence.OPTIONAL) &&
isBoolean(PIM_ENABLED, FieldPresence.OPTIONAL);
}
}
......
......@@ -22,6 +22,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.annotations.Beta;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import org.onosproject.incubator.net.intf.Interface;
......@@ -50,6 +51,31 @@ public class InterfaceConfig extends Config<ConnectPoint> {
private static final String INTF_NULL_ERROR = "Interface cannot be null";
private static final String INTF_NAME_ERROR = "Interface must have a valid name";
@Override
public boolean isValid() {
for (JsonNode node : array) {
if (!hasOnlyFields((ObjectNode) node, NAME, IPS, MAC, VLAN)) {
return false;
}
ObjectNode obj = (ObjectNode) node;
if (!(isString(obj, NAME, FieldPresence.OPTIONAL) &&
isMacAddress(obj, MAC, FieldPresence.OPTIONAL) &&
isIntegralNumber(obj, VLAN, FieldPresence.OPTIONAL, 0, VlanId.MAX_VLAN))) {
return false;
}
for (JsonNode ipNode : node.path(IPS)) {
if (!ipNode.isTextual() || IpPrefix.valueOf(ipNode.asText()) == null) {
return false;
}
}
}
return true;
}
/**
* Retrieves all interfaces configured on this port.
*
......