From 887fb8a181146390bccb6eaf5caeb0a84659c750 Mon Sep 17 00:00:00 2001 From: Michal Cmarada Date: Fri, 8 Jun 2018 11:54:53 +0200 Subject: HC2VPP-317 - Implement FIB table management support changes: - Added new custom model vpp-fib-table-management - allows management of IPv4 and IPv6 Fib tables for VPP Change-Id: I3647dd659dbefabab233eacef666c3835e69320d Signed-off-by: Michal Cmarada --- fib-management/asciidoc/Readme.adoc | 3 + .../fib-management-api/asciidoc/Readme.adoc | 7 + fib-management/fib-management-api/pom.xml | 31 ++ .../yang/vpp-fib-table-management@2018-05-21.yang | 117 ++++++++ .../fib-management-impl/asciidoc/Readme.adoc | 8 + fib-management/fib-management-impl/pom.xml | 110 +++++++ .../hc2vpp/fib/management/FibManagementIIds.java | 29 ++ .../hc2vpp/fib/management/FibManagementModule.java | 71 +++++ .../read/FibManagementReaderFactory.java | 73 +++++ .../fib/management/read/FibTableCustomizer.java | 119 ++++++++ .../fib/management/request/FibTableRequest.java | 102 +++++++ .../fib/management/services/FibTableService.java | 58 ++++ .../management/services/FibTableServiceImpl.java | 110 +++++++ .../services/FibTableServiceProvider.java | 38 +++ .../write/FibManagementWriterFactory.java | 39 +++ .../fib/management/write/FibTableCustomizer.java | 58 ++++ .../fib/management/FibManagementModuleTest.java | 99 +++++++ .../helpers/SchemaContextTestHelper.java | 31 ++ .../management/read/FibTableCustomizerTest.java | 172 +++++++++++ .../services/FibTableServiceImplTest.java | 103 +++++++ .../management/write/FibTableCustomizerTest.java | 89 ++++++ .../src/test/resources/fib.json | 26 ++ .../fib_management_postman_collection.json | 322 +++++++++++++++++++++ fib-management/pom.xml | 61 ++++ pom.xml | 3 +- routing/routing-impl/pom.xml | 6 + .../java/io/fd/hc2vpp/routing/RoutingModule.java | 17 -- .../hc2vpp/routing/services/FibTableService.java | 57 ---- .../routing/services/FibTableServiceImpl.java | 114 -------- .../routing/services/FibTableServiceProvider.java | 38 --- .../write/ControlPlaneProtocolCustomizer.java | 2 +- .../hc2vpp/routing/write/RoutingWriterFactory.java | 2 +- .../routing/write/factory/FibTableRequest.java | 101 ------- .../io/fd/hc2vpp/routing/RoutingModuleTest.java | 5 + .../routing/services/FibTableServiceImplTest.java | 110 ------- .../write/ControlPlaneProtocolCustomizerTest.java | 2 +- vpp-integration/api-docs/docs/pom.xml | 3 +- vpp-integration/minimal-distribution/pom.xml | 1 + 38 files changed, 1895 insertions(+), 442 deletions(-) create mode 100644 fib-management/asciidoc/Readme.adoc create mode 100644 fib-management/fib-management-api/asciidoc/Readme.adoc create mode 100644 fib-management/fib-management-api/pom.xml create mode 100644 fib-management/fib-management-api/src/main/yang/vpp-fib-table-management@2018-05-21.yang create mode 100644 fib-management/fib-management-impl/asciidoc/Readme.adoc create mode 100644 fib-management/fib-management-impl/pom.xml create mode 100644 fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/FibManagementIIds.java create mode 100644 fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/FibManagementModule.java create mode 100644 fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/read/FibManagementReaderFactory.java create mode 100644 fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/read/FibTableCustomizer.java create mode 100644 fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/request/FibTableRequest.java create mode 100644 fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/services/FibTableService.java create mode 100644 fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/services/FibTableServiceImpl.java create mode 100644 fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/services/FibTableServiceProvider.java create mode 100644 fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/write/FibManagementWriterFactory.java create mode 100644 fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/write/FibTableCustomizer.java create mode 100644 fib-management/fib-management-impl/src/test/java/io/fd/hc2vpp/fib/management/FibManagementModuleTest.java create mode 100644 fib-management/fib-management-impl/src/test/java/io/fd/hc2vpp/fib/management/helpers/SchemaContextTestHelper.java create mode 100644 fib-management/fib-management-impl/src/test/java/io/fd/hc2vpp/fib/management/read/FibTableCustomizerTest.java create mode 100644 fib-management/fib-management-impl/src/test/java/io/fd/hc2vpp/fib/management/services/FibTableServiceImplTest.java create mode 100644 fib-management/fib-management-impl/src/test/java/io/fd/hc2vpp/fib/management/write/FibTableCustomizerTest.java create mode 100644 fib-management/fib-management-impl/src/test/resources/fib.json create mode 100755 fib-management/fib_management_postman_collection.json create mode 100644 fib-management/pom.xml delete mode 100644 routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/services/FibTableService.java delete mode 100644 routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/services/FibTableServiceImpl.java delete mode 100644 routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/services/FibTableServiceProvider.java delete mode 100644 routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/FibTableRequest.java delete mode 100644 routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/services/FibTableServiceImplTest.java diff --git a/fib-management/asciidoc/Readme.adoc b/fib-management/asciidoc/Readme.adoc new file mode 100644 index 000000000..4f50d3ec2 --- /dev/null +++ b/fib-management/asciidoc/Readme.adoc @@ -0,0 +1,3 @@ += fib-management-aggregator + +Aggregates Fib management API module and Fib management Implementation module. diff --git a/fib-management/fib-management-api/asciidoc/Readme.adoc b/fib-management/fib-management-api/asciidoc/Readme.adoc new file mode 100644 index 000000000..618be1f36 --- /dev/null +++ b/fib-management/fib-management-api/asciidoc/Readme.adoc @@ -0,0 +1,7 @@ += fib-management-api + +Provides vpp-fib-table-management model to store configuration of FIB tables: + +- supports IPv4 and IPv6 Fib table configuration +- uses AddressFamily to distinguish between IPv4 and IPv6 FIB table type +- uses vni-reference type to store FIB table id diff --git a/fib-management/fib-management-api/pom.xml b/fib-management/fib-management-api/pom.xml new file mode 100644 index 000000000..c48cd3412 --- /dev/null +++ b/fib-management/fib-management-api/pom.xml @@ -0,0 +1,31 @@ + + + + + io.fd.hc2vpp.common + api-parent + 1.18.07-SNAPSHOT + ../../common/api-parent + + + 4.0.0 + io.fd.hc2vpp.fib.management + fib-management-api + 1.18.07-SNAPSHOT + ${project.artifactId} + bundle + diff --git a/fib-management/fib-management-api/src/main/yang/vpp-fib-table-management@2018-05-21.yang b/fib-management/fib-management-api/src/main/yang/vpp-fib-table-management@2018-05-21.yang new file mode 100644 index 000000000..7a80f912c --- /dev/null +++ b/fib-management/fib-management-api/src/main/yang/vpp-fib-table-management@2018-05-21.yang @@ -0,0 +1,117 @@ +module vpp-fib-table-management { + yang-version "1.1"; + namespace "urn:opendaylight:params:xml:ns:yang:vpp-fib-table-management"; + prefix "vpp-fib-table-management"; + + organization + "FD.io - The Fast Data Project"; + + contact + "Hc2vpp Wiki + Mailing List "; + + description + "This module contains a collection of YANG definitions + that extend hc2vpp-ietf-routing module + with VPP FIB table management features. + + Copyright (c) 2018 Bell Canada, Pantheon Technologies 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."; + + revision 2018-05-21 { + description "Initial revision."; + } + + typedef vni-reference { + type uint32; + description "VRF index reference"; + } + + identity address-family-identity { + description "Base identity from which identities describing address families are derived."; + } + + identity ipv4 { + base vpp-fib-table-management:address-family-identity; + description "This identity represents an IPv4 address family."; + } + + identity ipv6 { + base vpp-fib-table-management:address-family-identity; + description "This identity represents an IPv6 address family."; + } + + grouping vpp-fib-table-management { + container fib-tables { + description + "The FIB tables that are managed by control-plane-protocol"; + + list table { + key "table-id address-family"; + + description + "FIB table that is represented by VNI index (VRF reference index) and addres-family. + Each FIB table is uniquely identified by its index and addres family (e.g. IPv4 or IPv6). + Table cantains name for easier identification and description for a short summary of its + function. + In VPP this table is mapped to ip_table_add_del VPP API message: + Add/del table request + A table can be added multiple times, but need be deleted only once. + @param is_ipv6 - V4 or V6 table + @param table_id - table ID associated with the route + This table ID will apply to both the unicats and mlticast FIBs + @param name - A client provided name/tag for the table. If this is + not set by the client, then VPP will generate something meaningfull"; + leaf address-family { + type identityref { + base address-family-identity; + } + mandatory true; + description + "A reference to the address-family that the table represents (IPv4 or IPv6). + Mapped to is_ipv6 parameter of ip_table_add_del message."; + } + + leaf table-id { + type vni-reference; + mandatory true; + description + "VRF index reference. + Mapped to table_id parameter of ip_table_add_del message."; + } + + leaf name { + type string { + length "1..64"; + } + description + "Name of FIB table. + Mapped to name parameter of ip_table_add_del message."; + } + + leaf description { + type string; + config true; + description "Description of FIB table"; + } + } + } + } + + container fib-table-management { + description "Configuration parameters for FIB table management"; + + uses vpp-fib-table-management; + } +} diff --git a/fib-management/fib-management-impl/asciidoc/Readme.adoc b/fib-management/fib-management-impl/asciidoc/Readme.adoc new file mode 100644 index 000000000..d8b27e0dc --- /dev/null +++ b/fib-management/fib-management-impl/asciidoc/Readme.adoc @@ -0,0 +1,8 @@ += fib-management-impl + +# Supported Features + +FIB management plugin allows to create Ipv4/6 based FIB tables. + +Provides readers and writers to read or write FIB configuration to VPP. + +Uses vpp-fib-management yang model (see fib-management-api for details). diff --git a/fib-management/fib-management-impl/pom.xml b/fib-management/fib-management-impl/pom.xml new file mode 100644 index 000000000..1ec74b7ec --- /dev/null +++ b/fib-management/fib-management-impl/pom.xml @@ -0,0 +1,110 @@ + + + + + + io.fd.hc2vpp.common + vpp-impl-parent + 1.18.07-SNAPSHOT + ../../vpp-common/vpp-impl-parent + + + 4.0.0 + io.fd.hc2vpp.fib.management + fib-management-impl + 1.18.07-SNAPSHOT + ${project.artifactId} + bundle + + + + ${project.groupId} + fib-management-api + ${project.version} + + + + + io.fd.honeycomb + translate-api + + + + io.fd.honeycomb + translate-spi + + + + io.fd.honeycomb + cfg-init + + + + + io.fd.hc2vpp.common + vpp-translate-utils + + + + + com.google.inject + guice + + + net.jmob + guice.conf + + + com.google.inject.extensions + guice-multibindings + + + + + junit + junit + test + + + org.mockito + mockito-core + test + + + org.hamcrest + hamcrest-all + test + + + com.google.inject.extensions + guice-testlib + test + + + io.fd.hc2vpp.common + vpp-translate-test + ${project.version} + test + + + io.fd.honeycomb.infra + test-tools + test + + + diff --git a/fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/FibManagementIIds.java b/fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/FibManagementIIds.java new file mode 100644 index 000000000..c79ca2b16 --- /dev/null +++ b/fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/FibManagementIIds.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.fib.management; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.FibTableManagement; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.FibTables; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.Table; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class FibManagementIIds { + public static final InstanceIdentifier FIB_MNGMNT = + InstanceIdentifier.create(FibTableManagement.class); + public static final InstanceIdentifier FM_FIB_TABLES = FIB_MNGMNT.child(FibTables.class); + public static final InstanceIdentifier FM_FTBLS_TABLE = FM_FIB_TABLES.child(Table.class); +} diff --git a/fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/FibManagementModule.java b/fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/FibManagementModule.java new file mode 100644 index 000000000..462a1e4f6 --- /dev/null +++ b/fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/FibManagementModule.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.fib.management; + +import com.google.common.annotations.VisibleForTesting; +import com.google.inject.AbstractModule; +import com.google.inject.Provider; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; +import io.fd.hc2vpp.fib.management.read.FibManagementReaderFactory; +import io.fd.hc2vpp.fib.management.services.FibTableService; +import io.fd.hc2vpp.fib.management.services.FibTableServiceProvider; +import io.fd.hc2vpp.fib.management.write.FibManagementWriterFactory; +import io.fd.honeycomb.translate.read.ReaderFactory; +import io.fd.honeycomb.translate.write.WriterFactory; +import javax.annotation.Nonnull; +import net.jmob.guice.conf.core.ConfigurationModule; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * FibManagementModule class instantiating FIB management plugin components. + */ +public class FibManagementModule extends AbstractModule { + + private static final Logger LOG = LoggerFactory.getLogger(FibManagementModule.class); + private final Class> fibTableServiceProvider; + + public FibManagementModule() { + this(FibTableServiceProvider.class); + } + + @VisibleForTesting + protected FibManagementModule(@Nonnull final Class> fibTableServiceProvider) { + this.fibTableServiceProvider = fibTableServiceProvider; + } + + @Override + protected void configure() { + LOG.info("Starting FibManagementModule initialization"); + // requests injection of properties + install(ConfigurationModule.create()); + bind(FibTableService.class).toProvider(fibTableServiceProvider).in(Singleton.class); + + LOG.debug("Injecting FibManagementModule reader factories"); + // creates reader factory binding + final Multibinder readerFactoryBinder = Multibinder.newSetBinder(binder(), ReaderFactory.class); + readerFactoryBinder.addBinding().to(FibManagementReaderFactory.class); + + LOG.debug("Injecting FibManagementModule writers factories"); + // create writer factory binding + final Multibinder writerFactoryBinder = Multibinder.newSetBinder(binder(), WriterFactory.class); + writerFactoryBinder.addBinding().to(FibManagementWriterFactory.class); + + LOG.info("FibManagementModule started successfully"); + } +} diff --git a/fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/read/FibManagementReaderFactory.java b/fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/read/FibManagementReaderFactory.java new file mode 100644 index 000000000..d3adc91f7 --- /dev/null +++ b/fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/read/FibManagementReaderFactory.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.fib.management.read; + +import com.google.inject.Inject; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.fib.management.FibManagementIIds; +import io.fd.honeycomb.translate.impl.read.GenericListReader; +import io.fd.honeycomb.translate.read.ReaderFactory; +import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder; +import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; +import io.fd.vpp.jvpp.core.dto.Ip6FibDetailsReplyDump; +import io.fd.vpp.jvpp.core.dto.Ip6FibDump; +import io.fd.vpp.jvpp.core.dto.IpFibDetailsReplyDump; +import io.fd.vpp.jvpp.core.dto.IpFibDump; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.FibTableManagementBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.FibTablesBuilder; + +/** + * Factory producing readers for FIB management plugin's data. + */ +public final class FibManagementReaderFactory implements ReaderFactory, JvppReplyConsumer { + + @Inject + private FutureJVppCore vppApi; + + @Override + public void init(@Nonnull final ModifiableReaderRegistryBuilder registry) { + final DumpCacheManager ipv4DumpManager = newIpv4RoutesDumpManager(vppApi); + final DumpCacheManager ipv6DumpManager = newIpv6RoutesDumpManager(vppApi); + + registry.addStructuralReader(FibManagementIIds.FIB_MNGMNT, FibTableManagementBuilder.class); + registry.addStructuralReader(FibManagementIIds.FM_FIB_TABLES, FibTablesBuilder.class); + registry.add(new GenericListReader<>(FibManagementIIds.FM_FTBLS_TABLE, + new FibTableCustomizer(ipv4DumpManager, ipv6DumpManager))); + } + + private DumpCacheManager newIpv4RoutesDumpManager( + @Nonnull final FutureJVppCore vppApi) { + return new DumpCacheManager.DumpCacheManagerBuilder() + .withExecutor( + (identifier, params) -> getReplyForRead(vppApi.ipFibDump(new IpFibDump()).toCompletableFuture(), + identifier)) + .acceptOnly(IpFibDetailsReplyDump.class) + .build(); + } + + private DumpCacheManager newIpv6RoutesDumpManager( + @Nonnull final FutureJVppCore vppApi) { + return new DumpCacheManager.DumpCacheManagerBuilder() + .withExecutor( + (identifier, params) -> getReplyForRead( + vppApi.ip6FibDump(new Ip6FibDump()).toCompletableFuture(), identifier)) + .acceptOnly(Ip6FibDetailsReplyDump.class) + .build(); + } +} diff --git a/fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/read/FibTableCustomizer.java b/fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/read/FibTableCustomizer.java new file mode 100644 index 000000000..0151a1548 --- /dev/null +++ b/fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/read/FibTableCustomizer.java @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.fib.management.read; + +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer; +import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; +import io.fd.vpp.jvpp.core.dto.Ip6FibDetailsReplyDump; +import io.fd.vpp.jvpp.core.dto.IpFibDetailsReplyDump; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.AddressFamilyIdentity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.Ipv4; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.Ipv6; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.VniReference; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.FibTablesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.Table; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.TableBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.TableKey; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +class FibTableCustomizer implements ListReaderCustomizer, ByteDataTranslator { + private final DumpCacheManager ipv4DumpManager; + private final DumpCacheManager ipv6DumpManager; + + FibTableCustomizer(final DumpCacheManager ipv4DumpManager, + final DumpCacheManager ipv6DumpManager) { + + this.ipv4DumpManager = ipv4DumpManager; + this.ipv6DumpManager = ipv6DumpManager; + } + + @Nonnull + @Override + public List getAllIds(@Nonnull final InstanceIdentifier
instanceIdentifier, + @Nonnull final ReadContext readContext) throws ReadFailedException { + return Stream.concat(ipv4DumpManager.getDump(instanceIdentifier, readContext.getModificationCache()) + .or(new IpFibDetailsReplyDump()) + .ipFibDetails.stream() + .filter(ipFibDetails -> ipFibDetails.tableId >= 0) + .map(ipFibDetails -> new TableKey(Ipv4.class, new VniReference((long) ipFibDetails.tableId))) + .distinct(), + ipv6DumpManager.getDump(instanceIdentifier, readContext.getModificationCache()) + .or(new Ip6FibDetailsReplyDump()) + .ip6FibDetails.stream() + .filter(ip6FibDetails -> ip6FibDetails.tableId >= 0) + .map(ipFibDetails -> new TableKey(Ipv6.class, new VniReference((long) ipFibDetails.tableId)))) + .distinct() + .collect(Collectors.toList()); + } + + @Override + public void merge(@Nonnull final Builder builder, @Nonnull final List
list) { + ((FibTablesBuilder) builder).setTable(list); + } + + @Nonnull + @Override + public TableBuilder getBuilder(@Nonnull final InstanceIdentifier
instanceIdentifier) { + return new TableBuilder(); + } + + @Override + public void readCurrentAttributes(@Nonnull final InstanceIdentifier
instanceIdentifier, + @Nonnull final TableBuilder builder, @Nonnull final ReadContext readContext) + throws ReadFailedException { + TableKey tableKey = instanceIdentifier.firstKeyOf(Table.class); + + if (tableKey.getAddressFamily().equals(Ipv4.class)) { + ipv4DumpManager.getDump(instanceIdentifier, readContext.getModificationCache()) + .or(new IpFibDetailsReplyDump()) + .ipFibDetails.stream() + .filter(ipFibDetails -> ipFibDetails.tableId == tableKey.getTableId().getValue().intValue()) + .findFirst().ifPresent( + ipFibDetails -> parseFibDetails(ipFibDetails.tableId, ipFibDetails.tableName, Ipv4.class, builder)); + + } else { + ipv6DumpManager.getDump(instanceIdentifier, readContext.getModificationCache()) + .or(new Ip6FibDetailsReplyDump()) + .ip6FibDetails.stream() + .filter(ipFibDetails -> ipFibDetails.tableId == tableKey.getTableId().getValue().intValue()) + .findFirst().ifPresent( + ipFibDetails -> parseFibDetails(ipFibDetails.tableId, ipFibDetails.tableName, Ipv6.class, builder)); + } + } + + private void parseFibDetails(final Integer tableId, final byte[] tableName, + final Class addressFamily, + final TableBuilder builder) { + builder.setAddressFamily(addressFamily) + .setTableId(new VniReference(Integer.toUnsignedLong(tableId))); + + if (tableName != null) { + // table name is optional + builder.setName(toString(tableName)); + } + } +} diff --git a/fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/request/FibTableRequest.java b/fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/request/FibTableRequest.java new file mode 100644 index 000000000..6d6c69227 --- /dev/null +++ b/fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/request/FibTableRequest.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.fib.management.request; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import io.fd.hc2vpp.common.translate.util.AddressTranslator; +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.core.dto.IpTableAddDel; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.nio.charset.StandardCharsets; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class FibTableRequest implements AddressTranslator, JvppReplyConsumer { + + private final FutureJVppCore api; + /** + * FIB table Name + */ + private String fibName; + + /** + * FIB table id to be installed + */ + private int fibTable; + + /** + * Whether to write IPv6 FIB table or IPv4 + */ + private boolean isIpv6; + + public FibTableRequest(FutureJVppCore api) { + this.api = api; + } + + public void checkValid() { + checkNotNull(getFibName(), "Fib table name not set"); + checkArgument(!getFibName().isEmpty(), "Fib table name must not be empty"); + } + + public void write(InstanceIdentifier identifier) throws WriteFailedException { + sendRequest(identifier, ByteDataTranslator.BYTE_TRUE); + } + + public void delete(InstanceIdentifier identifier) throws WriteFailedException { + sendRequest(identifier, ByteDataTranslator.BYTE_FALSE); + } + + private void sendRequest(final InstanceIdentifier identifier, final byte isAdd) + throws WriteFailedException { + IpTableAddDel tableAddDel = new IpTableAddDel(); + tableAddDel.tableId = getFibTable(); + tableAddDel.isIpv6 = booleanToByte(isIpv6()); + tableAddDel.isAdd = isAdd; + if (getFibName() != null) { + // FIB table name is optional + tableAddDel.name = getFibName().getBytes(StandardCharsets.UTF_8); + } + getReplyForWrite(api.ipTableAddDel(tableAddDel).toCompletableFuture(), identifier); + } + + public int getFibTable() { + return fibTable; + } + + public void setFibTable(int fibTable) { + this.fibTable = fibTable; + } + + public boolean isIpv6() { + return isIpv6; + } + + public void setIpv6(boolean ipv6) { + isIpv6 = ipv6; + } + + public String getFibName() { + return fibName; + } + + public void setFibName(String fibName) { + this.fibName = fibName; + } +} diff --git a/fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/services/FibTableService.java b/fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/services/FibTableService.java new file mode 100644 index 000000000..eef4df7fa --- /dev/null +++ b/fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/services/FibTableService.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.fib.management.services; + +import static java.lang.String.format; + +import io.fd.honeycomb.translate.ModificationCache; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.write.WriteFailedException; +import javax.annotation.Nonnegative; +import javax.annotation.Nonnull; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public interface FibTableService { + + /** + * Checks whether FIB table with provided index exist in VPP + * + * @throws ReadFailedException if there was an error while reading FIB tables + * @throws FibTableService.FibTableDoesNotExistException if requested index does not exist + */ + void checkTableExist(@Nonnegative final int index, @Nonnull final ModificationCache cache) + throws ReadFailedException, FibTableService.FibTableDoesNotExistException; + + /** + * Writes FIB table in VPP + * + * @param identifier id of currently processed data + * @param tableId table Id to be written in VPP + * @param tableName name of the FIB table that will be added + * @param isIpv6 true if adding IPv6 FIB table, false if adding IPv4 table + * @throws WriteFailedException if there was an error while writing FIB tables + */ + @Deprecated + void write(InstanceIdentifier identifier, @Nonnegative int tableId, @Nonnull String tableName, boolean isIpv6) + throws WriteFailedException; + + class FibTableDoesNotExistException extends Exception { + + public FibTableDoesNotExistException(final int index) { + super(format("Fib table with index %s does not exist", index)); + } + } +} diff --git a/fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/services/FibTableServiceImpl.java b/fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/services/FibTableServiceImpl.java new file mode 100644 index 000000000..01d264189 --- /dev/null +++ b/fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/services/FibTableServiceImpl.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.fib.management.services; + +import static io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor.NO_PARAMS; + +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.hc2vpp.fib.management.FibManagementIIds; +import io.fd.hc2vpp.fib.management.request.FibTableRequest; +import io.fd.honeycomb.translate.ModificationCache; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.core.dto.Ip6FibDetailsReplyDump; +import io.fd.vpp.jvpp.core.dto.Ip6FibDump; +import io.fd.vpp.jvpp.core.dto.IpFibDetailsReplyDump; +import io.fd.vpp.jvpp.core.dto.IpFibDump; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.Collections; +import java.util.stream.Stream; +import javax.annotation.Nonnegative; +import javax.annotation.Nonnull; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +// Todo HC2VPP-317: FibTableService was created as a temporary workaround to write Fib tables in VPP. +// We need to implement proper support for Fib table management. +public class FibTableServiceImpl extends FutureJVppCustomizer implements FibTableService, JvppReplyConsumer { + + private static final Logger LOG = LoggerFactory.getLogger(FibTableServiceImpl.class); + private final DumpCacheManager v4DumpManager; + private final DumpCacheManager v6DumpManager; + + public FibTableServiceImpl(@Nonnull FutureJVppCore futureJVppCore) { + super(futureJVppCore); + v4DumpManager = new DumpCacheManager.DumpCacheManagerBuilder() + .acceptOnly(IpFibDetailsReplyDump.class) + .withExecutor((identifier, params) -> getReplyForRead( + futureJVppCore.ipFibDump(new IpFibDump()).toCompletableFuture(), identifier)) + .build(); + v6DumpManager = new DumpCacheManager.DumpCacheManagerBuilder() + .acceptOnly(Ip6FibDetailsReplyDump.class) + .withExecutor((identifier, params) -> getReplyForRead( + futureJVppCore.ip6FibDump(new Ip6FibDump()).toCompletableFuture(), identifier)) + .build(); + } + + @Override + public void write(InstanceIdentifier identifier, @Nonnegative int tableId, @Nonnull String tableName, + boolean isIpv6) throws WriteFailedException { + // Register FIB table in VPP + FibTableRequest fibTableRequest = new FibTableRequest(getFutureJVpp()); + fibTableRequest.setFibName(tableName); + fibTableRequest.setIpv6(isIpv6); + fibTableRequest.setFibTable(tableId); + fibTableRequest.checkValid(); + try { + fibTableRequest.write(identifier); + LOG.debug("Fib table written successfully. table-name: {}, table-id: {}, request: {}", tableName, tableId, + fibTableRequest); + } catch (WriteFailedException e) { + LOG.warn("Fib table write failed. request: {}", fibTableRequest); + throw new WriteFailedException(identifier, "Failed to write FIB table to VPP.", e); + } + } + + @Override + public void checkTableExist(@Nonnegative final int index, @Nonnull final ModificationCache cache) + throws ReadFailedException, FibTableService.FibTableDoesNotExistException { + + if (Stream.concat(dumpV4FibTableIdsStream(cache), dumpV6FibTableIdsStream(cache)) + .noneMatch(id -> id == index)) { + throw new FibTableService.FibTableDoesNotExistException(index); + } + } + + private Stream dumpV6FibTableIdsStream(final ModificationCache cache) throws ReadFailedException { + return v6DumpManager.getDump(FibManagementIIds.FIB_MNGMNT, cache, NO_PARAMS) + .toJavaUtil() + .map(ip6FibDetailsReplyDump -> ip6FibDetailsReplyDump.ip6FibDetails) + .orElse(Collections.emptyList()) + .stream() + .map(ip6FibDetails -> ip6FibDetails.tableId); + } + + private Stream dumpV4FibTableIdsStream(final ModificationCache cache) throws ReadFailedException { + return v4DumpManager.getDump(FibManagementIIds.FIB_MNGMNT, cache, NO_PARAMS) + .toJavaUtil() + .map(ipFibDetailsReplyDump -> ipFibDetailsReplyDump.ipFibDetails) + .orElse(Collections.emptyList()) + .stream() + .map(ipFibDetails -> ipFibDetails.tableId); + } +} diff --git a/fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/services/FibTableServiceProvider.java b/fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/services/FibTableServiceProvider.java new file mode 100644 index 000000000..d70f18e65 --- /dev/null +++ b/fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/services/FibTableServiceProvider.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.fib.management.services; + +import com.google.inject.Inject; +import com.google.inject.Provider; +import io.fd.honeycomb.translate.ModificationCache; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; + +public class FibTableServiceProvider implements Provider { + + @Inject + private + FutureJVppCore api; + + @Inject + private ModificationCache modificationCache; + + @Override + public FibTableService get() { + return new FibTableServiceImpl(api); + } +} diff --git a/fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/write/FibManagementWriterFactory.java b/fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/write/FibManagementWriterFactory.java new file mode 100644 index 000000000..781c6706b --- /dev/null +++ b/fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/write/FibManagementWriterFactory.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.fib.management.write; + +import com.google.inject.Inject; +import io.fd.hc2vpp.fib.management.FibManagementIIds; +import io.fd.honeycomb.translate.impl.write.GenericListWriter; +import io.fd.honeycomb.translate.write.WriterFactory; +import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import javax.annotation.Nonnull; + +/** + * Factory producing writers for FIB table management plugin's data. + */ +public final class FibManagementWriterFactory implements WriterFactory { + + @Inject + private FutureJVppCore vppApi; + + @Override + public void init(@Nonnull final ModifiableWriterRegistryBuilder registry) { + registry.add(new GenericListWriter<>(FibManagementIIds.FM_FTBLS_TABLE, new FibTableCustomizer(vppApi))); + } +} diff --git a/fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/write/FibTableCustomizer.java b/fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/write/FibTableCustomizer.java new file mode 100644 index 000000000..74b8dc768 --- /dev/null +++ b/fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/write/FibTableCustomizer.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.fib.management.write; + +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.fib.management.request.FibTableRequest; +import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.Ipv6; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.Table; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.TableKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +class FibTableCustomizer extends FutureJVppCustomizer implements ListWriterCustomizer { + FibTableCustomizer(@Nonnull final FutureJVppCore vppApi) { + super(vppApi); + } + + @Override + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier
instanceIdentifier, + @Nonnull final Table table, + @Nonnull final WriteContext writeContext) throws WriteFailedException { + bindFibTableRequest(table).write(instanceIdentifier); + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier
instanceIdentifier, + @Nonnull final Table table, + @Nonnull final WriteContext writeContext) throws WriteFailedException { + bindFibTableRequest(table).delete(instanceIdentifier); + } + + private FibTableRequest bindFibTableRequest(final @Nonnull Table table) { + FibTableRequest fibTableRequest = new FibTableRequest(getFutureJVpp()); + fibTableRequest.setFibName(table.getName()); + fibTableRequest.setFibTable(table.getTableId().getValue().intValue()); + fibTableRequest.setIpv6(table.getAddressFamily().equals(Ipv6.class)); + return fibTableRequest; + } +} diff --git a/fib-management/fib-management-impl/src/test/java/io/fd/hc2vpp/fib/management/FibManagementModuleTest.java b/fib-management/fib-management-impl/src/test/java/io/fd/hc2vpp/fib/management/FibManagementModuleTest.java new file mode 100644 index 000000000..f1f537114 --- /dev/null +++ b/fib-management/fib-management-impl/src/test/java/io/fd/hc2vpp/fib/management/FibManagementModuleTest.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.fib.management; + +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.junit.Assert.assertTrue; +import static org.mockito.MockitoAnnotations.initMocks; + +import com.google.inject.Guice; +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.fib.management.read.FibManagementReaderFactory; +import io.fd.hc2vpp.fib.management.write.FibManagementWriterFactory; +import io.fd.honeycomb.translate.impl.read.registry.CompositeReaderRegistryBuilder; +import io.fd.honeycomb.translate.impl.write.registry.FlatWriterRegistryBuilder; +import io.fd.honeycomb.translate.read.ReaderFactory; +import io.fd.honeycomb.translate.util.YangDAG; +import io.fd.honeycomb.translate.write.WriterFactory; +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; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; + +public class FibManagementModuleTest { + + @Named("honeycomb-context") + @Bind + @Mock + private DataBroker honeycombContext; + + @Named("honeycomb-initializer") + @Bind + @Mock + private DataBroker honeycombInitializer; + + @Bind + @Mock + private FutureJVppCore futureJVppCore; + + @Inject + private Set readerFactories = new HashSet<>(); + + @Inject + private Set writerFactories = new HashSet<>(); + + @Before + public void setUp() { + initMocks(this); + Guice.createInjector(new FibManagementModule(), BoundFieldModule.of(this)).injectMembers(this); + } + + @Test + public void testReaderFactories() { + assertThat(readerFactories, is(not(empty()))); + + // Test registration process (all dependencies present, topological order of readers does exist, etc.) + final CompositeReaderRegistryBuilder registryBuilder = new CompositeReaderRegistryBuilder(new YangDAG()); + readerFactories.forEach(factory -> factory.init(registryBuilder)); + assertNotNull(registryBuilder.build()); + assertEquals(1, readerFactories.size()); + assertTrue(readerFactories.iterator().next() instanceof FibManagementReaderFactory); + } + + @Test + public void testWriterFactories() { + assertThat(writerFactories, is(not(empty()))); + + // Test registration process (all dependencies present, topological order of writers does exist, etc.) + final FlatWriterRegistryBuilder registryBuilder = new FlatWriterRegistryBuilder(new YangDAG()); + writerFactories.forEach(factory -> factory.init(registryBuilder)); + assertNotNull(registryBuilder.build()); + assertEquals(1, writerFactories.size()); + assertTrue(writerFactories.iterator().next() instanceof FibManagementWriterFactory); + } +} diff --git a/fib-management/fib-management-impl/src/test/java/io/fd/hc2vpp/fib/management/helpers/SchemaContextTestHelper.java b/fib-management/fib-management-impl/src/test/java/io/fd/hc2vpp/fib/management/helpers/SchemaContextTestHelper.java new file mode 100644 index 000000000..1341e7e86 --- /dev/null +++ b/fib-management/fib-management-impl/src/test/java/io/fd/hc2vpp/fib/management/helpers/SchemaContextTestHelper.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.fib.management.helpers; + +import com.google.common.collect.ImmutableSet; +import io.fd.honeycomb.test.tools.annotations.InjectablesProcessor; +import io.fd.honeycomb.test.tools.annotations.SchemaContextProvider; +import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.$YangModuleInfoImpl; + +public interface SchemaContextTestHelper extends InjectablesProcessor { + + @SchemaContextProvider + default ModuleInfoBackedContext getSchemaContext() { + return provideSchemaContextFor(ImmutableSet.of($YangModuleInfoImpl.getInstance())); + } +} diff --git a/fib-management/fib-management-impl/src/test/java/io/fd/hc2vpp/fib/management/read/FibTableCustomizerTest.java b/fib-management/fib-management-impl/src/test/java/io/fd/hc2vpp/fib/management/read/FibTableCustomizerTest.java new file mode 100644 index 000000000..6b2d8c4d7 --- /dev/null +++ b/fib-management/fib-management-impl/src/test/java/io/fd/hc2vpp/fib/management/read/FibTableCustomizerTest.java @@ -0,0 +1,172 @@ +/* + * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.fib.management.read; + +import static org.hamcrest.Matchers.hasItems; +import static org.hamcrest.collection.IsCollectionWithSize.hasSize; +import static org.junit.Assert.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest; +import io.fd.hc2vpp.common.translate.util.AddressTranslator; +import io.fd.hc2vpp.fib.management.FibManagementIIds; +import io.fd.honeycomb.translate.ModificationCache; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; +import io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor; +import io.fd.vpp.jvpp.core.dto.Ip6FibDetails; +import io.fd.vpp.jvpp.core.dto.Ip6FibDetailsReplyDump; +import io.fd.vpp.jvpp.core.dto.IpFibDetails; +import io.fd.vpp.jvpp.core.dto.IpFibDetailsReplyDump; +import io.fd.vpp.jvpp.core.types.FibPath; +import java.util.Collections; +import java.util.List; +import org.junit.Assert; +import org.junit.Test; +import org.mockito.Mock; +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.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.Ipv4; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.Ipv6; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.VniReference; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.FibTablesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.Table; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.TableBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.TableKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class FibTableCustomizerTest extends ListReaderCustomizerTest implements + AddressTranslator { + + private static final String IPV4_VRF_1 = "IPV4_VRF_1"; + private static final IpAddress NEXT_HOP_1 = new IpAddress(new Ipv6Address("a::1")); + private static final IpAddress NEXT_HOP_2 = new IpAddress(new Ipv4Address("10.0.0.254")); + private static final InstanceIdentifier
TABLE_V4_ID = + FibManagementIIds.FM_FIB_TABLES.child(Table.class, new TableKey(Ipv4.class, new VniReference(1L))); + private static final InstanceIdentifier
TABLE_V6_ID = + FibManagementIIds.FM_FIB_TABLES.child(Table.class, new TableKey(Ipv6.class, new VniReference(1L))); + private static final IpAddress IP_ADDR_1 = new IpAddress(new Ipv6Address("a::")); + private static final IpAddress IP_ADDR_2 = new IpAddress(new Ipv4Address("10.0.0.1")); + private DumpCacheManager manager_v6; + private DumpCacheManager manager_v4; + + @Mock + private EntityDumpExecutor executor_v6; + + @Mock + private EntityDumpExecutor executor_v4; + + @Mock + private ModificationCache cache; + + public FibTableCustomizerTest() { + super(Table.class, FibTablesBuilder.class); + } + + @Override + public void setUp() throws ReadFailedException { + manager_v6 = new DumpCacheManager.DumpCacheManagerBuilder() + .withExecutor(executor_v6) + .acceptOnly(Ip6FibDetailsReplyDump.class) + .build(); + manager_v4 = new DumpCacheManager.DumpCacheManagerBuilder() + .withExecutor(executor_v4) + .acceptOnly(IpFibDetailsReplyDump.class) + .build(); + + when(executor_v6.executeDump(any(), any())).thenReturn(replyDumpV6()); + when(executor_v4.executeDump(any(), any())).thenReturn(replyDumpV4()); + when(ctx.getModificationCache()).thenReturn(cache); + } + + private Ip6FibDetailsReplyDump replyDumpV6() { + Ip6FibDetailsReplyDump replyDump = new Ip6FibDetailsReplyDump(); + + //simple + Ip6FibDetails ip6FibDetails = new Ip6FibDetails(); + ip6FibDetails.tableId = 1; + ip6FibDetails.address = ipAddressToArray(IP_ADDR_1); + ip6FibDetails.addressLength = 22; + ip6FibDetails.path = new FibPath[]{}; + + FibPath path = new FibPath(); + path.weight = 3; + path.nextHop = ipAddressToArray(NEXT_HOP_1); + path.afi = 0; + path.swIfIndex = 1; + ip6FibDetails.path = new FibPath[]{path}; + + replyDump.ip6FibDetails = Collections.singletonList(ip6FibDetails); + return replyDump; + } + + private IpFibDetailsReplyDump replyDumpV4() { + IpFibDetailsReplyDump replyDump = new IpFibDetailsReplyDump(); + + //simple + IpFibDetails detail = new IpFibDetails(); + detail.tableId = 1; + detail.address = ipAddressToArray(IP_ADDR_2); + detail.addressLength = 24; + detail.tableName = IPV4_VRF_1.getBytes(); + detail.path = new FibPath[]{}; + + FibPath path = new FibPath(); + path.weight = 3; + path.nextHop = ipAddressToArray(NEXT_HOP_2); + path.afi = 0; + path.swIfIndex = 1; + detail.path = new FibPath[]{path}; + + replyDump.ipFibDetails = Collections.singletonList(detail); + return replyDump; + } + + @Test + public void getAllIds() throws Exception { + final List keys = getCustomizer().getAllIds(TABLE_V6_ID, ctx); + + assertThat(keys, hasSize(2)); + assertThat(keys, hasItems(new TableKey(Ipv6.class, new VniReference(1L)), + new TableKey(Ipv4.class, new VniReference(1L)))); + } + + @Test + public void readCurrentAttributesSimpleHop() throws Exception { + TableBuilder builder = new TableBuilder(); + getCustomizer().readCurrentAttributes(TABLE_V6_ID, builder, ctx); + + Assert.assertEquals(Ipv6.class, builder.getAddressFamily()); + Assert.assertEquals(1L, builder.getTableId().getValue().longValue()); + Assert.assertNull(builder.getName()); + + builder = new TableBuilder(); + getCustomizer().readCurrentAttributes(TABLE_V4_ID, builder, ctx); + + Assert.assertEquals(Ipv4.class, builder.getAddressFamily()); + Assert.assertEquals(1L, builder.getTableId().getValue().longValue()); + Assert.assertEquals(IPV4_VRF_1, builder.getName()); + } + + @Override + protected ReaderCustomizer initCustomizer() { + return new FibTableCustomizer(manager_v4, manager_v6); + } +} diff --git a/fib-management/fib-management-impl/src/test/java/io/fd/hc2vpp/fib/management/services/FibTableServiceImplTest.java b/fib-management/fib-management-impl/src/test/java/io/fd/hc2vpp/fib/management/services/FibTableServiceImplTest.java new file mode 100644 index 000000000..2351ead2c --- /dev/null +++ b/fib-management/fib-management-impl/src/test/java/io/fd/hc2vpp/fib/management/services/FibTableServiceImplTest.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.fib.management.services; + +import static io.fd.vpp.jvpp.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import com.google.inject.Inject; +import io.fd.hc2vpp.common.test.util.FutureProducer; +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; +import io.fd.hc2vpp.fib.management.FibManagementIIds; +import io.fd.hc2vpp.fib.management.helpers.SchemaContextTestHelper; +import io.fd.honeycomb.translate.ModificationCache; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.core.dto.Ip6FibDetailsReplyDump; +import io.fd.vpp.jvpp.core.dto.IpFibDetailsReplyDump; +import io.fd.vpp.jvpp.core.dto.IpTableAddDel; +import io.fd.vpp.jvpp.core.dto.IpTableAddDelReply; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +public class FibTableServiceImplTest implements SchemaContextTestHelper, ByteDataTranslator, FutureProducer { + + private static final int FIB_TABLE_ID = 123456; + private static final String FIB_TABLE_NAME = "VRF123456"; + + @Inject + @Mock + private static FutureJVppCore api; + + @Mock + private ModificationCache modificationCache; + + @Captor + private ArgumentCaptor argumentCaptor; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + when(api.ipTableAddDel(any())).thenReturn(future(new IpTableAddDelReply())); + when(api.ipFibDump(any())).thenReturn(future(new IpFibDetailsReplyDump())); + when(api.ip6FibDump(any())).thenReturn(future(new Ip6FibDetailsReplyDump())); + when(modificationCache.get(any())).thenReturn(null); + + } + + @Test(expected = FibTableService.FibTableDoesNotExistException.class) + public void checkTableExistTest() throws ReadFailedException, FibTableService.FibTableDoesNotExistException { + FibTableServiceImpl fibService = new FibTableServiceImpl(api); + fibService.checkTableExist(FIB_TABLE_ID, modificationCache); + } + + @Test + public void writeIpv4Test() throws WriteFailedException { + FibTableServiceImpl fibTableService = new FibTableServiceImpl(api); + fibTableService.write(FibManagementIIds.FIB_MNGMNT, FIB_TABLE_ID, FIB_TABLE_NAME, false); + + verify(api, times(1)).ipTableAddDel(argumentCaptor.capture()); + + assertTableAddDelRequest(argumentCaptor.getValue(), false); + } + + @Test + public void writeIpv6Test() throws WriteFailedException { + FibTableServiceImpl fibTableService = new FibTableServiceImpl(api); + fibTableService.write(FibManagementIIds.FIB_MNGMNT, FIB_TABLE_ID, FIB_TABLE_NAME, true); + + verify(api, times(1)).ipTableAddDel(argumentCaptor.capture()); + + assertTableAddDelRequest(argumentCaptor.getValue(), true); + } + + private void assertTableAddDelRequest(IpTableAddDel jvppRequest, boolean isIpv6) { + assertEquals(ByteDataTranslator.BYTE_TRUE, jvppRequest.isAdd); + assertEquals(ByteDataTranslator.INSTANCE.booleanToByte(isIpv6), jvppRequest.isIpv6); + assertEquals(FIB_TABLE_ID, jvppRequest.tableId); + Assert.assertArrayEquals(FIB_TABLE_NAME.getBytes(), jvppRequest.name); + } +} diff --git a/fib-management/fib-management-impl/src/test/java/io/fd/hc2vpp/fib/management/write/FibTableCustomizerTest.java b/fib-management/fib-management-impl/src/test/java/io/fd/hc2vpp/fib/management/write/FibTableCustomizerTest.java new file mode 100644 index 000000000..c9d05dc45 --- /dev/null +++ b/fib-management/fib-management-impl/src/test/java/io/fd/hc2vpp/fib/management/write/FibTableCustomizerTest.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.fib.management.write; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; +import io.fd.hc2vpp.fib.management.FibManagementIIds; +import io.fd.hc2vpp.fib.management.helpers.SchemaContextTestHelper; +import io.fd.honeycomb.test.tools.HoneycombTestRunner; +import io.fd.honeycomb.test.tools.annotations.InjectTestData; +import io.fd.honeycomb.translate.ModificationCache; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.core.dto.IpTableAddDel; +import io.fd.vpp.jvpp.core.dto.IpTableAddDelReply; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.Ipv6; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.VniReference; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.FibTables; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.Table; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.TableKey; + +@RunWith(HoneycombTestRunner.class) +public class FibTableCustomizerTest extends WriterCustomizerTest implements SchemaContextTestHelper, + ByteDataTranslator { + private static final String FIB_PATH = + "/vpp-fib-table-management:fib-table-management/vpp-fib-table-management:fib-tables"; + private static final String IPV4_VRF_0 = "ipv4-VRF:0"; + private static final String IPV6_VRF_0 = "ipv6-VRF:0"; + @Mock + private ModificationCache modificationCache; + private FibTableCustomizer customizer; + + @Override + protected void setUpTest() { + customizer = new FibTableCustomizer(api); + when(writeContext.getModificationCache()).thenReturn(modificationCache); + when(api.ipTableAddDel(any())).thenReturn(future(new IpTableAddDelReply())); + } + + @Test + public void testWriteSimple(@InjectTestData(resourcePath = "/fib.json", id = FIB_PATH) FibTables tables) + throws WriteFailedException { + final Table data = tables.getTable().get(0); + customizer.writeCurrentAttributes(FibManagementIIds.FM_FIB_TABLES + .child(Table.class, new TableKey(Ipv6.class, new VniReference(0L))), data, writeContext); + final IpTableAddDel request = new IpTableAddDel(); + request.isAdd = 1; + request.isIpv6 = 0; + request.tableId = 0; + request.name = IPV4_VRF_0.getBytes(); + + verify(api).ipTableAddDel(request); + } + + @Test + public void testDelete(@InjectTestData(resourcePath = "/fib.json", id = FIB_PATH) FibTables tables) + throws WriteFailedException { + final Table data = tables.getTable().get(3); + customizer.deleteCurrentAttributes(FibManagementIIds.FM_FIB_TABLES + .child(Table.class, new TableKey(Ipv6.class, new VniReference(0L))), data, writeContext); + final IpTableAddDel request = new IpTableAddDel(); + request.isAdd = 0; + request.isIpv6 = 1; + request.tableId = 0; + request.name = IPV6_VRF_0.getBytes(); + + verify(api).ipTableAddDel(request); + } +} diff --git a/fib-management/fib-management-impl/src/test/resources/fib.json b/fib-management/fib-management-impl/src/test/resources/fib.json new file mode 100644 index 000000000..a96ca2866 --- /dev/null +++ b/fib-management/fib-management-impl/src/test/resources/fib.json @@ -0,0 +1,26 @@ +{ + "fib-tables": { + "vpp-fib-table-management:table": [ + { + "table-id": 0, + "address-family": "vpp-fib-table-management:ipv4", + "name": "ipv4-VRF:0" + }, + { + "table-id": 12, + "address-family": "vpp-fib-table-management:ipv4", + "name": "ipv4-VRF:12" + }, + { + "table-id": 0, + "address-family": "vpp-fib-table-management:ipv6", + "name": "ipv6-VRF:0" + }, + { + "table-id": 25, + "address-family": "vpp-fib-table-management:ipv6", + "name": "ipv6-VRF:25" + } + ] + } +} diff --git a/fib-management/fib_management_postman_collection.json b/fib-management/fib_management_postman_collection.json new file mode 100755 index 000000000..75552843d --- /dev/null +++ b/fib-management/fib_management_postman_collection.json @@ -0,0 +1,322 @@ +{ + "info": { + "_postman_id": "485269bc-c9b2-4173-b596-7919bd028016", + "name": "FIB Table Management", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + }, + "item": [ + { + "name": "Write IPv6 FIB 25", + "request": { + "method": "PUT", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"vpp-fib-table-management:table\": [\n {\n \"table-id\": 25,\n \"address-family\": \"vpp-fib-table-management:ipv6\",\n \"name\": \"ipv6-VRF:25\"\n }\n ]\n}" + }, + "url": { + "raw": "http://localhost:8183/restconf/config/vpp-fib-table-management:fib-table-management/vpp-fib-table-management:fib-tables/table/25/vpp-fib-table-management:ipv6", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8183", + "path": [ + "restconf", + "config", + "vpp-fib-table-management:fib-table-management", + "vpp-fib-table-management:fib-tables", + "table", + "25", + "vpp-fib-table-management:ipv6" + ] + } + }, + "response": [] + }, + { + "name": "Delete IPv6 FIB 25", + "request": { + "method": "DELETE", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "http://localhost:8183/restconf/config/vpp-fib-table-management:fib-table-management/vpp-fib-table-management:fib-tables/table/25/vpp-fib-table-management:ipv6", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8183", + "path": [ + "restconf", + "config", + "vpp-fib-table-management:fib-table-management", + "vpp-fib-table-management:fib-tables", + "table", + "25", + "vpp-fib-table-management:ipv6" + ] + } + }, + "response": [] + }, + { + "name": "Write IPv6 FIB 15 - without name", + "request": { + "method": "PUT", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"vpp-fib-table-management:table\": [\n {\n \"table-id\": 15,\n \"address-family\": \"vpp-fib-table-management:ipv6\"\n }\n ]\n}" + }, + "url": { + "raw": "http://localhost:8183/restconf/config/vpp-fib-table-management:fib-table-management/vpp-fib-table-management:fib-tables/table/15/vpp-fib-table-management:ipv6", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8183", + "path": [ + "restconf", + "config", + "vpp-fib-table-management:fib-table-management", + "vpp-fib-table-management:fib-tables", + "table", + "15", + "vpp-fib-table-management:ipv6" + ] + } + }, + "response": [] + }, + { + "name": "Delete IPv6 FIB 15 - without name", + "request": { + "method": "DELETE", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "http://localhost:8183/restconf/config/vpp-fib-table-management:fib-table-management/vpp-fib-table-management:fib-tables/table/15/vpp-fib-table-management:ipv6", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8183", + "path": [ + "restconf", + "config", + "vpp-fib-table-management:fib-table-management", + "vpp-fib-table-management:fib-tables", + "table", + "15", + "vpp-fib-table-management:ipv6" + ] + } + }, + "response": [] + }, + { + "name": "Write IPv4 FIB 12", + "request": { + "method": "PUT", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"vpp-fib-table-management:table\": [\n {\n \"table-id\": 12,\n \"address-family\": \"vpp-fib-table-management:ipv4\",\n \"name\": \"ipv4-VRF:12\"\n }\n ]\n}" + }, + "url": { + "raw": "http://localhost:8183/restconf/config/vpp-fib-table-management:fib-table-management/vpp-fib-table-management:fib-tables/table/12/vpp-fib-table-management:ipv4", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8183", + "path": [ + "restconf", + "config", + "vpp-fib-table-management:fib-table-management", + "vpp-fib-table-management:fib-tables", + "table", + "12", + "vpp-fib-table-management:ipv4" + ] + } + }, + "response": [] + }, + { + "name": "Delete IPv4 FIB 12", + "request": { + "method": "DELETE", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "http://localhost:8183/restconf/config/vpp-fib-table-management:fib-table-management/vpp-fib-table-management:fib-tables/table/12/vpp-fib-table-management:ipv4", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8183", + "path": [ + "restconf", + "config", + "vpp-fib-table-management:fib-table-management", + "vpp-fib-table-management:fib-tables", + "table", + "12", + "vpp-fib-table-management:ipv4" + ] + } + }, + "response": [] + }, + { + "name": "read all FIB tables - config", + "request": { + "method": "GET", + "header": [ + { + "key": "Authorization", + "value": "Basic YWRtaW46YWRtaW4=" + }, + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "http://localhost:8183/restconf/config/vpp-fib-table-management:fib-table-management/fib-tables/", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8183", + "path": [ + "restconf", + "config", + "vpp-fib-table-management:fib-table-management", + "fib-tables", + "" + ] + } + }, + "response": [] + }, + { + "name": "read all FIB tables - operational", + "request": { + "method": "GET", + "header": [ + { + "key": "Authorization", + "value": "Basic YWRtaW46YWRtaW4=" + }, + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "http://localhost:8183/restconf/operational/vpp-fib-table-management:fib-table-management/fib-tables/", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8183", + "path": [ + "restconf", + "operational", + "vpp-fib-table-management:fib-table-management", + "fib-tables", + "" + ] + } + }, + "response": [] + } + ], + "auth": { + "type": "basic", + "basic": [ + { + "key": "password", + "value": "admin", + "type": "string" + }, + { + "key": "username", + "value": "admin", + "type": "string" + } + ] + }, + "event": [ + { + "listen": "prerequest", + "script": { + "id": "e5a43a42-2764-434d-8aaa-59b56d8ae0ab", + "type": "text/javascript", + "exec": [ + "" + ] + } + }, + { + "listen": "test", + "script": { + "id": "576d0f8e-9325-4391-b6ba-4deb41ef90ec", + "type": "text/javascript", + "exec": [ + "" + ] + } + } + ] +} \ No newline at end of file diff --git a/fib-management/pom.xml b/fib-management/pom.xml new file mode 100644 index 000000000..259609780 --- /dev/null +++ b/fib-management/pom.xml @@ -0,0 +1,61 @@ + + + + + + io.fd.hc2vpp.common + hc2vpp-parent + 1.18.07-SNAPSHOT + ../common/hc2vpp-parent + + + io.fd.hc2vpp.routing + fib-management-aggregator + 1.18.07-SNAPSHOT + ${project.artifactId} + pom + 4.0.0 + + 3.1.1 + + Aggregator for Hc2vpp FIB management plugin + + + fib-management-api + fib-management-impl + + + + + + + org.apache.maven.plugins + maven-deploy-plugin + + true + + + + org.apache.maven.plugins + maven-install-plugin + + true + + + + + diff --git a/pom.xml b/pom.xml index e5f7b7fc8..72d308339 100644 --- a/pom.xml +++ b/pom.xml @@ -41,6 +41,7 @@ ioam nsh routing + fib-management nat lisp release-notes @@ -56,4 +57,4 @@ bgp mpls - \ No newline at end of file + diff --git a/routing/routing-impl/pom.xml b/routing/routing-impl/pom.xml index 8a37b5998..722679761 100644 --- a/routing/routing-impl/pom.xml +++ b/routing/routing-impl/pom.xml @@ -74,6 +74,12 @@ guice-multibindings + + io.fd.hc2vpp.fib.management + fib-management-impl + ${project.version} + + junit diff --git a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/RoutingModule.java b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/RoutingModule.java index 6badcab29..8a109aece 100644 --- a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/RoutingModule.java +++ b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/RoutingModule.java @@ -16,21 +16,15 @@ package io.fd.hc2vpp.routing; -import com.google.common.annotations.VisibleForTesting; import com.google.inject.AbstractModule; -import com.google.inject.Provider; -import com.google.inject.Singleton; import com.google.inject.multibindings.Multibinder; import com.google.inject.name.Names; import io.fd.hc2vpp.common.translate.util.MultiNamingContext; import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.hc2vpp.routing.read.RoutingReaderFactory; -import io.fd.hc2vpp.routing.services.FibTableService; -import io.fd.hc2vpp.routing.services.FibTableServiceProvider; import io.fd.hc2vpp.routing.write.RoutingWriterFactory; import io.fd.honeycomb.translate.read.ReaderFactory; import io.fd.honeycomb.translate.write.WriterFactory; -import javax.annotation.Nonnull; import net.jmob.guice.conf.core.ConfigurationModule; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,23 +35,12 @@ import org.slf4j.LoggerFactory; public class RoutingModule extends AbstractModule { private static final Logger LOG = LoggerFactory.getLogger(RoutingModule.class); - private final Class> fibTableServiceProvider; - - public RoutingModule() { - this(FibTableServiceProvider.class); - } - - @VisibleForTesting - protected RoutingModule(@Nonnull final Class> fibTableServiceProvider) { - this.fibTableServiceProvider = fibTableServiceProvider; - } @Override protected void configure() { LOG.info("Starting initialization"); // requests injection of properties install(ConfigurationModule.create()); - bind(FibTableService.class).toProvider(fibTableServiceProvider).in(Singleton.class); requestInjection(RoutingConfiguration.class); bind(NamingContext.class) diff --git a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/services/FibTableService.java b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/services/FibTableService.java deleted file mode 100644 index 4b01139a4..000000000 --- a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/services/FibTableService.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.routing.services; - -import static java.lang.String.format; - -import io.fd.honeycomb.translate.ModificationCache; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.write.WriteFailedException; -import javax.annotation.Nonnegative; -import javax.annotation.Nonnull; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -public interface FibTableService { - - /** - * Checks whether FIB table with provided index exist in VPP - * - * @throws ReadFailedException if there was an error while reading fib tables - * @throws FibTableService.FibTableDoesNotExistException if requested index does not exist - */ - void checkTableExist(@Nonnegative final int index, @Nonnull final ModificationCache cache) - throws ReadFailedException, FibTableService.FibTableDoesNotExistException; - - /** - * Writes FIB table in VPP - * - * @param identifier id of currently processed data - * @param tableId table Id to be written in VPP - * @param tableName name of the FIB table that will be added - * @param isIpv6 true if adding IPv6 FIB table, false if adding IPv4 table - * @throws WriteFailedException if there was an error while writing FIB tables - */ - void write(InstanceIdentifier identifier, @Nonnegative int tableId, @Nonnull String tableName, boolean isIpv6) - throws WriteFailedException; - - class FibTableDoesNotExistException extends Exception { - - public FibTableDoesNotExistException(final int index) { - super(format("Fib table with index %s does not exist", index)); - } - } -} diff --git a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/services/FibTableServiceImpl.java b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/services/FibTableServiceImpl.java deleted file mode 100644 index db40e4ee8..000000000 --- a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/services/FibTableServiceImpl.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.routing.services; - -import static io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor.NO_PARAMS; - -import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; -import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; -import io.fd.hc2vpp.routing.RoutingIIds; -import io.fd.hc2vpp.routing.write.factory.FibTableRequest; -import io.fd.honeycomb.translate.ModificationCache; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.vpp.jvpp.core.dto.Ip6FibDetailsReplyDump; -import io.fd.vpp.jvpp.core.dto.Ip6FibDump; -import io.fd.vpp.jvpp.core.dto.IpFibDetailsReplyDump; -import io.fd.vpp.jvpp.core.dto.IpFibDump; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; -import java.util.Collections; -import java.util.stream.Stream; -import javax.annotation.Nonnegative; -import javax.annotation.Nonnull; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -// Todo HC2VPP-317: FibTableService was created as a temporary workaround to write Fib tables in VPP. -// We need to implement proper support for Fib table management. -public class FibTableServiceImpl extends FutureJVppCustomizer implements FibTableService, JvppReplyConsumer { - - private static final Logger LOG = LoggerFactory.getLogger(FibTableServiceImpl.class); - private final DumpCacheManager v4DumpManager; - private final DumpCacheManager v6DumpManager; - private ModificationCache modificationCache; - - public FibTableServiceImpl(@Nonnull FutureJVppCore futureJVppCore, ModificationCache modificationCache) { - super(futureJVppCore); - this.modificationCache = modificationCache; - - v4DumpManager = new DumpCacheManager.DumpCacheManagerBuilder() - .acceptOnly(IpFibDetailsReplyDump.class) - .withExecutor((identifier, params) -> getReplyForRead( - futureJVppCore.ipFibDump(new IpFibDump()).toCompletableFuture(), identifier)) - .build(); - v6DumpManager = new DumpCacheManager.DumpCacheManagerBuilder() - .acceptOnly(Ip6FibDetailsReplyDump.class) - .withExecutor((identifier, params) -> getReplyForRead( - futureJVppCore.ip6FibDump(new Ip6FibDump()).toCompletableFuture(), identifier)) - .build(); - } - - @Override - public void write(InstanceIdentifier identifier, @Nonnegative int tableId, @Nonnull String tableName, - boolean isIpv6) throws WriteFailedException { - // Register fib table in VPP - FibTableRequest fibTableRequest = new FibTableRequest(getFutureJVpp(), modificationCache); - fibTableRequest.setFibName(tableName); - fibTableRequest.setIpv6(isIpv6); - fibTableRequest.setFibTable(tableId); - fibTableRequest.checkValid(); - try { - fibTableRequest.write(identifier); - LOG.debug("Fib table written successfully. table-name: {}, table-id: {}, request: {}", tableName, tableId, - fibTableRequest); - } catch (WriteFailedException e) { - LOG.warn("Fib table write failed. request: {}", fibTableRequest); - throw new WriteFailedException(identifier, "Failed to write fib table to VPP.", e); - } - } - - @Override - public void checkTableExist(@Nonnegative final int index, - @Nonnull final ModificationCache cache) - throws ReadFailedException, FibTableService.FibTableDoesNotExistException { - - if (Stream.concat(dumpV4FibTableIdsStream(cache), dumpV6FibTableIdsStream(cache)) - .noneMatch(id -> id == index)) { - throw new FibTableService.FibTableDoesNotExistException(index); - } - } - - private Stream dumpV6FibTableIdsStream(final ModificationCache cache) throws ReadFailedException { - return v6DumpManager.getDump(RoutingIIds.ROUTING, cache, NO_PARAMS) - .toJavaUtil() - .map(ip6FibDetailsReplyDump -> ip6FibDetailsReplyDump.ip6FibDetails) - .orElse(Collections.emptyList()) - .stream() - .map(ip6FibDetails -> ip6FibDetails.tableId); - } - - private Stream dumpV4FibTableIdsStream(final ModificationCache cache) throws ReadFailedException { - return v4DumpManager.getDump(RoutingIIds.ROUTING, cache, NO_PARAMS) - .toJavaUtil() - .map(ipFibDetailsReplyDump -> ipFibDetailsReplyDump.ipFibDetails) - .orElse(Collections.emptyList()) - .stream() - .map(ipFibDetails -> ipFibDetails.tableId); - } -} diff --git a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/services/FibTableServiceProvider.java b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/services/FibTableServiceProvider.java deleted file mode 100644 index e9d394610..000000000 --- a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/services/FibTableServiceProvider.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.routing.services; - -import com.google.inject.Inject; -import com.google.inject.Provider; -import io.fd.honeycomb.translate.ModificationCache; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; - -public class FibTableServiceProvider implements Provider { - - @Inject - private - FutureJVppCore api; - - @Inject - private ModificationCache modificationCache; - - @Override - public FibTableService get() { - return new FibTableServiceImpl(api, modificationCache); - } -} diff --git a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/ControlPlaneProtocolCustomizer.java b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/ControlPlaneProtocolCustomizer.java index 326b6f873..b68a503be 100644 --- a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/ControlPlaneProtocolCustomizer.java +++ b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/ControlPlaneProtocolCustomizer.java @@ -20,7 +20,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkState; import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.routing.services.FibTableService; +import io.fd.hc2vpp.fib.management.services.FibTableService; import io.fd.honeycomb.translate.MappingContext; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; diff --git a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/RoutingWriterFactory.java b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/RoutingWriterFactory.java index cd3c4d275..4af6f5579 100644 --- a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/RoutingWriterFactory.java +++ b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/RoutingWriterFactory.java @@ -25,11 +25,11 @@ import com.google.inject.Inject; import com.google.inject.name.Named; import io.fd.hc2vpp.common.translate.util.MultiNamingContext; import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.fib.management.services.FibTableService; import io.fd.hc2vpp.routing.Ipv4RoutingNodes; import io.fd.hc2vpp.routing.Ipv6RoutingNodes; import io.fd.hc2vpp.routing.RoutingConfiguration; import io.fd.hc2vpp.routing.RoutingIIds; -import io.fd.hc2vpp.routing.services.FibTableService; import io.fd.hc2vpp.vpp.classifier.context.VppClassifierContextManager; import io.fd.honeycomb.translate.impl.write.GenericWriter; import io.fd.honeycomb.translate.write.WriterFactory; diff --git a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/FibTableRequest.java b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/FibTableRequest.java deleted file mode 100644 index 5a471de35..000000000 --- a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/FibTableRequest.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.routing.write.factory; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import io.fd.hc2vpp.common.translate.util.AddressTranslator; -import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; -import io.fd.honeycomb.translate.ModificationCache; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.vpp.jvpp.core.dto.IpTableAddDel; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class FibTableRequest implements AddressTranslator, JvppReplyConsumer { - - private final ModificationCache modificationCache; - private static final Logger LOG = LoggerFactory.getLogger(FibTableRequest.class); - - private final FutureJVppCore api; - /** - * FIB table Name - */ - private String fibName; - - /** - * FIB table id to be installed - */ - private int fibTable; - - /** - * Whether to write IPv6 fib table or IPv4 - */ - private boolean isIpv6; - - public FibTableRequest(FutureJVppCore api, ModificationCache modificationCache) { - this.api = api; - this.modificationCache = modificationCache; - } - - public void checkValid() { - checkNotNull(getFibName(), "Fib table name not set"); - checkArgument(!getFibName().isEmpty(), "Fib table name must not be empty"); - } - - public void write(InstanceIdentifier identifier) throws WriteFailedException { - IpTableAddDel tableAddDel = new IpTableAddDel(); - try { - tableAddDel.tableId = getFibTable(); - tableAddDel.isIpv6 = (booleanToByte(isIpv6())); - tableAddDel.isAdd = (booleanToByte(true)); - tableAddDel.name = getFibName().getBytes(); - getReplyForWrite(api.ipTableAddDel(tableAddDel).toCompletableFuture(), identifier); - } catch (Exception ex) { - LOG.error("Error writing fib table. fibTable: {}, api: {}, cache: {}, id: {}", tableAddDel, api, - modificationCache, identifier); - throw new WriteFailedException(identifier, ex); - } - } - - public int getFibTable() { - return fibTable; - } - - public void setFibTable(int fibTable) { - this.fibTable = fibTable; - } - - public boolean isIpv6() { - return isIpv6; - } - - public void setIpv6(boolean ipv6) { - isIpv6 = ipv6; - } - - public String getFibName() { - return fibName; - } - - public void setFibName(String fibName) { - this.fibName = fibName; - } -} diff --git a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/RoutingModuleTest.java b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/RoutingModuleTest.java index 679b90316..a12d0e0cc 100644 --- a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/RoutingModuleTest.java +++ b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/RoutingModuleTest.java @@ -31,6 +31,7 @@ import com.google.inject.name.Named; import com.google.inject.testing.fieldbinder.Bind; import com.google.inject.testing.fieldbinder.BoundFieldModule; import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.fib.management.services.FibTableService; import io.fd.hc2vpp.routing.read.RoutingReaderFactory; import io.fd.hc2vpp.routing.write.RoutingWriterFactory; import io.fd.hc2vpp.vpp.classifier.context.VppClassifierContextManager; @@ -72,6 +73,10 @@ public class RoutingModuleTest { @Mock private FutureJVppCore futureJVppCore; + @Bind + @Mock + private FibTableService fibTableService; + @Inject private Set readerFactories = new HashSet<>(); diff --git a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/services/FibTableServiceImplTest.java b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/services/FibTableServiceImplTest.java deleted file mode 100644 index 988738aa6..000000000 --- a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/services/FibTableServiceImplTest.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.routing.services; - -import static io.fd.vpp.jvpp.Assertions.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import com.google.inject.Inject; -import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; -import io.fd.hc2vpp.routing.RoutingIIds; -import io.fd.hc2vpp.routing.helpers.RoutingRequestTestHelper; -import io.fd.hc2vpp.routing.helpers.SchemaContextTestHelper; -import io.fd.honeycomb.translate.ModificationCache; -import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.write.WriteContext; -import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.vpp.jvpp.core.dto.Ip6FibDetailsReplyDump; -import io.fd.vpp.jvpp.core.dto.IpFibDetailsReplyDump; -import io.fd.vpp.jvpp.core.dto.IpTableAddDel; -import io.fd.vpp.jvpp.core.dto.IpTableAddDelReply; -import io.fd.vpp.jvpp.core.future.FutureJVppCore; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -public class FibTableServiceImplTest implements RoutingRequestTestHelper, SchemaContextTestHelper { - - private static final int FIB_TABLE_ID = 123456; - private static final String FIB_TABLE_NAME = "VRF123456"; - - @Inject - @Mock - private static FutureJVppCore api; - - @Mock - private static WriteContext ctx; - - @Mock - private ModificationCache modificationCache; - - @Captor - private ArgumentCaptor argumentCaptor; - - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - when(api.ipTableAddDel(any())).thenReturn(future(new IpTableAddDelReply())); - when(api.ipFibDump(any())).thenReturn(future(new IpFibDetailsReplyDump())); - when(api.ip6FibDump(any())).thenReturn(future(new Ip6FibDetailsReplyDump())); - when(modificationCache.get(any())).thenReturn(null); - - } - - @Test(expected = FibTableService.FibTableDoesNotExistException.class) - public void checkTableExistTest() throws ReadFailedException, FibTableService.FibTableDoesNotExistException { - FibTableServiceImpl fibService = new FibTableServiceImpl(api, ctx.getModificationCache()); - - fibService.checkTableExist(FIB_TABLE_ID, modificationCache); - } - - @Test - public void writeIpv4Test() throws WriteFailedException { - FibTableServiceImpl fibTableService = new FibTableServiceImpl(api, ctx.getModificationCache()); - fibTableService.write(RoutingIIds.ROUTING, FIB_TABLE_ID, FIB_TABLE_NAME, false); - - verify(api, times(1)).ipTableAddDel(argumentCaptor.capture()); - - final IpTableAddDel jvppRequest = argumentCaptor.getValue(); - assertTableAddDelRequest(jvppRequest, true, false); - } - - @Test - public void writeIpv6Test() throws WriteFailedException { - FibTableServiceImpl fibTableService = new FibTableServiceImpl(api, ctx.getModificationCache()); - fibTableService.write(RoutingIIds.ROUTING, FIB_TABLE_ID, FIB_TABLE_NAME, true); - - verify(api, times(1)).ipTableAddDel(argumentCaptor.capture()); - - final IpTableAddDel jvppRequest = argumentCaptor.getValue(); - assertTableAddDelRequest(jvppRequest, true, true); - } - - private void assertTableAddDelRequest(IpTableAddDel jvppRequest, boolean isAdd, boolean isIpv6) { - assertEquals(ByteDataTranslator.INSTANCE.booleanToByte(isAdd), jvppRequest.isAdd); - assertEquals(ByteDataTranslator.INSTANCE.booleanToByte(isIpv6), jvppRequest.isIpv6); - assertEquals(FIB_TABLE_ID, jvppRequest.tableId); - Assert.assertArrayEquals(FIB_TABLE_NAME.getBytes(), jvppRequest.name); - } -} diff --git a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/ControlPlaneProtocolCustomizerTest.java b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/ControlPlaneProtocolCustomizerTest.java index b4cf64ead..c96e31373 100644 --- a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/ControlPlaneProtocolCustomizerTest.java +++ b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/ControlPlaneProtocolCustomizerTest.java @@ -23,7 +23,7 @@ import static org.junit.Assert.fail; import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; import io.fd.hc2vpp.common.translate.util.NamingContext; -import io.fd.hc2vpp.routing.services.FibTableService; +import io.fd.hc2vpp.fib.management.services.FibTableService; import io.fd.honeycomb.translate.write.WriteFailedException; import org.junit.Before; import org.junit.Test; diff --git a/vpp-integration/api-docs/docs/pom.xml b/vpp-integration/api-docs/docs/pom.xml index 6545ed671..b5c62171b 100644 --- a/vpp-integration/api-docs/docs/pom.xml +++ b/vpp-integration/api-docs/docs/pom.xml @@ -30,6 +30,7 @@ io.fd.hc2vpp.docs.core.mock.binding.MockBindingModule, io.fd.hc2vpp.management.VppManagementModule, + io.fd.hc2vpp.fib.management.FibManagementModule, io.fd.hc2vpp.lisp.LispModule, io.fd.hc2vpp.lisp.gpe.GpeModule, io.fd.hc2vpp.v3po.V3poModule, @@ -108,4 +109,4 @@ - \ No newline at end of file + diff --git a/vpp-integration/minimal-distribution/pom.xml b/vpp-integration/minimal-distribution/pom.xml index 8399ff27e..61ded4b13 100644 --- a/vpp-integration/minimal-distribution/pom.xml +++ b/vpp-integration/minimal-distribution/pom.xml @@ -49,6 +49,7 @@ io.fd.hc2vpp.common.integration.VppCommonModule, io.fd.hc2vpp.management.VppManagementModule, + io.fd.hc2vpp.fib.management.FibManagementModule, io.fd.hc2vpp.lisp.LispModule, io.fd.hc2vpp.lisp.gpe.GpeModule, io.fd.hc2vpp.v3po.V3poModule, -- cgit 1.2.3-korg