diff options
author | Jan Srnicek <jsrnicek@cisco.com> | 2017-02-17 09:54:53 +0100 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2017-02-17 09:30:49 +0000 |
commit | c9ab24206b1356dced7f90768606fbe83edbce1a (patch) | |
tree | f03ddcdc5982e5d252452b1913d8b04a8648a631 /v3po/v3po2vpp/src/main | |
parent | 6fd04fbf2dce17ee89b62eada5de398028679f7b (diff) |
HC2VPP-75 - vrf extraction fix
- fixed vrf extraction for Ipv6Neighbours + add test
- added vrf extraction for Ipv4Neighbours + add test
Change-Id: Ia7d1b6057c19e2f72139b3b0464f4a50a24b1c7b
Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'v3po/v3po2vpp/src/main')
2 files changed, 31 insertions, 4 deletions
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/Ipv4NeighbourCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/Ipv4NeighbourCustomizer.java index b44a827a9..aedd44286 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/Ipv4NeighbourCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/Ipv4NeighbourCustomizer.java @@ -16,6 +16,7 @@ package io.fd.hc2vpp.v3po.interfaces.ip.v4; +import com.google.common.base.Optional; import io.fd.hc2vpp.common.translate.util.AddressTranslator; import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; @@ -32,6 +33,8 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces. import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv4; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Neighbor; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.NeighborKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.RoutingBaseAttributes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppInterfaceAugmentation; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -68,6 +71,8 @@ public class Ipv4NeighbourCustomizer extends FutureJVppCustomizer request.swIfIndex = interfaceContext .getIndex(id.firstKeyOf(Interface.class).getName(), writeContext.getMappingContext()); + bindVrfIfSpecified(writeContext, id, request); + return request; }, getFutureJVpp()); LOG.debug("Neighbour {} successfully written", id); @@ -95,8 +100,26 @@ public class Ipv4NeighbourCustomizer extends FutureJVppCustomizer request.swIfIndex = interfaceContext .getIndex(id.firstKeyOf(Interface.class).getName(), writeContext.getMappingContext()); + bindVrfIfSpecified(writeContext, id, request); + return request; }, getFutureJVpp()); LOG.debug("Neighbour {} successfully deleted", id); } + + private void bindVrfIfSpecified(final WriteContext writeContext, + final InstanceIdentifier<Neighbor> id, + IpNeighborAddDel request) { + final Optional<Interface> optIface = writeContext.readBefore(id.firstIdentifierOf(Interface.class)); + + // if routing set, reads vrf-id + // uses java.util.Optional(its internal behaviour suites this use better than guava one) + if (optIface.isPresent()) { + java.util.Optional.of(optIface.get()) + .map(iface -> iface.getAugmentation(VppInterfaceAugmentation.class)) + .map(VppInterfaceAugmentation::getRouting) + .map(RoutingBaseAttributes::getIpv4VrfId) + .ifPresent(vrf -> request.vrfId = vrf.byteValue()); + } + } }
\ No newline at end of file diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/Ipv6NeighbourCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/Ipv6NeighbourCustomizer.java index dc059c3c9..b6948b508 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/Ipv6NeighbourCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/Ipv6NeighbourCustomizer.java @@ -36,6 +36,7 @@ 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.ip.rev140616.interfaces._interface.ipv6.Neighbor; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv6.NeighborKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.RoutingBaseAttributes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppInterfaceAugmentation; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; @@ -118,10 +119,13 @@ public class Ipv6NeighbourCustomizer extends FutureJVppCustomizer final Optional<Interface> optIface = writeContext.readBefore(id.firstIdentifierOf(Interface.class)); // if routing set, reads vrf-id - if (optIface.isPresent() && optIface.get().getAugmentation(VppInterfaceAugmentation.class) != null && - optIface.get().getAugmentation(VppInterfaceAugmentation.class).getRouting() != null) { - request.vrfId = optIface.get().getAugmentation(VppInterfaceAugmentation.class).getRouting().getIpv4VrfId() - .byteValue(); + // uses java.util.Optional(its internal behaviour suites this use better than guava one) + if (optIface.isPresent()) { + java.util.Optional.of(optIface.get()) + .map(iface -> iface.getAugmentation(VppInterfaceAugmentation.class)) + .map(VppInterfaceAugmentation::getRouting) + .map(RoutingBaseAttributes::getIpv6VrfId) + .ifPresent(vrf -> request.vrfId = vrf.byteValue()); } getReplyForWrite(getFutureJVpp().ipNeighborAddDel(request).toCompletableFuture(), id); } |