HC2VPP-317 - Implement FIB table management support 69/12669/12
authorMichal Cmarada <[email protected]>
Fri, 8 Jun 2018 09:54:53 +0000 (11:54 +0200)
committerMichal Cmarada <[email protected]>
Fri, 8 Jun 2018 09:54:53 +0000 (11:54 +0200)
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 <[email protected]>
33 files changed:
fib-management/asciidoc/Readme.adoc [new file with mode: 0644]
fib-management/fib-management-api/asciidoc/Readme.adoc [new file with mode: 0644]
fib-management/fib-management-api/pom.xml [new file with mode: 0644]
fib-management/fib-management-api/src/main/yang/[email protected] [new file with mode: 0644]
fib-management/fib-management-impl/asciidoc/Readme.adoc [new file with mode: 0644]
fib-management/fib-management-impl/pom.xml [new file with mode: 0644]
fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/FibManagementIIds.java [new file with mode: 0644]
fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/FibManagementModule.java [new file with mode: 0644]
fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/read/FibManagementReaderFactory.java [new file with mode: 0644]
fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/read/FibTableCustomizer.java [new file with mode: 0644]
fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/request/FibTableRequest.java [moved from routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/FibTableRequest.java with 67% similarity]
fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/services/FibTableService.java [moved from routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/services/FibTableService.java with 95% similarity]
fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/services/FibTableServiceImpl.java [moved from routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/services/FibTableServiceImpl.java with 87% similarity]
fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/services/FibTableServiceProvider.java [moved from routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/services/FibTableServiceProvider.java with 91% similarity]
fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/write/FibManagementWriterFactory.java [new file with mode: 0644]
fib-management/fib-management-impl/src/main/java/io/fd/hc2vpp/fib/management/write/FibTableCustomizer.java [new file with mode: 0644]
fib-management/fib-management-impl/src/test/java/io/fd/hc2vpp/fib/management/FibManagementModuleTest.java [new file with mode: 0644]
fib-management/fib-management-impl/src/test/java/io/fd/hc2vpp/fib/management/helpers/SchemaContextTestHelper.java [new file with mode: 0644]
fib-management/fib-management-impl/src/test/java/io/fd/hc2vpp/fib/management/read/FibTableCustomizerTest.java [new file with mode: 0644]
fib-management/fib-management-impl/src/test/java/io/fd/hc2vpp/fib/management/services/FibTableServiceImplTest.java [moved from routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/services/FibTableServiceImplTest.java with 75% similarity]
fib-management/fib-management-impl/src/test/java/io/fd/hc2vpp/fib/management/write/FibTableCustomizerTest.java [new file with mode: 0644]
fib-management/fib-management-impl/src/test/resources/fib.json [new file with mode: 0644]
fib-management/fib_management_postman_collection.json [new file with mode: 0755]
fib-management/pom.xml [new file with mode: 0644]
pom.xml
routing/routing-impl/pom.xml
routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/RoutingModule.java
routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/ControlPlaneProtocolCustomizer.java
routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/RoutingWriterFactory.java
routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/RoutingModuleTest.java
routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/write/ControlPlaneProtocolCustomizerTest.java
vpp-integration/api-docs/docs/pom.xml
vpp-integration/minimal-distribution/pom.xml

