= Developing plugins for VPP

link:release_notes.html[< Home]

Honeycomb's primary use case is to provide an agent for VPP. This section provides a tutorial for how to develop a Honeycomb plugin that translates YANG modeled data into VPP binary API invocation.

== Analyzing VPP's API
For this tutorial, VPP's VXLAN management API. Honeycomb already contains VXLAN management translation code inside V3PO plugin. This will be a simplified version.

Looking at VPP's API definition file, there are 3 calls related to VXLAN:

vxlan_add_del_tunnel - Creates and Deletes VXLAN tunnel (Update not supported)
vxlan_tunnel_dump - Reads all VXLAN tunnels
These are the shared-memory, binary APIs of VPP that would be difficult to use from Java. But VPP contains a jvpp component, that's completely generated from VPP's API definition file and allows Java applications to manage VPP in plain Java using JNI in the background. Honeycomb provides a component that can be included in a distribution.

== Updating sample-plugin to manage VPP

This tutorial starts where the previous one left and will continue to modify the sample plugin in order to be able to manage VPP's VXLAN tunnels.

=== Updating YANG models
YANG models need to reflect the intent of managing VXLAN tunnels in VPP. As mentioned before, VPP exposes 2 calls to manage VXLAN tunnels. Each vxlan tunnel has a set of attributes, but for simplicity, only 2 of them will be exposed in YANG : source IP address and destination IP address. Rest of attributes will be set to default values in the code.

So let's update the sample-plugin-params grouping to:

[source,yang]
----
grouping sample-plugin-params {
    container vxlans {
        list vxlan-tunnel {

            key id;
            leaf id {
                type string;
            }

            leaf src {
              type inet:ip-address;
            }
            leaf dst {
              type inet:ip-address;
            }
        }
    }
}
----

Since ietf-inet-types YANG model is used for the ip-address type, it needs to be imported (after the prefix statement):

[source,yang]
----
import ietf-inet-types { prefix "inet"; }
----

NOTE: The reason this works is that there are some general YANG models such as ietf-inet-types added to *-api module in its pom.xml.

Now rebuild the *-api module.

=== JVpp dependency
Another important thing that the plugin needs is dependency to VPP's JVpp (Java APIs). To do so, just update *-impl's pom.xml with:

[source,xml,subs="+attributes"]
----
<!-- VPP's core Java APIs -->
<dependency>
    <groupId>io.fd.vpp</groupId>
    <artifactId>jvpp-core</artifactId>
    <version>{project-vpp-snapshot-version}</version>
</dependency>
----

Also add vpp-translate-utils dependency so that writing translation code is easier:

[source,xml,subs="+attributes"]
----
<dependency>
    <groupId>io.fd.hc2vpp.vpp</groupId>
    <artifactId>vpp-translate-utils</artifactId>
    <version>{project-version}</version>
</dependency>
----

To use advanced features such as context caching, use dependency to translate-utils

[source,xml,subs="+attributes"]
----
<dependency>
    <groupId>io.fd.honeycomb</groupId>
    <artifactId>translate-utils</artifactId>
    <version>${project.version}</version>
</dependency>
----

Do not rebuild yet, since the APIs for this plugin have changed and the compilation would fail. But make sure to update the project if using an IDE to pick up the Jvpp dependency.

=== Updating the customizers

First of all, remove CrudService interface and ElementCrudService class. Will not be needed now.

==== Changes to ElementStateCustomizer

Rename it to VxlanReadCustomzier. Update the code to:

[source,java]
----
package io.fd.hc2vpp.samples.read;


import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import io.fd.hc2vpp.common.translate.util.AddressTranslator;
import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer;
import io.fd.hc2vpp.common.translate.util.NamingContext;
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.VxlanTunnelDetails;
import io.fd.vpp.jvpp.core.dto.VxlanTunnelDetailsReplyDump;
import io.fd.vpp.jvpp.core.dto.VxlanTunnelDump;
import io.fd.vpp.jvpp.core.future.FutureJVppCore;
import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.sample.plugin.rev161214.sample.plugin.params.VxlansBuilder;
import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.sample.plugin.rev161214.sample.plugin.params.vxlans.VxlanTunnel;
import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.sample.plugin.rev161214.sample.plugin.params.vxlans.VxlanTunnelBuilder;
import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.sample.plugin.rev161214.sample.plugin.params.vxlans.VxlanTunnelKey;
import org.opendaylight.yangtools.concepts.Builder;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;

