diff options
Diffstat (limited to 'v3po/v3po2vpp')
57 files changed, 0 insertions, 5955 deletions
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 42e406eb1..06d6d290f 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 @@ -23,15 +23,6 @@ import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.hc2vpp.v3po.cfgattrs.V3poConfiguration; 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.ProxyArpWriterFactory; -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.VppHoneycombWriterFactory; @@ -83,25 +74,12 @@ public class V3poModule extends AbstractModule { // Expose disabled interfaces in operational data readerFactoryBinder.addBinding().to(DisabledInterfacesManager.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<WriterFactory> writerFactoryBinder = Multibinder.newSetBinder(binder(), WriterFactory.class); writerFactoryBinder.addBinding().to(InterfacesWriterFactory.class); - writerFactoryBinder.addBinding().to(ProxyArpWriterFactory.class); writerFactoryBinder.addBinding().to(SubinterfaceAugmentationWriterFactory.class); writerFactoryBinder.addBinding().to(VppHoneycombWriterFactory.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<ManagedNotificationProducer> notifiersBinder = Multibinder.newSetBinder(binder(), ManagedNotificationProducer.class); 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 deleted file mode 100644 index 159436671..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/Ipv4StateReaderFactory.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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<Interface2> 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<Ipv4> ipv4Id = IFC_2_ID.child(Ipv4.class); - registry.add(new GenericReader<>(ipv4Id, new Ipv4Customizer(jvpp))); - // Ipv4 Address - final InstanceIdentifier<Address> ipv4AddrId = ipv4Id.child(Address.class); - registry.add(new GenericInitListReader<>(ipv4AddrId, new Ipv4AddressCustomizer(jvpp, ifcNamingCtx))); - // Ipv4 Neighbor - final InstanceIdentifier<Neighbor> 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 deleted file mode 100644 index 5a2ac5a29..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/Ipv4WriterFactory.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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<Interface1> ifc1AugId = IFC_ID.augmentation(Interface1.class); - - // Ipv4(after interface) - final InstanceIdentifier<Ipv4> ipv4Id = ifc1AugId.child(Ipv4.class); - registry.addAfter(new GenericWriter<>(ipv4Id, new Ipv4Customizer(jvpp)), - IFC_ID); - // Address(after Ipv4) = - final InstanceIdentifier<Address> 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 deleted file mode 100644 index b1533dfae..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/Ipv6StateReaderFactory.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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.hc2vpp.v3po.interfacesstate.ip.v6.nd.NdProxyCustomizer; -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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.NdProxyIp6StateAugmentation; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.NdProxyIp6StateAugmentationBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces.state._interface.ipv6.NdProxies; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces.state._interface.ipv6.NdProxiesBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces.state._interface.ipv6.nd.proxies.NdProxy; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class Ipv6StateReaderFactory implements ReaderFactory { - - private static final InstanceIdentifier<Interface2> 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<Ipv6> ipv6Id = IFC_2_ID.child(Ipv6.class); - registry.add(new GenericReader<>(ipv6Id, new Ipv6Customizer(jvpp))); - // Ipv6 Address - final InstanceIdentifier<Address> ipv6AddrId = ipv6Id.child(Address.class); - registry.add(new GenericInitListReader<>(ipv6AddrId, new Ipv6AddressCustomizer(jvpp, ifcNamingCtx))); - // Ipv6 Neighbor - final InstanceIdentifier<Neighbor> neighborId = ipv6Id.child(Neighbor.class); - registry.add(new GenericListReader<>(neighborId, new Ipv6NeighbourCustomizer(jvpp, ifcNamingCtx))); - // NdProxyIp6StateAugmentation (Structural) - final InstanceIdentifier<NdProxyIp6StateAugmentation> ndAugId = ipv6Id.augmentation(NdProxyIp6StateAugmentation.class); - registry.addStructuralReader(ndAugId, NdProxyIp6StateAugmentationBuilder.class); - // NdProxies (Structural) - final InstanceIdentifier<NdProxies> ndProxiesId = ndAugId.child(NdProxies.class); - registry.addStructuralReader(ndProxiesId, NdProxiesBuilder.class); - // ND Proxy - final InstanceIdentifier<NdProxy> ndProxyId = ndProxiesId.child(NdProxy.class); - registry.addAfter(new GenericInitListReader<>(ndProxyId, new NdProxyCustomizer(jvpp, ifcNamingCtx)), ipv6AddrId); - } -} 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 deleted file mode 100644 index 9fbd6b9ba..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/Ipv6WriterFactory.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * 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.hc2vpp.v3po.interfaces.ip.v6.nd.NdProxyCustomizer; -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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.NdProxyIp6Augmentation; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces._interface.ipv6.NdProxies; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces._interface.ipv6.nd.proxies.NdProxy; -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<Interface1> ifc1AugId = IFC_ID.augmentation(Interface1.class); - - // Ipv6(after interface) = - final InstanceIdentifier<Ipv6> ipv6Id = ifc1AugId.child(Ipv6.class); - registry.addAfter(new GenericWriter<>(ipv6Id, new Ipv6Customizer(jvpp)), IFC_ID); - - final InstanceIdentifier<Address> - 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); - // ND Proxy - final InstanceIdentifier<NdProxy> ndProxyId = - ipv6Id.augmentation(NdProxyIp6Augmentation.class).child(NdProxies.class).child(NdProxy.class); - registry.addAfter(new GenericListWriter<>(ndProxyId, new NdProxyCustomizer(jvpp, ifcNamingContext)), ipv6Id); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/ProxyArpWriterFactory.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/ProxyArpWriterFactory.java deleted file mode 100644 index 489a3b5b9..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/ProxyArpWriterFactory.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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.common.collect.Sets; -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.ProxyArpCustomizer; -import io.fd.hc2vpp.v3po.interfaces.ip.v4.ProxyRangeCustomizer; -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 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.opendaylight.params.xml.ns.yang.vpp.proxy.arp.rev170315.ProxyArpInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.proxy.arp.rev170315.ProxyRanges; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.proxy.arp.rev170315.interfaces._interface.ProxyArp; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.proxy.arp.rev170315.proxy.ranges.ProxyRange; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public final class ProxyArpWriterFactory implements WriterFactory { - - public static final InstanceIdentifier<ProxyRange> PROXY_RANGE_IID = - InstanceIdentifier.create(ProxyRanges.class).child(ProxyRange.class); - private static final InstanceIdentifier<Interface> - IFC_ID = InstanceIdentifier.create(Interfaces.class).child(Interface.class); - private static final InstanceIdentifier<ProxyArp> PROXY_ARP_IID = - IFC_ID.augmentation(ProxyArpInterfaceAugmentation.class).child(ProxyArp.class); - - private final FutureJVppCore jvpp; - private final NamingContext ifcNamingContext; - - @Inject - public ProxyArpWriterFactory(final FutureJVppCore vppJvppIfcDependency, - @Named("interface-context") final NamingContext interfaceContextDependency) { - this.jvpp = vppJvppIfcDependency; - this.ifcNamingContext = interfaceContextDependency; - } - - @Override - public void init(final ModifiableWriterRegistryBuilder registry) { - // proxy-arp - // proxy-range = - registry.add(new GenericListWriter<>(PROXY_RANGE_IID, new ProxyRangeCustomizer(jvpp))); - - // interfaces - // interface - // proxy-arp-interface-augmentation - // proxy-arp = - registry.addAfter(new GenericWriter<>(PROXY_ARP_IID, new ProxyArpCustomizer(jvpp, ifcNamingContext)), - Sets.newHashSet(PROXY_RANGE_IID, IFC_ID)); - } -} 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 deleted file mode 100644 index 208866c16..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubInterfaceIpv4WriterFactory.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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<Rewrite> rewriteId = L2_ID.child(Rewrite.class); - - // Ipv4(handled after L2 and L2/rewrite is done) = - final InstanceIdentifier<Address> ipv4SubifcAddressId = SUB_IFC_ID.child(Ipv4.class).child(Address.class); - registry.addAfter(new GenericListWriter<>(ipv4SubifcAddressId, - new SubInterfaceIpv4AddressCustomizer(jvpp, ifcNamingContext)), rewriteId); - final InstanceIdentifier<Neighbor> 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 deleted file mode 100644 index 600a991fb..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubInterfaceIpv6WriterFactory.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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<Rewrite> rewriteId = L2_ID.child(Rewrite.class); - - // Ipv6 - final InstanceIdentifier<Address> - 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<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip6.attributes.ipv6.Neighbor> - 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 deleted file mode 100644 index 920006df6..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubInterfaceStateIpv4ReaderFactory.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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<SubInterface> subIfcId = - InterfacesStateReaderFactory.IFC_ID.augmentation(SubinterfaceStateAugmentation.class) - .child(SubInterfaces.class).child(SubInterface.class); - - // Ipv4(Structural) - final InstanceIdentifier<Ipv4> 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 deleted file mode 100644 index fc5283213..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubInterfaceStateIpv6ReaderFactory.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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<SubInterface> subIfcId = - InterfacesStateReaderFactory.IFC_ID.augmentation(SubinterfaceStateAugmentation.class) - .child(SubInterfaces.class).child(SubInterface.class); - - // Ipv6(Structural) - final InstanceIdentifier<Ipv6> 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/interfaces/ip/IpWriter.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/IpWriter.java deleted file mode 100644 index 795dc4587..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/IpWriter.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.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<SwInterfaceAddDelAddressReply> 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<SwInterfaceAddDelAddressReply> 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<IpNeighborAddDel> 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/v4/Ipv4AddressCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/Ipv4AddressCustomizer.java deleted file mode 100644 index d6cc6a00f..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/Ipv4AddressCustomizer.java +++ /dev/null @@ -1,130 +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.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.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<Address, AddressKey>, IpWriter { - - private static final Logger LOG = LoggerFactory.getLogger(Ipv4AddressCustomizer.class); - private final NamingContext interfaceContext; - - public Ipv4AddressCustomizer(@Nonnull final FutureJVppCore futureJVppCore, - @Nonnull final NamingContext interfaceContext) { - super(futureJVppCore); - this.interfaceContext = checkNotNull(interfaceContext, "Interface context cannot be null"); - } - - @Override - public void writeCurrentAttributes(InstanceIdentifier<Address> id, Address dataAfter, WriteContext writeContext) - throws WriteFailedException { - - final String interfaceName = id.firstKeyOf(Interface.class).getName(); - final int interfaceIndex = interfaceContext.getIndex(interfaceName, writeContext.getMappingContext()); - // TODO - HC2VPP-92 - Add more descriptive exception handling after https://jira.fd.io/browse/VPP-649 - setAddress(true, id, interfaceName, interfaceIndex, dataAfter, writeContext); - } - - @Override - public void updateCurrentAttributes(InstanceIdentifier<Address> 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<Address> 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<Address> 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<Address> 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<Address> 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 deleted file mode 100644 index 15afda271..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/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.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<Ipv4> { - - private static final Logger LOG = LoggerFactory.getLogger(Ipv4Customizer.class); - - public Ipv4Customizer(final FutureJVppCore vppApi) { - super(vppApi); - } - - @Override - public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Ipv4> 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<Ipv4> 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<Ipv4> 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 deleted file mode 100644 index b758a7c14..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/Ipv4NeighbourCustomizer.java +++ /dev/null @@ -1,100 +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.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<Neighbor, NeighborKey>, 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<Neighbor> 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<Neighbor> id, @Nonnull Neighbor dataBefore, - @Nonnull Neighbor dataAfter, - @Nonnull WriteContext writeContext) throws WriteFailedException { - throw new UnsupportedOperationException("Operation not supported"); - } - - @Override - public void deleteCurrentAttributes(@Nonnull InstanceIdentifier<Neighbor> 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/ProxyArpCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/ProxyArpCustomizer.java deleted file mode 100644 index a39b9852f..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/ProxyArpCustomizer.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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; - -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.spi.write.WriterCustomizer; -import io.fd.honeycomb.translate.write.WriteContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.vpp.jvpp.core.dto.ProxyArpIntfcEnableDisable; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.proxy.arp.rev170315.interfaces._interface.ProxyArp; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ProxyArpCustomizer extends FutureJVppCustomizer implements WriterCustomizer<ProxyArp>, JvppReplyConsumer { - - private static final Logger LOG = LoggerFactory.getLogger(ProxyArpCustomizer.class); - private final NamingContext interfaceContext; - - public ProxyArpCustomizer(final FutureJVppCore vppApi, final NamingContext interfaceContext) { - super(vppApi); - this.interfaceContext = interfaceContext; - } - - @Override - public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<ProxyArp> id, - @Nonnull final ProxyArp dataAfter, - @Nonnull final WriteContext writeContext) throws WriteFailedException { - final String swIfName = id.firstKeyOf(Interface.class).getName(); - final int swIfIndex = interfaceContext.getIndex(swIfName, writeContext.getMappingContext()); - final ProxyArpIntfcEnableDisable request = new ProxyArpIntfcEnableDisable(); - request.swIfIndex = swIfIndex; - request.enableDisable = 1; - getReplyForWrite(getFutureJVpp().proxyArpIntfcEnableDisable(request).toCompletableFuture(), id); - LOG.debug("Proxy ARP was successfully enabled on interface {} (id={})", swIfName, swIfIndex); - } - - @Override - public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<ProxyArp> id, - @Nonnull final ProxyArp dataBefore, - @Nonnull final ProxyArp dataAfter, @Nonnull final WriteContext writeContext) - throws WriteFailedException { - throw new WriteFailedException.UpdateFailedException(id, dataBefore, dataAfter, - new UnsupportedOperationException("Proxy ARP feature update is not supported.")); - } - - @Override - public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<ProxyArp> id, - @Nonnull final ProxyArp dataBefore, - @Nonnull final WriteContext writeContext) throws WriteFailedException { - final String swIfName = id.firstKeyOf(Interface.class).getName(); - final int swIfIndex = interfaceContext.getIndex(swIfName, writeContext.getMappingContext()); - final ProxyArpIntfcEnableDisable request = new ProxyArpIntfcEnableDisable(); - request.swIfIndex = swIfIndex; - request.enableDisable = 0; - getReplyForDelete(getFutureJVpp().proxyArpIntfcEnableDisable(request).toCompletableFuture(), id); - LOG.debug("Proxy ARP was successfully disabled on interface {} (id={})", swIfName, swIfIndex); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/ProxyRangeCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/ProxyRangeCustomizer.java deleted file mode 100644 index b46289fb4..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/ProxyRangeCustomizer.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * 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; - -import com.google.common.net.InetAddresses; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; -import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; -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.ProxyArpAddDel; -import io.fd.vpp.jvpp.core.dto.ProxyArpAddDelReply; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; -import java.net.InetAddress; -import java.util.concurrent.Future; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.proxy.arp.rev170315.proxy.ranges.ProxyRange; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.proxy.arp.rev170315.proxy.ranges.ProxyRangeKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ProxyRangeCustomizer extends FutureJVppCustomizer - implements ListWriterCustomizer<ProxyRange, ProxyRangeKey>, JvppReplyConsumer { - - private static final Logger LOG = LoggerFactory.getLogger(ProxyRangeCustomizer.class); - - public ProxyRangeCustomizer(final FutureJVppCore vppApi) { - super(vppApi); - } - - @Override - public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<ProxyRange> id, - @Nonnull final ProxyRange dataAfter, - @Nonnull final WriteContext writeContext) throws WriteFailedException { - LOG.debug("Adding range of proxy ARP addresses: {}", dataAfter); - createProxyArp(getProxyArpRequestFuture(dataAfter, (byte) 1 /* 1 is add */), id, dataAfter); - } - - @Override - public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<ProxyRange> id, - @Nonnull final ProxyRange dataBefore, - @Nonnull final ProxyRange dataAfter, @Nonnull final WriteContext writeContext) - throws WriteFailedException { - throw new WriteFailedException.UpdateFailedException(id, dataBefore, dataAfter, - new UnsupportedOperationException("ARP proxy range update is not supported")); - } - - @Override - public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<ProxyRange> id, - @Nonnull final ProxyRange dataBefore, - @Nonnull final WriteContext writeContext) throws WriteFailedException { - LOG.debug("Removing range of proxy ARP addresses: {}", dataBefore); - deleteProxyArp(getProxyArpRequestFuture(dataBefore, (byte) 0 /* 0 is delete */), id); - } - - private Future<ProxyArpAddDelReply> getProxyArpRequestFuture(ProxyRange proxyArp, byte operation) - throws WriteFailedException { - final InetAddress srcAddress = InetAddresses.forString(proxyArp.getLowAddr().getValue()); - final InetAddress dstAddress = InetAddresses.forString(proxyArp.getHighAddr().getValue()); - final int vrfId = proxyArp.getVrfId().intValue(); - return getFutureJVpp().proxyArpAddDel( - getProxyArpConfRequest(operation, srcAddress.getAddress(), dstAddress.getAddress(), vrfId)) - .toCompletableFuture(); - } - - private void createProxyArp(final Future<ProxyArpAddDelReply> future, - final InstanceIdentifier<ProxyRange> identifier, - final ProxyRange data) - throws WriteFailedException { - final ProxyArpAddDelReply reply = getReplyForCreate(future, identifier, data); - LOG.debug("Proxy ARP setting create successful, with reply context:", reply.context); - } - - private void deleteProxyArp(final Future<ProxyArpAddDelReply> future, - final InstanceIdentifier<ProxyRange> identifier) - throws WriteFailedException { - final ProxyArpAddDelReply reply = getReplyForDelete(future, identifier); - LOG.debug("Proxy ARP setting delete successful, with reply context:", reply.context); - } - - private static ProxyArpAddDel getProxyArpConfRequest(final byte isAdd, final byte[] lAddr, final byte[] hAddr, - final int vrfId) { - final ProxyArpAddDel proxyArpAddDel = new ProxyArpAddDel(); - proxyArpAddDel.isAdd = isAdd; - proxyArpAddDel.lowAddress = lAddr; - proxyArpAddDel.hiAddress = hAddr; - proxyArpAddDel.vrfId = vrfId; - return proxyArpAddDel; - } -} 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 deleted file mode 100644 index f6b8ead69..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/subinterface/SubInterfaceIpv4AddressCustomizer.java +++ /dev/null @@ -1,132 +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.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<Address, AddressKey>, 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<Address> id, Address dataAfter, WriteContext writeContext) - throws WriteFailedException { - setAddress(true, id, dataAfter, writeContext); - } - - @Override - public void updateCurrentAttributes(InstanceIdentifier<Address> 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<Address> id, Address dataBefore, WriteContext writeContext) - throws WriteFailedException { - setAddress(false, id, dataBefore, writeContext); - } - - private void setAddress(boolean add, final InstanceIdentifier<Address> 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<Address> 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<Address> 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<Address> 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 deleted file mode 100644 index d7f6f327a..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/subinterface/SubInterfaceIpv4NeighbourCustomizer.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * 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<Neighbor, NeighborKey>, 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<Neighbor> 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()); - // we don't have support for sub-interface routing, so not setting vrf - - return request; - }, getFutureJVpp()); - LOG.debug("Neighbour {} successfully written", id); - } - - @Override - public void updateCurrentAttributes(@Nonnull InstanceIdentifier<Neighbor> id, @Nonnull Neighbor dataBefore, - @Nonnull Neighbor dataAfter, - @Nonnull WriteContext writeContext) throws WriteFailedException { - throw new UnsupportedOperationException("Operation not supported"); - } - - @Override - public void deleteCurrentAttributes(@Nonnull InstanceIdentifier<Neighbor> 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.debug("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 deleted file mode 100644 index 6984c8df6..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/Ipv6AddressCustomizer.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * 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<Address, AddressKey>, 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<Address> 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<Address> 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<Address> 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 deleted file mode 100644 index 003af53ab..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/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.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<Ipv6> { - - private static final Logger LOG = LoggerFactory.getLogger(Ipv6Customizer.class); - - public Ipv6Customizer(final FutureJVppCore vppApi) { - super(vppApi); - } - - @Override - public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Ipv6> id, - @Nonnull final Ipv6 dataAfter, @Nonnull final WriteContext writeContext) { - LOG.warn("Unsupported, ignoring configuration {}", dataAfter); - } - - @Override - public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<Ipv6> 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<Ipv6> 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 deleted file mode 100644 index 2d94e653b..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/Ipv6NeighbourCustomizer.java +++ /dev/null @@ -1,115 +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.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<Neighbor, NeighborKey>, 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<Neighbor> 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.debug("Neighbour successfully written"); - } - - @Override - public void updateCurrentAttributes(@Nonnull InstanceIdentifier<Neighbor> id, @Nonnull Neighbor dataBefore, - @Nonnull Neighbor dataAfter, - @Nonnull WriteContext writeContext) throws WriteFailedException { - throw new UnsupportedOperationException("Operation not supported"); - } - - @Override - public void deleteCurrentAttributes(@Nonnull InstanceIdentifier<Neighbor> 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.debug("Neighbour {} successfully deleted", id); - } - - private void addDelNeighbourAndReply(InstanceIdentifier<Neighbor> 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; - getReplyForWrite(getFutureJVpp().ipNeighborAddDel(request).toCompletableFuture(), id); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/nd/NdProxyCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/nd/NdProxyCustomizer.java deleted file mode 100644 index ed3d82ca9..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/nd/NdProxyCustomizer.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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.nd; - -import static com.google.common.base.Preconditions.checkNotNull; - -import io.fd.hc2vpp.common.translate.util.AddressTranslator; -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.spi.write.ListWriterCustomizer; -import io.fd.honeycomb.translate.write.WriteContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.vpp.jvpp.core.dto.Ip6NdProxyAddDel; -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.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.nd.proxy.rev170315.interfaces._interface.ipv6.nd.proxies.NdProxy; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces._interface.ipv6.nd.proxies.NdProxyKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public final class NdProxyCustomizer extends FutureJVppCustomizer - implements ListWriterCustomizer<NdProxy, NdProxyKey>, AddressTranslator, JvppReplyConsumer { - - private static final Logger LOG = LoggerFactory.getLogger(NdProxyCustomizer.class); - private final NamingContext interfaceContext; - - public NdProxyCustomizer(@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<NdProxy> id, @Nonnull final NdProxy dataAfter, - @Nonnull final WriteContext writeContext) throws WriteFailedException { - final String interfaceName = id.firstKeyOf(Interface.class).getName(); - final int swIfIndex = interfaceContext.getIndex(interfaceName, writeContext.getMappingContext()); - addDelNdProxy(id, swIfIndex, dataAfter.getAddress(), true); - LOG.debug("ND proxy was successfully added for interface {}(id={}): {}", interfaceName, swIfIndex, dataAfter); - } - - @Override - public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<NdProxy> id, - @Nonnull final NdProxy dataBefore, @Nonnull final NdProxy dataAfter, - @Nonnull final WriteContext writeContext) throws WriteFailedException { - throw new WriteFailedException.UpdateFailedException(id, dataBefore, dataAfter, - new UnsupportedOperationException("NdProxy update is not supported.")); - } - - @Override - public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<NdProxy> id, - @Nonnull final NdProxy dataBefore, - @Nonnull final WriteContext writeContext) throws WriteFailedException { - final String interfaceName = id.firstKeyOf(Interface.class).getName(); - final int swIfIndex = interfaceContext.getIndex(interfaceName, writeContext.getMappingContext()); - addDelNdProxy(id, swIfIndex, dataBefore.getAddress(), false); - LOG.debug("ND proxy was successfully removed from interface {}(id={}): {}", interfaceName, swIfIndex, - dataBefore); - } - - private void addDelNdProxy(final InstanceIdentifier<NdProxy> id, final int swIfIndex, - final Ipv6AddressNoZone address, final boolean add) - throws WriteFailedException { - - final byte[] addressBytes = ipv6AddressNoZoneToArray(address); - - final Ip6NdProxyAddDel request = new Ip6NdProxyAddDel(); - request.swIfIndex = swIfIndex; - request.address = addressBytes; - request.isDel = booleanToByte(!add); - - getReplyForWrite(getFutureJVpp().ip6NdProxyAddDel(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 deleted file mode 100644 index 8348c8a25..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/subinterface/SubInterfaceIpv6AddressCustomizer.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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<Address, AddressKey>, 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<Address> id, Address dataAfter, WriteContext writeContext) - throws WriteFailedException { - setAddress(true, id, dataAfter, writeContext); - } - - @Override - public void updateCurrentAttributes(InstanceIdentifier<Address> 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<Address> id, Address dataBefore, WriteContext writeContext) - throws WriteFailedException { - setAddress(false, id, dataBefore, writeContext); - } - - private void setAddress(boolean add, - final InstanceIdentifier<Address> 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 deleted file mode 100644 index 00a0832a3..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/subinterface/SubInterfaceIpv6NeighbourCustomizer.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * 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<Neighbor, NeighborKey>, 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<Neighbor> 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()); - // we don't have support for sub-interface routing, so not setting vrf - - return request; - }, getFutureJVpp()); - LOG.debug("Neighbour {} successfully written", id); - } - - @Override - public void updateCurrentAttributes(@Nonnull InstanceIdentifier<Neighbor> id, @Nonnull Neighbor dataBefore, - @Nonnull Neighbor dataAfter, - @Nonnull WriteContext writeContext) throws WriteFailedException { - throw new UnsupportedOperationException("Operation not supported"); - } - - @Override - public void deleteCurrentAttributes(@Nonnull InstanceIdentifier<Neighbor> 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/dump/params/IfaceDumpFilter.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/dump/params/IfaceDumpFilter.java deleted file mode 100644 index ce57e34be..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/dump/params/IfaceDumpFilter.java +++ /dev/null @@ -1,62 +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 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 + - '}'; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - IfaceDumpFilter that = (IfaceDumpFilter) o; - - if (interfaceIndex != that.interfaceIndex) return false; - return isIpv6 == that.isIpv6; - } - - @Override - public int hashCode() { - int result = interfaceIndex; - result = 31 * result + (isIpv6 ? 1 : 0); - return result; - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/readers/IpAddressReader.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/readers/IpAddressReader.java deleted file mode 100644 index cb6228b33..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/readers/IpAddressReader.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * 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.readers; - -import com.google.common.base.Optional; -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.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.util.RWUtils; -import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; -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 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.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.yangtools.yang.binding.Identifier; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -import javax.annotation.Nonnull; -import java.util.Collections; -import java.util.List; -import java.util.function.Function; -import java.util.stream.Collectors; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Provides logic for reading of ip addresses - */ -public abstract class IpAddressReader extends IpReader { - - private final DumpCacheManager<IpAddressDetailsReplyDump, IfaceDumpFilter> dumpCacheManager; - - protected IpAddressReader(@Nonnull final NamingContext interfaceContext, final boolean isIpv6, - @Nonnull final DumpCacheManager<IpAddressDetailsReplyDump, IfaceDumpFilter> dumpCacheManager) { - super(interfaceContext, isIpv6); - this.dumpCacheManager = dumpCacheManager; - } - - @Nonnull - protected Optional<IpAddressDetailsReplyDump> interfaceAddressDumpSupplier(@Nonnull final InstanceIdentifier<?> id, - @Nonnull final ReadContext context) throws ReadFailedException { - return dumpCacheManager.getDump(id, context.getModificationCache(), new IfaceDumpFilter(getInterfaceContext() - .getIndex(id.firstKeyOf(Interface.class).getName(), context.getMappingContext()), isIpv6())); - } - - @Nonnull - protected Optional<IpAddressDetailsReplyDump> subInterfaceAddressDumpSupplier(@Nonnull final InstanceIdentifier<?> id, - @Nonnull final ReadContext context) throws ReadFailedException { - final String subInterfaceName = SubInterfaceUtils.getSubInterfaceName(id.firstKeyOf(Interface.class).getName(), - id.firstKeyOf(SubInterface.class).getIdentifier().intValue()); - return dumpCacheManager.getDump(id, context.getModificationCache(), new IfaceDumpFilter(getInterfaceContext() - .getIndex(subInterfaceName, context.getMappingContext()), isIpv6())); - } - - @Nonnull - protected <T extends Identifier> List<T> getAllIpv4AddressIds( - final Optional<IpAddressDetailsReplyDump> dumpOptional, - @Nonnull final Function<Ipv4AddressNoZone, T> 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 - protected <T extends Identifier> List<T> getAllIpv6AddressIds( - final Optional<IpAddressDetailsReplyDump> dumpOptional, - @Nonnull final Function<Ipv6AddressNoZone, T> 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(); - } - } - - @Nonnull - protected Optional<IpAddressDetails> findIpv4AddressDetailsByIp( - final Optional<IpAddressDetailsReplyDump> dump, - @Nonnull final Ipv4AddressNoZone ip) { - checkNotNull(ip, "ip address should not be null"); - - if (dump.isPresent() && dump.get().ipAddressDetails != null) { - final List<IpAddressDetails> details = dump.get().ipAddressDetails; - - return Optional.of(details.stream() - .filter(singleDetail -> ip.equals(arrayToIpv4AddressNoZone(singleDetail.ip))) - .collect(RWUtils.singleItemCollector())); - } - return Optional.absent(); - } - - @Nonnull - protected Optional<IpAddressDetails> findIpv6AddressDetailsByIp( - final Optional<IpAddressDetailsReplyDump> dump, - @Nonnull final Ipv6AddressNoZone ip) { - checkNotNull(ip, "ip address should not be null"); - - if (dump.isPresent() && dump.get().ipAddressDetails != null) { - final List<IpAddressDetails> details = dump.get().ipAddressDetails; - - return Optional.of(details.stream() - .filter(singleDetail -> ip.equals(arrayToIpv6AddressNoZone(singleDetail.ip))) - .collect(RWUtils.singleItemCollector())); - } - return Optional.absent(); - } - - @Nonnull - protected static EntityDumpExecutor<IpAddressDetailsReplyDump, IfaceDumpFilter> createAddressDumpExecutor( - @Nonnull final FutureJVppCore vppApi) { - return (identifier, params) -> { - checkNotNull(params, "Address dump params cannot be null"); - - final IpAddressDump dumpRequest = new IpAddressDump(); - dumpRequest.isIpv6 = ByteDataTranslator.INSTANCE.booleanToByte(params.isIpv6()); - dumpRequest.swIfIndex = params.getInterfaceIndex(); - - return JvppReplyConsumer.INSTANCE.getReplyForRead(vppApi.ipAddressDump(dumpRequest).toCompletableFuture(), identifier); - }; - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/readers/IpNeighbourReader.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/readers/IpNeighbourReader.java deleted file mode 100644 index 0acfb5b81..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/readers/IpNeighbourReader.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * 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.readers; - -import com.google.common.base.Optional; -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.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.util.read.cache.DumpCacheManager; -import io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor; -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 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.yangtools.yang.binding.Identifier; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -import javax.annotation.Nonnull; -import java.util.Collections; -import java.util.List; -import java.util.function.Function; -import java.util.stream.Collectors; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Provides logic for reading ip neighbours - */ -public abstract class IpNeighbourReader extends IpReader { - - private final DumpCacheManager<IpNeighborDetailsReplyDump, IfaceDumpFilter> dumpCacheManager; - - protected IpNeighbourReader(@Nonnull final NamingContext interfaceContext, boolean isIpv6, - @Nonnull final DumpCacheManager<IpNeighborDetailsReplyDump, IfaceDumpFilter> dumpCacheManager) { - super(interfaceContext, isIpv6); - this.dumpCacheManager = dumpCacheManager; - } - - @Nonnull - protected Optional<IpNeighborDetailsReplyDump> interfaceNeighboursDump(@Nonnull final InstanceIdentifier<?> id, - @Nonnull final ReadContext context) throws ReadFailedException { - return dumpCacheManager.getDump(id, context.getModificationCache(), new IfaceDumpFilter(getInterfaceContext() - .getIndex(id.firstKeyOf(Interface.class).getName(), context.getMappingContext()), isIpv6())); - } - - @Nonnull - protected Optional<IpNeighborDetailsReplyDump> subInterfaceNeighboursDump(@Nonnull final InstanceIdentifier<?> id, - @Nonnull final ReadContext context) throws ReadFailedException { - final String subInterfaceName = SubInterfaceUtils.getSubInterfaceName(id.firstKeyOf(Interface.class).getName(), - id.firstKeyOf(SubInterface.class).getIdentifier().intValue()); - return dumpCacheManager.getDump(id, context.getModificationCache(), new IfaceDumpFilter(getInterfaceContext() - .getIndex(subInterfaceName, context.getMappingContext()), isIpv6())); - } - - @Nonnull - protected static EntityDumpExecutor<IpNeighborDetailsReplyDump, IfaceDumpFilter> createNeighbourDumpExecutor( - @Nonnull final FutureJVppCore vppApi) { - return (identifier, params) -> { - checkNotNull(params, "Address dump params cannot be null"); - - final IpNeighborDump dumpRequest = new IpNeighborDump(); - dumpRequest.isIpv6 = ByteDataTranslator.INSTANCE.booleanToByte(params.isIpv6()); - dumpRequest.swIfIndex = params.getInterfaceIndex(); - - return JvppReplyConsumer.INSTANCE.getReplyForRead(vppApi.ipNeighborDump(dumpRequest).toCompletableFuture(), identifier); - }; - } - - @Nonnull - protected <T extends Identifier> List<T> getNeighborKeys( - final Optional<IpNeighborDetailsReplyDump> neighbourDumpOpt, - final Function<IpNeighborDetails, T> detailToKey) - throws ReadFailedException { - 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/readers/IpReader.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/readers/IpReader.java deleted file mode 100644 index 9003dbab7..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/readers/IpReader.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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.readers; - -import com.google.common.collect.ImmutableSet; -import io.fd.hc2vpp.common.translate.util.AddressTranslator; -import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.util.read.cache.CacheKeyFactory; -import io.fd.honeycomb.translate.util.read.cache.TypeAwareIdentifierCacheKeyFactory; -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 javax.annotation.Nonnull; - -/** - * Utility class providing Ipv4/6 read support. - */ -abstract class IpReader implements AddressTranslator, JvppReplyConsumer { - - private final NamingContext interfaceContext; - private final boolean isIpv6; - - IpReader(@Nonnull final NamingContext interfaceContext, final boolean isIpv6) { - this.interfaceContext = interfaceContext; - this.isIpv6 = isIpv6; - } - - @Nonnull - protected static CacheKeyFactory interfaceScopedCacheKeyFactory(@Nonnull final Class<?> dumpReplyClass) { - return new TypeAwareIdentifierCacheKeyFactory(dumpReplyClass, ImmutableSet.of(Interface.class)); - } - - @Nonnull - protected static CacheKeyFactory subInterfaceScopedCacheKeyFactory(@Nonnull final Class<?> dumpReplyClass) { - return new TypeAwareIdentifierCacheKeyFactory(dumpReplyClass, ImmutableSet.of(SubInterface.class)); - } - - protected NamingContext getInterfaceContext() { - return interfaceContext; - } - - protected boolean isIpv6() { - return 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 deleted file mode 100644 index aeaae5bdf..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/Ipv4AddressCustomizer.java +++ /dev/null @@ -1,145 +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.v4; - -import com.google.common.base.Optional; -import com.google.common.base.Preconditions; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.InterfaceCustomizer; -import io.fd.hc2vpp.v3po.interfacesstate.ip.dump.params.IfaceDumpFilter; -import io.fd.hc2vpp.v3po.interfacesstate.ip.readers.IpAddressReader; -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.DumpCacheManagerBuilder; -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 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; - -import javax.annotation.Nonnull; -import java.util.List; - -/** - * Read customizer for interface Ipv4 addresses. - */ -public class Ipv4AddressCustomizer extends IpAddressReader - implements InitializingListReaderCustomizer<Address, AddressKey, AddressBuilder> { - - private static final Logger LOG = LoggerFactory.getLogger(Ipv4AddressCustomizer.class); - - public Ipv4AddressCustomizer(@Nonnull final FutureJVppCore futureJVppCore, - @Nonnull final NamingContext interfaceContext) { - super(interfaceContext, false, new DumpCacheManagerBuilder<IpAddressDetailsReplyDump, IfaceDumpFilter>() - .withExecutor(createAddressDumpExecutor(futureJVppCore)) - // Key needs to contain interface ID to distinguish dumps between interfaces - .withCacheKeyFactory(interfaceScopedCacheKeyFactory(IpAddressDetailsReplyDump.class)) - .build()); - } - - @Override - @Nonnull - public AddressBuilder getBuilder(@Nonnull InstanceIdentifier<Address> id) { - return new AddressBuilder(); - } - - @Override - public void readCurrentAttributes(@Nonnull InstanceIdentifier<Address> id, @Nonnull AddressBuilder builder, - @Nonnull ReadContext ctx) throws ReadFailedException { - LOG.debug("Reading attributes for interface address: {}", id); - final Optional<IpAddressDetailsReplyDump> dumpOptional = interfaceAddressDumpSupplier(id, ctx); - - if (!dumpOptional.isPresent() || dumpOptional.get().ipAddressDetails.isEmpty()) { - return; - } - final Optional<IpAddressDetails> 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()) { - final String interfaceName = id.firstKeyOf(Interface.class).getName(); - final int interfaceIndex = getInterfaceContext().getIndex(interfaceName, ctx.getMappingContext()); - LOG.debug("Attributes for {} interface (id={}) address {} successfully read: {}", - interfaceName, interfaceIndex, id, builder.build()); - } - } - } - - @Override - public List<AddressKey> getAllIds(@Nonnull InstanceIdentifier<Address> id, @Nonnull ReadContext ctx) - throws ReadFailedException { - LOG.debug("Reading list of keys for interface addresses: {}", id); - return getAllIpv4AddressIds(interfaceAddressDumpSupplier(id, ctx), AddressKey::new); - } - - @Override - public void merge(@Nonnull Builder<? extends DataObject> builder, @Nonnull List<Address> readData) { - ((Ipv4Builder) builder).setAddress(readData); - } - - @Override - public Initialized<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address> init( - @Nonnull final InstanceIdentifier<Address> 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<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.Address> getCfgId( - final InstanceIdentifier<Address> 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 deleted file mode 100644 index ef8813ae5..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/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.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<Ipv4, Ipv4Builder> { - - private static final Logger LOG = LoggerFactory.getLogger(Ipv4Customizer.class); - - public Ipv4Customizer(@Nonnull final FutureJVppCore futureJVppCore) { - super(futureJVppCore); - } - - @Override - public void merge(@Nonnull final Builder<? extends DataObject> parentBuilder, @Nonnull final Ipv4 readValue) { - ((Interface2Builder) parentBuilder).setIpv4(readValue); - } - - @Nonnull - @Override - public Ipv4Builder getBuilder(@Nonnull final InstanceIdentifier<Ipv4> id) { - return new Ipv4Builder(); - } - - @Override - public void readCurrentAttributes(@Nonnull final InstanceIdentifier<Ipv4> 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 deleted file mode 100644 index c4eb7fd30..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/Ipv4NeighbourCustomizer.java +++ /dev/null @@ -1,103 +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.v4; - -import com.google.common.base.Optional; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.ip.dump.params.IfaceDumpFilter; -import io.fd.hc2vpp.v3po.interfacesstate.ip.readers.IpNeighbourReader; -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.DumpCacheManagerBuilder; -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 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.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 javax.annotation.Nonnull; -import java.util.List; -import java.util.function.Function; - -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; - -/** - * Operational data read operation customizer for {@link Neighbor}<br> - * Currently not supported in jvpp, so this is only dummy implementation<br> - */ -public class Ipv4NeighbourCustomizer extends IpNeighbourReader - implements ListReaderCustomizer<Neighbor, NeighborKey, NeighborBuilder> { - - public Ipv4NeighbourCustomizer(@Nonnull final FutureJVppCore futureJVppCore, - @Nonnull final NamingContext interfaceContext) { - super(interfaceContext, false, new DumpCacheManagerBuilder<IpNeighborDetailsReplyDump, IfaceDumpFilter>() - .withExecutor(createNeighbourDumpExecutor(futureJVppCore)) - // cached with parent interface scope - .withCacheKeyFactory(interfaceScopedCacheKeyFactory(IpNeighborDetailsReplyDump.class)) - .build()); - } - - @Override - public NeighborBuilder getBuilder(InstanceIdentifier<Neighbor> id) { - return new NeighborBuilder(); - } - - @Override - public void readCurrentAttributes(InstanceIdentifier<Neighbor> id, NeighborBuilder builder, ReadContext ctx) - throws ReadFailedException { - - final Ipv4AddressNoZone ip = id.firstKeyOf(Neighbor.class).getIp(); - - final Optional<IpNeighborDetailsReplyDump> dumpOpt = interfaceNeighboursDump(id, ctx); - - 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<NeighborKey> getAllIds(InstanceIdentifier<Neighbor> id, ReadContext context) - throws ReadFailedException { - return getNeighborKeys(interfaceNeighboursDump(id, context), keyMapper()); - } - - @Override - public void merge(Builder<? extends DataObject> builder, List<Neighbor> readData) { - ((Ipv4Builder) builder).setNeighbor(readData); - } - - private Function<IpNeighborDetails, NeighborKey> keyMapper() { - return ipNeighborDetails -> new NeighborKey(arrayToIpv4AddressNoZone(ipNeighborDetails.ipAddress)); - } -}
\ 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 deleted file mode 100644 index 55fd6ca3a..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/subinterface/SubInterfaceIpv4AddressCustomizer.java +++ /dev/null @@ -1,127 +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.v4.subinterface; - -import com.google.common.base.Optional; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.SubInterfaceCustomizer; -import io.fd.hc2vpp.v3po.interfacesstate.ip.dump.params.IfaceDumpFilter; -import io.fd.hc2vpp.v3po.interfacesstate.ip.readers.IpAddressReader; -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.vpp.jvpp.core.dto.IpAddressDetails; -import io.fd.vpp.jvpp.core.dto.IpAddressDetailsReplyDump; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; -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; - -import javax.annotation.Nonnull; -import java.util.List; - -/** - * Read customizer for sub-interface Ipv4 addresses. - */ -public class SubInterfaceIpv4AddressCustomizer extends IpAddressReader - implements InitializingListReaderCustomizer<Address, AddressKey, AddressBuilder> { - - private static final Logger LOG = LoggerFactory.getLogger(SubInterfaceIpv4AddressCustomizer.class); - - public SubInterfaceIpv4AddressCustomizer(@Nonnull final FutureJVppCore futureJVppCore, - @Nonnull final NamingContext interfaceContext) { - super(interfaceContext, false, new DumpCacheManager.DumpCacheManagerBuilder<IpAddressDetailsReplyDump, IfaceDumpFilter>() - .withExecutor(createAddressDumpExecutor(futureJVppCore)) - //same as with ipv4 addresses for interfaces, these must have cache scope of their parent sub-interface - .withCacheKeyFactory(subInterfaceScopedCacheKeyFactory(IpAddressDetailsReplyDump.class)) - .build()); - } - - private static String getSubInterfaceName(@Nonnull final InstanceIdentifier<Address> id) { - return SubInterfaceUtils.getSubInterfaceName(id.firstKeyOf(Interface.class).getName(), - Math.toIntExact(id.firstKeyOf(SubInterface.class).getIdentifier())); - } - - @Override - @Nonnull - public AddressBuilder getBuilder(@Nonnull InstanceIdentifier<Address> id) { - return new AddressBuilder(); - } - - @Override - public void readCurrentAttributes(@Nonnull InstanceIdentifier<Address> id, @Nonnull AddressBuilder builder, - @Nonnull ReadContext ctx) - throws ReadFailedException { - LOG.debug("Reading attributes for sub-interface address: {}", id); - - final Optional<IpAddressDetails> ipAddressDetails = - findIpv4AddressDetailsByIp(subInterfaceAddressDumpSupplier(id, ctx), 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()) { - final String subInterfaceName = getSubInterfaceName(id); - final int subInterfaceIndex = getInterfaceContext().getIndex(subInterfaceName, ctx.getMappingContext()); - LOG.debug("Attributes for {} sub-interface (id={}) address {} successfully read: {}", - subInterfaceName, subInterfaceIndex, id, builder.build()); - } - } - } - - @Override - @Nonnull - public List<AddressKey> getAllIds(@Nonnull InstanceIdentifier<Address> id, @Nonnull ReadContext ctx) - throws ReadFailedException { - LOG.debug("Reading list of keys for sub-interface addresses: {}", id); - return getAllIpv4AddressIds(subInterfaceAddressDumpSupplier(id, ctx), AddressKey::new); - } - - @Override - public void merge(@Nonnull Builder<? extends DataObject> builder, @Nonnull List<Address> readData) { - ((Ipv4Builder) builder).setAddress(readData); - } - - @Override - public Initialized<Address> init( - @Nonnull final InstanceIdentifier<Address> id, @Nonnull final Address readValue, - @Nonnull final ReadContext ctx) { - return Initialized.create(getCfgId(id), readValue); - } - - private InstanceIdentifier<Address> getCfgId(final InstanceIdentifier<Address> 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 deleted file mode 100644 index aaedabd9f..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/subinterface/SubInterfaceIpv4NeighbourCustomizer.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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 io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.ip.dump.params.IfaceDumpFilter; -import io.fd.hc2vpp.v3po.interfacesstate.ip.readers.IpNeighbourReader; -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.DumpCacheManagerBuilder; -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 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; -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; - -import javax.annotation.Nonnull; -import java.util.List; -import java.util.function.Function; - -public class SubInterfaceIpv4NeighbourCustomizer extends IpNeighbourReader - implements ListReaderCustomizer<Neighbor, NeighborKey, NeighborBuilder> { - - public SubInterfaceIpv4NeighbourCustomizer(@Nonnull final FutureJVppCore futureJVppCore, - @Nonnull final NamingContext interfaceContext) { - super(interfaceContext, false, new DumpCacheManagerBuilder<IpNeighborDetailsReplyDump, IfaceDumpFilter>() - .withExecutor(createNeighbourDumpExecutor(futureJVppCore)) - // cached with parent interface scope - .withCacheKeyFactory(subInterfaceScopedCacheKeyFactory(IpNeighborDetailsReplyDump.class)) - .build()); - } - - @Override - public NeighborBuilder getBuilder(InstanceIdentifier<Neighbor> id) { - return new NeighborBuilder(); - } - - @Override - public void readCurrentAttributes(InstanceIdentifier<Neighbor> id, NeighborBuilder builder, ReadContext ctx) - throws ReadFailedException { - - final Ipv4AddressNoZone ip = id.firstKeyOf(Neighbor.class).getIp(); - - final Optional<IpNeighborDetailsReplyDump> dumpOpt = subInterfaceNeighboursDump(id, ctx); - - 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<NeighborKey> getAllIds(InstanceIdentifier<Neighbor> id, ReadContext context) - throws ReadFailedException { - return getNeighborKeys(subInterfaceNeighboursDump(id, context), keyMapper()); - } - - @Override - public void merge(Builder<? extends DataObject> builder, List<Neighbor> readData) { - ((Ipv4Builder) builder).setNeighbor(readData); - } - - private Function<IpNeighborDetails, NeighborKey> keyMapper() { - return ipNeighborDetails -> new NeighborKey(arrayToIpv4AddressNoZone(ipNeighborDetails.ipAddress)); - } -}
\ 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 deleted file mode 100644 index 55ca35250..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/Ipv6AddressCustomizer.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * 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 com.google.common.base.Optional; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.InterfaceCustomizer; -import io.fd.hc2vpp.v3po.interfacesstate.ip.dump.params.IfaceDumpFilter; -import io.fd.hc2vpp.v3po.interfacesstate.ip.readers.IpAddressReader; -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.DumpCacheManagerBuilder; -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 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; - -import javax.annotation.Nonnull; -import java.util.List; - -public class Ipv6AddressCustomizer extends IpAddressReader - implements InitializingListReaderCustomizer<Address, AddressKey, AddressBuilder> { - - private static final Logger LOG = LoggerFactory.getLogger(Ipv6AddressCustomizer.class); - - public Ipv6AddressCustomizer(@Nonnull final FutureJVppCore futureJVppCore, - @Nonnull final NamingContext interfaceContext) { - super(interfaceContext, true, new DumpCacheManagerBuilder<IpAddressDetailsReplyDump, IfaceDumpFilter>() - .withExecutor(createAddressDumpExecutor(futureJVppCore)) - // Key needs to contain interface ID to distinguish dumps between interfaces - .withCacheKeyFactory(interfaceScopedCacheKeyFactory(IpAddressDetailsReplyDump.class)) - .build()); - } - - @Override - @Nonnull - public AddressBuilder getBuilder(@Nonnull InstanceIdentifier<Address> id) { - return new AddressBuilder(); - } - - @Override - public void readCurrentAttributes(@Nonnull InstanceIdentifier<Address> id, @Nonnull AddressBuilder builder, - @Nonnull ReadContext ctx) - throws ReadFailedException { - LOG.debug("Reading attributes for interface address: {}", id); - final Optional<IpAddressDetails> ipAddressDetails = - findIpv6AddressDetailsByIp(interfaceAddressDumpSupplier(id, ctx), 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()) { - final String interfaceName = id.firstKeyOf(Interface.class).getName(); - final int interfaceIndex = getInterfaceContext().getIndex(interfaceName, ctx.getMappingContext()); - LOG.debug("Attributes for {} interface (id={}) address {} successfully read: {}", - interfaceName, interfaceIndex, id, builder.build()); - } - } - } - - @Override - public List<AddressKey> getAllIds(@Nonnull InstanceIdentifier<Address> id, @Nonnull ReadContext ctx) - throws ReadFailedException { - LOG.debug("Reading list of keys for interface addresses: {}", id); - return getAllIpv6AddressIds(interfaceAddressDumpSupplier(id, ctx), AddressKey::new); - } - - @Override - public void merge(@Nonnull Builder<? extends DataObject> builder, @Nonnull List<Address> readData) { - ((Ipv6Builder) builder).setAddress(readData); - } - - @Override - public Initialized<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv6.Address> init( - @Nonnull final InstanceIdentifier<Address> 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<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv6.Address> getCfgId( - final InstanceIdentifier<Address> 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 deleted file mode 100644 index 8f12619fd..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/Ipv6Customizer.java +++ /dev/null @@ -1,58 +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.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<Ipv6, Ipv6Builder> { - - private static final Logger LOG = LoggerFactory.getLogger(Ipv6Customizer.class); - - public Ipv6Customizer(@Nonnull final FutureJVppCore futureJVppCore) { - super(futureJVppCore); - } - - @Override - public void merge(@Nonnull final Builder<? extends DataObject> parentBuilder, @Nonnull final Ipv6 readValue) { - ((Interface2Builder) parentBuilder).setIpv6(readValue); - } - - @Nonnull - @Override - public Ipv6Builder getBuilder(@Nonnull final InstanceIdentifier<Ipv6> id) { - return new Ipv6Builder(); - } - - @Override - public void readCurrentAttributes(@Nonnull final InstanceIdentifier<Ipv6> 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 deleted file mode 100644 index de1b0ab5e..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/Ipv6NeighbourCustomizer.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * 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 com.google.common.base.Optional; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.ip.dump.params.IfaceDumpFilter; -import io.fd.hc2vpp.v3po.interfacesstate.ip.readers.IpNeighbourReader; -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.vpp.jvpp.core.dto.IpNeighborDetails; -import io.fd.vpp.jvpp.core.dto.IpNeighborDetailsReplyDump; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; -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.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; - -import javax.annotation.Nonnull; -import java.util.List; -import java.util.function.Function; - -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; - -public class Ipv6NeighbourCustomizer extends IpNeighbourReader - implements ListReaderCustomizer<Neighbor, NeighborKey, NeighborBuilder> { - - public Ipv6NeighbourCustomizer(@Nonnull final FutureJVppCore futureJVppCore, - @Nonnull final NamingContext interfaceContext) { - super(interfaceContext, true, new DumpCacheManager.DumpCacheManagerBuilder<IpNeighborDetailsReplyDump, IfaceDumpFilter>() - .withExecutor(createNeighbourDumpExecutor(futureJVppCore)) - // cached with parent interface scope - .withCacheKeyFactory(interfaceScopedCacheKeyFactory(IpNeighborDetailsReplyDump.class)) - .build()); - } - - @Override - public NeighborBuilder getBuilder(InstanceIdentifier<Neighbor> id) { - return new NeighborBuilder(); - } - - @Override - public void readCurrentAttributes(InstanceIdentifier<Neighbor> id, NeighborBuilder builder, ReadContext ctx) - throws ReadFailedException { - final Ipv6AddressNoZone ip = id.firstKeyOf(Neighbor.class).getIp(); - final Optional<IpNeighborDetailsReplyDump> dumpOpt = interfaceNeighboursDump(id, ctx); - - 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<NeighborKey> getAllIds(InstanceIdentifier<Neighbor> id, ReadContext context) - throws ReadFailedException { - return getNeighborKeys(interfaceNeighboursDump(id, context), keyMapper()); - } - - @Override - public void merge(Builder<? extends DataObject> builder, List<Neighbor> readData) { - ((Ipv6Builder) builder).setNeighbor(readData); - } - - private Function<IpNeighborDetails, NeighborKey> keyMapper() { - return ipNeighborDetails -> new NeighborKey(arrayToIpv6AddressNoZone(ipNeighborDetails.ipAddress)); - } -}
\ No newline at end of file diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/nd/NdProxyCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/nd/NdProxyCustomizer.java deleted file mode 100644 index 7ffde1dd4..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/nd/NdProxyCustomizer.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * 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.nd; - -import static com.google.common.base.Preconditions.checkNotNull; -import static io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor.NO_PARAMS; - -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.Ipv6Translator; -import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.InterfaceCustomizer; -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.vpp.jvpp.core.dto.Ip6NdProxyDetailsReplyDump; -import io.fd.vpp.jvpp.core.dto.Ip6NdProxyDump; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; -import java.util.Collections; -import java.util.List; -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.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.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.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.NdProxyIp6Augmentation; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces.state._interface.ipv6.NdProxiesBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces.state._interface.ipv6.nd.proxies.NdProxy; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces.state._interface.ipv6.nd.proxies.NdProxyBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces.state._interface.ipv6.nd.proxies.NdProxyKey; -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 final class NdProxyCustomizer extends FutureJVppCustomizer - implements InitializingListReaderCustomizer<NdProxy, NdProxyKey, NdProxyBuilder>, JvppReplyConsumer, - Ipv6Translator { - - private static final Logger LOG = LoggerFactory.getLogger(NdProxyCustomizer.class); - private final NamingContext interfaceContext; - private final DumpCacheManager<Ip6NdProxyDetailsReplyDump, Void> dumpManager; - - public NdProxyCustomizer(@Nonnull final FutureJVppCore futureJVppCore, - @Nonnull final NamingContext interfaceContext) { - super(futureJVppCore); - this.interfaceContext = checkNotNull(interfaceContext, "interfaceContext should not be null"); - dumpManager = new DumpCacheManager.DumpCacheManagerBuilder<Ip6NdProxyDetailsReplyDump, Void>() - .withExecutor((id, param) -> getReplyForRead( - getFutureJVpp().ip6NdProxyDump(new Ip6NdProxyDump()).toCompletableFuture(), id)) - .acceptOnly(Ip6NdProxyDetailsReplyDump.class) - .build(); - } - - @Nonnull - @Override - public List<NdProxyKey> getAllIds(@Nonnull final InstanceIdentifier<NdProxy> id, - @Nonnull final ReadContext context) throws ReadFailedException { - final String interfaceName = id.firstKeyOf(Interface.class).getName(); - final int swIfIndex = interfaceContext.getIndex(interfaceName, context.getMappingContext()); - LOG.debug("Reading NDProxies for interface {}(id={})", interfaceName, swIfIndex); - final Optional<Ip6NdProxyDetailsReplyDump> dump = - dumpManager.getDump(id, context.getModificationCache(), NO_PARAMS); - - if (!dump.isPresent() || dump.get().ip6NdProxyDetails.isEmpty()) { - return Collections.emptyList(); - } - - return dump.get().ip6NdProxyDetails.stream() - .filter(detail -> detail.swIfIndex == swIfIndex) - .map(detail -> new NdProxyKey(arrayToIpv6AddressNoZone(detail.address))) - .collect(Collectors.toList()); - } - - @Override - public void merge(@Nonnull final Builder<? extends DataObject> builder, @Nonnull final List<NdProxy> list) { - ((NdProxiesBuilder)builder).setNdProxy(list); - } - - @Nonnull - @Override - public NdProxyBuilder getBuilder(@Nonnull final InstanceIdentifier<NdProxy> instanceIdentifier) { - return new NdProxyBuilder(); - } - - @Override - public void readCurrentAttributes(@Nonnull final InstanceIdentifier<NdProxy> id, - @Nonnull final NdProxyBuilder builder, - @Nonnull final ReadContext context) - throws ReadFailedException { - // address is the only leaf and list key, so jvpp call is not needed: - builder.setAddress(id.firstKeyOf(NdProxy.class).getAddress()); - } - - @Nonnull - @Override - public Initialized<? extends DataObject> init(@Nonnull final InstanceIdentifier<NdProxy> id, - @Nonnull final NdProxy ndProxy, - @Nonnull final ReadContext readContext) { - return Initialized.create(getCfgId(id), - new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces._interface.ipv6.nd.proxies.NdProxyBuilder() - .setAddress(ndProxy.getAddress()) - .build()); - } - - @VisibleForTesting - protected static InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces._interface.ipv6.nd.proxies.NdProxy> getCfgId( - final InstanceIdentifier<NdProxy> id) { - final Ipv6AddressNoZone address = id.firstKeyOf(NdProxy.class).getAddress(); - return InterfaceCustomizer.getCfgId(RWUtils.cutId(id, Interface.class)) - .augmentation(Interface1.class).child(Ipv6.class).augmentation(NdProxyIp6Augmentation.class) - .child( - org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces._interface.ipv6.NdProxies.class) - .child( - org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces._interface.ipv6.nd.proxies.NdProxy.class, - new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces._interface.ipv6.nd.proxies.NdProxyKey( - address)); - } -} 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 deleted file mode 100644 index 1e4b62c87..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/subinterface/SubInterfaceIpv6AddressCustomizer.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * 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 io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.SubInterfaceCustomizer; -import io.fd.hc2vpp.v3po.interfacesstate.ip.dump.params.IfaceDumpFilter; -import io.fd.hc2vpp.v3po.interfacesstate.ip.readers.IpAddressReader; -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.vpp.jvpp.core.dto.IpAddressDetails; -import io.fd.vpp.jvpp.core.dto.IpAddressDetailsReplyDump; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; -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; - -import javax.annotation.Nonnull; -import java.util.List; - -public class SubInterfaceIpv6AddressCustomizer extends IpAddressReader - implements InitializingListReaderCustomizer<Address, AddressKey, AddressBuilder> { - - private static final Logger LOG = LoggerFactory.getLogger(SubInterfaceIpv6AddressCustomizer.class); - - public SubInterfaceIpv6AddressCustomizer(@Nonnull final FutureJVppCore futureJVppCore, - @Nonnull final NamingContext interfaceContext) { - super(interfaceContext, true, new DumpCacheManager.DumpCacheManagerBuilder<IpAddressDetailsReplyDump, IfaceDumpFilter>() - .withExecutor(createAddressDumpExecutor(futureJVppCore)) - .withCacheKeyFactory(subInterfaceScopedCacheKeyFactory(IpAddressDetailsReplyDump.class)) - .build()); - } - - private static String getSubInterfaceName(@Nonnull final InstanceIdentifier<Address> id) { - return SubInterfaceUtils.getSubInterfaceName(id.firstKeyOf(Interface.class).getName(), - Math.toIntExact(id.firstKeyOf(SubInterface.class).getIdentifier())); - } - - @Override - @Nonnull - public AddressBuilder getBuilder(@Nonnull InstanceIdentifier<Address> id) { - return new AddressBuilder(); - } - - @Override - public void readCurrentAttributes(@Nonnull InstanceIdentifier<Address> id, @Nonnull AddressBuilder builder, - @Nonnull ReadContext ctx) - throws ReadFailedException { - LOG.debug("Reading attributes for sub-interface address: {}", id); - final Optional<IpAddressDetails> ipAddressDetails = - findIpv6AddressDetailsByIp(subInterfaceAddressDumpSupplier(id, ctx), id.firstKeyOf(Address.class).getIp()); - - if (ipAddressDetails.isPresent()) { - final IpAddressDetails detail = ipAddressDetails.get(); - builder.setIp(arrayToIpv6AddressNoZone(detail.ip)); - builder.setPrefixLength((short) Byte.toUnsignedInt(detail.prefixLength)); - - if (LOG.isDebugEnabled()) { - final String subInterfaceName = getSubInterfaceName(id); - final int subInterfaceIndex = getInterfaceContext().getIndex(subInterfaceName, ctx.getMappingContext()); - LOG.debug("Attributes for {} sub-interface (id={}) address {} successfully read: {}", - subInterfaceName, subInterfaceIndex, id, builder.build()); - } - } - } - - @Override - @Nonnull - public List<AddressKey> getAllIds(@Nonnull InstanceIdentifier<Address> id, @Nonnull ReadContext ctx) - throws ReadFailedException { - LOG.debug("Reading list of keys for sub-interface addresses: {}", id); - return getAllIpv6AddressIds(subInterfaceAddressDumpSupplier(id, ctx), AddressKey::new); - } - - @Override - public void merge(@Nonnull Builder<? extends DataObject> builder, @Nonnull List<Address> readData) { - ((Ipv6Builder) builder).setAddress(readData); - } - - @Override - @Nonnull - public Initialized<Address> init( - @Nonnull final InstanceIdentifier<Address> id, @Nonnull final Address readValue, - @Nonnull final ReadContext ctx) { - return Initialized.create(getCfgId(id), readValue); - } - - private InstanceIdentifier<Address> getCfgId(final InstanceIdentifier<Address> 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 deleted file mode 100644 index a1b50680d..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/subinterface/SubInterfaceIpv6NeighbourCustomizer.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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 io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.v3po.interfacesstate.ip.dump.params.IfaceDumpFilter; -import io.fd.hc2vpp.v3po.interfacesstate.ip.readers.IpNeighbourReader; -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.DumpCacheManagerBuilder; -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 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone; -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; - -import javax.annotation.Nonnull; -import java.util.List; -import java.util.function.Function; - -public class SubInterfaceIpv6NeighbourCustomizer extends IpNeighbourReader - implements ListReaderCustomizer<Neighbor, NeighborKey, NeighborBuilder> { - - public SubInterfaceIpv6NeighbourCustomizer(@Nonnull final FutureJVppCore futureJVppCore, - @Nonnull final NamingContext interfaceContext) { - super(interfaceContext, true, new DumpCacheManagerBuilder<IpNeighborDetailsReplyDump, IfaceDumpFilter>() - .withExecutor(createNeighbourDumpExecutor(futureJVppCore)) - // cached with parent interface scope - .withCacheKeyFactory(subInterfaceScopedCacheKeyFactory(IpNeighborDetailsReplyDump.class)) - .build()); - } - - @Override - public NeighborBuilder getBuilder(InstanceIdentifier<Neighbor> id) { - return new NeighborBuilder(); - } - - @Override - public void readCurrentAttributes(InstanceIdentifier<Neighbor> id, NeighborBuilder builder, ReadContext ctx) - throws ReadFailedException { - - final Ipv6AddressNoZone ip = id.firstKeyOf(Neighbor.class).getIp(); - - final Optional<IpNeighborDetailsReplyDump> dumpOpt = subInterfaceNeighboursDump(id, ctx); - - 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<NeighborKey> getAllIds(InstanceIdentifier<Neighbor> id, ReadContext context) - throws ReadFailedException { - return getNeighborKeys(subInterfaceNeighboursDump(id, context), keyMapper()); - } - - @Override - public void merge(Builder<? extends DataObject> builder, List<Neighbor> readData) { - ((Ipv6Builder) builder).setNeighbor(readData); - } - - private Function<IpNeighborDetails, NeighborKey> keyMapper() { - return ipNeighborDetails -> new NeighborKey(arrayToIpv6AddressNoZone(ipNeighborDetails.ipAddress)); - } -}
\ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ProxyArpCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ProxyArpCustomizerTest.java deleted file mode 100644 index 2e6d17b90..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ProxyArpCustomizerTest.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2017 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.hc2vpp.v3po.interfaces; - -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -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.ProxyArpCustomizer; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.vpp.jvpp.core.dto.ProxyArpIntfcEnableDisable; -import io.fd.vpp.jvpp.core.dto.ProxyArpIntfcEnableDisableReply; -import org.junit.Test; -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.opendaylight.params.xml.ns.yang.vpp.proxy.arp.rev170315.ProxyArpInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.proxy.arp.rev170315.interfaces._interface.ProxyArp; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class ProxyArpCustomizerTest extends WriterCustomizerTest implements ByteDataTranslator { - private static final String IF_NAME = "eth1"; - private static final int IF_INDEX = 42; - private static final String IFACE_CTX_NAME = "ifc-test-instance"; - - private static final InstanceIdentifier<ProxyArp> - IID = InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)) - .augmentation(ProxyArpInterfaceAugmentation.class).child(ProxyArp.class); - - private ProxyArpCustomizer customizer; - private ProxyArp data; - - @Override - public void setUpTest() throws Exception { - data = mock(ProxyArp.class); - customizer = new ProxyArpCustomizer(api, new NamingContext("ifacePrefix", IFACE_CTX_NAME)); - defineMapping(mappingContext, IF_NAME, IF_INDEX, IFACE_CTX_NAME); - } - - @Test - public void testWrite() throws WriteFailedException { - when(api.proxyArpIntfcEnableDisable(any())).thenReturn(future(new ProxyArpIntfcEnableDisableReply())); - customizer.writeCurrentAttributes(IID, data, writeContext); - verify(api).proxyArpIntfcEnableDisable(expectedEnableRequest(true)); - } - - @Test(expected = WriteFailedException.class) - public void testWriteFailed() throws WriteFailedException { - when(api.proxyArpIntfcEnableDisable(any())).thenReturn(failedFuture()); - customizer.writeCurrentAttributes(IID, data, writeContext); - } - - @Test(expected = WriteFailedException.UpdateFailedException.class) - public void testUpdate() throws WriteFailedException { - customizer.updateCurrentAttributes(IID, data, data, writeContext); - } - - @Test - public void testDelete() throws WriteFailedException { - when(api.proxyArpIntfcEnableDisable(any())).thenReturn(future(new ProxyArpIntfcEnableDisableReply())); - customizer.deleteCurrentAttributes(IID, data, writeContext); - verify(api).proxyArpIntfcEnableDisable(expectedEnableRequest(false)); - } - - @Test(expected = WriteFailedException.DeleteFailedException.class) - public void testDeleteFailed() throws WriteFailedException { - when(api.proxyArpIntfcEnableDisable(any())).thenReturn(failedFuture()); - customizer.deleteCurrentAttributes(IID, data, writeContext); - } - - private ProxyArpIntfcEnableDisable expectedEnableRequest(final boolean enable) { - final ProxyArpIntfcEnableDisable request = new ProxyArpIntfcEnableDisable(); - request.swIfIndex = IF_INDEX; - request.enableDisable = booleanToByte(enable); - return request; - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ProxyRangeCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ProxyRangeCustomizerTest.java deleted file mode 100644 index 9b4760916..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ProxyRangeCustomizerTest.java +++ /dev/null @@ -1,96 +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; - -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.verify; -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.v3po.interfaces.ip.v4.ProxyRangeCustomizer; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.vpp.jvpp.core.dto.ProxyArpAddDel; -import io.fd.vpp.jvpp.core.dto.ProxyArpAddDelReply; -import org.junit.Test; -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.opendaylight.params.xml.ns.yang.vpp.proxy.arp.rev170315.ProxyRanges; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.proxy.arp.rev170315.proxy.ranges.ProxyRange; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.proxy.arp.rev170315.proxy.ranges.ProxyRangeBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.proxy.arp.rev170315.proxy.ranges.ProxyRangeKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; - -public class ProxyRangeCustomizerTest extends WriterCustomizerTest implements ByteDataTranslator { - - private KeyedInstanceIdentifier<ProxyRange, ProxyRangeKey> IID; - private ProxyRange RANGE; - private ProxyRangeCustomizer customizer; - - @Override - public void setUpTest() throws Exception { - final Ipv4Address highAddr = new Ipv4AddressNoZone("10.1.1.2"); - final Ipv4Address lowAddr = new Ipv4AddressNoZone("10.1.1.1"); - final long vrfId = 123; - IID = InstanceIdentifier.create(ProxyRanges.class) - .child(ProxyRange.class, new ProxyRangeKey(highAddr, lowAddr, vrfId)); - RANGE = new ProxyRangeBuilder().setVrfId(vrfId).setHighAddr(highAddr).setLowAddr(new Ipv4AddressNoZone(lowAddr)) - .build(); - customizer = new ProxyRangeCustomizer(api); - } - - @Test - public void testWrite() throws WriteFailedException { - when(api.proxyArpAddDel(any())).thenReturn(future(new ProxyArpAddDelReply())); - customizer.writeCurrentAttributes(IID, RANGE, writeContext); - verify(api).proxyArpAddDel(expectedAddDelRequest(true)); - } - - @Test(expected = WriteFailedException.class) - public void testWriteFailed() throws WriteFailedException { - when(api.proxyArpAddDel(any())).thenReturn(failedFuture()); - customizer.writeCurrentAttributes(IID, RANGE, writeContext); - } - - @Test(expected = WriteFailedException.UpdateFailedException.class) - public void testUpdate() throws WriteFailedException { - customizer.updateCurrentAttributes(IID, RANGE, RANGE, writeContext); - } - - @Test - public void testDelete() throws WriteFailedException { - when(api.proxyArpAddDel(any())).thenReturn(future(new ProxyArpAddDelReply())); - customizer.deleteCurrentAttributes(IID, RANGE, writeContext); - verify(api).proxyArpAddDel(expectedAddDelRequest(false)); - } - - @Test(expected = WriteFailedException.DeleteFailedException.class) - public void testDeleteFailed() throws WriteFailedException { - when(api.proxyArpAddDel(any())).thenReturn(failedFuture()); - customizer.deleteCurrentAttributes(IID, RANGE, writeContext); - } - - private ProxyArpAddDel expectedAddDelRequest(final boolean isAdd) { - final ProxyArpAddDel request = new ProxyArpAddDel(); - request.isAdd = booleanToByte(isAdd); - request.vrfId = 123; - request.lowAddress = new byte[] {10, 1, 1, 1}; - request.hiAddress = new byte[] {10, 1, 1, 2}; - return request; - } -} 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 deleted file mode 100644 index 98ff8da64..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/SubInterfaceIpv4AddressCustomizerTest.java +++ /dev/null @@ -1,145 +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.Mockito.verify; -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; -import io.fd.vpp.jvpp.core.dto.SwInterfaceAddDelAddressReply; -import org.junit.Test; -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.yang.types.rev130715.DottedQuad; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.SubinterfaceAugmentation; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.interfaces._interface.SubInterfaces; -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; -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.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.NetmaskBuilder; -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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev161214.sub._interface.ip4.attributes.ipv4.address.subnet.PrefixLengthBuilder; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class SubInterfaceIpv4AddressCustomizerTest extends WriterCustomizerTest implements ByteDataTranslator { - - private static final String IFC_CTX_NAME = "ifc-test-instance"; - private static final String IFACE_NAME = "eth0"; - private static final int IFACE_INDEX = 0; - private static final String SUBIF_NAME = "eth0.1"; - private static final long SUBIF_ID = 1; - private static final int SUBIF_INDEX = 123; - private static final InstanceIdentifier<Address> IID = - InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IFACE_NAME)) - .augmentation(SubinterfaceAugmentation.class).child(SubInterfaces.class) - .child(SubInterface.class, new SubInterfaceKey(SUBIF_ID)).child(Ipv4.class).child(Address.class); - - private SubInterfaceIpv4AddressCustomizer customizer; - - @Override - protected void setUpTest() { - customizer = new SubInterfaceIpv4AddressCustomizer(api, new NamingContext("prefix", IFC_CTX_NAME)); - defineMapping(mappingContext, IFACE_NAME, IFACE_INDEX, IFC_CTX_NAME); - defineMapping(mappingContext, SUBIF_NAME, SUBIF_INDEX, IFC_CTX_NAME); - } - - @Test - public void testWrite() throws WriteFailedException { - when(api.swInterfaceAddDelAddress(any())).thenReturn(future(new SwInterfaceAddDelAddressReply())); - customizer.writeCurrentAttributes(IID, address(prefixLength()), writeContext); - verify(api).swInterfaceAddDelAddress(expectedRequest(true)); - } - - @Test - public void testWriteFailed() { - when(api.swInterfaceAddDelAddress(any())).thenReturn(failedFuture()); - try { - customizer.writeCurrentAttributes(IID, address(prefixLength()), writeContext); - } catch (WriteFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verify(api).swInterfaceAddDelAddress(expectedRequest(true)); - return; - } - fail("WriteFailedException expected"); - } - - @Test - public void testDelete() throws WriteFailedException { - when(api.swInterfaceAddDelAddress(any())).thenReturn(future(new SwInterfaceAddDelAddressReply())); - customizer.deleteCurrentAttributes(IID, address(netmask()), writeContext); - verify(api).swInterfaceAddDelAddress(expectedRequest(false)); - } - - @Test - public void testDeleteFailed() { - when(api.swInterfaceAddDelAddress(any())).thenReturn(failedFuture()); - try { - customizer.deleteCurrentAttributes(IID, address(netmask()), writeContext); - } catch (WriteFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verify(api).swInterfaceAddDelAddress(expectedRequest(false)); - return; - } - fail("WriteFailedException expected"); - } - - private SwInterfaceAddDelAddress expectedRequest(boolean isAdd) { - final SwInterfaceAddDelAddress request = new SwInterfaceAddDelAddress(); - request.isAdd = booleanToByte(isAdd); - request.swIfIndex = SUBIF_INDEX; - request.isIpv6 = 0; - request.delAll = 0; - request.addressLength = 24; - request.address = new byte[] {(byte) 192, (byte) 168, 2, 1}; - return request; - } - - @Test(expected = WriteFailedException.UpdateFailedException.class) - public void testUpdate() throws Exception { - final Address address = address(prefixLength()); - customizer.updateCurrentAttributes(IID, address, address, writeContext); - } - - private Address address(final Subnet subnet) { - final Ipv4AddressNoZone noZoneIp = new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1")); - return new AddressBuilder().setIp(noZoneIp).setSubnet(subnet).build(); - } - - private PrefixLength prefixLength() { - return new PrefixLengthBuilder().setPrefixLength(new Integer(24).shortValue()).build(); - } - - private Netmask netmask() { - return new NetmaskBuilder().setNetmask(new DottedQuad("255.255.255.0")).build(); - } -}
\ No newline at end of file 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 deleted file mode 100644 index ffae78ea8..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/Ipv4AddressCustomizerTest.java +++ /dev/null @@ -1,295 +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.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.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; - - private NamingContext interfaceContext; - private Ipv4AddressCustomizer customizer; - - private static InstanceIdentifier<Address> 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<InstanceIdentifier<?>> 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); - - doReturn(future(new IpAddressDetailsReplyDump())).when(api).ipAddressDump(any()); - } - - 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 { - final InstanceIdentifier<Address> 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<Address> 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(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<Address> 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<Address> 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<Address> 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<Address> 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<Address> 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/v4/Ipv4NeighbourCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/Ipv4NeighbourCustomizerTest.java deleted file mode 100644 index 3e5f969bd..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/v4/Ipv4NeighbourCustomizerTest.java +++ /dev/null @@ -1,155 +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.v4; - -import static junit.framework.TestCase.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -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.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; -import io.fd.vpp.jvpp.core.dto.IpNeighborAddDelReply; -import org.junit.Test; -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.InterfaceBuilder; -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.ipv4.Neighbor; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.ipv4.NeighborBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; -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.VppInterfaceAugmentationBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.RoutingBuilder; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class Ipv4NeighbourCustomizerTest extends WriterCustomizerTest implements Ipv4Translator { - - private static final String IFC_CTX_NAME = "ifc-test-instance"; - private static final String IFACE_NAME = "parent"; - private static final int IFACE_ID = 5; - private static final InstanceIdentifier<Neighbor> IID = - InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IFACE_NAME)) - .augmentation(Interface1.class).child(Ipv4.class).child(Neighbor.class); - - private Ipv4NeighbourCustomizer customizer; - - @Override - public void setUpTest() { - defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); - customizer = new Ipv4NeighbourCustomizer(api, new NamingContext("prefix", IFC_CTX_NAME)); - } - - @Test - public void testWriteCurrentAttributes() throws WriteFailedException { - when(writeContext.readBefore(IID.firstIdentifierOf(Interface.class))).thenReturn(Optional.absent()); - when(api.ipNeighborAddDel(any())).thenReturn(future(new IpNeighborAddDelReply())); - customizer.writeCurrentAttributes(IID, getData(), writeContext); - verify(api).ipNeighborAddDel(getExpectedRequest(true)); - } - - @Test - public void testWriteCurrentAttributesFailed() { - when(writeContext.readBefore(IID.firstIdentifierOf(Interface.class))).thenReturn(Optional.absent()); - when(api.ipNeighborAddDel(any())).thenReturn(failedFuture()); - try { - customizer.writeCurrentAttributes(IID, getData(), writeContext); - } catch (WriteFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verify(api).ipNeighborAddDel(getExpectedRequest(true)); - return; - } - fail("WriteFailedException expected"); - } - @Test(expected = UnsupportedOperationException.class) - public void testUpdateCurrentAttributes() throws WriteFailedException { - customizer.updateCurrentAttributes(IID, getData(), getData(), writeContext); - } - - @Test - public void testDeleteCurrentAttributes() throws WriteFailedException { - when(writeContext.readBefore(IID.firstIdentifierOf(Interface.class))).thenReturn(Optional.absent()); - when(api.ipNeighborAddDel(any())).thenReturn(future(new IpNeighborAddDelReply())); - customizer.deleteCurrentAttributes(IID, getData(), writeContext); - verify(api).ipNeighborAddDel(getExpectedRequest(false)); - } - - @Test - public void testDeleteCurrentAttributesFailed() { - when(writeContext.readBefore(IID.firstIdentifierOf(Interface.class))).thenReturn(Optional.absent()); - when(api.ipNeighborAddDel(any())).thenReturn(failedFuture()); - try { - customizer.deleteCurrentAttributes(IID, getData(), writeContext); - } catch (WriteFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verify(api).ipNeighborAddDel(getExpectedRequest(false)); - return; - } - fail("WriteFailedException expected"); - } - - @Test - public void testVrfExtractionCornerCases() throws WriteFailedException { - when(api.ipNeighborAddDel(any())).thenReturn(future(new IpNeighborAddDelReply())); - - when(writeContext.readBefore(IID.firstIdentifierOf(Interface.class))) - // no augment - .thenReturn(Optional.of(new InterfaceBuilder().build())) - // empty augment - .thenReturn(Optional.of(new InterfaceBuilder() - .addAugmentation(VppInterfaceAugmentation.class, new VppInterfaceAugmentationBuilder().build()).build())) - //empty routing - .thenReturn(Optional.of(new InterfaceBuilder() - .addAugmentation(VppInterfaceAugmentation.class, new VppInterfaceAugmentationBuilder() - .setRouting(new RoutingBuilder().build()) - .build()).build())); - - - customizer.writeCurrentAttributes(IID, getData(), writeContext); - customizer.writeCurrentAttributes(IID, getData(), writeContext); - customizer.writeCurrentAttributes(IID, getData(), writeContext); - verify(api, times(3)).ipNeighborAddDel(getExpectedRequest(true)); - } - - private Neighbor getData() { - final Ipv4AddressNoZone noZoneIp = new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1")); - final PhysAddress mac = new PhysAddress("aa:bb:cc:ee:11:22"); - return new NeighborBuilder().setIp(noZoneIp).setLinkLayerAddress(mac).build(); - } - private IpNeighborAddDel getExpectedRequest(final boolean isAdd) { - final IpNeighborAddDel request = new IpNeighborAddDel(); - request.isIpv6 = 0; - request.isAdd = booleanToByte(isAdd); - request.isStatic = 1; - request.dstAddress = new byte[] {(byte) 192, (byte) 168, 2, 1}; - request.macAddress = new byte[] {(byte) 0xaa, (byte) 0xbb, (byte) 0xcc, (byte) 0xee, 0x11, 0x22}; - request.swIfIndex = IFACE_ID; - return request; - } -}
\ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/Ipv6NeighbourCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/Ipv6NeighbourCustomizerTest.java deleted file mode 100644 index ca6bae56e..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/Ipv6NeighbourCustomizerTest.java +++ /dev/null @@ -1,154 +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.v6; - -import com.google.common.base.Optional; -import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; -import io.fd.hc2vpp.common.translate.util.Ipv6Translator; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.vpp.jvpp.VppBaseCallException; -import io.fd.vpp.jvpp.core.dto.IpNeighborAddDel; -import io.fd.vpp.jvpp.core.dto.IpNeighborAddDelReply; -import org.junit.Test; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address; -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; -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.InterfaceBuilder; -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.Ipv6; -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.NeighborBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; -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.VppInterfaceAugmentationBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.RoutingBuilder; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -import static junit.framework.TestCase.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; - -public class Ipv6NeighbourCustomizerTest extends WriterCustomizerTest implements Ipv6Translator { - - private static final String IFC_CTX_NAME = "ifc-test-instance"; - private static final String IFACE_NAME = "parent"; - private static final int IFACE_ID = 5; - private static final InstanceIdentifier<Neighbor> IID = - InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IFACE_NAME)) - .augmentation(Interface1.class).child(Ipv6.class).child(Neighbor.class); - - private Ipv6NeighbourCustomizer customizer; - - @Override - public void setUpTest() { - defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); - customizer = new Ipv6NeighbourCustomizer(api, new NamingContext("prefix", IFC_CTX_NAME)); - } - - @Test - public void testWriteCurrentAttributes() throws WriteFailedException { - when(writeContext.readBefore(IID.firstIdentifierOf(Interface.class))).thenReturn(Optional.absent()); - when(api.ipNeighborAddDel(any())).thenReturn(future(new IpNeighborAddDelReply())); - customizer.writeCurrentAttributes(IID, getData(), writeContext); - verify(api).ipNeighborAddDel(getExpectedRequest(true)); - } - - @Test - public void testWriteCurrentAttributesFailed() { - when(writeContext.readBefore(IID.firstIdentifierOf(Interface.class))).thenReturn(Optional.absent()); - when(api.ipNeighborAddDel(any())).thenReturn(failedFuture()); - try { - customizer.writeCurrentAttributes(IID, getData(), writeContext); - } catch (WriteFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verify(api).ipNeighborAddDel(getExpectedRequest(true)); - return; - } - fail("WriteFailedException expected"); - } - - @Test(expected = UnsupportedOperationException.class) - public void testUpdateCurrentAttributes() throws WriteFailedException { - customizer.updateCurrentAttributes(IID, getData(), getData(), writeContext); - } - - @Test - public void testDeleteCurrentAttributes() throws WriteFailedException { - when(writeContext.readBefore(IID.firstIdentifierOf(Interface.class))).thenReturn(Optional.absent()); - when(api.ipNeighborAddDel(any())).thenReturn(future(new IpNeighborAddDelReply())); - customizer.deleteCurrentAttributes(IID, getData(), writeContext); - verify(api).ipNeighborAddDel(getExpectedRequest(false)); - } - - @Test - public void testDeleteCurrentAttributesFailed() { - when(writeContext.readBefore(IID.firstIdentifierOf(Interface.class))).thenReturn(Optional.absent()); - when(api.ipNeighborAddDel(any())).thenReturn(failedFuture()); - try { - customizer.deleteCurrentAttributes(IID, getData(), writeContext); - } catch (WriteFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verify(api).ipNeighborAddDel(getExpectedRequest(false)); - return; - } - fail("WriteFailedException expected"); - } - - @Test - public void testVrfExtractionCornerCases() throws WriteFailedException { - when(api.ipNeighborAddDel(any())).thenReturn(future(new IpNeighborAddDelReply())); - - when(writeContext.readBefore(IID.firstIdentifierOf(Interface.class))) - // no augment - .thenReturn(Optional.of(new InterfaceBuilder().build())) - // empty augment - .thenReturn(Optional.of(new InterfaceBuilder() - .addAugmentation(VppInterfaceAugmentation.class, new VppInterfaceAugmentationBuilder().build()).build())) - //empty routing - .thenReturn(Optional.of(new InterfaceBuilder() - .addAugmentation(VppInterfaceAugmentation.class, new VppInterfaceAugmentationBuilder() - .setRouting(new RoutingBuilder().build()) - .build()).build())); - - - customizer.writeCurrentAttributes(IID, getData(), writeContext); - customizer.writeCurrentAttributes(IID, getData(), writeContext); - customizer.writeCurrentAttributes(IID, getData(), writeContext); - verify(api, times(3)).ipNeighborAddDel(getExpectedRequest(true)); - } - - private Neighbor getData() { - final Ipv6AddressNoZone noZoneIp = new Ipv6AddressNoZone(new Ipv6Address("2001:0db8:0a0b:12f0:0000:0000:0000:0001")); - final PhysAddress mac = new PhysAddress("aa:bb:cc:ee:11:22"); - return new NeighborBuilder().setIp(noZoneIp).setLinkLayerAddress(mac).build(); - } - - private IpNeighborAddDel getExpectedRequest(final boolean isAdd) { - final IpNeighborAddDel request = new IpNeighborAddDel(); - request.isIpv6 = 1; - request.isAdd = booleanToByte(isAdd); - request.isStatic = 1; - request.dstAddress = new byte[]{32, 1, 13, -72, 10, 11, 18, -16, 0, 0, 0, 0, 0, 0, 0, 1}; - request.macAddress = new byte[]{(byte) 0xaa, (byte) 0xbb, (byte) 0xcc, (byte) 0xee, 0x11, 0x22}; - request.swIfIndex = IFACE_ID; - return request; - } - -}
\ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/nd/NdProxyCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/nd/NdProxyCustomizerTest.java deleted file mode 100644 index 7d6fcb062..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/ip/v6/nd/NdProxyCustomizerTest.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * 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.nd; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.vpp.jvpp.core.dto.Ip6NdProxyAddDel; -import io.fd.vpp.jvpp.core.dto.Ip6NdProxyAddDelReply; -import org.junit.Test; -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; -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.Ipv6; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.NdProxyIp6Augmentation; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces._interface.ipv6.NdProxies; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces._interface.ipv6.nd.proxies.NdProxy; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces._interface.ipv6.nd.proxies.NdProxyBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces._interface.ipv6.nd.proxies.NdProxyKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class NdProxyCustomizerTest extends WriterCustomizerTest { - private static final String IF_NAME = "eth1"; - private static final InstanceIdentifier<NdProxies> ND_PROXIES_IID = - InstanceIdentifier.create(Interfaces.class).child(Interface.class, new InterfaceKey(IF_NAME)) - .augmentation(Interface1.class).child(Ipv6.class).augmentation(NdProxyIp6Augmentation.class) - .child(NdProxies.class); - private static final int IF_INDEX = 1; - - private static final String IFACE_CTX_NAME = "ifc-test-instance"; - - private NdProxyCustomizer customizer; - - @Override - protected void setUpTest() { - customizer = new NdProxyCustomizer(api, new NamingContext("ifacePrefix", IFACE_CTX_NAME)); - when(api.ip6NdProxyAddDel(any())).thenReturn(future(new Ip6NdProxyAddDelReply())); - defineMapping(mappingContext, IF_NAME, IF_INDEX, IFACE_CTX_NAME); - } - - @Test - public void testWrite() throws WriteFailedException { - final Ipv6AddressNoZone address = new Ipv6AddressNoZone("2001::1"); - final NdProxy data = new NdProxyBuilder().setAddress(address).build(); - customizer.writeCurrentAttributes(getId(address), data, writeContext); - final Ip6NdProxyAddDel request = new Ip6NdProxyAddDel(); - request.swIfIndex = IF_INDEX; - request.address = new byte[] {0x20, 0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01}; - verify(api).ip6NdProxyAddDel(request); - } - - @Test(expected = WriteFailedException.UpdateFailedException.class) - public void testUpdate() throws WriteFailedException { - final Ipv6AddressNoZone address = new Ipv6AddressNoZone("2001::2"); - final NdProxy data = new NdProxyBuilder().setAddress(address).build(); - customizer.updateCurrentAttributes(getId(address), mock(NdProxy.class), data, writeContext); - } - - @Test - public void testDelete() throws WriteFailedException { - final Ipv6AddressNoZone address = new Ipv6AddressNoZone("2001::3"); - final NdProxy data = new NdProxyBuilder().setAddress(address).build(); - customizer.deleteCurrentAttributes(getId(address), data, writeContext); - final Ip6NdProxyAddDel request = new Ip6NdProxyAddDel(); - request.isDel = 1; - request.swIfIndex = IF_INDEX; - request.address = new byte[] {0x20, 0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x03}; - verify(api).ip6NdProxyAddDel(request); - } - - private InstanceIdentifier<NdProxy> getId(final Ipv6AddressNoZone address) { - return ND_PROXIES_IID.child(NdProxy.class, new NdProxyKey(address)); - } -}
\ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/InterfaceChildNodeTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/InterfaceChildNodeTest.java deleted file mode 100644 index 4e323e45d..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/InterfaceChildNodeTest.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * 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 io.fd.hc2vpp.common.test.util.FutureProducer; -import io.fd.hc2vpp.common.test.util.NamingContextHelper; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.vpp.jvpp.core.dto.*; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; -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.yang.types.rev130715.PhysAddress; - -import javax.annotation.Nonnull; -import java.util.Arrays; -import java.util.List; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.hasSize; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.when; - -public interface InterfaceChildNodeTest extends NamingContextHelper, FutureProducer { - - String INTERFACE_CONTEXT_NAME = "iface-context"; - NamingContext INTERFACE_CONTEXT = new NamingContext("prefix", INTERFACE_CONTEXT_NAME); - - String IFACE_NAME = "eth0"; - int IFACE_ID = 1; - - String SUB_IFACE_NAME = "eth0.4"; - int SUB_IFACE_ID = 4; - - String IFACE_2_NAME = "eth1"; - int IFACE_2_ID = 2; - - String SUB_IFACE_2_NAME = "eth1.7"; - int SUB_IFACE_2_ID = 7; - - String IPV6_ONE_COMPRESSED = "2001:db8:a0b:12f0::1"; - byte[] IPV6_ONE_BYTES = {32, 1, 13, -72, 10, 11, 18, -16, 0, 0, 0, 0, 0, 0, 0, 1}; - byte IPV6_ONE_PREFIX = 64; - Ipv6AddressNoZone IPV6_ONE_ADDRESS_COMPRESSED = new Ipv6AddressNoZone(IPV6_ONE_COMPRESSED); - - String IPV6_TWO_COMPRESSED = "2001:db8:a0b:12f0::2"; - byte[] IPV6_TWO_BYTES = {32, 1, 13, -72, 10, 11, 18, -16, 0, 0, 0, 0, 0, 0, 0, 2}; - byte IPV6_TWO_PREFIX = 48; - Ipv6AddressNoZone IPV6_TWO_ADDRESS_COMPRESSED = new Ipv6AddressNoZone(IPV6_TWO_COMPRESSED); - - String IPV4_ONE = "192.168.2.1"; - byte[] IPV4_ONE_BYTES = {-64, -88, 2, 1}; - byte IPV4_ONE_PREFIX = 24; - Ipv4AddressNoZone IPV4_ONE_ADDRESS = new Ipv4AddressNoZone(IPV4_ONE); - - String IPV4_TWO = "192.168.2.2"; - byte[] IPV4_TWO_BYTES = {-64, -88, 2, 2}; - byte IPV4_TWO_PREFIX = 24; - Ipv4AddressNoZone IPV4_TWO_ADDRESS = new Ipv4AddressNoZone(IPV4_TWO); - - String MAC_ONE = "00:00:00:00:00:00"; - byte[] MAC_ONE_BYTES = {0, 0, 0, 0, 0, 0}; - PhysAddress MAC_ONE_ADDRESS = new PhysAddress(MAC_ONE); - - String MAC_TWO = "00:00:00:00:00:01"; - byte[] MAC_TWO_BYTES = {0, 0, 0, 0, 0, 1}; - PhysAddress MAC_TWO_ADDRESS = new PhysAddress(MAC_TWO); - - String MAC_THREE = "00:00:00:00:00:02"; - byte[] MAC_THREE_BYTES = {0, 0, 0, 0, 0, 2}; - PhysAddress MAC_THREE_ADDRESS = new PhysAddress(MAC_THREE); - - String MAC_FOUR = "00:00:00:00:00:03"; - byte[] MAC_FOUR_BYTES = {0, 0, 0, 0, 0, 3}; - PhysAddress MAC_FOUR_ADDRESS = new PhysAddress(MAC_FOUR); - - default void mockNeighborDump(@Nonnull final FutureJVppCore api, - @Nonnull final IpNeighborDump request, - @Nonnull final IpNeighborDetailsReplyDump reply) { - when(api.ipNeighborDump(request)).thenReturn(future(reply)); - } - - default void mockAddressDump(@Nonnull final FutureJVppCore api, - @Nonnull final IpAddressDump request, - @Nonnull final IpAddressDetailsReplyDump reply) { - when(api.ipAddressDump(request)).thenReturn(future(reply)); - } - - default IpAddressDump dumpV6AddressesIfaceTwo() { - IpAddressDump request = new IpAddressDump(); - request.isIpv6 = 1; - request.swIfIndex = IFACE_2_ID; - return request; - } - - default IpAddressDump dumpV6AddressesSubIfaceOne() { - IpAddressDump request = new IpAddressDump(); - request.swIfIndex = SUB_IFACE_ID; - request.isIpv6 = 1; - return request; - } - - - default IpNeighborDump dumpV4NeighborIfaceOne() { - IpNeighborDump request = new IpNeighborDump(); - request.swIfIndex = IFACE_ID; - request.isIpv6 = 0; - return request; - } - - default IpNeighborDump dumpV6NeighborsIfaceOne() { - IpNeighborDump request = new IpNeighborDump(); - request.swIfIndex = IFACE_ID; - request.isIpv6 = 1; - return request; - } - - default IpNeighborDump dumpV6NeighborsSubIfaceTwo() { - IpNeighborDump request = new IpNeighborDump(); - request.swIfIndex = SUB_IFACE_2_ID; - request.isIpv6 = 1; - return request; - } - - default IpNeighborDump dumpV4NeighborsSubIfaceOne() { - IpNeighborDump request = new IpNeighborDump(); - request.swIfIndex = SUB_IFACE_ID; - request.isIpv6 = 0; - return request; - } - - default void verifyList(@Nonnull final List<?> expected, @Nonnull final List<?> current) { - assertThat(current, hasSize(expected.size())); - assertTrue(expected.containsAll(current)); - } - - default IpNeighborDetailsReplyDump v4Neighbors() { - IpNeighborDetailsReplyDump fullDump = new IpNeighborDetailsReplyDump(); - fullDump.ipNeighborDetails = Arrays.asList( - neighborDump(IPV4_ONE_BYTES, 0, MAC_ONE_BYTES), - neighborDump(IPV4_TWO_BYTES, 0, MAC_TWO_BYTES)); - return fullDump; - } - - default IpNeighborDetailsReplyDump v6Neighbors() { - IpNeighborDetailsReplyDump fullDump = new IpNeighborDetailsReplyDump(); - fullDump.ipNeighborDetails = Arrays.asList( - neighborDump(IPV6_ONE_BYTES, 1, MAC_THREE_BYTES), - neighborDump(IPV6_TWO_BYTES, 1, MAC_FOUR_BYTES)); - return fullDump; - } - - default IpAddressDetailsReplyDump v4Addresses() { - IpAddressDetailsReplyDump fullDump = new IpAddressDetailsReplyDump(); - fullDump.ipAddressDetails = Arrays.asList( - addressDump(IPV4_ONE_BYTES, IPV4_ONE_PREFIX), - addressDump(IPV4_TWO_BYTES, IPV4_TWO_PREFIX)); - return fullDump; - } - - default IpAddressDetailsReplyDump v6Addresses() { - IpAddressDetailsReplyDump fullDump = new IpAddressDetailsReplyDump(); - fullDump.ipAddressDetails = Arrays.asList( - addressDump(IPV6_ONE_BYTES, IPV6_ONE_PREFIX), - addressDump(IPV6_TWO_BYTES, IPV6_TWO_PREFIX)); - return fullDump; - } - - static IpNeighborDetails neighborDump(byte[] address, int isIpv6, byte[] mac) { - IpNeighborDetails detail = new IpNeighborDetails(); - detail.ipAddress = address; - detail.isIpv6 = (byte) isIpv6; - detail.macAddress = mac; - return detail; - } - - static IpAddressDetails addressDump(byte[] address, byte prefix) { - IpAddressDetails details = new IpAddressDetails(); - details.ip = address; - details.prefixLength = prefix; - return details; - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/Ipv4AddressCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/Ipv4AddressCustomizerTest.java deleted file mode 100644 index 58077d6e9..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/Ipv4AddressCustomizerTest.java +++ /dev/null @@ -1,269 +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.v4; - - -import com.google.common.collect.ImmutableList; -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.InterfaceChildNodeTest; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.honeycomb.translate.util.read.cache.CacheKeyFactory; -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.dto.IpAddressDump; -import org.hamcrest.Matchers; -import org.junit.Test; -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.InterfacesState; -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.interfaces.rev140508.interfaces.state.InterfaceKey; -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.Ipv4; -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.PrefixLength; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.stream.Collectors; - -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; -import static org.mockito.Mockito.when; - -public class Ipv4AddressCustomizerTest extends ListReaderCustomizerTest<Address, AddressKey, AddressBuilder> implements - Ipv4Translator,InterfaceChildNodeTest { - - - private static final String IFC_CTX_NAME = "ifc-test-instance"; - - private NamingContext interfacesContext; - private InstanceIdentifier<Address> ifaceOneAddressOneIdentifier; - private InstanceIdentifier<Address> ifaceTwoAddressOneIdentifier; - private CacheKeyFactory cacheKeyFactory; - - public Ipv4AddressCustomizerTest() { - super(Address.class, Ipv4Builder.class); - } - - private static InstanceIdentifier<Address> getId(final String address, final String ifaceName) { - return InstanceIdentifier.builder(InterfacesState.class) - .child(Interface.class, new InterfaceKey(ifaceName)) - .augmentation(Interface2.class) - .child(Ipv4.class) - .child(Address.class, new AddressKey(new Ipv4AddressNoZone(new Ipv4Address(address)))) - .build(); - } - - @Override - public void setUp() { - interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); - defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); - defineMapping(mappingContext, IFACE_2_NAME, IFACE_2_ID, IFC_CTX_NAME); - - ifaceOneAddressOneIdentifier = - InstanceIdentifier.create(InterfacesState.class) - .child(Interface.class, new InterfaceKey(IFACE_NAME)) - .augmentation(Interface2.class) - .child(Ipv4.class) - .child(Address.class, new AddressKey(new Ipv4AddressNoZone("192.168.2.1"))); - ifaceTwoAddressOneIdentifier = - InstanceIdentifier.create(InterfacesState.class) - .child(Interface.class, new InterfaceKey(IFACE_2_NAME)) - .augmentation(Interface2.class) - .child(Ipv4.class) - .child(Address.class, new AddressKey(new Ipv4AddressNoZone("192.168.2.1"))); - - // to simulate complex key - cacheKeyFactory = new TypeAwareIdentifierCacheKeyFactory(IpAddressDetailsReplyDump.class, - ImmutableSet.of(Interface.class)); - } - - @Override - protected ReaderCustomizer<Address, AddressBuilder> initCustomizer() { - return new Ipv4AddressCustomizer(api, interfacesContext); - } - - @Test - public void testReadCurrentAttributesFor2Ifcs() throws ReadFailedException { - //changed to mock to not store first dumped data(otherwise that double thenReturn on line 118 is not gonna work) - - IpAddressDetails detail1 = new IpAddressDetails(); - IpAddressDetails detail2 = new IpAddressDetails(); - - detail1.ip = ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))); - detail2.ip = ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.2"))); - - IpAddressDetailsReplyDump reply = new IpAddressDetailsReplyDump(); - reply.ipAddressDetails = ImmutableList.of(detail1); - IpAddressDetailsReplyDump reply2 = new IpAddressDetailsReplyDump(); - reply2.ipAddressDetails = ImmutableList.of(detail2); - - CompletableFuture<IpAddressDetailsReplyDump> future = new CompletableFuture<>(); - future.complete(reply); - CompletableFuture<IpAddressDetailsReplyDump> future2 = new CompletableFuture<>(); - future2.complete(reply2); - - when(api.ipAddressDump(Mockito.any(IpAddressDump.class))).thenReturn(future).thenReturn(future2) - .thenReturn(future).thenReturn(future2); - when(api.ipAddressDump(Mockito.any(IpAddressDump.class))).thenReturn(future(reply)).thenReturn(future(reply2)) - .thenReturn(future(reply)).thenReturn(future(reply2)); - when(ctx.getModificationCache()).thenReturn(cache); - - - final InstanceIdentifier<Address> id = getId("192.168.2.1", IFACE_NAME); - final InstanceIdentifier<Address> id2 = getId("192.168.2.2", IFACE_2_NAME); - - final List<AddressKey> ifc1Ids = getCustomizer().getAllIds(id, ctx); - assertThat(ifc1Ids.size(), is(1)); - assertThat(ifc1Ids, Matchers.hasItem(new AddressKey(new Ipv4AddressNoZone("192.168.2.1")))); - final List<AddressKey> ifc2Ids = getCustomizer().getAllIds(id2, ctx); - assertThat(ifc2Ids.size(), is(1)); - assertThat(ifc2Ids, Matchers.hasItem(new AddressKey(new Ipv4AddressNoZone("192.168.2.2")))); - - AddressBuilder builder = new AddressBuilder(); - getCustomizer().readCurrentAttributes(id, builder, ctx); - assertEquals(builder.getIp().getValue(), "192.168.2.1"); - builder = new AddressBuilder(); - getCustomizer().readCurrentAttributes(id2, builder, ctx); - assertEquals(builder.getIp().getValue(), "192.168.2.2"); - } - - @Test - public void testReadCurrentAttributesSuccessfull() throws ReadFailedException { - IpAddressDetails detail1 = new IpAddressDetails(); - IpAddressDetails detail2 = new IpAddressDetails(); - IpAddressDetails detail3 = new IpAddressDetails(); - - detail1.ip = ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))); - detail2.ip = ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.2"))); - detail3.ip = ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.3"))); - - IpAddressDetailsReplyDump reply = new IpAddressDetailsReplyDump(); - reply.ipAddressDetails = ImmutableList.of(detail1, detail2, detail3); - when(api.ipAddressDump(Mockito.any(IpAddressDump.class))).thenReturn(future(reply)); - when(ctx.getModificationCache()).thenReturn(cache); - - final AddressBuilder builder = new AddressBuilder(); - final InstanceIdentifier<Address> id = getId("192.168.2.1", IFACE_NAME); - - getCustomizer().readCurrentAttributes(id, builder, ctx); - - assertEquals("192.168.2.1", builder.getIp().getValue()); - } - - @Test - public void testGetAllIdsFromSuccessfull() throws ReadFailedException { - IpAddressDetails detail1 = new IpAddressDetails(); - IpAddressDetails detail2 = new IpAddressDetails(); - IpAddressDetails detail3 = new IpAddressDetails(); - - detail1.ip = ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))); - detail2.ip = ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.2"))); - detail3.ip = ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.3"))); - - IpAddressDetailsReplyDump reply = new IpAddressDetailsReplyDump(); - reply.ipAddressDetails = ImmutableList.of(detail1, detail2, detail3); - when(api.ipAddressDump(Mockito.any(IpAddressDump.class))).thenReturn(future(reply)); - when(ctx.getModificationCache()).thenReturn(cache); - - final InstanceIdentifier<Address> id = getId("192.168.2.1", IFACE_NAME); - - List<Ipv4AddressNoZone> ids = getCustomizer().getAllIds(id, ctx).stream() - .map(key -> key.getIp()) - .collect(Collectors.toList()); - - assertEquals(3, ids.size()); - assertEquals(true, "192.168.2.1".equals(ids.get(0).getValue())); - assertEquals(true, "192.168.2.2".equals(ids.get(1).getValue())); - assertEquals(true, "192.168.2.3".equals(ids.get(2).getValue())); - } - - @Test - public void testCachingScopeSpecificRequest() throws ReadFailedException { - fillCacheForTwoIfaces(); - final AddressBuilder ifaceOneAddressBuilder = new AddressBuilder(); - final AddressBuilder ifaceTwoAddressBuilder = new AddressBuilder(); - - getCustomizer().readCurrentAttributes(ifaceOneAddressOneIdentifier, ifaceOneAddressBuilder, ctx); - getCustomizer().readCurrentAttributes(ifaceTwoAddressOneIdentifier, ifaceTwoAddressBuilder, ctx); - - // addresses have caching scope of parent interface, so returned address should have respective prefix lengths - assertEquals("192.168.2.1", ifaceOneAddressBuilder.getIp().getValue()); - assertTrue(ifaceOneAddressBuilder.getSubnet() instanceof PrefixLength); - assertEquals(22, PrefixLength.class.cast(ifaceOneAddressBuilder.getSubnet()).getPrefixLength().intValue()); - - assertEquals("192.168.2.1", ifaceTwoAddressBuilder.getIp().getValue()); - assertTrue(ifaceTwoAddressBuilder.getSubnet() instanceof PrefixLength); - assertEquals(23, PrefixLength.class.cast(ifaceTwoAddressBuilder.getSubnet()).getPrefixLength().intValue()); - } - - @Test - public void testCachingScopeGetAll() throws ReadFailedException { - fillCacheForFirstIfaceSecondEmpty(); - - final List<AddressKey> keysForIfaceOne = getCustomizer().getAllIds(ifaceOneAddressOneIdentifier, ctx); - assertThat(keysForIfaceOne, hasSize(1)); - final AddressKey keyIfaceOne = keysForIfaceOne.get(0); - assertEquals("192.168.2.1", keyIfaceOne.getIp().getValue()); - - final List<AddressKey> keysForIfaceTwo = getCustomizer().getAllIds(ifaceTwoAddressOneIdentifier, ctx); - assertThat(keysForIfaceTwo, is(empty())); - } - - private void fillCacheForTwoIfaces() { - IpAddressDetails detailIfaceOneAddressOne = new IpAddressDetails(); - IpAddressDetails detailIfaceTwoAddressOne = new IpAddressDetails(); - IpAddressDetailsReplyDump replyIfaceOne = new IpAddressDetailsReplyDump(); - IpAddressDetailsReplyDump replyIfaceTwo = new IpAddressDetailsReplyDump(); - - replyIfaceOne.ipAddressDetails = Arrays.asList(detailIfaceOneAddressOne); - replyIfaceTwo.ipAddressDetails = Arrays.asList(detailIfaceTwoAddressOne); - - detailIfaceOneAddressOne.ip = ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))); - detailIfaceOneAddressOne.prefixLength = 22; - - detailIfaceTwoAddressOne.ip = ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))); - detailIfaceTwoAddressOne.prefixLength = 23; - - cache.put(cacheKeyFactory.createKey(ifaceOneAddressOneIdentifier), replyIfaceOne); - cache.put(cacheKeyFactory.createKey(ifaceTwoAddressOneIdentifier), replyIfaceTwo); - } - - private void fillCacheForFirstIfaceSecondEmpty() { - IpAddressDetails detailIfaceOneAddressOne = new IpAddressDetails(); - IpAddressDetailsReplyDump replyIfaceOne = new IpAddressDetailsReplyDump(); - replyIfaceOne.ipAddressDetails = Arrays.asList(detailIfaceOneAddressOne); - - detailIfaceOneAddressOne.ip = ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))); - detailIfaceOneAddressOne.prefixLength = 22; - - cache.put(cacheKeyFactory.createKey(ifaceOneAddressOneIdentifier), replyIfaceOne); - cache.put(cacheKeyFactory.createKey(ifaceTwoAddressOneIdentifier), new IpAddressDetailsReplyDump()); - } -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/Ipv4CustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/Ipv4CustomizerTest.java deleted file mode 100644 index da2213027..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/Ipv4CustomizerTest.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.v4; - -import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; -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; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces.state._interface.Ipv4Builder; - -import static org.mockito.Mockito.verifyZeroInteractions; - -public class Ipv4CustomizerTest extends ReaderCustomizerTest<Ipv4, Ipv4Builder> { - - public Ipv4CustomizerTest() { - super(Ipv4.class, Interface2Builder.class); - } - - @Test - public void testReadCurrentAttributes() throws Exception { - customizer.readCurrentAttributes(null, null, ctx); - verifyZeroInteractions(api); - } - - @Override - protected ReaderCustomizer<Ipv4, Ipv4Builder> initCustomizer() { - return new Ipv4Customizer(api); - } -}
\ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/Ipv4NeighbourCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/Ipv4NeighbourCustomizerTest.java deleted file mode 100644 index d540dfa3b..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/Ipv4NeighbourCustomizerTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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; - -import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest; -import io.fd.hc2vpp.v3po.interfacesstate.ip.InterfaceChildNodeTest; -import io.fd.honeycomb.translate.read.ReadFailedException; -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.interfaces.rev140508.InterfacesState; -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.interfaces.rev140508.interfaces.state.InterfaceKey; -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.Ipv4; -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.yang.binding.InstanceIdentifier; - -import java.util.Arrays; - -import static org.junit.Assert.assertEquals; - -public class Ipv4NeighbourCustomizerTest extends ListReaderCustomizerTest<Neighbor, NeighborKey, NeighborBuilder> - implements InterfaceChildNodeTest { - - private InstanceIdentifier<Neighbor> instanceIdentifier; - - public Ipv4NeighbourCustomizerTest() { - super(Neighbor.class, Ipv4Builder.class); - } - - @Override - protected void setUp() throws Exception { - instanceIdentifier = InstanceIdentifier.create(InterfacesState.class) - .child(Interface.class, new InterfaceKey(IFACE_NAME)) - .augmentation(Interface2.class) - .child(Ipv4.class) - .child(Neighbor.class, new NeighborKey(IPV4_ONE_ADDRESS)); - defineMapping(mappingContext, IFACE_NAME, IFACE_ID, INTERFACE_CONTEXT_NAME); - mockNeighborDump(api, dumpV4NeighborIfaceOne(), v4Neighbors()); - } - - @Test - public void testGetAll() throws ReadFailedException { - verifyList(Arrays.asList(new NeighborKey(IPV4_ONE_ADDRESS), new NeighborKey(IPV4_TWO_ADDRESS)), - getCustomizer().getAllIds(instanceIdentifier, ctx)); - } - - @Test - public void readCurrent() throws ReadFailedException { - final NeighborBuilder builder = new NeighborBuilder(); - getCustomizer().readCurrentAttributes(instanceIdentifier, builder, ctx); - - assertEquals(IPV4_ONE_ADDRESS, builder.getIp()); - assertEquals(MAC_ONE_ADDRESS, builder.getLinkLayerAddress()); - } - - @Override - protected ReaderCustomizer<Neighbor, NeighborBuilder> initCustomizer() { - return new Ipv4NeighbourCustomizer(api, INTERFACE_CONTEXT); - } -}
\ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/subinterface/SubInterfaceIpv4AddressCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/subinterface/SubInterfaceIpv4AddressCustomizerTest.java deleted file mode 100644 index 736ff0031..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/subinterface/SubInterfaceIpv4AddressCustomizerTest.java +++ /dev/null @@ -1,235 +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.v4.subinterface; - -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.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer; -import io.fd.honeycomb.translate.util.read.cache.CacheKeyFactory; -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 org.junit.Assert; -import org.junit.Test; -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.InterfacesState; -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.interfaces.rev140508.interfaces.state.InterfaceKey; -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.interfaces.state._interface.sub.interfaces.SubInterfaceKey; -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.PrefixLength; -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.yang.binding.InstanceIdentifier; - -import java.util.Arrays; -import java.util.List; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.*; - -public class SubInterfaceIpv4AddressCustomizerTest extends ListReaderCustomizerTest<Address, AddressKey, AddressBuilder> - implements Ipv4Translator { - - private static final String IFC_CTX_NAME = "ifc-test-instance"; - private static final String IF_NAME = "local0"; - private static final int IF_INDEX = 1; - private static final String SUB_IF_NAME = "local0.1"; - private static final String SUB_IF_2_NAME = "local0.2"; - private static final long SUB_IF_ID = 1; - private static final int SUB_IF_INDEX = 11; - private static final int SUB_IF_2_INDEX = 12; - private static final InstanceIdentifier<Ipv4> IP4_IID = - InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(IF_NAME)) - .augmentation(SubinterfaceStateAugmentation.class) - .child(SubInterfaces.class).child(SubInterface.class, new SubInterfaceKey(SUB_IF_ID)) - .child(Ipv4.class); - private static final Ipv4AddressNoZone IP1 = new Ipv4AddressNoZone("10.1.1.1"); - private static final Ipv4AddressNoZone IP2 = new Ipv4AddressNoZone("10.1.1.2"); - private static final short PREFIX_LENGTH = 16; - private InstanceIdentifier<Address> ifaceOneAddressOneIdentifier; - private InstanceIdentifier<Address> ifaceTwoAddressOneIdentifier; - private CacheKeyFactory cacheKeyFactory; - private NamingContext interfaceContext; - - public SubInterfaceIpv4AddressCustomizerTest() { - super(Address.class, Ipv4Builder.class); - } - - private static InstanceIdentifier<Address> getId() { - return IP4_IID.child(Address.class); - } - - private static InstanceIdentifier<Address> getId(final Ipv4AddressNoZone ip) { - return IP4_IID.child(Address.class, new AddressKey(ip)); - } - - @Override - protected void setUp() throws Exception { - interfaceContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); - - ifaceOneAddressOneIdentifier = InstanceIdentifier.create(InterfacesState.class) - .child(Interface.class, new InterfaceKey(IF_NAME)) - .augmentation(SubinterfaceStateAugmentation.class) - .child(SubInterfaces.class) - .child(SubInterface.class, new SubInterfaceKey(1L)) - .child(Ipv4.class) - .child(Address.class, new AddressKey(new Ipv4AddressNoZone("192.168.2.1"))); - ifaceTwoAddressOneIdentifier = InstanceIdentifier.create(InterfacesState.class) - .child(Interface.class, new InterfaceKey(IF_NAME)) - .augmentation(SubinterfaceStateAugmentation.class) - .child(SubInterfaces.class) - .child(SubInterface.class, new SubInterfaceKey(2L)) - .child(Ipv4.class) - .child(Address.class, new AddressKey(new Ipv4AddressNoZone("192.168.2.1"))); - - // to simulate complex key - cacheKeyFactory = new TypeAwareIdentifierCacheKeyFactory(IpAddressDetailsReplyDump.class, - ImmutableSet.of(SubInterface.class)); - - defineMapping(mappingContext, IF_NAME, IF_INDEX, IFC_CTX_NAME); - defineMapping(mappingContext, SUB_IF_NAME, SUB_IF_INDEX, IFC_CTX_NAME); - defineMapping(mappingContext, SUB_IF_2_NAME, SUB_IF_2_INDEX, IFC_CTX_NAME); - } - - @Override - protected ListReaderCustomizer<Address, AddressKey, AddressBuilder> initCustomizer() { - return new SubInterfaceIpv4AddressCustomizer(api, interfaceContext); - } - - @Test - public void testRead() throws ReadFailedException { - final AddressBuilder builder = mock(AddressBuilder.class); - when(api.ipAddressDump(any())).thenReturn(future(dump())); - getCustomizer().readCurrentAttributes(getId(IP2), builder, ctx); - verify(builder).setIp(IP2); - verify(builder).setSubnet(new PrefixLengthBuilder().setPrefixLength(PREFIX_LENGTH).build()); - } - - @Test(expected = ReadFailedException.class) - public void testReadFailed() throws ReadFailedException { - when(api.ipAddressDump(any())).thenReturn(failedFuture()); - getCustomizer().readCurrentAttributes(getId(IP1), mock(AddressBuilder.class), ctx); - } - - @Test - public void testGetAllIds() throws ReadFailedException { - when(api.ipAddressDump(any())).thenReturn(future(dump())); - final List<AddressKey> allIds = getCustomizer().getAllIds(getId(), ctx); - assertThat(allIds, hasSize(2)); - assertThat(allIds, containsInAnyOrder(new AddressKey(IP1), new AddressKey(IP2))); - } - - @Test(expected = ReadFailedException.class) - public void testGetAllIdsFailed() throws ReadFailedException { - when(api.ipAddressDump(any())).thenReturn(failedFuture()); - getCustomizer().getAllIds(getId(), ctx); - } - - @Test - public void testCachingScopeSpecificRequest() throws ReadFailedException { - fillCacheForTwoIfaces(); - final AddressBuilder ifaceOneAddressBuilder = new AddressBuilder(); - final AddressBuilder ifaceTwoAddressBuilder = new AddressBuilder(); - - getCustomizer().readCurrentAttributes(ifaceOneAddressOneIdentifier, ifaceOneAddressBuilder, ctx); - getCustomizer().readCurrentAttributes(ifaceTwoAddressOneIdentifier, ifaceTwoAddressBuilder, ctx); - - // addresses have caching scope of parent interface, so returned address should have respective prefix lengths - assertEquals("192.168.2.1", ifaceOneAddressBuilder.getIp().getValue()); - assertTrue(ifaceOneAddressBuilder.getSubnet() instanceof PrefixLength); - assertEquals(22, PrefixLength.class.cast(ifaceOneAddressBuilder.getSubnet()).getPrefixLength().intValue()); - - assertEquals("192.168.2.1", ifaceTwoAddressBuilder.getIp().getValue()); - assertTrue(ifaceTwoAddressBuilder.getSubnet() instanceof PrefixLength); - assertEquals(23, PrefixLength.class.cast(ifaceTwoAddressBuilder.getSubnet()).getPrefixLength().intValue()); - } - - @Test - public void testCachingScopeGetAll() throws ReadFailedException { - fillCacheForFirstIfaceSecondEmpty(); - - final List<AddressKey> keysForIfaceOne = getCustomizer().getAllIds(ifaceOneAddressOneIdentifier, ctx); - Assert.assertThat(keysForIfaceOne, hasSize(1)); - final AddressKey keyIfaceOne = keysForIfaceOne.get(0); - assertEquals("192.168.2.1", keyIfaceOne.getIp().getValue()); - - final List<AddressKey> keysForIfaceTwo = getCustomizer().getAllIds(ifaceTwoAddressOneIdentifier, ctx); - Assert.assertThat(keysForIfaceTwo, is(empty())); - } - - private void fillCacheForTwoIfaces() { - IpAddressDetails detailIfaceOneAddressOne = new IpAddressDetails(); - IpAddressDetails detailIfaceTwoAddressOne = new IpAddressDetails(); - IpAddressDetailsReplyDump replyIfaceOne = new IpAddressDetailsReplyDump(); - IpAddressDetailsReplyDump replyIfaceTwo = new IpAddressDetailsReplyDump(); - - replyIfaceOne.ipAddressDetails = Arrays.asList(detailIfaceOneAddressOne); - replyIfaceTwo.ipAddressDetails = Arrays.asList(detailIfaceTwoAddressOne); - - detailIfaceOneAddressOne.ip = ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))); - detailIfaceOneAddressOne.prefixLength = 22; - - detailIfaceTwoAddressOne.ip = ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))); - detailIfaceTwoAddressOne.prefixLength = 23; - - cache.put(cacheKeyFactory.createKey(ifaceOneAddressOneIdentifier), replyIfaceOne); - cache.put(cacheKeyFactory.createKey(ifaceTwoAddressOneIdentifier), replyIfaceTwo); - } - - private void fillCacheForFirstIfaceSecondEmpty() { - IpAddressDetails detailIfaceOneAddressOne = new IpAddressDetails(); - IpAddressDetailsReplyDump replyIfaceOne = new IpAddressDetailsReplyDump(); - replyIfaceOne.ipAddressDetails = Arrays.asList(detailIfaceOneAddressOne); - - detailIfaceOneAddressOne.ip = ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(new Ipv4Address("192.168.2.1"))); - detailIfaceOneAddressOne.prefixLength = 22; - - cache.put(cacheKeyFactory.createKey(ifaceOneAddressOneIdentifier), replyIfaceOne); - cache.put(cacheKeyFactory.createKey(ifaceTwoAddressOneIdentifier), new IpAddressDetailsReplyDump()); - } - - private IpAddressDetailsReplyDump dump() { - final IpAddressDetailsReplyDump reply = new IpAddressDetailsReplyDump(); - - final IpAddressDetails details1 = new IpAddressDetails(); - details1.ip = new byte[]{10, 1, 1, 1}; - details1.prefixLength = (byte) PREFIX_LENGTH; - reply.ipAddressDetails.add(details1); - - final IpAddressDetails details2 = new IpAddressDetails(); - details2.ip = new byte[]{10, 1, 1, 2}; - details2.prefixLength = (byte) PREFIX_LENGTH; - reply.ipAddressDetails.add(details2); - - return reply; - } -}
\ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/subinterface/SubInterfaceIpv4NeighbourCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/subinterface/SubInterfaceIpv4NeighbourCustomizerTest.java deleted file mode 100644 index 02fe52457..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v4/subinterface/SubInterfaceIpv4NeighbourCustomizerTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * 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 io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest; -import io.fd.hc2vpp.v3po.interfacesstate.ip.InterfaceChildNodeTest; -import io.fd.honeycomb.translate.read.ReadFailedException; -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.interfaces.rev140508.InterfacesState; -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.interfaces.rev140508.interfaces.state.InterfaceKey; -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.interfaces.state._interface.sub.interfaces.SubInterfaceKey; -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.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.yang.binding.InstanceIdentifier; - -import java.util.Arrays; - -import static org.junit.Assert.assertEquals; - -public class SubInterfaceIpv4NeighbourCustomizerTest extends ListReaderCustomizerTest<Neighbor, NeighborKey, NeighborBuilder> - implements InterfaceChildNodeTest { - - private InstanceIdentifier<Neighbor> instanceIdentifier; - - public SubInterfaceIpv4NeighbourCustomizerTest() { - super(Neighbor.class, Ipv4Builder.class); - } - - @Override - protected void setUp() throws Exception { - instanceIdentifier = InstanceIdentifier.create(InterfacesState.class) - .child(Interface.class, new InterfaceKey(IFACE_NAME)) - .augmentation(SubinterfaceStateAugmentation.class) - .child(SubInterfaces.class) - .child(SubInterface.class, new SubInterfaceKey((long) SUB_IFACE_ID)) - .child(Ipv4.class) - .child(Neighbor.class, new NeighborKey(IPV4_TWO_ADDRESS)); - - defineMapping(mappingContext, IFACE_NAME, IFACE_ID, INTERFACE_CONTEXT_NAME); - defineMapping(mappingContext, SUB_IFACE_NAME, SUB_IFACE_ID, INTERFACE_CONTEXT_NAME); - mockNeighborDump(api, dumpV4NeighborsSubIfaceOne(), v4Neighbors()); - } - - @Test - public void testGetAll() throws ReadFailedException { - verifyList(Arrays.asList(new NeighborKey(IPV4_ONE_ADDRESS), new NeighborKey(IPV4_TWO_ADDRESS)), - getCustomizer().getAllIds(instanceIdentifier, ctx)); - } - - @Test - public void testReadCurrent() throws ReadFailedException { - final NeighborBuilder neighborBuilder = new NeighborBuilder(); - getCustomizer().readCurrentAttributes(instanceIdentifier, neighborBuilder, ctx); - - assertEquals(MAC_TWO_ADDRESS, neighborBuilder.getLinkLayerAddress()); - assertEquals(IPV4_TWO_ADDRESS, neighborBuilder.getIp()); - } - - @Override - protected ReaderCustomizer<Neighbor, NeighborBuilder> initCustomizer() { - return new SubInterfaceIpv4NeighbourCustomizer(api, INTERFACE_CONTEXT); - } -}
\ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/Ipv6AddressCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/Ipv6AddressCustomizerTest.java deleted file mode 100644 index 487f56918..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/Ipv6AddressCustomizerTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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 io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest; -import io.fd.hc2vpp.v3po.interfacesstate.ip.InterfaceChildNodeTest; -import io.fd.honeycomb.translate.read.ReadFailedException; -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.interfaces.rev140508.InterfacesState; -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.interfaces.rev140508.interfaces.state.InterfaceKey; -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.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.yang.binding.InstanceIdentifier; - -import java.util.Arrays; - -import static org.junit.Assert.assertEquals; - -public class Ipv6AddressCustomizerTest extends ListReaderCustomizerTest<Address, AddressKey, AddressBuilder> - implements InterfaceChildNodeTest { - - private InstanceIdentifier<Address> instanceIdentifier; - - public Ipv6AddressCustomizerTest() { - super(Address.class, Ipv6Builder.class); - } - - @Override - protected void setUp() throws Exception { - instanceIdentifier = InstanceIdentifier.create(InterfacesState.class) - .child(Interface.class, new InterfaceKey(IFACE_2_NAME)) - .augmentation(Interface2.class) - .child(Ipv6.class) - .child(Address.class, new AddressKey(IPV6_TWO_ADDRESS_COMPRESSED)); - defineMapping(mappingContext, IFACE_2_NAME, IFACE_2_ID, INTERFACE_CONTEXT_NAME); - mockAddressDump(api, dumpV6AddressesIfaceTwo(), v6Addresses()); - } - - @Override - protected ReaderCustomizer<Address, AddressBuilder> initCustomizer() { - return new Ipv6AddressCustomizer(api, INTERFACE_CONTEXT); - } - - @Test - public void testGetAll() throws ReadFailedException { - verifyList(Arrays.asList( - new AddressKey(IPV6_ONE_ADDRESS_COMPRESSED), new AddressKey(IPV6_TWO_ADDRESS_COMPRESSED)), - getCustomizer().getAllIds(instanceIdentifier, ctx)); - } - - @Test - public void testReadCurrent() throws ReadFailedException { - AddressBuilder builder = new AddressBuilder(); - getCustomizer().readCurrentAttributes(instanceIdentifier, builder, ctx); - - assertEquals(IPV6_TWO_ADDRESS_COMPRESSED, builder.getIp()); - assertEquals(IPV6_TWO_PREFIX, builder.getPrefixLength().longValue()); - } -}
\ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/Ipv6NeighbourCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/Ipv6NeighbourCustomizerTest.java deleted file mode 100644 index 6f5a08abb..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/Ipv6NeighbourCustomizerTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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 io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest; -import io.fd.hc2vpp.v3po.interfacesstate.ip.InterfaceChildNodeTest; -import io.fd.honeycomb.translate.read.ReadFailedException; -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.interfaces.rev140508.InterfacesState; -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.interfaces.rev140508.interfaces.state.InterfaceKey; -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.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.yang.binding.InstanceIdentifier; - -import java.util.Arrays; - -import static org.junit.Assert.assertEquals; - - -public class Ipv6NeighbourCustomizerTest extends ListReaderCustomizerTest<Neighbor, NeighborKey, NeighborBuilder> - implements InterfaceChildNodeTest { - - private InstanceIdentifier<Neighbor> instanceIdentifier; - - public Ipv6NeighbourCustomizerTest() { - super(Neighbor.class, Ipv6Builder.class); - } - - @Override - protected void setUp() throws Exception { - instanceIdentifier = InstanceIdentifier.create(InterfacesState.class) - .child(Interface.class, new InterfaceKey(IFACE_NAME)) - .augmentation(Interface2.class) - .child(Ipv6.class) - .child(Neighbor.class, new NeighborKey(IPV6_ONE_ADDRESS_COMPRESSED)); - defineMapping(mappingContext, IFACE_NAME, IFACE_ID, INTERFACE_CONTEXT_NAME); - mockNeighborDump(api, dumpV6NeighborsIfaceOne(), v6Neighbors()); - } - - @Test - public void testGetAll() throws ReadFailedException { - verifyList(Arrays.asList( - new NeighborKey(IPV6_ONE_ADDRESS_COMPRESSED), - new NeighborKey(IPV6_TWO_ADDRESS_COMPRESSED)), - getCustomizer().getAllIds(instanceIdentifier, ctx)); - } - - @Test - public void readCurrent() throws ReadFailedException { - final NeighborBuilder builder = new NeighborBuilder(); - getCustomizer().readCurrentAttributes(instanceIdentifier, builder, ctx); - - assertEquals(IPV6_ONE_ADDRESS_COMPRESSED, builder.getIp()); - assertEquals(MAC_THREE_ADDRESS, builder.getLinkLayerAddress()); - } - - @Override - protected ReaderCustomizer<Neighbor, NeighborBuilder> initCustomizer() { - return new Ipv6NeighbourCustomizer(api, INTERFACE_CONTEXT); - } -}
\ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/nd/NdProxyCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/nd/NdProxyCustomizerTest.java deleted file mode 100644 index 0db4c95fd..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/nd/NdProxyCustomizerTest.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * 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.nd; - -import static io.fd.hc2vpp.v3po.interfacesstate.ip.v6.nd.NdProxyCustomizer.getCfgId; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; - -import io.fd.hc2vpp.common.test.read.InitializingListReaderCustomizerTest; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.vpp.jvpp.core.dto.Ip6NdProxyDetails; -import io.fd.vpp.jvpp.core.dto.Ip6NdProxyDetailsReplyDump; -import java.util.List; -import org.junit.Test; -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.InterfacesState; -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.interfaces.rev140508.interfaces.state.InterfaceKey; -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.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.NdProxyIp6StateAugmentation; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces.state._interface.ipv6.NdProxies; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces.state._interface.ipv6.NdProxiesBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces.state._interface.ipv6.nd.proxies.NdProxy; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces.state._interface.ipv6.nd.proxies.NdProxyBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces.state._interface.ipv6.nd.proxies.NdProxyKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class NdProxyCustomizerTest extends InitializingListReaderCustomizerTest<NdProxy, NdProxyKey, NdProxyBuilder> { - private static final String IF1_NAME = "eth1"; - private static final int IF1_INDEX = 1; - private static final String IF2_NAME = "eth2"; - private static final int IF2_INDEX = 2; - private static final String IFACE_CTX_NAME = "ifc-test-instance"; - - public NdProxyCustomizerTest() { - super(NdProxy.class, NdProxiesBuilder.class); - } - - @Override - protected void setUp() throws Exception { - defineMapping(mappingContext, IF1_NAME, IF1_INDEX, IFACE_CTX_NAME); - defineMapping(mappingContext, IF2_NAME, IF2_INDEX, IFACE_CTX_NAME); - final Ip6NdProxyDetailsReplyDump reply = new Ip6NdProxyDetailsReplyDump(); - final Ip6NdProxyDetails proxy1 = new Ip6NdProxyDetails(); - proxy1.swIfIndex = IF1_INDEX; - proxy1.address = new byte[] {0x20, 0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01}; - final Ip6NdProxyDetails proxy2 = new Ip6NdProxyDetails(); - proxy2.swIfIndex = IF1_INDEX; - proxy2.address = new byte[] {0x20, 0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x02}; - final Ip6NdProxyDetails proxy3 = new Ip6NdProxyDetails(); - proxy3.swIfIndex = IF2_INDEX; - proxy3.address = new byte[] {0x20, 0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x03}; - reply.ip6NdProxyDetails.add(proxy1); - reply.ip6NdProxyDetails.add(proxy2); - reply.ip6NdProxyDetails.add(proxy3); - when(api.ip6NdProxyDump(any())).thenReturn(future(reply)); - } - - @Override - protected ReaderCustomizer<NdProxy, NdProxyBuilder> initCustomizer() { - return new NdProxyCustomizer(api, new NamingContext("ifacePrefix", IFACE_CTX_NAME)); - } - - @Test - public void readCurrent() throws ReadFailedException { - final NdProxyBuilder builder = new NdProxyBuilder(); - final Ipv6AddressNoZone address = new Ipv6AddressNoZone("2001::1"); - getCustomizer().readCurrentAttributes(getId(IF1_NAME, address), builder, ctx); - assertEquals(builder.getAddress(), address); - } - - @Test - public void testGetAllInterface1() throws ReadFailedException { - final List<NdProxyKey> allIds = getCustomizer().getAllIds(getProxiesId(IF1_NAME).child(NdProxy.class), ctx); - assertThat(allIds, containsInAnyOrder( - new NdProxyKey(new Ipv6AddressNoZone("2001::1")), - new NdProxyKey(new Ipv6AddressNoZone("2001::2")) - )); - } - - @Test - public void testGetAllInterface2() throws ReadFailedException { - final List<NdProxyKey> allIds = getCustomizer().getAllIds(getProxiesId(IF2_NAME).child(NdProxy.class), ctx); - assertThat(allIds, containsInAnyOrder(new NdProxyKey(new Ipv6AddressNoZone("2001::3")))); - } - - @Test - public void testInit() { - final Ipv6AddressNoZone address = new Ipv6AddressNoZone("2001::1"); - final InstanceIdentifier<NdProxy> id = getId(IF1_NAME, address); - invokeInitTest( - id, - new NdProxyBuilder().setAddress(address).build(), - getCfgId(id), - new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nd.proxy.rev170315.interfaces._interface.ipv6.nd.proxies.NdProxyBuilder() - .setAddress(address).build() - ); - } - - private InstanceIdentifier<NdProxy> getId(final String ifName, final Ipv6AddressNoZone address) { - return getProxiesId(ifName).child(NdProxy.class, new NdProxyKey(address)); - } - - private InstanceIdentifier<NdProxies> getProxiesId(final String ifName) { - return InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(ifName)) - .augmentation(Interface2.class).child(Ipv6.class).augmentation(NdProxyIp6StateAugmentation.class) - .child(NdProxies.class); - } -}
\ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/subinterface/SubInterfaceIpv6AddressCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/subinterface/SubInterfaceIpv6AddressCustomizerTest.java deleted file mode 100644 index 51d9f603f..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/subinterface/SubInterfaceIpv6AddressCustomizerTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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 io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest; -import io.fd.hc2vpp.v3po.interfacesstate.ip.InterfaceChildNodeTest; -import io.fd.honeycomb.translate.read.ReadFailedException; -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.interfaces.rev140508.InterfacesState; -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.interfaces.rev140508.interfaces.state.InterfaceKey; -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.interfaces.state._interface.sub.interfaces.SubInterfaceKey; -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.yang.binding.InstanceIdentifier; - -import java.util.Arrays; - -public class SubInterfaceIpv6AddressCustomizerTest extends ListReaderCustomizerTest<Address, AddressKey, AddressBuilder> - implements InterfaceChildNodeTest { - - private InstanceIdentifier<Address> instanceIdentifier; - - public SubInterfaceIpv6AddressCustomizerTest() { - super(Address.class, Ipv6Builder.class); - } - - @Override - protected void setUp() throws Exception { - instanceIdentifier = InstanceIdentifier.create(InterfacesState.class) - .child(Interface.class, new InterfaceKey(IFACE_NAME)) - .augmentation(SubinterfaceStateAugmentation.class) - .child(SubInterfaces.class) - .child(SubInterface.class, new SubInterfaceKey((long) SUB_IFACE_ID)) - .child(Ipv6.class) - .child(Address.class, new AddressKey(IPV6_TWO_ADDRESS_COMPRESSED)); - - defineMapping(mappingContext, IFACE_NAME, IFACE_ID, INTERFACE_CONTEXT_NAME); - defineMapping(mappingContext, SUB_IFACE_NAME, SUB_IFACE_ID, INTERFACE_CONTEXT_NAME); - mockAddressDump(api, dumpV6AddressesSubIfaceOne(), v6Addresses()); - } - - @Test - public void testGetAll() throws ReadFailedException { - verifyList(Arrays.asList( - new AddressKey(IPV6_ONE_ADDRESS_COMPRESSED), new AddressKey(IPV6_TWO_ADDRESS_COMPRESSED)), - getCustomizer().getAllIds(instanceIdentifier, ctx)); - } - - @Override - protected ReaderCustomizer<Address, AddressBuilder> initCustomizer() { - return new SubInterfaceIpv6AddressCustomizer(api, INTERFACE_CONTEXT); - } -}
\ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/subinterface/SubInterfaceIpv6NeighbourCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/subinterface/SubInterfaceIpv6NeighbourCustomizerTest.java deleted file mode 100644 index 24fd17eb8..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/ip/v6/subinterface/SubInterfaceIpv6NeighbourCustomizerTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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 io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest; -import io.fd.hc2vpp.v3po.interfacesstate.ip.InterfaceChildNodeTest; -import io.fd.honeycomb.translate.read.ReadFailedException; -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.interfaces.rev140508.InterfacesState; -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.interfaces.rev140508.interfaces.state.InterfaceKey; -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.interfaces.state._interface.sub.interfaces.SubInterfaceKey; -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.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.yang.binding.InstanceIdentifier; - -import java.util.Arrays; - -import static org.junit.Assert.assertEquals; - -public class SubInterfaceIpv6NeighbourCustomizerTest extends ListReaderCustomizerTest<Neighbor, NeighborKey, NeighborBuilder> - implements InterfaceChildNodeTest { - - private InstanceIdentifier<Neighbor> instanceIdentifier; - - public SubInterfaceIpv6NeighbourCustomizerTest() { - super(Neighbor.class, Ipv6Builder.class); - } - - @Override - protected void setUp() throws Exception { - instanceIdentifier = InstanceIdentifier.create(InterfacesState.class) - .child(Interface.class, new InterfaceKey(IFACE_2_NAME)) - .augmentation(SubinterfaceStateAugmentation.class) - .child(SubInterfaces.class) - .child(SubInterface.class, new SubInterfaceKey((long) SUB_IFACE_2_ID)) - .child(Ipv6.class) - .child(Neighbor.class, new NeighborKey(IPV6_TWO_ADDRESS_COMPRESSED)); - defineMapping(mappingContext, IFACE_2_NAME, IFACE_2_ID, INTERFACE_CONTEXT_NAME); - defineMapping(mappingContext, SUB_IFACE_2_NAME, SUB_IFACE_2_ID, INTERFACE_CONTEXT_NAME); - mockNeighborDump(api, dumpV6NeighborsSubIfaceTwo(), v6Neighbors()); - } - - @Test - public void testGetAll() throws ReadFailedException { - verifyList(Arrays.asList( - new NeighborKey(IPV6_ONE_ADDRESS_COMPRESSED), - new NeighborKey(IPV6_TWO_ADDRESS_COMPRESSED)), - getCustomizer().getAllIds(instanceIdentifier, ctx)); - } - - @Test - public void readCurrent() throws ReadFailedException { - NeighborBuilder builder = new NeighborBuilder(); - getCustomizer().readCurrentAttributes(instanceIdentifier, builder, ctx); - - assertEquals(IPV6_TWO_ADDRESS_COMPRESSED, builder.getIp()); - assertEquals(MAC_FOUR_ADDRESS, builder.getLinkLayerAddress()); - } - - @Override - protected ReaderCustomizer<Neighbor, NeighborBuilder> initCustomizer() { - return new SubInterfaceIpv6NeighbourCustomizer(api, INTERFACE_CONTEXT); - } -}
\ No newline at end of file |