From e83f0e1d6451c96ef9850b4a8b058c4b5c307617 Mon Sep 17 00:00:00 2001 From: Srihari Raghavan Date: Thu, 27 Oct 2016 15:23:36 +0530 Subject: HONEYCOMB-257 - Honeycomb support for in-band OAM (iOAM) path tracing - Add iOAM module to handle configuration for the iOAM trace VPP plugin - Add iOAM module test to verify add/delete configurations - Reader/Initializers for future, dependent on https://gerrit.fd.io/r/3387 Change-Id: I557604a955771c139165aed7cd9e5716abbac3d1 Signed-off-by: Srihari Raghavan --- ioam/api/asciidoc/Readme.adoc | 3 + ioam/api/pom.xml | 38 +++++ ioam/api/src/main/yang/ioam-sb-trace.yang | 184 ++++++++++++++++++++ ioam/asciidoc/Readme.adoc | 11 ++ ioam/impl/asciidoc/Readme.adoc | 3 + ioam/impl/pom.xml | 123 ++++++++++++++ .../fd/honeycomb/vppioam/impl/VppIoamModule.java | 63 +++++++ .../impl/config/IoamTraceWriterCustomizer.java | 134 +++++++++++++++ .../vppioam/impl/config/VppIoamWriterFactory.java | 49 ++++++ .../impl/util/FutureJVppIoamCustomizer.java | 45 +++++ .../vppioam/impl/util/JVppIoamProvider.java | 62 +++++++ .../honeycomb/vppioam/impl/VppIoamModuleTest.java | 97 +++++++++++ .../impl/config/IoamTraceWriterCustomizerTest.java | 186 +++++++++++++++++++++ ioam/ioam_trace_postman_collection.json | 34 ++++ ioam/pom.xml | 56 +++++++ packaging/deb/trusty/debian/control | 2 +- packaging/deb/xenial/debian/control | 2 +- pom.xml | 3 +- .../src/main/asciidoc/user_guide/user_guide.adoc | 6 + vpp-integration/minimal-distribution/pom.xml | 10 +- 20 files changed, 1107 insertions(+), 4 deletions(-) create mode 100644 ioam/api/asciidoc/Readme.adoc create mode 100644 ioam/api/pom.xml create mode 100644 ioam/api/src/main/yang/ioam-sb-trace.yang create mode 100644 ioam/asciidoc/Readme.adoc create mode 100644 ioam/impl/asciidoc/Readme.adoc create mode 100644 ioam/impl/pom.xml create mode 100755 ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/VppIoamModule.java create mode 100755 ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/config/IoamTraceWriterCustomizer.java create mode 100755 ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/config/VppIoamWriterFactory.java create mode 100755 ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/util/FutureJVppIoamCustomizer.java create mode 100755 ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/util/JVppIoamProvider.java create mode 100644 ioam/impl/src/test/java/io/fd/honeycomb/vppioam/impl/VppIoamModuleTest.java create mode 100644 ioam/impl/src/test/java/io/fd/honeycomb/vppioam/impl/config/IoamTraceWriterCustomizerTest.java create mode 100644 ioam/ioam_trace_postman_collection.json create mode 100644 ioam/pom.xml diff --git a/ioam/api/asciidoc/Readme.adoc b/ioam/api/asciidoc/Readme.adoc new file mode 100644 index 000000000..fe70e0a4a --- /dev/null +++ b/ioam/api/asciidoc/Readme.adoc @@ -0,0 +1,3 @@ += vppioam-api + +Overview of vppioam-api diff --git a/ioam/api/pom.xml b/ioam/api/pom.xml new file mode 100644 index 000000000..ebdadea05 --- /dev/null +++ b/ioam/api/pom.xml @@ -0,0 +1,38 @@ + + + + + io.fd.honeycomb.common + api-parent + 1.16.12-SNAPSHOT + ../../common/api-parent + + + 4.0.0 + io.fd.honeycomb.vppioam + vppioam-api + ${project.artifactId} + 1.16.12-SNAPSHOT + bundle + + + + org.opendaylight.mdsal.model + ietf-interfaces + + + diff --git a/ioam/api/src/main/yang/ioam-sb-trace.yang b/ioam/api/src/main/yang/ioam-sb-trace.yang new file mode 100644 index 000000000..731fda96d --- /dev/null +++ b/ioam/api/src/main/yang/ioam-sb-trace.yang @@ -0,0 +1,184 @@ +module ioam-sb-trace { + yang-version 1; + namespace "urn:cisco:params:xml:ns:yang:ioam-sb-trace"; + prefix ioam-sb-trace; + + import ietf-interfaces { prefix ietf-if; } + + organization "Cisco Systems, Inc."; + + contact + "Author: Srihari Raghavan + srihari@cisco.com"; + + description + "This YANG module defines a component that describing the + configuration of in-band OAM device configuration for + trace elements. + "; + + revision 2016-05-12 { + description + "Base model for in-band OAM trace device configuration."; + reference + ""; + } + + container ioam-trace-config { + description + "Device specific configuration for in-band OAM trace."; + + list trace-config { + key "trace-config-name"; + ordered-by system; + description + "Set of ioam trace configurations that group parameters + required to enable iOAM6 tracing at a service node"; + + leaf trace-config-name { + type string { + length "0..255"; + } + mandatory true; + description + "Unique identifier for each node tracing configuration"; + } + + leaf acl-name { + type string; + description + "The ACL name associated to classify and apply this + trace config"; + } + + leaf trace-type { + type uint8 { + range "3|7|9|17|25|31"; + } + + mandatory true; + description + "Trace type that defines the trace element variant. Moving + from LSB to MSB, each bit represents node_id, ingress_if_id, + egress_if_id, timestamp, app_data and others are undefined. + Currently, the supported values are 0x03, 0x07, 0x09, + 0x11, 0x19 and 0x1f."; + } + + leaf trace-num-elt { + type uint8; + + mandatory true; + description + "Number of trace elements to be inserted in the tracing + options."; + } + + leaf trace-tsp { + type enumeration { + enum seconds { + value 0; + description "Timestamp in seconds."; + } + enum milliseconds { + value 1; + description "Timestamp in milli seconds."; + } + enum microseconds { + value 2; + description "Timestamp in micro seconds."; + } + enum nanoseconds { + value 3; + description "Timestamp in nano seconds."; + } + } + + mandatory true; + description + "This field depicts the delay domain of the trace path, + whether it is in seconds, milliseconds, microseconds + or nanoseconds."; + } + + leaf trace-op { + type enumeration { + enum add { + value 0; + description "Add new and fill trace information."; + } + enum update { + value 1; + description "Update existing trace information."; + } + enum remove { + value 2; + description "Decap or remove existing trace information."; + } + } + + mandatory true; + description + "The type of trace element operation that the service node + handling this profile should do. The options are to add the + trace elements, update the trace elements or to remove the + trace elements."; + } + + leaf trace-app-data { + type uint32; + description + "Application specific data to be added by the node"; + } + + leaf node-id { + type uint32; + mandatory true; + description + "iOAM Service Node id assigned to this node"; + } + + list node-interfaces { + key "index"; + ordered-by system; + description + "List of node's interfaces on which the trace configuration + need to be applied. Typically this is to all interfaces + but can be filtered."; + + leaf index { + type uint32; + mandatory true; + description + "Index for the interfaces list"; + } + + leaf intf-name { + type ietf-if:interface-ref; + mandatory true; + description + "Instance of ietf-interfaces:interface-ref"; + } + } + + /*** links to ioam-sb-data-export ***/ + leaf data-export-profile-name { + type string; + description + "The data export profile name with server information to + send data to."; + } + + /*** Transport encap profiles. Not used currently ***/ + leaf transport-encap-profile-name { + type string; + description + "The transport encap profile name with sub configurations for + handling transport encap."; + } +/*** list: end ***/ + } +/*** container: end ***/ + } +/*** module: end ***/ +} diff --git a/ioam/asciidoc/Readme.adoc b/ioam/asciidoc/Readme.adoc new file mode 100644 index 000000000..c0e30bd70 --- /dev/null +++ b/ioam/asciidoc/Readme.adoc @@ -0,0 +1,11 @@ += ioam + +This is a Honeycomb plugin providing mapping code between HC and iOAM Plugin APIs. + +== Usage + +Refer to ioam_postman_collection.json for sample requests. + +In order to make HC iOAM plugin work, need to start vpp and load ioam plugin first. + +At this point in time, iOAM trace plugin configurations are supported. diff --git a/ioam/impl/asciidoc/Readme.adoc b/ioam/impl/asciidoc/Readme.adoc new file mode 100644 index 000000000..6660fc457 --- /dev/null +++ b/ioam/impl/asciidoc/Readme.adoc @@ -0,0 +1,3 @@ += vppioam-impl + +Overview of vppioam-impl diff --git a/ioam/impl/pom.xml b/ioam/impl/pom.xml new file mode 100644 index 000000000..dd106d003 --- /dev/null +++ b/ioam/impl/pom.xml @@ -0,0 +1,123 @@ + + + + + io.fd.honeycomb.common + impl-parent + 1.16.12-SNAPSHOT + ../../common/impl-parent + + + 4.0.0 + io.fd.honeycomb.vppioam + vppioam-impl + ${project.artifactId} + 1.16.12-SNAPSHOT + bundle + + + 1.0-SNAPSHOT + 16.12-SNAPSHOT + + + + + ${project.groupId} + vppioam-api + ${project.version} + + + + com.google.inject + guice + + + net.jmob + guice.conf + + + com.google.inject.extensions + guice-multibindings + + + com.google.inject.extensions + guice-testlib + test + + + org.hamcrest + hamcrest-all + test + + + + io.fd.honeycomb + translate-impl + ${project.version} + + + io.fd.honeycomb + translate-api + ${project.version} + + + io.fd.honeycomb + notification-api + ${project.version} + + + io.fd.honeycomb + cfg-init + ${project.version} + + + io.fd.vpp + jvpp-registry + ${jvpp.version} + + + io.fd.vpp + jvpp-ioam-trace + ${ioam.version} + + + io.fd.honeycomb.vpp + vpp-translate-utils + ${project.version} + + + io.fd.honeycomb.vpp + vpp-translate-test + ${project.version} + test + + + io.fd.honeycomb + minimal-distribution + ${project.version} + + + junit + junit + test + + + org.mockito + mockito-core + test + + + diff --git a/ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/VppIoamModule.java b/ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/VppIoamModule.java new file mode 100755 index 000000000..34975d71d --- /dev/null +++ b/ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/VppIoamModule.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fd.honeycomb.vppioam.impl; + +import com.google.common.annotations.VisibleForTesting; +import com.google.inject.AbstractModule; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; +import com.google.inject.name.Names; +import com.google.inject.Provider; +import io.fd.honeycomb.data.init.DataTreeInitializer; +import io.fd.honeycomb.translate.read.ReaderFactory; +import io.fd.honeycomb.translate.write.WriterFactory; +import io.fd.honeycomb.vppioam.impl.config.VppIoamWriterFactory; +import io.fd.honeycomb.vppioam.impl.util.JVppIoamProvider; +import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtrace; +import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtraceFacade; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Glue code necessary for Honeycomb distribution to pick up the plugin classes + */ +public final class VppIoamModule extends AbstractModule { + + private static final Logger LOG = LoggerFactory.getLogger(VppIoamModule.class); + private final Class> jvppIoamProviderClass; + + public VppIoamModule() { + this(JVppIoamProvider.class); + } + + @VisibleForTesting + VppIoamModule(Class> jvppIoamProvider) { + this.jvppIoamProviderClass = jvppIoamProvider; + } + + @Override + protected void configure() { + LOG.debug("Installing iOAM module"); + + // Bind to Plugin's JVPP. + bind(FutureJVppIoamtrace.class).toProvider(jvppIoamProviderClass).in(Singleton.class); + + // Below are classes picked up by HC framework + Multibinder.newSetBinder(binder(), WriterFactory.class).addBinding().to(VppIoamWriterFactory.class); + + LOG.debug("Module iOAM successfully configured"); + } +} diff --git a/ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/config/IoamTraceWriterCustomizer.java b/ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/config/IoamTraceWriterCustomizer.java new file mode 100755 index 000000000..8a45e87df --- /dev/null +++ b/ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/config/IoamTraceWriterCustomizer.java @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fd.honeycomb.vppioam.impl.config; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; + +import io.fd.honeycomb.translate.MappingContext; +import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; +import io.fd.honeycomb.translate.vpp.util.ByteDataTranslator; +import io.fd.honeycomb.translate.vpp.util.JvppReplyConsumer; +import io.fd.honeycomb.translate.vpp.util.NamingContext; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.honeycomb.vppioam.impl.util.FutureJVppIoamCustomizer; + +import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileAdd; +import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileAddReply; +import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileDel; +import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileDelReply; +import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtrace; + +import java.util.concurrent.CompletionStage; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.IoamTraceConfig; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.TraceConfig; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.TraceConfig.TraceOp; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.trace.config.NodeInterfaces; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.TraceConfigKey; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.trace.config.NodeInterfaces; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Writer customizer responsible for Ioam Trace create/delete. + */ +public class IoamTraceWriterCustomizer extends FutureJVppIoamCustomizer + implements ListWriterCustomizer, ByteDataTranslator, JvppReplyConsumer { + + private static final Logger LOG = LoggerFactory.getLogger(IoamTraceWriterCustomizer.class); + + public IoamTraceWriterCustomizer(@Nonnull final FutureJVppIoamtrace futureJVppIoam) { + super(futureJVppIoam); + } + + @Override + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final TraceConfig dataCurr, + @Nonnull final WriteContext writeContext) + throws WriteFailedException { + + try { + addTraceConfig(dataCurr, writeContext, id); + } catch (Exception exCreate) { + LOG.error("Add Trace Configuration failed", exCreate); + throw new WriteFailedException.CreateFailedException(id, dataCurr, exCreate); + } + + LOG.debug("Trace config added iid={}, added {}", id, dataCurr); + } + + @Override + public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final TraceConfig dataBefore, + @Nonnull final TraceConfig dataAfter, + @Nonnull final WriteContext ctx) throws WriteFailedException { + try { + deleteTraceConfig(dataBefore, id); + addTraceConfig(dataAfter, ctx, id); + } catch (Exception exUpdate) { + LOG.error("Update Trace Configuration failed", exUpdate); + throw new WriteFailedException.UpdateFailedException(id, dataBefore, dataAfter, exUpdate); + } + + LOG.debug("Trace config updated {}", dataAfter); + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final TraceConfig dataBefore, + @Nonnull final WriteContext ctx) throws WriteFailedException { + try { + deleteTraceConfig(dataBefore, id); + } catch (Exception exDelete) { + LOG.error("Delete Trace Configuration failed", exDelete); + throw new WriteFailedException.DeleteFailedException(id, exDelete); + } + + LOG.debug("Trace config deleted:iid={} dataBefore={}", id, dataBefore); + } + + public TraceProfileAddReply addTraceConfig(TraceConfig traceConfig, + WriteContext ctx, + final InstanceIdentifier id) throws Exception { + + TraceProfileAdd traceProfileAdd = new TraceProfileAdd(); + traceProfileAdd.traceType = (byte) traceConfig.getTraceType().byteValue(); //trace type + traceProfileAdd.numElts = (byte) traceConfig.getTraceNumElt().byteValue(); //num of elts + traceProfileAdd.traceTsp = (byte) traceConfig.getTraceTsp().getIntValue(); // tsp + traceProfileAdd.appData = (int) traceConfig.getTraceAppData().intValue(); // appdata + traceProfileAdd.nodeId = (int) traceConfig.getNodeId().intValue(); // nodeid + + /* Write to VPP */ + final TraceProfileAddReply reply = getReplyForWrite((getFutureJVppIoam(). + traceProfileAdd(traceProfileAdd). + toCompletableFuture()), id); + return reply; + } + + public TraceProfileDelReply deleteTraceConfig(TraceConfig dataBefore, + final InstanceIdentifier id) throws Exception { + TraceProfileDel del = new TraceProfileDel(); + + /* Write to VPP */ + TraceProfileDelReply reply = getReplyForWrite((getFutureJVppIoam(). + traceProfileDel(del).toCompletableFuture()), id); + + return reply; + } +} diff --git a/ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/config/VppIoamWriterFactory.java b/ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/config/VppIoamWriterFactory.java new file mode 100755 index 000000000..40311cd8c --- /dev/null +++ b/ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/config/VppIoamWriterFactory.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.vppioam.impl.config; + +import com.google.common.collect.Sets; +import com.google.inject.Inject; +import com.google.inject.name.Named; +import io.fd.honeycomb.translate.impl.write.GenericListWriter; +import io.fd.honeycomb.translate.vpp.util.NamingContext; +import io.fd.honeycomb.translate.write.WriterFactory; +import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.IoamTraceConfig; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.TraceConfig; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtrace; + +public class VppIoamWriterFactory implements WriterFactory { + + @Nonnull + private final FutureJVppIoamtrace jvppIoam; + + @Inject + public VppIoamWriterFactory(@Nonnull final FutureJVppIoamtrace jvppIoam) { + this.jvppIoam = jvppIoam; + } + + @Override + public void init(@Nonnull final ModifiableWriterRegistryBuilder registry) { + // TraceConfig + final InstanceIdentifier trId = + InstanceIdentifier.create(IoamTraceConfig.class).child(TraceConfig.class); + registry.add(new GenericListWriter<>(trId, new IoamTraceWriterCustomizer(jvppIoam))); + } +} diff --git a/ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/util/FutureJVppIoamCustomizer.java b/ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/util/FutureJVppIoamCustomizer.java new file mode 100755 index 000000000..b60581a1b --- /dev/null +++ b/ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/util/FutureJVppIoamCustomizer.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.vppioam.impl.util; + +import com.google.common.annotations.Beta; +import com.google.common.base.Preconditions; +import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtrace; +import javax.annotation.Nonnull; + +/** + * Abstract utility to hold the IoamApi reference. + */ +@Beta +public abstract class FutureJVppIoamCustomizer { + + private final FutureJVppIoamtrace futureJVppIoam; + + public FutureJVppIoamCustomizer(@Nonnull final FutureJVppIoamtrace futureJVppIoam) { + this.futureJVppIoam = Preconditions.checkNotNull(futureJVppIoam, + "futureJVppIoam should not be null"); + } + + /** + * Get IoamApi reference + * + * @return IoamApi reference + */ + public FutureJVppIoamtrace getFutureJVppIoam() { + return futureJVppIoam; + } +} diff --git a/ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/util/JVppIoamProvider.java b/ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/util/JVppIoamProvider.java new file mode 100755 index 000000000..d95266457 --- /dev/null +++ b/ioam/impl/src/main/java/io/fd/honeycomb/vppioam/impl/util/JVppIoamProvider.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2016 Cisco and 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.honeycomb.vppioam.impl.util; + +import com.google.inject.Inject; +import com.google.inject.Provider; +import io.fd.honeycomb.infra.distro.ProviderTrait; +import java.io.IOException; +import io.fd.vpp.jvpp.JVppRegistry; +import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtrace; +import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtraceFacade; +import io.fd.vpp.jvpp.ioamtrace.JVppIoamtraceImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Provides future API for jvpp-ioam plugin. Must be a singleton due to shutdown hook usage. + * Registers shutdown hook to free plugin's resources on shutdown. + */ +public final class JVppIoamProvider extends ProviderTrait { + + private static final Logger LOG = LoggerFactory.getLogger(JVppIoamProvider.class); + + @Inject + private JVppRegistry registry; + + @Override + protected FutureJVppIoamtraceFacade create() { + try { + final JVppIoamtraceImpl jVppIoamTr = new JVppIoamtraceImpl(); + // Free jvpp-ioam plugin's resources on shutdown + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { + LOG.info("Unloading jvpp-ioam plugin"); + jVppIoamTr.close(); + LOG.info("Successfully unloaded jvpp-ioam plugin"); + } + }); + + LOG.debug("Successfully loaded jvpp-ioam plugin"); + return new FutureJVppIoamtraceFacade(registry, jVppIoamTr); + } catch (IOException e) { + throw new IllegalStateException("Unable to open VPP management connection", e); + } + } +} + diff --git a/ioam/impl/src/test/java/io/fd/honeycomb/vppioam/impl/VppIoamModuleTest.java b/ioam/impl/src/test/java/io/fd/honeycomb/vppioam/impl/VppIoamModuleTest.java new file mode 100644 index 000000000..288122fd0 --- /dev/null +++ b/ioam/impl/src/test/java/io/fd/honeycomb/vppioam/impl/VppIoamModuleTest.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.vppioam.impl; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.Matchers.empty; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.MockitoAnnotations.initMocks; + +import com.google.inject.Guice; +import com.google.inject.Inject; +import com.google.inject.Provider; +import com.google.inject.multibindings.Multibinder; +import com.google.inject.name.Named; +import com.google.inject.testing.fieldbinder.Bind; +import com.google.inject.testing.fieldbinder.BoundFieldModule; +import io.fd.honeycomb.translate.util.read.registry.CompositeReaderRegistryBuilder; +import io.fd.honeycomb.translate.util.write.registry.FlatWriterRegistryBuilder; +import io.fd.honeycomb.translate.vpp.util.NamingContext; +import io.fd.honeycomb.translate.write.WriterFactory; +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; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +import io.fd.honeycomb.vppioam.impl.config.VppIoamWriterFactory; +import io.fd.honeycomb.vppioam.impl.util.JVppIoamProvider; +import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtrace; +import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtraceFacade; +import io.fd.vpp.jvpp.JVppRegistry; + + +public class VppIoamModuleTest { + + @Named("honeycomb-context") + @Bind + @Mock + private DataBroker honeycombContext; + + @Named("honeycomb-initializer") + @Bind + @Mock + private DataBroker honeycombInitializer; + + @Bind + @Mock + private JVppRegistry registry; + + @Inject + private Set writerFactories = new HashSet<>(); + + @Before + public void setUp() throws Exception { + + initMocks(this); + + Guice.createInjector(new VppIoamModule(MockJVppIoamProvider.class), BoundFieldModule.of(this)).injectMembers(this); + } + + @Test + public void testWriterFactories() throws Exception { + assertThat(writerFactories, is(not(empty()))); + + final FlatWriterRegistryBuilder registryBuilder = new FlatWriterRegistryBuilder(); + writerFactories.forEach(factory -> factory.init(registryBuilder)); + assertNotNull(registryBuilder.build()); + } + + private static final class MockJVppIoamProvider implements Provider { + + @Override + public FutureJVppIoamtraceFacade get() { + return mock(FutureJVppIoamtraceFacade.class); + } + } +} + diff --git a/ioam/impl/src/test/java/io/fd/honeycomb/vppioam/impl/config/IoamTraceWriterCustomizerTest.java b/ioam/impl/src/test/java/io/fd/honeycomb/vppioam/impl/config/IoamTraceWriterCustomizerTest.java new file mode 100644 index 000000000..8c182dd01 --- /dev/null +++ b/ioam/impl/src/test/java/io/fd/honeycomb/vppioam/impl/config/IoamTraceWriterCustomizerTest.java @@ -0,0 +1,186 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.vppioam.impl.config; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import io.fd.honeycomb.translate.vpp.util.NamingContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileAdd; +import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileAddReply; +import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileDel; +import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileDelReply; +import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtrace; +import io.fd.vpp.jvpp.VppBaseCallException; +import io.fd.vpp.jvpp.VppCallbackException; + +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.IoamTraceConfig; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.TraceConfig; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.TraceConfig.TraceTsp; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.TraceConfigBuilder; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.TraceConfig.TraceOp; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.trace.config.NodeInterfaces; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.TraceConfigKey; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.trace.config.NodeInterfaces; + + +public class IoamTraceWriterCustomizerTest extends WriterCustomizerTest { + + private static final String TRACE_NAME = "trace_test"; + + @Mock + protected FutureJVppIoamtrace jvppIoam; + + private IoamTraceWriterCustomizer customizer; + + @Override + public void setUp() throws Exception { + customizer = new IoamTraceWriterCustomizer(jvppIoam); + } + + private static TraceConfig generateTraceConfig(final String name) { + final TraceConfigBuilder builder = new TraceConfigBuilder(); + builder.setTraceConfigName(name); + builder.setKey(new TraceConfigKey(name)); + builder.setAclName(name); + builder.setTraceType(new Short("31")); + builder.setTraceNumElt(new Short("4")); + builder.setTraceTsp(TraceTsp.Milliseconds); + builder.setTraceOp(TraceOp.Add); + builder.setTraceAppData(new Long("123")); + builder.setNodeId(new Long("1")); + + return builder.build(); + } + + private static InstanceIdentifier getTraceConfigId(final String name) { + return InstanceIdentifier.create(IoamTraceConfig.class) + .child(TraceConfig.class, new TraceConfigKey(name)); + } + + private void whenTraceAddThenSuccess() { + final TraceProfileAddReply reply = new TraceProfileAddReply(); + reply.context = 1; + doReturn(future(reply)).when(jvppIoam).traceProfileAdd(any(TraceProfileAdd.class)); + } + + private void whenTraceAddThenFailure() { + doReturn(failedFuture()).when(jvppIoam).traceProfileAdd(any(TraceProfileAdd.class)); + } + + private void whenTraceDelThenSuccess() { + final TraceProfileDelReply reply = new TraceProfileDelReply(); + reply.context = 1; + doReturn(future(reply)).when(jvppIoam).traceProfileDel(any(TraceProfileDel.class)); + } + + private void whenTraceDelThenFailure() { + doReturn(failedFuture()).when(jvppIoam).traceProfileDel(any(TraceProfileDel.class)); + } + + private static TraceProfileAdd generateTraceProfileAdd() { + final TraceProfileAdd request = new TraceProfileAdd(); + request.traceType = 0x1f; + request.numElts = 4; + request.nodeId = 1; + request.traceTsp = 1; + request.appData = 123; + + return request; + } + + private static TraceProfileDel generateTraceProfileDel() { + final TraceProfileDel request = new TraceProfileDel(); + + return request; + } + + @Test + public void testCreate() throws Exception { + final TraceConfig traceConfig = generateTraceConfig(TRACE_NAME); + final InstanceIdentifier id = getTraceConfigId(TRACE_NAME); + + whenTraceAddThenSuccess(); + + customizer.writeCurrentAttributes(id, traceConfig, writeContext); + + verify(jvppIoam).traceProfileAdd(generateTraceProfileAdd()); + } + + @Test + public void testCreateFailed() throws Exception { + final TraceConfig traceConfig = generateTraceConfig(TRACE_NAME); + final InstanceIdentifier id = getTraceConfigId(TRACE_NAME); + + whenTraceAddThenFailure(); + + try { + customizer.writeCurrentAttributes(id, traceConfig, writeContext); + } catch (WriteFailedException e) { + //assertTrue(e.getCause() instanceof VppBaseCallException); + verify(jvppIoam).traceProfileAdd(generateTraceProfileAdd()); + + return; + } + fail("WriteFailedException.CreateFailedException was expected"); + } + + @Test + public void testDelete() throws Exception { + + final TraceConfig traceConfig = generateTraceConfig(TRACE_NAME); + final InstanceIdentifier id = getTraceConfigId(TRACE_NAME); + + whenTraceDelThenSuccess(); + + customizer.deleteCurrentAttributes(id, traceConfig, writeContext); + + verify(jvppIoam).traceProfileDel(generateTraceProfileDel()); + } + + @Test + public void testDeleteFailed() throws Exception { + + final TraceConfig traceConfig = generateTraceConfig(TRACE_NAME); + final InstanceIdentifier id = getTraceConfigId(TRACE_NAME); + + whenTraceDelThenFailure(); + + try { + customizer.deleteCurrentAttributes(id, traceConfig, writeContext); + } catch (WriteFailedException e) { + //assertTrue(e.getCause() instanceof VppBaseCallException); + verify(jvppIoam).traceProfileDel(generateTraceProfileDel()); + + return; + } + fail("WriteFailedException.DeleteFailedException was expected"); + + customizer.deleteCurrentAttributes(id, traceConfig, writeContext); + } +} diff --git a/ioam/ioam_trace_postman_collection.json b/ioam/ioam_trace_postman_collection.json new file mode 100644 index 000000000..d5248139a --- /dev/null +++ b/ioam/ioam_trace_postman_collection.json @@ -0,0 +1,34 @@ +{ + "id": "7d81e8b0-274e-1f22-de94-d40cb78a389d", + "name": "Honeycomb RESTCONF calls for iOAM Trace", + "description": "To enable iOAM trace on VPP management nodes.", + "order": [ + "f5a5aaea-2d61-a57f-191a-7cc81286f605" + ], + "folders": [], + "timestamp": 1478073563257, + "owner": 0, + "public": false, + "requests": [ + { + "id": "f5a5aaea-2d61-a57f-191a-7cc81286f605", + "headers": "Authorization: Basic YWRtaW46YWRtaW4=\nContent-Type: application/json\n", + "url": "http://localhost:8181/restconf/config/ioam-sb-trace:ioam-trace-config/", + "preRequestScript": "", + "pathVariables": {}, + "method": "PUT", + "data": [], + "dataMode": "raw", + "version": 2, + "tests": "", + "currentHelper": "normal", + "helperAttributes": {}, + "time": 1478077673476, + "name": "iaom trace", + "description": "", + "collectionId": "7d81e8b0-274e-1f22-de94-d40cb78a389d", + "responses": [], + "rawModeData": "{\n\"trace-config\":{\n \"trace-config-name\":\"trace\",\n \"acl-name\":\"testAcl\",\n \"trace-type\":31,\n \"trace-num-elt\":3,\n \"trace-tsp\":\"milliseconds\",\n \"trace-op\":\"add\",\n \"trace-app-data\":1234,\n \"data-export-profile-name\":\"dataProfileName\",\n \"transport-encap-profile-name\":\"transProfileName\",\n \"node-id\":1,\n \"node-interfaces\":[\n {\n \"index\":5,\n \"intf-name\":\"GigabitEthernetb/0/0\"\n }\n ]\n }\n}\n" + } + ] +} \ No newline at end of file diff --git a/ioam/pom.xml b/ioam/pom.xml new file mode 100644 index 000000000..2708114ce --- /dev/null +++ b/ioam/pom.xml @@ -0,0 +1,56 @@ + + + + + + io.fd.honeycomb.common + honeycomb-parent + 1.16.12-SNAPSHOT + ../common/honeycomb-parent + + + io.fd.honeycomb.ioam + vppioam-aggregator + 1.16.12-SNAPSHOT + ${project.artifactId} + pom + 4.0.0 + Aggregator for Honeycomb iOAM plugin + + + api + impl + + + + + + org.apache.maven.plugins + maven-deploy-plugin + + true + + + + org.apache.maven.plugins + maven-install-plugin + + true + + + + + diff --git a/packaging/deb/trusty/debian/control b/packaging/deb/trusty/debian/control index 6e705e122..d84f7d98b 100644 --- a/packaging/deb/trusty/debian/control +++ b/packaging/deb/trusty/debian/control @@ -10,5 +10,5 @@ Vcs-Browser: https://git.fd.io/cgit/honeycomb/tree/ Package: honeycomb Architecture: all Depends: vpp, vpp-plugins, openjdk-8-jdk | openjdk-8-jre -Suggests: vpp-nsh-plugin +Suggests: vpp-nsh-plugin, vpp-ioam-plugin Description: Honeycomb agent for VPP diff --git a/packaging/deb/xenial/debian/control b/packaging/deb/xenial/debian/control index d24f243bd..22ed1774e 100644 --- a/packaging/deb/xenial/debian/control +++ b/packaging/deb/xenial/debian/control @@ -10,5 +10,5 @@ Vcs-Browser: https://git.fd.io/cgit/honeycomb/tree/ Package: honeycomb Architecture: all Depends: vpp, vpp-plugins, openjdk-8-jdk | openjdk-8-jre -Suggests: vpp-nsh-plugin +Suggests: vpp-nsh-plugin, vpp-ioam-plugin Description: Honeycomb agent for VPP diff --git a/pom.xml b/pom.xml index 7835cdd3e..57fa98b4f 100644 --- a/pom.xml +++ b/pom.xml @@ -45,6 +45,7 @@ samples tools nat + ioam release-notes - \ No newline at end of file + diff --git a/release-notes/src/main/asciidoc/user_guide/user_guide.adoc b/release-notes/src/main/asciidoc/user_guide/user_guide.adoc index 7c7c4532d..0f72c8bc9 100644 --- a/release-notes/src/main/asciidoc/user_guide/user_guide.adoc +++ b/release-notes/src/main/asciidoc/user_guide/user_guide.adoc @@ -22,6 +22,8 @@ Honeycomb's configuration files present within its distribution: ** {project-git-web}/lisp/lisp2vpp/src/main/resources/honeycomb-minimal-resources/config/lisp.json?h={project-branch}[LISP plugin for Honeycomb configuration] * NSH plugin: ** {project-git-web}/nsh/impl/src/main/resources/honeycomb-minimal-resources/config/vppnsh.json?h={project-branch}[NSH_SFC plugin for Honeycomb configuration] +* iOAM plugin: +** {project-git-web}/ioam/impl/src/main/resources/honeycomb-minimal-resources/config/vppioam.json?h={project-branch}[IOAM plugin for Honeycomb configuration] === YANG models @@ -33,6 +35,8 @@ Honeycomb's configuration files present within its distribution: ** {project-git-web}/nsh/api/src/main/yang?h={project-branch}[NSH YANG models] * NAT plugin ** {project-git-web}/nat/nat-api/src/main/yang?h={project-branch}[NAT YANG models] +* iOAM plugin +** {project-git-web}/ioam/api/src/main/yang?h={project-branch}[IOAM YANG models] * Context models ** {project-git-web}/vpp-common/naming-context-api/src/main/yang?h={project-branch}[Context YANG models] @@ -46,3 +50,5 @@ Honeycomb's configuration files present within its distribution: ** {project-git-web}/nsh/nsh_postman_rest_collection.json?h={project-branch}[NSH postman collection] * NAT plugin ** {project-git-web}/nat/postman_rest_collection.json?h={project-branch}[NAT postman collection] +* iOAM plugin +** {project-git-web}/ioam/ioam_trace_postman_collection.json?h={project-branch}[IOAM postman collection] diff --git a/vpp-integration/minimal-distribution/pom.xml b/vpp-integration/minimal-distribution/pom.xml index 0f504ec70..83fee5689 100644 --- a/vpp-integration/minimal-distribution/pom.xml +++ b/vpp-integration/minimal-distribution/pom.xml @@ -35,14 +35,17 @@ 1.16.12-SNAPSHOT 1.16.12-SNAPSHOT 1.16.12-SNAPSHOT + 1.16.12-SNAPSHOT io.fd.honeycomb.vpp.common.integration.VppCommonModule, io.fd.honeycomb.lisp.LispModule, io.fd.honeycomb.translate.v3po.V3poModule, io.fd.honeycomb.nat.NatModule, - // io.fd.honeycomb.vppnsh.impl.VppNshModule + // io.fd.honeycomb.vppnsh.impl.VppNshModule, + //io.fd.honeycomb.vppioam.impl.VppIoamModule + @@ -95,5 +98,10 @@ nat2vpp ${nat.version} + + io.fd.honeycomb.vppioam + vppioam-impl + ${ioam.version} + -- cgit 1.2.3-korg