From 5ec31f19f7a74a884e2bef8e5238fdd4cfa2c4c2 Mon Sep 17 00:00:00 2001 From: Jan Srnicek Date: Tue, 14 Mar 2017 09:29:12 +0100 Subject: HC2VPP-7 - Split vpp state/Cli RPC to separate module Introduces VppManageModule containing - Vpp state attributes - CLI RPC support - Keep-alive Change-Id: I8907e57132cc9e57840aa3b9607fa131a77f767d Signed-off-by: Jan Srnicek --- pom.xml | 1 + v3po/api/src/main/yang/v3po.yang | 71 +---- .../main/java/io/fd/hc2vpp/v3po/V3poModule.java | 24 +- .../fd/hc2vpp/v3po/cfgattrs/V3poConfiguration.java | 32 -- .../v3po/factory/L2HoneycombWriterFactory.java | 81 +++++ .../factory/L2StateHoneycombReaderFactory.java | 67 ++++ .../v3po/factory/VppHoneycombWriterFactory.java | 82 ----- .../factory/VppStateHoneycombReaderFactory.java | 94 ------ .../l2/ArpTerminationTableEntryCustomizer.java | 115 +++++++ .../fd/hc2vpp/v3po/l2/BridgeDomainCustomizer.java | 164 ++++++++++ .../io/fd/hc2vpp/v3po/l2/L2FibEntryCustomizer.java | 143 +++++++++ .../v3po/l2state/BridgeDomainCustomizer.java | 180 +++++++++++ .../hc2vpp/v3po/l2state/L2FibEntryCustomizer.java | 165 ++++++++++ .../io/fd/hc2vpp/v3po/rpc/CliInbandService.java | 62 ---- .../vpp/ArpTerminationTableEntryCustomizer.java | 115 ------- .../fd/hc2vpp/v3po/vpp/BridgeDomainCustomizer.java | 163 ---------- .../fd/hc2vpp/v3po/vpp/L2FibEntryCustomizer.java | 143 --------- .../v3po/vppstate/BridgeDomainCustomizer.java | 181 ----------- .../hc2vpp/v3po/vppstate/L2FibEntryCustomizer.java | 165 ---------- .../fd/hc2vpp/v3po/vppstate/VersionCustomizer.java | 82 ----- .../honeycomb-minimal-resources/config/v3po.json | 3 - .../java/io/fd/hc2vpp/v3po/V3poModuleTest.java | 10 +- .../l2/ArpTerminationTableEntryCustomizerTest.java | 192 ++++++++++++ .../hc2vpp/v3po/l2/BridgeDomainCustomizerTest.java | 338 +++++++++++++++++++++ .../hc2vpp/v3po/l2/L2FibEntryCustomizerTest.java | 283 +++++++++++++++++ .../v3po/l2state/BridgeDomainCustomizerTest.java | 48 +++ .../v3po/l2state/L2FibEntryCustomizerTest.java | 125 ++++++++ .../io/fd/hc2vpp/v3po/l2state/L2StateTest.java | 216 +++++++++++++ .../fd/hc2vpp/v3po/rpc/CliInbandServiceTest.java | 52 ---- .../ArpTerminationTableEntryCustomizerTest.java | 192 ------------ .../v3po/vpp/BridgeDomainCustomizerTest.java | 338 --------------------- .../hc2vpp/v3po/vpp/L2FibEntryCustomizerTest.java | 283 ----------------- .../v3po/vppstate/BridgeDomainCustomizerTest.java | 47 --- .../v3po/vppstate/L2FibEntryCustomizerTest.java | 124 -------- .../v3po/vppstate/VersionCustomizerTest.java | 60 ---- .../io/fd/hc2vpp/v3po/vppstate/VppStateTest.java | 326 -------------------- v3po/v3po2vpp/src/test/resources/v3po.json | 3 - vpp-integration/minimal-distribution/pom.xml | 7 + vpp-management/api/asciidoc/Readme.adoc | 9 + vpp-management/api/pom.xml | 32 ++ .../api/src/main/yang/vpp-management.yang | 54 ++++ vpp-management/asciidoc/Readme.adoc | 3 + vpp-management/impl/asciidoc/Readme.adoc | 15 + vpp-management/impl/pom.xml | 95 ++++++ .../management/VppManagementConfiguration.java | 32 ++ .../fd/hc2vpp/management/VppManagementModule.java | 47 +++ .../fd/hc2vpp/management/rpc/CliInbandService.java | 62 ++++ .../management/state/StateReaderFactory.java | 61 ++++ .../hc2vpp/management/state/VersionCustomizer.java | 82 +++++ .../config/vpp-management.json | 3 + .../hc2vpp/management/VppManagementModuleTest.java | 69 +++++ .../management/rpc/CliInbandServiceTest.java | 52 ++++ .../fd/hc2vpp/management/state/VppStateTest.java | 142 +++++++++ .../impl/src/test/resources/vpp-management.json | 3 + vpp-management/pom.xml | 58 ++++ .../vpp_management_postman_collection.json | 106 +++++++ 56 files changed, 3067 insertions(+), 2635 deletions(-) delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/cfgattrs/V3poConfiguration.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/L2HoneycombWriterFactory.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/L2StateHoneycombReaderFactory.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/VppHoneycombWriterFactory.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/VppStateHoneycombReaderFactory.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/l2/ArpTerminationTableEntryCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/l2/BridgeDomainCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/l2/L2FibEntryCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/l2state/BridgeDomainCustomizer.java create mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/l2state/L2FibEntryCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/rpc/CliInbandService.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/vpp/ArpTerminationTableEntryCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/vpp/BridgeDomainCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/vpp/L2FibEntryCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/vppstate/BridgeDomainCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/vppstate/L2FibEntryCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/vppstate/VersionCustomizer.java delete mode 100644 v3po/v3po2vpp/src/main/resources/honeycomb-minimal-resources/config/v3po.json create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/ArpTerminationTableEntryCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/BridgeDomainCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/L2FibEntryCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2state/BridgeDomainCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2state/L2FibEntryCustomizerTest.java create mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2state/L2StateTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/rpc/CliInbandServiceTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vpp/ArpTerminationTableEntryCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vpp/BridgeDomainCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vpp/L2FibEntryCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vppstate/BridgeDomainCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vppstate/L2FibEntryCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vppstate/VersionCustomizerTest.java delete mode 100644 v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vppstate/VppStateTest.java delete mode 100644 v3po/v3po2vpp/src/test/resources/v3po.json create mode 100644 vpp-management/api/asciidoc/Readme.adoc create mode 100644 vpp-management/api/pom.xml create mode 100644 vpp-management/api/src/main/yang/vpp-management.yang create mode 100644 vpp-management/asciidoc/Readme.adoc create mode 100644 vpp-management/impl/asciidoc/Readme.adoc create mode 100644 vpp-management/impl/pom.xml create mode 100644 vpp-management/impl/src/main/java/io/fd/hc2vpp/management/VppManagementConfiguration.java create mode 100644 vpp-management/impl/src/main/java/io/fd/hc2vpp/management/VppManagementModule.java create mode 100644 vpp-management/impl/src/main/java/io/fd/hc2vpp/management/rpc/CliInbandService.java create mode 100644 vpp-management/impl/src/main/java/io/fd/hc2vpp/management/state/StateReaderFactory.java create mode 100644 vpp-management/impl/src/main/java/io/fd/hc2vpp/management/state/VersionCustomizer.java create mode 100644 vpp-management/impl/src/main/resources/honeycomb-minimal-resources/config/vpp-management.json create mode 100644 vpp-management/impl/src/test/java/io/fd/hc2vpp/management/VppManagementModuleTest.java create mode 100644 vpp-management/impl/src/test/java/io/fd/hc2vpp/management/rpc/CliInbandServiceTest.java create mode 100644 vpp-management/impl/src/test/java/io/fd/hc2vpp/management/state/VppStateTest.java create mode 100644 vpp-management/impl/src/test/resources/vpp-management.json create mode 100644 vpp-management/pom.xml create mode 100644 vpp-management/vpp_management_postman_collection.json diff --git a/pom.xml b/pom.xml index 81095debb..6032cc843 100644 --- a/pom.xml +++ b/pom.xml @@ -48,5 +48,6 @@ samples vpp-classifier l3 + vpp-management diff --git a/v3po/api/src/main/yang/v3po.yang b/v3po/api/src/main/yang/v3po.yang index f5f6b3293..e9df2f933 100644 --- a/v3po/api/src/main/yang/v3po.yang +++ b/v3po/api/src/main/yang/v3po.yang @@ -39,7 +39,7 @@ module v3po { typedef bridge-domain-ref { type leafref { - path "/vpp/bridge-domains/bridge-domain/name"; + path "/bridge-domains/bridge-domain/name"; } description "This type is used by to reference a bridge domain table"; @@ -585,24 +585,19 @@ module v3po { } } - container vpp { - description - "VPP config data"; + container bridge-domains { + list bridge-domain { + key "name"; - container bridge-domains { - list bridge-domain { - key "name"; + leaf name { + type string; + } - leaf name { - type string; - } + uses bridge-domain-attributes; + uses l2-fib-attributes; - uses bridge-domain-attributes; - uses l2-fib-attributes; - - description - "bridge-domain configuration"; - } + description + "bridge-domain configuration"; } } @@ -675,13 +670,7 @@ module v3po { } } - container vpp-state { - config false; - - description - "VPP operational data"; - - container bridge-domains { + container bridge-domains-state { // FIXME: Should this live in bridge-domain.yang in a modular fashion ? list bridge-domain { @@ -696,29 +685,6 @@ module v3po { description "bridge-domain operational data"; } - } - - container version { - leaf name { - type string; - } - leaf build-directory { - type string; - } - leaf build-date { - type string; - } - leaf branch { - type string; - } - leaf pid { - type uint32; - description - "PID of the vpp process"; - } - description - "vlib version info"; - } } // VPP Notifications @@ -760,17 +726,4 @@ module v3po { type interface-name-or-index; } } - - rpc cli-inband { - input { - leaf cmd { - type string; - } - } - output { - leaf reply { - type string; - } - } - } } 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 06d6d290f..1a0430049 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 @@ -20,22 +20,16 @@ import com.google.inject.AbstractModule; import com.google.inject.multibindings.Multibinder; import com.google.inject.name.Names; 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.L2HoneycombWriterFactory; +import io.fd.hc2vpp.v3po.factory.L2StateHoneycombReaderFactory; import io.fd.hc2vpp.v3po.factory.SubinterfaceAugmentationWriterFactory; import io.fd.hc2vpp.v3po.factory.SubinterfaceStateAugmentationReaderFactory; -import io.fd.hc2vpp.v3po.factory.VppHoneycombWriterFactory; -import io.fd.hc2vpp.v3po.factory.VppStateHoneycombReaderFactory; import io.fd.hc2vpp.v3po.notification.InterfaceChangeNotificationProducer; -import io.fd.hc2vpp.v3po.rpc.CliInbandService; import io.fd.honeycomb.notification.ManagedNotificationProducer; -import io.fd.honeycomb.rpc.RpcService; import io.fd.honeycomb.translate.read.ReaderFactory; import io.fd.honeycomb.translate.write.WriterFactory; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import net.jmob.guice.conf.core.ConfigurationModule; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,8 +40,6 @@ public class V3poModule extends AbstractModule { @Override protected void configure() { LOG.debug("Installing V3PO module"); - install(ConfigurationModule.create()); - requestInjection(V3poConfiguration.class); // TODO HONEYCOMB-173 put into constants // Naming contexts @@ -58,10 +50,6 @@ public class V3poModule extends AbstractModule { .annotatedWith(Names.named("bridge-domain-context")) .toInstance(new NamingContext("bridge-domain-", "bridge-domain-context")); - // Executor needed for keepalives - bind(ScheduledExecutorService.class).toInstance(Executors.newScheduledThreadPool(1)); - - // Context utility for deleted interfaces bind(DisabledInterfacesManager.class).toInstance(new DisabledInterfacesManager()); @@ -69,7 +57,7 @@ public class V3poModule extends AbstractModule { final Multibinder readerFactoryBinder = Multibinder.newSetBinder(binder(), ReaderFactory.class); readerFactoryBinder.addBinding().to(InterfacesStateReaderFactory.class); readerFactoryBinder.addBinding().to(SubinterfaceStateAugmentationReaderFactory.class); - readerFactoryBinder.addBinding().to(VppStateHoneycombReaderFactory.class); + readerFactoryBinder.addBinding().to(L2StateHoneycombReaderFactory.class); // Expose disabled interfaces in operational data readerFactoryBinder.addBinding().to(DisabledInterfacesManager.ContextsReaderFactory.class); @@ -78,17 +66,13 @@ public class V3poModule extends AbstractModule { final Multibinder writerFactoryBinder = Multibinder.newSetBinder(binder(), WriterFactory.class); writerFactoryBinder.addBinding().to(InterfacesWriterFactory.class); writerFactoryBinder.addBinding().to(SubinterfaceAugmentationWriterFactory.class); - writerFactoryBinder.addBinding().to(VppHoneycombWriterFactory.class); + writerFactoryBinder.addBinding().to(L2HoneycombWriterFactory.class); // Notifications final Multibinder notifiersBinder = Multibinder.newSetBinder(binder(), ManagedNotificationProducer.class); notifiersBinder.addBinding().to(InterfaceChangeNotificationProducer.class); - // RPCs - final Multibinder rpcsBinder = Multibinder.newSetBinder(binder(), RpcService.class); - rpcsBinder.addBinding().to(CliInbandService.class); - LOG.info("Module V3PO successfully configured"); } } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/cfgattrs/V3poConfiguration.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/cfgattrs/V3poConfiguration.java deleted file mode 100644 index f7b52accd..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/cfgattrs/V3poConfiguration.java +++ /dev/null @@ -1,32 +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.cfgattrs; - -import net.jmob.guice.conf.core.BindConfig; -import net.jmob.guice.conf.core.InjectConfig; -import net.jmob.guice.conf.core.Syntax; - -@BindConfig(value = "v3po", syntax = Syntax.JSON) -public class V3poConfiguration { - - @InjectConfig("keepalive-delay") - private String keepaliveDelay; - - public int getKeepaliveDelay() { - return Integer.valueOf(this.keepaliveDelay); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/L2HoneycombWriterFactory.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/L2HoneycombWriterFactory.java new file mode 100644 index 000000000..80f72db78 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/L2HoneycombWriterFactory.java @@ -0,0 +1,81 @@ +/* + * 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.factory; + +import com.google.common.collect.Sets; +import com.google.inject.Inject; +import com.google.inject.name.Named; +import io.fd.hc2vpp.v3po.l2.ArpTerminationTableEntryCustomizer; +import io.fd.hc2vpp.v3po.l2.BridgeDomainCustomizer; +import io.fd.hc2vpp.v3po.l2.L2FibEntryCustomizer; +import io.fd.honeycomb.translate.impl.write.GenericListWriter; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.WriterFactory; +import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.BridgeDomains; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domain.attributes.ArpTerminationTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domain.attributes.arp.termination.table.ArpTerminationTableEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.BridgeDomain; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.L2FibTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntry; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; + +public final class L2HoneycombWriterFactory implements WriterFactory { + + private final FutureJVppCore jvpp; + private final NamingContext bdContext; + private final NamingContext ifcContext; + + @Inject + public L2HoneycombWriterFactory(final FutureJVppCore vppJvppWriterDependency, + @Named("bridge-domain-context") final NamingContext bridgeDomainContextVppDependency, + @Named("interface-context") final NamingContext interfaceContextVppDependency) { + this.jvpp = vppJvppWriterDependency; + this.bdContext = bridgeDomainContextVppDependency; + this.ifcContext = interfaceContextVppDependency; + } + + @Override + public void init(final ModifiableWriterRegistryBuilder registry) { + // Vpp has no handlers + // BridgeDomains has no handlers + // BridgeDomain(handled before L2 of ifc and subifc) = + final InstanceIdentifier bdId = + InstanceIdentifier.create(BridgeDomains.class).child(BridgeDomain.class); + registry.addBefore(new GenericListWriter<>(bdId, new BridgeDomainCustomizer(jvpp, bdContext)), + Sets.newHashSet( + InterfacesWriterFactory.L2_ID, + SubinterfaceAugmentationWriterFactory.L2_ID)); + // L2FibTable has no handlers + // L2FibEntry(handled after BridgeDomain and L2 of ifc and subifc) = + final InstanceIdentifier l2FibEntryId = bdId.child(L2FibTable.class).child(L2FibEntry.class); + registry.addAfter( + new GenericListWriter<>(l2FibEntryId, new L2FibEntryCustomizer(jvpp, bdContext, ifcContext)), + Sets.newHashSet( + bdId, + InterfacesWriterFactory.L2_ID, + SubinterfaceAugmentationWriterFactory.L2_ID)); + // ArpTerminationTable has no handlers + // ArpTerminationTableEntry(handled after BridgeDomain) = + final InstanceIdentifier arpEntryId = + bdId.child(ArpTerminationTable.class).child(ArpTerminationTableEntry.class); + registry.addAfter( + new GenericListWriter<>(arpEntryId, new ArpTerminationTableEntryCustomizer(jvpp, bdContext)), + bdId); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/L2StateHoneycombReaderFactory.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/L2StateHoneycombReaderFactory.java new file mode 100644 index 000000000..eacc371fe --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/L2StateHoneycombReaderFactory.java @@ -0,0 +1,67 @@ +/* + * 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.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.l2state.BridgeDomainCustomizer; +import io.fd.hc2vpp.v3po.l2state.L2FibEntryCustomizer; +import io.fd.honeycomb.translate.impl.read.GenericInitListReader; +import io.fd.honeycomb.translate.read.ReaderFactory; +import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.BridgeDomainsState; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.BridgeDomainsStateBuilder; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.state.BridgeDomain; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.L2FibTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.L2FibTableBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntry; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public final class L2StateHoneycombReaderFactory implements ReaderFactory { + + private final FutureJVppCore jVpp; + private final NamingContext ifcCtx; + private final NamingContext bdCtx; + + @Inject + public L2StateHoneycombReaderFactory(final FutureJVppCore jVpp, + @Named("interface-context") final NamingContext ifcCtx, + @Named("bridge-domain-context") final NamingContext bdCtx) { + this.jVpp = jVpp; + this.ifcCtx = ifcCtx; + this.bdCtx = bdCtx; + } + + @Override + public void init(final ModifiableReaderRegistryBuilder registry) { + // BridgeDomains(Structural) + final InstanceIdentifier bridgeDomainsId = InstanceIdentifier.create(BridgeDomainsState.class); + registry.addStructuralReader(bridgeDomainsId, BridgeDomainsStateBuilder.class); + // BridgeDomain + final InstanceIdentifier bridgeDomainId = bridgeDomainsId.child(BridgeDomain.class); + registry.add(new GenericInitListReader<>(bridgeDomainId, new BridgeDomainCustomizer(jVpp, bdCtx))); + // L2FibTable(Structural) + final InstanceIdentifier l2FibTableId = bridgeDomainId.child(L2FibTable.class); + registry.addStructuralReader(l2FibTableId, L2FibTableBuilder.class); + // L2FibEntry + registry.add(new GenericInitListReader<>(l2FibTableId.child(L2FibEntry.class), + new L2FibEntryCustomizer(jVpp, bdCtx, ifcCtx))); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/VppHoneycombWriterFactory.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/VppHoneycombWriterFactory.java deleted file mode 100644 index 0fb95938a..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/VppHoneycombWriterFactory.java +++ /dev/null @@ -1,82 +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.factory; - -import com.google.common.collect.Sets; -import com.google.inject.Inject; -import com.google.inject.name.Named; -import io.fd.hc2vpp.v3po.vpp.ArpTerminationTableEntryCustomizer; -import io.fd.hc2vpp.v3po.vpp.BridgeDomainCustomizer; -import io.fd.hc2vpp.v3po.vpp.L2FibEntryCustomizer; -import io.fd.honeycomb.translate.impl.write.GenericListWriter; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.WriterFactory; -import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.Vpp; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domain.attributes.ArpTerminationTable; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domain.attributes.arp.termination.table.ArpTerminationTableEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.L2FibTable; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.BridgeDomains; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.bridge.domains.BridgeDomain; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; - -public final class VppHoneycombWriterFactory implements WriterFactory { - - private final FutureJVppCore jvpp; - private final NamingContext bdContext; - private final NamingContext ifcContext; - - @Inject - public VppHoneycombWriterFactory(final FutureJVppCore vppJvppWriterDependency, - @Named("bridge-domain-context") final NamingContext bridgeDomainContextVppDependency, - @Named("interface-context") final NamingContext interfaceContextVppDependency) { - this.jvpp = vppJvppWriterDependency; - this.bdContext = bridgeDomainContextVppDependency; - this.ifcContext = interfaceContextVppDependency; - } - - @Override - public void init(final ModifiableWriterRegistryBuilder registry) { - // Vpp has no handlers - // BridgeDomains has no handlers - // BridgeDomain(handled before L2 of ifc and subifc) = - final InstanceIdentifier bdId = - InstanceIdentifier.create(Vpp.class).child(BridgeDomains.class).child(BridgeDomain.class); - registry.addBefore(new GenericListWriter<>(bdId, new BridgeDomainCustomizer(jvpp, bdContext)), - Sets.newHashSet( - InterfacesWriterFactory.L2_ID, - SubinterfaceAugmentationWriterFactory.L2_ID)); - // L2FibTable has no handlers - // L2FibEntry(handled after BridgeDomain and L2 of ifc and subifc) = - final InstanceIdentifier l2FibEntryId = bdId.child(L2FibTable.class).child(L2FibEntry.class); - registry.addAfter( - new GenericListWriter<>(l2FibEntryId, new L2FibEntryCustomizer(jvpp, bdContext, ifcContext)), - Sets.newHashSet( - bdId, - InterfacesWriterFactory.L2_ID, - SubinterfaceAugmentationWriterFactory.L2_ID)); - // ArpTerminationTable has no handlers - // ArpTerminationTableEntry(handled after BridgeDomain) = - final InstanceIdentifier arpEntryId = - bdId.child(ArpTerminationTable.class).child(ArpTerminationTableEntry.class); - registry.addAfter( - new GenericListWriter<>(arpEntryId, new ArpTerminationTableEntryCustomizer(jvpp, bdContext)), - bdId); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/VppStateHoneycombReaderFactory.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/VppStateHoneycombReaderFactory.java deleted file mode 100644 index 6d019ea2a..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/VppStateHoneycombReaderFactory.java +++ /dev/null @@ -1,94 +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.factory; - -import com.google.inject.Inject; -import com.google.inject.name.Named; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.common.translate.util.ReadTimeoutException; -import io.fd.hc2vpp.common.translate.util.VppStatusListener; -import io.fd.hc2vpp.v3po.cfgattrs.V3poConfiguration; -import io.fd.hc2vpp.v3po.vppstate.BridgeDomainCustomizer; -import io.fd.hc2vpp.v3po.vppstate.L2FibEntryCustomizer; -import io.fd.hc2vpp.v3po.vppstate.VersionCustomizer; -import io.fd.honeycomb.translate.impl.read.GenericInitListReader; -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.honeycomb.translate.util.read.KeepaliveReaderWrapper; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; -import java.util.concurrent.ScheduledExecutorService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppState; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppStateBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.L2FibTable; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.L2FibTableBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.BridgeDomains; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.BridgeDomainsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.Version; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.bridge.domains.BridgeDomain; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public final class VppStateHoneycombReaderFactory implements ReaderFactory { - - private final FutureJVppCore jVpp; - private final NamingContext ifcCtx; - private final NamingContext bdCtx; - private final ScheduledExecutorService keepaliveExecutor; - private final VppStatusListener vppStatusListener; - - @Inject - private V3poConfiguration v3poConfiguration; - - @Inject - public VppStateHoneycombReaderFactory(final FutureJVppCore jVpp, - @Named("interface-context") final NamingContext ifcCtx, - @Named("bridge-domain-context") final NamingContext bdCtx, - final ScheduledExecutorService keepaliveExecutorDependency, - final VppStatusListener vppStatusListener) { - this.jVpp = jVpp; - this.ifcCtx = ifcCtx; - this.bdCtx = bdCtx; - this.keepaliveExecutor = keepaliveExecutorDependency; - this.vppStatusListener = vppStatusListener; - } - - @Override - public void init(final ModifiableReaderRegistryBuilder registry) { - // VppState(Structural) - final InstanceIdentifier vppStateId = InstanceIdentifier.create(VppState.class); - registry.addStructuralReader(vppStateId, VppStateBuilder.class); - // Version - // Wrap with keepalive reader to detect connection issues - // Relying on VersionCustomizer to provide a "timing out read" - registry.add(new KeepaliveReaderWrapper<>( - new GenericReader<>(vppStateId.child(Version.class), new VersionCustomizer(jVpp)), - keepaliveExecutor, ReadTimeoutException.class, v3poConfiguration.getKeepaliveDelay(), vppStatusListener)); - // BridgeDomains(Structural) - final InstanceIdentifier bridgeDomainsId = vppStateId.child(BridgeDomains.class); - registry.addStructuralReader(bridgeDomainsId, BridgeDomainsBuilder.class); - // BridgeDomain - final InstanceIdentifier bridgeDomainId = bridgeDomainsId.child(BridgeDomain.class); - registry.add(new GenericInitListReader<>(bridgeDomainId, new BridgeDomainCustomizer(jVpp, bdCtx))); - // L2FibTable(Structural) - final InstanceIdentifier l2FibTableId = bridgeDomainId.child(L2FibTable.class); - registry.addStructuralReader(l2FibTableId, L2FibTableBuilder.class); - // L2FibEntry - registry.add(new GenericInitListReader<>(l2FibTableId.child(L2FibEntry.class), - new L2FibEntryCustomizer(jVpp, bdCtx, ifcCtx))); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/l2/ArpTerminationTableEntryCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/l2/ArpTerminationTableEntryCustomizer.java new file mode 100644 index 000000000..614570dcc --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/l2/ArpTerminationTableEntryCustomizer.java @@ -0,0 +1,115 @@ +/* + * 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.l2; + +import com.google.common.base.Preconditions; +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.spi.write.ListWriterCustomizer; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.core.dto.BdIpMacAddDel; +import io.fd.vpp.jvpp.core.dto.BdIpMacAddDelReply; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.concurrent.CompletionStage; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domain.attributes.arp.termination.table.ArpTerminationTableEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domain.attributes.arp.termination.table.ArpTerminationTableEntryKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.BridgeDomain; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Writer Customizer responsible for ARP termination table management.
Sends {@code bd_ip_mac_add_del} message to + * VPP.
Equivalent of invoking {@code vppctl set bridge-domain arp term} command. + */ +public class ArpTerminationTableEntryCustomizer extends FutureJVppCustomizer + implements ListWriterCustomizer, ByteDataTranslator, + AddressTranslator, JvppReplyConsumer { + + private static final Logger LOG = LoggerFactory.getLogger(ArpTerminationTableEntryCustomizer.class); + + private final NamingContext bdContext; + + public ArpTerminationTableEntryCustomizer(@Nonnull final FutureJVppCore futureJvpp, + @Nonnull final NamingContext bdContext) { + super(futureJvpp); + this.bdContext = Preconditions.checkNotNull(bdContext, "bdContext should not be null"); + } + + @Override + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final ArpTerminationTableEntry dataAfter, + @Nonnull final WriteContext writeContext) + throws WriteFailedException { + LOG.debug("Creating ARP termination table entry: {} {}", id, dataAfter); + bdIpMacAddDel(id, dataAfter, writeContext, true); + LOG.debug("L2 ARP termination table entry created successfully: {} {}", id, dataAfter); + } + + @Override + public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final ArpTerminationTableEntry dataBefore, + @Nonnull final ArpTerminationTableEntry dataAfter, + @Nonnull final WriteContext writeContext) throws WriteFailedException { + throw new UnsupportedOperationException( + "ARP termination table entry update is not supported. It has to be deleted and then created."); + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final ArpTerminationTableEntry dataBefore, + @Nonnull final WriteContext writeContext) + throws WriteFailedException { + LOG.debug("Deleting ARP termination table entry entry: {} {}", id, dataBefore); + bdIpMacAddDel(id, dataBefore, writeContext, false); + LOG.debug("ARP termination table entry deleted successfully: {} {}", id, dataBefore); + } + + private void bdIpMacAddDel(@Nonnull final InstanceIdentifier id, + @Nonnull final ArpTerminationTableEntry entry, + final WriteContext writeContext, boolean isAdd) throws WriteFailedException { + final String bdName = id.firstKeyOf(BridgeDomain.class).getName(); + final int bdId = bdContext.getIndex(bdName, writeContext.getMappingContext()); + + final BdIpMacAddDel request = createRequest(entry, bdId, isAdd); + LOG.debug("Sending l2FibAddDel request: {}", request); + final CompletionStage replyCompletionStage = + getFutureJVpp().bdIpMacAddDel(request); + + getReplyForWrite(replyCompletionStage.toCompletableFuture(), id); + } + + private BdIpMacAddDel createRequest(final ArpTerminationTableEntry entry, final int bdId, boolean isAdd) { + final BdIpMacAddDel request = new BdIpMacAddDel(); + request.bdId = bdId; + request.isAdd = booleanToByte(isAdd); + request.macAddress = parseMac(entry.getPhysAddress().getValue()); + + final IpAddress ipAddress = entry.getIpAddress(); + + request.ipAddress = ipAddressToArray(ipAddress); + request.isIpv6 = booleanToByte(isIpv6(ipAddress)); + + return request; + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/l2/BridgeDomainCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/l2/BridgeDomainCustomizer.java new file mode 100644 index 000000000..b316d28be --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/l2/BridgeDomainCustomizer.java @@ -0,0 +1,164 @@ +/* + * 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.l2; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static java.util.stream.Collectors.toList; + +import com.google.common.base.Preconditions; +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.common.translate.util.ReferenceCheck; +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.BridgeDomainAddDel; +import io.fd.vpp.jvpp.core.dto.BridgeDomainAddDelReply; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.Collections; +import java.util.Optional; +import javax.annotation.Nonnull; +import javax.annotation.concurrent.GuardedBy; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.L2BaseAttributes; +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.bridge.domains.BridgeDomain; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.BridgeDomainKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.base.attributes.interconnection.BridgeBased; + +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class BridgeDomainCustomizer extends FutureJVppCustomizer + implements ListWriterCustomizer, ByteDataTranslator, JvppReplyConsumer, + ReferenceCheck { + + private static final Logger LOG = LoggerFactory.getLogger(BridgeDomainCustomizer.class); + + private static final byte ADD_OR_UPDATE_BD = (byte) 1; + private final NamingContext bdContext; + @GuardedBy("this") + private int bridgeDomainIndexCounter = 1; + + public BridgeDomainCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext bdContext) { + super(futureJVppCore); + this.bdContext = Preconditions.checkNotNull(bdContext, "bdContext should not be null"); + } + + private BridgeDomainAddDelReply addOrUpdateBridgeDomain(@Nonnull final InstanceIdentifier id, + final int bdId, @Nonnull final BridgeDomain bd) + throws WriteFailedException { + final BridgeDomainAddDelReply reply; + final BridgeDomainAddDel request = new BridgeDomainAddDel(); + request.bdId = bdId; + request.flood = booleanToByte(bd.isFlood()); + request.forward = booleanToByte(bd.isForward()); + request.learn = booleanToByte(bd.isLearn()); + request.uuFlood = booleanToByte(bd.isUnknownUnicastFlood()); + request.arpTerm = booleanToByte(bd.isArpTermination()); + request.isAdd = ADD_OR_UPDATE_BD; + + reply = getReplyForWrite(getFutureJVpp().bridgeDomainAddDel(request).toCompletableFuture(), id); + LOG.debug("Bridge domain {} (id={}) add/update successful", bd.getName(), bdId); + return reply; + } + + @Override + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final BridgeDomain dataBefore, + @Nonnull final WriteContext ctx) + throws WriteFailedException { + LOG.debug("writeCurrentAttributes: id={}, current={}, ctx={}", id, dataBefore, ctx); + final String bdName = dataBefore.getName(); + + // Invoke 1. check index, 2. increase index 3. create ND 4. store mapping in a synchronized block to prevent + // race conditions in case of concurrent invocation + synchronized (this) { + int index; + if (bdContext.containsIndex(bdName, ctx.getMappingContext())) { + index = bdContext.getIndex(bdName, ctx.getMappingContext()); + } else { + // Critical section due to bridgeDomainIndexCounter read and write access + // TODO HONEYCOMB-199 move this "get next available index" into naming context or an adapter + // or a dedicated object + + // Use counter to assign bridge domain index, but still check naming context if it's not taken there + while (bdContext.containsName(bridgeDomainIndexCounter, ctx.getMappingContext())) { + bridgeDomainIndexCounter++; + } + index = bridgeDomainIndexCounter; + } + addOrUpdateBridgeDomain(id, index, dataBefore); + bdContext.addName(index, bdName, ctx.getMappingContext()); + } + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final BridgeDomain dataBefore, + @Nonnull final WriteContext ctx) + throws WriteFailedException { + LOG.debug("deleteCurrentAttributes: id={}, dataBefore={}, ctx={}", id, dataBefore, ctx); + final String bdName = id.firstKeyOf(BridgeDomain.class).getName(); + + final com.google.common.base.Optional after = + ctx.readAfter(InstanceIdentifier.create(Interfaces.class)); + + if (after.isPresent()) { + checkReferenceExist(id, Optional.ofNullable(after.get().getInterface()) + .orElse(Collections.emptyList()) + .stream() + .map(iface -> Optional.ofNullable(iface.getAugmentation(VppInterfaceAugmentation.class)) + .map(VppInterfaceAugmentation::getL2) + .map(L2BaseAttributes::getInterconnection) + .orElse(null)) + .filter(interconnection -> interconnection instanceof BridgeBased) + .map(BridgeBased.class::cast) + .filter(bridgeBased -> bdName.equals(bridgeBased.getBridgeDomain())) + .collect(toList())); + } + + int bdId = bdContext.getIndex(bdName, ctx.getMappingContext()); + + final BridgeDomainAddDel request = new BridgeDomainAddDel(); + request.bdId = bdId; + + getReplyForWrite(getFutureJVpp().bridgeDomainAddDel(request).toCompletableFuture(), id); + LOG.debug("Bridge domain {} (id={}) deleted successfully", bdName, bdId); + } + + @Override + public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final BridgeDomain dataBefore, @Nonnull final BridgeDomain dataAfter, + @Nonnull final WriteContext ctx) + throws WriteFailedException { + LOG.debug("updateCurrentAttributes: id={}, dataBefore={}, dataAfter={}, ctx={}", id, dataBefore, dataAfter, + ctx); + + final String bdName = checkNotNull(dataAfter.getName()); + checkArgument(bdName.equals(dataBefore.getName()), + "BridgeDomain name changed. It should be deleted and then created."); + + addOrUpdateBridgeDomain(id, bdContext.getIndex(bdName, ctx.getMappingContext()), dataAfter); + } + +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/l2/L2FibEntryCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/l2/L2FibEntryCustomizer.java new file mode 100644 index 000000000..db2e0aef0 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/l2/L2FibEntryCustomizer.java @@ -0,0 +1,143 @@ +/* + * 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.l2; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.primitives.Longs; +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.MacTranslator; +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.L2FibAddDel; +import io.fd.vpp.jvpp.core.dto.L2FibAddDelReply; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.concurrent.CompletionStage; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.L2FibFilter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.BridgeDomain; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntryKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Writer Customizer responsible for L2 FIB create/delete operations.
Sends {@code l2_fib_add_del} message to + * VPP.
Equivalent of invoking {@code vppctl l2fib add/del} command. + */ +public class L2FibEntryCustomizer extends FutureJVppCustomizer + implements ListWriterCustomizer, ByteDataTranslator, MacTranslator, + JvppReplyConsumer { + + private static final Logger LOG = LoggerFactory.getLogger(L2FibEntryCustomizer.class); + public static final int NO_INTERFACE_REF = -1; + + private final NamingContext bdContext; + private final NamingContext interfaceContext; + + public L2FibEntryCustomizer(@Nonnull final FutureJVppCore futureJVppCore, @Nonnull final NamingContext bdContext, + @Nonnull final NamingContext interfaceContext) { + super(futureJVppCore); + this.bdContext = checkNotNull(bdContext, "bdContext should not be null"); + this.interfaceContext = checkNotNull(interfaceContext, "interfaceContext should not be null"); + } + + @Override + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final L2FibEntry dataAfter, @Nonnull final WriteContext writeContext) + throws WriteFailedException { + + LOG.debug("Creating L2 FIB entry: {} {}", id, dataAfter); + l2FibAddDel(id, dataAfter, writeContext, true); + LOG.debug("L2 FIB entry created successfully: {} {}", id, dataAfter); + } + + @Override + public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final L2FibEntry dataBefore, @Nonnull final L2FibEntry dataAfter, + @Nonnull final WriteContext writeContext) throws WriteFailedException { + throw new UnsupportedOperationException( + "L2 FIB entry update is not supported. It has to be deleted and then created."); + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final L2FibEntry dataBefore, @Nonnull final WriteContext writeContext) + throws WriteFailedException { + + LOG.debug("Deleting L2 FIB entry: {} {}", id, dataBefore); + l2FibAddDel(id, dataBefore, writeContext, false); + LOG.debug("L2 FIB entry deleted successfully: {} {}", id, dataBefore); + } + + private void l2FibAddDel(@Nonnull final InstanceIdentifier id, @Nonnull final L2FibEntry entry, + final WriteContext writeContext, boolean isAdd) throws WriteFailedException { + final String bdName = id.firstKeyOf(BridgeDomain.class).getName(); + final MappingContext mappingContext = writeContext.getMappingContext(); + final int bdId = bdContext.getIndex(bdName, mappingContext); + + final L2FibAddDel l2FibRequest = createL2FibRequest(entry, bdId, getCheckedInterfaceIndex(entry, + mappingContext), isAdd); + LOG.debug("Sending l2FibAddDel request: {}", l2FibRequest); + final CompletionStage l2FibAddDelReplyCompletionStage = + getFutureJVpp().l2FibAddDel(l2FibRequest); + + getReplyForWrite(l2FibAddDelReplyCompletionStage.toCompletableFuture(), id); + } + + private int getCheckedInterfaceIndex(final L2FibEntry entry, final MappingContext mappingContext) { + if (L2FibFilter.class == entry.getAction()) { + // if filter, interface should not be defined + checkArgument(entry.getOutgoingInterface() == null, "Interface reference should not be defined for type %s", + L2FibFilter.class); + return NO_INTERFACE_REF; + } else { + // if type is not filter, interface reference is mandatory + return interfaceContext.getIndex( + checkNotNull(entry.getOutgoingInterface(), "Interface reference should be defined for type %s", + entry.getAction()), mappingContext); + } + } + + private L2FibAddDel createL2FibRequest(final L2FibEntry entry, final int bdId, final int swIfIndex, boolean isAdd) { + final L2FibAddDel request = new L2FibAddDel(); + request.mac = macToLong(entry.getPhysAddress().getValue()); + request.bdId = bdId; + request.swIfIndex = swIfIndex; + request.isAdd = booleanToByte(isAdd); + if (isAdd) { + request.staticMac = booleanToByte(entry.isStaticConfig()); + request.filterMac = booleanToByte(L2FibFilter.class == entry.getAction()); + } + return request; + } + + // mac address is string of the form: 11:22:33:44:55:66 + // but VPP expects long value in the format 11:22:33:44:55:66:XX:XX + private long macToLong(final String macAddress) { + final byte[] mac = parseMac(macAddress); + return Longs.fromBytes(mac[0], mac[1], mac[2], mac[3], + mac[4], mac[5], (byte) 0, (byte) 0); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/l2state/BridgeDomainCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/l2state/BridgeDomainCustomizer.java new file mode 100644 index 000000000..bf4222a77 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/l2state/BridgeDomainCustomizer.java @@ -0,0 +1,180 @@ +/* + * 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.l2state; + +import com.google.common.base.Preconditions; +import com.google.common.collect.Iterables; +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.hc2vpp.common.translate.util.ByteDataTranslator; +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.vpp.jvpp.core.dto.BridgeDomainDetails; +import io.fd.vpp.jvpp.core.dto.BridgeDomainDetailsReplyDump; +import io.fd.vpp.jvpp.core.dto.BridgeDomainDump; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.BridgeDomains; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.BridgeDomainsStateBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.state.BridgeDomain; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.state.BridgeDomainBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.state.BridgeDomainKey; +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 BridgeDomainCustomizer extends FutureJVppCustomizer + implements InitializingListReaderCustomizer, ByteDataTranslator { + + private static final Logger LOG = LoggerFactory.getLogger(BridgeDomainCustomizer.class); + private final NamingContext bdContext; + + public BridgeDomainCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext bdContext) { + super(futureJVppCore); + this.bdContext = Preconditions.checkNotNull(bdContext, "bdContext should not be null"); + } + + @Override + public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final BridgeDomainBuilder builder, @Nonnull final ReadContext context) + throws ReadFailedException { + LOG.debug("vppstate.BridgeDomainCustomizer.readCurrentAttributes: id={}, builderbuilder={}, context={}", + id, builder, context); + + final BridgeDomainKey key = id.firstKeyOf(id.getTargetType()); + LOG.debug("vppstate.BridgeDomainCustomizer.readCurrentAttributes: key={}", key); + + final int bdId = bdContext.getIndex(key.getName(), context.getMappingContext()); + LOG.debug("vppstate.BridgeDomainCustomizer.readCurrentAttributes: bdId={}", bdId); + + BridgeDomainDetailsReplyDump reply; + BridgeDomainDetails bridgeDomainDetails; + final BridgeDomainDump request = new BridgeDomainDump(); + request.bdId = bdContext.getIndex(key.getName(), context.getMappingContext()); + try { + reply = getFutureJVpp().bridgeDomainDump(request).toCompletableFuture().get(); + bridgeDomainDetails = Iterables.getOnlyElement(reply.bridgeDomainDetails); + } catch (Exception e) { + LOG.debug("Unable to read bridge domain: {}", key.getName(), e); + return; + } + + logBridgeDomainDetails(bridgeDomainDetails); + + builder.setName(key.getName()); + builder.setArpTermination(byteToBoolean(bridgeDomainDetails.arpTerm)); + builder.setFlood(byteToBoolean(bridgeDomainDetails.flood)); + builder.setForward(byteToBoolean(bridgeDomainDetails.forward)); + builder.setLearn(byteToBoolean(bridgeDomainDetails.learn)); + builder.setUnknownUnicastFlood(byteToBoolean(bridgeDomainDetails.uuFlood)); + } + + private void logBridgeDomainDetails(final BridgeDomainDetails bridgeDomainDetails) { + LOG.debug("bridgeDomainDetails={}", bridgeDomainDetails); + if (bridgeDomainDetails != null) { + LOG.debug("bridgeDomainDetails.arpTerm={}", bridgeDomainDetails.arpTerm); + LOG.debug("bridgeDomainDetails.bdId={}", bridgeDomainDetails.bdId); + LOG.debug("bridgeDomainDetails.bviSwIfIndex={}", bridgeDomainDetails.bviSwIfIndex); + LOG.debug("bridgeDomainDetails.flood={}", bridgeDomainDetails.flood); + LOG.debug("bridgeDomainDetails.forward={}", bridgeDomainDetails.forward); + LOG.debug("bridgeDomainDetails.learn={}", bridgeDomainDetails.learn); + LOG.debug("bridgeDomainDetails.nSwIfs={}", bridgeDomainDetails.nSwIfs); + LOG.debug("bridgeDomainDetails.uuFlood={}", bridgeDomainDetails.uuFlood); + } + } + + @Nonnull + @Override + public BridgeDomainBuilder getBuilder(@Nonnull final InstanceIdentifier id) { + return new BridgeDomainBuilder(); + } + + @Nonnull + @Override + public List getAllIds(@Nonnull final InstanceIdentifier id, + @Nonnull final ReadContext context) throws ReadFailedException { + final BridgeDomainDump request = new BridgeDomainDump(); + request.bdId = -1; // dump call + + BridgeDomainDetailsReplyDump reply; + try { + reply = getFutureJVpp().bridgeDomainDump(request).toCompletableFuture().get(); + } catch (Exception e) { + throw new ReadFailedException(id, e); + } + + if (reply == null || reply.bridgeDomainDetails == null) { + return Collections.emptyList(); + } + + final int bIdsLength = reply.bridgeDomainDetails.size(); + LOG.debug("vppstate.BridgeDomainCustomizer.getAllIds: bIds.length={}", bIdsLength); + if (bIdsLength == 0) { + // No bridge domains + return Collections.emptyList(); + } + + final List allIds = new ArrayList<>(bIdsLength); + for (BridgeDomainDetails detail : reply.bridgeDomainDetails) { + logBridgeDomainDetails(detail); + + final String bName = bdContext.getName(detail.bdId, context.getMappingContext()); + LOG.debug("vppstate.BridgeDomainCustomizer.getAllIds: bName={}", bName); + allIds.add(new BridgeDomainKey(bName)); + } + + return allIds; + } + + @Override + public void merge(@Nonnull final Builder builder, + @Nonnull final List readData) { + ((BridgeDomainsStateBuilder) builder).setBridgeDomain(readData); + } + + @Override + public Initialized init( + @Nonnull final InstanceIdentifier id, + @Nonnull final BridgeDomain readValue, + @Nonnull final ReadContext ctx) { + return Initialized.create(getCfgId(id), + new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.BridgeDomainBuilder() + .setName(readValue.getName()) + .setLearn(readValue.isLearn()) + .setUnknownUnicastFlood(readValue.isUnknownUnicastFlood()) + .setArpTermination(readValue.isArpTermination()) + .setFlood(readValue.isFlood()) + .setForward(readValue.isForward()) + .build()); + } + + static InstanceIdentifier getCfgId( + final InstanceIdentifier id) { + return InstanceIdentifier.create(BridgeDomains.class).child( + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.BridgeDomain.class, + new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.BridgeDomainKey( + id.firstKeyOf(BridgeDomain.class).getName())); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/l2state/L2FibEntryCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/l2state/L2FibEntryCustomizer.java new file mode 100644 index 000000000..95188e5b1 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/l2state/L2FibEntryCustomizer.java @@ -0,0 +1,165 @@ +/* + * 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.l2state; + +import com.google.common.base.Preconditions; +import com.google.common.primitives.Longs; +import io.fd.hc2vpp.v3po.interfacesstate.InterfaceDataTranslator; +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.hc2vpp.common.translate.util.ByteDataTranslator; +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.vpp.jvpp.core.dto.L2FibTableDump; +import io.fd.vpp.jvpp.core.dto.L2FibTableEntry; +import io.fd.vpp.jvpp.core.dto.L2FibTableEntryReplyDump; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Collector; +import java.util.stream.Collectors; +import javax.annotation.Nonnull; +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.L2FibFilter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.L2FibForward; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.state.BridgeDomain; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.state.BridgeDomainKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.L2FibTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.L2FibTableBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntryKey; +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 L2FibEntryCustomizer extends FutureJVppCustomizer + implements InitializingListReaderCustomizer, ByteDataTranslator, + InterfaceDataTranslator { + + private static final Logger LOG = LoggerFactory.getLogger(L2FibEntryCustomizer.class); + + private static final Collector SINGLE_ITEM_COLLECTOR = + RWUtils.singleItemCollector(); + + private final NamingContext bdContext; + private final NamingContext interfaceContext; + + public L2FibEntryCustomizer(@Nonnull final FutureJVppCore futureJVppCore, @Nonnull final NamingContext bdContext, + @Nonnull final NamingContext interfaceContext) { + super(futureJVppCore); + this.bdContext = Preconditions.checkNotNull(bdContext, "bdContext should not be null"); + this.interfaceContext = Preconditions.checkNotNull(interfaceContext, "interfaceContext should not be null"); + } + + @Override + public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final L2FibEntryBuilder builder, @Nonnull final ReadContext ctx) + throws ReadFailedException { + + final L2FibEntryKey key = id.firstKeyOf(id.getTargetType()); + final BridgeDomainKey bridgeDomainKey = id.firstKeyOf(BridgeDomain.class); + final int bdId = bdContext.getIndex(bridgeDomainKey.getName(), ctx.getMappingContext()); + LOG.debug("Reading L2 FIB entry: key={}. bridgeDomainKey={}, bdId={}", key, bridgeDomainKey, bdId); + + try { + // TODO HONEYCOMB-186 use cached l2FibTable + final L2FibTableEntry entry = dumpL2Fibs(id, bdId).stream().filter(e -> key.getPhysAddress() + .equals(new PhysAddress(vppPhysAddrToYang(Longs.toByteArray(e.mac), 2)))) + .collect(SINGLE_ITEM_COLLECTOR); + + builder.setAction(byteToBoolean(entry.filterMac) + ? L2FibFilter.class + : L2FibForward.class); + builder.setBridgedVirtualInterface(byteToBoolean(entry.bviMac)); + + if (entry.swIfIndex != -1) { + builder.setOutgoingInterface(interfaceContext.getName(entry.swIfIndex, ctx.getMappingContext())); + } + builder.setStaticConfig(byteToBoolean(entry.staticMac)); + builder.setPhysAddress(key.getPhysAddress()); + builder.setKey(key); + } catch (Exception e) { + throw new ReadFailedException(id, e); + } + } + + @Nonnull + private List dumpL2Fibs(final InstanceIdentifier id, final int bdId) + throws ReadFailedException { + final L2FibTableDump l2FibRequest = new L2FibTableDump(); + l2FibRequest.bdId = bdId; + + final CompletableFuture l2FibTableDumpCompletableFuture = + getFutureJVpp().l2FibTableDump(l2FibRequest).toCompletableFuture(); + + final L2FibTableEntryReplyDump dump = getReplyForRead(l2FibTableDumpCompletableFuture, id); + + if (null == dump || null == dump.l2FibTableEntry) { + return Collections.emptyList(); + } else { + return dump.l2FibTableEntry; + } + } + + @Nonnull + @Override + public List getAllIds(@Nonnull final InstanceIdentifier id, + @Nonnull final ReadContext ctx) throws ReadFailedException { + final BridgeDomainKey bridgeDomainKey = id.firstKeyOf(BridgeDomain.class); + final int bdId = bdContext.getIndex(bridgeDomainKey.getName(), ctx.getMappingContext()); + + LOG.debug("Reading L2 FIB for bridge domain {} (bdId={})", bridgeDomainKey, bdId); + return dumpL2Fibs(id, bdId).stream() + .map(entry -> new L2FibEntryKey( + new PhysAddress(vppPhysAddrToYang(Longs.toByteArray(entry.mac), 2)))) + .collect(Collectors.toList()); + } + + @Override + public void merge(@Nonnull final Builder builder, @Nonnull final List readData) { + ((L2FibTableBuilder) builder).setL2FibEntry(readData); + } + + @Nonnull + @Override + public L2FibEntryBuilder getBuilder(@Nonnull final InstanceIdentifier id) { + return new L2FibEntryBuilder(); + } + + @Override + public Initialized init( + @Nonnull final InstanceIdentifier id, + @Nonnull final L2FibEntry readValue, + @Nonnull final ReadContext ctx) { + return Initialized.create(getCfgId(id), + // Convert operational object to config. VPP does not support setting BVI (see v3po.yang) + new L2FibEntryBuilder(readValue).setBridgedVirtualInterface(null).build()); + } + + static InstanceIdentifier getCfgId( + final @Nonnull InstanceIdentifier id) { + return BridgeDomainCustomizer.getCfgId(RWUtils.cutId(id, BridgeDomain.class)).child( + L2FibTable.class).child(L2FibEntry.class, new L2FibEntryKey(id.firstKeyOf(L2FibEntry.class))); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/rpc/CliInbandService.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/rpc/CliInbandService.java deleted file mode 100644 index 7128d06bc..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/rpc/CliInbandService.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.rpc; - -import com.google.inject.Inject; -import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; -import io.fd.honeycomb.rpc.RpcService; -import io.fd.vpp.jvpp.core.dto.CliInband; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; -import java.nio.charset.StandardCharsets; -import java.util.concurrent.CompletionStage; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.CliInbandInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.CliInbandOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.CliInbandOutputBuilder; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; - -public class CliInbandService implements RpcService, JvppReplyConsumer { - - private final FutureJVppCore jvpp; - private static final String localName = "cli-inband"; - private static final QName name = QName.create(CliInbandInput.QNAME, localName); - private static final SchemaPath schemaPath = SchemaPath.ROOT.createChild(name); - - @Inject - public CliInbandService(@Nonnull final FutureJVppCore jvpp) { - this.jvpp = jvpp; - } - - @Override - @Nonnull - public CompletionStage invoke(@Nonnull final CliInbandInput input) { - final CliInband request = new CliInband(); - request.cmd = input.getCmd().getBytes(StandardCharsets.UTF_8); - request.length = request.cmd.length; - return jvpp.cliInband(request) - .thenApply( - reply -> new CliInbandOutputBuilder().setReply(new String(reply.reply)).build() - ); - } - - @Nonnull - @Override - public SchemaPath getManagedNode() { - return schemaPath; - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/vpp/ArpTerminationTableEntryCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/vpp/ArpTerminationTableEntryCustomizer.java deleted file mode 100644 index 2b9f59209..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/vpp/ArpTerminationTableEntryCustomizer.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.vpp; - -import com.google.common.base.Preconditions; -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.spi.write.ListWriterCustomizer; -import io.fd.honeycomb.translate.write.WriteContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.vpp.jvpp.core.dto.BdIpMacAddDel; -import io.fd.vpp.jvpp.core.dto.BdIpMacAddDelReply; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; -import java.util.concurrent.CompletionStage; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domain.attributes.arp.termination.table.ArpTerminationTableEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domain.attributes.arp.termination.table.ArpTerminationTableEntryKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.bridge.domains.BridgeDomain; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Writer Customizer responsible for ARP termination table management.
Sends {@code bd_ip_mac_add_del} message to - * VPP.
Equivalent of invoking {@code vppctl set bridge-domain arp term} command. - */ -public class ArpTerminationTableEntryCustomizer extends FutureJVppCustomizer - implements ListWriterCustomizer, ByteDataTranslator, - AddressTranslator, JvppReplyConsumer { - - private static final Logger LOG = LoggerFactory.getLogger(ArpTerminationTableEntryCustomizer.class); - - private final NamingContext bdContext; - - public ArpTerminationTableEntryCustomizer(@Nonnull final FutureJVppCore futureJvpp, - @Nonnull final NamingContext bdContext) { - super(futureJvpp); - this.bdContext = Preconditions.checkNotNull(bdContext, "bdContext should not be null"); - } - - @Override - public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final ArpTerminationTableEntry dataAfter, - @Nonnull final WriteContext writeContext) - throws WriteFailedException { - LOG.debug("Creating ARP termination table entry: {} {}", id, dataAfter); - bdIpMacAddDel(id, dataAfter, writeContext, true); - LOG.debug("L2 ARP termination table entry created successfully: {} {}", id, dataAfter); - } - - @Override - public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final ArpTerminationTableEntry dataBefore, - @Nonnull final ArpTerminationTableEntry dataAfter, - @Nonnull final WriteContext writeContext) throws WriteFailedException { - throw new UnsupportedOperationException( - "ARP termination table entry update is not supported. It has to be deleted and then created."); - } - - @Override - public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final ArpTerminationTableEntry dataBefore, - @Nonnull final WriteContext writeContext) - throws WriteFailedException { - LOG.debug("Deleting ARP termination table entry entry: {} {}", id, dataBefore); - bdIpMacAddDel(id, dataBefore, writeContext, false); - LOG.debug("ARP termination table entry deleted successfully: {} {}", id, dataBefore); - } - - private void bdIpMacAddDel(@Nonnull final InstanceIdentifier id, - @Nonnull final ArpTerminationTableEntry entry, - final WriteContext writeContext, boolean isAdd) throws WriteFailedException { - final String bdName = id.firstKeyOf(BridgeDomain.class).getName(); - final int bdId = bdContext.getIndex(bdName, writeContext.getMappingContext()); - - final BdIpMacAddDel request = createRequest(entry, bdId, isAdd); - LOG.debug("Sending l2FibAddDel request: {}", request); - final CompletionStage replyCompletionStage = - getFutureJVpp().bdIpMacAddDel(request); - - getReplyForWrite(replyCompletionStage.toCompletableFuture(), id); - } - - private BdIpMacAddDel createRequest(final ArpTerminationTableEntry entry, final int bdId, boolean isAdd) { - final BdIpMacAddDel request = new BdIpMacAddDel(); - request.bdId = bdId; - request.isAdd = booleanToByte(isAdd); - request.macAddress = parseMac(entry.getPhysAddress().getValue()); - - final IpAddress ipAddress = entry.getIpAddress(); - - request.ipAddress = ipAddressToArray(ipAddress); - request.isIpv6 = booleanToByte(isIpv6(ipAddress)); - - return request; - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/vpp/BridgeDomainCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/vpp/BridgeDomainCustomizer.java deleted file mode 100644 index 2962ec578..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/vpp/BridgeDomainCustomizer.java +++ /dev/null @@ -1,163 +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.vpp; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static java.util.stream.Collectors.toList; - -import com.google.common.base.Preconditions; -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.common.translate.util.ReferenceCheck; -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.BridgeDomainAddDel; -import io.fd.vpp.jvpp.core.dto.BridgeDomainAddDelReply; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; -import java.util.Collections; -import java.util.Optional; -import javax.annotation.Nonnull; -import javax.annotation.concurrent.GuardedBy; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.L2BaseAttributes; -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.l2.base.attributes.interconnection.BridgeBased; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.bridge.domains.BridgeDomain; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.bridge.domains.BridgeDomainKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class BridgeDomainCustomizer extends FutureJVppCustomizer - implements ListWriterCustomizer, ByteDataTranslator, JvppReplyConsumer, - ReferenceCheck { - - private static final Logger LOG = LoggerFactory.getLogger(BridgeDomainCustomizer.class); - - private static final byte ADD_OR_UPDATE_BD = (byte) 1; - private final NamingContext bdContext; - @GuardedBy("this") - private int bridgeDomainIndexCounter = 1; - - public BridgeDomainCustomizer(@Nonnull final FutureJVppCore futureJVppCore, - @Nonnull final NamingContext bdContext) { - super(futureJVppCore); - this.bdContext = Preconditions.checkNotNull(bdContext, "bdContext should not be null"); - } - - private BridgeDomainAddDelReply addOrUpdateBridgeDomain(@Nonnull final InstanceIdentifier id, - final int bdId, @Nonnull final BridgeDomain bd) - throws WriteFailedException { - final BridgeDomainAddDelReply reply; - final BridgeDomainAddDel request = new BridgeDomainAddDel(); - request.bdId = bdId; - request.flood = booleanToByte(bd.isFlood()); - request.forward = booleanToByte(bd.isForward()); - request.learn = booleanToByte(bd.isLearn()); - request.uuFlood = booleanToByte(bd.isUnknownUnicastFlood()); - request.arpTerm = booleanToByte(bd.isArpTermination()); - request.isAdd = ADD_OR_UPDATE_BD; - - reply = getReplyForWrite(getFutureJVpp().bridgeDomainAddDel(request).toCompletableFuture(), id); - LOG.debug("Bridge domain {} (id={}) add/update successful", bd.getName(), bdId); - return reply; - } - - @Override - public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final BridgeDomain dataBefore, - @Nonnull final WriteContext ctx) - throws WriteFailedException { - LOG.debug("writeCurrentAttributes: id={}, current={}, ctx={}", id, dataBefore, ctx); - final String bdName = dataBefore.getName(); - - // Invoke 1. check index, 2. increase index 3. create ND 4. store mapping in a synchronized block to prevent - // race conditions in case of concurrent invocation - synchronized (this) { - int index; - if (bdContext.containsIndex(bdName, ctx.getMappingContext())) { - index = bdContext.getIndex(bdName, ctx.getMappingContext()); - } else { - // Critical section due to bridgeDomainIndexCounter read and write access - // TODO HONEYCOMB-199 move this "get next available index" into naming context or an adapter - // or a dedicated object - - // Use counter to assign bridge domain index, but still check naming context if it's not taken there - while (bdContext.containsName(bridgeDomainIndexCounter, ctx.getMappingContext())) { - bridgeDomainIndexCounter++; - } - index = bridgeDomainIndexCounter; - } - addOrUpdateBridgeDomain(id, index, dataBefore); - bdContext.addName(index, bdName, ctx.getMappingContext()); - } - } - - @Override - public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final BridgeDomain dataBefore, - @Nonnull final WriteContext ctx) - throws WriteFailedException { - LOG.debug("deleteCurrentAttributes: id={}, dataBefore={}, ctx={}", id, dataBefore, ctx); - final String bdName = id.firstKeyOf(BridgeDomain.class).getName(); - - final com.google.common.base.Optional after = - ctx.readAfter(InstanceIdentifier.create(Interfaces.class)); - - if (after.isPresent()) { - checkReferenceExist(id, Optional.ofNullable(after.get().getInterface()) - .orElse(Collections.emptyList()) - .stream() - .map(iface -> Optional.ofNullable(iface.getAugmentation(VppInterfaceAugmentation.class)) - .map(VppInterfaceAugmentation::getL2) - .map(L2BaseAttributes::getInterconnection) - .orElse(null)) - .filter(interconnection -> interconnection instanceof BridgeBased) - .map(BridgeBased.class::cast) - .filter(bridgeBased -> bdName.equals(bridgeBased.getBridgeDomain())) - .collect(toList())); - } - - int bdId = bdContext.getIndex(bdName, ctx.getMappingContext()); - - final BridgeDomainAddDel request = new BridgeDomainAddDel(); - request.bdId = bdId; - - getReplyForWrite(getFutureJVpp().bridgeDomainAddDel(request).toCompletableFuture(), id); - LOG.debug("Bridge domain {} (id={}) deleted successfully", bdName, bdId); - } - - @Override - public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final BridgeDomain dataBefore, @Nonnull final BridgeDomain dataAfter, - @Nonnull final WriteContext ctx) - throws WriteFailedException { - LOG.debug("updateCurrentAttributes: id={}, dataBefore={}, dataAfter={}, ctx={}", id, dataBefore, dataAfter, - ctx); - - final String bdName = checkNotNull(dataAfter.getName()); - checkArgument(bdName.equals(dataBefore.getName()), - "BridgeDomain name changed. It should be deleted and then created."); - - addOrUpdateBridgeDomain(id, bdContext.getIndex(bdName, ctx.getMappingContext()), dataAfter); - } - -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/vpp/L2FibEntryCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/vpp/L2FibEntryCustomizer.java deleted file mode 100644 index 0eced8237..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/vpp/L2FibEntryCustomizer.java +++ /dev/null @@ -1,143 +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.vpp; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.primitives.Longs; -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.MacTranslator; -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.L2FibAddDel; -import io.fd.vpp.jvpp.core.dto.L2FibAddDelReply; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; -import java.util.concurrent.CompletionStage; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.L2FibFilter; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntryKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.bridge.domains.BridgeDomain; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Writer Customizer responsible for L2 FIB create/delete operations.
Sends {@code l2_fib_add_del} message to - * VPP.
Equivalent of invoking {@code vppctl l2fib add/del} command. - */ -public class L2FibEntryCustomizer extends FutureJVppCustomizer - implements ListWriterCustomizer, ByteDataTranslator, MacTranslator, - JvppReplyConsumer { - - private static final Logger LOG = LoggerFactory.getLogger(L2FibEntryCustomizer.class); - public static final int NO_INTERFACE_REF = -1; - - private final NamingContext bdContext; - private final NamingContext interfaceContext; - - public L2FibEntryCustomizer(@Nonnull final FutureJVppCore futureJVppCore, @Nonnull final NamingContext bdContext, - @Nonnull final NamingContext interfaceContext) { - super(futureJVppCore); - this.bdContext = checkNotNull(bdContext, "bdContext should not be null"); - this.interfaceContext = checkNotNull(interfaceContext, "interfaceContext should not be null"); - } - - @Override - public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final L2FibEntry dataAfter, @Nonnull final WriteContext writeContext) - throws WriteFailedException { - - LOG.debug("Creating L2 FIB entry: {} {}", id, dataAfter); - l2FibAddDel(id, dataAfter, writeContext, true); - LOG.debug("L2 FIB entry created successfully: {} {}", id, dataAfter); - } - - @Override - public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final L2FibEntry dataBefore, @Nonnull final L2FibEntry dataAfter, - @Nonnull final WriteContext writeContext) throws WriteFailedException { - throw new UnsupportedOperationException( - "L2 FIB entry update is not supported. It has to be deleted and then created."); - } - - @Override - public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final L2FibEntry dataBefore, @Nonnull final WriteContext writeContext) - throws WriteFailedException { - - LOG.debug("Deleting L2 FIB entry: {} {}", id, dataBefore); - l2FibAddDel(id, dataBefore, writeContext, false); - LOG.debug("L2 FIB entry deleted successfully: {} {}", id, dataBefore); - } - - private void l2FibAddDel(@Nonnull final InstanceIdentifier id, @Nonnull final L2FibEntry entry, - final WriteContext writeContext, boolean isAdd) throws WriteFailedException { - final String bdName = id.firstKeyOf(BridgeDomain.class).getName(); - final MappingContext mappingContext = writeContext.getMappingContext(); - final int bdId = bdContext.getIndex(bdName, mappingContext); - - final L2FibAddDel l2FibRequest = createL2FibRequest(entry, bdId, getCheckedInterfaceIndex(entry, - mappingContext), isAdd); - LOG.debug("Sending l2FibAddDel request: {}", l2FibRequest); - final CompletionStage l2FibAddDelReplyCompletionStage = - getFutureJVpp().l2FibAddDel(l2FibRequest); - - getReplyForWrite(l2FibAddDelReplyCompletionStage.toCompletableFuture(), id); - } - - private int getCheckedInterfaceIndex(final L2FibEntry entry, final MappingContext mappingContext) { - if (L2FibFilter.class == entry.getAction()) { - // if filter, interface should not be defined - checkArgument(entry.getOutgoingInterface() == null, "Interface reference should not be defined for type %s", - L2FibFilter.class); - return NO_INTERFACE_REF; - } else { - // if type is not filter, interface reference is mandatory - return interfaceContext.getIndex( - checkNotNull(entry.getOutgoingInterface(), "Interface reference should be defined for type %s", - entry.getAction()), mappingContext); - } - } - - private L2FibAddDel createL2FibRequest(final L2FibEntry entry, final int bdId, final int swIfIndex, boolean isAdd) { - final L2FibAddDel request = new L2FibAddDel(); - request.mac = macToLong(entry.getPhysAddress().getValue()); - request.bdId = bdId; - request.swIfIndex = swIfIndex; - request.isAdd = booleanToByte(isAdd); - if (isAdd) { - request.staticMac = booleanToByte(entry.isStaticConfig()); - request.filterMac = booleanToByte(L2FibFilter.class == entry.getAction()); - } - return request; - } - - // mac address is string of the form: 11:22:33:44:55:66 - // but VPP expects long value in the format 11:22:33:44:55:66:XX:XX - private long macToLong(final String macAddress) { - final byte[] mac = parseMac(macAddress); - return Longs.fromBytes(mac[0], mac[1], mac[2], mac[3], - mac[4], mac[5], (byte) 0, (byte) 0); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/vppstate/BridgeDomainCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/vppstate/BridgeDomainCustomizer.java deleted file mode 100644 index e6f3bbb49..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/vppstate/BridgeDomainCustomizer.java +++ /dev/null @@ -1,181 +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.vppstate; - -import com.google.common.base.Preconditions; -import com.google.common.collect.Iterables; -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.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.vpp.jvpp.core.dto.BridgeDomainDetails; -import io.fd.vpp.jvpp.core.dto.BridgeDomainDetailsReplyDump; -import io.fd.vpp.jvpp.core.dto.BridgeDomainDump; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.Vpp; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.BridgeDomains; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.BridgeDomainsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.bridge.domains.BridgeDomain; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.bridge.domains.BridgeDomainBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.bridge.domains.BridgeDomainKey; -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 BridgeDomainCustomizer extends FutureJVppCustomizer - implements InitializingListReaderCustomizer, ByteDataTranslator { - - private static final Logger LOG = LoggerFactory.getLogger(BridgeDomainCustomizer.class); - private final NamingContext bdContext; - - public BridgeDomainCustomizer(@Nonnull final FutureJVppCore futureJVppCore, - @Nonnull final NamingContext bdContext) { - super(futureJVppCore); - this.bdContext = Preconditions.checkNotNull(bdContext, "bdContext should not be null"); - } - - @Override - public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final BridgeDomainBuilder builder, @Nonnull final ReadContext context) - throws ReadFailedException { - LOG.debug("vppstate.BridgeDomainCustomizer.readCurrentAttributes: id={}, builderbuilder={}, context={}", - id, builder, context); - - final BridgeDomainKey key = id.firstKeyOf(id.getTargetType()); - LOG.debug("vppstate.BridgeDomainCustomizer.readCurrentAttributes: key={}", key); - - final int bdId = bdContext.getIndex(key.getName(), context.getMappingContext()); - LOG.debug("vppstate.BridgeDomainCustomizer.readCurrentAttributes: bdId={}", bdId); - - BridgeDomainDetailsReplyDump reply; - BridgeDomainDetails bridgeDomainDetails; - final BridgeDomainDump request = new BridgeDomainDump(); - request.bdId = bdContext.getIndex(key.getName(), context.getMappingContext()); - try { - reply = getFutureJVpp().bridgeDomainDump(request).toCompletableFuture().get(); - bridgeDomainDetails = Iterables.getOnlyElement(reply.bridgeDomainDetails); - } catch (Exception e) { - LOG.debug("Unable to read bridge domain: {}", key.getName(), e); - return; - } - - logBridgeDomainDetails(bridgeDomainDetails); - - builder.setName(key.getName()); - builder.setArpTermination(byteToBoolean(bridgeDomainDetails.arpTerm)); - builder.setFlood(byteToBoolean(bridgeDomainDetails.flood)); - builder.setForward(byteToBoolean(bridgeDomainDetails.forward)); - builder.setLearn(byteToBoolean(bridgeDomainDetails.learn)); - builder.setUnknownUnicastFlood(byteToBoolean(bridgeDomainDetails.uuFlood)); - } - - private void logBridgeDomainDetails(final BridgeDomainDetails bridgeDomainDetails) { - LOG.debug("bridgeDomainDetails={}", bridgeDomainDetails); - if (bridgeDomainDetails != null) { - LOG.debug("bridgeDomainDetails.arpTerm={}", bridgeDomainDetails.arpTerm); - LOG.debug("bridgeDomainDetails.bdId={}", bridgeDomainDetails.bdId); - LOG.debug("bridgeDomainDetails.bviSwIfIndex={}", bridgeDomainDetails.bviSwIfIndex); - LOG.debug("bridgeDomainDetails.flood={}", bridgeDomainDetails.flood); - LOG.debug("bridgeDomainDetails.forward={}", bridgeDomainDetails.forward); - LOG.debug("bridgeDomainDetails.learn={}", bridgeDomainDetails.learn); - LOG.debug("bridgeDomainDetails.nSwIfs={}", bridgeDomainDetails.nSwIfs); - LOG.debug("bridgeDomainDetails.uuFlood={}", bridgeDomainDetails.uuFlood); - } - } - - @Nonnull - @Override - public BridgeDomainBuilder getBuilder(@Nonnull final InstanceIdentifier id) { - return new BridgeDomainBuilder(); - } - - @Nonnull - @Override - public List getAllIds(@Nonnull final InstanceIdentifier id, - @Nonnull final ReadContext context) throws ReadFailedException { - final BridgeDomainDump request = new BridgeDomainDump(); - request.bdId = -1; // dump call - - BridgeDomainDetailsReplyDump reply; - try { - reply = getFutureJVpp().bridgeDomainDump(request).toCompletableFuture().get(); - } catch (Exception e) { - throw new ReadFailedException(id, e); - } - - if (reply == null || reply.bridgeDomainDetails == null) { - return Collections.emptyList(); - } - - final int bIdsLength = reply.bridgeDomainDetails.size(); - LOG.debug("vppstate.BridgeDomainCustomizer.getAllIds: bIds.length={}", bIdsLength); - if (bIdsLength == 0) { - // No bridge domains - return Collections.emptyList(); - } - - final List allIds = new ArrayList<>(bIdsLength); - for (BridgeDomainDetails detail : reply.bridgeDomainDetails) { - logBridgeDomainDetails(detail); - - final String bName = bdContext.getName(detail.bdId, context.getMappingContext()); - LOG.debug("vppstate.BridgeDomainCustomizer.getAllIds: bName={}", bName); - allIds.add(new BridgeDomainKey(bName)); - } - - return allIds; - } - - @Override - public void merge(@Nonnull final Builder builder, - @Nonnull final List readData) { - ((BridgeDomainsBuilder) builder).setBridgeDomain(readData); - } - - @Override - public Initialized init( - @Nonnull final InstanceIdentifier id, - @Nonnull final BridgeDomain readValue, - @Nonnull final ReadContext ctx) { - return Initialized.create(getCfgId(id), - new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.bridge.domains.BridgeDomainBuilder() - .setName(readValue.getName()) - .setLearn(readValue.isLearn()) - .setUnknownUnicastFlood(readValue.isUnknownUnicastFlood()) - .setArpTermination(readValue.isArpTermination()) - .setFlood(readValue.isFlood()) - .setForward(readValue.isForward()) - .build()); - } - - static InstanceIdentifier getCfgId( - final InstanceIdentifier id) { - return InstanceIdentifier.create(Vpp.class).child(BridgeDomains.class).child( - org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.bridge.domains.BridgeDomain.class, - new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.bridge.domains.BridgeDomainKey( - id.firstKeyOf(BridgeDomain.class).getName())); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/vppstate/L2FibEntryCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/vppstate/L2FibEntryCustomizer.java deleted file mode 100644 index 2605293c5..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/vppstate/L2FibEntryCustomizer.java +++ /dev/null @@ -1,165 +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.vppstate; - -import com.google.common.base.Preconditions; -import com.google.common.primitives.Longs; -import io.fd.hc2vpp.v3po.interfacesstate.InterfaceDataTranslator; -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.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.vpp.jvpp.core.dto.L2FibTableDump; -import io.fd.vpp.jvpp.core.dto.L2FibTableEntry; -import io.fd.vpp.jvpp.core.dto.L2FibTableEntryReplyDump; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.stream.Collector; -import java.util.stream.Collectors; -import javax.annotation.Nonnull; -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.L2FibFilter; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.L2FibForward; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.L2FibTable; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.L2FibTableBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntryKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.bridge.domains.BridgeDomain; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.bridge.domains.BridgeDomainKey; -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 L2FibEntryCustomizer extends FutureJVppCustomizer - implements InitializingListReaderCustomizer, ByteDataTranslator, - InterfaceDataTranslator { - - private static final Logger LOG = LoggerFactory.getLogger(L2FibEntryCustomizer.class); - - private static final Collector SINGLE_ITEM_COLLECTOR = - RWUtils.singleItemCollector(); - - private final NamingContext bdContext; - private final NamingContext interfaceContext; - - public L2FibEntryCustomizer(@Nonnull final FutureJVppCore futureJVppCore, @Nonnull final NamingContext bdContext, - @Nonnull final NamingContext interfaceContext) { - super(futureJVppCore); - this.bdContext = Preconditions.checkNotNull(bdContext, "bdContext should not be null"); - this.interfaceContext = Preconditions.checkNotNull(interfaceContext, "interfaceContext should not be null"); - } - - @Override - public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, - @Nonnull final L2FibEntryBuilder builder, @Nonnull final ReadContext ctx) - throws ReadFailedException { - - final L2FibEntryKey key = id.firstKeyOf(id.getTargetType()); - final BridgeDomainKey bridgeDomainKey = id.firstKeyOf(BridgeDomain.class); - final int bdId = bdContext.getIndex(bridgeDomainKey.getName(), ctx.getMappingContext()); - LOG.debug("Reading L2 FIB entry: key={}. bridgeDomainKey={}, bdId={}", key, bridgeDomainKey, bdId); - - try { - // TODO HONEYCOMB-186 use cached l2FibTable - final L2FibTableEntry entry = dumpL2Fibs(id, bdId).stream().filter(e -> key.getPhysAddress() - .equals(new PhysAddress(vppPhysAddrToYang(Longs.toByteArray(e.mac), 2)))) - .collect(SINGLE_ITEM_COLLECTOR); - - builder.setAction(byteToBoolean(entry.filterMac) - ? L2FibFilter.class - : L2FibForward.class); - builder.setBridgedVirtualInterface(byteToBoolean(entry.bviMac)); - - if (entry.swIfIndex != -1) { - builder.setOutgoingInterface(interfaceContext.getName(entry.swIfIndex, ctx.getMappingContext())); - } - builder.setStaticConfig(byteToBoolean(entry.staticMac)); - builder.setPhysAddress(key.getPhysAddress()); - builder.setKey(key); - } catch (Exception e) { - throw new ReadFailedException(id, e); - } - } - - @Nonnull - private List dumpL2Fibs(final InstanceIdentifier id, final int bdId) - throws ReadFailedException { - final L2FibTableDump l2FibRequest = new L2FibTableDump(); - l2FibRequest.bdId = bdId; - - final CompletableFuture l2FibTableDumpCompletableFuture = - getFutureJVpp().l2FibTableDump(l2FibRequest).toCompletableFuture(); - - final L2FibTableEntryReplyDump dump = getReplyForRead(l2FibTableDumpCompletableFuture, id); - - if (null == dump || null == dump.l2FibTableEntry) { - return Collections.emptyList(); - } else { - return dump.l2FibTableEntry; - } - } - - @Nonnull - @Override - public List getAllIds(@Nonnull final InstanceIdentifier id, - @Nonnull final ReadContext ctx) throws ReadFailedException { - final BridgeDomainKey bridgeDomainKey = id.firstKeyOf(BridgeDomain.class); - final int bdId = bdContext.getIndex(bridgeDomainKey.getName(), ctx.getMappingContext()); - - LOG.debug("Reading L2 FIB for bridge domain {} (bdId={})", bridgeDomainKey, bdId); - return dumpL2Fibs(id, bdId).stream() - .map(entry -> new L2FibEntryKey( - new PhysAddress(vppPhysAddrToYang(Longs.toByteArray(entry.mac), 2)))) - .collect(Collectors.toList()); - } - - @Override - public void merge(@Nonnull final Builder builder, @Nonnull final List readData) { - ((L2FibTableBuilder) builder).setL2FibEntry(readData); - } - - @Nonnull - @Override - public L2FibEntryBuilder getBuilder(@Nonnull final InstanceIdentifier id) { - return new L2FibEntryBuilder(); - } - - @Override - public Initialized init( - @Nonnull final InstanceIdentifier id, - @Nonnull final L2FibEntry readValue, - @Nonnull final ReadContext ctx) { - return Initialized.create(getCfgId(id), - // Convert operational object to config. VPP does not support setting BVI (see v3po.yang) - new L2FibEntryBuilder(readValue).setBridgedVirtualInterface(null).build()); - } - - static InstanceIdentifier getCfgId( - final @Nonnull InstanceIdentifier id) { - return BridgeDomainCustomizer.getCfgId(RWUtils.cutId(id, BridgeDomain.class)).child( - L2FibTable.class).child(L2FibEntry.class, new L2FibEntryKey(id.firstKeyOf(L2FibEntry.class))); - } -} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/vppstate/VersionCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/vppstate/VersionCustomizer.java deleted file mode 100644 index 3f69c98df..000000000 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/vppstate/VersionCustomizer.java +++ /dev/null @@ -1,82 +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.vppstate; - -import com.google.common.primitives.UnsignedInts; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; -import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; -import io.fd.vpp.jvpp.core.dto.ShowVersion; -import io.fd.vpp.jvpp.core.dto.ShowVersionReply; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; -import io.fd.vpp.jvpp.dto.ControlPing; -import io.fd.vpp.jvpp.dto.ControlPingReply; -import io.fd.vpp.jvpp.dto.JVppReply; -import java.util.concurrent.CompletionStage; -import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppStateBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.Version; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.VersionBuilder; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public final class VersionCustomizer - extends FutureJVppCustomizer - implements ReaderCustomizer, ByteDataTranslator, JvppReplyConsumer { - - public VersionCustomizer(@Nonnull final FutureJVppCore futureJVppCore) { - super(futureJVppCore); - } - - @Override - public void merge(@Nonnull final Builder parentBuilder, @Nonnull final Version readValue) { - ((VppStateBuilder) parentBuilder).setVersion(readValue); - } - - @Nonnull - @Override - public VersionBuilder getBuilder(@Nonnull InstanceIdentifier id) { - return new VersionBuilder(); - } - - @Override - public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final VersionBuilder builder, - @Nonnull final ReadContext context) throws ReadFailedException { - - // Execute with timeout - final CompletionStage showVersionFuture = getFutureJVpp().showVersion(new ShowVersion()); - final ShowVersionReply reply = getReplyForRead(showVersionFuture.toCompletableFuture(), id); - - builder.setBranch(toString(reply.version)); - builder.setName(toString(reply.program)); - builder.setBuildDate(toString(reply.buildDate)); - builder.setBuildDirectory(toString(reply.buildDirectory)); - builder.setPid(getPid(id)); - } - - private Long getPid(@Nonnull final InstanceIdentifier id) throws ReadFailedException { - final CompletionStage> request = getFutureJVpp().send(new ControlPing()); - final ControlPingReply reply = (ControlPingReply)getReplyForRead(request.toCompletableFuture(), id); - return UnsignedInts.toLong(reply.vpePid); - } - - -} diff --git a/v3po/v3po2vpp/src/main/resources/honeycomb-minimal-resources/config/v3po.json b/v3po/v3po2vpp/src/main/resources/honeycomb-minimal-resources/config/v3po.json deleted file mode 100644 index 9ea66efe8..000000000 --- a/v3po/v3po2vpp/src/main/resources/honeycomb-minimal-resources/config/v3po.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "keepalive-delay": "30" -} diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/V3poModuleTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/V3poModuleTest.java index 66231b2ff..9d799d850 100644 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/V3poModuleTest.java +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/V3poModuleTest.java @@ -19,7 +19,6 @@ package io.fd.hc2vpp.v3po; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.Matchers.empty; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; import static org.mockito.MockitoAnnotations.initMocks; @@ -29,7 +28,6 @@ import com.google.inject.Inject; import com.google.inject.name.Named; import com.google.inject.testing.fieldbinder.Bind; import com.google.inject.testing.fieldbinder.BoundFieldModule; -import io.fd.hc2vpp.v3po.cfgattrs.V3poConfiguration; import io.fd.honeycomb.translate.MappingContext; import io.fd.honeycomb.translate.impl.read.registry.CompositeReaderRegistryBuilder; import io.fd.honeycomb.translate.impl.write.registry.FlatWriterRegistryBuilder; @@ -70,9 +68,6 @@ public class V3poModuleTest { @Inject private Set writerFactories = new HashSet<>(); - @Inject - private V3poConfiguration configuration; - @Before public void setUp() { initMocks(this); @@ -99,8 +94,5 @@ public class V3poModuleTest { assertNotNull(registryBuilder.build()); } - @Test - public void testConfiguration() { - assertEquals(30, configuration.getKeepaliveDelay()); - } + } \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/ArpTerminationTableEntryCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/ArpTerminationTableEntryCustomizerTest.java new file mode 100644 index 000000000..29caf068b --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/ArpTerminationTableEntryCustomizerTest.java @@ -0,0 +1,192 @@ +/* + * 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.l2; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +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.VppInvocationException; +import io.fd.vpp.jvpp.core.dto.BdIpMacAddDel; +import io.fd.vpp.jvpp.core.dto.BdIpMacAddDelReply; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; +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 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.BridgeDomains; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domain.attributes.ArpTerminationTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domain.attributes.arp.termination.table.ArpTerminationTableEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domain.attributes.arp.termination.table.ArpTerminationTableEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domain.attributes.arp.termination.table.ArpTerminationTableEntryKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.BridgeDomain; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.BridgeDomainKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class ArpTerminationTableEntryCustomizerTest extends WriterCustomizerTest { + private static final String BD_CTX_NAME = "bd-test-instance"; + private static final String IFC_CTX_NAME = "ifc-test-instance"; + + private static final String BD_NAME = "testBD0"; + private static final int BD_ID = 111; + private static final String IFACE_NAME = "eth0"; + private static final int IFACE_ID = 123; + private ArpTerminationTableEntryCustomizer customizer; + private byte[] ipAddressRaw; + private byte[] ip6AddressRaw; + private byte[] physAddressRaw; + private PhysAddress physAddress; + private IpAddress ipAddress; + private IpAddress ip6Address; + private ArpTerminationTableEntry entry; + private ArpTerminationTableEntry ip6entry; + private InstanceIdentifier id; + + private static InstanceIdentifier getArpEntryId(final IpAddress ipAddress, + final PhysAddress physAddress) { + return InstanceIdentifier.create(BridgeDomains.class).child(BridgeDomain.class, new BridgeDomainKey(BD_NAME)) + .child(ArpTerminationTable.class) + .child(ArpTerminationTableEntry.class, new ArpTerminationTableEntryKey(ipAddress, physAddress)); + } + + @Override + public void setUpTest() throws Exception { + customizer = new ArpTerminationTableEntryCustomizer(api, new NamingContext("generatedBdName", BD_CTX_NAME)); + + ipAddressRaw = new byte[]{1, 2, 3, 4}; + ip6AddressRaw = new byte[]{32, 1, 13, -72, 10, 11, 18, -16, 0, 0, 0, 0, 0, 0, 0, 1}; + physAddressRaw = new byte[]{1, 2, 3, 4, 5, 6}; + physAddress = new PhysAddress("01:02:03:04:05:06"); + + ipAddress = new IpAddress(Ipv4AddressNoZone.getDefaultInstance("1.2.3.4")); + ip6Address = new IpAddress(Ipv6AddressNoZone.getDefaultInstance("2001:0db8:0a0b:12f0:0000:0000:0000:0001")); + entry = generateArpEntry(ipAddress, physAddress); + ip6entry = generateArpEntry(ip6Address, physAddress); + id = getArpEntryId(ipAddress, physAddress); + + defineMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME); + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); + } + + private void whenBdIpMacAddDelThenSuccess() { + doReturn(future(new BdIpMacAddDelReply())).when(api).bdIpMacAddDel(any(BdIpMacAddDel.class)); + } + + private void whenBdIpMacAddDelThenFailure() { + doReturn(failedFuture()).when(api).bdIpMacAddDel(any(BdIpMacAddDel.class)); + } + + private BdIpMacAddDel generateBdIpMacAddDelRequest(final byte[] ipAddress, final byte[] macAddress, + final byte isAdd) { + final BdIpMacAddDel request = new BdIpMacAddDel(); + request.ipAddress = ipAddress; + request.macAddress = macAddress; + request.bdId = BD_ID; + request.isAdd = isAdd; + return request; + } + + private ArpTerminationTableEntry generateArpEntry(final IpAddress ipAddress, final PhysAddress physAddress) { + final ArpTerminationTableEntryBuilder entry = new ArpTerminationTableEntryBuilder(); + entry.setKey(new ArpTerminationTableEntryKey(ipAddress, physAddress)); + entry.setPhysAddress(physAddress); + entry.setIpAddress(ipAddress); + return entry.build(); + } + + private void verifyBdIpMacAddDelWasInvoked(final BdIpMacAddDel expected) throws + VppInvocationException { + ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(BdIpMacAddDel.class); + verify(api).bdIpMacAddDel(argumentCaptor.capture()); + final BdIpMacAddDel actual = argumentCaptor.getValue(); + assertArrayEquals(expected.macAddress, actual.macAddress); + assertArrayEquals(expected.ipAddress, actual.ipAddress); + assertEquals(expected.bdId, actual.bdId); + assertEquals(expected.isAdd, actual.isAdd); + } + + @Test + public void testCreate() throws Exception { + whenBdIpMacAddDelThenSuccess(); + customizer.writeCurrentAttributes(id, entry, writeContext); + verifyBdIpMacAddDelWasInvoked(generateBdIpMacAddDelRequest(ipAddressRaw, physAddressRaw, (byte) 1)); + } + + @Test + public void testCreateIpv6() throws Exception { + whenBdIpMacAddDelThenSuccess(); + customizer.writeCurrentAttributes(id, ip6entry, writeContext); + verifyBdIpMacAddDelWasInvoked(generateBdIpMacAddDelRequest(ip6AddressRaw, physAddressRaw, (byte) 1)); + } + + @Test + public void testCreateFailed() throws Exception { + whenBdIpMacAddDelThenFailure(); + try { + customizer.writeCurrentAttributes(id, entry, writeContext); + } catch (WriteFailedException e) { + assertTrue(e.getCause() instanceof VppBaseCallException); + verifyBdIpMacAddDelWasInvoked(generateBdIpMacAddDelRequest(ipAddressRaw, physAddressRaw, (byte) 1)); + return; + } + fail("WriteFailedException.CreateFailedException was expected"); + } + + @Test(expected = UnsupportedOperationException.class) + public void testUpdate() throws Exception { + customizer.updateCurrentAttributes(InstanceIdentifier.create(ArpTerminationTableEntry.class), + mock(ArpTerminationTableEntry.class), + mock(ArpTerminationTableEntry.class), writeContext); + } + + @Test + public void testDelete() throws Exception { + whenBdIpMacAddDelThenSuccess(); + customizer.deleteCurrentAttributes(id, entry, writeContext); + verifyBdIpMacAddDelWasInvoked(generateBdIpMacAddDelRequest(ipAddressRaw, physAddressRaw, (byte) 0)); + } + + @Test + public void testDeleteIpv6() throws Exception { + whenBdIpMacAddDelThenSuccess(); + customizer.deleteCurrentAttributes(id, ip6entry, writeContext); + verifyBdIpMacAddDelWasInvoked(generateBdIpMacAddDelRequest(ip6AddressRaw, physAddressRaw, (byte) 0)); + } + + @Test + public void testDeleteFailed() throws Exception { + whenBdIpMacAddDelThenFailure(); + try { + customizer.deleteCurrentAttributes(id, entry, writeContext); + } catch (WriteFailedException e) { + assertTrue(e.getCause() instanceof VppBaseCallException); + verifyBdIpMacAddDelWasInvoked(generateBdIpMacAddDelRequest(ipAddressRaw, physAddressRaw, (byte) 0)); + return; + } + fail("WriteFailedException.DeleteFailedException was expected"); + } +} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/BridgeDomainCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/BridgeDomainCustomizerTest.java new file mode 100644 index 000000000..8bf7007fe --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/BridgeDomainCustomizerTest.java @@ -0,0 +1,338 @@ +/* + * 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.l2; + +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.never; +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.ByteDataTranslator; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.VppInvocationException; +import io.fd.vpp.jvpp.core.dto.BridgeDomainAddDel; +import io.fd.vpp.jvpp.core.dto.BridgeDomainAddDelReply; +import java.util.Arrays; +import javax.annotation.Nullable; +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.InterfacesBuilder; +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.opendaylight.params.xml.ns.yang.v3po.rev161214.BridgeDomains; +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.bridge.domains.BridgeDomain; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.BridgeDomainBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.BridgeDomainKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.interfaces._interface.L2Builder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.base.attributes.interconnection.BridgeBasedBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; + +public class BridgeDomainCustomizerTest extends WriterCustomizerTest implements ByteDataTranslator { + + private static final String BD_CTX_NAME = "bd-test-instance"; + private static final byte ADD_OR_UPDATE_BD = (byte) 1; + private BridgeDomainCustomizer customizer; + + @Nullable + private static Boolean intToBoolean(final int value) { + if (value == 0) { + return Boolean.FALSE; + } + if (value == 1) { + return Boolean.TRUE; + } + return null; + } + + private static KeyedInstanceIdentifier bdIdentifierForName( + final String bdName) { + return InstanceIdentifier.create(BridgeDomains.class).child(BridgeDomain.class, new BridgeDomainKey(bdName)); + } + + @Override + public void setUpTest() throws Exception { + customizer = new BridgeDomainCustomizer(api, new NamingContext("generatedBDName", BD_CTX_NAME)); + } + + private BridgeDomain generateBridgeDomain(final String bdName) { + final byte arpTerm = 0; + final byte flood = 1; + final byte forward = 0; + final byte learn = 1; + final byte uuf = 0; + return generateBridgeDomain(bdName, arpTerm, flood, forward, learn, uuf); + } + + private BridgeDomain generateBridgeDomain(final String bdName, final int arpTerm, final int flood, + final int forward, final int learn, final int uuf) { + return new BridgeDomainBuilder() + .setName(bdName) + .setArpTermination(intToBoolean(arpTerm)) + .setFlood(intToBoolean(flood)) + .setForward(intToBoolean(forward)) + .setLearn(intToBoolean(learn)) + .setUnknownUnicastFlood(intToBoolean(uuf)) + .build(); + } + + private void verifyBridgeDomainAddOrUpdateWasInvoked(final BridgeDomain bd, final int bdId) + throws VppInvocationException { + final BridgeDomainAddDel expected = new BridgeDomainAddDel(); + expected.arpTerm = booleanToByte(bd.isArpTermination()); + expected.flood = booleanToByte(bd.isFlood()); + expected.forward = booleanToByte(bd.isForward()); + expected.learn = booleanToByte(bd.isLearn()); + expected.uuFlood = booleanToByte(bd.isUnknownUnicastFlood()); + expected.isAdd = ADD_OR_UPDATE_BD; + expected.bdId = bdId; + verify(api).bridgeDomainAddDel(expected); + } + + private void verifyBridgeDomainDeleteWasInvoked(final int bdId) throws VppInvocationException { + final BridgeDomainAddDel expected = new BridgeDomainAddDel(); + expected.bdId = bdId; + verify(api).bridgeDomainAddDel(expected); + } + + private void whenBridgeDomainAddDelThenSuccess() { + when(api.bridgeDomainAddDel(any(BridgeDomainAddDel.class))).thenReturn(future(new BridgeDomainAddDelReply())); + } + + private void whenBridgeDomainAddDelThenFailure() { + doReturn(failedFuture()).when(api).bridgeDomainAddDel(any(BridgeDomainAddDel.class)); + } + + @Test + public void testAddBridgeDomain() throws Exception { + final int bdId = 1; + final String bdName = "bd1"; + final BridgeDomain bd = generateBridgeDomain(bdName); + noMappingDefined(mappingContext, bdName, BD_CTX_NAME); + + whenBridgeDomainAddDelThenSuccess(); + + customizer.writeCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext); + + verifyBridgeDomainAddOrUpdateWasInvoked(bd, bdId); + verify(mappingContext).put(mappingIid(bdName, BD_CTX_NAME), mapping(bdName, bdId).get()); + } + + @Test + public void testAddBridgeDomainPresentInBdContext() throws Exception { + final int bdId = 1; + final String bdName = "bd1"; + final BridgeDomain bd = generateBridgeDomain(bdName); + defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); + + whenBridgeDomainAddDelThenSuccess(); + + customizer.writeCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext); + + verifyBridgeDomainAddOrUpdateWasInvoked(bd, bdId); + verify(mappingContext).put(mappingIid(bdName, BD_CTX_NAME), mapping(bdName, bdId).get()); + } + + @Test + public void testAddBridgeDomainFailed() throws Exception { + final int bdId = 1; + final String bdName = "bd1"; + final BridgeDomain bd = generateBridgeDomain(bdName); + noMappingDefined(mappingContext, bdName, BD_CTX_NAME); + + whenBridgeDomainAddDelThenFailure(); + + try { + customizer.writeCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext); + } catch (WriteFailedException e) { + verifyBridgeDomainAddOrUpdateWasInvoked(bd, bdId); + return; + } + fail("WriteFailedException.CreateFailedException was expected"); + } + + @Test + public void testDeleteBridgeDomain() throws Exception { + final int bdId = 1; + final String bdName = "bd1"; + final BridgeDomain bd = generateBridgeDomain(bdName); + defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); + when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.absent()); + + whenBridgeDomainAddDelThenSuccess(); + + customizer.deleteCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext); + + verifyBridgeDomainDeleteWasInvoked(bdId); + } + + @Test + public void testDeleteReferencedBridgeDomain() throws Exception { + final int bdId = 1; + final String bdName = "bd1"; + final BridgeDomain bd = generateBridgeDomain(bdName); + defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); + when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.of( + new InterfacesBuilder().setInterface(Arrays.asList(l2ReferenceToBd("bd1"), l2ReferenceToBd("other-bd"))) + .build() + )); + + try { + customizer.deleteCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext); + } catch (IllegalStateException e) { + verify(api, never()).bridgeDomainAddDel(any(BridgeDomainAddDel.class)); + return; + } + fail("IllegalStateException was expected"); + } + + @Test + public void testDeleteReferencedPartialData() throws Exception { + final int bdId = 1; + final String bdName = "bd1"; + final BridgeDomain bd = generateBridgeDomain(bdName); + defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); + whenBridgeDomainAddDelThenSuccess(); + when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.of( + new InterfacesBuilder().setInterface(Arrays.asList(new InterfaceBuilder() + .addAugmentation(VppInterfaceAugmentation.class, new VppInterfaceAugmentationBuilder().build()) + .build())).build() + )); + + customizer.deleteCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext); + verifyBridgeDomainDeleteWasInvoked(bdId); + } + + private static Interface l2ReferenceToBd(final String bridgeDomain) { + return new InterfaceBuilder() + .addAugmentation(VppInterfaceAugmentation.class, new VppInterfaceAugmentationBuilder() + .setL2(new L2Builder() + .setInterconnection(new BridgeBasedBuilder() + .setBridgeDomain(bridgeDomain) + .build()) + .build()) + .build()) + .build(); + } + + @Test + public void testDeleteUnknownBridgeDomain() throws Exception { + final String bdName = "bd1"; + final BridgeDomain bd = generateBridgeDomain("bd1"); + noMappingDefined(mappingContext, bdName, BD_CTX_NAME); + when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.absent()); + + try { + customizer.deleteCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext); + } catch (IllegalArgumentException e) { + verify(api, never()).bridgeDomainAddDel(any(BridgeDomainAddDel.class)); + return; + } + fail("IllegalArgumentException was expected"); + } + + @Test + public void testDeleteBridgeDomainFailed() throws Exception { + final int bdId = 1; + final String bdName = "bd1"; + final BridgeDomain bd = generateBridgeDomain(bdName); + defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); + when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.absent()); + + whenBridgeDomainAddDelThenFailure(); + + try { + customizer.deleteCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext); + } catch (WriteFailedException e) { + verifyBridgeDomainDeleteWasInvoked(bdId); + return; + } + + fail("WriteFailedException.DeleteFailedException was expected"); + } + + @Test + public void testUpdateBridgeDomain() throws Exception { + final int bdId = 1; + final String bdName = "bd1"; + defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); + + final byte arpTermBefore = 1; + final byte floodBefore = 1; + final byte forwardBefore = 0; + final byte learnBefore = 1; + final byte uufBefore = 0; + + final BridgeDomain dataBefore = + generateBridgeDomain(bdName, arpTermBefore, floodBefore, forwardBefore, learnBefore, uufBefore); + final BridgeDomain dataAfter = + generateBridgeDomain(bdName, arpTermBefore ^ 1, floodBefore ^ 1, forwardBefore ^ 1, learnBefore ^ 1, + uufBefore ^ 1); + + whenBridgeDomainAddDelThenSuccess(); + + customizer + .updateCurrentAttributes(bdIdentifierForName(bdName), dataBefore, dataAfter, + writeContext); + verifyBridgeDomainAddOrUpdateWasInvoked(dataAfter, bdId); + } + + @Test + public void testUpdateUnknownBridgeDomain() throws Exception { + final String bdName = "bd1"; + final BridgeDomain bdBefore = generateBridgeDomain(bdName, 0, 1, 0, 1, 0); + final BridgeDomain bdAfter = generateBridgeDomain(bdName, 1, 1, 0, 1, 0); + noMappingDefined(mappingContext, bdName, BD_CTX_NAME); + + try { + customizer + .updateCurrentAttributes(bdIdentifierForName(bdName), bdBefore, bdAfter, + writeContext); + } catch (IllegalArgumentException e) { + verify(api, never()).bridgeDomainAddDel(any(BridgeDomainAddDel.class)); + return; + } + fail("IllegalArgumentException was expected"); + } + + @Test + public void testUpdateBridgeDomainFailed() throws Exception { + final int bdId = 1; + final String bdName = "bd1"; + final BridgeDomain bdBefore = generateBridgeDomain(bdName, 0, 1, 0, 1, 0); + final BridgeDomain bdAfter = generateBridgeDomain(bdName, 1, 1, 0, 1, 0); + defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); + + whenBridgeDomainAddDelThenFailure(); + + try { + customizer.updateCurrentAttributes(bdIdentifierForName(bdName), bdBefore, bdAfter, writeContext); + } catch (WriteFailedException e) { + verifyBridgeDomainAddOrUpdateWasInvoked(bdAfter, bdId); + return; + } + fail("IllegalStateException was expected"); + } + +} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/L2FibEntryCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/L2FibEntryCustomizerTest.java new file mode 100644 index 000000000..b00e9e7e2 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/L2FibEntryCustomizerTest.java @@ -0,0 +1,283 @@ +/* + * 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.l2; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +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.VppInvocationException; +import io.fd.vpp.jvpp.core.dto.L2FibAddDel; +import io.fd.vpp.jvpp.core.dto.L2FibAddDelReply; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +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.BridgeDomains; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.L2FibFilter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.L2FibForward; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.BridgeDomain; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.BridgeDomainKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.L2FibTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntryKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class L2FibEntryCustomizerTest extends WriterCustomizerTest { + private static final String BD_CTX_NAME = "bd-test-instance"; + private static final String IFC_CTX_NAME = "ifc-test-instance"; + + private static final String BD_NAME = "testBD0"; + private static final int BD_ID = 111; + private static final String IFACE_NAME = "eth0"; + private static final int IFACE_ID = 123; + private static final int NO_INTERFACE = -1; + + private L2FibEntryCustomizer customizer; + + private static InstanceIdentifier getL2FibEntryId(final PhysAddress address) { + return InstanceIdentifier.create(BridgeDomains.class).child(BridgeDomain.class, new BridgeDomainKey(BD_NAME)) + .child(L2FibTable.class).child(L2FibEntry.class, new L2FibEntryKey(address)); + } + + @Override + public void setUpTest() throws Exception { + defineMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME); + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); + + customizer = new L2FibEntryCustomizer( + api, + new NamingContext("generatedBdName", BD_CTX_NAME), + new NamingContext("generatedIfaceName", IFC_CTX_NAME)); + } + + private void whenL2FibAddDelThenSuccess() { + doReturn(future(new L2FibAddDelReply())).when(api).l2FibAddDel(any(L2FibAddDel.class)); + } + + private void whenL2FibAddDelThenFailure() { + doReturn(failedFuture()).when(api).l2FibAddDel(any(L2FibAddDel.class)); + } + + private L2FibAddDel generateL2FibAddDelFilterRequest(final long mac, final byte isAdd, final int ifaceIndex) { + final L2FibAddDel request = new L2FibAddDel(); + request.mac = mac; + request.bdId = BD_ID; + request.swIfIndex = ifaceIndex; + request.isAdd = isAdd; + if (isAdd == 1) { + request.staticMac = 1; + request.filterMac = 1; + } + return request; + } + + private L2FibAddDel generateL2FibAddDelForwardRequest(final long mac, final byte isAdd, final int ifaceIndex) { + final L2FibAddDel request = new L2FibAddDel(); + request.mac = mac; + request.bdId = BD_ID; + request.swIfIndex = ifaceIndex; + request.isAdd = isAdd; + if (isAdd == 1) { + request.staticMac = 1; + request.filterMac = 0; + } + return request; + } + + private L2FibEntry generateL2FibFilterEntry(final PhysAddress address) { + final L2FibEntryBuilder entry = new L2FibEntryBuilder(); + entry.setKey(new L2FibEntryKey(address)); + entry.setPhysAddress(address); + entry.setStaticConfig(true); + entry.setBridgedVirtualInterface(false); + entry.setAction(L2FibFilter.class); + return entry.build(); + } + + private L2FibEntry generateL2FibForwardEntry(final PhysAddress address) { + final L2FibEntryBuilder entry = new L2FibEntryBuilder(); + entry.setKey(new L2FibEntryKey(address)); + entry.setPhysAddress(address); + entry.setStaticConfig(true); + entry.setBridgedVirtualInterface(false); + entry.setAction(L2FibForward.class); + entry.setOutgoingInterface(IFACE_NAME); + return entry.build(); + } + + + private void verifyL2FibAddDelWasInvoked(final L2FibAddDel expected) throws + VppInvocationException { + ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(L2FibAddDel.class); + verify(api).l2FibAddDel(argumentCaptor.capture()); + final L2FibAddDel actual = argumentCaptor.getValue(); + assertEquals(expected.mac, actual.mac); + assertEquals(expected.bdId, actual.bdId); + assertEquals(expected.swIfIndex, actual.swIfIndex); + assertEquals(expected.isAdd, actual.isAdd); + assertEquals(expected.staticMac, actual.staticMac); + assertEquals(expected.filterMac, actual.filterMac); + } + + @Test + public void testCreateFilter() throws Exception { + final long address_vpp = 0x0102030405060000L; + final PhysAddress address = new PhysAddress("01:02:03:04:05:06"); + final L2FibEntry entry = generateL2FibFilterEntry(address); + final InstanceIdentifier id = getL2FibEntryId(address); + + whenL2FibAddDelThenSuccess(); + + customizer.writeCurrentAttributes(id, entry, writeContext); + + verifyL2FibAddDelWasInvoked(generateL2FibAddDelFilterRequest(address_vpp, (byte) 1, NO_INTERFACE)); + } + + @Test + public void testCreateForward() throws Exception { + final long address_vpp = 0x0102030405060000L; + final PhysAddress address = new PhysAddress("01:02:03:04:05:06"); + final L2FibEntry entry = generateL2FibForwardEntry(address); + final InstanceIdentifier id = getL2FibEntryId(address); + + whenL2FibAddDelThenSuccess(); + + customizer.writeCurrentAttributes(id, entry, writeContext); + + verifyL2FibAddDelWasInvoked(generateL2FibAddDelForwardRequest(address_vpp, (byte) 1, IFACE_ID)); + } + + @Test + public void testCreateFilterFailed() throws Exception { + final long address_vpp = 0x1122334455660000L; + final PhysAddress address = new PhysAddress("11:22:33:44:55:66"); + final L2FibEntry entry = generateL2FibFilterEntry(address); + final InstanceIdentifier id = getL2FibEntryId(address); + + whenL2FibAddDelThenFailure(); + + try { + customizer.writeCurrentAttributes(id, entry, writeContext); + } catch (WriteFailedException e) { + assertTrue(e.getCause() instanceof VppBaseCallException); + verifyL2FibAddDelWasInvoked(generateL2FibAddDelFilterRequest(address_vpp, (byte) 1, NO_INTERFACE)); + return; + } + fail("WriteFailedException.CreateFailedException was expected"); + } + + @Test + public void testCreateForwardFailed() throws Exception { + final long address_vpp = 0x1122334455660000L; + final PhysAddress address = new PhysAddress("11:22:33:44:55:66"); + final L2FibEntry entry = generateL2FibForwardEntry(address); + final InstanceIdentifier id = getL2FibEntryId(address); + + whenL2FibAddDelThenFailure(); + + try { + customizer.writeCurrentAttributes(id, entry, writeContext); + } catch (WriteFailedException e) { + assertTrue(e.getCause() instanceof VppBaseCallException); + verifyL2FibAddDelWasInvoked(generateL2FibAddDelForwardRequest(address_vpp, (byte) 1, IFACE_ID)); + return; + } + fail("WriteFailedException.CreateFailedException was expected"); + } + + @Test(expected = UnsupportedOperationException.class) + public void testUpdate() throws Exception { + customizer.updateCurrentAttributes(InstanceIdentifier.create(L2FibEntry.class), mock(L2FibEntry.class), + mock(L2FibEntry.class), writeContext); + } + + @Test + public void testDeleteFilter() throws Exception { + final long address_vpp = 0x1122334455660000L; + final PhysAddress address = new PhysAddress("11:22:33:44:55:66"); + final L2FibEntry entry = generateL2FibFilterEntry(address); + final InstanceIdentifier id = getL2FibEntryId(address); + + whenL2FibAddDelThenSuccess(); + + customizer.deleteCurrentAttributes(id, entry, writeContext); + + verifyL2FibAddDelWasInvoked(generateL2FibAddDelFilterRequest(address_vpp, (byte) 0, NO_INTERFACE)); + } + + @Test + public void testDeleteForward() throws Exception { + final long address_vpp = 0x1122334455660000L; + final PhysAddress address = new PhysAddress("11:22:33:44:55:66"); + final L2FibEntry entry = generateL2FibForwardEntry(address); + final InstanceIdentifier id = getL2FibEntryId(address); + + whenL2FibAddDelThenSuccess(); + + customizer.deleteCurrentAttributes(id, entry, writeContext); + + verifyL2FibAddDelWasInvoked(generateL2FibAddDelForwardRequest(address_vpp, (byte) 0, IFACE_ID)); + } + + + @Test + public void testDeleteFilterFailed() throws Exception { + final long address_vpp = 0x0102030405060000L; + final PhysAddress address = new PhysAddress("01:02:03:04:05:06"); + final L2FibEntry entry = generateL2FibFilterEntry(address); + final InstanceIdentifier id = getL2FibEntryId(address); + + whenL2FibAddDelThenFailure(); + + try { + customizer.deleteCurrentAttributes(id, entry, writeContext); + } catch (WriteFailedException e) { + assertTrue(e.getCause() instanceof VppBaseCallException); + verifyL2FibAddDelWasInvoked(generateL2FibAddDelFilterRequest(address_vpp, (byte) 0, NO_INTERFACE)); + return; + } + fail("WriteFailedException.DeleteFailedException was expected"); + } + + @Test + public void testDeleteForwardFailed() throws Exception { + final long address_vpp = 0x0102030405060000L; + final PhysAddress address = new PhysAddress("01:02:03:04:05:06"); + final L2FibEntry entry = generateL2FibForwardEntry(address); + final InstanceIdentifier id = getL2FibEntryId(address); + + whenL2FibAddDelThenFailure(); + + try { + customizer.deleteCurrentAttributes(id, entry, writeContext); + } catch (WriteFailedException e) { + assertTrue(e.getCause() instanceof VppBaseCallException); + verifyL2FibAddDelWasInvoked(generateL2FibAddDelForwardRequest(address_vpp, (byte) 0, IFACE_ID)); + return; + } + fail("WriteFailedException.DeleteFailedException was expected"); + } +} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2state/BridgeDomainCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2state/BridgeDomainCustomizerTest.java new file mode 100644 index 000000000..98e0cde08 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2state/BridgeDomainCustomizerTest.java @@ -0,0 +1,48 @@ +/* + * 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.l2state; + +import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.BridgeDomainsStateBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.state.BridgeDomain; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.state.BridgeDomainBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.state.BridgeDomainKey; + + +public class BridgeDomainCustomizerTest + extends ListReaderCustomizerTest { + + private NamingContext bdContext; + private NamingContext interfacesContext; + + public BridgeDomainCustomizerTest() { + super(BridgeDomain.class, BridgeDomainsStateBuilder.class); + } + + @Override + public void setUp() { + bdContext = new NamingContext("generatedBdName", "bd-test-instance"); + interfacesContext = new NamingContext("generatedIfaceName", "ifc-test-instance"); + } + + @Override + protected ReaderCustomizer initCustomizer() { + return new BridgeDomainCustomizer(api, bdContext); + } +} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2state/L2FibEntryCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2state/L2FibEntryCustomizerTest.java new file mode 100644 index 000000000..836653b28 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2state/L2FibEntryCustomizerTest.java @@ -0,0 +1,125 @@ +/* + * 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.l2state; + +import static org.junit.Assert.assertEquals; +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.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.ExecutionException; +import org.junit.Test; +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.BridgeDomains; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.BridgeDomainsState; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.L2FibForward; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.state.BridgeDomain; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.state.BridgeDomainKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.L2FibTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.L2FibTableBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntryKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import io.fd.vpp.jvpp.VppInvocationException; +import io.fd.vpp.jvpp.core.dto.L2FibTableDump; +import io.fd.vpp.jvpp.core.dto.L2FibTableEntry; +import io.fd.vpp.jvpp.core.dto.L2FibTableEntryReplyDump; + +public class L2FibEntryCustomizerTest extends ListReaderCustomizerTest { + + private static final String BD_NAME = "testBD0"; + private static final int BD_ID = 111; + private static final String IFACE_NAME = "eth0"; + private static final int IFACE_ID = 123; + private static final String BD_CTX_NAME = "bd-test-instance"; + private static final String IFC_CTX_NAME = "ifc-test-instance"; + private NamingContext bdContext; + private NamingContext interfacesContext; + + public L2FibEntryCustomizerTest() { + super(L2FibEntry.class, L2FibTableBuilder.class); + } + + @Override + public void setUp() { + bdContext = new NamingContext("generatedBdName", BD_CTX_NAME); + defineMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME); + interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); + } + + @Override + protected ReaderCustomizer initCustomizer() { + return new L2FibEntryCustomizer(api, bdContext, interfacesContext); + } + + private static InstanceIdentifier getL2FibEntryId(final String bdName, final PhysAddress address) { + return InstanceIdentifier.create(BridgeDomainsState.class).child(BridgeDomain.class, new BridgeDomainKey(bdName)) + .child(L2FibTable.class).child(L2FibEntry.class, new L2FibEntryKey(address)); + } + + private void whenL2FibTableDumpThenReturn(final List l2FibTableEntryList) + throws ExecutionException, InterruptedException, VppInvocationException { + final L2FibTableEntryReplyDump reply = new L2FibTableEntryReplyDump(); + reply.l2FibTableEntry = l2FibTableEntryList; + when(api.l2FibTableDump(any(L2FibTableDump.class))).thenReturn(future(reply)); + } + + @Test + public void testRead() throws Exception { + final long address_vpp = 0x0000010203040506L; + final PhysAddress address = new PhysAddress("01:02:03:04:05:06"); + defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); + + whenL2FibTableDumpThenReturn(Collections.singletonList(generateL2FibEntry(address_vpp))); + + final L2FibEntryBuilder builder = mock(L2FibEntryBuilder.class); + getCustomizer().readCurrentAttributes(getL2FibEntryId(BD_NAME, address), builder, ctx); + + verify(builder).setAction(L2FibForward.class); + verify(builder).setBridgedVirtualInterface(false); + verify(builder).setOutgoingInterface(IFACE_NAME); + verify(builder).setStaticConfig(false); + verify(builder).setPhysAddress(address); + verify(builder).setKey(new L2FibEntryKey(address)); + } + + private L2FibTableEntry generateL2FibEntry(final long mac) { + final L2FibTableEntry entry = new L2FibTableEntry(); + entry.mac = mac; + entry.swIfIndex = IFACE_ID; + return entry; + } + + @Test + public void testGetAllIds() throws Exception { + final long address_vpp = 0x0000112233445566L; + final PhysAddress address = new PhysAddress("11:22:33:44:55:66"); + + whenL2FibTableDumpThenReturn(Collections.singletonList(generateL2FibEntry(address_vpp))); + + final List ids = getCustomizer().getAllIds(getL2FibEntryId(BD_NAME, address), ctx); + assertEquals(1, ids.size()); + assertEquals(address, ids.get(0).getPhysAddress()); + } +} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2state/L2StateTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2state/L2StateTest.java new file mode 100644 index 000000000..9a0d0e4c8 --- /dev/null +++ b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2state/L2StateTest.java @@ -0,0 +1,216 @@ +/* + * 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.l2state; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +import com.google.common.base.Optional; +import com.google.common.collect.Iterables; +import com.google.common.collect.Multimap; +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.honeycomb.translate.MappingContext; +import io.fd.honeycomb.translate.ModificationCache; +import io.fd.honeycomb.translate.impl.read.GenericListReader; +import io.fd.honeycomb.translate.impl.read.registry.CompositeReaderRegistryBuilder; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.read.registry.ReaderRegistry; +import io.fd.vpp.jvpp.core.dto.BridgeDomainDetails; +import io.fd.vpp.jvpp.core.dto.BridgeDomainDetailsReplyDump; +import io.fd.vpp.jvpp.core.dto.BridgeDomainDump; +import io.fd.vpp.jvpp.core.dto.L2FibTableDump; +import io.fd.vpp.jvpp.core.dto.L2FibTableEntry; +import io.fd.vpp.jvpp.core.dto.L2FibTableEntryReplyDump; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import javax.annotation.Nonnull; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.BridgeDomainsState; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.BridgeDomainsStateBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.state.BridgeDomain; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.state.BridgeDomainBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domains.state.BridgeDomainKey; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class L2StateTest implements FutureProducer, NamingContextHelper { + + private static final String BD_CTX_NAME = "bd-test-instance"; + @Mock + private FutureJVppCore api; + @Mock + private ReadContext ctx; + @Mock + private MappingContext mappingContext; + + private NamingContext bdContext; + + private ReaderRegistry readerRegistry; + + private static InstanceIdentifier bridgeDomainsId; + + /** + * Create root VppState reader with all its children wired. + */ + private static ReaderRegistry getVppStateReader(@Nonnull final FutureJVppCore jVpp, + @Nonnull final NamingContext bdContext) { + final CompositeReaderRegistryBuilder registry = new CompositeReaderRegistryBuilder(); + + // BridgeDomains(Structural) + bridgeDomainsId = InstanceIdentifier.create(BridgeDomainsState.class); + registry.addStructuralReader(bridgeDomainsId, BridgeDomainsStateBuilder.class); + // BridgeDomain + registry.add(getBridgeDomainReader(jVpp, bdContext)); + return registry.build(); + } + + private static GenericListReader getBridgeDomainReader( + final @Nonnull FutureJVppCore jVpp, final @Nonnull NamingContext bdContext) { + final InstanceIdentifier bridgeDomainId = bridgeDomainsId.child(BridgeDomain.class); + return new GenericListReader<>(bridgeDomainId, new BridgeDomainCustomizer(jVpp, bdContext)); + } + + @Before + public void setUp() throws Exception { + initMocks(this); + final ModificationCache cache = new ModificationCache(); + doReturn(cache).when(ctx).getModificationCache(); + doReturn(mappingContext).when(ctx).getMappingContext(); + + bdContext = new NamingContext("generatedBdName", BD_CTX_NAME); + readerRegistry = getVppStateReader(api, bdContext); + } + + private void whenL2FibTableDumpThenReturn(final List entryList) { + final L2FibTableEntryReplyDump reply = new L2FibTableEntryReplyDump(); + reply.l2FibTableEntry = entryList; + when(api.l2FibTableDump(any(L2FibTableDump.class))).thenReturn(future(reply)); + } + + private void whenBridgeDomainDumpThenReturn(final List bdList) { + final BridgeDomainDetailsReplyDump reply = new BridgeDomainDetailsReplyDump(); + reply.bridgeDomainDetails = bdList; + + doAnswer(invocation -> { + BridgeDomainDump request = (BridgeDomainDump) invocation.getArguments()[0]; + if (request.bdId == -1) { + reply.bridgeDomainDetails = bdList; + } else { + reply.bridgeDomainDetails = Collections.singletonList(bdList.get(request.bdId)); + } + return future(reply); + }).when(api).bridgeDomainDump(any(BridgeDomainDump.class)); + } + + @Test + public void testReadAll() throws Exception { + final BridgeDomainDetails bridgeDomainDetails = new BridgeDomainDetails(); + final BridgeDomainDetails bridgeDomainDetails2 = new BridgeDomainDetails(); + bridgeDomainDetails2.bdId = 1; + + final List bdList = Arrays.asList(bridgeDomainDetails, bridgeDomainDetails2); + mockBdMapping(bridgeDomainDetails, "bd1"); + mockBdMapping(bridgeDomainDetails2, "bd2"); + + whenBridgeDomainDumpThenReturn(bdList); + + final Multimap, ? extends DataObject> dataObjects = + readerRegistry.readAll(ctx); + assertEquals(dataObjects.size(), 1); + final BridgeDomainsState dataObject = + (BridgeDomainsState) Iterables.getOnlyElement(dataObjects.get(Iterables.getOnlyElement(dataObjects.keySet()))); + assertEquals(2, dataObject.getBridgeDomain().size()); + } + + @Test + public void testReadBridgeDomains() throws Exception { + final BridgeDomainDetails details = new BridgeDomainDetails(); + whenBridgeDomainDumpThenReturn(Collections.singletonList(details)); + + mockBdMapping(details, "bdn1"); + BridgeDomainsState readRoot = (BridgeDomainsState) readerRegistry.read(InstanceIdentifier.create(BridgeDomainsState.class), ctx).get(); + + Optional read = + readerRegistry.read(InstanceIdentifier.create(BridgeDomainsState.class), ctx); + assertTrue(read.isPresent()); + assertEquals(readRoot.getBridgeDomain(), BridgeDomainsState.class.cast(read.get()).getBridgeDomain()); + } + + private void mockBdMapping(final BridgeDomainDetails bd, final String bdName) { + defineMapping(mappingContext, bdName, bd.bdId, BD_CTX_NAME); + } + + @Test + public void testReadBridgeDomainAll() throws Exception { + final BridgeDomainDetails details = new BridgeDomainDetails(); + whenBridgeDomainDumpThenReturn(Collections.singletonList(details)); + mockBdMapping(details, "bd2"); + + BridgeDomainsState readRoot = (BridgeDomainsState) readerRegistry.read(InstanceIdentifier.create(BridgeDomainsState.class), ctx).get(); + + final GenericListReader bridgeDomainReader = + getBridgeDomainReader(api, bdContext); + + final List read = + bridgeDomainReader.readList(InstanceIdentifier.create(BridgeDomainsState.class).child( + BridgeDomain.class), ctx); + + assertEquals(readRoot.getBridgeDomain(), read); + } + + @Test + public void testReadBridgeDomain() throws Exception { + final BridgeDomainDetails bd = new BridgeDomainDetails(); + bd.bdId = 0; + final String bdName = "bdn1"; + mockBdMapping(bd, bdName); + + whenBridgeDomainDumpThenReturn(Collections.singletonList(bd)); + + BridgeDomainsState readRoot = (BridgeDomainsState) readerRegistry.read(InstanceIdentifier.create(BridgeDomainsState.class), ctx).get(); + + final Optional read = + readerRegistry.read(InstanceIdentifier.create(BridgeDomainsState.class).child( + BridgeDomain.class, new BridgeDomainKey(bdName)), ctx); + + assertTrue(read.isPresent()); + assertEquals(readRoot.getBridgeDomain().stream().filter( + input -> input.getKey().getName().equals(bdName)).findFirst().get(), + read.get()); + } + + @Test(expected = ReadFailedException.class) + public void testReadBridgeDomainNotExisting() throws Exception { + final String nonExistingBdName = "NOT EXISTING"; + noMappingDefined(mappingContext, nonExistingBdName, BD_CTX_NAME); + + readerRegistry.read(InstanceIdentifier.create(BridgeDomainsState.class).child( + BridgeDomain.class, new BridgeDomainKey(nonExistingBdName)), ctx); + } +} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/rpc/CliInbandServiceTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/rpc/CliInbandServiceTest.java deleted file mode 100644 index baedba6fc..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/rpc/CliInbandServiceTest.java +++ /dev/null @@ -1,52 +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.rpc; - -import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; - -import io.fd.hc2vpp.common.test.util.FutureProducer; -import io.fd.vpp.jvpp.core.dto.CliInbandReply; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; -import org.junit.Test; -import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.CliInbandInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.CliInbandInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.CliInbandOutput; - -public class CliInbandServiceTest implements FutureProducer { - - @Mock - private FutureJVppCore api; - - @Test - public void testInvoke() throws Exception { - initMocks(this); - final String replyString = "CLI output"; - - final CliInbandService service = new CliInbandService(api); - final CliInbandReply reply = new CliInbandReply(); - reply.reply = replyString.getBytes(); - when(api.cliInband(any())).thenReturn(future(reply)); - - final CliInbandInput request = new CliInbandInputBuilder().setCmd("cmd").build(); - final CliInbandOutput response = service.invoke(request).toCompletableFuture().get(); - assertEquals(replyString, response.getReply()); - } -} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vpp/ArpTerminationTableEntryCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vpp/ArpTerminationTableEntryCustomizerTest.java deleted file mode 100644 index c1dd5b170..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vpp/ArpTerminationTableEntryCustomizerTest.java +++ /dev/null @@ -1,192 +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.vpp; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; - -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.VppInvocationException; -import io.fd.vpp.jvpp.core.dto.BdIpMacAddDel; -import io.fd.vpp.jvpp.core.dto.BdIpMacAddDelReply; -import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; -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 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domain.attributes.ArpTerminationTable; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domain.attributes.arp.termination.table.ArpTerminationTableEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domain.attributes.arp.termination.table.ArpTerminationTableEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.bridge.domain.attributes.arp.termination.table.ArpTerminationTableEntryKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.BridgeDomains; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.bridge.domains.BridgeDomain; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.bridge.domains.BridgeDomainKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class ArpTerminationTableEntryCustomizerTest extends WriterCustomizerTest { - private static final String BD_CTX_NAME = "bd-test-instance"; - private static final String IFC_CTX_NAME = "ifc-test-instance"; - - private static final String BD_NAME = "testBD0"; - private static final int BD_ID = 111; - private static final String IFACE_NAME = "eth0"; - private static final int IFACE_ID = 123; - private ArpTerminationTableEntryCustomizer customizer; - private byte[] ipAddressRaw; - private byte[] ip6AddressRaw; - private byte[] physAddressRaw; - private PhysAddress physAddress; - private IpAddress ipAddress; - private IpAddress ip6Address; - private ArpTerminationTableEntry entry; - private ArpTerminationTableEntry ip6entry; - private InstanceIdentifier id; - - private static InstanceIdentifier getArpEntryId(final IpAddress ipAddress, - final PhysAddress physAddress) { - return InstanceIdentifier.create(BridgeDomains.class).child(BridgeDomain.class, new BridgeDomainKey(BD_NAME)) - .child(ArpTerminationTable.class) - .child(ArpTerminationTableEntry.class, new ArpTerminationTableEntryKey(ipAddress, physAddress)); - } - - @Override - public void setUpTest() throws Exception { - customizer = new ArpTerminationTableEntryCustomizer(api, new NamingContext("generatedBdName", BD_CTX_NAME)); - - ipAddressRaw = new byte[]{1, 2, 3, 4}; - ip6AddressRaw = new byte[]{32, 1, 13, -72, 10, 11, 18, -16, 0, 0, 0, 0, 0, 0, 0, 1}; - physAddressRaw = new byte[]{1, 2, 3, 4, 5, 6}; - physAddress = new PhysAddress("01:02:03:04:05:06"); - - ipAddress = new IpAddress(Ipv4AddressNoZone.getDefaultInstance("1.2.3.4")); - ip6Address = new IpAddress(Ipv6AddressNoZone.getDefaultInstance("2001:0db8:0a0b:12f0:0000:0000:0000:0001")); - entry = generateArpEntry(ipAddress, physAddress); - ip6entry = generateArpEntry(ip6Address, physAddress); - id = getArpEntryId(ipAddress, physAddress); - - defineMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME); - defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); - } - - private void whenBdIpMacAddDelThenSuccess() { - doReturn(future(new BdIpMacAddDelReply())).when(api).bdIpMacAddDel(any(BdIpMacAddDel.class)); - } - - private void whenBdIpMacAddDelThenFailure() { - doReturn(failedFuture()).when(api).bdIpMacAddDel(any(BdIpMacAddDel.class)); - } - - private BdIpMacAddDel generateBdIpMacAddDelRequest(final byte[] ipAddress, final byte[] macAddress, - final byte isAdd) { - final BdIpMacAddDel request = new BdIpMacAddDel(); - request.ipAddress = ipAddress; - request.macAddress = macAddress; - request.bdId = BD_ID; - request.isAdd = isAdd; - return request; - } - - private ArpTerminationTableEntry generateArpEntry(final IpAddress ipAddress, final PhysAddress physAddress) { - final ArpTerminationTableEntryBuilder entry = new ArpTerminationTableEntryBuilder(); - entry.setKey(new ArpTerminationTableEntryKey(ipAddress, physAddress)); - entry.setPhysAddress(physAddress); - entry.setIpAddress(ipAddress); - return entry.build(); - } - - private void verifyBdIpMacAddDelWasInvoked(final BdIpMacAddDel expected) throws - VppInvocationException { - ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(BdIpMacAddDel.class); - verify(api).bdIpMacAddDel(argumentCaptor.capture()); - final BdIpMacAddDel actual = argumentCaptor.getValue(); - assertArrayEquals(expected.macAddress, actual.macAddress); - assertArrayEquals(expected.ipAddress, actual.ipAddress); - assertEquals(expected.bdId, actual.bdId); - assertEquals(expected.isAdd, actual.isAdd); - } - - @Test - public void testCreate() throws Exception { - whenBdIpMacAddDelThenSuccess(); - customizer.writeCurrentAttributes(id, entry, writeContext); - verifyBdIpMacAddDelWasInvoked(generateBdIpMacAddDelRequest(ipAddressRaw, physAddressRaw, (byte) 1)); - } - - @Test - public void testCreateIpv6() throws Exception { - whenBdIpMacAddDelThenSuccess(); - customizer.writeCurrentAttributes(id, ip6entry, writeContext); - verifyBdIpMacAddDelWasInvoked(generateBdIpMacAddDelRequest(ip6AddressRaw, physAddressRaw, (byte) 1)); - } - - @Test - public void testCreateFailed() throws Exception { - whenBdIpMacAddDelThenFailure(); - try { - customizer.writeCurrentAttributes(id, entry, writeContext); - } catch (WriteFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verifyBdIpMacAddDelWasInvoked(generateBdIpMacAddDelRequest(ipAddressRaw, physAddressRaw, (byte) 1)); - return; - } - fail("WriteFailedException.CreateFailedException was expected"); - } - - @Test(expected = UnsupportedOperationException.class) - public void testUpdate() throws Exception { - customizer.updateCurrentAttributes(InstanceIdentifier.create(ArpTerminationTableEntry.class), - mock(ArpTerminationTableEntry.class), - mock(ArpTerminationTableEntry.class), writeContext); - } - - @Test - public void testDelete() throws Exception { - whenBdIpMacAddDelThenSuccess(); - customizer.deleteCurrentAttributes(id, entry, writeContext); - verifyBdIpMacAddDelWasInvoked(generateBdIpMacAddDelRequest(ipAddressRaw, physAddressRaw, (byte) 0)); - } - - @Test - public void testDeleteIpv6() throws Exception { - whenBdIpMacAddDelThenSuccess(); - customizer.deleteCurrentAttributes(id, ip6entry, writeContext); - verifyBdIpMacAddDelWasInvoked(generateBdIpMacAddDelRequest(ip6AddressRaw, physAddressRaw, (byte) 0)); - } - - @Test - public void testDeleteFailed() throws Exception { - whenBdIpMacAddDelThenFailure(); - try { - customizer.deleteCurrentAttributes(id, entry, writeContext); - } catch (WriteFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verifyBdIpMacAddDelWasInvoked(generateBdIpMacAddDelRequest(ipAddressRaw, physAddressRaw, (byte) 0)); - return; - } - fail("WriteFailedException.DeleteFailedException was expected"); - } -} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vpp/BridgeDomainCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vpp/BridgeDomainCustomizerTest.java deleted file mode 100644 index 25b398fab..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vpp/BridgeDomainCustomizerTest.java +++ /dev/null @@ -1,338 +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.vpp; - -import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.never; -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.ByteDataTranslator; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.vpp.jvpp.VppInvocationException; -import io.fd.vpp.jvpp.core.dto.BridgeDomainAddDel; -import io.fd.vpp.jvpp.core.dto.BridgeDomainAddDelReply; -import java.util.Arrays; -import javax.annotation.Nullable; -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.InterfacesBuilder; -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.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.L2Builder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.base.attributes.interconnection.BridgeBasedBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.BridgeDomains; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.bridge.domains.BridgeDomain; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.bridge.domains.BridgeDomainBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.bridge.domains.BridgeDomainKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; - -public class BridgeDomainCustomizerTest extends WriterCustomizerTest implements ByteDataTranslator { - - private static final String BD_CTX_NAME = "bd-test-instance"; - private static final byte ADD_OR_UPDATE_BD = (byte) 1; - private BridgeDomainCustomizer customizer; - - @Nullable - private static Boolean intToBoolean(final int value) { - if (value == 0) { - return Boolean.FALSE; - } - if (value == 1) { - return Boolean.TRUE; - } - return null; - } - - private static KeyedInstanceIdentifier bdIdentifierForName( - final String bdName) { - return InstanceIdentifier.create(BridgeDomains.class).child(BridgeDomain.class, new BridgeDomainKey(bdName)); - } - - @Override - public void setUpTest() throws Exception { - customizer = new BridgeDomainCustomizer(api, new NamingContext("generatedBDName", BD_CTX_NAME)); - } - - private BridgeDomain generateBridgeDomain(final String bdName) { - final byte arpTerm = 0; - final byte flood = 1; - final byte forward = 0; - final byte learn = 1; - final byte uuf = 0; - return generateBridgeDomain(bdName, arpTerm, flood, forward, learn, uuf); - } - - private BridgeDomain generateBridgeDomain(final String bdName, final int arpTerm, final int flood, - final int forward, final int learn, final int uuf) { - return new BridgeDomainBuilder() - .setName(bdName) - .setArpTermination(intToBoolean(arpTerm)) - .setFlood(intToBoolean(flood)) - .setForward(intToBoolean(forward)) - .setLearn(intToBoolean(learn)) - .setUnknownUnicastFlood(intToBoolean(uuf)) - .build(); - } - - private void verifyBridgeDomainAddOrUpdateWasInvoked(final BridgeDomain bd, final int bdId) - throws VppInvocationException { - final BridgeDomainAddDel expected = new BridgeDomainAddDel(); - expected.arpTerm = booleanToByte(bd.isArpTermination()); - expected.flood = booleanToByte(bd.isFlood()); - expected.forward = booleanToByte(bd.isForward()); - expected.learn = booleanToByte(bd.isLearn()); - expected.uuFlood = booleanToByte(bd.isUnknownUnicastFlood()); - expected.isAdd = ADD_OR_UPDATE_BD; - expected.bdId = bdId; - verify(api).bridgeDomainAddDel(expected); - } - - private void verifyBridgeDomainDeleteWasInvoked(final int bdId) throws VppInvocationException { - final BridgeDomainAddDel expected = new BridgeDomainAddDel(); - expected.bdId = bdId; - verify(api).bridgeDomainAddDel(expected); - } - - private void whenBridgeDomainAddDelThenSuccess() { - when(api.bridgeDomainAddDel(any(BridgeDomainAddDel.class))).thenReturn(future(new BridgeDomainAddDelReply())); - } - - private void whenBridgeDomainAddDelThenFailure() { - doReturn(failedFuture()).when(api).bridgeDomainAddDel(any(BridgeDomainAddDel.class)); - } - - @Test - public void testAddBridgeDomain() throws Exception { - final int bdId = 1; - final String bdName = "bd1"; - final BridgeDomain bd = generateBridgeDomain(bdName); - noMappingDefined(mappingContext, bdName, BD_CTX_NAME); - - whenBridgeDomainAddDelThenSuccess(); - - customizer.writeCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext); - - verifyBridgeDomainAddOrUpdateWasInvoked(bd, bdId); - verify(mappingContext).put(mappingIid(bdName, BD_CTX_NAME), mapping(bdName, bdId).get()); - } - - @Test - public void testAddBridgeDomainPresentInBdContext() throws Exception { - final int bdId = 1; - final String bdName = "bd1"; - final BridgeDomain bd = generateBridgeDomain(bdName); - defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); - - whenBridgeDomainAddDelThenSuccess(); - - customizer.writeCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext); - - verifyBridgeDomainAddOrUpdateWasInvoked(bd, bdId); - verify(mappingContext).put(mappingIid(bdName, BD_CTX_NAME), mapping(bdName, bdId).get()); - } - - @Test - public void testAddBridgeDomainFailed() throws Exception { - final int bdId = 1; - final String bdName = "bd1"; - final BridgeDomain bd = generateBridgeDomain(bdName); - noMappingDefined(mappingContext, bdName, BD_CTX_NAME); - - whenBridgeDomainAddDelThenFailure(); - - try { - customizer.writeCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext); - } catch (WriteFailedException e) { - verifyBridgeDomainAddOrUpdateWasInvoked(bd, bdId); - return; - } - fail("WriteFailedException.CreateFailedException was expected"); - } - - @Test - public void testDeleteBridgeDomain() throws Exception { - final int bdId = 1; - final String bdName = "bd1"; - final BridgeDomain bd = generateBridgeDomain(bdName); - defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); - when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.absent()); - - whenBridgeDomainAddDelThenSuccess(); - - customizer.deleteCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext); - - verifyBridgeDomainDeleteWasInvoked(bdId); - } - - @Test - public void testDeleteReferencedBridgeDomain() throws Exception { - final int bdId = 1; - final String bdName = "bd1"; - final BridgeDomain bd = generateBridgeDomain(bdName); - defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); - when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.of( - new InterfacesBuilder().setInterface(Arrays.asList(l2ReferenceToBd("bd1"), l2ReferenceToBd("other-bd"))) - .build() - )); - - try { - customizer.deleteCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext); - } catch (IllegalStateException e) { - verify(api, never()).bridgeDomainAddDel(any(BridgeDomainAddDel.class)); - return; - } - fail("IllegalStateException was expected"); - } - - @Test - public void testDeleteReferencedPartialData() throws Exception { - final int bdId = 1; - final String bdName = "bd1"; - final BridgeDomain bd = generateBridgeDomain(bdName); - defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); - whenBridgeDomainAddDelThenSuccess(); - when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.of( - new InterfacesBuilder().setInterface(Arrays.asList(new InterfaceBuilder() - .addAugmentation(VppInterfaceAugmentation.class, new VppInterfaceAugmentationBuilder().build()) - .build())).build() - )); - - customizer.deleteCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext); - verifyBridgeDomainDeleteWasInvoked(bdId); - } - - private static Interface l2ReferenceToBd(final String bridgeDomain) { - return new InterfaceBuilder() - .addAugmentation(VppInterfaceAugmentation.class, new VppInterfaceAugmentationBuilder() - .setL2(new L2Builder() - .setInterconnection(new BridgeBasedBuilder() - .setBridgeDomain(bridgeDomain) - .build()) - .build()) - .build()) - .build(); - } - - @Test - public void testDeleteUnknownBridgeDomain() throws Exception { - final String bdName = "bd1"; - final BridgeDomain bd = generateBridgeDomain("bd1"); - noMappingDefined(mappingContext, bdName, BD_CTX_NAME); - when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.absent()); - - try { - customizer.deleteCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext); - } catch (IllegalArgumentException e) { - verify(api, never()).bridgeDomainAddDel(any(BridgeDomainAddDel.class)); - return; - } - fail("IllegalArgumentException was expected"); - } - - @Test - public void testDeleteBridgeDomainFailed() throws Exception { - final int bdId = 1; - final String bdName = "bd1"; - final BridgeDomain bd = generateBridgeDomain(bdName); - defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); - when(writeContext.readAfter(InstanceIdentifier.create(Interfaces.class))).thenReturn(Optional.absent()); - - whenBridgeDomainAddDelThenFailure(); - - try { - customizer.deleteCurrentAttributes(bdIdentifierForName(bdName), bd, writeContext); - } catch (WriteFailedException e) { - verifyBridgeDomainDeleteWasInvoked(bdId); - return; - } - - fail("WriteFailedException.DeleteFailedException was expected"); - } - - @Test - public void testUpdateBridgeDomain() throws Exception { - final int bdId = 1; - final String bdName = "bd1"; - defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); - - final byte arpTermBefore = 1; - final byte floodBefore = 1; - final byte forwardBefore = 0; - final byte learnBefore = 1; - final byte uufBefore = 0; - - final BridgeDomain dataBefore = - generateBridgeDomain(bdName, arpTermBefore, floodBefore, forwardBefore, learnBefore, uufBefore); - final BridgeDomain dataAfter = - generateBridgeDomain(bdName, arpTermBefore ^ 1, floodBefore ^ 1, forwardBefore ^ 1, learnBefore ^ 1, - uufBefore ^ 1); - - whenBridgeDomainAddDelThenSuccess(); - - customizer - .updateCurrentAttributes(bdIdentifierForName(bdName), dataBefore, dataAfter, - writeContext); - verifyBridgeDomainAddOrUpdateWasInvoked(dataAfter, bdId); - } - - @Test - public void testUpdateUnknownBridgeDomain() throws Exception { - final String bdName = "bd1"; - final BridgeDomain bdBefore = generateBridgeDomain(bdName, 0, 1, 0, 1, 0); - final BridgeDomain bdAfter = generateBridgeDomain(bdName, 1, 1, 0, 1, 0); - noMappingDefined(mappingContext, bdName, BD_CTX_NAME); - - try { - customizer - .updateCurrentAttributes(bdIdentifierForName(bdName), bdBefore, bdAfter, - writeContext); - } catch (IllegalArgumentException e) { - verify(api, never()).bridgeDomainAddDel(any(BridgeDomainAddDel.class)); - return; - } - fail("IllegalArgumentException was expected"); - } - - @Test - public void testUpdateBridgeDomainFailed() throws Exception { - final int bdId = 1; - final String bdName = "bd1"; - final BridgeDomain bdBefore = generateBridgeDomain(bdName, 0, 1, 0, 1, 0); - final BridgeDomain bdAfter = generateBridgeDomain(bdName, 1, 1, 0, 1, 0); - defineMapping(mappingContext, bdName, bdId, BD_CTX_NAME); - - whenBridgeDomainAddDelThenFailure(); - - try { - customizer.updateCurrentAttributes(bdIdentifierForName(bdName), bdBefore, bdAfter, writeContext); - } catch (WriteFailedException e) { - verifyBridgeDomainAddOrUpdateWasInvoked(bdAfter, bdId); - return; - } - fail("IllegalStateException was expected"); - } - -} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vpp/L2FibEntryCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vpp/L2FibEntryCustomizerTest.java deleted file mode 100644 index 551b0879e..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vpp/L2FibEntryCustomizerTest.java +++ /dev/null @@ -1,283 +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.vpp; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; - -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.VppInvocationException; -import io.fd.vpp.jvpp.core.dto.L2FibAddDel; -import io.fd.vpp.jvpp.core.dto.L2FibAddDelReply; -import org.junit.Test; -import org.mockito.ArgumentCaptor; -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.L2FibFilter; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.L2FibForward; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.L2FibTable; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntryKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.BridgeDomains; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.bridge.domains.BridgeDomain; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.bridge.domains.BridgeDomainKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class L2FibEntryCustomizerTest extends WriterCustomizerTest { - private static final String BD_CTX_NAME = "bd-test-instance"; - private static final String IFC_CTX_NAME = "ifc-test-instance"; - - private static final String BD_NAME = "testBD0"; - private static final int BD_ID = 111; - private static final String IFACE_NAME = "eth0"; - private static final int IFACE_ID = 123; - private static final int NO_INTERFACE = -1; - - private L2FibEntryCustomizer customizer; - - private static InstanceIdentifier getL2FibEntryId(final PhysAddress address) { - return InstanceIdentifier.create(BridgeDomains.class).child(BridgeDomain.class, new BridgeDomainKey(BD_NAME)) - .child(L2FibTable.class).child(L2FibEntry.class, new L2FibEntryKey(address)); - } - - @Override - public void setUpTest() throws Exception { - defineMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME); - defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); - - customizer = new L2FibEntryCustomizer( - api, - new NamingContext("generatedBdName", BD_CTX_NAME), - new NamingContext("generatedIfaceName", IFC_CTX_NAME)); - } - - private void whenL2FibAddDelThenSuccess() { - doReturn(future(new L2FibAddDelReply())).when(api).l2FibAddDel(any(L2FibAddDel.class)); - } - - private void whenL2FibAddDelThenFailure() { - doReturn(failedFuture()).when(api).l2FibAddDel(any(L2FibAddDel.class)); - } - - private L2FibAddDel generateL2FibAddDelFilterRequest(final long mac, final byte isAdd, final int ifaceIndex) { - final L2FibAddDel request = new L2FibAddDel(); - request.mac = mac; - request.bdId = BD_ID; - request.swIfIndex = ifaceIndex; - request.isAdd = isAdd; - if (isAdd == 1) { - request.staticMac = 1; - request.filterMac = 1; - } - return request; - } - - private L2FibAddDel generateL2FibAddDelForwardRequest(final long mac, final byte isAdd, final int ifaceIndex) { - final L2FibAddDel request = new L2FibAddDel(); - request.mac = mac; - request.bdId = BD_ID; - request.swIfIndex = ifaceIndex; - request.isAdd = isAdd; - if (isAdd == 1) { - request.staticMac = 1; - request.filterMac = 0; - } - return request; - } - - private L2FibEntry generateL2FibFilterEntry(final PhysAddress address) { - final L2FibEntryBuilder entry = new L2FibEntryBuilder(); - entry.setKey(new L2FibEntryKey(address)); - entry.setPhysAddress(address); - entry.setStaticConfig(true); - entry.setBridgedVirtualInterface(false); - entry.setAction(L2FibFilter.class); - return entry.build(); - } - - private L2FibEntry generateL2FibForwardEntry(final PhysAddress address) { - final L2FibEntryBuilder entry = new L2FibEntryBuilder(); - entry.setKey(new L2FibEntryKey(address)); - entry.setPhysAddress(address); - entry.setStaticConfig(true); - entry.setBridgedVirtualInterface(false); - entry.setAction(L2FibForward.class); - entry.setOutgoingInterface(IFACE_NAME); - return entry.build(); - } - - - private void verifyL2FibAddDelWasInvoked(final L2FibAddDel expected) throws - VppInvocationException { - ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(L2FibAddDel.class); - verify(api).l2FibAddDel(argumentCaptor.capture()); - final L2FibAddDel actual = argumentCaptor.getValue(); - assertEquals(expected.mac, actual.mac); - assertEquals(expected.bdId, actual.bdId); - assertEquals(expected.swIfIndex, actual.swIfIndex); - assertEquals(expected.isAdd, actual.isAdd); - assertEquals(expected.staticMac, actual.staticMac); - assertEquals(expected.filterMac, actual.filterMac); - } - - @Test - public void testCreateFilter() throws Exception { - final long address_vpp = 0x0102030405060000L; - final PhysAddress address = new PhysAddress("01:02:03:04:05:06"); - final L2FibEntry entry = generateL2FibFilterEntry(address); - final InstanceIdentifier id = getL2FibEntryId(address); - - whenL2FibAddDelThenSuccess(); - - customizer.writeCurrentAttributes(id, entry, writeContext); - - verifyL2FibAddDelWasInvoked(generateL2FibAddDelFilterRequest(address_vpp, (byte) 1, NO_INTERFACE)); - } - - @Test - public void testCreateForward() throws Exception { - final long address_vpp = 0x0102030405060000L; - final PhysAddress address = new PhysAddress("01:02:03:04:05:06"); - final L2FibEntry entry = generateL2FibForwardEntry(address); - final InstanceIdentifier id = getL2FibEntryId(address); - - whenL2FibAddDelThenSuccess(); - - customizer.writeCurrentAttributes(id, entry, writeContext); - - verifyL2FibAddDelWasInvoked(generateL2FibAddDelForwardRequest(address_vpp, (byte) 1, IFACE_ID)); - } - - @Test - public void testCreateFilterFailed() throws Exception { - final long address_vpp = 0x1122334455660000L; - final PhysAddress address = new PhysAddress("11:22:33:44:55:66"); - final L2FibEntry entry = generateL2FibFilterEntry(address); - final InstanceIdentifier id = getL2FibEntryId(address); - - whenL2FibAddDelThenFailure(); - - try { - customizer.writeCurrentAttributes(id, entry, writeContext); - } catch (WriteFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verifyL2FibAddDelWasInvoked(generateL2FibAddDelFilterRequest(address_vpp, (byte) 1, NO_INTERFACE)); - return; - } - fail("WriteFailedException.CreateFailedException was expected"); - } - - @Test - public void testCreateForwardFailed() throws Exception { - final long address_vpp = 0x1122334455660000L; - final PhysAddress address = new PhysAddress("11:22:33:44:55:66"); - final L2FibEntry entry = generateL2FibForwardEntry(address); - final InstanceIdentifier id = getL2FibEntryId(address); - - whenL2FibAddDelThenFailure(); - - try { - customizer.writeCurrentAttributes(id, entry, writeContext); - } catch (WriteFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verifyL2FibAddDelWasInvoked(generateL2FibAddDelForwardRequest(address_vpp, (byte) 1, IFACE_ID)); - return; - } - fail("WriteFailedException.CreateFailedException was expected"); - } - - @Test(expected = UnsupportedOperationException.class) - public void testUpdate() throws Exception { - customizer.updateCurrentAttributes(InstanceIdentifier.create(L2FibEntry.class), mock(L2FibEntry.class), - mock(L2FibEntry.class), writeContext); - } - - @Test - public void testDeleteFilter() throws Exception { - final long address_vpp = 0x1122334455660000L; - final PhysAddress address = new PhysAddress("11:22:33:44:55:66"); - final L2FibEntry entry = generateL2FibFilterEntry(address); - final InstanceIdentifier id = getL2FibEntryId(address); - - whenL2FibAddDelThenSuccess(); - - customizer.deleteCurrentAttributes(id, entry, writeContext); - - verifyL2FibAddDelWasInvoked(generateL2FibAddDelFilterRequest(address_vpp, (byte) 0, NO_INTERFACE)); - } - - @Test - public void testDeleteForward() throws Exception { - final long address_vpp = 0x1122334455660000L; - final PhysAddress address = new PhysAddress("11:22:33:44:55:66"); - final L2FibEntry entry = generateL2FibForwardEntry(address); - final InstanceIdentifier id = getL2FibEntryId(address); - - whenL2FibAddDelThenSuccess(); - - customizer.deleteCurrentAttributes(id, entry, writeContext); - - verifyL2FibAddDelWasInvoked(generateL2FibAddDelForwardRequest(address_vpp, (byte) 0, IFACE_ID)); - } - - - @Test - public void testDeleteFilterFailed() throws Exception { - final long address_vpp = 0x0102030405060000L; - final PhysAddress address = new PhysAddress("01:02:03:04:05:06"); - final L2FibEntry entry = generateL2FibFilterEntry(address); - final InstanceIdentifier id = getL2FibEntryId(address); - - whenL2FibAddDelThenFailure(); - - try { - customizer.deleteCurrentAttributes(id, entry, writeContext); - } catch (WriteFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verifyL2FibAddDelWasInvoked(generateL2FibAddDelFilterRequest(address_vpp, (byte) 0, NO_INTERFACE)); - return; - } - fail("WriteFailedException.DeleteFailedException was expected"); - } - - @Test - public void testDeleteForwardFailed() throws Exception { - final long address_vpp = 0x0102030405060000L; - final PhysAddress address = new PhysAddress("01:02:03:04:05:06"); - final L2FibEntry entry = generateL2FibForwardEntry(address); - final InstanceIdentifier id = getL2FibEntryId(address); - - whenL2FibAddDelThenFailure(); - - try { - customizer.deleteCurrentAttributes(id, entry, writeContext); - } catch (WriteFailedException e) { - assertTrue(e.getCause() instanceof VppBaseCallException); - verifyL2FibAddDelWasInvoked(generateL2FibAddDelForwardRequest(address_vpp, (byte) 0, IFACE_ID)); - return; - } - fail("WriteFailedException.DeleteFailedException was expected"); - } -} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vppstate/BridgeDomainCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vppstate/BridgeDomainCustomizerTest.java deleted file mode 100644 index 0fbdb986e..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vppstate/BridgeDomainCustomizerTest.java +++ /dev/null @@ -1,47 +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.vppstate; - -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.BridgeDomainsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.bridge.domains.BridgeDomain; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.bridge.domains.BridgeDomainBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.bridge.domains.BridgeDomainKey; - -public class BridgeDomainCustomizerTest - extends ListReaderCustomizerTest { - - private NamingContext bdContext; - private NamingContext interfacesContext; - - public BridgeDomainCustomizerTest() { - super(BridgeDomain.class, BridgeDomainsBuilder.class); - } - - @Override - public void setUp() { - bdContext = new NamingContext("generatedBdName", "bd-test-instance"); - interfacesContext = new NamingContext("generatedIfaceName", "ifc-test-instance"); - } - - @Override - protected ReaderCustomizer initCustomizer() { - return new BridgeDomainCustomizer(api, bdContext); - } -} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vppstate/L2FibEntryCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vppstate/L2FibEntryCustomizerTest.java deleted file mode 100644 index 94a654c15..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vppstate/L2FibEntryCustomizerTest.java +++ /dev/null @@ -1,124 +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.vppstate; - -import static org.junit.Assert.assertEquals; -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.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.ExecutionException; -import org.junit.Test; -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.L2FibForward; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.L2FibTable; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.L2FibTableBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntryKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.BridgeDomains; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.bridge.domains.BridgeDomain; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.bridge.domains.BridgeDomainKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.VppInvocationException; -import io.fd.vpp.jvpp.core.dto.L2FibTableDump; -import io.fd.vpp.jvpp.core.dto.L2FibTableEntry; -import io.fd.vpp.jvpp.core.dto.L2FibTableEntryReplyDump; - -public class L2FibEntryCustomizerTest extends ListReaderCustomizerTest { - - private static final String BD_NAME = "testBD0"; - private static final int BD_ID = 111; - private static final String IFACE_NAME = "eth0"; - private static final int IFACE_ID = 123; - private static final String BD_CTX_NAME = "bd-test-instance"; - private static final String IFC_CTX_NAME = "ifc-test-instance"; - private NamingContext bdContext; - private NamingContext interfacesContext; - - public L2FibEntryCustomizerTest() { - super(L2FibEntry.class, L2FibTableBuilder.class); - } - - @Override - public void setUp() { - bdContext = new NamingContext("generatedBdName", BD_CTX_NAME); - defineMapping(mappingContext, BD_NAME, BD_ID, BD_CTX_NAME); - interfacesContext = new NamingContext("generatedIfaceName", IFC_CTX_NAME); - } - - @Override - protected ReaderCustomizer initCustomizer() { - return new L2FibEntryCustomizer(api, bdContext, interfacesContext); - } - - private static InstanceIdentifier getL2FibEntryId(final String bdName, final PhysAddress address) { - return InstanceIdentifier.create(BridgeDomains.class).child(BridgeDomain.class, new BridgeDomainKey(bdName)) - .child(L2FibTable.class).child(L2FibEntry.class, new L2FibEntryKey(address)); - } - - private void whenL2FibTableDumpThenReturn(final List l2FibTableEntryList) - throws ExecutionException, InterruptedException, VppInvocationException { - final L2FibTableEntryReplyDump reply = new L2FibTableEntryReplyDump(); - reply.l2FibTableEntry = l2FibTableEntryList; - when(api.l2FibTableDump(any(L2FibTableDump.class))).thenReturn(future(reply)); - } - - @Test - public void testRead() throws Exception { - final long address_vpp = 0x0000010203040506L; - final PhysAddress address = new PhysAddress("01:02:03:04:05:06"); - defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME); - - whenL2FibTableDumpThenReturn(Collections.singletonList(generateL2FibEntry(address_vpp))); - - final L2FibEntryBuilder builder = mock(L2FibEntryBuilder.class); - getCustomizer().readCurrentAttributes(getL2FibEntryId(BD_NAME, address), builder, ctx); - - verify(builder).setAction(L2FibForward.class); - verify(builder).setBridgedVirtualInterface(false); - verify(builder).setOutgoingInterface(IFACE_NAME); - verify(builder).setStaticConfig(false); - verify(builder).setPhysAddress(address); - verify(builder).setKey(new L2FibEntryKey(address)); - } - - private L2FibTableEntry generateL2FibEntry(final long mac) { - final L2FibTableEntry entry = new L2FibTableEntry(); - entry.mac = mac; - entry.swIfIndex = IFACE_ID; - return entry; - } - - @Test - public void testGetAllIds() throws Exception { - final long address_vpp = 0x0000112233445566L; - final PhysAddress address = new PhysAddress("11:22:33:44:55:66"); - - whenL2FibTableDumpThenReturn(Collections.singletonList(generateL2FibEntry(address_vpp))); - - final List ids = getCustomizer().getAllIds(getL2FibEntryId(BD_NAME, address), ctx); - assertEquals(1, ids.size()); - assertEquals(address, ids.get(0).getPhysAddress()); - } -} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vppstate/VersionCustomizerTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vppstate/VersionCustomizerTest.java deleted file mode 100644 index 2f12cbde1..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vppstate/VersionCustomizerTest.java +++ /dev/null @@ -1,60 +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.vppstate; - -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; -import io.fd.hc2vpp.common.test.read.ReaderCustomizerTest; -import io.fd.vpp.jvpp.core.dto.ShowVersion; -import io.fd.vpp.jvpp.core.dto.ShowVersionReply; -import io.fd.vpp.jvpp.dto.ControlPing; -import io.fd.vpp.jvpp.dto.ControlPingReply; -import org.junit.Test; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppStateBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.Version; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.VersionBuilder; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public class VersionCustomizerTest extends ReaderCustomizerTest { - - public VersionCustomizerTest() { - super(Version.class, VppStateBuilder.class); - } - - @Override - protected ReaderCustomizer initCustomizer() { - return new VersionCustomizer(api); - } - - @Test - public void testReadCurrentAttributes() throws Exception { - final ShowVersionReply reply = new ShowVersionReply(); - reply.version = new byte[] {}; - reply.program = new byte[] {}; - reply.buildDate = new byte[] {}; - reply.buildDirectory = new byte[] {}; - - when(api.showVersion(any(ShowVersion.class))).thenReturn(future(reply)); - when(api.send(any(ControlPing.class))).thenReturn(future(new ControlPingReply())); - getCustomizer().readCurrentAttributes(InstanceIdentifier.create(Version.class), new VersionBuilder(), ctx); - verify(api).showVersion(any(ShowVersion.class)); - verify(api).send(any(ControlPing.class)); - } -} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vppstate/VppStateTest.java b/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vppstate/VppStateTest.java deleted file mode 100644 index 7134a595a..000000000 --- a/v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/vppstate/VppStateTest.java +++ /dev/null @@ -1,326 +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.vppstate; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; - -import com.google.common.base.Optional; -import com.google.common.collect.Iterables; -import com.google.common.collect.Multimap; -import io.fd.honeycomb.translate.MappingContext; -import io.fd.honeycomb.translate.ModificationCache; -import io.fd.honeycomb.translate.impl.read.GenericListReader; -import io.fd.honeycomb.translate.impl.read.GenericReader; -import io.fd.honeycomb.translate.read.ReadContext; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.read.registry.ReaderRegistry; -import io.fd.honeycomb.translate.impl.read.registry.CompositeReaderRegistryBuilder; -import io.fd.hc2vpp.common.test.util.NamingContextHelper; -import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.common.test.util.FutureProducer; -import io.fd.vpp.jvpp.dto.ControlPing; -import io.fd.vpp.jvpp.dto.ControlPingReply; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import javax.annotation.Nonnull; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.mockito.Mock; -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.VppState; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppStateBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.L2FibTable; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.fib.attributes.l2.fib.table.L2FibEntryKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.BridgeDomains; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.BridgeDomainsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.Version; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.VersionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.bridge.domains.BridgeDomain; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.bridge.domains.BridgeDomainBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.state.bridge.domains.BridgeDomainKey; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.dto.BridgeDomainDetails; -import io.fd.vpp.jvpp.core.dto.BridgeDomainDetailsReplyDump; -import io.fd.vpp.jvpp.core.dto.BridgeDomainDump; -import io.fd.vpp.jvpp.core.dto.L2FibTableDump; -import io.fd.vpp.jvpp.core.dto.L2FibTableEntry; -import io.fd.vpp.jvpp.core.dto.L2FibTableEntryReplyDump; -import io.fd.vpp.jvpp.core.dto.ShowVersion; -import io.fd.vpp.jvpp.core.dto.ShowVersionReply; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; - -public class VppStateTest implements FutureProducer, NamingContextHelper { - - private static final String BD_CTX_NAME = "bd-test-instance"; - @Mock - private FutureJVppCore api; - @Mock - private ReadContext ctx; - @Mock - private MappingContext mappingContext; - - private NamingContext bdContext; - - private ReaderRegistry readerRegistry; - - private static InstanceIdentifier bridgeDomainsId; - - /** - * Create root VppState reader with all its children wired. - */ - private static ReaderRegistry getVppStateReader(@Nonnull final FutureJVppCore jVpp, - @Nonnull final NamingContext bdContext) { - final CompositeReaderRegistryBuilder registry = new CompositeReaderRegistryBuilder(); - - // VppState(Structural) - final InstanceIdentifier vppStateId = InstanceIdentifier.create(VppState.class); - registry.addStructuralReader(vppStateId, VppStateBuilder.class); - // Version - registry.add(new GenericReader<>(vppStateId.child(Version.class), new VersionCustomizer(jVpp))); - // BridgeDomains(Structural) - bridgeDomainsId = vppStateId.child(BridgeDomains.class); - registry.addStructuralReader(bridgeDomainsId, BridgeDomainsBuilder.class); - // BridgeDomain - registry.add(getBridgeDomainReader(jVpp, bdContext)); - return registry.build(); - } - - private static GenericListReader getBridgeDomainReader( - final @Nonnull FutureJVppCore jVpp, final @Nonnull NamingContext bdContext) { - final InstanceIdentifier bridgeDomainId = bridgeDomainsId.child(BridgeDomain.class); - return new GenericListReader<>(bridgeDomainId, new BridgeDomainCustomizer(jVpp, bdContext)); - } - - @Before - public void setUp() throws Exception { - initMocks(this); - final ModificationCache cache = new ModificationCache(); - doReturn(cache).when(ctx).getModificationCache(); - doReturn(mappingContext).when(ctx).getMappingContext(); - - bdContext = new NamingContext("generatedBdName", BD_CTX_NAME); - readerRegistry = getVppStateReader(api, bdContext); - } - - private static Version getVersion() { - return new VersionBuilder() - .setName("test") - .setBuildDirectory("1") - .setBranch("2") - .setBuildDate("3") - .setPid(0L) - .build(); - } - - private void whenShowVersionThenReturn(final Version version) { - final ShowVersionReply reply = new ShowVersionReply(); - reply.buildDate = version.getBuildDate().getBytes(); - reply.program = version.getName().getBytes(); - reply.version = version.getBranch().getBytes(); - reply.buildDirectory = version.getBuildDirectory().getBytes(); - when(api.showVersion(any(ShowVersion.class))).thenReturn(future(reply)); - // Version Customizer uses ControlPing to obtain PID - when(api.send(any(ControlPing.class))).thenReturn(future(new ControlPingReply())); - } - - private void whenL2FibTableDumpThenReturn(final List entryList) { - final L2FibTableEntryReplyDump reply = new L2FibTableEntryReplyDump(); - reply.l2FibTableEntry = entryList; - when(api.l2FibTableDump(any(L2FibTableDump.class))).thenReturn(future(reply)); - } - - private void whenBridgeDomainDumpThenReturn(final List bdList) { - final BridgeDomainDetailsReplyDump reply = new BridgeDomainDetailsReplyDump(); - reply.bridgeDomainDetails = bdList; - - doAnswer(invocation -> { - BridgeDomainDump request = (BridgeDomainDump) invocation.getArguments()[0]; - if (request.bdId == -1) { - reply.bridgeDomainDetails = bdList; - } else { - reply.bridgeDomainDetails = Collections.singletonList(bdList.get(request.bdId)); - } - return future(reply); - }).when(api).bridgeDomainDump(any(BridgeDomainDump.class)); - } - - @Test - public void testReadAll() throws Exception { - final Version version = getVersion(); - whenShowVersionThenReturn(version); - - final BridgeDomainDetails bridgeDomainDetails = new BridgeDomainDetails(); - final BridgeDomainDetails bridgeDomainDetails2 = new BridgeDomainDetails(); - bridgeDomainDetails2.bdId = 1; - - final List bdList = Arrays.asList(bridgeDomainDetails, bridgeDomainDetails2); - mockBdMapping(bridgeDomainDetails, "bd1"); - mockBdMapping(bridgeDomainDetails2, "bd2"); - - whenBridgeDomainDumpThenReturn(bdList); - - final Multimap, ? extends DataObject> dataObjects = - readerRegistry.readAll(ctx); - assertEquals(dataObjects.size(), 1); - final VppState dataObject = - (VppState) Iterables.getOnlyElement(dataObjects.get(Iterables.getOnlyElement(dataObjects.keySet()))); - assertEquals(version, dataObject.getVersion()); - assertEquals(2, dataObject.getBridgeDomains().getBridgeDomain().size()); - } - - @Test - public void testReadSpecific() throws Exception { - final Version version = getVersion(); - whenShowVersionThenReturn(version); - whenBridgeDomainDumpThenReturn(Collections.emptyList()); - - final Optional read = readerRegistry.read(InstanceIdentifier.create(VppState.class), ctx); - assertTrue(read.isPresent()); - assertEquals(version, ((VppState) read.get()).getVersion()); - } - - @Test - public void testReadBridgeDomains() throws Exception { - final Version version = getVersion(); - whenShowVersionThenReturn(version); - final BridgeDomainDetails details = new BridgeDomainDetails(); - whenBridgeDomainDumpThenReturn(Collections.singletonList(details)); - - mockBdMapping(details, "bdn1"); - VppState readRoot = (VppState) readerRegistry.read(InstanceIdentifier.create(VppState.class), ctx).get(); - - Optional read = - readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class), ctx); - assertTrue(read.isPresent()); - assertEquals(readRoot.getBridgeDomains(), read.get()); - } - - /** - * L2fib does not have a dedicated reader, relying on auto filtering - */ - @Test - @Ignore("L2 FIB was moved to dedicated customizer. TODO: add infra test that covers such case") - @SuppressWarnings("unchecked") - public void testReadL2Fib() throws Exception { - final BridgeDomainDetails bd = new BridgeDomainDetails(); - bd.bdId = 0; - final String bdName = "bdn1"; - mockBdMapping(bd, bdName); - defineMapping(mappingContext, "eth1", 0, "ifc-test-instance"); - - whenBridgeDomainDumpThenReturn(Collections.singletonList(bd)); - final L2FibTableEntry l2FibEntry = new L2FibTableEntry(); - l2FibEntry.bdId = 0; - l2FibEntry.mac = 0x0605040302010000L; - whenL2FibTableDumpThenReturn(Collections.singletonList(l2FibEntry)); - - // Deep child without a dedicated reader with specific l2fib key - final InstanceIdentifier idExisting = - InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child( - BridgeDomain.class, new BridgeDomainKey("bdn1")).child(L2FibTable.class) - .child(L2FibEntry.class, new L2FibEntryKey(new PhysAddress("01:02:03:04:05:06"))); - Optional read = - readerRegistry.read(idExisting, ctx); - assertTrue(read.isPresent()); - - // non existing l2fib - final InstanceIdentifier idNonExisting = - InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child( - BridgeDomain.class, new BridgeDomainKey("bdn1")).child(L2FibTable.class) - .child(L2FibEntry.class, new L2FibEntryKey(new PhysAddress("FF:FF:FF:04:05:06"))); - read = readerRegistry.read(idNonExisting, ctx); - assertFalse(read.isPresent()); - } - - private void mockBdMapping(final BridgeDomainDetails bd, final String bdName) { - defineMapping(mappingContext, bdName, bd.bdId, BD_CTX_NAME); - } - - @Test - public void testReadBridgeDomainAll() throws Exception { - final Version version = getVersion(); - whenShowVersionThenReturn(version); - final BridgeDomainDetails details = new BridgeDomainDetails(); - whenBridgeDomainDumpThenReturn(Collections.singletonList(details)); - mockBdMapping(details, "bd2"); - - VppState readRoot = (VppState) readerRegistry.read(InstanceIdentifier.create(VppState.class), ctx).get(); - - final GenericListReader bridgeDomainReader = - getBridgeDomainReader(api, bdContext); - - final List read = - bridgeDomainReader.readList(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child( - BridgeDomain.class), ctx); - - assertEquals(readRoot.getBridgeDomains().getBridgeDomain(), read); - } - - @Test - public void testReadBridgeDomain() throws Exception { - final BridgeDomainDetails bd = new BridgeDomainDetails(); - bd.bdId = 0; - final String bdName = "bdn1"; - mockBdMapping(bd, bdName); - - whenBridgeDomainDumpThenReturn(Collections.singletonList(bd)); - whenShowVersionThenReturn(getVersion()); - - VppState readRoot = (VppState) readerRegistry.read(InstanceIdentifier.create(VppState.class), ctx).get(); - - final Optional read = - readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child( - BridgeDomain.class, new BridgeDomainKey(bdName)), ctx); - - assertTrue(read.isPresent()); - assertEquals(readRoot.getBridgeDomains().getBridgeDomain().stream().filter( - input -> input.getKey().getName().equals(bdName)).findFirst().get(), - read.get()); - } - - @Test(expected = ReadFailedException.class) - public void testReadBridgeDomainNotExisting() throws Exception { - final String nonExistingBdName = "NOT EXISTING"; - noMappingDefined(mappingContext, nonExistingBdName, BD_CTX_NAME); - - readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child( - BridgeDomain.class, new BridgeDomainKey(nonExistingBdName)), ctx); - } - - @Test - public void testReadVersion() throws Exception { - whenShowVersionThenReturn(getVersion()); - whenBridgeDomainDumpThenReturn(Collections.emptyList()); - VppState readRoot = (VppState) readerRegistry.read(InstanceIdentifier.create(VppState.class), ctx).get(); - - Optional read = - readerRegistry.read(InstanceIdentifier.create(VppState.class).child(Version.class), ctx); - assertTrue(read.isPresent()); - assertEquals(readRoot.getVersion(), read.get()); - } -} \ No newline at end of file diff --git a/v3po/v3po2vpp/src/test/resources/v3po.json b/v3po/v3po2vpp/src/test/resources/v3po.json deleted file mode 100644 index 9ea66efe8..000000000 --- a/v3po/v3po2vpp/src/test/resources/v3po.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "keepalive-delay": "30" -} diff --git a/vpp-integration/minimal-distribution/pom.xml b/vpp-integration/minimal-distribution/pom.xml index 3bfa03039..2ae8b5e1f 100644 --- a/vpp-integration/minimal-distribution/pom.xml +++ b/vpp-integration/minimal-distribution/pom.xml @@ -41,9 +41,11 @@ 1.17.04-SNAPSHOT 1.17.04-SNAPSHOT 1.17.04-SNAPSHOT + 1.17.04-SNAPSHOT io.fd.hc2vpp.common.integration.VppCommonModule, + io.fd.hc2vpp.management.VppManagementModule, io.fd.hc2vpp.lisp.LispModule, io.fd.hc2vpp.v3po.V3poModule, io.fd.hc2vpp.l3.InterfaceL3Module, @@ -147,5 +149,10 @@ dhcp-impl ${dhcp.version} + + io.fd.hc2vpp.management + vpp-management-impl + ${vpp-management-impl.version} + diff --git a/vpp-management/api/asciidoc/Readme.adoc b/vpp-management/api/asciidoc/Readme.adoc new file mode 100644 index 000000000..221faa60b --- /dev/null +++ b/vpp-management/api/asciidoc/Readme.adoc @@ -0,0 +1,9 @@ += vpp-management-api + +Overview of vpp-management-api + +Provides model for two major features + +* Management attributes of underlaying vpp instance(version,pid,...) +* RPC support for invoking CLI commands + diff --git a/vpp-management/api/pom.xml b/vpp-management/api/pom.xml new file mode 100644 index 000000000..8168257e2 --- /dev/null +++ b/vpp-management/api/pom.xml @@ -0,0 +1,32 @@ + + + + + 4.0.0 + + + io.fd.honeycomb.common + api-parent + 1.17.04-SNAPSHOT + + + io.fd.hc2vpp.management + vpp-management-api + 1.17.04-SNAPSHOT + \ No newline at end of file diff --git a/vpp-management/api/src/main/yang/vpp-management.yang b/vpp-management/api/src/main/yang/vpp-management.yang new file mode 100644 index 000000000..2582cbea4 --- /dev/null +++ b/vpp-management/api/src/main/yang/vpp-management.yang @@ -0,0 +1,54 @@ +module vpp-management { + yang-version 1; + namespace "urn:opendaylight:params:xml:ns:yang:vpp:management"; + prefix "vpp-m"; + + revision "2017-03-15" { + description + "This revision add support for + - Vpp state attributes read + - RPC cli support"; + } + + container vpp-state { + config false; + + description + "VPP operational data"; + + container version { + leaf name { + type string; + } + leaf build-directory { + type string; + } + leaf build-date { + type string; + } + leaf branch { + type string; + } + leaf pid { + type uint32; + description + "PID of the vpp process"; + } + description + "vlib version info"; + } + } + + rpc cli-inband { + input { + leaf cmd { + type string; + } + } + output { + leaf reply { + type string; + } + } + } +} \ No newline at end of file diff --git a/vpp-management/asciidoc/Readme.adoc b/vpp-management/asciidoc/Readme.adoc new file mode 100644 index 000000000..8fa4da830 --- /dev/null +++ b/vpp-management/asciidoc/Readme.adoc @@ -0,0 +1,3 @@ += vpp-management-aggregator + +Overview of vpp-management-aggregator \ No newline at end of file diff --git a/vpp-management/impl/asciidoc/Readme.adoc b/vpp-management/impl/asciidoc/Readme.adoc new file mode 100644 index 000000000..c53e5db0d --- /dev/null +++ b/vpp-management/impl/asciidoc/Readme.adoc @@ -0,0 +1,15 @@ += vpp-management-impl + +Overview of vpp-management-impl + +Provides following features + +* Read support for VPP management attributes +* Implementation of RPC support of CLI commands +* Initialization of Keep-alive service + +Exposes following configuration + +*vpp-management.json* + +* keepalive-delay - delay period for keep-alive manager \ No newline at end of file diff --git a/vpp-management/impl/pom.xml b/vpp-management/impl/pom.xml new file mode 100644 index 000000000..da4d8ff12 --- /dev/null +++ b/vpp-management/impl/pom.xml @@ -0,0 +1,95 @@ + + + + + + io.fd.hc2vpp.common + vpp-impl-parent + 1.17.04-SNAPSHOT + ../../vpp-common/vpp-impl-parent + + + 4.0.0 + + io.fd.hc2vpp.management + vpp-management-impl + 1.17.04-SNAPSHOT + + + + + io.fd.hc2vpp.management + vpp-management-api + ${project.version} + + + io.fd.honeycomb + translate-api + ${project.version} + + + io.fd.honeycomb + rpc-api + ${project.version} + + + + + com.google.inject + guice + + + com.google.inject.extensions + guice-multibindings + + + net.jmob + guice.conf + + + + + io.fd.hc2vpp.common + vpp-translate-utils + + + io.fd.honeycomb + translate-impl + ${project.version} + + + + + junit + junit + test + + + io.fd.hc2vpp.common + vpp-translate-test + ${project.version} + test + + + com.google.inject.extensions + guice-testlib + test + + + \ No newline at end of file diff --git a/vpp-management/impl/src/main/java/io/fd/hc2vpp/management/VppManagementConfiguration.java b/vpp-management/impl/src/main/java/io/fd/hc2vpp/management/VppManagementConfiguration.java new file mode 100644 index 000000000..53872f16e --- /dev/null +++ b/vpp-management/impl/src/main/java/io/fd/hc2vpp/management/VppManagementConfiguration.java @@ -0,0 +1,32 @@ +/* + * 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.management; + +import net.jmob.guice.conf.core.BindConfig; +import net.jmob.guice.conf.core.InjectConfig; +import net.jmob.guice.conf.core.Syntax; + +@BindConfig(value = "vpp-management", syntax = Syntax.JSON) +public class VppManagementConfiguration { + + @InjectConfig("keepalive-delay") + private int keepaliveDelay; + + public int getKeepaliveDelay() { + return this.keepaliveDelay; + } +} diff --git a/vpp-management/impl/src/main/java/io/fd/hc2vpp/management/VppManagementModule.java b/vpp-management/impl/src/main/java/io/fd/hc2vpp/management/VppManagementModule.java new file mode 100644 index 000000000..508da64d0 --- /dev/null +++ b/vpp-management/impl/src/main/java/io/fd/hc2vpp/management/VppManagementModule.java @@ -0,0 +1,47 @@ +/* + * 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.management; + +import com.google.inject.AbstractModule; +import com.google.inject.multibindings.Multibinder; +import io.fd.hc2vpp.management.rpc.CliInbandService; +import io.fd.hc2vpp.management.state.StateReaderFactory; +import io.fd.honeycomb.rpc.RpcService; +import io.fd.honeycomb.translate.read.ReaderFactory; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import net.jmob.guice.conf.core.ConfigurationModule; + +public class VppManagementModule extends AbstractModule { + + @Override + protected void configure() { + install(ConfigurationModule.create()); + requestInjection(VppManagementConfiguration.class); + + // Readers + final Multibinder readerFactoryBinder = Multibinder.newSetBinder(binder(), ReaderFactory.class); + readerFactoryBinder.addBinding().to(StateReaderFactory.class); + + // Executor needed for keepalives + bind(ScheduledExecutorService.class).toInstance(Executors.newScheduledThreadPool(1)); + + // RPCs + final Multibinder rpcsBinder = Multibinder.newSetBinder(binder(), RpcService.class); + rpcsBinder.addBinding().to(CliInbandService.class); + } +} diff --git a/vpp-management/impl/src/main/java/io/fd/hc2vpp/management/rpc/CliInbandService.java b/vpp-management/impl/src/main/java/io/fd/hc2vpp/management/rpc/CliInbandService.java new file mode 100644 index 000000000..ab55abe3f --- /dev/null +++ b/vpp-management/impl/src/main/java/io/fd/hc2vpp/management/rpc/CliInbandService.java @@ -0,0 +1,62 @@ +/* + * 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.management.rpc; + +import com.google.inject.Inject; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.honeycomb.rpc.RpcService; +import io.fd.vpp.jvpp.core.dto.CliInband; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.nio.charset.StandardCharsets; +import java.util.concurrent.CompletionStage; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.management.rev170315.CliInbandInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.management.rev170315.CliInbandOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.management.rev170315.CliInbandOutputBuilder; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.model.api.SchemaPath; + +public class CliInbandService implements RpcService, JvppReplyConsumer { + + private final FutureJVppCore jvpp; + private static final String localName = "cli-inband"; + private static final QName name = QName.create(CliInbandInput.QNAME, localName); + private static final SchemaPath schemaPath = SchemaPath.ROOT.createChild(name); + + @Inject + public CliInbandService(@Nonnull final FutureJVppCore jvpp) { + this.jvpp = jvpp; + } + + @Override + @Nonnull + public CompletionStage invoke(@Nonnull final CliInbandInput input) { + final CliInband request = new CliInband(); + request.cmd = input.getCmd().getBytes(StandardCharsets.UTF_8); + request.length = request.cmd.length; + return jvpp.cliInband(request) + .thenApply( + reply -> new CliInbandOutputBuilder().setReply(new String(reply.reply)).build() + ); + } + + @Nonnull + @Override + public SchemaPath getManagedNode() { + return schemaPath; + } +} diff --git a/vpp-management/impl/src/main/java/io/fd/hc2vpp/management/state/StateReaderFactory.java b/vpp-management/impl/src/main/java/io/fd/hc2vpp/management/state/StateReaderFactory.java new file mode 100644 index 000000000..541de30a1 --- /dev/null +++ b/vpp-management/impl/src/main/java/io/fd/hc2vpp/management/state/StateReaderFactory.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.management.state; + +import com.google.inject.Inject; +import io.fd.hc2vpp.common.translate.util.ReadTimeoutException; +import io.fd.hc2vpp.common.translate.util.VppStatusListener; +import io.fd.hc2vpp.management.VppManagementConfiguration; +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.honeycomb.translate.util.read.KeepaliveReaderWrapper; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.concurrent.ScheduledExecutorService; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.management.rev170315.VppState; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.management.rev170315.VppStateBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.management.rev170315.vpp.state.Version; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class StateReaderFactory implements ReaderFactory { + + @Inject + private FutureJVppCore vppApi; + + @Inject + private ScheduledExecutorService keepaliveExecutor; + + @Inject + private VppStatusListener vppStatusListener; + + @Inject + private VppManagementConfiguration configuration; + + @Override + public void init(@Nonnull final ModifiableReaderRegistryBuilder registry) { + // VppState(Structural) + final InstanceIdentifier vppStateId = InstanceIdentifier.create(VppState.class); + registry.addStructuralReader(vppStateId, VppStateBuilder.class); + // Version + // Wrap with keepalive reader to detect connection issues + // Relying on VersionCustomizer to provide a "timing out read" + registry.add(new KeepaliveReaderWrapper<>( + new GenericReader<>(vppStateId.child(Version.class), new VersionCustomizer(vppApi)), + keepaliveExecutor, ReadTimeoutException.class, configuration.getKeepaliveDelay(), vppStatusListener)); + } +} diff --git a/vpp-management/impl/src/main/java/io/fd/hc2vpp/management/state/VersionCustomizer.java b/vpp-management/impl/src/main/java/io/fd/hc2vpp/management/state/VersionCustomizer.java new file mode 100644 index 000000000..bfbabcb0c --- /dev/null +++ b/vpp-management/impl/src/main/java/io/fd/hc2vpp/management/state/VersionCustomizer.java @@ -0,0 +1,82 @@ +/* + * 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.management.state; + +import com.google.common.primitives.UnsignedInts; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.vpp.jvpp.core.dto.ShowVersion; +import io.fd.vpp.jvpp.core.dto.ShowVersionReply; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import io.fd.vpp.jvpp.dto.ControlPing; +import io.fd.vpp.jvpp.dto.ControlPingReply; +import io.fd.vpp.jvpp.dto.JVppReply; +import java.util.concurrent.CompletionStage; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.management.rev170315.VppStateBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.management.rev170315.vpp.state.Version; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.management.rev170315.vpp.state.VersionBuilder; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public final class VersionCustomizer + extends FutureJVppCustomizer + implements ReaderCustomizer, ByteDataTranslator, JvppReplyConsumer { + + public VersionCustomizer(@Nonnull final FutureJVppCore futureJVppCore) { + super(futureJVppCore); + } + + @Override + public void merge(@Nonnull final Builder parentBuilder, @Nonnull final Version readValue) { + ((VppStateBuilder) parentBuilder).setVersion(readValue); + } + + @Nonnull + @Override + public VersionBuilder getBuilder(@Nonnull InstanceIdentifier id) { + return new VersionBuilder(); + } + + @Override + public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final VersionBuilder builder, + @Nonnull final ReadContext context) throws ReadFailedException { + + // Execute with timeout + final CompletionStage showVersionFuture = getFutureJVpp().showVersion(new ShowVersion()); + final ShowVersionReply reply = getReplyForRead(showVersionFuture.toCompletableFuture(), id); + + builder.setBranch(toString(reply.version)); + builder.setName(toString(reply.program)); + builder.setBuildDate(toString(reply.buildDate)); + builder.setBuildDirectory(toString(reply.buildDirectory)); + builder.setPid(getPid(id)); + } + + private Long getPid(@Nonnull final InstanceIdentifier id) throws ReadFailedException { + final CompletionStage> request = getFutureJVpp().send(new ControlPing()); + final ControlPingReply reply = (ControlPingReply)getReplyForRead(request.toCompletableFuture(), id); + return UnsignedInts.toLong(reply.vpePid); + } + + +} diff --git a/vpp-management/impl/src/main/resources/honeycomb-minimal-resources/config/vpp-management.json b/vpp-management/impl/src/main/resources/honeycomb-minimal-resources/config/vpp-management.json new file mode 100644 index 000000000..28b25b263 --- /dev/null +++ b/vpp-management/impl/src/main/resources/honeycomb-minimal-resources/config/vpp-management.json @@ -0,0 +1,3 @@ +{ + "keepalive-delay":30 +} \ No newline at end of file diff --git a/vpp-management/impl/src/test/java/io/fd/hc2vpp/management/VppManagementModuleTest.java b/vpp-management/impl/src/test/java/io/fd/hc2vpp/management/VppManagementModuleTest.java new file mode 100644 index 000000000..eb2c3a933 --- /dev/null +++ b/vpp-management/impl/src/test/java/io/fd/hc2vpp/management/VppManagementModuleTest.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.management; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.mockito.MockitoAnnotations.initMocks; + +import com.google.inject.Guice; +import com.google.inject.Inject; +import com.google.inject.testing.fieldbinder.Bind; +import com.google.inject.testing.fieldbinder.BoundFieldModule; +import io.fd.honeycomb.translate.impl.read.registry.CompositeReaderRegistryBuilder; +import io.fd.honeycomb.translate.read.ReaderFactory; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.HashSet; +import java.util.Set; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; + +public class VppManagementModuleTest { + + @Bind + @Mock + private FutureJVppCore futureJVppCore; + + @Inject + private VppManagementConfiguration configuration; + + @Inject + private Set readerFactories = new HashSet<>(); + + @Before + public void setUp() { + initMocks(this); + Guice.createInjector(new VppManagementModule(), BoundFieldModule.of(this)).injectMembers(this); + } + + @Test + public void testReaderFactories() throws Exception { + assertFalse(readerFactories.isEmpty()); + + // Test registration process (all dependencies present, topological order of readers does exist, etc.) + final CompositeReaderRegistryBuilder registryBuilder = new CompositeReaderRegistryBuilder(); + readerFactories.stream().forEach(factory -> factory.init(registryBuilder)); + assertNotNull(registryBuilder.build()); + } + + @Test + public void testConfiguration() { + assertEquals(30, configuration.getKeepaliveDelay()); + } +} \ No newline at end of file diff --git a/vpp-management/impl/src/test/java/io/fd/hc2vpp/management/rpc/CliInbandServiceTest.java b/vpp-management/impl/src/test/java/io/fd/hc2vpp/management/rpc/CliInbandServiceTest.java new file mode 100644 index 000000000..dcf0a0186 --- /dev/null +++ b/vpp-management/impl/src/test/java/io/fd/hc2vpp/management/rpc/CliInbandServiceTest.java @@ -0,0 +1,52 @@ +/* + * 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.management.rpc; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +import io.fd.hc2vpp.common.test.util.FutureProducer; +import io.fd.vpp.jvpp.core.dto.CliInbandReply; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.management.rev170315.CliInbandInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.management.rev170315.CliInbandInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.management.rev170315.CliInbandOutput; + +public class CliInbandServiceTest implements FutureProducer { + + @Mock + private FutureJVppCore api; + + @Test + public void testInvoke() throws Exception { + initMocks(this); + final String replyString = "CLI output"; + + final CliInbandService service = new CliInbandService(api); + final CliInbandReply reply = new CliInbandReply(); + reply.reply = replyString.getBytes(); + when(api.cliInband(any())).thenReturn(future(reply)); + + final CliInbandInput request = new CliInbandInputBuilder().setCmd("cmd").build(); + final CliInbandOutput response = service.invoke(request).toCompletableFuture().get(); + assertEquals(replyString, response.getReply()); + } +} \ No newline at end of file diff --git a/vpp-management/impl/src/test/java/io/fd/hc2vpp/management/state/VppStateTest.java b/vpp-management/impl/src/test/java/io/fd/hc2vpp/management/state/VppStateTest.java new file mode 100644 index 000000000..81db88511 --- /dev/null +++ b/vpp-management/impl/src/test/java/io/fd/hc2vpp/management/state/VppStateTest.java @@ -0,0 +1,142 @@ +/* + * 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.management.state; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +import com.google.common.base.Optional; +import com.google.common.collect.Iterables; +import com.google.common.collect.Multimap; +import io.fd.hc2vpp.common.test.util.FutureProducer; +import io.fd.honeycomb.translate.MappingContext; +import io.fd.honeycomb.translate.ModificationCache; +import io.fd.honeycomb.translate.impl.read.GenericReader; +import io.fd.honeycomb.translate.impl.read.registry.CompositeReaderRegistryBuilder; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.registry.ReaderRegistry; +import io.fd.vpp.jvpp.core.dto.ShowVersion; +import io.fd.vpp.jvpp.core.dto.ShowVersionReply; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import io.fd.vpp.jvpp.dto.ControlPing; +import io.fd.vpp.jvpp.dto.ControlPingReply; +import javax.annotation.Nonnull; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentMatchers; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.management.rev170315.VppState; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.management.rev170315.VppStateBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.management.rev170315.vpp.state.Version; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.management.rev170315.vpp.state.VersionBuilder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class VppStateTest implements FutureProducer { + + @Mock + private FutureJVppCore api; + @Mock + private ReadContext ctx; + @Mock + private MappingContext mappingContext; + + private ReaderRegistry readerRegistry; + + /** + * Create root VppState reader with all its children wired. + */ + private static ReaderRegistry getVppStateReader(@Nonnull final FutureJVppCore jVpp) { + final CompositeReaderRegistryBuilder registry = new CompositeReaderRegistryBuilder(); + + // VppState(Structural) + final InstanceIdentifier vppStateId = InstanceIdentifier.create(VppState.class); + registry.addStructuralReader(vppStateId, VppStateBuilder.class); + // Version + registry.add(new GenericReader<>(vppStateId.child(Version.class), new VersionCustomizer(jVpp))); + return registry.build(); + } + + @Before + public void setUp() throws Exception { + initMocks(this); + final ModificationCache cache = new ModificationCache(); + doReturn(cache).when(ctx).getModificationCache(); + doReturn(mappingContext).when(ctx).getMappingContext(); + + + readerRegistry = getVppStateReader(api); + } + + private static Version getVersion() { + return new VersionBuilder() + .setName("test") + .setBuildDirectory("1") + .setBranch("2") + .setBuildDate("3") + .setPid(0L) + .build(); + } + + private void whenShowVersionThenReturn(final Version version) { + final ShowVersionReply reply = new ShowVersionReply(); + reply.buildDate = version.getBuildDate().getBytes(); + reply.program = version.getName().getBytes(); + reply.version = version.getBranch().getBytes(); + reply.buildDirectory = version.getBuildDirectory().getBytes(); + when(api.showVersion(ArgumentMatchers.any(ShowVersion.class))).thenReturn(future(reply)); + // Version Customizer uses ControlPing to obtain PID + when(api.send(ArgumentMatchers.any(ControlPing.class))).thenReturn(future(new ControlPingReply())); + } + + @Test + public void testReadAll() throws Exception { + final Version version = getVersion(); + whenShowVersionThenReturn(version); + + final Multimap, ? extends DataObject> dataObjects = + readerRegistry.readAll(ctx); + assertEquals(dataObjects.size(), 1); + final VppState dataObject = + (VppState) Iterables.getOnlyElement(dataObjects.get(Iterables.getOnlyElement(dataObjects.keySet()))); + assertEquals(version, dataObject.getVersion()); + } + + @Test + public void testReadSpecific() throws Exception { + final Version version = getVersion(); + whenShowVersionThenReturn(version); + + final Optional read = readerRegistry.read(InstanceIdentifier.create(VppState.class), ctx); + assertTrue(read.isPresent()); + assertEquals(version, ((VppState) read.get()).getVersion()); + } + + @Test + public void testReadVersion() throws Exception { + whenShowVersionThenReturn(getVersion()); + VppState readRoot = (VppState) readerRegistry.read(InstanceIdentifier.create(VppState.class), ctx).get(); + + Optional read = + readerRegistry.read(InstanceIdentifier.create(VppState.class).child(Version.class), ctx); + assertTrue(read.isPresent()); + assertEquals(readRoot.getVersion(), read.get()); + } +} \ No newline at end of file diff --git a/vpp-management/impl/src/test/resources/vpp-management.json b/vpp-management/impl/src/test/resources/vpp-management.json new file mode 100644 index 000000000..28b25b263 --- /dev/null +++ b/vpp-management/impl/src/test/resources/vpp-management.json @@ -0,0 +1,3 @@ +{ + "keepalive-delay":30 +} \ No newline at end of file diff --git a/vpp-management/pom.xml b/vpp-management/pom.xml new file mode 100644 index 000000000..a87af1d9d --- /dev/null +++ b/vpp-management/pom.xml @@ -0,0 +1,58 @@ + + + + + + io.fd.honeycomb.common + honeycomb-parent + 1.17.04-SNAPSHOT + + + pom + 4.0.0 + + io.fd.hc2vpp.management + vpp-management-aggregator + 1.17.04-SNAPSHOT + + + api + impl + + + + + + + org.apache.maven.plugins + maven-deploy-plugin + + true + + + + org.apache.maven.plugins + maven-install-plugin + + true + + + + + \ No newline at end of file diff --git a/vpp-management/vpp_management_postman_collection.json b/vpp-management/vpp_management_postman_collection.json new file mode 100644 index 000000000..591862dd5 --- /dev/null +++ b/vpp-management/vpp_management_postman_collection.json @@ -0,0 +1,106 @@ +{ + "id": "b638a073-6954-5c89-320a-7105437dae94", + "name": "Vpp management Collection", + "description": "", + "order": [ + "1bfd69f7-e187-beb0-447c-0074aa636045" + ], + "folders": [ + { + "id": "299be85f-5ada-34f7-bd80-9fbc4e5b200a", + "name": "RPCs", + "description": "", + "order": [ + "1c552a48-498c-f2e8-8dee-2d5b67120a3a", + "2df7f806-dfb3-bf4f-9cab-0c9863ed4486", + "d4f87db0-06e5-b309-8918-d1c29f59fab1" + ], + "owner": "658985" + } + ], + "timestamp": 1489148746054, + "owner": "658985", + "public": false, + "requests": [ + { + "id": "1bfd69f7-e187-beb0-447c-0074aa636045", + "headers": "Authorization: Basic YWRtaW46YWRtaW4=\nContent-Type: application/json\n", + "url": "http://localhost:8183/restconf/operational/vpp-management:vpp-state", + "preRequestScript": "", + "pathVariables": {}, + "method": "GET", + "data": [], + "dataMode": "raw", + "version": 2, + "tests": "", + "currentHelper": "normal", + "helperAttributes": {}, + "time": 1489149850732, + "name": "Read vpp-state - oper", + "description": "", + "collectionId": "b638a073-6954-5c89-320a-7105437dae94", + "responses": [], + "rawModeData": "{\r\n \r\n \"interface\": [\r\n {\r\n \"name\": \"testInterface\",\r\n \"description\": \"for testing purposes\",\r\n \"type\": \"iana-if-type:ethernetCsmacd\",\r\n \"enabled\": \"true\",\r\n \"link-up-down-trap-enable\": \"enabled\",\r\n \"ietf-ip:ipv4\": {\r\n \"enabled\": \"true\",\r\n \"mtu\": \"1500\",\r\n \"address\": [\r\n {\r\n \"ip\": \"1.2.3.0\",\r\n \"netmask\": \"255.255.255.0\"\r\n }\r\n ]\r\n }\r\n }\r\n ]\r\n \r\n}" + }, + { + "id": "1c552a48-498c-f2e8-8dee-2d5b67120a3a", + "headers": "Authorization: Basic YWRtaW46YWRtaW4=\nContent-Type: application/json\n", + "url": "http://localhost:8183/restconf/operations/vpp-management:cli-inband", + "preRequestScript": "", + "pathVariables": {}, + "method": "POST", + "data": [], + "dataMode": "raw", + "version": 2, + "tests": "", + "currentHelper": "normal", + "helperAttributes": {}, + "time": 1489149921151, + "name": "show version", + "description": "The cli-inband rpc provides support for CLI commands.\nHere is equivalent of show version.", + "collectionId": "b638a073-6954-5c89-320a-7105437dae94", + "responses": [], + "rawModeData": "{\n \"input\" :\n {\n \"cmd\" : \"show version\"\n }\n}" + }, + { + "id": "2df7f806-dfb3-bf4f-9cab-0c9863ed4486", + "headers": "Authorization: Basic YWRtaW46YWRtaW4=\nContent-Type: application/json\n", + "url": "http://localhost:8183/restconf/operations/vpp-management:cli-inband", + "preRequestScript": "", + "pathVariables": {}, + "method": "POST", + "data": [], + "dataMode": "raw", + "version": 2, + "tests": "", + "currentHelper": "normal", + "helperAttributes": {}, + "time": 1489149929797, + "name": "show interfaces", + "description": "The cli-inband rpc provides support for CLI commands.\nHere is equivalent of show int.", + "collectionId": "b638a073-6954-5c89-320a-7105437dae94", + "responses": [], + "rawModeData": "{\n \"input\" :\n {\n \"cmd\" : \"show int\"\n }\n}" + }, + { + "id": "d4f87db0-06e5-b309-8918-d1c29f59fab1", + "headers": "Authorization: Basic YWRtaW46YWRtaW4=\nContent-Type: application/json\n", + "url": "http://localhost:8183/restconf/operations/vpp-management:cli-inband", + "preRequestScript": "", + "pathVariables": {}, + "method": "POST", + "data": [], + "dataMode": "raw", + "version": 2, + "tests": "", + "currentHelper": "normal", + "helperAttributes": {}, + "time": 1489149940101, + "name": "create loopback interface", + "description": "The cli-inband rpc provides support for CLI commands.\nHere is equivalent of create loopback interface", + "collectionId": "b638a073-6954-5c89-320a-7105437dae94", + "responses": [], + "rawModeData": "{\n \"input\" :\n {\n \"cmd\" : \"create loopback interface\"\n }\n}" + } + ] +} \ No newline at end of file -- cgit 1.2.3-korg