import javax.annotation.Nonnull;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;


/**
 * Reader for {@link VxlanTunnel} list node from our YANG model.
 */
public final class VxlanReadCustomizer implements
        ListReaderCustomizer<VxlanTunnel, VxlanTunnelKey, VxlanTunnelBuilder>,
        // provides utility methods to translate binary data
        ByteDataTranslator,
        // provides utility methods to translate Ipv4,Ipv6,Mac addresses.
        // in case that just one address family processing is needed,use *address-family-name*Translator,
        // for ex Ipv4Translator
        AddressTranslator,
        // provides utility methods to consume results of jvpp api calls
        JvppReplyConsumer {

    // JVpp core. This is the Java API for VPP's core API.
    private final FutureJVppCore jVppCore;
    // Naming context for interfaces
    // Honeycomb provides a "context" storage for plugins. This storage is used for storing metadata required during
    // data translation (just like in this plugin). An example of such metadata would be interface identifier. In Honeycomb
    // we use string names for interfaces, however VPP uses only indices (that are created automatically).
    // This means that translation layer has to store the mapping between HC interface name <-> VPP' interface index.
    // And since vxlan tunnel is a type of interface in VPP, the same applies here
    //
    // Honeycomb provides a couple utilities on top of context storage such as NamingContext. It is just a map
    // backed by context storage that makes the lookup and storing easier.
    private final NamingContext vxlanNamingContext;

    // Dump manager that provides intelligent caching based on provided contextual key
    private DumpCacheManager<VxlanTunnelDetailsReplyDump, Integer> dumpManager;

    public VxlanReadCustomizer(final FutureJVppCore jVppCore, final NamingContext vxlanNamingContext) {
        this.jVppCore = jVppCore;
        this.vxlanNamingContext = vxlanNamingContext;

        this.dumpManager = new DumpCacheManager.DumpCacheManagerBuilder<VxlanTunnelDetailsReplyDump, Integer>()
                // executor handles dumping of data itself, based on provided lambda
                // instanceIdentifier - identifier of entity that we are caching, should be the one passed as parameter
                // to getAllIds or readCurrentAttributes. Caching is by default performed based on this key
                // param - can be anything that needs to be bind to request
                .withExecutor((instanceIdentifier, param) -> {
                    // creates dump request
                    final VxlanTunnelDump vxlanTunnelDump = new VxlanTunnelDump();
                    // binds parameters, in this case index of interface
                    vxlanTunnelDump.swIfIndex = param;
                    // perform dump action with default timeout and either return result or throw ReadFailedException
                    // identified by provided instanceIdentifier
                    return getReplyForRead(jVppCore.vxlanTunnelDump(vxlanTunnelDump).toCompletableFuture(), instanceIdentifier);
                })
                // this provides type-awareness for caching, so multiple DumpManagers can be used withing the same
                // customizer, using same instance identifiers, as long as they handle different data types
                .acceptOnly(VxlanTunnelDetailsReplyDump.class)

                // either acceptOnly is required or custom cache key factory must be provided to tell manager,
                // how to produce keys. can be used to change caching scope of data
                //.withCacheKeyFactory()

                // serves as post-dump processing of any kind, triggered only once after calling executor
                //.withPostProcessingFunction()
                .build();
    }

    /**
     * Provide a list of IDs for all VXLANs in VPP
     */
    @Nonnull
    @Override
    public List<VxlanTunnelKey> getAllIds(@Nonnull final InstanceIdentifier<VxlanTunnel> id,
                                          @Nonnull final ReadContext context)
            throws ReadFailedException {

        final Optional<VxlanTunnelDetailsReplyDump> dump = dumpManager.getDump(id, context.getModificationCache(), 0);

        if (!dump.isPresent()) {
            return Collections.emptyList();
        }

        return dump.get().vxlanTunnelDetails.stream()
                // Need a name of an interface here. Use context to look it up from index
                // In case the naming context does not contain such mapping, it creates an artificial one
                .map(a -> new VxlanTunnelKey(vxlanNamingContext.getName(a.swIfIndex, context.getMappingContext())))
                .collect(Collectors.toList());
    }

    @Override
    public void merge(@Nonnull final Builder<? extends DataObject> builder, @Nonnull final List<VxlanTunnel> readData) {
        // Just set the readValue into parent builder
        // The cast has to be performed here
        ((VxlansBuilder) builder).setVxlanTunnel(readData);
    }

    @Nonnull
    @Override
    public VxlanTunnelBuilder getBuilder(@Nonnull final InstanceIdentifier<VxlanTunnel> id) {
        // Setting key from id is not necessary, builder will take care of that
        return new VxlanTunnelBuilder();
    }

    /**
     * Read all the attributes of a single VXLAN tunnel
     */
    @Override
    public void readCurrentAttributes(@Nonnull final InstanceIdentifier<VxlanTunnel> id,
                                      @Nonnull final VxlanTunnelBuilder builder,
                                      @Nonnull final ReadContext ctx) throws ReadFailedException {
        // The ID received here contains the name of a particular interface that should be read
        // It was either requested directly by HC users or is one of the IDs from getAllIds that could have been invoked
        // just before this method invocation
        final String vxlanName = id.firstKeyOf(VxlanTunnel.class).getId();

        // Naming context must contain the mapping because:
        // 1. The vxlan tunnel was created in VPP using HC + this plugin meaning we stored the mapping in write customizer
        // 2. The vxlan tunnel was already present in VPP, but HC reconciliation mechanism took care of that (as long as proper Initializer is provided by this plugin)

        final Optional<VxlanTunnelDetailsReplyDump> dump = dumpManager.getDump(id, ctx.getModificationCache(),
                vxlanNamingContext.getIndex(vxlanName, ctx.getMappingContext()));


        Preconditions.checkState(dump.isPresent() && dump.get().vxlanTunnelDetails != null);
        final VxlanTunnelDetails singleVxlanDetail = dump.get().vxlanTunnelDetails.stream().findFirst().get();

        // Now translate all attributes into provided builder
        final Boolean isIpv6 = byteToBoolean(singleVxlanDetail.isIpv6);
        builder.setSrc(arrayToIpAddress(isIpv6, singleVxlanDetail.srcAddress));
        builder.setDst(arrayToIpAddress(isIpv6, singleVxlanDetail.dstAddress));
        // There are additional attributes of a vxlan tunnel that wont be used here
    }
}
----

