Committed by
Jonathan Hart
Added validation check for access agent config
Addressed comments in https://gerrit.onosproject.org/#/c/8959/ Change-Id: I3f730042ea31d7f4183985991fe5b4e630572521
Showing
1 changed file
with
38 additions
and
3 deletions
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 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 | + | ||
| 1 | package org.onosproject.cordconfig.access; | 17 | package org.onosproject.cordconfig.access; |
| 2 | 18 | ||
| 3 | import com.fasterxml.jackson.databind.JsonNode; | 19 | import com.fasterxml.jackson.databind.JsonNode; |
| 20 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
| 21 | +import com.google.common.collect.Iterators; | ||
| 4 | import com.google.common.collect.Maps; | 22 | import com.google.common.collect.Maps; |
| 23 | +import org.apache.commons.lang.StringUtils; | ||
| 5 | import org.onlab.packet.MacAddress; | 24 | import org.onlab.packet.MacAddress; |
| 6 | import org.onosproject.net.ConnectPoint; | 25 | import org.onosproject.net.ConnectPoint; |
| 7 | import org.onosproject.net.DeviceId; | 26 | import org.onosproject.net.DeviceId; |
| ... | @@ -11,6 +30,9 @@ import org.onosproject.net.config.Config; | ... | @@ -11,6 +30,9 @@ import org.onosproject.net.config.Config; |
| 11 | import java.util.Map; | 30 | import java.util.Map; |
| 12 | import java.util.Optional; | 31 | import java.util.Optional; |
| 13 | 32 | ||
| 33 | +import static org.onosproject.net.config.Config.FieldPresence.MANDATORY; | ||
| 34 | +import static org.onosproject.net.config.Config.FieldPresence.OPTIONAL; | ||
| 35 | + | ||
| 14 | /** | 36 | /** |
| 15 | * Represents configuration for an OLT agent. | 37 | * Represents configuration for an OLT agent. |
| 16 | */ | 38 | */ |
| ... | @@ -22,6 +44,14 @@ public class AccessAgentConfig extends Config<DeviceId> { | ... | @@ -22,6 +44,14 @@ public class AccessAgentConfig extends Config<DeviceId> { |
| 22 | // TODO: Remove this, it is only useful as long as XOS doesn't manage this. | 44 | // TODO: Remove this, it is only useful as long as XOS doesn't manage this. |
| 23 | private static final String VTN_LOCATION = "vtn-location"; | 45 | private static final String VTN_LOCATION = "vtn-location"; |
| 24 | 46 | ||
| 47 | + @Override | ||
| 48 | + public boolean isValid() { | ||
| 49 | + return hasOnlyFields(OLTS, AGENT_MAC, VTN_LOCATION) && | ||
| 50 | + isMacAddress(AGENT_MAC, MANDATORY) && | ||
| 51 | + isConnectPoint(VTN_LOCATION, OPTIONAL) && | ||
| 52 | + isValidOlts(); | ||
| 53 | + } | ||
| 54 | + | ||
| 25 | /** | 55 | /** |
| 26 | * Gets the access agent configuration for this device. | 56 | * Gets the access agent configuration for this device. |
| 27 | * | 57 | * |
| ... | @@ -29,9 +59,6 @@ public class AccessAgentConfig extends Config<DeviceId> { | ... | @@ -29,9 +59,6 @@ public class AccessAgentConfig extends Config<DeviceId> { |
| 29 | */ | 59 | */ |
| 30 | public AccessAgentData getAgent() { | 60 | public AccessAgentData getAgent() { |
| 31 | JsonNode olts = node.get(OLTS); | 61 | JsonNode olts = node.get(OLTS); |
| 32 | - if (!olts.isObject()) { | ||
| 33 | - throw new IllegalArgumentException(OLTS + " should be an object"); | ||
| 34 | - } | ||
| 35 | Map<ConnectPoint, MacAddress> oltMacInfo = Maps.newHashMap(); | 62 | Map<ConnectPoint, MacAddress> oltMacInfo = Maps.newHashMap(); |
| 36 | olts.fields().forEachRemaining(item -> oltMacInfo.put( | 63 | olts.fields().forEachRemaining(item -> oltMacInfo.put( |
| 37 | new ConnectPoint(subject(), PortNumber.fromString(item.getKey())), | 64 | new ConnectPoint(subject(), PortNumber.fromString(item.getKey())), |
| ... | @@ -50,4 +77,12 @@ public class AccessAgentConfig extends Config<DeviceId> { | ... | @@ -50,4 +77,12 @@ public class AccessAgentConfig extends Config<DeviceId> { |
| 50 | return new AccessAgentData(subject(), oltMacInfo, agentMac, vtnLocation); | 77 | return new AccessAgentData(subject(), oltMacInfo, agentMac, vtnLocation); |
| 51 | } | 78 | } |
| 52 | 79 | ||
| 80 | + private boolean isValidOlts() { | ||
| 81 | + JsonNode olts = node.get(OLTS); | ||
| 82 | + if (!olts.isObject()) { | ||
| 83 | + return false; | ||
| 84 | + } | ||
| 85 | + return !Iterators.any(olts.fields(), item -> !StringUtils.isNumeric(item.getKey()) || | ||
| 86 | + !isMacAddress((ObjectNode) olts, item.getKey(), MANDATORY)); | ||
| 87 | + } | ||
| 53 | } | 88 | } | ... | ... |
-
Please register or login to post a comment