diff options
author | Jan Srnicek <jsrnicek@cisco.com> | 2017-05-10 09:55:07 +0200 |
---|---|---|
committer | Jan Srnicek <jsrnicek@cisco.com> | 2017-05-10 09:55:07 +0200 |
commit | b663b44d862d366c722466ecfb7db1231ff01ccd (patch) | |
tree | 9990f894056099df4f59099dbca7ebf7950961b4 /v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces | |
parent | 9244433a6cb743c29001faee608f85666537610b (diff) |
HC2VPP-114 - Ipv4/6 routing support for sub interfaces
Provides option to set ipv4/6 vrf id for sub interface same way
as for interface
Change-Id: I3e14620d61e364e6741a1f1642570dd9ee317255
Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces')
6 files changed, 157 insertions, 65 deletions
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingCustomizer.java new file mode 100644 index 000000000..456178b73 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceRoutingCustomizer.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * + * 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; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.spi.write.WriterCustomizer; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.interfaces._interface.Routing; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class InterfaceRoutingCustomizer extends RoutingCustomizer + implements WriterCustomizer<Routing> { + + public InterfaceRoutingCustomizer(@Nonnull final FutureJVppCore vppApi,@Nonnull final NamingContext interfaceContext) { + super(vppApi, interfaceContext); + } + + @Override + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Routing> id, + @Nonnull final Routing dataAfter, @Nonnull final WriteContext writeContext) + throws WriteFailedException { + + final String ifName = id.firstKeyOf(Interface.class).getName(); + setRouting(id, ifName, dataAfter, writeContext); + } + + @Override + public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<Routing> id, + @Nonnull final Routing dataBefore, @Nonnull final Routing dataAfter, + @Nonnull final WriteContext writeContext) + throws WriteFailedException { + + final String ifName = id.firstKeyOf(Interface.class).getName(); + setRouting(id, ifName, dataAfter, writeContext); + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Routing> id, + @Nonnull final Routing dataBefore, @Nonnull final WriteContext writeContext) + throws WriteFailedException { + final String ifName = id.firstKeyOf(Interface.class).getName(); + disableRouting(id, ifName, writeContext); + } + +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/RewriteCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/RewriteCustomizer.java index 1c55e96ba..e34ff1cab 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/RewriteCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/RewriteCustomizer.java @@ -17,13 +17,13 @@ package io.fd.hc2vpp.v3po.interfaces; import com.google.common.base.Preconditions; -import io.fd.honeycomb.translate.spi.write.WriterCustomizer; import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.util.SubInterfaceUtils; import io.fd.hc2vpp.common.translate.util.TagRewriteOperation; +import io.fd.hc2vpp.v3po.util.SubInterfaceUtils; +import io.fd.honeycomb.translate.spi.write.WriterCustomizer; import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; import io.fd.vpp.jvpp.core.dto.L2InterfaceVlanTagRewrite; @@ -33,11 +33,11 @@ import java.util.List; import java.util.concurrent.CompletionStage; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170315._802dot1q; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170315.interfaces._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170315.sub._interface.base.attributes.l2.Rewrite; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170315.sub._interface.base.attributes.l2.RewriteBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170315.tag.rewrite.PushTags; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509._802dot1q; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.sub._interface.base.attributes.l2.Rewrite; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.sub._interface.base.attributes.l2.RewriteBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.tag.rewrite.PushTags; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/RoutingCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/RoutingCustomizer.java index dc0b6dc16..e23ebc826 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/RoutingCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/RoutingCustomizer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Cisco and/or its affiliates. + * Copyright (c) 2017 Cisco and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ package io.fd.hc2vpp.v3po.interfaces; import static com.google.common.base.Preconditions.checkArgument; -import io.fd.honeycomb.translate.spi.write.WriterCustomizer; import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; @@ -30,53 +29,25 @@ import io.fd.vpp.jvpp.core.dto.SwInterfaceSetTableReply; import io.fd.vpp.jvpp.core.future.FutureJVppCore; import java.util.concurrent.CompletionStage; import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.interfaces._interface.Routing; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.RoutingBaseAttributes; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class RoutingCustomizer extends FutureJVppCustomizer implements WriterCustomizer<Routing>, JvppReplyConsumer, - ByteDataTranslator { - +abstract class RoutingCustomizer extends FutureJVppCustomizer implements JvppReplyConsumer, ByteDataTranslator { private static final Logger LOG = LoggerFactory.getLogger(RoutingCustomizer.class); - private final NamingContext interfaceContext; + protected final NamingContext interfaceContext; - public RoutingCustomizer(final FutureJVppCore vppApi, final NamingContext interfaceContext) { - super(vppApi); + protected RoutingCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext interfaceContext) { + super(futureJVppCore); this.interfaceContext = interfaceContext; } - @Override - public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Routing> id, - @Nonnull final Routing dataAfter, @Nonnull final WriteContext writeContext) - throws WriteFailedException { - - final String ifName = id.firstKeyOf(Interface.class).getName(); - setRouting(id, ifName, dataAfter, writeContext); - } - - @Override - public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<Routing> id, - @Nonnull final Routing dataBefore, @Nonnull final Routing dataAfter, - @Nonnull final WriteContext writeContext) - throws WriteFailedException { - - final String ifName = id.firstKeyOf(Interface.class).getName(); - setRouting(id, ifName, dataAfter, writeContext); - } - - @Override - public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Routing> id, - @Nonnull final Routing dataBefore, @Nonnull final WriteContext writeContext) - throws WriteFailedException { - final String ifName = id.firstKeyOf(Interface.class).getName(); - disableRouting(id, ifName, writeContext); - } - - private void setRouting(@Nonnull final InstanceIdentifier<Routing> id, @Nonnull final String name, - @Nonnull final Routing rt, - @Nonnull final WriteContext writeContext) throws WriteFailedException { + protected void setRouting(@Nonnull final InstanceIdentifier<? extends RoutingBaseAttributes> id, + @Nonnull final String name, + @Nonnull final RoutingBaseAttributes rt, + @Nonnull final WriteContext writeContext) throws WriteFailedException { final int swIfc = interfaceContext.getIndex(name, writeContext.getMappingContext()); LOG.debug("Setting routing for interface: {}, {}. Routing: {}", name, swIfc, rt); checkArgument(rt.getIpv4VrfId() != null || rt.getIpv6VrfId() != null, "No vrf-id given"); @@ -87,13 +58,14 @@ public class RoutingCustomizer extends FutureJVppCustomizer implements WriterCus LOG.debug("Routing set successfully for interface: {}, {}, routing: {}", name, swIfc, rt); } - private void setVrfId(final InstanceIdentifier<Routing> id, final int swIfc, final Long vrfId, boolean isIp6) - throws WriteFailedException { + private void setVrfId(final InstanceIdentifier<? extends RoutingBaseAttributes> id, final int swIfc, + final Long vrfId, boolean isIp6) + throws WriteFailedException { if (vrfId == null) { return; } final CompletionStage<SwInterfaceSetTableReply> cs = getFutureJVpp() - .swInterfaceSetTable(getInterfaceSetTableRequest(swIfc, booleanToByte(isIp6), vrfId.intValue())); + .swInterfaceSetTable(getInterfaceSetTableRequest(swIfc, booleanToByte(isIp6), vrfId.intValue())); getReplyForWrite(cs.toCompletableFuture(), id); } @@ -101,13 +73,13 @@ public class RoutingCustomizer extends FutureJVppCustomizer implements WriterCus * In this case, there is no such thing as delete routing,only thing that can be done is to disable it by setting * default value 0 */ - private void disableRouting(final InstanceIdentifier<Routing> id, final String name, - final WriteContext writeContext) throws WriteFailedException { + void disableRouting(final InstanceIdentifier<? extends RoutingBaseAttributes> id, final String name, + final WriteContext writeContext) throws WriteFailedException { final int swIfc = interfaceContext.getIndex(name, writeContext.getMappingContext()); LOG.debug("Disabling routing for interface: {}, {}.", name, swIfc); getReplyForDelete(getFutureJVpp() - .swInterfaceSetTable(getInterfaceSetTableRequest(swIfc, (byte) 0, 0)).toCompletableFuture(), id); + .swInterfaceSetTable(getInterfaceSetTableRequest(swIfc, (byte) 0, 0)).toCompletableFuture(), id); LOG.debug("Routing for interface: {}, {} successfully disabled", name, swIfc); } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceCustomizer.java index fbcdf8f00..306914986 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceCustomizer.java @@ -41,13 +41,13 @@ import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev1 import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.SVlan; import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.or.any.Dot1qTag; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170315._802dot1ad; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170315.interfaces._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170315.interfaces._interface.sub.interfaces.SubInterfaceKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170315.match.attributes.MatchType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170315.match.attributes.match.type.Default; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170315.match.attributes.match.type.VlanTagged; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170315.sub._interface.base.attributes.tags.Tag; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509._802dot1ad; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.interfaces._interface.sub.interfaces.SubInterfaceKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.match.attributes.MatchType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.match.attributes.match.type.Default; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.match.attributes.match.type.VlanTagged; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.sub._interface.base.attributes.tags.Tag; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceL2Customizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceL2Customizer.java index f1c6586bc..22786ad64 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceL2Customizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceL2Customizer.java @@ -16,20 +16,20 @@ package io.fd.hc2vpp.v3po.interfaces; -import io.fd.honeycomb.translate.spi.write.WriterCustomizer; import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.hc2vpp.v3po.util.SubInterfaceUtils; +import io.fd.honeycomb.translate.spi.write.WriterCustomizer; import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170315.interfaces._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170315.interfaces._interface.sub.interfaces.SubInterfaceKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170315.sub._interface.base.attributes.L2; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.interfaces._interface.sub.interfaces.SubInterfaceKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.sub._interface.base.attributes.L2; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceRoutingCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceRoutingCustomizer.java new file mode 100644 index 000000000..03eceb155 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/SubInterfaceRoutingCustomizer.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * + * 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; + +import static io.fd.hc2vpp.v3po.util.SubInterfaceUtils.subInterfaceFullNameConfig; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.spi.write.WriterCustomizer; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.sub._interface.routing.attributes.Routing; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class SubInterfaceRoutingCustomizer extends RoutingCustomizer implements WriterCustomizer<Routing> { + + public SubInterfaceRoutingCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext interfaceContext) { + super(futureJVppCore, interfaceContext); + } + + @Override + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Routing> instanceIdentifier, + @Nonnull final Routing routing, @Nonnull final WriteContext writeContext) + throws WriteFailedException { + setRouting(instanceIdentifier, subInterfaceFullNameConfig(instanceIdentifier), routing, writeContext); + } + + @Override + public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<Routing> instanceIdentifier, + @Nonnull final Routing routing, @Nonnull final Routing d1, + @Nonnull final WriteContext writeContext) throws WriteFailedException { + setRouting(instanceIdentifier, subInterfaceFullNameConfig(instanceIdentifier), routing, writeContext); + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Routing> instanceIdentifier, + @Nonnull final Routing routing, @Nonnull final WriteContext writeContext) + throws WriteFailedException { + disableRouting(instanceIdentifier, subInterfaceFullNameConfig(instanceIdentifier), writeContext); + } +} |