The '"ReaderFactory also needs to be updated:

[source,java]
----
package io.fd.hc2vpp.samples.read;

import com.google.inject.Inject;
import io.fd.hc2vpp.common.translate.util.NamingContext;
import io.fd.honeycomb.translate.impl.read.GenericListReader;
import io.fd.honeycomb.translate.read.ReaderFactory;
import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder;
import io.fd.vpp.jvpp.core.future.FutureJVppCore;
import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.sample.plugin.rev161214.SamplePluginState;
import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.sample.plugin.rev161214.SamplePluginStateBuilder;
import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.sample.plugin.rev161214.sample.plugin.params.Vxlans;
import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.sample.plugin.rev161214.sample.plugin.params.VxlansBuilder;
import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.sample.plugin.rev161214.sample.plugin.params.vxlans.VxlanTunnel;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;

import javax.annotation.Nonnull;

/**
 * Factory producing readers for sample-plugin plugin's data.
 */
public final class ModuleStateReaderFactory implements ReaderFactory {

    public static final InstanceIdentifier<SamplePluginState> ROOT_STATE_CONTAINER_ID =
            InstanceIdentifier.create(SamplePluginState.class);

    /**
     * Injected vxlan naming context shared with writer, provided by this plugin
     */
    @Inject
    private NamingContext vxlanNamingContext;
    /**
     * Injected jvpp core APIs, provided by Honeycomb's infrastructure
     */
    @Inject
    private FutureJVppCore jvppCore;

    @Override
    public void init(@Nonnull final ModifiableReaderRegistryBuilder registry) {
        // register reader that only delegate read's to its children
        registry.addStructuralReader(ROOT_STATE_CONTAINER_ID, SamplePluginStateBuilder.class);
        // register reader that only delegate read's to its children
        registry.addStructuralReader(ROOT_STATE_CONTAINER_ID.child(Vxlans.class), VxlansBuilder.class);

        // just adds reader to the structure
        // use addAfter/addBefore if you want to add specific order to readers on the same level of tree
        // use subtreeAdd if you want to handle multiple nodes in single customizer/subtreeAddAfter/subtreeAddBefore if you also want to add order
        // be aware that instance identifier passes to subtreeAdd/subtreeAddAfter/subtreeAddBefore should define subtree,
        // therefore it should be relative from handled node down - InstanceIdentifier.create(HandledNode), not parent.child(HandledNode.class)
        registry.add(new GenericListReader<>(
                // What part of subtree this reader handles is identified by an InstanceIdentifier
                ROOT_STATE_CONTAINER_ID.child(Vxlans.class).child(VxlanTunnel.class),
                // Customizer (the actual translation code to do the heavy lifting)
                new VxlanReadCustomizer(jvppCore, vxlanNamingContext)));
    }
}
----

