diff options
Diffstat (limited to 'v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/pbb')
-rw-r--r-- | v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/pbb/PbbRewriteCustomizer.java | 33 | ||||
-rw-r--r-- | v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/pbb/PbbRewriteValidator.java | 82 |
2 files changed, 89 insertions, 26 deletions
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/pbb/PbbRewriteCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/pbb/PbbRewriteCustomizer.java index 13fccf7dd..86622663d 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/pbb/PbbRewriteCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/pbb/PbbRewriteCustomizer.java @@ -16,8 +16,6 @@ package io.fd.hc2vpp.v3po.interfaces.pbb; -import static com.google.common.base.Preconditions.checkNotNull; - import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; import io.fd.hc2vpp.common.translate.util.MacTranslator; @@ -44,7 +42,7 @@ public class PbbRewriteCustomizer extends FutureJVppCustomizer public PbbRewriteCustomizer(@Nonnull final FutureJVppCore futureJVppCore, @Nonnull final NamingContext interfaceNamingContext) { super(futureJVppCore); - this.interfaceNamingContext = checkNotNull(interfaceNamingContext, "Interface naming context cannot be null"); + this.interfaceNamingContext = interfaceNamingContext; } @Override @@ -84,16 +82,16 @@ public class PbbRewriteCustomizer extends FutureJVppCustomizer private void setPbbRewrite(final InstanceIdentifier<PbbRewrite> id, final PbbRewrite data, final WriteContext writeContext, final boolean disable) throws TimeoutException, VppBaseCallException { - final String interfaceName = checkNotNull(id.firstKeyOf(Interface.class), "Interface key not found").getName(); + final String interfaceName = id.firstKeyOf(Interface.class).getName(); final L2InterfacePbbTagRewrite request = new L2InterfacePbbTagRewrite(); //checking all attributes in preconditions(pbb-rewrite is subcontainer, so there can't be mandatory statements) request.swIfIndex = interfaceNamingContext.getIndex(interfaceName, writeContext.getMappingContext()); - request.bDmac = parseMac(verifiedDestinationAddress(data)); - request.bSmac = parseMac(verifiedSourceAddress(data)); - request.bVlanid = verifiedBVlanId(data); - request.iSid = verifiedISid(data); + request.bDmac = parseMac(data.getDestinationAddress().getValue()); + request.bSmac = parseMac(data.getSourceAddress().getValue()); + request.bVlanid = data.getBVlanTagVlanId().shortValue(); + request.iSid = data.getITagIsid().intValue(); request.vtrOp = verifiedOperation(data, disable); //not sure whats gonna happen to this attribute, so its left optional for now @@ -104,27 +102,10 @@ public class PbbRewriteCustomizer extends FutureJVppCustomizer getReply(getFutureJVpp().l2InterfacePbbTagRewrite(request).toCompletableFuture()); } - private String verifiedDestinationAddress(final PbbRewrite data) { - return checkNotNull(data.getDestinationAddress(), "Destination address cannot be null").getValue(); - } - - private String verifiedSourceAddress(final PbbRewrite data) { - return checkNotNull(data.getSourceAddress(), "Destination address cannot be null").getValue(); - } - - private short verifiedBVlanId(final PbbRewrite data) { - return checkNotNull(data.getBVlanTagVlanId(), "BVlan id cannot be null").shortValue(); - } - - private int verifiedISid(final PbbRewrite data) { - return checkNotNull(data.getITagIsid(), "ISid cannot be null").intValue(); - } - // if disabled ,then uses non-public allowed value 0, which is equal to operation disable private int verifiedOperation(final PbbRewrite data, final boolean disable) { - return disable ? OPERATION_DISABLE - : checkNotNull(data.getInterfaceOperation(), "Operation cannot be null").getIntValue(); + : data.getInterfaceOperation().getIntValue(); } } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/pbb/PbbRewriteValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/pbb/PbbRewriteValidator.java new file mode 100644 index 000000000..e5ec7fc69 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/pbb/PbbRewriteValidator.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2019 PANTHEON.tech. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.interfaces.pbb; + +import static com.google.common.base.Preconditions.checkNotNull; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.DataValidationFailedException; +import io.fd.honeycomb.translate.write.Validator; +import io.fd.honeycomb.translate.write.WriteContext; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.pbb.rev161214.interfaces._interface.PbbRewrite; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev180220.interfaces.Interface; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class PbbRewriteValidator implements Validator<PbbRewrite> { + + + public PbbRewriteValidator(@Nonnull final NamingContext interfaceNamingContext) { + checkNotNull(interfaceNamingContext, "Interface naming context cannot be null"); + } + + @Override + public void validateWrite(@Nonnull final InstanceIdentifier<PbbRewrite> id, @Nonnull final PbbRewrite dataAfter, + @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.CreateValidationFailedException { + try { + validatePbbRewrite(id, dataAfter, false); + } catch(Exception e) { + throw new DataValidationFailedException.CreateValidationFailedException(id, dataAfter, e); + } + } + + @Override + public void validateUpdate(@Nonnull final InstanceIdentifier<PbbRewrite> id, @Nonnull final PbbRewrite dataBefore, + @Nonnull final PbbRewrite dataAfter, @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.UpdateValidationFailedException { + + try { + validatePbbRewrite(id, dataAfter, false); + } catch(Exception e) { + throw new DataValidationFailedException.UpdateValidationFailedException(id, dataBefore, dataAfter, e); + } + } + + @Override + public void validateDelete(@Nonnull final InstanceIdentifier<PbbRewrite> id, @Nonnull final PbbRewrite dataBefore, + @Nonnull final WriteContext writeContext) + throws DataValidationFailedException.DeleteValidationFailedException { + try { + validatePbbRewrite(id, dataBefore, true); + } catch(Exception e) { + throw new DataValidationFailedException.DeleteValidationFailedException(id, e); + } + } + + private void validatePbbRewrite(final InstanceIdentifier<PbbRewrite> id, @Nonnull final PbbRewrite data, + final boolean disable) { + checkNotNull(id.firstKeyOf(Interface.class), "Interface key not found"); + checkNotNull(data.getDestinationAddress(), "Destination address cannot be null"); + checkNotNull(data.getSourceAddress(), "Source address cannot be null"); + checkNotNull(data.getBVlanTagVlanId(), "BVlan id cannot be null"); + checkNotNull(data.getITagIsid(), "ISid cannot be null"); + if (disable) { + checkNotNull(data.getInterfaceOperation(), "Operation cannot be null"); + } + } +} |