diff --git a/fib-management/asciidoc/Readme.adoc b/fib-management/asciidoc/Readme.adoc
new file mode 100644 (file)
index 0000000..4f50d3e
--- /dev/null
@@ -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 (file)
index 0000000..618be1f
--- /dev/null
@@ -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 (file)
index 0000000..c48cd34
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <groupId>io.fd.hc2vpp.common</groupId>
+        <artifactId>api-parent</artifactId>
+        <version>1.18.07-SNAPSHOT</version>
+        <relativePath>../../common/api-parent</relativePath>
+    </parent>
+
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>io.fd.hc2vpp.fib.management</groupId>
+    <artifactId>fib-management-api</artifactId>
+    <version>1.18.07-SNAPSHOT</version>
+    <name>${project.artifactId}</name>
+    <packaging>bundle</packaging>
+</project>
diff --git a/fib-management/fib-management-api/src/main/yang/[email protected] b/fib-management/fib-management-api/src/main/yang/[email protected]
new file mode 100644 (file)
index 0000000..7a80f91
--- /dev/null
@@ -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 <https://wiki.fd.io/view/Hc2vpp>
+         Mailing List <[email protected]>";
+
+    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 (file)
index 0000000..d8b27e0
--- /dev/null
@@ -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 (file)
index 0000000..1ec74b7
--- /dev/null
@@ -0,0 +1,110 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  ~ 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.
+  -->
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <groupId>io.fd.hc2vpp.common</groupId>
+        <artifactId>vpp-impl-parent</artifactId>
+        <version>1.18.07-SNAPSHOT</version>
+        <relativePath>../../vpp-common/vpp-impl-parent</relativePath>
+    </parent>
+
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>io.fd.hc2vpp.fib.management</groupId>
+    <artifactId>fib-management-impl</artifactId>
+    <version>1.18.07-SNAPSHOT</version>
+    <name>${project.artifactId}</name>
+    <packaging>bundle</packaging>
+
+    <dependencies>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>fib-management-api</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <!-- Honeycomb infrastructure-->
+        <dependency>
+            <groupId>io.fd.honeycomb</groupId>
+            <artifactId>translate-api</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>io.fd.honeycomb</groupId>
+            <artifactId>translate-spi</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>io.fd.honeycomb</groupId>
+            <artifactId>cfg-init</artifactId>
+        </dependency>
+
+        <!-- Translation -->
+        <dependency>
+            <groupId>io.fd.hc2vpp.common</groupId>
+            <artifactId>vpp-translate-utils</artifactId>
+        </dependency>
+
+        <!-- DI -->
+        <dependency>
+            <groupId>com.google.inject</groupId>
+            <artifactId>guice</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>net.jmob</groupId>
+            <artifactId>guice.conf</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.google.inject.extensions</groupId>
+            <artifactId>guice-multibindings</artifactId>
+        </dependency>
+
+        <!-- Testing dependencies-->
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.hamcrest</groupId>
+            <artifactId>hamcrest-all</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.google.inject.extensions</groupId>
+            <artifactId>guice-testlib</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>io.fd.hc2vpp.common</groupId>
+            <artifactId>vpp-translate-test</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>io.fd.honeycomb.infra</groupId>
+            <artifactId>test-tools</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+</project>
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 (file)
index 0000000..c79ca2b
--- /dev/null
@@ -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<FibTableManagement> FIB_MNGMNT =
+            InstanceIdentifier.create(FibTableManagement.class);
+    public static final InstanceIdentifier<FibTables> FM_FIB_TABLES = FIB_MNGMNT.child(FibTables.class);
+    public static final InstanceIdentifier<Table> 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 (file)
index 0000000..462a1e4
--- /dev/null
@@ -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<? extends Provider<FibTableService>> fibTableServiceProvider;
+
+    public FibManagementModule() {
+        this(FibTableServiceProvider.class);
+    }
+
+    @VisibleForTesting
+    protected FibManagementModule(@Nonnull final Class<? extends Provider<FibTableService>> 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<ReaderFactory> readerFactoryBinder = Multibinder.newSetBinder(binder(), ReaderFactory.class);
+        readerFactoryBinder.addBinding().to(FibManagementReaderFactory.class);
+
+        LOG.debug("Injecting FibManagementModule writers factories");
+        // create writer factory binding
+        final Multibinder<WriterFactory> 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 (file)
index 0000000..d3adc91
--- /dev/null
@@ -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<IpFibDetailsReplyDump, Void> ipv4DumpManager = newIpv4RoutesDumpManager(vppApi);
+        final DumpCacheManager<Ip6FibDetailsReplyDump, Void> 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<IpFibDetailsReplyDump, Void> newIpv4RoutesDumpManager(
+            @Nonnull final FutureJVppCore vppApi) {
+        return new DumpCacheManager.DumpCacheManagerBuilder<IpFibDetailsReplyDump, Void>()
+                .withExecutor(
+                        (identifier, params) -> getReplyForRead(vppApi.ipFibDump(new IpFibDump()).toCompletableFuture(),
+                                identifier))
+                .acceptOnly(IpFibDetailsReplyDump.class)
+                .build();
+    }
+
+    private DumpCacheManager<Ip6FibDetailsReplyDump, Void> newIpv6RoutesDumpManager(
+            @Nonnull final FutureJVppCore vppApi) {
+        return new DumpCacheManager.DumpCacheManagerBuilder<Ip6FibDetailsReplyDump, Void>()
+                .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 (file)
index 0000000..0151a15
--- /dev/null
@@ -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<Table, TableKey, TableBuilder>, ByteDataTranslator {
+    private final DumpCacheManager<IpFibDetailsReplyDump, Void> ipv4DumpManager;
+    private final DumpCacheManager<Ip6FibDetailsReplyDump, Void> ipv6DumpManager;
+
+    FibTableCustomizer(final DumpCacheManager<IpFibDetailsReplyDump, Void> ipv4DumpManager,
+                       final DumpCacheManager<Ip6FibDetailsReplyDump, Void> ipv6DumpManager) {
+
+        this.ipv4DumpManager = ipv4DumpManager;
+        this.ipv6DumpManager = ipv6DumpManager;
+    }
+
+    @Nonnull
+    @Override
+    public List<TableKey> getAllIds(@Nonnull final InstanceIdentifier<Table> 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<? extends DataObject> builder, @Nonnull final List<Table> list) {
+        ((FibTablesBuilder) builder).setTable(list);
+    }
+
+    @Nonnull
+    @Override
+    public TableBuilder getBuilder(@Nonnull final InstanceIdentifier<Table> instanceIdentifier) {
+        return new TableBuilder();
+    }
+
+    @Override
+    public void readCurrentAttributes(@Nonnull final InstanceIdentifier<Table> 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<? extends AddressFamilyIdentity> addressFamily,
+                                 final TableBuilder builder) {
+        builder.setAddressFamily(addressFamily)
+                .setTableId(new VniReference(Integer.toUnsignedLong(tableId)));
+
+        if (tableName != null) {
+            // table name is optional
+            builder.setName(toString(tableName));
+        }
+    }
+}
  * limitations under the License.
  */
 
-package io.fd.hc2vpp.routing.write.factory;
+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.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 java.nio.charset.StandardCharsets;
 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
@@ -46,13 +42,12 @@ public class FibTableRequest implements AddressTranslator, JvppReplyConsumer {
     private int fibTable;
 
     /**
-     * Whether to write IPv6 fib table or IPv4
+     * Whether to write IPv6 FIB table or IPv4
      */
     private boolean isIpv6;
 
-    public FibTableRequest(FutureJVppCore api, ModificationCache modificationCache) {
+    public FibTableRequest(FutureJVppCore api) {
         this.api = api;
-        this.modificationCache = modificationCache;
     }
 
     public void checkValid() {
@@ -61,18 +56,24 @@ public class FibTableRequest implements AddressTranslator, JvppReplyConsumer {
     }
 
     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();
-        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);
+        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() {
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package io.fd.hc2vpp.routing.services;
+package io.fd.hc2vpp.fib.management.services;
 
 import static java.lang.String.format;
 
@@ -30,7 +30,7 @@ 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 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)
@@ -45,6 +45,7 @@ public interface FibTableService {
      * @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;
 
  * limitations under the License.
  */
 
-package io.fd.hc2vpp.routing.services;
+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.routing.RoutingIIds;
-import io.fd.hc2vpp.routing.write.factory.FibTableRequest;
+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;
@@ -46,12 +46,9 @@ public class FibTableServiceImpl extends FutureJVppCustomizer implements FibTabl
     private static final Logger LOG = LoggerFactory.getLogger(FibTableServiceImpl.class);
     private final DumpCacheManager<IpFibDetailsReplyDump, Void> v4DumpManager;
     private final DumpCacheManager<Ip6FibDetailsReplyDump, Void> v6DumpManager;
-    private ModificationCache modificationCache;
 
-    public FibTableServiceImpl(@Nonnull FutureJVppCore futureJVppCore, ModificationCache modificationCache) {
+    public FibTableServiceImpl(@Nonnull FutureJVppCore futureJVppCore) {
         super(futureJVppCore);
-        this.modificationCache = modificationCache;
-
         v4DumpManager = new DumpCacheManager.DumpCacheManagerBuilder<IpFibDetailsReplyDump, Void>()
                 .acceptOnly(IpFibDetailsReplyDump.class)
                 .withExecutor((identifier, params) -> getReplyForRead(
@@ -67,8 +64,8 @@ public class FibTableServiceImpl extends FutureJVppCustomizer implements FibTabl
     @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);
+        // Register FIB table in VPP
+        FibTableRequest fibTableRequest = new FibTableRequest(getFutureJVpp());
         fibTableRequest.setFibName(tableName);
         fibTableRequest.setIpv6(isIpv6);
         fibTableRequest.setFibTable(tableId);
@@ -79,13 +76,12 @@ public class FibTableServiceImpl extends FutureJVppCustomizer implements FibTabl
                     fibTableRequest);
         } catch (WriteFailedException e) {
             LOG.warn("Fib table write failed. request: {}", fibTableRequest);
-            throw new WriteFailedException(identifier, "Failed to write fib table to VPP.", e);
+            throw new WriteFailedException(identifier, "Failed to write FIB table to VPP.", e);
         }
     }
 
     @Override
-    public void checkTableExist(@Nonnegative final int index,
-                                @Nonnull final ModificationCache cache)
+    public void checkTableExist(@Nonnegative final int index, @Nonnull final ModificationCache cache)
             throws ReadFailedException, FibTableService.FibTableDoesNotExistException {
 
         if (Stream.concat(dumpV4FibTableIdsStream(cache), dumpV6FibTableIdsStream(cache))
@@ -95,7 +91,7 @@ public class FibTableServiceImpl extends FutureJVppCustomizer implements FibTabl
     }
 
     private Stream<Integer> dumpV6FibTableIdsStream(final ModificationCache cache) throws ReadFailedException {
-        return v6DumpManager.getDump(RoutingIIds.ROUTING, cache, NO_PARAMS)
+        return v6DumpManager.getDump(FibManagementIIds.FIB_MNGMNT, cache, NO_PARAMS)
                 .toJavaUtil()
                 .map(ip6FibDetailsReplyDump -> ip6FibDetailsReplyDump.ip6FibDetails)
                 .orElse(Collections.emptyList())
@@ -104,7 +100,7 @@ public class FibTableServiceImpl extends FutureJVppCustomizer implements FibTabl
     }
 
     private Stream<Integer> dumpV4FibTableIdsStream(final ModificationCache cache) throws ReadFailedException {
-        return v4DumpManager.getDump(RoutingIIds.ROUTING, cache, NO_PARAMS)
+        return v4DumpManager.getDump(FibManagementIIds.FIB_MNGMNT, cache, NO_PARAMS)
                 .toJavaUtil()
                 .map(ipFibDetailsReplyDump -> ipFibDetailsReplyDump.ipFibDetails)
                 .orElse(Collections.emptyList())
@@ -15,7 +15,7 @@
  */
 
 
-package io.fd.hc2vpp.routing.services;
+package io.fd.hc2vpp.fib.management.services;
 
 import com.google.inject.Inject;
 import com.google.inject.Provider;
@@ -33,6 +33,6 @@ public class FibTableServiceProvider implements Provider<FibTableService> {
 
     @Override
     public FibTableService get() {
-        return new FibTableServiceImpl(api, modificationCache);
+        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 (file)
index 0000000..781c670
--- /dev/null
@@ -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 (file)
index 0000000..74b8dc7
--- /dev/null
@@ -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<Table, TableKey> {
+    FibTableCustomizer(@Nonnull final FutureJVppCore vppApi) {
+        super(vppApi);
+    }
+
+    @Override
+    public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Table> instanceIdentifier,
+                                       @Nonnull final Table table,
+                                       @Nonnull final WriteContext writeContext) throws WriteFailedException {
+        bindFibTableRequest(table).write(instanceIdentifier);
+    }
+
+    @Override
+    public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Table> 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 (file)
index 0000000..f1f5371
--- /dev/null
@@ -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<ReaderFactory> readerFactories = new HashSet<>();
+
+    @Inject
+    private Set<WriterFactory> 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 (file)
index 0000000..1341e7e
--- /dev/null
@@ -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 (file)
index 0000000..6b2d8c4
--- /dev/null
@@ -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<Table, TableKey, TableBuilder> 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> TABLE_V4_ID =
+            FibManagementIIds.FM_FIB_TABLES.child(Table.class, new TableKey(Ipv4.class, new VniReference(1L)));
+    private static final InstanceIdentifier<Table> 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<Ip6FibDetailsReplyDump, Void> manager_v6;
+    private DumpCacheManager<IpFibDetailsReplyDump, Void> manager_v4;
+
+    @Mock
+    private EntityDumpExecutor<Ip6FibDetailsReplyDump, Void> executor_v6;
+
+    @Mock
+    private EntityDumpExecutor<IpFibDetailsReplyDump, Void> executor_v4;
+
+    @Mock
+    private ModificationCache cache;
+
+    public FibTableCustomizerTest() {
+        super(Table.class, FibTablesBuilder.class);
+    }
+
+    @Override
+    public void setUp() throws ReadFailedException {
+        manager_v6 = new DumpCacheManager.DumpCacheManagerBuilder<Ip6FibDetailsReplyDump, Void>()
+                .withExecutor(executor_v6)
+                .acceptOnly(Ip6FibDetailsReplyDump.class)
+                .build();
+        manager_v4 = new DumpCacheManager.DumpCacheManagerBuilder<IpFibDetailsReplyDump, Void>()
+                .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<TableKey> 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<Table, TableBuilder> initCustomizer() {
+        return new FibTableCustomizer(manager_v4, manager_v6);
+    }
+}
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package io.fd.hc2vpp.routing.services;
+package io.fd.hc2vpp.fib.management.services;
 
 import static io.fd.vpp.jvpp.Assertions.assertEquals;
 import static org.mockito.ArgumentMatchers.any;
@@ -23,13 +23,12 @@ 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.routing.RoutingIIds;
-import io.fd.hc2vpp.routing.helpers.RoutingRequestTestHelper;
-import io.fd.hc2vpp.routing.helpers.SchemaContextTestHelper;
+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.WriteContext;
 import io.fd.honeycomb.translate.write.WriteFailedException;
 import io.fd.vpp.jvpp.core.dto.Ip6FibDetailsReplyDump;
 import io.fd.vpp.jvpp.core.dto.IpFibDetailsReplyDump;
@@ -44,7 +43,7 @@ import org.mockito.Captor;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 
-public class FibTableServiceImplTest implements RoutingRequestTestHelper, SchemaContextTestHelper {
+public class FibTableServiceImplTest implements SchemaContextTestHelper, ByteDataTranslator, FutureProducer {
 
     private static final int FIB_TABLE_ID = 123456;
     private static final String FIB_TABLE_NAME = "VRF123456";
@@ -53,9 +52,6 @@ public class FibTableServiceImplTest implements RoutingRequestTestHelper, Schema
     @Mock
     private static FutureJVppCore api;
 
-    @Mock
-    private static WriteContext ctx;
-
     @Mock
     private ModificationCache modificationCache;
 
@@ -74,35 +70,32 @@ public class FibTableServiceImplTest implements RoutingRequestTestHelper, Schema
 
     @Test(expected = FibTableService.FibTableDoesNotExistException.class)
     public void checkTableExistTest() throws ReadFailedException, FibTableService.FibTableDoesNotExistException {
-        FibTableServiceImpl fibService = new FibTableServiceImpl(api, ctx.getModificationCache());
-
+        FibTableServiceImpl fibService = new FibTableServiceImpl(api);
         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);
+        FibTableServiceImpl fibTableService = new FibTableServiceImpl(api);
+        fibTableService.write(FibManagementIIds.FIB_MNGMNT, FIB_TABLE_ID, FIB_TABLE_NAME, false);
 
         verify(api, times(1)).ipTableAddDel(argumentCaptor.capture());
 
-        final IpTableAddDel jvppRequest = argumentCaptor.getValue();
-        assertTableAddDelRequest(jvppRequest, true, false);
+        assertTableAddDelRequest(argumentCaptor.getValue(), 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);
+        FibTableServiceImpl fibTableService = new FibTableServiceImpl(api);
+        fibTableService.write(FibManagementIIds.FIB_MNGMNT, FIB_TABLE_ID, FIB_TABLE_NAME, true);
 
         verify(api, times(1)).ipTableAddDel(argumentCaptor.capture());
 
-        final IpTableAddDel jvppRequest = argumentCaptor.getValue();
-        assertTableAddDelRequest(jvppRequest, true, true);
+        assertTableAddDelRequest(argumentCaptor.getValue(), true);
     }
 
-    private void assertTableAddDelRequest(IpTableAddDel jvppRequest, boolean isAdd, boolean isIpv6) {
-        assertEquals(ByteDataTranslator.INSTANCE.booleanToByte(isAdd), jvppRequest.isAdd);
+    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 (file)
index 0000000..c9d05dc
--- /dev/null
@@ -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 (file)
index 0000000..a96ca28
--- /dev/null
@@ -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 (executable)
index 0000000..7555284
--- /dev/null
@@ -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 (file)
index 0000000..2596097
--- /dev/null
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+    <parent>
+        <groupId>io.fd.hc2vpp.common</groupId>
+        <artifactId>hc2vpp-parent</artifactId>
+        <version>1.18.07-SNAPSHOT</version>
+        <relativePath>../common/hc2vpp-parent</relativePath>
+    </parent>
+
+    <groupId>io.fd.hc2vpp.routing</groupId>
+    <artifactId>fib-management-aggregator</artifactId>
+    <version>1.18.07-SNAPSHOT</version>
+    <name>${project.artifactId}</name>
+    <packaging>pom</packaging>
+    <modelVersion>4.0.0</modelVersion>
+    <prerequisites>
+        <maven>3.1.1</maven>
+    </prerequisites>
+    <description>Aggregator for Hc2vpp FIB management plugin</description>
+
+    <modules>
+        <module>fib-management-api</module>
+        <module>fib-management-impl</module>
+    </modules>
+
+    <!-- DO NOT install or deploy the repo root pom as it's only needed to initiate a build -->
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-deploy-plugin</artifactId>
+                <configuration>
+                    <skip>true</skip>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-install-plugin</artifactId>
+                <configuration>
+                    <skip>true</skip>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>
diff --git a/pom.xml b/pom.xml
index e5f7b7f..72d3083 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -41,6 +41,7 @@
     <module>ioam</module>
     <module>nsh</module>
     <module>routing</module>
+    <module>fib-management</module>
     <module>nat</module>
     <module>lisp</module>
     <module>release-notes</module>
@@ -56,4 +57,4 @@
     <module>bgp</module>
     <module>mpls</module>
   </modules>
-</project>
\ No newline at end of file
+</project>
index 8a37b59..7226797 100644 (file)
             <artifactId>guice-multibindings</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>io.fd.hc2vpp.fib.management</groupId>
+            <artifactId>fib-management-impl</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
         <!-- Testing dependencies-->
         <dependency>
             <groupId>junit</groupId>
index 6badcab..8a109ae 100644 (file)
 
 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<? extends Provider<FibTableService>> fibTableServiceProvider;
-
-    public RoutingModule() {
-        this(FibTableServiceProvider.class);
-    }
-
-    @VisibleForTesting
-    protected RoutingModule(@Nonnull final Class<? extends Provider<FibTableService>> 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)
index 326b6f8..b68a503 100644 (file)
@@ -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;
index cd3c4d2..4af6f55 100644 (file)
@@ -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;
index 679b903..a12d0e0 100644 (file)
@@ -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<ReaderFactory> readerFactories = new HashSet<>();
 
index b4cf64e..c96e313 100644 (file)
@@ -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;
index 6545ed6..b5c6217 100644 (file)
@@ -30,6 +30,7 @@
         <api.docs.modules>
             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,
             </plugin>
         </plugins>
     </build>
-</project>
\ No newline at end of file
+</project>
index 8399ff2..61ded4b 100644 (file)
@@ -49,6 +49,7 @@
     <distribution.modules>
       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,