==== Changes to ElementCustomizer

Rename to VxlanWriteCustomizer. Update the code to:

[source,java]
----
package io.fd.hc2vpp.samples.write;


import io.fd.hc2vpp.common.translate.util.AddressTranslator;
import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer;
import io.fd.hc2vpp.common.translate.util.NamingContext;
import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer;
import io.fd.honeycomb.translate.write.WriteContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
import io.fd.vpp.jvpp.core.dto.VxlanAddDelTunnel;
import io.fd.vpp.jvpp.core.dto.VxlanAddDelTunnelReply;
import io.fd.vpp.jvpp.core.future.FutureJVppCore;
import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.sample.plugin.rev161214.sample.plugin.params.vxlans.VxlanTunnel;
import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.sample.plugin.rev161214.sample.plugin.params.vxlans.VxlanTunnelKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;

import javax.annotation.Nonnull;

/**
 * Writer for {@link VxlanTunnel} list node from our YANG model.
 */
public final class VxlanWriteCustomizer implements ListWriterCustomizer<VxlanTunnel, VxlanTunnelKey>,
        ByteDataTranslator,
        AddressTranslator,
        JvppReplyConsumer {

    /**
     * JVpp APIs
     */
    private final FutureJVppCore jvppCore;
    /**
     * Shared vxlan tunnel naming context
     */
    private final NamingContext vxlanTunnelNamingContext;

    public VxlanWriteCustomizer(final FutureJVppCore jvppCore, final NamingContext vxlanTunnelNamingContext) {
        this.jvppCore = jvppCore;
        this.vxlanTunnelNamingContext = vxlanTunnelNamingContext;
    }

    @Override
    public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<VxlanTunnel> id,
                                       @Nonnull final VxlanTunnel dataAfter,
                                       @Nonnull final WriteContext writeContext) throws WriteFailedException {
        // Create and set vxlan tunnel add request
        final VxlanAddDelTunnel vxlanAddDelTunnel = new VxlanAddDelTunnel();
        // 1 for add, 0 for delete
        vxlanAddDelTunnel.isAdd = 1;
        // dataAfter is the new vxlanTunnel configuration
        final boolean isIpv6 = dataAfter.getSrc().getIpv6Address() != null;
        vxlanAddDelTunnel.isIpv6 = booleanToByte(isIpv6);
        vxlanAddDelTunnel.srcAddress = ipAddressToArray(isIpv6, dataAfter.getSrc());
        vxlanAddDelTunnel.dstAddress = ipAddressToArray(isIpv6, dataAfter.getDst());
        // There are other input parameters that are not exposed by our YANG model, default values will be used


        final VxlanAddDelTunnelReply replyForWrite = getReplyForWrite(jvppCore.vxlanAddDelTunnel(vxlanAddDelTunnel).toCompletableFuture(), id);

        // VPP returns the index of new vxlan tunnel
        final int newVxlanTunnelIndex = replyForWrite.swIfIndex;
        // It's important to store it in context so that reader knows to which name a vxlan tunnel is mapped
        vxlanTunnelNamingContext.addName(newVxlanTunnelIndex, dataAfter.getId(), writeContext.getMappingContext());
    }

    /**
    * Most VPP apis does not support update, these updates are handled as delete+create pair invocation.
    * If you want to implement update directly, please @Override method updateCurrentAttributes()
    */

    @Override
    public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<VxlanTunnel> id,
                                        @Nonnull final VxlanTunnel dataBefore,
                                        @Nonnull final WriteContext writeContext) throws WriteFailedException {
        // Create and set vxlan tunnel add request
        final VxlanAddDelTunnel vxlanAddDelTunnel = new VxlanAddDelTunnel();
        // 1 for add, 0 for delete
        vxlanAddDelTunnel.isAdd = 0;
        // Vxlan tunnel is identified by its attributes when deleting, not index, so set all attributes
        // dataBefore is the vxlan tunnel that's being deleted
        final boolean isIpv6 = dataBefore.getSrc().getIpv6Address() != null;
        vxlanAddDelTunnel.isIpv6 = booleanToByte(isIpv6);
        vxlanAddDelTunnel.srcAddress = ipAddressToArray(isIpv6, dataBefore.getSrc());
        vxlanAddDelTunnel.dstAddress = ipAddressToArray(isIpv6, dataBefore.getDst());
        // There are other input parameters that are not exposed by our YANG model, default values will be used

        final VxlanAddDelTunnelReply replyForWrite = getReplyForWrite(jvppCore.vxlanAddDelTunnel(vxlanAddDelTunnel).toCompletableFuture(), id);
        // It's important to remove the mapping from context
        vxlanTunnelNamingContext.removeName(dataBefore.getId(), writeContext.getMappingContext());
    }
}
----

