From ae767d51cdba6f2296c52b63cd569a98d6f7db27 Mon Sep 17 00:00:00 2001 From: Jan Srnicek Date: Wed, 4 Jan 2017 16:39:10 +0100 Subject: HONEYCOMB-102/HONEYCOMB-103 - Ipv6 Support Contains - Ipv6 read/write Support for Interfaces - Ipv6 read/write Support for Subi-Interfaces - Postman collection with relevant requests Todo - Test coverage - HC2VPP-11 - Refactoring - HC2VPP-12 - Could be related to - HONEYCOMB-328 Tested - read/write for both interfaces and sub-interfaces - passes ok - init with following scenarios - vpp clean/hc has data - passes ok - vpp has data/hc clean - passed with error for sub-interface described in HONEYCOMB-328. The actual ipv4/ipv6 part passes ok Change-Id: Ib18acb9b18d6374dc5847e30db4049696d512e72 Signed-off-by: Jan Srnicek --- .../main/java/io/fd/hc2vpp/v3po/V3poModule.java | 19 ++ .../v3po/factory/InterfacesStateReaderFactory.java | 33 +- .../v3po/factory/InterfacesWriterFactory.java | 31 -- .../v3po/factory/Ipv4StateReaderFactory.java | 69 +++++ .../fd/hc2vpp/v3po/factory/Ipv4WriterFactory.java | 66 ++++ .../v3po/factory/Ipv6StateReaderFactory.java | 64 ++++ .../fd/hc2vpp/v3po/factory/Ipv6WriterFactory.java | 68 +++++ .../factory/SubInterfaceIpv4WriterFactory.java | 61 ++++ .../factory/SubInterfaceIpv6WriterFactory.java | 63 ++++ .../SubInterfaceStateIpv4ReaderFactory.java | 67 ++++ .../SubInterfaceStateIpv6ReaderFactory.java | 67 ++++ .../SubinterfaceAugmentationWriterFactory.java | 8 - ...SubinterfaceStateAugmentationReaderFactory.java | 12 +- .../io/fd/hc2vpp/v3po/interfaces/ip/IpWriter.java | 166 ++++++++++ .../v3po/interfaces/ip/Ipv4AddressCustomizer.java | 151 --------- .../hc2vpp/v3po/interfaces/ip/Ipv4Customizer.java | 56 ---- .../interfaces/ip/Ipv4NeighbourCustomizer.java | 126 -------- .../fd/hc2vpp/v3po/interfaces/ip/Ipv4Writer.java | 108 ------- .../hc2vpp/v3po/interfaces/ip/Ipv6Customizer.java | 55 ---- .../ip/SubInterfaceIpv4AddressCustomizer.java | 131 -------- .../ip/subnet/validation/Ipv4SubnetValidator.java | 80 +++++ .../ip/subnet/validation/SubnetValidator.java | 80 ----- .../interfaces/ip/v4/Ipv4AddressCustomizer.java | 154 ++++++++++ .../v3po/interfaces/ip/v4/Ipv4Customizer.java | 56 ++++ .../interfaces/ip/v4/Ipv4NeighbourCustomizer.java | 102 +++++++ .../SubInterfaceIpv4AddressCustomizer.java | 132 ++++++++ .../SubInterfaceIpv4NeighbourCustomizer.java | 99 ++++++ .../interfaces/ip/v6/Ipv6AddressCustomizer.java | 92 ++++++ .../v3po/interfaces/ip/v6/Ipv6Customizer.java | 55 ++++ .../interfaces/ip/v6/Ipv6NeighbourCustomizer.java | 120 ++++++++ .../SubInterfaceIpv6AddressCustomizer.java | 73 +++++ .../SubInterfaceIpv6NeighbourCustomizer.java | 100 ++++++ .../hc2vpp/v3po/interfacesstate/ip/IpReader.java | 152 ++++++++++ .../interfacesstate/ip/Ipv4AddressCustomizer.java | 166 ---------- .../v3po/interfacesstate/ip/Ipv4Customizer.java | 59 ---- .../ip/Ipv4NeighbourCustomizer.java | 73 ----- .../hc2vpp/v3po/interfacesstate/ip/Ipv4Reader.java | 84 ----- .../v3po/interfacesstate/ip/Ipv6Customizer.java | 66 ---- .../ip/SubInterfaceIpv4AddressCustomizer.java | 144 --------- .../ip/dump/params/AddressDumpParams.java | 44 --- .../ip/dump/params/IfaceDumpFilter.java | 44 +++ .../ip/v4/Ipv4AddressCustomizer.java | 166 ++++++++++ .../v3po/interfacesstate/ip/v4/Ipv4Customizer.java | 59 ++++ .../ip/v4/Ipv4NeighbourCustomizer.java | 123 ++++++++ .../SubInterfaceIpv4AddressCustomizer.java | 146 +++++++++ .../SubInterfaceIpv4NeighbourCustomizer.java | 113 +++++++ .../ip/v6/Ipv6AddressCustomizer.java | 149 +++++++++ .../v3po/interfacesstate/ip/v6/Ipv6Customizer.java | 58 ++++ .../ip/v6/Ipv6NeighbourCustomizer.java | 119 ++++++++ .../SubInterfaceIpv6AddressCustomizer.java | 143 +++++++++ .../SubInterfaceIpv6NeighbourCustomizer.java | 113 +++++++ .../interfaces/ip/Ipv4AddressCustomizerTest.java | 337 --------------------- .../interfaces/ip/Ipv4NeighbourCustomizerTest.java | 1 + .../ip/SubInterfaceIpv4AddressCustomizerTest.java | 1 + .../subnet/validation/Ipv4SubnetValidatorTest.java | 88 ++++++ .../ip/subnet/validation/SubnetValidatorTest.java | 88 ------ .../ip/v4/Ipv4AddressCustomizerTest.java | 337 +++++++++++++++++++++ .../ip/Ipv4AddressCustomizerTest.java | 1 + .../interfacesstate/ip/Ipv4CustomizerTest.java | 3 +- .../ip/SubInterfaceIpv4AddressCustomizerTest.java | 1 + 60 files changed, 3591 insertions(+), 1851 deletions(-) create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/Ipv4StateReaderFactory.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/Ipv4WriterFactory.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/Ipv6StateReaderFactory.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/Ipv6WriterFactory.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubInterfaceIpv4WriterFactory.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubInterfaceIpv6WriterFactory.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubInterfaceStateIpv4ReaderFactory.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubInterfaceStateIpv6ReaderFactory.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/IpWriter.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/Ipv4AddressCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/Ipv4Customizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/Ipv4NeighbourCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/Ipv4Writer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/Ipv6Customizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/SubInterfaceIpv4AddressCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/subnet/validation/Ipv4SubnetValidator.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/subnet/validation/SubnetValidator.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/Ipv4AddressCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/Ipv4Customizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/Ipv4NeighbourCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/subinterface/SubInterfaceIpv4AddressCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/subinterface/SubInterfaceIpv4NeighbourCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/Ipv6AddressCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/Ipv6Customizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/Ipv6NeighbourCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/subinterface/SubInterfaceIpv6AddressCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/subinterface/SubInterfaceIpv6NeighbourCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/IpReader.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4AddressCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4Customizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4NeighbourCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4Reader.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv6Customizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/dump/params/AddressDumpParams.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/dump/params/IfaceDumpFilter.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/Ipv4AddressCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/Ipv4Customizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/Ipv4NeighbourCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/subinterface/SubInterfaceIpv4AddressCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/subinterface/SubInterfaceIpv4NeighbourCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/Ipv6AddressCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/Ipv6Customizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/Ipv6NeighbourCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/subinterface/SubInterfaceIpv6AddressCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/subinterface/SubInterfaceIpv6NeighbourCustomizer.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/Ipv4AddressCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/subnet/validation/Ipv4SubnetValidatorTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/subnet/validation/SubnetValidatorTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/Ipv4AddressCustomizerTest.java (limited to 'v3po/v3po2vpp/src') diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/V3poModule.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/V3poModule.java index fce96b7f5..d2e3ba442 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/V3poModule.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/V3poModule.java @@ -25,6 +25,14 @@ import io.fd.hc2vpp.v3po.factory.EgressIetfAClWriterProvider; import io.fd.hc2vpp.v3po.factory.IngressIetfAClWriterProvider; import io.fd.hc2vpp.v3po.factory.InterfacesStateReaderFactory; import io.fd.hc2vpp.v3po.factory.InterfacesWriterFactory; +import io.fd.hc2vpp.v3po.factory.Ipv4StateReaderFactory; +import io.fd.hc2vpp.v3po.factory.Ipv4WriterFactory; +import io.fd.hc2vpp.v3po.factory.Ipv6StateReaderFactory; +import io.fd.hc2vpp.v3po.factory.Ipv6WriterFactory; +import io.fd.hc2vpp.v3po.factory.SubInterfaceIpv4WriterFactory; +import io.fd.hc2vpp.v3po.factory.SubInterfaceIpv6WriterFactory; +import io.fd.hc2vpp.v3po.factory.SubInterfaceStateIpv4ReaderFactory; +import io.fd.hc2vpp.v3po.factory.SubInterfaceStateIpv6ReaderFactory; import io.fd.hc2vpp.v3po.factory.SubinterfaceAugmentationWriterFactory; import io.fd.hc2vpp.v3po.factory.SubinterfaceStateAugmentationReaderFactory; import io.fd.hc2vpp.v3po.factory.VppClassifierHoneycombWriterFactory; @@ -88,6 +96,11 @@ public class V3poModule extends AbstractModule { readerFactoryBinder.addBinding().to(DisabledInterfacesManager.ContextsReaderFactory.class); // Expose vpp-classfier-context interfaces in operational data readerFactoryBinder.addBinding().to(VppClassifierContextManagerImpl.ContextsReaderFactory.class); + //Ipv4/Ipv6 + readerFactoryBinder.addBinding().to(Ipv4StateReaderFactory.class); + readerFactoryBinder.addBinding().to(Ipv6StateReaderFactory.class); + readerFactoryBinder.addBinding().to(SubInterfaceStateIpv4ReaderFactory.class); + readerFactoryBinder.addBinding().to(SubInterfaceStateIpv6ReaderFactory.class); // Writers final Multibinder writerFactoryBinder = Multibinder.newSetBinder(binder(), WriterFactory.class); @@ -96,6 +109,12 @@ public class V3poModule extends AbstractModule { writerFactoryBinder.addBinding().to(VppHoneycombWriterFactory.class); writerFactoryBinder.addBinding().to(VppClassifierHoneycombWriterFactory.class); + //Ipv4/Ipv6 + writerFactoryBinder.addBinding().to(Ipv4WriterFactory.class); + writerFactoryBinder.addBinding().to(Ipv6WriterFactory.class); + writerFactoryBinder.addBinding().to(SubInterfaceIpv4WriterFactory.class); + writerFactoryBinder.addBinding().to(SubInterfaceIpv6WriterFactory.class); + // Notifications final Multibinder notifiersBinder = Multibinder.newSetBinder(binder(), ManagedNotificationProducer.class); diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesStateReaderFactory.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesStateReaderFactory.java index 494a17375..bdb155677 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesStateReaderFactory.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesStateReaderFactory.java @@ -33,16 +33,11 @@ import io.fd.hc2vpp.v3po.interfacesstate.VhostUserCustomizer; import io.fd.hc2vpp.v3po.interfacesstate.VxlanCustomizer; import io.fd.hc2vpp.v3po.interfacesstate.VxlanGpeCustomizer; import io.fd.hc2vpp.v3po.interfacesstate.acl.ingress.AclCustomizer; -import io.fd.hc2vpp.v3po.interfacesstate.ip.Ipv4AddressCustomizer; -import io.fd.hc2vpp.v3po.interfacesstate.ip.Ipv4Customizer; -import io.fd.hc2vpp.v3po.interfacesstate.ip.Ipv4NeighbourCustomizer; -import io.fd.hc2vpp.v3po.interfacesstate.ip.Ipv6Customizer; import io.fd.hc2vpp.v3po.interfacesstate.pbb.PbbRewriteStateCustomizer; import io.fd.hc2vpp.v3po.interfacesstate.span.MirroredInterfacesCustomizer; import io.fd.hc2vpp.v3po.vppclassifier.VppClassifierContextManager; import io.fd.honeycomb.translate.impl.read.GenericInitListReader; import io.fd.honeycomb.translate.impl.read.GenericInitReader; -import io.fd.honeycomb.translate.impl.read.GenericListReader; import io.fd.honeycomb.translate.impl.read.GenericReader; import io.fd.honeycomb.translate.read.ReaderFactory; import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder; @@ -50,12 +45,6 @@ import io.fd.vpp.jvpp.core.future.FutureJVppCore; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesStateBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface2; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface2Builder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv6; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.Neighbor; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppInterfaceStateAugmentation; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppInterfaceStateAugmentationBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces.state._interface.Acl; @@ -116,31 +105,11 @@ public final class InterfacesStateReaderFactory implements ReaderFactory { // v3po.yang initVppIfcAugmentationReaders(registry, IFC_ID); - // ietf-ip.yang - initInterface2AugmentationReaders(registry, IFC_ID); + //vpp-pbb.yang initPbbRewriteAugmentation(registry, IFC_ID); } - private void initInterface2AugmentationReaders(final ModifiableReaderRegistryBuilder registry, - final InstanceIdentifier ifcId) { - // Interface2Augmentation(Structural) - final InstanceIdentifier ifc2AugId = ifcId.augmentation(Interface2.class); - registry.addStructuralReader(ifc2AugId, Interface2Builder.class); - // Ipv4 - final InstanceIdentifier ipv4Id = ifc2AugId.child(Ipv4.class); - registry.add(new GenericReader<>(ipv4Id, new Ipv4Customizer(jvpp))); - // Address - final InstanceIdentifier
ipv4AddrId = ipv4Id.child(Address.class); - registry.add(new GenericInitListReader<>(ipv4AddrId, new Ipv4AddressCustomizer(jvpp, ifcNamingCtx))); - // Neighbor - final InstanceIdentifier neighborId = ipv4Id.child(Neighbor.class); - registry.add(new GenericListReader<>(neighborId, new Ipv4NeighbourCustomizer(jvpp))); - // Ipv6 - final InstanceIdentifier ipv6Id = ifc2AugId.child(Ipv6.class); - registry.add(new GenericReader<>(ipv6Id, new Ipv6Customizer(jvpp, ifcNamingCtx))); - } - private void initVppIfcAugmentationReaders(final ModifiableReaderRegistryBuilder registry, final InstanceIdentifier ifcId) { // VppInterfaceStateAugmentation diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesWriterFactory.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesWriterFactory.java index 27a2dd95a..62fbe822a 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesWriterFactory.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesWriterFactory.java @@ -36,10 +36,6 @@ import io.fd.hc2vpp.v3po.interfaces.VhostUserCustomizer; import io.fd.hc2vpp.v3po.interfaces.VxlanCustomizer; import io.fd.hc2vpp.v3po.interfaces.VxlanGpeCustomizer; import io.fd.hc2vpp.v3po.interfaces.acl.ingress.AclCustomizer; -import io.fd.hc2vpp.v3po.interfaces.ip.Ipv4AddressCustomizer; -import io.fd.hc2vpp.v3po.interfaces.ip.Ipv4Customizer; -import io.fd.hc2vpp.v3po.interfaces.ip.Ipv4NeighbourCustomizer; -import io.fd.hc2vpp.v3po.interfaces.ip.Ipv6Customizer; import io.fd.hc2vpp.v3po.interfaces.pbb.PbbRewriteCustomizer; import io.fd.hc2vpp.v3po.interfaces.span.MirroredInterfaceCustomizer; import io.fd.hc2vpp.v3po.vppclassifier.VppClassifierContextManager; @@ -51,11 +47,6 @@ import io.fd.vpp.jvpp.core.future.FutureJVppCore; import java.util.Set; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; 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.Interface1; -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.Ipv6; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address; -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.opendaylight.params.xml.ns.yang.v3po.rev161214.VppInterfaceAugmentation; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.Acl; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.Ethernet; @@ -115,32 +106,10 @@ public final class InterfacesWriterFactory implements WriterFactory { registry.add(new GenericListWriter<>(IFC_ID, new InterfaceCustomizer(jvpp, ifcNamingContext))); // VppInterfaceAugmentation addVppInterfaceAgmentationWriters(IFC_ID, registry); - // Interface1 (ietf-ip augmentation) - addInterface1AugmentationWriters(IFC_ID, registry); addPbbAugmentationWriters(IFC_ID, registry); } - private void addInterface1AugmentationWriters(final InstanceIdentifier ifcId, - final ModifiableWriterRegistryBuilder registry) { - final InstanceIdentifier ifc1AugId = ifcId.augmentation(Interface1.class); - // Ipv6(after interface) = - registry.addAfter(new GenericWriter<>(ifc1AugId.child(Ipv6.class), new Ipv6Customizer(jvpp)), - ifcId); - // Ipv4(after interface) - final InstanceIdentifier ipv4Id = ifc1AugId.child(Ipv4.class); - registry.addAfter(new GenericWriter<>(ipv4Id, new Ipv4Customizer(jvpp)), - ifcId); - // Address(after Ipv4) = - final InstanceIdentifier
ipv4AddressId = ipv4Id.child(Address.class); - registry.addAfter(new GenericListWriter<>(ipv4AddressId, new Ipv4AddressCustomizer(jvpp, ifcNamingContext)), - ipv4Id); - // Neighbor(after ipv4Address) - registry.addAfter(new GenericListWriter<>(ipv4Id.child(Neighbor.class), new Ipv4NeighbourCustomizer(jvpp, - ifcNamingContext)), - ipv4AddressId); - } - private void addVppInterfaceAgmentationWriters(final InstanceIdentifier ifcId, final ModifiableWriterRegistryBuilder registry) { // VhostUser(Needs to be executed before Interface customizer) = diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/Ipv4StateReaderFactory.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/Ipv4StateReaderFactory.java new file mode 100644 index 000000000..159436671 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/Ipv4StateReaderFactory.java @@ -0,0 +1,69 @@ +/* + * 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.factory; + + +import static io.fd.hc2vpp.v3po.factory.InterfacesStateReaderFactory.IFC_ID; + +import com.google.inject.Inject; +import com.google.inject.name.Named; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfacesstate.ip.v4.Ipv4AddressCustomizer; +import io.fd.hc2vpp.v3po.interfacesstate.ip.v4.Ipv4Customizer; +import io.fd.hc2vpp.v3po.interfacesstate.ip.v4.Ipv4NeighbourCustomizer; +import io.fd.honeycomb.translate.impl.read.GenericInitListReader; +import io.fd.honeycomb.translate.impl.read.GenericListReader; +import io.fd.honeycomb.translate.impl.read.GenericReader; +import io.fd.honeycomb.translate.read.ReaderFactory; +import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder; +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.ip.rev140616.Interface2; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface2Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.Neighbor; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class Ipv4StateReaderFactory implements ReaderFactory { + + private static final InstanceIdentifier IFC_2_ID = IFC_ID.augmentation(Interface2.class); + + @Inject + private FutureJVppCore jvpp; + + @Inject + @Named("interface-context") + private NamingContext ifcNamingCtx; + + @Override + public void init(@Nonnull final ModifiableReaderRegistryBuilder registry) { + + //add also structural reader + registry.addStructuralReader(IFC_2_ID, Interface2Builder.class); + + // Ipv4 + final InstanceIdentifier ipv4Id = IFC_2_ID.child(Ipv4.class); + registry.add(new GenericReader<>(ipv4Id, new Ipv4Customizer(jvpp))); + // Ipv4 Address + final InstanceIdentifier
ipv4AddrId = ipv4Id.child(Address.class); + registry.add(new GenericInitListReader<>(ipv4AddrId, new Ipv4AddressCustomizer(jvpp, ifcNamingCtx))); + // Ipv4 Neighbor + final InstanceIdentifier neighborId = ipv4Id.child(Neighbor.class); + registry.add(new GenericListReader<>(neighborId, new Ipv4NeighbourCustomizer(jvpp, ifcNamingCtx))); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/Ipv4WriterFactory.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/Ipv4WriterFactory.java new file mode 100644 index 000000000..5a2ac5a29 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/Ipv4WriterFactory.java @@ -0,0 +1,66 @@ +/* + * 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.factory; + +import static io.fd.hc2vpp.v3po.factory.InterfacesWriterFactory.IFC_ID; + +import com.google.inject.Inject; +import com.google.inject.name.Named; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfaces.ip.v4.Ipv4AddressCustomizer; +import io.fd.hc2vpp.v3po.interfaces.ip.v4.Ipv4Customizer; +import io.fd.hc2vpp.v3po.interfaces.ip.v4.Ipv4NeighbourCustomizer; +import io.fd.honeycomb.translate.impl.write.GenericListWriter; +import io.fd.honeycomb.translate.impl.write.GenericWriter; +import io.fd.honeycomb.translate.write.WriterFactory; +import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder; +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.ip.rev140616.Interface1; +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.Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Neighbor; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class Ipv4WriterFactory implements WriterFactory { + + @Inject + private FutureJVppCore jvpp; + + @Inject + @Named("interface-context") + private NamingContext ifcNamingContext; + + @Override + public void init(@Nonnull final ModifiableWriterRegistryBuilder registry) { + + final InstanceIdentifier ifc1AugId = IFC_ID.augmentation(Interface1.class); + + // Ipv4(after interface) + final InstanceIdentifier ipv4Id = ifc1AugId.child(Ipv4.class); + registry.addAfter(new GenericWriter<>(ipv4Id, new Ipv4Customizer(jvpp)), + IFC_ID); + // Address(after Ipv4) = + final InstanceIdentifier
ipv4AddressId = ipv4Id.child(Address.class); + registry.addAfter(new GenericListWriter<>(ipv4AddressId, new Ipv4AddressCustomizer(jvpp, ifcNamingContext)), + ipv4Id); + // Neighbor(after ipv4Address) + registry.addAfter(new GenericListWriter<>(ipv4Id.child(Neighbor.class), new Ipv4NeighbourCustomizer(jvpp, + ifcNamingContext)), ipv4AddressId); + } + +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/Ipv6StateReaderFactory.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/Ipv6StateReaderFactory.java new file mode 100644 index 000000000..628cd14f3 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/Ipv6StateReaderFactory.java @@ -0,0 +1,64 @@ +/* + * 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.factory; + + +import static io.fd.hc2vpp.v3po.factory.InterfacesStateReaderFactory.IFC_ID; + +import com.google.inject.Inject; +import com.google.inject.name.Named; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfacesstate.ip.v6.Ipv6AddressCustomizer; +import io.fd.hc2vpp.v3po.interfacesstate.ip.v6.Ipv6Customizer; +import io.fd.hc2vpp.v3po.interfacesstate.ip.v6.Ipv6NeighbourCustomizer; +import io.fd.honeycomb.translate.impl.read.GenericInitListReader; +import io.fd.honeycomb.translate.impl.read.GenericListReader; +import io.fd.honeycomb.translate.impl.read.GenericReader; +import io.fd.honeycomb.translate.read.ReaderFactory; +import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder; +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.ip.rev140616.Interface2; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv6; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv6.Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv6.Neighbor; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class Ipv6StateReaderFactory implements ReaderFactory { + + private static final InstanceIdentifier IFC_2_ID = IFC_ID.augmentation(Interface2.class); + + @Inject + private FutureJVppCore jvpp; + + @Inject + @Named("interface-context") + private NamingContext ifcNamingCtx; + + @Override + public void init(@Nonnull final ModifiableReaderRegistryBuilder registry) { + // Ipv6 + final InstanceIdentifier ipv6Id = IFC_2_ID.child(Ipv6.class); + registry.add(new GenericReader<>(ipv6Id, new Ipv6Customizer(jvpp))); + // Ipv6 Address + final InstanceIdentifier
ipv6AddrId = ipv6Id.child(Address.class); + registry.add(new GenericInitListReader<>(ipv6AddrId, new Ipv6AddressCustomizer(jvpp, ifcNamingCtx))); + // Ipv6 Neighbor + final InstanceIdentifier neighborId = ipv6Id.child(Neighbor.class); + registry.add(new GenericListReader<>(neighborId, new Ipv6NeighbourCustomizer(jvpp, ifcNamingCtx))); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/Ipv6WriterFactory.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/Ipv6WriterFactory.java new file mode 100644 index 000000000..ce63eb1af --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/Ipv6WriterFactory.java @@ -0,0 +1,68 @@ +/* + * 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.factory; + +import static io.fd.hc2vpp.v3po.factory.InterfacesWriterFactory.IFC_ID; + +import com.google.inject.Inject; +import com.google.inject.name.Named; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfaces.ip.v6.Ipv6AddressCustomizer; +import io.fd.hc2vpp.v3po.interfaces.ip.v6.Ipv6Customizer; +import io.fd.hc2vpp.v3po.interfaces.ip.v6.Ipv6NeighbourCustomizer; +import io.fd.honeycomb.translate.impl.write.GenericListWriter; +import io.fd.honeycomb.translate.impl.write.GenericWriter; +import io.fd.honeycomb.translate.write.WriterFactory; +import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder; +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.ip.rev140616.Interface1; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv6; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv6.Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv6.Neighbor; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +/** + * Created by jsrnicek on 3.1.2017. + */ +public class Ipv6WriterFactory implements WriterFactory { + + @Inject + private FutureJVppCore jvpp; + + @Inject + @Named("interface-context") + private NamingContext ifcNamingContext; + + @Override + public void init(@Nonnull final ModifiableWriterRegistryBuilder registry) { + + final InstanceIdentifier ifc1AugId = IFC_ID.augmentation(Interface1.class); + + // Ipv6(after interface) = + final InstanceIdentifier ipv6Id = ifc1AugId.child(Ipv6.class); + registry.addAfter(new GenericWriter<>(ipv6Id, new Ipv6Customizer(jvpp)), IFC_ID); + + final InstanceIdentifier
+ ipv6AddressId = ipv6Id.child(Address.class); + registry.addAfter(new GenericListWriter<>(ipv6AddressId, new Ipv6AddressCustomizer(jvpp, ifcNamingContext)), + ipv6Id); + + registry.addAfter(new GenericListWriter<>(ipv6Id.child(Neighbor.class), + new Ipv6NeighbourCustomizer(jvpp, ifcNamingContext)), ipv6AddressId); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubInterfaceIpv4WriterFactory.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubInterfaceIpv4WriterFactory.java new file mode 100644 index 000000000..208866c16 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubInterfaceIpv4WriterFactory.java @@ -0,0 +1,61 @@ +/* + * 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.factory; + + +import static io.fd.hc2vpp.v3po.factory.SubinterfaceAugmentationWriterFactory.L2_ID; +import static io.fd.hc2vpp.v3po.factory.SubinterfaceAugmentationWriterFactory.SUB_IFC_ID; + +import com.google.inject.Inject; +import com.google.inject.name.Named; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfaces.ip.v4.subinterface.SubInterfaceIpv4AddressCustomizer; +import io.fd.hc2vpp.v3po.interfaces.ip.v4.subinterface.SubInterfaceIpv4NeighbourCustomizer; +import io.fd.honeycomb.translate.impl.write.GenericListWriter; +import io.fd.honeycomb.translate.write.WriterFactory; +import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder; +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.rev161214.sub._interface.base.attributes.l2.Rewrite; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.Ipv4; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.Address; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.Neighbor; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class SubInterfaceIpv4WriterFactory implements WriterFactory{ + + @Inject + private FutureJVppCore jvpp; + + @Inject + @Named("interface-context") + private NamingContext ifcNamingContext; + + @Override + public void init(@Nonnull final ModifiableWriterRegistryBuilder registry) { + + final InstanceIdentifier rewriteId = L2_ID.child(Rewrite.class); + + // Ipv4(handled after L2 and L2/rewrite is done) = + final InstanceIdentifier
ipv4SubifcAddressId = SUB_IFC_ID.child(Ipv4.class).child(Address.class); + registry.addAfter(new GenericListWriter<>(ipv4SubifcAddressId, + new SubInterfaceIpv4AddressCustomizer(jvpp, ifcNamingContext)), rewriteId); + final InstanceIdentifier ipv4NeighborId = SUB_IFC_ID.child(Ipv4.class).child(Neighbor.class); + registry.addAfter(new GenericListWriter<>(ipv4NeighborId, + new SubInterfaceIpv4NeighbourCustomizer(jvpp, ifcNamingContext)), rewriteId); + + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubInterfaceIpv6WriterFactory.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubInterfaceIpv6WriterFactory.java new file mode 100644 index 000000000..600a991fb --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubInterfaceIpv6WriterFactory.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.factory; + + +import static io.fd.hc2vpp.v3po.factory.SubinterfaceAugmentationWriterFactory.L2_ID; +import static io.fd.hc2vpp.v3po.factory.SubinterfaceAugmentationWriterFactory.SUB_IFC_ID; + +import com.google.inject.Inject; +import com.google.inject.name.Named; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfaces.ip.v6.subinterface.SubInterfaceIpv6AddressCustomizer; +import io.fd.hc2vpp.v3po.interfaces.ip.v6.subinterface.SubInterfaceIpv6NeighbourCustomizer; +import io.fd.honeycomb.translate.impl.write.GenericListWriter; +import io.fd.honeycomb.translate.write.WriterFactory; +import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder; +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.rev161214.sub._interface.base.attributes.l2.Rewrite; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip6.attributes.Ipv6; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip6.attributes.ipv6.Address; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class SubInterfaceIpv6WriterFactory implements WriterFactory { + + @Inject + private FutureJVppCore jvpp; + + @Inject + @Named("interface-context") + private NamingContext ifcNamingContext; + + @Override + public void init(@Nonnull final ModifiableWriterRegistryBuilder registry) { + + final InstanceIdentifier rewriteId = L2_ID.child(Rewrite.class); + + // Ipv6 + final InstanceIdentifier
+ ipv6SubifcAddressId = SUB_IFC_ID.child(Ipv6.class) + .child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip6.attributes.ipv6.Address.class); + registry.addAfter(new GenericListWriter<>(ipv6SubifcAddressId, + new SubInterfaceIpv6AddressCustomizer(jvpp, ifcNamingContext)), rewriteId); + final InstanceIdentifier + ipv6NeighborId = SUB_IFC_ID.child(Ipv6.class) + .child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip6.attributes.ipv6.Neighbor.class); + registry.addAfter(new GenericListWriter<>(ipv6NeighborId, + new SubInterfaceIpv6NeighbourCustomizer(jvpp, ifcNamingContext)), rewriteId); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubInterfaceStateIpv4ReaderFactory.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubInterfaceStateIpv4ReaderFactory.java new file mode 100644 index 000000000..920006df6 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubInterfaceStateIpv4ReaderFactory.java @@ -0,0 +1,67 @@ +/* + * 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.factory; + +import com.google.inject.Inject; +import com.google.inject.name.Named; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfacesstate.ip.v4.subinterface.SubInterfaceIpv4AddressCustomizer; +import io.fd.hc2vpp.v3po.interfacesstate.ip.v4.subinterface.SubInterfaceIpv4NeighbourCustomizer; +import io.fd.honeycomb.translate.impl.read.GenericInitListReader; +import io.fd.honeycomb.translate.impl.read.GenericListReader; +import io.fd.honeycomb.translate.read.ReaderFactory; +import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder; +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.rev161214.SubinterfaceStateAugmentation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.SubInterfaces; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.Ipv4; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.Ipv4Builder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.Address; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.Neighbor; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + + +public class SubInterfaceStateIpv4ReaderFactory implements ReaderFactory { + + @Inject + private FutureJVppCore jvpp; + + @Inject + @Named("interface-context") + private NamingContext ifcNamingContext; + + @Override + public void init(@Nonnull final ModifiableReaderRegistryBuilder registry) { + + final InstanceIdentifier subIfcId = + InterfacesStateReaderFactory.IFC_ID.augmentation(SubinterfaceStateAugmentation.class) + .child(SubInterfaces.class).child(SubInterface.class); + + // Ipv4(Structural) + final InstanceIdentifier ipv4Id = subIfcId.child(Ipv4.class); + registry.addStructuralReader(ipv4Id, Ipv4Builder.class); + // Address + registry.add( + new GenericInitListReader<>(ipv4Id.child(Address.class), + new SubInterfaceIpv4AddressCustomizer(jvpp, ifcNamingContext))); + + registry.add(new GenericListReader<>(ipv4Id.child(Neighbor.class), + new SubInterfaceIpv4NeighbourCustomizer(jvpp, ifcNamingContext))); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubInterfaceStateIpv6ReaderFactory.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubInterfaceStateIpv6ReaderFactory.java new file mode 100644 index 000000000..fc5283213 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubInterfaceStateIpv6ReaderFactory.java @@ -0,0 +1,67 @@ +/* + * 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.factory; + + +import com.google.inject.Inject; +import com.google.inject.name.Named; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfacesstate.ip.v6.subinterface.SubInterfaceIpv6AddressCustomizer; +import io.fd.hc2vpp.v3po.interfacesstate.ip.v6.subinterface.SubInterfaceIpv6NeighbourCustomizer; +import io.fd.honeycomb.translate.impl.read.GenericInitListReader; +import io.fd.honeycomb.translate.impl.read.GenericListReader; +import io.fd.honeycomb.translate.read.ReaderFactory; +import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder; +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.rev161214.SubinterfaceStateAugmentation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.SubInterfaces; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip6.attributes.Ipv6; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip6.attributes.Ipv6Builder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip6.attributes.ipv6.Address; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip6.attributes.ipv6.Neighbor; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class SubInterfaceStateIpv6ReaderFactory implements ReaderFactory { + + @Inject + private FutureJVppCore jvpp; + + @Inject + @Named("interface-context") + private NamingContext ifcNamingContext; + + @Override + public void init(@Nonnull final ModifiableReaderRegistryBuilder registry) { + + final InstanceIdentifier subIfcId = + InterfacesStateReaderFactory.IFC_ID.augmentation(SubinterfaceStateAugmentation.class) + .child(SubInterfaces.class).child(SubInterface.class); + + // Ipv6(Structural) + final InstanceIdentifier ipv6Id = subIfcId.child(Ipv6.class); + registry.addStructuralReader(ipv6Id, Ipv6Builder.class); + // Address + registry.add( + new GenericInitListReader<>(ipv6Id.child(Address.class), + new SubInterfaceIpv6AddressCustomizer(jvpp, ifcNamingContext))); + + registry.add(new GenericListReader<>(ipv6Id.child(Neighbor.class), + new SubInterfaceIpv6NeighbourCustomizer(jvpp, ifcNamingContext))); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubinterfaceAugmentationWriterFactory.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubinterfaceAugmentationWriterFactory.java index 42743c227..7a60c7dae 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubinterfaceAugmentationWriterFactory.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubinterfaceAugmentationWriterFactory.java @@ -24,7 +24,6 @@ import io.fd.hc2vpp.v3po.interfaces.RewriteCustomizer; import io.fd.hc2vpp.v3po.interfaces.SubInterfaceCustomizer; import io.fd.hc2vpp.v3po.interfaces.SubInterfaceL2Customizer; import io.fd.hc2vpp.v3po.interfaces.acl.ingress.SubInterfaceAclCustomizer; -import io.fd.hc2vpp.v3po.interfaces.ip.SubInterfaceIpv4AddressCustomizer; import io.fd.hc2vpp.v3po.vppclassifier.VppClassifierContextManager; import io.fd.honeycomb.translate.impl.write.GenericListWriter; import io.fd.honeycomb.translate.impl.write.GenericWriter; @@ -46,8 +45,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.acl.Ingress; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.l2.Rewrite; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.tags.Tag; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.Ipv4; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.Address; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.tag.rewrite.PushTags; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -106,11 +103,6 @@ public final class SubinterfaceAugmentationWriterFactory implements WriterFactor org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.Dot1qTag.class)), new GenericWriter<>(rewriteId, new RewriteCustomizer(jvpp, ifcContext)), L2_ID); - // Ipv4(handled after L2 and L2/rewrite is done) = - final InstanceIdentifier
ipv4SubifcAddressId = SUB_IFC_ID.child(Ipv4.class).child(Address.class); - registry.addAfter(new GenericListWriter<>(ipv4SubifcAddressId, - new SubInterfaceIpv4AddressCustomizer(jvpp, ifcContext)), - rewriteId); // Ingress (execute after classify table and session writers) // also handles L2Acl, Ip4Acl and Ip6Acl: diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubinterfaceStateAugmentationReaderFactory.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubinterfaceStateAugmentationReaderFactory.java index 8d44fccfc..50233b690 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubinterfaceStateAugmentationReaderFactory.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubinterfaceStateAugmentationReaderFactory.java @@ -24,7 +24,6 @@ import io.fd.hc2vpp.v3po.interfacesstate.RewriteCustomizer; import io.fd.hc2vpp.v3po.interfacesstate.SubInterfaceCustomizer; import io.fd.hc2vpp.v3po.interfacesstate.SubInterfaceL2Customizer; import io.fd.hc2vpp.v3po.interfacesstate.acl.ingress.SubInterfaceAclCustomizer; -import io.fd.hc2vpp.v3po.interfacesstate.ip.SubInterfaceIpv4AddressCustomizer; import io.fd.hc2vpp.v3po.vppclassifier.VppClassifierContextManager; import io.fd.honeycomb.translate.impl.read.GenericInitListReader; import io.fd.honeycomb.translate.impl.read.GenericInitReader; @@ -50,9 +49,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.acl.Ingress; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.l2.Rewrite; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.base.attributes.tags.Tag; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.Ipv4; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.Ipv4Builder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.Address; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.tag.rewrite.PushTags; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -102,13 +98,7 @@ public final class SubinterfaceStateAugmentationReaderFactory implements ReaderF .child( org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.Dot1qTag.class)), new GenericReader<>(l2Id.child(Rewrite.class), new RewriteCustomizer(jvpp, ifcCtx))); - // Ipv4(Structural) - final InstanceIdentifier ipv4Id = subIfcId.child(Ipv4.class); - registry.addStructuralReader(ipv4Id, Ipv4Builder.class); - // Address - registry.add( - new GenericInitListReader<>(ipv4Id.child(Address.class), - new SubInterfaceIpv4AddressCustomizer(jvpp, ifcCtx))); + // Acl(Structural) final InstanceIdentifier aclIid = subIfcId.child(Acl.class); registry.addStructuralReader(aclIid, AclBuilder.class); diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/IpWriter.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/IpWriter.java new file mode 100644 index 000000000..795dc4587 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/IpWriter.java @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2016 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.ip; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import io.fd.hc2vpp.common.translate.util.AddressTranslator; +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.MappingContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.core.dto.IpNeighborAddDel; +import io.fd.vpp.jvpp.core.dto.SwInterfaceAddDelAddress; +import io.fd.vpp.jvpp.core.dto.SwInterfaceAddDelAddressReply; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.concurrent.CompletionStage; +import java.util.function.Supplier; +import javax.annotation.Nonnegative; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone; +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.rev161214.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +/** + * Utility class providing Ipv4/6 CUD support. + */ +public interface IpWriter extends ByteDataTranslator, AddressTranslator, JvppReplyConsumer { + + int DOTTED_QUAD_MASK_LENGTH = 4; + int IPV4_ADDRESS_PART_BITS_COUNT = 8; + int NETMASK_PART_LIMIT = 256; // 2 power to 8 + + default void addDelAddress(@Nonnull final FutureJVppCore futureJVppCore, final boolean add, + final InstanceIdentifier id, + @Nonnegative final int ifaceId, + @Nonnull final Ipv4AddressNoZone address, @Nonnegative final byte prefixLength) + throws WriteFailedException { + checkArgument(prefixLength > 0, "Invalid prefix length"); + checkNotNull(address, "address should not be null"); + + final byte[] addressBytes = ipv4AddressNoZoneToArray(address); + + final CompletionStage swInterfaceAddDelAddressReplyCompletionStage = + futureJVppCore.swInterfaceAddDelAddress( + getSwInterfaceAddDelAddressRequest(ifaceId, booleanToByte(add) /* isAdd */, + (byte) 0 /* isIpv6 */, (byte) 0 /* delAll */, prefixLength, addressBytes)); + + getReplyForWrite(swInterfaceAddDelAddressReplyCompletionStage.toCompletableFuture(), id); + } + + default void addDelAddress(@Nonnull final FutureJVppCore futureJVppCore, final boolean add, + final InstanceIdentifier id, + @Nonnegative final int ifaceId, + @Nonnull final Ipv6AddressNoZone address, @Nonnegative final byte prefixLength) + throws WriteFailedException { + checkNotNull(address, "address should not be null"); + + final byte[] addressBytes = ipv6AddressNoZoneToArray(address); + + final CompletionStage swInterfaceAddDelAddressReplyCompletionStage = + futureJVppCore.swInterfaceAddDelAddress( + getSwInterfaceAddDelAddressRequest(ifaceId, booleanToByte(add) /* isAdd */, + (byte) 1 /* isIpv6 */, (byte) 0 /* delAll */, prefixLength, addressBytes)); + + getReplyForWrite(swInterfaceAddDelAddressReplyCompletionStage.toCompletableFuture(), id); + } + + default SwInterfaceAddDelAddress getSwInterfaceAddDelAddressRequest(final int swIfc, final byte isAdd, + final byte ipv6, final byte deleteAll, + final byte length, final byte[] addr) { + final SwInterfaceAddDelAddress swInterfaceAddDelAddress = new SwInterfaceAddDelAddress(); + swInterfaceAddDelAddress.swIfIndex = swIfc; + swInterfaceAddDelAddress.isAdd = isAdd; + swInterfaceAddDelAddress.isIpv6 = ipv6; + swInterfaceAddDelAddress.delAll = deleteAll; + swInterfaceAddDelAddress.address = addr; + swInterfaceAddDelAddress.addressLength = length; + return swInterfaceAddDelAddress; + } + + /** + * Returns the prefix size in bits of the specified subnet mask. Example: For the subnet mask 255.255.255.128 it + * returns 25 while for 255.0.0.0 it returns 8. If the passed subnetMask array is not complete or contains not only + * leading ones, IllegalArgumentExpression is thrown + * + * @param mask the subnet mask in dot notation 255.255.255.255 + * @return the prefix length as number of bits + */ + default byte getSubnetMaskLength(final String mask) { + String[] maskParts = mask.split("\\."); + + checkArgument(maskParts.length == DOTTED_QUAD_MASK_LENGTH, + "Network mask %s is not in Quad Dotted Decimal notation!", mask); + + long maskAsNumber = 0; + for (int i = 0; i < DOTTED_QUAD_MASK_LENGTH; i++) { + maskAsNumber <<= IPV4_ADDRESS_PART_BITS_COUNT; + int value = Integer.parseInt(maskParts[i]); + checkArgument(value < NETMASK_PART_LIMIT, "Network mask %s contains invalid number(s) over 255!", mask); + checkArgument(value >= 0, "Network mask %s contains invalid negative number(s)!", mask); + maskAsNumber += value; + } + + String bits = Long.toBinaryString(maskAsNumber); + checkArgument(bits.length() == IPV4_ADDRESS_PART_BITS_COUNT * DOTTED_QUAD_MASK_LENGTH, + "Incorrect network mask %s", mask); + final int leadingOnes = bits.indexOf('0'); + checkArgument(leadingOnes != -1, "Broadcast address %s is not allowed!", mask); + checkArgument(bits.substring(leadingOnes).indexOf('1') == -1, + "Non-contiguous network mask %s is not allowed!", mask); + return (byte) leadingOnes; + } + + default int subInterfaceIndex(final InstanceIdentifier id, final NamingContext interfaceContext, + final MappingContext mappingContext) { + return interfaceContext + .getIndex(id.firstKeyOf(Interface.class).getName() + "." + id.firstKeyOf(SubInterface.class).getIdentifier(), + mappingContext); + } + + default void addDelNeighbour(@Nonnull final InstanceIdentifier id, + @Nonnull final Supplier requestSupplier, + @Nonnull final FutureJVppCore api) throws WriteFailedException { + getReplyForWrite(api.ipNeighborAddDel(requestSupplier.get()).toCompletableFuture(), id); + } + + default IpNeighborAddDel preBindIpv4Request(final boolean add) { + IpNeighborAddDel request = staticPreBindRequest(add); + request.isIpv6 = 0; + + return request; + } + + default IpNeighborAddDel preBindIpv6Request(final boolean add) { + IpNeighborAddDel request = staticPreBindRequest(add); + request.isIpv6 = 1; + + return request; + } + + static IpNeighborAddDel staticPreBindRequest(final boolean add) { + IpNeighborAddDel request = new IpNeighborAddDel(); + + request.isAdd = ByteDataTranslator.INSTANCE.booleanToByte(add); + request.isStatic = 1; + return request; + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/Ipv4AddressCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/Ipv4AddressCustomizer.java deleted file mode 100644 index 6a6bb6c35..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/Ipv4AddressCustomizer.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (c) 2016 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.ip; - -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Optional; -import io.fd.hc2vpp.v3po.interfaces.ip.subnet.validation.SubnetValidationException; -import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; -import io.fd.honeycomb.translate.util.RWUtils; -import io.fd.hc2vpp.v3po.interfaces.ip.subnet.validation.SubnetValidator; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -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.ip.rev140616.interfaces._interface.Ipv4; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.AddressKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.Subnet; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.Netmask; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.PrefixLength; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DottedQuad; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Customizer for writing {@link Address} - */ -public class Ipv4AddressCustomizer extends FutureJVppCustomizer - implements ListWriterCustomizer, Ipv4Writer { - - private static final Logger LOG = LoggerFactory.getLogger(Ipv4AddressCustomizer.class); - private final NamingContext interfaceContext; - private final SubnetValidator subnetValidator; - - Ipv4AddressCustomizer(@Nonnull final FutureJVppCore futureJVppCore, @Nonnull final NamingContext interfaceContext, - @Nonnull final SubnetValidator subnetValidator) { - super(futureJVppCore); - this.interfaceContext = checkNotNull(interfaceContext, "Interface context cannot be null"); - this.subnetValidator = checkNotNull(subnetValidator, "Subnet validator cannot be null"); - } - - public Ipv4AddressCustomizer(@Nonnull final FutureJVppCore futureJVppCore, - @Nonnull final NamingContext interfaceContext) { - this(futureJVppCore, interfaceContext, new SubnetValidator()); - } - - @Override - public void writeCurrentAttributes(InstanceIdentifier
id, Address dataAfter, WriteContext writeContext) - throws WriteFailedException { - - final String interfaceName = id.firstKeyOf(Interface.class).getName(); - final int interfaceIndex = interfaceContext.getIndex(interfaceName, writeContext.getMappingContext()); - - // checks whether address is not from same subnet of some address already defined on this interface - try { - - final InstanceIdentifier parentId = RWUtils.cutId(id, InstanceIdentifier.create(Ipv4.class)); - final Optional ipv4Optional = writeContext.readAfter(parentId); - - //no need to check isPresent() - we are inside of address customizer, therefore there must be Address data - //that is being processed by infrastructure - - subnetValidator.checkNotAddingToSameSubnet(ipv4Optional.get().getAddress()); - } catch (SubnetValidationException e) { - throw new WriteFailedException(id, e); - } - - setAddress(true, id, interfaceName, interfaceIndex, dataAfter, writeContext); - } - - @Override - public void updateCurrentAttributes(InstanceIdentifier
id, Address dataBefore, Address dataAfter, - WriteContext writeContext) throws WriteFailedException { - throw new WriteFailedException.UpdateFailedException(id, dataBefore, dataAfter, - new UnsupportedOperationException("Operation not supported")); - } - - @Override - public void deleteCurrentAttributes(InstanceIdentifier
id, Address dataBefore, WriteContext writeContext) - throws WriteFailedException { - - final String interfaceName = id.firstKeyOf(Interface.class).getName(); - final int interfaceIndex = interfaceContext.getIndex(interfaceName, writeContext.getMappingContext()); - - setAddress(false, id, interfaceName, interfaceIndex, dataBefore, writeContext); - } - - private void setAddress(boolean add, final InstanceIdentifier
id, final String interfaceName, - final int interfaceIndex, final Address address, - final WriteContext writeContext) throws WriteFailedException { - - Subnet subnet = address.getSubnet(); - - if (subnet instanceof PrefixLength) { - setPrefixLengthSubnet(add, id, interfaceName, interfaceIndex, address, (PrefixLength) subnet); - } else if (subnet instanceof Netmask) { - setNetmaskSubnet(add, id, interfaceName, interfaceIndex, address, (Netmask) subnet); - } else { - LOG.error("Unable to handle subnet of type {}", subnet.getClass()); - throw new WriteFailedException(id, "Unable to handle subnet of type " + subnet.getClass()); - } - } - - private void setNetmaskSubnet(final boolean add, @Nonnull final InstanceIdentifier
id, - @Nonnull final String interfaceName, final int interfaceIndex, - @Nonnull final Address address, @Nonnull final Netmask subnet) - throws WriteFailedException { - - LOG.debug("Setting Subnet(subnet-mask) for interface: {}(id={}). Subnet: {}, address: {}", - interfaceName, interfaceIndex, subnet, address); - - final DottedQuad netmask = subnet.getNetmask(); - checkNotNull(netmask, "netmask value should not be null"); - - final byte subnetLength = getSubnetMaskLength(netmask.getValue()); - addDelAddress(getFutureJVpp(), add, id, interfaceIndex, address.getIp(), subnetLength); - } - - private void setPrefixLengthSubnet(final boolean add, @Nonnull final InstanceIdentifier
id, - @Nonnull final String interfaceName, final int interfaceIndex, - @Nonnull final Address address, @Nonnull final PrefixLength subnet) - throws WriteFailedException { - LOG.debug("Setting Subnet(prefix-length) for interface: {}(id={}). Subnet: {}, address: {}", - interfaceName, interfaceIndex, subnet, address); - - addDelAddress(getFutureJVpp(), add, id, interfaceIndex, address.getIp(), - subnet.getPrefixLength().byteValue()); - - LOG.debug("Subnet(prefix-length) set successfully for interface: {}(id={}). Subnet: {}, address: {}", - interfaceName, interfaceIndex, subnet, address); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/Ipv4Customizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/Ipv4Customizer.java deleted file mode 100644 index ff86331b1..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/Ipv4Customizer.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2016 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.ip; - -import io.fd.honeycomb.translate.spi.write.WriterCustomizer; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; -import io.fd.honeycomb.translate.write.WriteContext; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv4; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class Ipv4Customizer extends FutureJVppCustomizer implements WriterCustomizer { - - private static final Logger LOG = LoggerFactory.getLogger(Ipv4Customizer.class); - - public Ipv4Customizer(final FutureJVppCore vppApi) { - super(vppApi); - } - - @Override - public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final Ipv4 dataAfter, @Nonnull final WriteContext writeContext) { - LOG.debug("Handling Ipv4 leaves (mtu, forwarding) is not supported by VPP API. Ignoring configuration"); - } - - @Override - public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final Ipv4 dataBefore, @Nonnull final Ipv4 dataAfter, - @Nonnull final WriteContext writeContext) { - LOG.debug("Handling Ipv4 leaves (mtu, forwarding) is not supported by VPP API. Ignoring configuration"); - } - - @Override - public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final Ipv4 dataBefore, @Nonnull final WriteContext writeContext) { - LOG.debug("Handling Ipv4 leaves (mtu, forwarding) is not supported by VPP API. Ignoring configuration"); - } - -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/Ipv4NeighbourCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/Ipv4NeighbourCustomizer.java deleted file mode 100644 index 1a1c2d2c0..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/Ipv4NeighbourCustomizer.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2016 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.ip; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; - -import io.fd.honeycomb.translate.MappingContext; -import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; -import io.fd.hc2vpp.common.translate.util.AddressTranslator; -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.honeycomb.translate.write.WriteContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.vpp.jvpp.core.dto.IpNeighborAddDel; -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.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.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -/** - * Customizer for writing {@link Neighbor} for {@link Ipv4}. - */ -public class Ipv4NeighbourCustomizer extends FutureJVppCustomizer - implements ListWriterCustomizer, ByteDataTranslator, AddressTranslator, - JvppReplyConsumer { - - - private static final Logger LOG = LoggerFactory.getLogger(Ipv4NeighbourCustomizer.class); - final NamingContext interfaceContext; - - public Ipv4NeighbourCustomizer(final FutureJVppCore futureJVppCore, final NamingContext interfaceContext) { - super(futureJVppCore); - this.interfaceContext = interfaceContext; - } - - @Override - public void writeCurrentAttributes(@Nonnull InstanceIdentifier id, @Nonnull Neighbor dataAfter, - @Nonnull WriteContext writeContext) - throws WriteFailedException { - - checkNotNull(dataAfter, "Cannot write null neighbour"); - checkArgument(id.firstKeyOf(Interface.class) != null, "No parent interface key found"); - - LOG.debug("Processing request for Neigbour write"); - String interfaceName = id.firstKeyOf(Interface.class).getName(); - MappingContext mappingContext = writeContext.getMappingContext(); - - checkState(interfaceContext.containsIndex(interfaceName, mappingContext), - "Mapping does not contains mapping for provider interface name ".concat(interfaceName)); - - LOG.debug("Parent interface index found"); - addDelNeighbourAndReply(id, true, - interfaceContext.getIndex(interfaceName, mappingContext), dataAfter); - LOG.info("Neighbour successfully written"); - } - - @Override - public void updateCurrentAttributes(@Nonnull InstanceIdentifier id, @Nonnull Neighbor dataBefore, - @Nonnull Neighbor dataAfter, - @Nonnull WriteContext writeContext) throws WriteFailedException { - throw new UnsupportedOperationException("Operation not supported"); - } - - @Override - public void deleteCurrentAttributes(@Nonnull InstanceIdentifier id, @Nonnull Neighbor dataBefore, - @Nonnull WriteContext writeContext) - throws WriteFailedException { - - checkNotNull(dataBefore, "Cannot delete null neighbour"); - checkArgument(id.firstKeyOf(Interface.class) != null, "No parent interface key found"); - - LOG.debug("Processing request for Neigbour delete"); - String interfaceName = id.firstKeyOf(Interface.class).getName(); - MappingContext mappingContext = writeContext.getMappingContext(); - - checkState(interfaceContext.containsIndex(interfaceName, mappingContext), - "Mapping does not contains mapping for provider interface name %s", interfaceName); - - LOG.debug("Parent interface[{}] index found", interfaceName); - - addDelNeighbourAndReply(id, false, - interfaceContext.getIndex(interfaceName, mappingContext), dataBefore); - LOG.info("Neighbour {} successfully deleted", id); - } - - private void addDelNeighbourAndReply(InstanceIdentifier id, boolean add, int parentInterfaceIndex, - Neighbor data) throws WriteFailedException { - - IpNeighborAddDel request = new IpNeighborAddDel(); - - request.isAdd = booleanToByte(add); - request.isIpv6 = 0; - request.isStatic = 1; - request.dstAddress = ipv4AddressNoZoneToArray(data.getIp()); - request.macAddress = parseMac(data.getLinkLayerAddress().getValue()); - request.swIfIndex = parentInterfaceIndex; - - //TODO HONEYCOMB-182 if it is necessary for future use ,make adjustments to be able to set vrfid - //request.vrfId - getReplyForWrite(getFutureJVpp().ipNeighborAddDel(request).toCompletableFuture(), id); - } -} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/Ipv4Writer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/Ipv4Writer.java deleted file mode 100644 index 36e1800e1..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/Ipv4Writer.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2016 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.ip; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.common.translate.util.Ipv4Translator; -import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.vpp.jvpp.core.dto.SwInterfaceAddDelAddress; -import io.fd.vpp.jvpp.core.dto.SwInterfaceAddDelAddressReply; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; -import java.util.concurrent.CompletionStage; -import javax.annotation.Nonnegative; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -/** - * Utility class providing Ipv4 CUD support. - */ -public interface Ipv4Writer extends ByteDataTranslator, Ipv4Translator, JvppReplyConsumer { - - int DOTTED_QUAD_MASK_LENGTH = 4; - int IPV4_ADDRESS_PART_BITS_COUNT = 8; - int NETMASK_PART_LIMIT = 256; // 2 power to 8 - - default void addDelAddress(@Nonnull final FutureJVppCore futureJVppCore, final boolean add, - final InstanceIdentifier id, - @Nonnegative final int ifaceId, - @Nonnull final Ipv4AddressNoZone address, @Nonnegative final byte prefixLength) - throws WriteFailedException { - checkArgument(prefixLength > 0, "Invalid prefix length"); - checkNotNull(address, "address should not be null"); - - final byte[] addressBytes = ipv4AddressNoZoneToArray(address); - - final CompletionStage swInterfaceAddDelAddressReplyCompletionStage = - futureJVppCore.swInterfaceAddDelAddress( - getSwInterfaceAddDelAddressRequest(ifaceId, booleanToByte(add) /* isAdd */, - (byte) 0 /* isIpv6 */, (byte) 0 /* delAll */, prefixLength, addressBytes)); - - getReplyForWrite(swInterfaceAddDelAddressReplyCompletionStage.toCompletableFuture(), id); - } - - default SwInterfaceAddDelAddress getSwInterfaceAddDelAddressRequest(final int swIfc, final byte isAdd, - final byte ipv6, final byte deleteAll, - final byte length, final byte[] addr) { - final SwInterfaceAddDelAddress swInterfaceAddDelAddress = new SwInterfaceAddDelAddress(); - swInterfaceAddDelAddress.swIfIndex = swIfc; - swInterfaceAddDelAddress.isAdd = isAdd; - swInterfaceAddDelAddress.isIpv6 = ipv6; - swInterfaceAddDelAddress.delAll = deleteAll; - swInterfaceAddDelAddress.address = addr; - swInterfaceAddDelAddress.addressLength = length; - return swInterfaceAddDelAddress; - } - - /** - * Returns the prefix size in bits of the specified subnet mask. Example: For the subnet mask 255.255.255.128 it - * returns 25 while for 255.0.0.0 it returns 8. If the passed subnetMask array is not complete or contains not only - * leading ones, IllegalArgumentExpression is thrown - * - * @param mask the subnet mask in dot notation 255.255.255.255 - * @return the prefix length as number of bits - */ - default byte getSubnetMaskLength(final String mask) { - String[] maskParts = mask.split("\\."); - - checkArgument(maskParts.length == DOTTED_QUAD_MASK_LENGTH, - "Network mask %s is not in Quad Dotted Decimal notation!", mask); - - long maskAsNumber = 0; - for (int i = 0; i < DOTTED_QUAD_MASK_LENGTH; i++) { - maskAsNumber <<= IPV4_ADDRESS_PART_BITS_COUNT; - int value = Integer.parseInt(maskParts[i]); - checkArgument(value < NETMASK_PART_LIMIT, "Network mask %s contains invalid number(s) over 255!", mask); - checkArgument(value >= 0, "Network mask %s contains invalid negative number(s)!", mask); - maskAsNumber += value; - } - - String bits = Long.toBinaryString(maskAsNumber); - checkArgument(bits.length() == IPV4_ADDRESS_PART_BITS_COUNT * DOTTED_QUAD_MASK_LENGTH, - "Incorrect network mask %s", mask); - final int leadingOnes = bits.indexOf('0'); - checkArgument(leadingOnes != -1, "Broadcast address %s is not allowed!", mask); - checkArgument(bits.substring(leadingOnes).indexOf('1') == -1, - "Non-contiguous network mask %s is not allowed!", mask); - return (byte) leadingOnes; - } - -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/Ipv6Customizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/Ipv6Customizer.java deleted file mode 100644 index 85f190d83..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/Ipv6Customizer.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2016 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.ip; - -import io.fd.honeycomb.translate.spi.write.WriterCustomizer; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; -import io.fd.honeycomb.translate.write.WriteContext; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv6; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class Ipv6Customizer extends FutureJVppCustomizer implements WriterCustomizer { - - private static final Logger LOG = LoggerFactory.getLogger(Ipv6Customizer.class); - - public Ipv6Customizer(final FutureJVppCore vppApi) { - super(vppApi); - } - - @Override - public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final Ipv6 dataAfter, @Nonnull final WriteContext writeContext) { - LOG.warn("Unsupported, ignoring configuration {}", dataAfter); - } - - @Override - public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final Ipv6 dataBefore, @Nonnull final Ipv6 dataAfter, - @Nonnull final WriteContext writeContext) { - LOG.warn("Unsupported, ignoring configuration {}", dataAfter); - } - - @Override - public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final Ipv6 dataBefore, @Nonnull final WriteContext writeContext) { - LOG.warn("Unsupported, ignoring configuration delete {}", id); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/SubInterfaceIpv4AddressCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/SubInterfaceIpv4AddressCustomizer.java deleted file mode 100644 index 214ff36c4..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/SubInterfaceIpv4AddressCustomizer.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (c) 2016 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.ip; - -import static com.google.common.base.Preconditions.checkNotNull; - -import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; -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.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.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DottedQuad; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.sub.interfaces.SubInterfaceKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.Address; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.AddressKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.address.Subnet; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.address.subnet.Netmask; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.address.subnet.PrefixLength; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Write customizer for sub-interface {@link Address} - */ -public class SubInterfaceIpv4AddressCustomizer extends FutureJVppCustomizer - implements ListWriterCustomizer, Ipv4Writer { - - private static final Logger LOG = LoggerFactory.getLogger(SubInterfaceIpv4AddressCustomizer.class); - private final NamingContext interfaceContext; - - public SubInterfaceIpv4AddressCustomizer(@Nonnull final FutureJVppCore futureJVppCore, - @Nonnull final NamingContext interfaceContext) { - super(futureJVppCore); - this.interfaceContext = checkNotNull(interfaceContext, "interface context should not be null"); - } - - @Override - public void writeCurrentAttributes(InstanceIdentifier
id, Address dataAfter, WriteContext writeContext) - throws WriteFailedException { - setAddress(true, id, dataAfter, writeContext); - } - - @Override - public void updateCurrentAttributes(InstanceIdentifier
id, Address dataBefore, Address dataAfter, - WriteContext writeContext) throws WriteFailedException { - throw new WriteFailedException.UpdateFailedException(id, dataBefore, dataAfter, - new UnsupportedOperationException("Operation not supported")); - } - - @Override - public void deleteCurrentAttributes(InstanceIdentifier
id, Address dataBefore, WriteContext writeContext) - throws WriteFailedException { - setAddress(false, id, dataBefore, writeContext); - } - - private void setAddress(boolean add, final InstanceIdentifier
id, final Address address, - final WriteContext writeContext) throws WriteFailedException { - - final String interfaceName = id.firstKeyOf(Interface.class).getName(); - final String subInterfaceName = getSubInterfaceName(id); - final int subInterfaceIndex = interfaceContext.getIndex(subInterfaceName, writeContext.getMappingContext()); - - Subnet subnet = address.getSubnet(); - - if (subnet instanceof PrefixLength) { - setPrefixLengthSubnet(add, id, interfaceName, subInterfaceIndex, address, (PrefixLength) subnet); - } else if (subnet instanceof Netmask) { - setNetmaskSubnet(add, id, interfaceName, subInterfaceIndex, address, (Netmask) subnet); - } else { - LOG.error("Unable to handle subnet of type {}", subnet.getClass()); - throw new WriteFailedException(id, "Unable to handle subnet of type " + subnet.getClass()); - } - } - - private String getSubInterfaceName(@Nonnull final InstanceIdentifier
id) { - final InterfaceKey parentInterfacekey = id.firstKeyOf(Interface.class); - final SubInterfaceKey subInterfacekey = id.firstKeyOf(SubInterface.class); - return SubInterfaceUtils - .getSubInterfaceName(parentInterfacekey.getName(), subInterfacekey.getIdentifier().intValue()); - } - - private void setNetmaskSubnet(final boolean add, @Nonnull final InstanceIdentifier
id, - @Nonnull final String subInterfaceName, final int subInterfaceIndex, - @Nonnull final Address address, @Nonnull final Netmask subnet) - throws WriteFailedException { - - LOG.debug("Setting Subnet(subnet-mask) for sub-interface: {}(id={}). Subnet: {}, address: {}", - subInterfaceName, subInterfaceIndex, subnet, address); - - final DottedQuad netmask = subnet.getNetmask(); - checkNotNull(netmask, "netmask value should not be null"); - - final byte subnetLength = getSubnetMaskLength(netmask.getValue()); - addDelAddress(getFutureJVpp(), add, id, subInterfaceIndex, address.getIp(), subnetLength); - } - - private void setPrefixLengthSubnet(final boolean add, @Nonnull final InstanceIdentifier
id, - @Nonnull final String subInterfaceName, final int subInterfaceIndex, - @Nonnull final Address address, @Nonnull final PrefixLength subnet) - throws WriteFailedException { - LOG.debug("Setting Subnet(prefix-length) for sub-interface: {}(id={}). Subnet: {}, address: {}", - subInterfaceName, subInterfaceIndex, subnet, address); - - addDelAddress(getFutureJVpp(), add, id, subInterfaceIndex, address.getIp(), - subnet.getPrefixLength().byteValue()); - - LOG.debug("Subnet(prefix-length) set successfully for sub-interface: {}(id={}). Subnet: {}, address: {}", - subInterfaceName, subInterfaceIndex, subnet, address); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/subnet/validation/Ipv4SubnetValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/subnet/validation/Ipv4SubnetValidator.java new file mode 100644 index 000000000..28cd70440 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/subnet/validation/Ipv4SubnetValidator.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2016 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.ip.subnet.validation; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.base.Function; +import com.google.common.collect.Multimap; +import com.google.common.collect.Multimaps; +import io.fd.hc2vpp.v3po.interfaces.ip.IpWriter; +import java.util.List; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.Subnet; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.Netmask; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.PrefixLength; + +/** + * Validator for detecting if there is an attempt to assign multiple addresses from same subnet + */ +public class Ipv4SubnetValidator implements IpWriter { + + /** + * Checks whether data provided for writing are not in collision with already existing data + */ + public void checkNotAddingToSameSubnet(@Nonnull final List
addresses) + throws SubnetValidationException { + + final Multimap prefixLengthRegister = Multimaps.index(addresses, toPrefixLength()); + final int keySetSize = prefixLengthRegister.keySet().size(); + + if (keySetSize == 0 || keySetSize == addresses.size()) { + //this means that every key is unique(has only one value) or no addresses were prefix-length based ,so there is no conflict + return; + } + + //finds conflicting prefix + final Short conflictingPrefix = prefixLengthRegister.keySet() + .stream() + .filter(a -> prefixLengthRegister.get(a).size() > 1) + .findFirst() + .get(); + + //and reports it with affected addresses + throw SubnetValidationException + .forConflictingData(conflictingPrefix, prefixLengthRegister.get(conflictingPrefix)); + } + + private Function toPrefixLength() { + return (final Address address) -> { + final Subnet subnet = address.getSubnet(); + + if (subnet instanceof PrefixLength) { + return ((PrefixLength) subnet).getPrefixLength(); + } + + if (address.getSubnet() instanceof Netmask) { + return (short) getSubnetMaskLength( + checkNotNull(((Netmask) subnet).getNetmask(), "No netmask defined for %s", subnet) + .getValue()); + } + + throw new IllegalArgumentException("Unsupported subnet : " + subnet); + }; + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/subnet/validation/SubnetValidator.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/subnet/validation/SubnetValidator.java deleted file mode 100644 index c5b011e07..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/subnet/validation/SubnetValidator.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2016 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.ip.subnet.validation; - -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Function; -import com.google.common.collect.Multimap; -import com.google.common.collect.Multimaps; -import io.fd.hc2vpp.v3po.interfaces.ip.Ipv4Writer; -import java.util.List; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.Subnet; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.Netmask; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.PrefixLength; - -/** - * Validator for detecting if there is an attempt to assign multiple addresses from same subnet - */ -public class SubnetValidator implements Ipv4Writer { - - /** - * Checks whether data provided for writing are not in collision with already existing data - */ - public void checkNotAddingToSameSubnet(@Nonnull final List
addresses) - throws SubnetValidationException { - - final Multimap prefixLengthRegister = Multimaps.index(addresses, toPrefixLength()); - final int keySetSize = prefixLengthRegister.keySet().size(); - - if (keySetSize == 0 || keySetSize == addresses.size()) { - //this means that every key is unique(has only one value) or no addresses were prefix-length based ,so there is no conflict - return; - } - - //finds conflicting prefix - final Short conflictingPrefix = prefixLengthRegister.keySet() - .stream() - .filter(a -> prefixLengthRegister.get(a).size() > 1) - .findFirst() - .get(); - - //and reports it with affected addresses - throw SubnetValidationException - .forConflictingData(conflictingPrefix, prefixLengthRegister.get(conflictingPrefix)); - } - - private Function toPrefixLength() { - return (final Address address) -> { - final Subnet subnet = address.getSubnet(); - - if (subnet instanceof PrefixLength) { - return ((PrefixLength) subnet).getPrefixLength(); - } - - if (address.getSubnet() instanceof Netmask) { - return (short) getSubnetMaskLength( - checkNotNull(((Netmask) subnet).getNetmask(), "No netmask defined for %s", subnet) - .getValue()); - } - - throw new IllegalArgumentException("Unsupported subnet : " + subnet); - }; - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/Ipv4AddressCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/Ipv4AddressCustomizer.java new file mode 100644 index 000000000..0860436d3 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/Ipv4AddressCustomizer.java @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2016 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.ip.v4; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Optional; +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfaces.ip.IpWriter; +import io.fd.hc2vpp.v3po.interfaces.ip.subnet.validation.Ipv4SubnetValidator; +import io.fd.hc2vpp.v3po.interfaces.ip.subnet.validation.SubnetValidationException; +import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; +import io.fd.honeycomb.translate.util.RWUtils; +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.ip.rev140616.interfaces._interface.Ipv4; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.AddressKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.Subnet; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.Netmask; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.PrefixLength; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DottedQuad; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Customizer for writing {@link Address} + */ +public class Ipv4AddressCustomizer extends FutureJVppCustomizer + implements ListWriterCustomizer, IpWriter { + + private static final Logger LOG = LoggerFactory.getLogger(Ipv4AddressCustomizer.class); + private final NamingContext interfaceContext; + private final Ipv4SubnetValidator subnetValidator; + + @VisibleForTesting + Ipv4AddressCustomizer(@Nonnull final FutureJVppCore futureJVppCore, @Nonnull final NamingContext interfaceContext, + @Nonnull final Ipv4SubnetValidator subnetValidator) { + super(futureJVppCore); + this.interfaceContext = checkNotNull(interfaceContext, "Interface context cannot be null"); + this.subnetValidator = checkNotNull(subnetValidator, "Subnet validator cannot be null"); + } + + public Ipv4AddressCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext interfaceContext) { + this(futureJVppCore, interfaceContext, new Ipv4SubnetValidator()); + } + + @Override + public void writeCurrentAttributes(InstanceIdentifier
id, Address dataAfter, WriteContext writeContext) + throws WriteFailedException { + + final String interfaceName = id.firstKeyOf(Interface.class).getName(); + final int interfaceIndex = interfaceContext.getIndex(interfaceName, writeContext.getMappingContext()); + + // checks whether address is not from same subnet of some address already defined on this interface + try { + + final InstanceIdentifier parentId = RWUtils.cutId(id, InstanceIdentifier.create(Ipv4.class)); + final Optional ipv4Optional = writeContext.readAfter(parentId); + + //no need to check isPresent() - we are inside of address customizer, therefore there must be Address data + //that is being processed by infrastructure + + subnetValidator.checkNotAddingToSameSubnet(ipv4Optional.get().getAddress()); + } catch (SubnetValidationException e) { + throw new WriteFailedException(id, e); + } + + setAddress(true, id, interfaceName, interfaceIndex, dataAfter, writeContext); + } + + @Override + public void updateCurrentAttributes(InstanceIdentifier
id, Address dataBefore, Address dataAfter, + WriteContext writeContext) throws WriteFailedException { + throw new WriteFailedException.UpdateFailedException(id, dataBefore, dataAfter, + new UnsupportedOperationException("Operation not supported")); + } + + @Override + public void deleteCurrentAttributes(InstanceIdentifier
id, Address dataBefore, WriteContext writeContext) + throws WriteFailedException { + + final String interfaceName = id.firstKeyOf(Interface.class).getName(); + final int interfaceIndex = interfaceContext.getIndex(interfaceName, writeContext.getMappingContext()); + + setAddress(false, id, interfaceName, interfaceIndex, dataBefore, writeContext); + } + + private void setAddress(boolean add, final InstanceIdentifier
id, final String interfaceName, + final int interfaceIndex, final Address address, + final WriteContext writeContext) throws WriteFailedException { + + Subnet subnet = address.getSubnet(); + + if (subnet instanceof PrefixLength) { + setPrefixLengthSubnet(add, id, interfaceName, interfaceIndex, address, (PrefixLength) subnet); + } else if (subnet instanceof Netmask) { + setNetmaskSubnet(add, id, interfaceName, interfaceIndex, address, (Netmask) subnet); + } else { + LOG.error("Unable to handle subnet of type {}", subnet.getClass()); + throw new WriteFailedException(id, "Unable to handle subnet of type " + subnet.getClass()); + } + } + + private void setNetmaskSubnet(final boolean add, @Nonnull final InstanceIdentifier
id, + @Nonnull final String interfaceName, final int interfaceIndex, + @Nonnull final Address address, @Nonnull final Netmask subnet) + throws WriteFailedException { + + LOG.debug("Setting Subnet(subnet-mask) for interface: {}(id={}). Subnet: {}, address: {}", + interfaceName, interfaceIndex, subnet, address); + + final DottedQuad netmask = subnet.getNetmask(); + checkNotNull(netmask, "netmask value should not be null"); + + final byte subnetLength = getSubnetMaskLength(netmask.getValue()); + addDelAddress(getFutureJVpp(), add, id, interfaceIndex, address.getIp(), subnetLength); + } + + private void setPrefixLengthSubnet(final boolean add, @Nonnull final InstanceIdentifier
id, + @Nonnull final String interfaceName, final int interfaceIndex, + @Nonnull final Address address, @Nonnull final PrefixLength subnet) + throws WriteFailedException { + LOG.debug("Setting Subnet(prefix-length) for interface: {}(id={}). Subnet: {}, address: {}", + interfaceName, interfaceIndex, subnet, address); + + addDelAddress(getFutureJVpp(), add, id, interfaceIndex, address.getIp(), + subnet.getPrefixLength().byteValue()); + + LOG.debug("Subnet(prefix-length) set successfully for interface: {}(id={}). Subnet: {}, address: {}", + interfaceName, interfaceIndex, subnet, address); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/Ipv4Customizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/Ipv4Customizer.java new file mode 100644 index 000000000..15afda271 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/Ipv4Customizer.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2016 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.ip.v4; + +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.honeycomb.translate.spi.write.WriterCustomizer; +import io.fd.honeycomb.translate.write.WriteContext; +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.ip.rev140616.interfaces._interface.Ipv4; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class Ipv4Customizer extends FutureJVppCustomizer implements WriterCustomizer { + + private static final Logger LOG = LoggerFactory.getLogger(Ipv4Customizer.class); + + public Ipv4Customizer(final FutureJVppCore vppApi) { + super(vppApi); + } + + @Override + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final Ipv4 dataAfter, @Nonnull final WriteContext writeContext) { + LOG.debug("Handling Ipv4 leaves (mtu, forwarding) is not supported by VPP API. Ignoring configuration"); + } + + @Override + public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final Ipv4 dataBefore, @Nonnull final Ipv4 dataAfter, + @Nonnull final WriteContext writeContext) { + LOG.debug("Handling Ipv4 leaves (mtu, forwarding) is not supported by VPP API. Ignoring configuration"); + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final Ipv4 dataBefore, @Nonnull final WriteContext writeContext) { + LOG.debug("Handling Ipv4 leaves (mtu, forwarding) is not supported by VPP API. Ignoring configuration"); + } + +} 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 new file mode 100644 index 000000000..b44a827a9 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/Ipv4NeighbourCustomizer.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2016 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.ip.v4; + +import io.fd.hc2vpp.common.translate.util.AddressTranslator; +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.interfaces.ip.IpWriter; +import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.core.dto.IpNeighborAddDel; +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.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.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Customizer for writing {@link Neighbor} for {@link Ipv4}. + */ +public class Ipv4NeighbourCustomizer extends FutureJVppCustomizer + implements ListWriterCustomizer, ByteDataTranslator, AddressTranslator, + IpWriter, JvppReplyConsumer { + + + private static final Logger LOG = LoggerFactory.getLogger(Ipv4NeighbourCustomizer.class); + private final NamingContext interfaceContext; + + public Ipv4NeighbourCustomizer(final FutureJVppCore futureJVppCore, final NamingContext interfaceContext) { + super(futureJVppCore); + this.interfaceContext = interfaceContext; + } + + @Override + public void writeCurrentAttributes(@Nonnull InstanceIdentifier id, @Nonnull Neighbor data, + @Nonnull WriteContext writeContext) + throws WriteFailedException { + + LOG.debug("Processing request for Neighbour {} write", id); + + addDelNeighbour(id, () -> { + IpNeighborAddDel request = preBindIpv4Request(true); + + request.dstAddress = ipv4AddressNoZoneToArray(data.getIp()); + request.macAddress = parseMac(data.getLinkLayerAddress().getValue()); + request.swIfIndex = interfaceContext + .getIndex(id.firstKeyOf(Interface.class).getName(), writeContext.getMappingContext()); + + return request; + }, getFutureJVpp()); + LOG.debug("Neighbour {} successfully written", id); + } + + @Override + public void updateCurrentAttributes(@Nonnull InstanceIdentifier id, @Nonnull Neighbor dataBefore, + @Nonnull Neighbor dataAfter, + @Nonnull WriteContext writeContext) throws WriteFailedException { + throw new UnsupportedOperationException("Operation not supported"); + } + + @Override + public void deleteCurrentAttributes(@Nonnull InstanceIdentifier id, @Nonnull Neighbor data, + @Nonnull WriteContext writeContext) + throws WriteFailedException { + + LOG.debug("Processing request for Neighbour {} delete", id); + + addDelNeighbour(id, () -> { + IpNeighborAddDel request = preBindIpv4Request(false); + + request.dstAddress = ipv4AddressNoZoneToArray(data.getIp()); + request.macAddress = parseMac(data.getLinkLayerAddress().getValue()); + request.swIfIndex = interfaceContext + .getIndex(id.firstKeyOf(Interface.class).getName(), writeContext.getMappingContext()); + + return request; + }, getFutureJVpp()); + LOG.debug("Neighbour {} successfully deleted", id); + } +} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/subinterface/SubInterfaceIpv4AddressCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/subinterface/SubInterfaceIpv4AddressCustomizer.java new file mode 100644 index 000000000..f6b8ead69 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/subinterface/SubInterfaceIpv4AddressCustomizer.java @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2016 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.ip.v4.subinterface; + +import static com.google.common.base.Preconditions.checkNotNull; + +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfaces.ip.IpWriter; +import io.fd.hc2vpp.v3po.util.SubInterfaceUtils; +import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; +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.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DottedQuad; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.sub.interfaces.SubInterfaceKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.Address; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.AddressKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.address.Subnet; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.address.subnet.Netmask; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.address.subnet.PrefixLength; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Write customizer for sub-interface {@link Address} + */ +public class SubInterfaceIpv4AddressCustomizer extends FutureJVppCustomizer + implements ListWriterCustomizer, IpWriter { + + private static final Logger LOG = LoggerFactory.getLogger(SubInterfaceIpv4AddressCustomizer.class); + private final NamingContext interfaceContext; + + public SubInterfaceIpv4AddressCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext interfaceContext) { + super(futureJVppCore); + this.interfaceContext = checkNotNull(interfaceContext, "interface context should not be null"); + } + + @Override + public void writeCurrentAttributes(InstanceIdentifier
id, Address dataAfter, WriteContext writeContext) + throws WriteFailedException { + setAddress(true, id, dataAfter, writeContext); + } + + @Override + public void updateCurrentAttributes(InstanceIdentifier
id, Address dataBefore, Address dataAfter, + WriteContext writeContext) throws WriteFailedException { + throw new WriteFailedException.UpdateFailedException(id, dataBefore, dataAfter, + new UnsupportedOperationException("Operation not supported")); + } + + @Override + public void deleteCurrentAttributes(InstanceIdentifier
id, Address dataBefore, WriteContext writeContext) + throws WriteFailedException { + setAddress(false, id, dataBefore, writeContext); + } + + private void setAddress(boolean add, final InstanceIdentifier
id, final Address address, + final WriteContext writeContext) throws WriteFailedException { + + final String interfaceName = id.firstKeyOf(Interface.class).getName(); + final String subInterfaceName = getSubInterfaceName(id); + final int subInterfaceIndex = interfaceContext.getIndex(subInterfaceName, writeContext.getMappingContext()); + + Subnet subnet = address.getSubnet(); + + if (subnet instanceof PrefixLength) { + setPrefixLengthSubnet(add, id, interfaceName, subInterfaceIndex, address, (PrefixLength) subnet); + } else if (subnet instanceof Netmask) { + setNetmaskSubnet(add, id, interfaceName, subInterfaceIndex, address, (Netmask) subnet); + } else { + LOG.error("Unable to handle subnet of type {}", subnet.getClass()); + throw new WriteFailedException(id, "Unable to handle subnet of type " + subnet.getClass()); + } + } + + private String getSubInterfaceName(@Nonnull final InstanceIdentifier
id) { + final InterfaceKey parentInterfacekey = id.firstKeyOf(Interface.class); + final SubInterfaceKey subInterfacekey = id.firstKeyOf(SubInterface.class); + return SubInterfaceUtils + .getSubInterfaceName(parentInterfacekey.getName(), subInterfacekey.getIdentifier().intValue()); + } + + private void setNetmaskSubnet(final boolean add, @Nonnull final InstanceIdentifier
id, + @Nonnull final String subInterfaceName, final int subInterfaceIndex, + @Nonnull final Address address, @Nonnull final Netmask subnet) + throws WriteFailedException { + + LOG.debug("Setting Subnet(subnet-mask) for sub-interface: {}(id={}). Subnet: {}, address: {}", + subInterfaceName, subInterfaceIndex, subnet, address); + + final DottedQuad netmask = subnet.getNetmask(); + checkNotNull(netmask, "netmask value should not be null"); + + final byte subnetLength = getSubnetMaskLength(netmask.getValue()); + addDelAddress(getFutureJVpp(), add, id, subInterfaceIndex, address.getIp(), subnetLength); + } + + private void setPrefixLengthSubnet(final boolean add, @Nonnull final InstanceIdentifier
id, + @Nonnull final String subInterfaceName, final int subInterfaceIndex, + @Nonnull final Address address, @Nonnull final PrefixLength subnet) + throws WriteFailedException { + LOG.debug("Setting Subnet(prefix-length) for sub-interface: {}(id={}). Subnet: {}, address: {}", + subInterfaceName, subInterfaceIndex, subnet, address); + + addDelAddress(getFutureJVpp(), add, id, subInterfaceIndex, address.getIp(), + subnet.getPrefixLength().byteValue()); + + LOG.debug("Subnet(prefix-length) set successfully for sub-interface: {}(id={}). Subnet: {}, address: {}", + subInterfaceName, subInterfaceIndex, subnet, address); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/subinterface/SubInterfaceIpv4NeighbourCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/subinterface/SubInterfaceIpv4NeighbourCustomizer.java new file mode 100644 index 000000000..6255d08ee --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/subinterface/SubInterfaceIpv4NeighbourCustomizer.java @@ -0,0 +1,99 @@ +/* + * 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.ip.v4.subinterface; + +import io.fd.hc2vpp.common.translate.util.AddressTranslator; +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.interfaces.ip.IpWriter; +import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.core.dto.IpNeighborAddDel; +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.rev161214.sub._interface.ip4.attributes.ipv4.Neighbor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.NeighborKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SubInterfaceIpv4NeighbourCustomizer extends FutureJVppCustomizer + implements ListWriterCustomizer, ByteDataTranslator, AddressTranslator, IpWriter, + JvppReplyConsumer { + + private static final Logger LOG = LoggerFactory.getLogger(SubInterfaceIpv4NeighbourCustomizer.class); + private final NamingContext interfaceContext; + + public SubInterfaceIpv4NeighbourCustomizer(final FutureJVppCore futureJVppCore, + final NamingContext interfaceContext) { + super(futureJVppCore); + this.interfaceContext = interfaceContext; + } + + @Override + public void writeCurrentAttributes(@Nonnull InstanceIdentifier id, @Nonnull Neighbor data, + @Nonnull WriteContext writeContext) + throws WriteFailedException { + + LOG.debug("Processing request for Neighbour {} write", id); + + addDelNeighbour(id, () -> { + IpNeighborAddDel request = preBindIpv4Request(true); + + request.dstAddress = ipv4AddressNoZoneToArray(data.getIp()); + request.macAddress = parseMac(data.getLinkLayerAddress().getValue()); + request.swIfIndex = subInterfaceIndex(id, interfaceContext, writeContext.getMappingContext()); + + //TODO HONEYCOMB-182 if it is necessary for future use ,make adjustments to be able to set vrfid + //request.vrfId + return request; + }, getFutureJVpp()); + LOG.info("Neighbour {} successfully written", id); + } + + @Override + public void updateCurrentAttributes(@Nonnull InstanceIdentifier id, @Nonnull Neighbor dataBefore, + @Nonnull Neighbor dataAfter, + @Nonnull WriteContext writeContext) throws WriteFailedException { + throw new UnsupportedOperationException("Operation not supported"); + } + + @Override + public void deleteCurrentAttributes(@Nonnull InstanceIdentifier id, @Nonnull Neighbor data, + @Nonnull WriteContext writeContext) + throws WriteFailedException { + + LOG.debug("Processing request for Neighbour {} delete", id); + + addDelNeighbour(id, () -> { + IpNeighborAddDel request = preBindIpv4Request(false); + + request.dstAddress = ipv4AddressNoZoneToArray(data.getIp()); + request.macAddress = parseMac(data.getLinkLayerAddress().getValue()); + request.swIfIndex = subInterfaceIndex(id, interfaceContext, writeContext.getMappingContext()); + + //TODO HONEYCOMB-182 if it is necessary for future use ,make adjustments to be able to set vrfid + //request.vrfId + return request; + }, getFutureJVpp()); + LOG.info("Neighbour {} successfully deleted", id); + } + +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/Ipv6AddressCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/Ipv6AddressCustomizer.java new file mode 100644 index 000000000..6984c8df6 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/Ipv6AddressCustomizer.java @@ -0,0 +1,92 @@ +/* + * 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.ip.v6; + +import static com.google.common.base.Preconditions.checkNotNull; + +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfaces.ip.IpWriter; +import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; +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.ip.rev140616.interfaces._interface.ipv6.Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv6.AddressKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public class Ipv6AddressCustomizer extends FutureJVppCustomizer + implements ListWriterCustomizer, IpWriter { + + private static final Logger LOG = LoggerFactory.getLogger(Ipv6AddressCustomizer.class); + + private static final String LINK_LOCAL_START_MASK = "fe08"; + private final NamingContext interfaceContext; + + public Ipv6AddressCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext interfaceContext) { + super(futureJVppCore); + this.interfaceContext = checkNotNull(interfaceContext, "Interface context cannot be null"); + } + + @Override + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier
id, @Nonnull final Address dataAfter, + @Nonnull final WriteContext writeContext) throws WriteFailedException { + final String interfaceName = id.firstKeyOf(Interface.class).getName(); + final int interfaceIndex = interfaceContext.getIndex(interfaceName, writeContext.getMappingContext()); + + // prevents scenario + // - vpp has been restarted == cleaned state + // - hc tries to restore data, which has link-local address in it + // link layer address is created by vpp(generated) after adding first address, so its present just + // after adding first address, and attempt to override it during init would cause error -1 + if (dataAfter.getIp().getValue().startsWith(LINK_LOCAL_START_MASK)) { + LOG.info("An attempt to rewrite link-local address with {} has been detected,ignoring request", + dataAfter.getIp()); + return; + } + + addDelAddress(getFutureJVpp(), true, id, interfaceIndex, dataAfter.getIp(), + dataAfter.getPrefixLength().byteValue()); + } + + @Override + public void updateCurrentAttributes(@Nonnull final InstanceIdentifier
id, + @Nonnull final Address dataBefore, + @Nonnull final Address dataAfter, @Nonnull final WriteContext writeContext) + throws WriteFailedException { + throw new WriteFailedException.UpdateFailedException(id, dataBefore, dataAfter, + new UnsupportedOperationException("Operation not supported")); + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier
id, + @Nonnull final Address dataBefore, + @Nonnull final WriteContext writeContext) throws WriteFailedException { + final String interfaceName = id.firstKeyOf(Interface.class).getName(); + final int interfaceIndex = interfaceContext.getIndex(interfaceName, writeContext.getMappingContext()); + + addDelAddress(getFutureJVpp(), false, id, interfaceIndex, dataBefore.getIp(), + dataBefore.getPrefixLength().byteValue()); + } + +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/Ipv6Customizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/Ipv6Customizer.java new file mode 100644 index 000000000..003af53ab --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/Ipv6Customizer.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2016 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.ip.v6; + +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.honeycomb.translate.spi.write.WriterCustomizer; +import io.fd.honeycomb.translate.write.WriteContext; +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.ip.rev140616.interfaces._interface.Ipv6; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class Ipv6Customizer extends FutureJVppCustomizer implements WriterCustomizer { + + private static final Logger LOG = LoggerFactory.getLogger(Ipv6Customizer.class); + + public Ipv6Customizer(final FutureJVppCore vppApi) { + super(vppApi); + } + + @Override + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final Ipv6 dataAfter, @Nonnull final WriteContext writeContext) { + LOG.warn("Unsupported, ignoring configuration {}", dataAfter); + } + + @Override + public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final Ipv6 dataBefore, @Nonnull final Ipv6 dataAfter, + @Nonnull final WriteContext writeContext) { + LOG.warn("Unsupported, ignoring configuration {}", dataAfter); + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final Ipv6 dataBefore, @Nonnull final WriteContext writeContext) { + LOG.warn("Unsupported, ignoring configuration delete {}", id); + } +} 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 new file mode 100644 index 000000000..376ac9a1b --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/Ipv6NeighbourCustomizer.java @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2016 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.ip.v6; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; + +import io.fd.hc2vpp.common.translate.util.AddressTranslator; +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.honeycomb.translate.MappingContext; +import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.core.dto.IpNeighborAddDel; +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.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.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class Ipv6NeighbourCustomizer extends FutureJVppCustomizer + implements ListWriterCustomizer, ByteDataTranslator, AddressTranslator, + JvppReplyConsumer { + + private static final Logger LOG = LoggerFactory.getLogger(Ipv6NeighbourCustomizer.class); + final NamingContext interfaceContext; + + public Ipv6NeighbourCustomizer(final FutureJVppCore futureJVppCore, final NamingContext interfaceContext) { + super(futureJVppCore); + this.interfaceContext = interfaceContext; + } + + @Override + public void writeCurrentAttributes(@Nonnull InstanceIdentifier id, @Nonnull Neighbor dataAfter, + @Nonnull WriteContext writeContext) + throws WriteFailedException { + + checkNotNull(dataAfter, "Cannot write null neighbour"); + checkArgument(id.firstKeyOf(Interface.class) != null, "No parent interface key found"); + + LOG.debug("Processing request for Neigbour write"); + String interfaceName = id.firstKeyOf(Interface.class).getName(); + MappingContext mappingContext = writeContext.getMappingContext(); + + checkState(interfaceContext.containsIndex(interfaceName, mappingContext), + "Mapping does not contains mapping for provider interface name ".concat(interfaceName)); + + LOG.debug("Parent interface index found"); + addDelNeighbourAndReply(id, true, + interfaceContext.getIndex(interfaceName, mappingContext), dataAfter); + LOG.info("Neighbour successfully written"); + } + + @Override + public void updateCurrentAttributes(@Nonnull InstanceIdentifier id, @Nonnull Neighbor dataBefore, + @Nonnull Neighbor dataAfter, + @Nonnull WriteContext writeContext) throws WriteFailedException { + throw new UnsupportedOperationException("Operation not supported"); + } + + @Override + public void deleteCurrentAttributes(@Nonnull InstanceIdentifier id, @Nonnull Neighbor dataBefore, + @Nonnull WriteContext writeContext) + throws WriteFailedException { + + checkNotNull(dataBefore, "Cannot delete null neighbour"); + checkArgument(id.firstKeyOf(Interface.class) != null, "No parent interface key found"); + + LOG.debug("Processing request for Neigbour delete"); + String interfaceName = id.firstKeyOf(Interface.class).getName(); + MappingContext mappingContext = writeContext.getMappingContext(); + + checkState(interfaceContext.containsIndex(interfaceName, mappingContext), + "Mapping does not contains mapping for provider interface name %s", interfaceName); + + LOG.debug("Parent interface[{}] index found", interfaceName); + + addDelNeighbourAndReply(id, false, + interfaceContext.getIndex(interfaceName, mappingContext), dataBefore); + LOG.info("Neighbour {} successfully deleted", id); + } + + private void addDelNeighbourAndReply(InstanceIdentifier id, boolean add, int parentInterfaceIndex, + Neighbor data) throws WriteFailedException { + + IpNeighborAddDel request = new IpNeighborAddDel(); + + request.isAdd = booleanToByte(add); + request.isIpv6 = 1; + request.isStatic = 1; + request.dstAddress = ipv6AddressNoZoneToArray(data.getIp()); + request.macAddress = parseMac(data.getLinkLayerAddress().getValue()); + request.swIfIndex = parentInterfaceIndex; + + //TODO HONEYCOMB-182 if it is necessary for future use ,make adjustments to be able to set vrfid + //request.vrfId + getReplyForWrite(getFutureJVpp().ipNeighborAddDel(request).toCompletableFuture(), id); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/subinterface/SubInterfaceIpv6AddressCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/subinterface/SubInterfaceIpv6AddressCustomizer.java new file mode 100644 index 000000000..8348c8a25 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/subinterface/SubInterfaceIpv6AddressCustomizer.java @@ -0,0 +1,73 @@ +/* + * 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.ip.v6.subinterface; + + +import static com.google.common.base.Preconditions.checkNotNull; + +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfaces.ip.IpWriter; +import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; +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.rev161214.sub._interface.ip6.attributes.ipv6.Address; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip6.attributes.ipv6.AddressKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class SubInterfaceIpv6AddressCustomizer extends FutureJVppCustomizer + implements ListWriterCustomizer, IpWriter { + + private final NamingContext interfaceContext; + + public SubInterfaceIpv6AddressCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext interfaceContext) { + super(futureJVppCore); + this.interfaceContext = checkNotNull(interfaceContext, "interface context should not be null"); + } + + @Override + public void writeCurrentAttributes(InstanceIdentifier
id, Address dataAfter, WriteContext writeContext) + throws WriteFailedException { + setAddress(true, id, dataAfter, writeContext); + } + + @Override + public void updateCurrentAttributes(InstanceIdentifier
id, Address dataBefore, Address dataAfter, + WriteContext writeContext) throws WriteFailedException { + throw new WriteFailedException.UpdateFailedException(id, dataBefore, dataAfter, + new UnsupportedOperationException("Operation not supported")); + } + + @Override + public void deleteCurrentAttributes(InstanceIdentifier
id, Address dataBefore, WriteContext writeContext) + throws WriteFailedException { + setAddress(false, id, dataBefore, writeContext); + } + + private void setAddress(boolean add, + final InstanceIdentifier
id, + final Address address, + final WriteContext writeContext) throws WriteFailedException { + + addDelAddress(getFutureJVpp(), add, id, + subInterfaceIndex(id, interfaceContext, writeContext.getMappingContext()), address.getIp(), + address.getPrefixLength().byteValue()); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/subinterface/SubInterfaceIpv6NeighbourCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/subinterface/SubInterfaceIpv6NeighbourCustomizer.java new file mode 100644 index 000000000..9d26a9a40 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/subinterface/SubInterfaceIpv6NeighbourCustomizer.java @@ -0,0 +1,100 @@ +/* + * 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.ip.v6.subinterface; + +import io.fd.hc2vpp.common.translate.util.AddressTranslator; +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.interfaces.ip.IpWriter; +import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.core.dto.IpNeighborAddDel; +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.rev161214.sub._interface.ip6.attributes.ipv6.Neighbor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip6.attributes.ipv6.NeighborKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SubInterfaceIpv6NeighbourCustomizer extends FutureJVppCustomizer + implements ListWriterCustomizer, ByteDataTranslator, AddressTranslator, IpWriter, + JvppReplyConsumer { + + private static final Logger LOG = LoggerFactory.getLogger(SubInterfaceIpv6NeighbourCustomizer.class); + private final NamingContext interfaceContext; + + public SubInterfaceIpv6NeighbourCustomizer(final FutureJVppCore futureJVppCore, + final NamingContext interfaceContext) { + super(futureJVppCore); + this.interfaceContext = interfaceContext; + } + + @Override + public void writeCurrentAttributes(@Nonnull InstanceIdentifier id, @Nonnull Neighbor data, + @Nonnull WriteContext writeContext) + throws WriteFailedException { + + LOG.debug("Processing request for Neighbour {} write", id); + + addDelNeighbour(id, () -> { + IpNeighborAddDel request = preBindIpv6Request(true); + + request.dstAddress = ipv6AddressNoZoneToArray(data.getIp()); + request.macAddress = parseMac(data.getLinkLayerAddress().getValue()); + request.swIfIndex = subInterfaceIndex(id, interfaceContext, writeContext.getMappingContext()); + + //TODO HONEYCOMB-182 if it is necessary for future use ,make adjustments to be able to set vrfid + //request.vrfId + return request; + }, getFutureJVpp()); + LOG.debug("Neighbour {} successfully written", id); + } + + @Override + public void updateCurrentAttributes(@Nonnull InstanceIdentifier id, @Nonnull Neighbor dataBefore, + @Nonnull Neighbor dataAfter, + @Nonnull WriteContext writeContext) throws WriteFailedException { + throw new UnsupportedOperationException("Operation not supported"); + } + + @Override + public void deleteCurrentAttributes(@Nonnull InstanceIdentifier id, @Nonnull Neighbor data, + @Nonnull WriteContext writeContext) + throws WriteFailedException { + + LOG.debug("Processing request for Neighbour {} delete", id); + + addDelNeighbour(id, () -> { + IpNeighborAddDel request = preBindIpv6Request(false); + + request.dstAddress = ipv6AddressNoZoneToArray(data.getIp()); + request.macAddress = parseMac(data.getLinkLayerAddress().getValue()); + request.swIfIndex = subInterfaceIndex(id, interfaceContext, writeContext.getMappingContext()); + + //TODO HONEYCOMB-182 if it is necessary for future use ,make adjustments to be able to set vrfid + //request.vrfId + return request; + }, getFutureJVpp()); + + LOG.debug("Neighbour {} successfully deleted", id); + } + +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/IpReader.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/IpReader.java new file mode 100644 index 000000000..c16bde1ca --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/IpReader.java @@ -0,0 +1,152 @@ +/* + * 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.interfacesstate.ip; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.base.Optional; +import io.fd.hc2vpp.common.translate.util.AddressTranslator; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.v3po.interfacesstate.ip.dump.params.IfaceDumpFilter; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.util.RWUtils; +import io.fd.honeycomb.translate.util.read.cache.DumpSupplier; +import io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor; +import io.fd.vpp.jvpp.core.dto.IpAddressDetails; +import io.fd.vpp.jvpp.core.dto.IpAddressDetailsReplyDump; +import io.fd.vpp.jvpp.core.dto.IpAddressDump; +import io.fd.vpp.jvpp.core.dto.IpNeighborDetails; +import io.fd.vpp.jvpp.core.dto.IpNeighborDetailsReplyDump; +import io.fd.vpp.jvpp.core.dto.IpNeighborDump; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.Collections; +import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone; +import org.opendaylight.yangtools.yang.binding.Identifier; + +/** + * Utility class providing Ipv4/6 read support. + */ +public interface IpReader extends AddressTranslator, JvppReplyConsumer { + + @Nonnull + default List getAllIpv4AddressIds( + final Optional dumpOptional, + @Nonnull final Function keyConstructor) { + if (dumpOptional.isPresent() && dumpOptional.get().ipAddressDetails != null) { + return dumpOptional.get().ipAddressDetails.stream() + .map(detail -> keyConstructor.apply(arrayToIpv4AddressNoZone(detail.ip))) + .collect(Collectors.toList()); + } else { + return Collections.emptyList(); + } + } + + @Nonnull + default List getAllIpv6AddressIds( + final Optional dumpOptional, + @Nonnull final Function keyConstructor) { + if (dumpOptional.isPresent() && dumpOptional.get().ipAddressDetails != null) { + return dumpOptional.get().ipAddressDetails.stream() + .map(detail -> keyConstructor.apply(arrayToIpv6AddressNoZone(detail.ip))) + .collect(Collectors.toList()); + } else { + return Collections.emptyList(); + } + } + + default Optional findIpv4AddressDetailsByIp( + final Optional dump, + @Nonnull final Ipv4AddressNoZone ip) { + checkNotNull(ip, "ip address should not be null"); + + if (dump.isPresent() && dump.get().ipAddressDetails != null) { + final List details = dump.get().ipAddressDetails; + + return Optional.of(details.stream() + .filter(singleDetail -> ip.equals(arrayToIpv4AddressNoZone(singleDetail.ip))) + .collect(RWUtils.singleItemCollector())); + } + return Optional.absent(); + } + + default Optional findIpv6AddressDetailsByIp( + final Optional dump, + @Nonnull final Ipv6AddressNoZone ip) { + checkNotNull(ip, "ip address should not be null"); + + if (dump.isPresent() && dump.get().ipAddressDetails != null) { + final List details = dump.get().ipAddressDetails; + + return Optional.of(details.stream() + .filter(singleDetail -> ip.equals(arrayToIpv6AddressNoZone(singleDetail.ip))) + .collect(RWUtils.singleItemCollector())); + } + return Optional.absent(); + } + + default EntityDumpExecutor createAddressDumpExecutor( + @Nonnull final FutureJVppCore vppApi) { + return (identifier, params) -> { + checkNotNull(params, "Address dump params cannot be null"); + + final IpAddressDump dumpRequest = new IpAddressDump(); + dumpRequest.isIpv6 = booleanToByte(params.isIpv6()); + dumpRequest.swIfIndex = params.getInterfaceIndex(); + + return getReplyForRead(vppApi.ipAddressDump(dumpRequest).toCompletableFuture(), identifier); + }; + } + + default EntityDumpExecutor createNeighbourDumpExecutor( + @Nonnull final FutureJVppCore vppApi) { + return (identifier, params) -> { + checkNotNull(params, "Address dump params cannot be null"); + + final IpNeighborDump dumpRequest = new IpNeighborDump(); + dumpRequest.isIpv6 = booleanToByte(params.isIpv6()); + dumpRequest.swIfIndex = params.getInterfaceIndex(); + + return getReplyForRead(vppApi.ipNeighborDump(dumpRequest).toCompletableFuture(), identifier); + }; + } + + @Nonnull + default List getNeighborKeys( + final DumpSupplier> dumpSupplier, + final Function detailToKey) + throws ReadFailedException { + final Optional neighbourDumpOpt = dumpSupplier.get(); + + if (neighbourDumpOpt.isPresent()) { + final IpNeighborDetailsReplyDump neighbourDump = neighbourDumpOpt.get(); + + return neighbourDump.ipNeighborDetails.stream() + .map(detailToKey) + .collect(Collectors.toList()); + } else { + return Collections.emptyList(); + } + } + + + +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4AddressCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4AddressCustomizer.java deleted file mode 100644 index a3e12faea..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4AddressCustomizer.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright (c) 2016 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.interfacesstate.ip; - -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Optional; -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableSet; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.InterfaceCustomizer; -import io.fd.hc2vpp.v3po.interfacesstate.ip.dump.params.AddressDumpParams; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.Initialized; -import io.fd.honeycomb.translate.spi.read.InitializingListReaderCustomizer; -import io.fd.honeycomb.translate.util.RWUtils; -import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; -import io.fd.honeycomb.translate.util.read.cache.TypeAwareIdentifierCacheKeyFactory; -import io.fd.vpp.jvpp.core.dto.IpAddressDetails; -import io.fd.vpp.jvpp.core.dto.IpAddressDetailsReplyDump; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; -import java.util.List; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1; -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.address.Subnet; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4Builder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.AddressBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.AddressKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.address.subnet.PrefixLengthBuilder; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Read customizer for interface Ipv4 addresses. - */ -public class Ipv4AddressCustomizer extends FutureJVppCustomizer - implements InitializingListReaderCustomizer, Ipv4Reader { - - private static final Logger LOG = LoggerFactory.getLogger(Ipv4AddressCustomizer.class); - private static final String CACHE_KEY = Ipv4AddressCustomizer.class.getName(); - - private final NamingContext interfaceContext; - private final DumpCacheManager dumpManager; - - public Ipv4AddressCustomizer(@Nonnull final FutureJVppCore futureJVppCore, - @Nonnull final NamingContext interfaceContext) { - super(futureJVppCore); - this.interfaceContext = checkNotNull(interfaceContext, "interfaceContext should not be null"); - this.dumpManager = - new DumpCacheManager.DumpCacheManagerBuilder() - .withExecutor(createExecutor(futureJVppCore)) - // Key needs to contain interface ID to distinguish dumps between interfaces - .withCacheKeyFactory(new TypeAwareIdentifierCacheKeyFactory(IpAddressDetailsReplyDump.class, - ImmutableSet.of(Interface.class))) - .build(); - } - - @Override - @Nonnull - public AddressBuilder getBuilder(@Nonnull InstanceIdentifier
id) { - return new AddressBuilder(); - } - - @Override - public void readCurrentAttributes(@Nonnull InstanceIdentifier
id, @Nonnull AddressBuilder builder, - @Nonnull ReadContext ctx) - throws ReadFailedException { - LOG.debug("Reading attributes for interface address: {}", id); - - final String interfaceName = id.firstKeyOf(Interface.class).getName(); - final int interfaceIndex = interfaceContext.getIndex(interfaceName, ctx.getMappingContext()); - final Optional dumpOptional = - dumpManager.getDump(id, ctx.getModificationCache(), new AddressDumpParams(interfaceIndex, false)); - - if (!dumpOptional.isPresent() || dumpOptional.get().ipAddressDetails.isEmpty()) { - return; - } - final Optional ipAddressDetails = - findIpAddressDetailsByIp(dumpOptional, id.firstKeyOf(Address.class).getIp()); - - if (ipAddressDetails.isPresent()) { - final IpAddressDetails detail = ipAddressDetails.get(); - builder.setIp(arrayToIpv4AddressNoZone(detail.ip)) - .setSubnet(new PrefixLengthBuilder().setPrefixLength(Short.valueOf(detail.prefixLength)).build()); - - if (LOG.isDebugEnabled()) { - LOG.debug("Attributes for {} interface (id={}) address {} successfully read: {}", - interfaceName, interfaceIndex, id, builder.build()); - } - } - } - - @Override - public List getAllIds(@Nonnull InstanceIdentifier
id, @Nonnull ReadContext ctx) - throws ReadFailedException { - LOG.debug("Reading list of keys for interface addresses: {}", id); - - final String interfaceName = id.firstKeyOf(Interface.class).getName(); - final int interfaceIndex = interfaceContext.getIndex(interfaceName, ctx.getMappingContext()); - final Optional dumpOptional = - dumpManager.getDump(id, ctx.getModificationCache(), new AddressDumpParams(interfaceIndex, false)); - - return getAllIpv4AddressIds(dumpOptional, AddressKey::new); - } - - @Override - public void merge(@Nonnull Builder builder, @Nonnull List
readData) { - ((Ipv4Builder) builder).setAddress(readData); - } - - @Override - public Initialized init( - @Nonnull final InstanceIdentifier
id, @Nonnull final Address readValue, - @Nonnull final ReadContext ctx) { - return Initialized.create(getCfgId(id), - new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.AddressBuilder() - .setIp(readValue.getIp()) - .setSubnet(getSubnet(readValue)) - .build()); - } - - private static Subnet getSubnet(final Address address) { - final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.address.Subnet - subnet = address.getSubnet(); - - // Only prefix length supported - Preconditions.checkArgument( - subnet instanceof org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.address.subnet.PrefixLength); - - return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.PrefixLengthBuilder() - .setPrefixLength( - ((org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.address.subnet.PrefixLength) subnet) - .getPrefixLength()).build(); - } - - static InstanceIdentifier getCfgId( - final InstanceIdentifier
id) { - return InterfaceCustomizer.getCfgId(RWUtils.cutId(id, Interface.class)) - .augmentation(Interface1.class) - .child(Ipv4.class) - .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address.class, - new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.AddressKey(id.firstKeyOf(Address.class).getIp())); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4Customizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4Customizer.java deleted file mode 100644 index 316f8ec47..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4Customizer.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2016 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.interfacesstate.ip; - -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface2Builder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4Builder; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class Ipv4Customizer extends FutureJVppCustomizer implements ReaderCustomizer { - - private static final Logger LOG = LoggerFactory.getLogger(Ipv4Customizer.class); - - public Ipv4Customizer(@Nonnull final FutureJVppCore futureJVppCore) { - super(futureJVppCore); - } - - @Override - public void merge(@Nonnull final Builder parentBuilder, @Nonnull final Ipv4 readValue) { - ((Interface2Builder) parentBuilder).setIpv4(readValue); - } - - @Nonnull - @Override - public Ipv4Builder getBuilder(@Nonnull final InstanceIdentifier id) { - return new Ipv4Builder(); - } - - @Override - public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final Ipv4Builder builder, - @Nonnull final ReadContext ctx) throws ReadFailedException { - LOG.debug("Reading Ipv4 leaves (mtu, forwarding) is not supported by VPP API"); - } - -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4NeighbourCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4NeighbourCustomizer.java deleted file mode 100644 index a32f8f20c..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4NeighbourCustomizer.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2016 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.interfacesstate.ip; - -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; -import java.util.Collections; -import java.util.List; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4Builder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.Neighbor; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.NeighborBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.NeighborKey; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Operational data read operation customizer for {@link Neighbor}
- * Currently not supported in jvpp, so this is only dummy implementation
- */ -public class Ipv4NeighbourCustomizer extends FutureJVppCustomizer - implements ListReaderCustomizer { - - private static final Logger LOG = LoggerFactory.getLogger(Ipv4NeighbourCustomizer.class); - - public Ipv4NeighbourCustomizer(FutureJVppCore futureJVppCore) { - super(futureJVppCore); - } - - @Override - public NeighborBuilder getBuilder(InstanceIdentifier id) { - return new NeighborBuilder(); - } - - @Override - public void readCurrentAttributes(InstanceIdentifier id, NeighborBuilder builder, ReadContext ctx) - throws ReadFailedException { - //TODO - not supported, implement https://jira.fd.io/browse/VPP-164 first + implement init - LOG.warn("Operation not supported"); - } - - @Override - public List getAllIds(InstanceIdentifier id, ReadContext context) - throws ReadFailedException { - //TODO - not supported, implement https://jira.fd.io/browse/VPP-164 first - LOG.warn("Operation not supported,returning empty List"); - return Collections.emptyList(); - } - - @Override - public void merge(Builder builder, List readData) { - ((Ipv4Builder) builder).setNeighbor(readData); - } -} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4Reader.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4Reader.java deleted file mode 100644 index 8c8299dbd..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4Reader.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2016 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.interfacesstate.ip; - -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Optional; -import io.fd.hc2vpp.common.translate.util.Ipv4Translator; -import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; -import io.fd.hc2vpp.v3po.interfacesstate.ip.dump.params.AddressDumpParams; -import io.fd.honeycomb.translate.util.RWUtils; -import io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor; -import io.fd.vpp.jvpp.core.dto.IpAddressDetails; -import io.fd.vpp.jvpp.core.dto.IpAddressDetailsReplyDump; -import io.fd.vpp.jvpp.core.dto.IpAddressDump; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; -import java.util.Collections; -import java.util.List; -import java.util.function.Function; -import java.util.stream.Collectors; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; -import org.opendaylight.yangtools.yang.binding.Identifier; - -/** - * Utility class providing Ipv4 read support. - */ -interface Ipv4Reader extends Ipv4Translator, JvppReplyConsumer { - - @Nonnull - default List getAllIpv4AddressIds( - final Optional dumpOptional, - @Nonnull final Function keyConstructor) { - if (dumpOptional.isPresent() && dumpOptional.get().ipAddressDetails != null) { - return dumpOptional.get().ipAddressDetails.stream() - .map(detail -> keyConstructor.apply(arrayToIpv4AddressNoZone(detail.ip))) - .collect(Collectors.toList()); - } else { - return Collections.emptyList(); - } - } - - default Optional findIpAddressDetailsByIp( - final Optional dump, - @Nonnull final Ipv4AddressNoZone ip) { - checkNotNull(ip, "ip address should not be null"); - - if (dump.isPresent() && dump.get().ipAddressDetails != null) { - final List details = dump.get().ipAddressDetails; - - return Optional.of(details.stream() - .filter(singleDetail -> ip.equals(arrayToIpv4AddressNoZone(singleDetail.ip))) - .collect(RWUtils.singleItemCollector())); - } - return Optional.absent(); - } - - default EntityDumpExecutor createExecutor( - @Nonnull final FutureJVppCore vppApi) { - return (identifier, params) -> { - checkNotNull(params, "Address dump params cannot be null"); - - final IpAddressDump dumpRequest = new IpAddressDump(); - dumpRequest.isIpv6 = booleanToByte(params.isIpv6()); - dumpRequest.swIfIndex = params.getInterfaceIndex(); - - return getReplyForRead(vppApi.ipAddressDump(dumpRequest).toCompletableFuture(), identifier); - }; - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv6Customizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv6Customizer.java deleted file mode 100644 index 97f223a8c..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv6Customizer.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2016 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.interfacesstate.ip; - -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface2Builder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv6; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv6Builder; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; - -public class Ipv6Customizer extends FutureJVppCustomizer implements ReaderCustomizer { - - private final NamingContext interfaceContext; - - public Ipv6Customizer(@Nonnull final FutureJVppCore futureJVppCore, final NamingContext interfaceContext) { - super(futureJVppCore); - this.interfaceContext = interfaceContext; - } - - @Override - public void merge(@Nonnull final Builder parentBuilder, @Nonnull final Ipv6 readValue) { - ((Interface2Builder) parentBuilder).setIpv6(readValue); - } - - @Nonnull - @Override - public Ipv6Builder getBuilder(@Nonnull final InstanceIdentifier id) { - return new Ipv6Builder(); - } - - @Override - public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final Ipv6Builder builder, - @Nonnull final ReadContext ctx) throws ReadFailedException { - // TODO HONEYCOMB-102 implement + init -// final IpAddressDump dumpRequest = new IpAddressDump(); -// dumpRequest.isIpv6 = 1; -// dumpRequest.swIfIndex = interfaceContext.getIndex(id.firstKeyOf(Interface.class).getName(), -// ctx.getMappingContext()); -// final CompletionStage addressDumpFuture = getFutureJVpp(). -// ipAddressDump(dumpRequest); -// final IpAddressDetailsReplyDump reply = TranslateUtils.getReply(addressDumpFuture.toCompletableFuture()); - } - -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizer.java deleted file mode 100644 index a8617c578..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizer.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (c) 2016 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.interfacesstate.ip; - -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Optional; -import com.google.common.collect.ImmutableSet; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.SubInterfaceCustomizer; -import io.fd.hc2vpp.v3po.interfacesstate.ip.dump.params.AddressDumpParams; -import io.fd.hc2vpp.v3po.util.SubInterfaceUtils; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.Initialized; -import io.fd.honeycomb.translate.spi.read.InitializingListReaderCustomizer; -import io.fd.honeycomb.translate.util.RWUtils; -import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; -import io.fd.honeycomb.translate.util.read.cache.TypeAwareIdentifierCacheKeyFactory; -import io.fd.vpp.jvpp.core.dto.IpAddressDetails; -import io.fd.vpp.jvpp.core.dto.IpAddressDetailsReplyDump; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; -import java.util.List; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.sub.interfaces.SubInterface; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.Ipv4; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.Ipv4Builder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.Address; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.AddressBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.AddressKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.address.subnet.PrefixLengthBuilder; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Read customizer for sub-interface Ipv4 addresses. - */ -public class SubInterfaceIpv4AddressCustomizer extends FutureJVppCustomizer - implements InitializingListReaderCustomizer, Ipv4Reader { - - private static final Logger LOG = LoggerFactory.getLogger(SubInterfaceIpv4AddressCustomizer.class); - - private final NamingContext interfaceContext; - private final DumpCacheManager dumpManager; - - public SubInterfaceIpv4AddressCustomizer(@Nonnull final FutureJVppCore futureJVppCore, - @Nonnull final NamingContext interfaceContext) { - super(futureJVppCore); - this.interfaceContext = checkNotNull(interfaceContext, "interfaceContext should not be null"); - this.dumpManager = new DumpCacheManager.DumpCacheManagerBuilder() - .withExecutor(createExecutor(futureJVppCore)) - //same as with ipv4 addresses for interfaces, these must have cache scope of their parent sub-interface - .withCacheKeyFactory(new TypeAwareIdentifierCacheKeyFactory(IpAddressDetailsReplyDump.class, - ImmutableSet.of(SubInterface.class))) - .build(); - } - - private static String getSubInterfaceName(@Nonnull final InstanceIdentifier
id) { - return SubInterfaceUtils.getSubInterfaceName(id.firstKeyOf(Interface.class).getName(), - Math.toIntExact(id.firstKeyOf(SubInterface.class).getIdentifier())); - } - - @Override - @Nonnull - public AddressBuilder getBuilder(@Nonnull InstanceIdentifier
id) { - return new AddressBuilder(); - } - - @Override - public void readCurrentAttributes(@Nonnull InstanceIdentifier
id, @Nonnull AddressBuilder builder, - @Nonnull ReadContext ctx) - throws ReadFailedException { - LOG.debug("Reading attributes for sub-interface address: {}", id); - - final String subInterfaceName = getSubInterfaceName(id); - final int subInterfaceIndex = interfaceContext.getIndex(subInterfaceName, ctx.getMappingContext()); - final Optional dumpOptional = dumpManager - .getDump(id, ctx.getModificationCache(), new AddressDumpParams(subInterfaceIndex, false)); - - final Optional ipAddressDetails = - findIpAddressDetailsByIp(dumpOptional, id.firstKeyOf(Address.class).getIp()); - - if (ipAddressDetails.isPresent()) { - final IpAddressDetails detail = ipAddressDetails.get(); - builder.setIp(arrayToIpv4AddressNoZone(detail.ip)); - builder.setSubnet(new PrefixLengthBuilder().setPrefixLength(Short.valueOf(detail.prefixLength)).build()); - - if (LOG.isDebugEnabled()) { - LOG.debug("Attributes for {} sub-interface (id={}) address {} successfully read: {}", - subInterfaceName, subInterfaceIndex, id, builder.build()); - } - } - } - - @Override - public List getAllIds(@Nonnull InstanceIdentifier
id, @Nonnull ReadContext ctx) - throws ReadFailedException { - LOG.debug("Reading list of keys for sub-interface addresses: {}", id); - - final String subInterfaceName = getSubInterfaceName(id); - final int subInterfaceIndex = interfaceContext.getIndex(subInterfaceName, ctx.getMappingContext()); - final Optional dumpOptional = dumpManager - .getDump(id, ctx.getModificationCache(), new AddressDumpParams(subInterfaceIndex, false)); - - return getAllIpv4AddressIds(dumpOptional, AddressKey::new); - } - - @Override - public void merge(@Nonnull Builder builder, @Nonnull List
readData) { - ((Ipv4Builder) builder).setAddress(readData); - } - - @Override - public Initialized
init( - @Nonnull final InstanceIdentifier
id, @Nonnull final Address readValue, - @Nonnull final ReadContext ctx) { - return Initialized.create(getCfgId(id), readValue); - } - - private InstanceIdentifier
getCfgId(final InstanceIdentifier
id) { - return SubInterfaceCustomizer.getCfgId(RWUtils.cutId(id, SubInterface.class)) - .child(Ipv4.class) - .child(Address.class, new AddressKey(id.firstKeyOf(Address.class))); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/dump/params/AddressDumpParams.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/dump/params/AddressDumpParams.java deleted file mode 100644 index cb80893be..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/dump/params/AddressDumpParams.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2016 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.interfacesstate.ip.dump.params; - -public class AddressDumpParams { - - private final int interfaceIndex; - private final boolean isIpv6; - - public AddressDumpParams(final int interfaceIndex, final boolean isIpv6) { - this.interfaceIndex = interfaceIndex; - this.isIpv6 = isIpv6; - } - - public int getInterfaceIndex() { - return interfaceIndex; - } - - public boolean isIpv6() { - return isIpv6; - } - - @Override - public String toString() { - return "AddressDumpParams{" + - "interfaceIndex=" + interfaceIndex + - ", isIpv6=" + isIpv6 + - '}'; - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/dump/params/IfaceDumpFilter.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/dump/params/IfaceDumpFilter.java new file mode 100644 index 000000000..19a3ed7f9 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/dump/params/IfaceDumpFilter.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2016 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.interfacesstate.ip.dump.params; + +public class IfaceDumpFilter { + + private final int interfaceIndex; + private final boolean isIpv6; + + public IfaceDumpFilter(final int interfaceIndex, final boolean isIpv6) { + this.interfaceIndex = interfaceIndex; + this.isIpv6 = isIpv6; + } + + public int getInterfaceIndex() { + return interfaceIndex; + } + + public boolean isIpv6() { + return isIpv6; + } + + @Override + public String toString() { + return "IfaceDumpFilter{" + + "interfaceIndex=" + interfaceIndex + + ", isIpv6=" + isIpv6 + + '}'; + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/Ipv4AddressCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/Ipv4AddressCustomizer.java new file mode 100644 index 000000000..8b84cfa24 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/Ipv4AddressCustomizer.java @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2016 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.interfacesstate.ip.v4; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.base.Optional; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableSet; +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfacesstate.InterfaceCustomizer; +import io.fd.hc2vpp.v3po.interfacesstate.ip.IpReader; +import io.fd.hc2vpp.v3po.interfacesstate.ip.dump.params.IfaceDumpFilter; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.Initialized; +import io.fd.honeycomb.translate.spi.read.InitializingListReaderCustomizer; +import io.fd.honeycomb.translate.util.RWUtils; +import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; +import io.fd.honeycomb.translate.util.read.cache.TypeAwareIdentifierCacheKeyFactory; +import io.fd.vpp.jvpp.core.dto.IpAddressDetails; +import io.fd.vpp.jvpp.core.dto.IpAddressDetailsReplyDump; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.List; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1; +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.address.Subnet; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.AddressBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.AddressKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.address.subnet.PrefixLengthBuilder; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Read customizer for interface Ipv4 addresses. + */ +public class Ipv4AddressCustomizer extends FutureJVppCustomizer + implements InitializingListReaderCustomizer, IpReader { + + private static final Logger LOG = LoggerFactory.getLogger(Ipv4AddressCustomizer.class); + + private final NamingContext interfaceContext; + private final DumpCacheManager dumpManager; + + public Ipv4AddressCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext interfaceContext) { + super(futureJVppCore); + this.interfaceContext = checkNotNull(interfaceContext, "interfaceContext should not be null"); + this.dumpManager = + new DumpCacheManager.DumpCacheManagerBuilder() + .withExecutor(createAddressDumpExecutor(futureJVppCore)) + // Key needs to contain interface ID to distinguish dumps between interfaces + .withCacheKeyFactory(new TypeAwareIdentifierCacheKeyFactory(IpAddressDetailsReplyDump.class, + ImmutableSet.of(Interface.class))) + .build(); + } + + @Override + @Nonnull + public AddressBuilder getBuilder(@Nonnull InstanceIdentifier
id) { + return new AddressBuilder(); + } + + @Override + public void readCurrentAttributes(@Nonnull InstanceIdentifier
id, @Nonnull AddressBuilder builder, + @Nonnull ReadContext ctx) + throws ReadFailedException { + LOG.debug("Reading attributes for interface address: {}", id); + + final String interfaceName = id.firstKeyOf(Interface.class).getName(); + final int interfaceIndex = interfaceContext.getIndex(interfaceName, ctx.getMappingContext()); + final Optional dumpOptional = + dumpManager.getDump(id, ctx.getModificationCache(), new IfaceDumpFilter(interfaceIndex, false)); + + if (!dumpOptional.isPresent() || dumpOptional.get().ipAddressDetails.isEmpty()) { + return; + } + final Optional ipAddressDetails = + findIpv4AddressDetailsByIp(dumpOptional, id.firstKeyOf(Address.class).getIp()); + + if (ipAddressDetails.isPresent()) { + final IpAddressDetails detail = ipAddressDetails.get(); + builder.setIp(arrayToIpv4AddressNoZone(detail.ip)) + .setSubnet(new PrefixLengthBuilder().setPrefixLength(Short.valueOf(detail.prefixLength)).build()); + + if (LOG.isDebugEnabled()) { + LOG.debug("Attributes for {} interface (id={}) address {} successfully read: {}", + interfaceName, interfaceIndex, id, builder.build()); + } + } + } + + @Override + public List getAllIds(@Nonnull InstanceIdentifier
id, @Nonnull ReadContext ctx) + throws ReadFailedException { + LOG.debug("Reading list of keys for interface addresses: {}", id); + + final String interfaceName = id.firstKeyOf(Interface.class).getName(); + final int interfaceIndex = interfaceContext.getIndex(interfaceName, ctx.getMappingContext()); + final Optional dumpOptional = + dumpManager.getDump(id, ctx.getModificationCache(), new IfaceDumpFilter(interfaceIndex, false)); + + return getAllIpv4AddressIds(dumpOptional, AddressKey::new); + } + + @Override + public void merge(@Nonnull Builder builder, @Nonnull List
readData) { + ((Ipv4Builder) builder).setAddress(readData); + } + + @Override + public Initialized init( + @Nonnull final InstanceIdentifier
id, @Nonnull final Address readValue, + @Nonnull final ReadContext ctx) { + return Initialized.create(getCfgId(id), + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.AddressBuilder() + .setIp(readValue.getIp()) + .setSubnet(getSubnet(readValue)) + .build()); + } + + private static Subnet getSubnet(final Address address) { + final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.address.Subnet + subnet = address.getSubnet(); + + // Only prefix length supported + Preconditions.checkArgument( + subnet instanceof org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.address.subnet.PrefixLength); + + return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.PrefixLengthBuilder() + .setPrefixLength( + ((org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.address.subnet.PrefixLength) subnet) + .getPrefixLength()).build(); + } + + static InstanceIdentifier getCfgId( + final InstanceIdentifier
id) { + return InterfaceCustomizer.getCfgId(RWUtils.cutId(id, Interface.class)) + .augmentation(Interface1.class) + .child(Ipv4.class) + .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address.class, + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.AddressKey(id.firstKeyOf(Address.class).getIp())); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/Ipv4Customizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/Ipv4Customizer.java new file mode 100644 index 000000000..ef8813ae5 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/Ipv4Customizer.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2016 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.interfacesstate.ip.v4; + +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +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.ip.rev140616.Interface2Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4Builder; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class Ipv4Customizer extends FutureJVppCustomizer implements ReaderCustomizer { + + private static final Logger LOG = LoggerFactory.getLogger(Ipv4Customizer.class); + + public Ipv4Customizer(@Nonnull final FutureJVppCore futureJVppCore) { + super(futureJVppCore); + } + + @Override + public void merge(@Nonnull final Builder parentBuilder, @Nonnull final Ipv4 readValue) { + ((Interface2Builder) parentBuilder).setIpv4(readValue); + } + + @Nonnull + @Override + public Ipv4Builder getBuilder(@Nonnull final InstanceIdentifier id) { + return new Ipv4Builder(); + } + + @Override + public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final Ipv4Builder builder, + @Nonnull final ReadContext ctx) throws ReadFailedException { + LOG.debug("Reading Ipv4 leaves (mtu, forwarding) is not supported by VPP API"); + } + +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/Ipv4NeighbourCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/Ipv4NeighbourCustomizer.java new file mode 100644 index 000000000..0e5fb310f --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/Ipv4NeighbourCustomizer.java @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2016 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.interfacesstate.ip.v4; + +import static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.NeighborOrigin.Dynamic; +import static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.NeighborOrigin.Static; + +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableSet; +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfacesstate.ip.IpReader; +import io.fd.hc2vpp.v3po.interfacesstate.ip.dump.params.IfaceDumpFilter; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer; +import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; +import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager.DumpCacheManagerBuilder; +import io.fd.honeycomb.translate.util.read.cache.DumpSupplier; +import io.fd.honeycomb.translate.util.read.cache.TypeAwareIdentifierCacheKeyFactory; +import io.fd.vpp.jvpp.core.dto.IpNeighborDetails; +import io.fd.vpp.jvpp.core.dto.IpNeighborDetailsReplyDump; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.List; +import java.util.function.Function; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.Neighbor; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.NeighborBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv4.NeighborKey; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +/** + * Operational data read operation customizer for {@link Neighbor}
+ * Currently not supported in jvpp, so this is only dummy implementation
+ */ +public class Ipv4NeighbourCustomizer extends FutureJVppCustomizer + implements ListReaderCustomizer, IpReader { + + private final DumpCacheManager dumpManager; + private final NamingContext interfaceContext; + + public Ipv4NeighbourCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext interfaceContext) { + super(futureJVppCore); + dumpManager = new DumpCacheManagerBuilder() + .withExecutor(createNeighbourDumpExecutor(futureJVppCore)) + // cached with parent interface scope + .withCacheKeyFactory(new TypeAwareIdentifierCacheKeyFactory(IpNeighborDetailsReplyDump.class, + ImmutableSet.of(Interface.class))) + .build(); + this.interfaceContext = interfaceContext; + } + + @Override + public NeighborBuilder getBuilder(InstanceIdentifier id) { + return new NeighborBuilder(); + } + + @Override + public void readCurrentAttributes(InstanceIdentifier id, NeighborBuilder builder, ReadContext ctx) + throws ReadFailedException { + + final Ipv4AddressNoZone ip = id.firstKeyOf(Neighbor.class).getIp(); + + final Optional dumpOpt = dumpSupplier(id, ctx).get(); + + if (dumpOpt.isPresent()) { + dumpOpt.get().ipNeighborDetails + .stream() + .filter(ipNeighborDetails -> ip.equals(arrayToIpv4AddressNoZone(ipNeighborDetails.ipAddress))) + .findFirst() + .ifPresent(ipNeighborDetails -> builder.setIp(arrayToIpv4AddressNoZone(ipNeighborDetails.ipAddress)) + .setKey(keyMapper().apply(ipNeighborDetails)) + .setLinkLayerAddress(toPhysAddress(ipNeighborDetails.macAddress)) + .setOrigin(ipNeighborDetails.isStatic == 0 + ? Dynamic + : Static)); + } + } + + @Override + public List getAllIds(InstanceIdentifier id, ReadContext context) + throws ReadFailedException { + return getNeighborKeys(dumpSupplier(id, context), keyMapper()); + } + + @Override + public void merge(Builder builder, List readData) { + ((Ipv4Builder) builder).setNeighbor(readData); + } + + private Function keyMapper() { + return ipNeighborDetails -> new NeighborKey(arrayToIpv4AddressNoZone(ipNeighborDetails.ipAddress)); + } + + private DumpSupplier> dumpSupplier(final InstanceIdentifier id, + final ReadContext context) { + return () -> dumpManager + .getDump(id, context.getModificationCache(), new IfaceDumpFilter(interfaceContext + .getIndex(id.firstKeyOf(Interface.class).getName(), context.getMappingContext()), + false)); + } + +} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/subinterface/SubInterfaceIpv4AddressCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/subinterface/SubInterfaceIpv4AddressCustomizer.java new file mode 100644 index 000000000..f27229acd --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/subinterface/SubInterfaceIpv4AddressCustomizer.java @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2016 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.interfacesstate.ip.v4.subinterface; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableSet; +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfacesstate.SubInterfaceCustomizer; +import io.fd.hc2vpp.v3po.interfacesstate.ip.IpReader; +import io.fd.hc2vpp.v3po.interfacesstate.ip.dump.params.IfaceDumpFilter; +import io.fd.hc2vpp.v3po.util.SubInterfaceUtils; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.Initialized; +import io.fd.honeycomb.translate.spi.read.InitializingListReaderCustomizer; +import io.fd.honeycomb.translate.util.RWUtils; +import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; +import io.fd.honeycomb.translate.util.read.cache.TypeAwareIdentifierCacheKeyFactory; +import io.fd.vpp.jvpp.core.dto.IpAddressDetails; +import io.fd.vpp.jvpp.core.dto.IpAddressDetailsReplyDump; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.List; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.Ipv4; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.Ipv4Builder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.Address; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.AddressBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.AddressKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.address.subnet.PrefixLengthBuilder; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Read customizer for sub-interface Ipv4 addresses. + */ +public class SubInterfaceIpv4AddressCustomizer extends FutureJVppCustomizer + implements InitializingListReaderCustomizer, IpReader { + + private static final Logger LOG = LoggerFactory.getLogger(SubInterfaceIpv4AddressCustomizer.class); + + private final NamingContext interfaceContext; + private final DumpCacheManager dumpManager; + + public SubInterfaceIpv4AddressCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext interfaceContext) { + super(futureJVppCore); + this.interfaceContext = checkNotNull(interfaceContext, "interfaceContext should not be null"); + this.dumpManager = new DumpCacheManager.DumpCacheManagerBuilder() + .withExecutor(createAddressDumpExecutor(futureJVppCore)) + //same as with ipv4 addresses for interfaces, these must have cache scope of their parent sub-interface + .withCacheKeyFactory(new TypeAwareIdentifierCacheKeyFactory(IpAddressDetailsReplyDump.class, + ImmutableSet.of(SubInterface.class))) + .build(); + } + + private static String getSubInterfaceName(@Nonnull final InstanceIdentifier
id) { + return SubInterfaceUtils.getSubInterfaceName(id.firstKeyOf(Interface.class).getName(), + Math.toIntExact(id.firstKeyOf(SubInterface.class).getIdentifier())); + } + + @Override + @Nonnull + public AddressBuilder getBuilder(@Nonnull InstanceIdentifier
id) { + return new AddressBuilder(); + } + + @Override + public void readCurrentAttributes(@Nonnull InstanceIdentifier
id, @Nonnull AddressBuilder builder, + @Nonnull ReadContext ctx) + throws ReadFailedException { + LOG.debug("Reading attributes for sub-interface address: {}", id); + + final String subInterfaceName = getSubInterfaceName(id); + final int subInterfaceIndex = interfaceContext.getIndex(subInterfaceName, ctx.getMappingContext()); + final Optional dumpOptional = dumpManager + .getDump(id, ctx.getModificationCache(), new IfaceDumpFilter(subInterfaceIndex, false)); + + final Optional ipAddressDetails = + findIpv4AddressDetailsByIp(dumpOptional, id.firstKeyOf(Address.class).getIp()); + + if (ipAddressDetails.isPresent()) { + final IpAddressDetails detail = ipAddressDetails.get(); + builder.setIp(arrayToIpv4AddressNoZone(detail.ip)); + builder.setSubnet(new PrefixLengthBuilder().setPrefixLength((short) detail.prefixLength).build()); + + if (LOG.isDebugEnabled()) { + LOG.debug("Attributes for {} sub-interface (id={}) address {} successfully read: {}", + subInterfaceName, subInterfaceIndex, id, builder.build()); + } + } + } + + @Override + @Nonnull + public List getAllIds(@Nonnull InstanceIdentifier
id, @Nonnull ReadContext ctx) + throws ReadFailedException { + LOG.debug("Reading list of keys for sub-interface addresses: {}", id); + + final String subInterfaceName = getSubInterfaceName(id); + final int subInterfaceIndex = interfaceContext.getIndex(subInterfaceName, ctx.getMappingContext()); + final Optional dumpOptional = dumpManager + .getDump(id, ctx.getModificationCache(), new IfaceDumpFilter(subInterfaceIndex, false)); + + return getAllIpv4AddressIds(dumpOptional, AddressKey::new); + } + + @Override + public void merge(@Nonnull Builder builder, @Nonnull List
readData) { + ((Ipv4Builder) builder).setAddress(readData); + } + + @Override + public Initialized
init( + @Nonnull final InstanceIdentifier
id, @Nonnull final Address readValue, + @Nonnull final ReadContext ctx) { + return Initialized.create(getCfgId(id), readValue); + } + + private InstanceIdentifier
getCfgId(final InstanceIdentifier
id) { + return SubInterfaceCustomizer.getCfgId(RWUtils.cutId(id, SubInterface.class)) + .child(Ipv4.class) + .child(Address.class, new AddressKey(id.firstKeyOf(Address.class))); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/subinterface/SubInterfaceIpv4NeighbourCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/subinterface/SubInterfaceIpv4NeighbourCustomizer.java new file mode 100644 index 000000000..71833db0d --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/subinterface/SubInterfaceIpv4NeighbourCustomizer.java @@ -0,0 +1,113 @@ +/* + * 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.interfacesstate.ip.v4.subinterface; + +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableSet; +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfacesstate.ip.IpReader; +import io.fd.hc2vpp.v3po.interfacesstate.ip.dump.params.IfaceDumpFilter; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer; +import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; +import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager.DumpCacheManagerBuilder; +import io.fd.honeycomb.translate.util.read.cache.DumpSupplier; +import io.fd.honeycomb.translate.util.read.cache.TypeAwareIdentifierCacheKeyFactory; +import io.fd.vpp.jvpp.core.dto.IpNeighborDetails; +import io.fd.vpp.jvpp.core.dto.IpNeighborDetailsReplyDump; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.List; +import java.util.function.Function; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.Ipv4Builder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.Neighbor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.NeighborBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.NeighborKey; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class SubInterfaceIpv4NeighbourCustomizer extends FutureJVppCustomizer + implements ListReaderCustomizer, IpReader { + + private final DumpCacheManager dumpManager; + private final NamingContext interfaceContext; + + public SubInterfaceIpv4NeighbourCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext interfaceContext) { + super(futureJVppCore); + dumpManager = new DumpCacheManagerBuilder() + .withExecutor(createNeighbourDumpExecutor(futureJVppCore)) + // cached with parent interface scope + .withCacheKeyFactory(new TypeAwareIdentifierCacheKeyFactory(IpNeighborDetailsReplyDump.class, + ImmutableSet.of(Interface.class))) + .build(); + this.interfaceContext = interfaceContext; + } + + @Override + public NeighborBuilder getBuilder(InstanceIdentifier id) { + return new NeighborBuilder(); + } + + @Override + public void readCurrentAttributes(InstanceIdentifier id, NeighborBuilder builder, ReadContext ctx) + throws ReadFailedException { + + final Ipv4AddressNoZone ip = id.firstKeyOf(Neighbor.class).getIp(); + + final Optional dumpOpt = dumpSupplier(id, ctx).get(); + + if (dumpOpt.isPresent()) { + dumpOpt.get().ipNeighborDetails + .stream() + .filter(ipNeighborDetails -> ip.equals(arrayToIpv4AddressNoZone(ipNeighborDetails.ipAddress))) + .findFirst() + .ifPresent(ipNeighborDetails -> builder.setIp(arrayToIpv4AddressNoZone(ipNeighborDetails.ipAddress)) + .setKey(keyMapper().apply(ipNeighborDetails)) + .setLinkLayerAddress(toPhysAddress(ipNeighborDetails.macAddress))); + } + } + + @Override + public List getAllIds(InstanceIdentifier id, ReadContext context) + throws ReadFailedException { + return getNeighborKeys(dumpSupplier(id, context), keyMapper()); + } + + @Override + public void merge(Builder builder, List readData) { + ((Ipv4Builder) builder).setNeighbor(readData); + } + + private Function keyMapper() { + return ipNeighborDetails -> new NeighborKey(arrayToIpv4AddressNoZone(ipNeighborDetails.ipAddress)); + } + + private DumpSupplier> dumpSupplier(final InstanceIdentifier id, + final ReadContext context) { + return () -> dumpManager + .getDump(id, context.getModificationCache(), new IfaceDumpFilter(interfaceContext + .getIndex(id.firstKeyOf(Interface.class).getName(), context.getMappingContext()), + false)); + } + +} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/Ipv6AddressCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/Ipv6AddressCustomizer.java new file mode 100644 index 000000000..a5166525e --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/Ipv6AddressCustomizer.java @@ -0,0 +1,149 @@ +/* + * 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.interfacesstate.ip.v6; + + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableSet; +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfacesstate.InterfaceCustomizer; +import io.fd.hc2vpp.v3po.interfacesstate.ip.IpReader; +import io.fd.hc2vpp.v3po.interfacesstate.ip.dump.params.IfaceDumpFilter; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.Initialized; +import io.fd.honeycomb.translate.spi.read.InitializingListReaderCustomizer; +import io.fd.honeycomb.translate.util.RWUtils; +import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; +import io.fd.honeycomb.translate.util.read.cache.TypeAwareIdentifierCacheKeyFactory; +import io.fd.vpp.jvpp.core.dto.IpAddressDetails; +import io.fd.vpp.jvpp.core.dto.IpAddressDetailsReplyDump; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.List; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv6; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv6Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv6.Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv6.AddressBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv6.AddressKey; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class Ipv6AddressCustomizer extends FutureJVppCustomizer + implements InitializingListReaderCustomizer, IpReader { + + private static final Logger LOG = LoggerFactory.getLogger(Ipv6AddressCustomizer.class); + + private final NamingContext interfaceContext; + private final DumpCacheManager dumpManager; + + public Ipv6AddressCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext interfaceContext) { + super(futureJVppCore); + this.interfaceContext = checkNotNull(interfaceContext, "interfaceContext should not be null"); + this.dumpManager = + new DumpCacheManager.DumpCacheManagerBuilder() + .withExecutor(createAddressDumpExecutor(futureJVppCore)) + // Key needs to contain interface ID to distinguish dumps between interfaces + .withCacheKeyFactory(new TypeAwareIdentifierCacheKeyFactory(IpAddressDetailsReplyDump.class, + ImmutableSet.of(Interface.class))) + .build(); + } + + @Override + @Nonnull + public AddressBuilder getBuilder(@Nonnull InstanceIdentifier
id) { + return new AddressBuilder(); + } + + @Override + public void readCurrentAttributes(@Nonnull InstanceIdentifier
id, @Nonnull AddressBuilder builder, + @Nonnull ReadContext ctx) + throws ReadFailedException { + LOG.debug("Reading attributes for interface address: {}", id); + + final String interfaceName = id.firstKeyOf(Interface.class).getName(); + final int interfaceIndex = interfaceContext.getIndex(interfaceName, ctx.getMappingContext()); + final Optional dumpOptional = + dumpManager.getDump(id, ctx.getModificationCache(), new IfaceDumpFilter(interfaceIndex, true)); + + if (!dumpOptional.isPresent() || dumpOptional.get().ipAddressDetails.isEmpty()) { + return; + } + final Optional ipAddressDetails = + findIpv6AddressDetailsByIp(dumpOptional, id.firstKeyOf(Address.class).getIp()); + + if (ipAddressDetails.isPresent()) { + final IpAddressDetails detail = ipAddressDetails.get(); + builder.setIp(arrayToIpv6AddressNoZone(detail.ip)) + .setPrefixLength((short) Byte.toUnsignedInt(detail.prefixLength)) + .build(); + + if (LOG.isDebugEnabled()) { + LOG.debug("Attributes for {} interface (id={}) address {} successfully read: {}", + interfaceName, interfaceIndex, id, builder.build()); + } + } + } + + @Override + public List getAllIds(@Nonnull InstanceIdentifier
id, @Nonnull ReadContext ctx) + throws ReadFailedException { + LOG.debug("Reading list of keys for interface addresses: {}", id); + + final String interfaceName = id.firstKeyOf(Interface.class).getName(); + final int interfaceIndex = interfaceContext.getIndex(interfaceName, ctx.getMappingContext()); + final Optional dumpOptional = + dumpManager.getDump(id, ctx.getModificationCache(), new IfaceDumpFilter(interfaceIndex, true)); + + return getAllIpv6AddressIds(dumpOptional, AddressKey::new); + } + + @Override + public void merge(@Nonnull Builder builder, @Nonnull List
readData) { + ((Ipv6Builder) builder).setAddress(readData); + } + + @Override + public Initialized init( + @Nonnull final InstanceIdentifier
id, @Nonnull final Address readValue, + @Nonnull final ReadContext ctx) { + return Initialized.create(getCfgId(id), + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv6.AddressBuilder() + .setIp(readValue.getIp()) + .setPrefixLength(readValue.getPrefixLength()) + .build()); + } + + static InstanceIdentifier getCfgId( + final InstanceIdentifier
id) { + return InterfaceCustomizer.getCfgId(RWUtils.cutId(id, Interface.class)) + .augmentation(Interface1.class) + .child(Ipv6.class) + .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv6.Address.class, + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv6.AddressKey( + id.firstKeyOf(Address.class).getIp())); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/Ipv6Customizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/Ipv6Customizer.java new file mode 100644 index 000000000..8f12619fd --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/Ipv6Customizer.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2016 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.interfacesstate.ip.v6; + +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +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.ip.rev140616.Interface2Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv6; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv6Builder; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class Ipv6Customizer extends FutureJVppCustomizer implements ReaderCustomizer { + + private static final Logger LOG = LoggerFactory.getLogger(Ipv6Customizer.class); + + public Ipv6Customizer(@Nonnull final FutureJVppCore futureJVppCore) { + super(futureJVppCore); + } + + @Override + public void merge(@Nonnull final Builder parentBuilder, @Nonnull final Ipv6 readValue) { + ((Interface2Builder) parentBuilder).setIpv6(readValue); + } + + @Nonnull + @Override + public Ipv6Builder getBuilder(@Nonnull final InstanceIdentifier id) { + return new Ipv6Builder(); + } + + @Override + public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final Ipv6Builder builder, + @Nonnull final ReadContext ctx) throws ReadFailedException { + LOG.debug("Reading Ipv6 leaves (mtu, forwarding) is not supported by VPP API"); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/Ipv6NeighbourCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/Ipv6NeighbourCustomizer.java new file mode 100644 index 000000000..923795f50 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/Ipv6NeighbourCustomizer.java @@ -0,0 +1,119 @@ +/* + * 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.interfacesstate.ip.v6; + + +import static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.NeighborOrigin.Dynamic; +import static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.NeighborOrigin.Static; + +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableSet; +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfacesstate.ip.IpReader; +import io.fd.hc2vpp.v3po.interfacesstate.ip.dump.params.IfaceDumpFilter; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer; +import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; +import io.fd.honeycomb.translate.util.read.cache.DumpSupplier; +import io.fd.honeycomb.translate.util.read.cache.TypeAwareIdentifierCacheKeyFactory; +import io.fd.vpp.jvpp.core.dto.IpNeighborDetails; +import io.fd.vpp.jvpp.core.dto.IpNeighborDetailsReplyDump; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.List; +import java.util.function.Function; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv6Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv6.Neighbor; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv6.NeighborBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.ipv6.NeighborKey; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class Ipv6NeighbourCustomizer extends FutureJVppCustomizer + implements ListReaderCustomizer, IpReader { + + + private final DumpCacheManager dumpManager; + private final NamingContext interfaceContext; + + public Ipv6NeighbourCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext interfaceContext) { + super(futureJVppCore); + dumpManager = new DumpCacheManager.DumpCacheManagerBuilder() + .withExecutor(createNeighbourDumpExecutor(futureJVppCore)) + // cached with parent interface scope + .withCacheKeyFactory(new TypeAwareIdentifierCacheKeyFactory(IpNeighborDetailsReplyDump.class, + ImmutableSet.of(Interface.class))) + .build(); + this.interfaceContext = interfaceContext; + } + + @Override + public NeighborBuilder getBuilder(InstanceIdentifier id) { + return new NeighborBuilder(); + } + + @Override + public void readCurrentAttributes(InstanceIdentifier id, NeighborBuilder builder, ReadContext ctx) + throws ReadFailedException { + + final Ipv6AddressNoZone ip = id.firstKeyOf(Neighbor.class).getIp(); + + final Optional dumpOpt = dumpSupplier(id, ctx).get(); + + if (dumpOpt.isPresent()) { + dumpOpt.get().ipNeighborDetails + .stream() + .filter(ipNeighborDetails -> ip.equals(arrayToIpv6AddressNoZone(ipNeighborDetails.ipAddress))) + .findFirst() + .ifPresent(ipNeighborDetails -> builder.setIp(arrayToIpv6AddressNoZone(ipNeighborDetails.ipAddress)) + .setKey(keyMapper().apply(ipNeighborDetails)) + .setLinkLayerAddress(toPhysAddress(ipNeighborDetails.macAddress)) + .setOrigin(ipNeighborDetails.isStatic == 0 + ? Dynamic + : Static)); + } + } + + @Override + public List getAllIds(InstanceIdentifier id, ReadContext context) + throws ReadFailedException { + return getNeighborKeys(dumpSupplier(id, context), keyMapper()); + } + + @Override + public void merge(Builder builder, List readData) { + ((Ipv6Builder) builder).setNeighbor(readData); + } + + private Function keyMapper() { + return ipNeighborDetails -> new NeighborKey(arrayToIpv6AddressNoZone(ipNeighborDetails.ipAddress)); + } + + private DumpSupplier> dumpSupplier(final InstanceIdentifier id, + final ReadContext context) { + return () -> dumpManager + .getDump(id, context.getModificationCache(), new IfaceDumpFilter(interfaceContext + .getIndex(id.firstKeyOf(Interface.class).getName(), context.getMappingContext()), + true)); + } +} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/subinterface/SubInterfaceIpv6AddressCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/subinterface/SubInterfaceIpv6AddressCustomizer.java new file mode 100644 index 000000000..4aea4c00e --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/subinterface/SubInterfaceIpv6AddressCustomizer.java @@ -0,0 +1,143 @@ +/* + * 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.interfacesstate.ip.v6.subinterface; + + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableSet; +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfacesstate.SubInterfaceCustomizer; +import io.fd.hc2vpp.v3po.interfacesstate.ip.IpReader; +import io.fd.hc2vpp.v3po.interfacesstate.ip.dump.params.IfaceDumpFilter; +import io.fd.hc2vpp.v3po.util.SubInterfaceUtils; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.Initialized; +import io.fd.honeycomb.translate.spi.read.InitializingListReaderCustomizer; +import io.fd.honeycomb.translate.util.RWUtils; +import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; +import io.fd.honeycomb.translate.util.read.cache.TypeAwareIdentifierCacheKeyFactory; +import io.fd.vpp.jvpp.core.dto.IpAddressDetails; +import io.fd.vpp.jvpp.core.dto.IpAddressDetailsReplyDump; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.List; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces.state._interface.sub.interfaces.SubInterface; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip6.attributes.Ipv6; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip6.attributes.Ipv6Builder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip6.attributes.ipv6.Address; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip6.attributes.ipv6.AddressBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip6.attributes.ipv6.AddressKey; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SubInterfaceIpv6AddressCustomizer extends FutureJVppCustomizer + implements InitializingListReaderCustomizer, IpReader { + + private static final Logger LOG = LoggerFactory.getLogger(SubInterfaceIpv6AddressCustomizer.class); + + private final NamingContext interfaceContext; + private final DumpCacheManager dumpManager; + + public SubInterfaceIpv6AddressCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext interfaceContext) { + super(futureJVppCore); + this.interfaceContext = checkNotNull(interfaceContext, "interfaceContext should not be null"); + this.dumpManager = new DumpCacheManager.DumpCacheManagerBuilder() + .withExecutor(createAddressDumpExecutor(futureJVppCore)) + .withCacheKeyFactory(new TypeAwareIdentifierCacheKeyFactory(IpAddressDetailsReplyDump.class, + ImmutableSet.of(SubInterface.class))) + .build(); + } + + private static String getSubInterfaceName(@Nonnull final InstanceIdentifier
id) { + return SubInterfaceUtils.getSubInterfaceName(id.firstKeyOf(Interface.class).getName(), + Math.toIntExact(id.firstKeyOf(SubInterface.class).getIdentifier())); + } + + @Override + @Nonnull + public AddressBuilder getBuilder(@Nonnull InstanceIdentifier
id) { + return new AddressBuilder(); + } + + @Override + public void readCurrentAttributes(@Nonnull InstanceIdentifier
id, @Nonnull AddressBuilder builder, + @Nonnull ReadContext ctx) + throws ReadFailedException { + LOG.debug("Reading attributes for sub-interface address: {}", id); + + final String subInterfaceName = getSubInterfaceName(id); + final int subInterfaceIndex = interfaceContext.getIndex(subInterfaceName, ctx.getMappingContext()); + final Optional dumpOptional = dumpManager + .getDump(id, ctx.getModificationCache(), new IfaceDumpFilter(subInterfaceIndex, false)); + + final Optional ipAddressDetails = + findIpv6AddressDetailsByIp(dumpOptional, id.firstKeyOf(Address.class).getIp()); + + if (ipAddressDetails.isPresent()) { + final IpAddressDetails detail = ipAddressDetails.get(); + builder.setIp(arrayToIpv6AddressNoZone(detail.ip)); + builder.setPrefixLength((short) detail.prefixLength); + + if (LOG.isDebugEnabled()) { + LOG.debug("Attributes for {} sub-interface (id={}) address {} successfully read: {}", + subInterfaceName, subInterfaceIndex, id, builder.build()); + } + } + } + + @Override + @Nonnull + public List getAllIds(@Nonnull InstanceIdentifier
id, @Nonnull ReadContext ctx) + throws ReadFailedException { + LOG.debug("Reading list of keys for sub-interface addresses: {}", id); + + final String subInterfaceName = getSubInterfaceName(id); + final int subInterfaceIndex = interfaceContext.getIndex(subInterfaceName, ctx.getMappingContext()); + final Optional dumpOptional = dumpManager + .getDump(id, ctx.getModificationCache(), new IfaceDumpFilter(subInterfaceIndex, false)); + + return getAllIpv6AddressIds(dumpOptional, AddressKey::new); + } + + @Override + public void merge(@Nonnull Builder builder, @Nonnull List
readData) { + ((Ipv6Builder) builder).setAddress(readData); + } + + @Override + @Nonnull + public Initialized
init( + @Nonnull final InstanceIdentifier
id, @Nonnull final Address readValue, + @Nonnull final ReadContext ctx) { + return Initialized.create(getCfgId(id), readValue); + } + + private InstanceIdentifier
getCfgId(final InstanceIdentifier
id) { + return SubInterfaceCustomizer.getCfgId(RWUtils.cutId(id, SubInterface.class)) + .child(Ipv6.class) + .child(Address.class, new AddressKey(id.firstKeyOf(Address.class))); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/subinterface/SubInterfaceIpv6NeighbourCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/subinterface/SubInterfaceIpv6NeighbourCustomizer.java new file mode 100644 index 000000000..ac7882729 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/subinterface/SubInterfaceIpv6NeighbourCustomizer.java @@ -0,0 +1,113 @@ +/* + * 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.interfacesstate.ip.v6.subinterface; + +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableSet; +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfacesstate.ip.IpReader; +import io.fd.hc2vpp.v3po.interfacesstate.ip.dump.params.IfaceDumpFilter; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer; +import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; +import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager.DumpCacheManagerBuilder; +import io.fd.honeycomb.translate.util.read.cache.DumpSupplier; +import io.fd.honeycomb.translate.util.read.cache.TypeAwareIdentifierCacheKeyFactory; +import io.fd.vpp.jvpp.core.dto.IpNeighborDetails; +import io.fd.vpp.jvpp.core.dto.IpNeighborDetailsReplyDump; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.List; +import java.util.function.Function; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip6.attributes.Ipv6Builder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip6.attributes.ipv6.Neighbor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip6.attributes.ipv6.NeighborBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip6.attributes.ipv6.NeighborKey; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class SubInterfaceIpv6NeighbourCustomizer extends FutureJVppCustomizer + implements ListReaderCustomizer, IpReader { + + private final DumpCacheManager dumpManager; + private final NamingContext interfaceContext; + + public SubInterfaceIpv6NeighbourCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext interfaceContext) { + super(futureJVppCore); + dumpManager = new DumpCacheManagerBuilder() + .withExecutor(createNeighbourDumpExecutor(futureJVppCore)) + // cached with parent interface scope + .withCacheKeyFactory(new TypeAwareIdentifierCacheKeyFactory(IpNeighborDetailsReplyDump.class, + ImmutableSet.of(Interface.class))) + .build(); + this.interfaceContext = interfaceContext; + } + + @Override + public NeighborBuilder getBuilder(InstanceIdentifier id) { + return new NeighborBuilder(); + } + + @Override + public void readCurrentAttributes(InstanceIdentifier id, NeighborBuilder builder, ReadContext ctx) + throws ReadFailedException { + + final Ipv6AddressNoZone ip = id.firstKeyOf(Neighbor.class).getIp(); + + final Optional dumpOpt = dumpSupplier(id, ctx).get(); + + if (dumpOpt.isPresent()) { + dumpOpt.get().ipNeighborDetails + .stream() + .filter(ipNeighborDetails -> ip.equals(arrayToIpv6AddressNoZone(ipNeighborDetails.ipAddress))) + .findFirst() + .ifPresent(ipNeighborDetails -> builder.setIp(arrayToIpv6AddressNoZone(ipNeighborDetails.ipAddress)) + .setKey(keyMapper().apply(ipNeighborDetails)) + .setLinkLayerAddress(toPhysAddress(ipNeighborDetails.macAddress))); + } + } + + @Override + public List getAllIds(InstanceIdentifier id, ReadContext context) + throws ReadFailedException { + return getNeighborKeys(dumpSupplier(id, context), keyMapper()); + } + + @Override + public void merge(Builder builder, List readData) { + ((Ipv6Builder) builder).setNeighbor(readData); + } + + private Function keyMapper() { + return ipNeighborDetails -> new NeighborKey(arrayToIpv6AddressNoZone(ipNeighborDetails.ipAddress)); + } + + private DumpSupplier> dumpSupplier(final InstanceIdentifier id, + final ReadContext context) { + return () -> dumpManager + .getDump(id, context.getModificationCache(), new IfaceDumpFilter(interfaceContext + .getIndex(id.firstKeyOf(Interface.class).getName(), context.getMappingContext()), + true)); + } + +} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/Ipv4AddressCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/Ipv4AddressCustomizerTest.java deleted file mode 100644 index 3b46d7fb0..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/Ipv4AddressCustomizerTest.java +++ /dev/null @@ -1,337 +0,0 @@ -/* - * Copyright (c) 2016 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.ip; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.argThat; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import com.google.common.base.Optional; -import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfaces.ip.subnet.validation.SubnetValidationException; -import io.fd.hc2vpp.v3po.interfaces.ip.subnet.validation.SubnetValidator; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.vpp.jvpp.VppBaseCallException; -import io.fd.vpp.jvpp.core.dto.IpAddressDetailsReplyDump; -import io.fd.vpp.jvpp.core.dto.SwInterfaceAddDelAddress; -import io.fd.vpp.jvpp.core.dto.SwInterfaceAddDelAddressReply; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import org.junit.Before; -import org.junit.Test; -import org.mockito.ArgumentMatcher; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; -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.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1; -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.Ipv4Builder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.AddressBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.Netmask; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.NetmaskBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.PrefixLength; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.PrefixLengthBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DottedQuad; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class Ipv4AddressCustomizerTest extends WriterCustomizerTest { - - private static final String IFC_CTX_NAME = "ifc-test-instance"; - private static final String IFACE_NAME = "eth0"; - private static final int IFACE_ID = 123; - - @Mock - private SubnetValidator subnetValidator; - - private NamingContext interfaceContext; - private Ipv4AddressCustomizer customizer; - - private static InstanceIdentifier
getAddressId(final String ifaceName) { - return InstanceIdentifier.builder(Interfaces.class) - .child(Interface.class, new InterfaceKey(ifaceName)) - .augmentation(Interface1.class) - .child(Ipv4.class) - .child(Address.class) - .build(); - } - - private static ArgumentMatcher> matchInstanceIdentifier( - Class desiredClass) { - return o -> o instanceof InstanceIdentifier && (o.getTargetType().equals(desiredClass)); - } - - @Before - public void setUpTest() throws Exception { - interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); - - customizer = new Ipv4AddressCustomizer(api, interfaceContext, subnetValidator); - - doReturn(future(new IpAddressDetailsReplyDump())).when(api).ipAddressDump(any()); - when(writeContext.readAfter(Mockito.any())) - .thenReturn(Optional.of(new Ipv4Builder().setAddress(Collections.emptyList()).build())); - } - - private void whenSwInterfaceAddDelAddressThenSuccess() { - doReturn(future(new SwInterfaceAddDelAddressReply())).when(api).swInterfaceAddDelAddress(any(SwInterfaceAddDelAddress.class)); - } - - private void whenSwInterfaceAddDelAddressThenFailure() { - doReturn(failedFuture()).when(api).swInterfaceAddDelAddress(any(SwInterfaceAddDelAddress.class)); - } - - @Test - public void testAddPrefixLengthIpv4Address() throws Exception { - doNothing().when(subnetValidator).checkNotAddingToSameSubnet(Mockito.anyList()); - - final InstanceIdentifier
id = getAddressId(IFACE_NAME); - when(writeContext.readBefore(id)).thenReturn(Optional.absent()); - - Ipv4AddressNoZone noZoneIp = new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1")); - PrefixLength length = new PrefixLengthBuilder().setPrefixLength(new Integer(24).shortValue()).build(); - Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(length).build(); - - defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); - whenSwInterfaceAddDelAddressThenSuccess(); - - customizer.writeCurrentAttributes(id, data, writeContext); - - verify(api).swInterfaceAddDelAddress(generateSwInterfaceAddDelAddressRequest(new byte[]{-64, -88, 2, 1}, - (byte) 1, (byte) 24)); - } - - @Test - public void testAddPrefixLengthIpv4AddressFailed() throws Exception { - final InstanceIdentifier
id = getAddressId(IFACE_NAME); - when(writeContext.readBefore(id)).thenReturn(Optional.absent()); - - Ipv4AddressNoZone noZoneIp = new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1")); - PrefixLength length = new PrefixLengthBuilder().setPrefixLength(new Integer(24).shortValue()).build(); - Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(length).build(); - - defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); - whenSwInterfaceAddDelAddressThenFailure(); - - try { - customizer.writeCurrentAttributes(id, data, writeContext); - } catch (WriteFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verify(api).swInterfaceAddDelAddress( - generateSwInterfaceAddDelAddressRequest(new byte[]{-64, -88, 2, 1}, - (byte) 1, (byte) 24)); - return; - } - fail("WriteFailedException was expected"); - } - - @Test - public void testAddPrefixLengthIpv4AddressConflicted() throws Exception { - - final InstanceIdentifier
id = getAddressId(IFACE_NAME); - when(writeContext.readBefore(id)).thenReturn(Optional.absent()); - - Ipv4AddressNoZone noZoneIp = new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1")); - PrefixLength length = new PrefixLengthBuilder().setPrefixLength(new Integer(24).shortValue()).build(); - Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(length).build(); - final List
addressList = Arrays.asList(data); - - //throws when validation invoked - Mockito.doThrow(SubnetValidationException.forConflictingData((short) 24, Arrays.asList(data))).when(subnetValidator) - .checkNotAddingToSameSubnet(addressList); - - //fake data return from WriteContext - doReturn(Optional.of(new Ipv4Builder().setAddress(addressList).build())).when(writeContext) - .readAfter(argThat(matchInstanceIdentifier(Ipv4.class))); - - defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); - - try { - customizer.writeCurrentAttributes(id, data, writeContext); - } catch (WriteFailedException e) { - //verifies if cause of exception is correct type - assertTrue(e.getCause() instanceof SubnetValidationException); - - //verify that validation call was invoked with data from writeContext - verify(subnetValidator, times(1)).checkNotAddingToSameSubnet(addressList); - } - - } - - @Test(expected = WriteFailedException.UpdateFailedException.class) - public void testUpdate() throws Exception { - final Address data = mock(Address.class); - customizer.updateCurrentAttributes(getAddressId(IFACE_NAME), data, data, writeContext); - } - - private SwInterfaceAddDelAddress generateSwInterfaceAddDelAddressRequest(final byte[] address, final byte isAdd, - final byte prefixLength) { - final SwInterfaceAddDelAddress request = new SwInterfaceAddDelAddress(); - request.swIfIndex = IFACE_ID; - request.isAdd = isAdd; - request.isIpv6 = 0; - request.delAll = 0; - request.addressLength = prefixLength; - request.address = address; - return request; - } - - @Test - public void testDeletePrefixLengthIpv4Address() throws Exception { - final InstanceIdentifier
id = getAddressId(IFACE_NAME); - - Ipv4AddressNoZone noZoneIp = new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1")); - PrefixLength length = new PrefixLengthBuilder().setPrefixLength(new Integer(24).shortValue()).build(); - Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(length).build(); - - defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); - whenSwInterfaceAddDelAddressThenSuccess(); - - customizer.deleteCurrentAttributes(id, data, writeContext); - - verify(api).swInterfaceAddDelAddress(generateSwInterfaceAddDelAddressRequest(new byte[]{-64, -88, 2, 1}, - (byte) 0, (byte) 24)); - } - - @Test - public void testDeletePrefixLengthIpv4AddressFailed() throws Exception { - final InstanceIdentifier
id = getAddressId(IFACE_NAME); - - Ipv4AddressNoZone noZoneIp = new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1")); - PrefixLength length = new PrefixLengthBuilder().setPrefixLength(new Integer(24).shortValue()).build(); - Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(length).build(); - - defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); - whenSwInterfaceAddDelAddressThenFailure(); - - try { - customizer.deleteCurrentAttributes(id, data, writeContext); - } catch (WriteFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verify(api).swInterfaceAddDelAddress( - generateSwInterfaceAddDelAddressRequest(new byte[]{-64, -88, 2, 1}, - (byte) 0, (byte) 24)); - return; - } - fail("WriteFailedException was expec16ted"); - } - - @Test - public void testNetmaskFailed() { - final int expectedPrefixLength = 1; - final String stringMask = "128.0.0.0"; - final InstanceIdentifier
id = getAddressId(IFACE_NAME); - when(writeContext.readBefore(id)).thenReturn(Optional.absent()); - - Ipv4AddressNoZone noZoneIp = new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1")); - Netmask subnet = new NetmaskBuilder().setNetmask(new DottedQuad(stringMask)).build(); - Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(subnet).build(); - - defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); - whenSwInterfaceAddDelAddressThenFailure(); - - try { - customizer.writeCurrentAttributes(id, data, writeContext); - } catch (WriteFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verify(api).swInterfaceAddDelAddress(generateSwInterfaceAddDelAddressRequest(new byte[]{-64, -88, 2, 1}, - (byte) 1, (byte) expectedPrefixLength)); - return; - } - fail("WriteFailedException was expec16ted"); - - } - - private void testSingleNetmask(final int expectedPrefixLength, final String stringMask) throws Exception { - final InstanceIdentifier
id = getAddressId(IFACE_NAME); - when(writeContext.readBefore(id)).thenReturn(Optional.absent()); - - Ipv4AddressNoZone noZoneIp = new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1")); - Netmask subnet = new NetmaskBuilder().setNetmask(new DottedQuad(stringMask)).build(); - Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(subnet).build(); - - defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); - whenSwInterfaceAddDelAddressThenSuccess(); - - customizer.writeCurrentAttributes(id, data, writeContext); - - verify(api).swInterfaceAddDelAddress(generateSwInterfaceAddDelAddressRequest(new byte[]{-64, -88, 2, 1}, - (byte) 1, (byte) expectedPrefixLength)); - } - - private void testSingleIllegalNetmask(final String stringMask) throws Exception { - try { - final InstanceIdentifier
id = getAddressId(IFACE_NAME); - when(writeContext.readBefore(id)).thenReturn(Optional.absent()); - - Ipv4AddressNoZone noZoneIp = new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1")); - Netmask subnet = new NetmaskBuilder().setNetmask(new DottedQuad(stringMask)).build(); - Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(subnet).build(); - - defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); - whenSwInterfaceAddDelAddressThenSuccess(); - - customizer.writeCurrentAttributes(id, data, writeContext); - } catch (IllegalArgumentException e) { - return; - } - fail("IllegalArgumentException expected"); - - } - - /** - * Test contiguous netmask length from QuadDotted notation - */ - @Test - public void testNetmaskLength() throws Exception { - testSingleNetmask(1, "128.0.0.0"); - testSingleNetmask(2, "192.0.0.0"); - testSingleNetmask(8, "255.0.0.0"); - testSingleNetmask(9, "255.128.0.0"); - testSingleNetmask(16, "255.255.0.0"); - testSingleNetmask(24, "255.255.255.0"); - } - - @Test - public void testNetmaskIllegal() throws Exception { - testSingleIllegalNetmask(""); - testSingleIllegalNetmask("."); - testSingleIllegalNetmask(".255"); - testSingleIllegalNetmask("255"); - testSingleIllegalNetmask("255."); - testSingleIllegalNetmask("255.255"); - testSingleIllegalNetmask("255.255.0"); - testSingleIllegalNetmask("255.255.255."); - testSingleIllegalNetmask("255.255.255.256"); - testSingleIllegalNetmask("0.0.0.0"); - testSingleIllegalNetmask("10.10.10.10"); - testSingleIllegalNetmask("255.1.255.0"); - testSingleIllegalNetmask("255.255.255.255"); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/Ipv4NeighbourCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/Ipv4NeighbourCustomizerTest.java index 9ddefdc87..b93a8b5bb 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/Ipv4NeighbourCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/Ipv4NeighbourCustomizerTest.java @@ -25,6 +25,7 @@ import static org.mockito.Mockito.when; import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; import io.fd.hc2vpp.common.translate.util.Ipv4Translator; import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfaces.ip.v4.Ipv4NeighbourCustomizer; import io.fd.honeycomb.translate.write.WriteFailedException; import io.fd.vpp.jvpp.VppBaseCallException; import io.fd.vpp.jvpp.core.dto.IpNeighborAddDel; diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/SubInterfaceIpv4AddressCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/SubInterfaceIpv4AddressCustomizerTest.java index e4479a0e0..98ff8da64 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/SubInterfaceIpv4AddressCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/SubInterfaceIpv4AddressCustomizerTest.java @@ -25,6 +25,7 @@ import static org.mockito.Mockito.when; import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfaces.ip.v4.subinterface.SubInterfaceIpv4AddressCustomizer; import io.fd.honeycomb.translate.write.WriteFailedException; import io.fd.vpp.jvpp.VppBaseCallException; import io.fd.vpp.jvpp.core.dto.SwInterfaceAddDelAddress; diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/subnet/validation/Ipv4SubnetValidatorTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/subnet/validation/Ipv4SubnetValidatorTest.java new file mode 100644 index 000000000..faa860f45 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/subnet/validation/Ipv4SubnetValidatorTest.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2016 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.ip.subnet.validation; + + +import com.google.common.collect.Lists; +import java.util.List; +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.AddressBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.NetmaskBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.PrefixLengthBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DottedQuad; + +public class Ipv4SubnetValidatorTest { + + private Ipv4SubnetValidator subnetValidator; + + @Before + public void init() { + subnetValidator = new Ipv4SubnetValidator(); + } + + @Test(expected = SubnetValidationException.class) + public void testValidateNegativeSameTypes() throws SubnetValidationException { + List
addresses = Lists.newArrayList(); + + addresses.add(new AddressBuilder().setSubnet(new PrefixLengthBuilder().setPrefixLength((short) 24).build()) + .build()); + addresses.add(new AddressBuilder().setSubnet(new PrefixLengthBuilder().setPrefixLength((short) 24).build()) + .build()); + + subnetValidator.checkNotAddingToSameSubnet(addresses); + } + + @Test(expected = SubnetValidationException.class) + public void testValidateNegativeMixedTypes() throws SubnetValidationException { + List
addresses = Lists.newArrayList(); + + addresses.add(new AddressBuilder().setSubnet(new PrefixLengthBuilder().setPrefixLength((short) 24).build()) + .build()); + addresses.add(new AddressBuilder() + .setSubnet(new NetmaskBuilder().setNetmask(new DottedQuad("255.255.255.0")).build()) + .build()); + + subnetValidator.checkNotAddingToSameSubnet(addresses); + } + + @Test + public void testValidatePositiveSameTypes() throws SubnetValidationException { + List
addresses = Lists.newArrayList(); + + addresses.add(new AddressBuilder().setSubnet(new PrefixLengthBuilder().setPrefixLength((short) 24).build()) + .build()); + addresses.add(new AddressBuilder().setSubnet(new PrefixLengthBuilder().setPrefixLength((short) 25).build()) + .build()); + + subnetValidator.checkNotAddingToSameSubnet(addresses); + } + + @Test + public void testValidatePositiveMixedTypes() throws SubnetValidationException { + List
addresses = Lists.newArrayList(); + + addresses.add(new AddressBuilder().setSubnet(new PrefixLengthBuilder().setPrefixLength((short) 24).build()) + .build()); + addresses.add(new AddressBuilder() + .setSubnet(new NetmaskBuilder().setNetmask(new DottedQuad("255.255.0.0")).build()) + .build()); + + subnetValidator.checkNotAddingToSameSubnet(addresses); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/subnet/validation/SubnetValidatorTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/subnet/validation/SubnetValidatorTest.java deleted file mode 100644 index 0c1e878a8..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/subnet/validation/SubnetValidatorTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2016 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.ip.subnet.validation; - - -import com.google.common.collect.Lists; -import java.util.List; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.AddressBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.NetmaskBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.PrefixLengthBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DottedQuad; - -public class SubnetValidatorTest { - - private SubnetValidator subnetValidator; - - @Before - public void init() { - subnetValidator = new SubnetValidator(); - } - - @Test(expected = SubnetValidationException.class) - public void testValidateNegativeSameTypes() throws SubnetValidationException { - List
addresses = Lists.newArrayList(); - - addresses.add(new AddressBuilder().setSubnet(new PrefixLengthBuilder().setPrefixLength((short) 24).build()) - .build()); - addresses.add(new AddressBuilder().setSubnet(new PrefixLengthBuilder().setPrefixLength((short) 24).build()) - .build()); - - subnetValidator.checkNotAddingToSameSubnet(addresses); - } - - @Test(expected = SubnetValidationException.class) - public void testValidateNegativeMixedTypes() throws SubnetValidationException { - List
addresses = Lists.newArrayList(); - - addresses.add(new AddressBuilder().setSubnet(new PrefixLengthBuilder().setPrefixLength((short) 24).build()) - .build()); - addresses.add(new AddressBuilder() - .setSubnet(new NetmaskBuilder().setNetmask(new DottedQuad("255.255.255.0")).build()) - .build()); - - subnetValidator.checkNotAddingToSameSubnet(addresses); - } - - @Test - public void testValidatePositiveSameTypes() throws SubnetValidationException { - List
addresses = Lists.newArrayList(); - - addresses.add(new AddressBuilder().setSubnet(new PrefixLengthBuilder().setPrefixLength((short) 24).build()) - .build()); - addresses.add(new AddressBuilder().setSubnet(new PrefixLengthBuilder().setPrefixLength((short) 25).build()) - .build()); - - subnetValidator.checkNotAddingToSameSubnet(addresses); - } - - @Test - public void testValidatePositiveMixedTypes() throws SubnetValidationException { - List
addresses = Lists.newArrayList(); - - addresses.add(new AddressBuilder().setSubnet(new PrefixLengthBuilder().setPrefixLength((short) 24).build()) - .build()); - addresses.add(new AddressBuilder() - .setSubnet(new NetmaskBuilder().setNetmask(new DottedQuad("255.255.0.0")).build()) - .build()); - - subnetValidator.checkNotAddingToSameSubnet(addresses); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/Ipv4AddressCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/Ipv4AddressCustomizerTest.java new file mode 100644 index 000000000..8f3dafd10 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/Ipv4AddressCustomizerTest.java @@ -0,0 +1,337 @@ +/* + * Copyright (c) 2016 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.ip.v4; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.argThat; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import com.google.common.base.Optional; +import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfaces.ip.subnet.validation.Ipv4SubnetValidator; +import io.fd.hc2vpp.v3po.interfaces.ip.subnet.validation.SubnetValidationException; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.VppBaseCallException; +import io.fd.vpp.jvpp.core.dto.IpAddressDetailsReplyDump; +import io.fd.vpp.jvpp.core.dto.SwInterfaceAddDelAddress; +import io.fd.vpp.jvpp.core.dto.SwInterfaceAddDelAddressReply; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentMatcher; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; +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.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1; +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.Ipv4Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.AddressBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.Netmask; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.NetmaskBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.PrefixLength; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.address.subnet.PrefixLengthBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DottedQuad; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class Ipv4AddressCustomizerTest extends WriterCustomizerTest { + + private static final String IFC_CTX_NAME = "ifc-test-instance"; + private static final String IFACE_NAME = "eth0"; + private static final int IFACE_ID = 123; + + @Mock + private Ipv4SubnetValidator subnetValidator; + + private NamingContext interfaceContext; + private Ipv4AddressCustomizer customizer; + + private static InstanceIdentifier
getAddressId(final String ifaceName) { + return InstanceIdentifier.builder(Interfaces.class) + .child(Interface.class, new InterfaceKey(ifaceName)) + .augmentation(Interface1.class) + .child(Ipv4.class) + .child(Address.class) + .build(); + } + + private static ArgumentMatcher> matchInstanceIdentifier( + Class desiredClass) { + return o -> o instanceof InstanceIdentifier && (o.getTargetType().equals(desiredClass)); + } + + @Before + public void setUpTest() throws Exception { + interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); + + customizer = new Ipv4AddressCustomizer(api, interfaceContext, subnetValidator); + + doReturn(future(new IpAddressDetailsReplyDump())).when(api).ipAddressDump(any()); + when(writeContext.readAfter(Mockito.any())) + .thenReturn(Optional.of(new Ipv4Builder().setAddress(Collections.emptyList()).build())); + } + + private void whenSwInterfaceAddDelAddressThenSuccess() { + doReturn(future(new SwInterfaceAddDelAddressReply())).when(api).swInterfaceAddDelAddress(any(SwInterfaceAddDelAddress.class)); + } + + private void whenSwInterfaceAddDelAddressThenFailure() { + doReturn(failedFuture()).when(api).swInterfaceAddDelAddress(any(SwInterfaceAddDelAddress.class)); + } + + @Test + public void testAddPrefixLengthIpv4Address() throws Exception { + doNothing().when(subnetValidator).checkNotAddingToSameSubnet(Mockito.anyList()); + + final InstanceIdentifier
id = getAddressId(IFACE_NAME); + when(writeContext.readBefore(id)).thenReturn(Optional.absent()); + + Ipv4AddressNoZone noZoneIp = new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1")); + PrefixLength length = new PrefixLengthBuilder().setPrefixLength(new Integer(24).shortValue()).build(); + Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(length).build(); + + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); + whenSwInterfaceAddDelAddressThenSuccess(); + + customizer.writeCurrentAttributes(id, data, writeContext); + + verify(api).swInterfaceAddDelAddress(generateSwInterfaceAddDelAddressRequest(new byte[]{-64, -88, 2, 1}, + (byte) 1, (byte) 24)); + } + + @Test + public void testAddPrefixLengthIpv4AddressFailed() throws Exception { + final InstanceIdentifier
id = getAddressId(IFACE_NAME); + when(writeContext.readBefore(id)).thenReturn(Optional.absent()); + + Ipv4AddressNoZone noZoneIp = new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1")); + PrefixLength length = new PrefixLengthBuilder().setPrefixLength(new Integer(24).shortValue()).build(); + Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(length).build(); + + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); + whenSwInterfaceAddDelAddressThenFailure(); + + try { + customizer.writeCurrentAttributes(id, data, writeContext); + } catch (WriteFailedException e) { + assertTrue(e.getCause() instanceof VppBaseCallException); + verify(api).swInterfaceAddDelAddress( + generateSwInterfaceAddDelAddressRequest(new byte[]{-64, -88, 2, 1}, + (byte) 1, (byte) 24)); + return; + } + fail("WriteFailedException was expected"); + } + + @Test + public void testAddPrefixLengthIpv4AddressConflicted() throws Exception { + + final InstanceIdentifier
id = getAddressId(IFACE_NAME); + when(writeContext.readBefore(id)).thenReturn(Optional.absent()); + + Ipv4AddressNoZone noZoneIp = new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1")); + PrefixLength length = new PrefixLengthBuilder().setPrefixLength(new Integer(24).shortValue()).build(); + Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(length).build(); + final List
addressList = Arrays.asList(data); + + //throws when validation invoked + Mockito.doThrow(SubnetValidationException.forConflictingData((short) 24, Arrays.asList(data))).when(subnetValidator) + .checkNotAddingToSameSubnet(addressList); + + //fake data return from WriteContext + doReturn(Optional.of(new Ipv4Builder().setAddress(addressList).build())).when(writeContext) + .readAfter(argThat(matchInstanceIdentifier(Ipv4.class))); + + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); + + try { + customizer.writeCurrentAttributes(id, data, writeContext); + } catch (WriteFailedException e) { + //verifies if cause of exception is correct type + assertTrue(e.getCause() instanceof SubnetValidationException); + + //verify that validation call was invoked with data from writeContext + verify(subnetValidator, times(1)).checkNotAddingToSameSubnet(addressList); + } + + } + + @Test(expected = WriteFailedException.UpdateFailedException.class) + public void testUpdate() throws Exception { + final Address data = mock(Address.class); + customizer.updateCurrentAttributes(getAddressId(IFACE_NAME), data, data, writeContext); + } + + private SwInterfaceAddDelAddress generateSwInterfaceAddDelAddressRequest(final byte[] address, final byte isAdd, + final byte prefixLength) { + final SwInterfaceAddDelAddress request = new SwInterfaceAddDelAddress(); + request.swIfIndex = IFACE_ID; + request.isAdd = isAdd; + request.isIpv6 = 0; + request.delAll = 0; + request.addressLength = prefixLength; + request.address = address; + return request; + } + + @Test + public void testDeletePrefixLengthIpv4Address() throws Exception { + final InstanceIdentifier
id = getAddressId(IFACE_NAME); + + Ipv4AddressNoZone noZoneIp = new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1")); + PrefixLength length = new PrefixLengthBuilder().setPrefixLength(new Integer(24).shortValue()).build(); + Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(length).build(); + + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); + whenSwInterfaceAddDelAddressThenSuccess(); + + customizer.deleteCurrentAttributes(id, data, writeContext); + + verify(api).swInterfaceAddDelAddress(generateSwInterfaceAddDelAddressRequest(new byte[]{-64, -88, 2, 1}, + (byte) 0, (byte) 24)); + } + + @Test + public void testDeletePrefixLengthIpv4AddressFailed() throws Exception { + final InstanceIdentifier
id = getAddressId(IFACE_NAME); + + Ipv4AddressNoZone noZoneIp = new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1")); + PrefixLength length = new PrefixLengthBuilder().setPrefixLength(new Integer(24).shortValue()).build(); + Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(length).build(); + + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); + whenSwInterfaceAddDelAddressThenFailure(); + + try { + customizer.deleteCurrentAttributes(id, data, writeContext); + } catch (WriteFailedException e) { + assertTrue(e.getCause() instanceof VppBaseCallException); + verify(api).swInterfaceAddDelAddress( + generateSwInterfaceAddDelAddressRequest(new byte[]{-64, -88, 2, 1}, + (byte) 0, (byte) 24)); + return; + } + fail("WriteFailedException was expec16ted"); + } + + @Test + public void testNetmaskFailed() { + final int expectedPrefixLength = 1; + final String stringMask = "128.0.0.0"; + final InstanceIdentifier
id = getAddressId(IFACE_NAME); + when(writeContext.readBefore(id)).thenReturn(Optional.absent()); + + Ipv4AddressNoZone noZoneIp = new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1")); + Netmask subnet = new NetmaskBuilder().setNetmask(new DottedQuad(stringMask)).build(); + Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(subnet).build(); + + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); + whenSwInterfaceAddDelAddressThenFailure(); + + try { + customizer.writeCurrentAttributes(id, data, writeContext); + } catch (WriteFailedException e) { + assertTrue(e.getCause() instanceof VppBaseCallException); + verify(api).swInterfaceAddDelAddress(generateSwInterfaceAddDelAddressRequest(new byte[]{-64, -88, 2, 1}, + (byte) 1, (byte) expectedPrefixLength)); + return; + } + fail("WriteFailedException was expec16ted"); + + } + + private void testSingleNetmask(final int expectedPrefixLength, final String stringMask) throws Exception { + final InstanceIdentifier
id = getAddressId(IFACE_NAME); + when(writeContext.readBefore(id)).thenReturn(Optional.absent()); + + Ipv4AddressNoZone noZoneIp = new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1")); + Netmask subnet = new NetmaskBuilder().setNetmask(new DottedQuad(stringMask)).build(); + Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(subnet).build(); + + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); + whenSwInterfaceAddDelAddressThenSuccess(); + + customizer.writeCurrentAttributes(id, data, writeContext); + + verify(api).swInterfaceAddDelAddress(generateSwInterfaceAddDelAddressRequest(new byte[]{-64, -88, 2, 1}, + (byte) 1, (byte) expectedPrefixLength)); + } + + private void testSingleIllegalNetmask(final String stringMask) throws Exception { + try { + final InstanceIdentifier
id = getAddressId(IFACE_NAME); + when(writeContext.readBefore(id)).thenReturn(Optional.absent()); + + Ipv4AddressNoZone noZoneIp = new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1")); + Netmask subnet = new NetmaskBuilder().setNetmask(new DottedQuad(stringMask)).build(); + Address data = new AddressBuilder().setIp(noZoneIp).setSubnet(subnet).build(); + + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); + whenSwInterfaceAddDelAddressThenSuccess(); + + customizer.writeCurrentAttributes(id, data, writeContext); + } catch (IllegalArgumentException e) { + return; + } + fail("IllegalArgumentException expected"); + + } + + /** + * Test contiguous netmask length from QuadDotted notation + */ + @Test + public void testNetmaskLength() throws Exception { + testSingleNetmask(1, "128.0.0.0"); + testSingleNetmask(2, "192.0.0.0"); + testSingleNetmask(8, "255.0.0.0"); + testSingleNetmask(9, "255.128.0.0"); + testSingleNetmask(16, "255.255.0.0"); + testSingleNetmask(24, "255.255.255.0"); + } + + @Test + public void testNetmaskIllegal() throws Exception { + testSingleIllegalNetmask(""); + testSingleIllegalNetmask("."); + testSingleIllegalNetmask(".255"); + testSingleIllegalNetmask("255"); + testSingleIllegalNetmask("255."); + testSingleIllegalNetmask("255.255"); + testSingleIllegalNetmask("255.255.0"); + testSingleIllegalNetmask("255.255.255."); + testSingleIllegalNetmask("255.255.255.256"); + testSingleIllegalNetmask("0.0.0.0"); + testSingleIllegalNetmask("10.10.10.10"); + testSingleIllegalNetmask("255.1.255.0"); + testSingleIllegalNetmask("255.255.255.255"); + } +} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java index 0ab64b21e..e1b199ecc 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4AddressCustomizerTest.java @@ -30,6 +30,7 @@ import com.google.common.collect.ImmutableSet; import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest; import io.fd.hc2vpp.common.translate.util.Ipv4Translator; import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfacesstate.ip.v4.Ipv4AddressCustomizer; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; import io.fd.honeycomb.translate.util.read.cache.CacheKeyFactory; diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4CustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4CustomizerTest.java index 1bfb62771..9475d4664 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4CustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/Ipv4CustomizerTest.java @@ -18,8 +18,9 @@ package io.fd.hc2vpp.v3po.interfacesstate.ip; import static org.mockito.Mockito.verifyZeroInteractions; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; +import io.fd.hc2vpp.v3po.interfacesstate.ip.v4.Ipv4Customizer; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; import org.junit.Test; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface2Builder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4; diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizerTest.java index 8c67735aa..cfc7bc6dd 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizerTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/SubInterfaceIpv4AddressCustomizerTest.java @@ -32,6 +32,7 @@ import com.google.common.collect.ImmutableSet; import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest; import io.fd.hc2vpp.common.translate.util.Ipv4Translator; import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfacesstate.ip.v4.subinterface.SubInterfaceIpv4AddressCustomizer; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer; import io.fd.honeycomb.translate.util.read.cache.CacheKeyFactory; -- cgit 1.2.3-korg