The '"WriterFactory also needs to be updated:

[source,java]
----
package io.fd.hc2vpp.samples.write;

import com.google.inject.Inject;
import io.fd.hc2vpp.common.translate.util.NamingContext;
import io.fd.honeycomb.translate.impl.write.GenericWriter;
import io.fd.honeycomb.translate.write.WriterFactory;
import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder;
import io.fd.vpp.jvpp.core.future.FutureJVppCore;
import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.sample.plugin.rev161214.SamplePlugin;
import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.sample.plugin.rev161214.sample.plugin.params.Vxlans;
import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.sample.plugin.rev161214.sample.plugin.params.vxlans.VxlanTunnel;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import javax.annotation.Nonnull;

/**
 * Factory producing writers for sample-plugin plugin's data.
 */
public final class ModuleWriterFactory implements WriterFactory {

    private static final InstanceIdentifier<SamplePlugin> ROOT_CONTAINER_ID = InstanceIdentifier.create(SamplePlugin.class);

    /**
     * Injected vxlan naming context shared with writer, provided by this plugin
     */
    @Inject
    private NamingContext vxlanNamingContext;
    /**
     * Injected jvpp core APIs, provided by Honeycomb's infrastructure
     */
    @Inject
    private FutureJVppCore jvppCore;

    @Override
    public void init(@Nonnull final ModifiableWriterRegistryBuilder registry) {
        // Unlike ReaderFactory, there's no need to add structural writers, just the writers that actually do something

        // register writer for vxlan tunnel
        registry.add(new GenericWriter<>(
                // What part of subtree this writer handles is identified by an InstanceIdentifier
                ROOT_CONTAINER_ID.child(Vxlans.class).child(VxlanTunnel.class),
                // Customizer (the actual translation code to do the heavy lifting)
                new VxlanWriteCustomizer(jvppCore, vxlanNamingContext)));
    }
}
----

==== Changes to Module
The module needs to be updated to:

* Include new instance of naming context
* Remove crud service

and the code needs to look like:

[source,java]
----
package io.fd.hc2vpp.samples;

import com.google.inject.AbstractModule;
import com.google.inject.multibindings.Multibinder;
import io.fd.hc2vpp.common.translate.util.NamingContext;
import io.fd.hc2vpp.samples.read.ModuleStateReaderFactory;
import io.fd.hc2vpp.samples.write.ModuleWriterFactory;
import io.fd.honeycomb.translate.read.ReaderFactory;
import io.fd.honeycomb.translate.write.WriterFactory;
import net.jmob.guice.conf.core.ConfigurationModule;

/**
 * Module class instantiating sample-plugin plugin components.
 */
public final class Module extends AbstractModule {

    @Override
    protected void configure() {
        // requests injection of properties
        install(ConfigurationModule.create());
        requestInjection(ModuleConfiguration.class);

        // bind naming context instance for reader and writer factories
        // the first parameter is artificial name prefix in cases a name needs to be reconstructed for a vxlan tunnel
        // that is present in VPP but not in Honeycomb (could be extracted into configuration)
        // the second parameter is just the naming context ID (could be extracted into configuration)
        binder().bind(NamingContext.class).toInstance(new NamingContext("vxlan-tunnel", "vxlan-tunnel-context"));

        // creates reader factory binding
        // can hold multiple binding for separate yang modules
        final Multibinder<ReaderFactory> readerFactoryBinder = Multibinder.newSetBinder(binder(), ReaderFactory.class);
        readerFactoryBinder.addBinding().to(ModuleStateReaderFactory.class);

        // create writer factory binding
        // can hold multiple binding for separate yang modules
        final Multibinder<WriterFactory> writerFactoryBinder = Multibinder.newSetBinder(binder(), WriterFactory.class);
        writerFactoryBinder.addBinding().to(ModuleWriterFactory.class);


        // Disable notification producer for now
//        Multibinder.newSetBinder(binder(), ManagedNotificationProducer.class).addBinding()
//                .to(SampleNotificationProducer.class);
    }
}
----
*Now it's time to rebuild the plugin using mvn clean install to make the jars available for integrating them with vpp-integration distribution in next sections*

== Integrating with vpp-integration distribution
The vxlan tunnel management plugin can now be integrated with any honeycomb distribution. Honeycomb provides a vpp-integration distribution, where all VPP related plugins integrate to create a distribution with all available VPP related features.

This distribution comes with honeycomb infrastructure + common components for VPP Honeycomb plugins (e.g. Java APIs for VPP).

In order to add this new plugin into vpp-integration:

* clone honeycomb codebase (since that's the home of vpp-integration distribution)
* add a dependency for this sample plugin in vpp-integration distribution (honeycomb/vpp-integration/minimal-distribution/pom.xml):

[source,xml,subs="+attributes"]
----
<dependency>
  <groupId>io.fd.honeycomb.tutorial</groupId>
  <artifactId>sample-plugin-impl</artifactId>
  <version>{project-version}</version>
</dependency>
----

* modify Modify vpp-integration-distribution pom.xml property <distribution.modules>
[source,xml,subs="+attributes"]
----
 <distribution.modules>
      some.module.full.package.name.ModuleClass,
      io.fd.hc2vpp.samples.Module //add your plugin module class
</distribution.modules>
----

Now just rebuild the honeycomb project.

== Verifying distribution
At this point, the vpp-integration distribution with sample-plugin can now be started. But first, make sure that a compatible version of VPP is installed and running. Next, start honeycomb with:

[source,xml,subs="+attributes"]
----
sudo hc2vpp/vpp-integration/minimal-distribution/target/vpp-integration-distribution-{project-version}-hc/vpp-integration-distribution-{project-version}
----

=== Testing over RESTCONF
Reading vxlans operational data (should return empty vxlans container at first):

 curl -u admin:admin  http://localhost:8183/restconf/operational/sample-plugin:sample-plugin-state

Adding a vxlan tunnel:

 curl -H 'Content-Type: application/json' -H 'Accept: application/json' -u admin:admin -X PUT -d '{"vxlans":{"vxlan-tunnel": [{"id":"vxlan-test-tunnel", "src":"10.0.0.1", "dst":"10.0.0.2"}]}}' http://localhost:8183/restconf/config/sample-plugin:sample-plugin/vxlans

Reading vxlans config data (data that we posted to Honeycomb):

 curl -u admin:admin  http://localhost:8183/restconf/config/sample-plugin:sample-plugin

Reading vxlans operational data (data coming from VPP being transformed by ReaderCustomizer on the fly):

 curl -u admin:admin  http://localhost:8183/restconf/operational/sample-plugin:sample-plugin-state

Verifying vxlan tunnel existence in VPP:

 telnet 0 5002
 show interface

should show:

[source]
----
Name                             Idx       State          Counter          Count
local0                            0        down
vxlan_tunnel0                     1         up
----

Deleting a vxlan tunnel:

 curl -u admin:admin -X DELETE http://localhost:8183/restconf/config/sample-plugin:sample-plugin/vxlans/vxlan-tunnel/vxlan-test-tunnel

Disclaimer: The vxlan tunnel will be removed from Honeycomb, and delete command will be executed on VPP, but VPP will just disable that interface and keep it as some sort of placeholder for next vxlan tunnel (that's VPPs behavior, so a vxlan tunnel cant be really deleted). So that's why you would still see the tunnel in VPP's CLI after delete.

==== Testing over NETCONF
Netconf testing guide including Notifications, can be found in Honeycomb/Running_Honeycomb.

NOTE: Netconf and Restconf are equivalent interfaces to Honeycomb, being capable of providing the same APIs. The only difference is with notifications. Only NETCONF is capable of emitting the notifications.

== Full working sample (outdated)

Full working sample (hc2vpp 1.16.09) on github: https://github.com/marosmars/honeycomb-samples/tree/vpp-plugin

[NOTE]
====
just a note on what further work for this plugin might contain:

* unit tests
* POSTMAN REST collection with sample requests
* logging
====
