1 From 9a00b1af18dfe4c2df185299b8bd2db7f5d061c0 Mon Sep 17 00:00:00 2001
2 From: Johnson Li <johnson.li@intel.com>
3 Date: Fri, 8 Sep 2017 17:35:16 +0800
4 Subject: [PATCH] Add VES agent configuration for vG-MUX
6 Signed-off-by: Johnson Li <johnson.li@intel.com>
8 diff --git a/pom.xml b/pom.xml
9 index 538a5d9..581bedf 100644
15 <module>release-notes</module>
16 - <module>vpp-integration</module>
19 + <module>ves</module>
20 <module>samples</module>
21 <module>vpp-classifier</module>
23 <module>vpp-management</module>
24 + <module>vpp-integration</module>
28 \ No newline at end of file
29 diff --git a/ves/asciidoc/Readme.adoc b/ves/asciidoc/Readme.adoc
31 index 0000000..682e755
33 +++ b/ves/asciidoc/Readme.adoc
37 +Overview of ves-agent
38 diff --git a/ves/pom.xml b/ves/pom.xml
40 index 0000000..1ded010
44 +<?xml version="1.0" encoding="UTF-8"?>
46 + Copyright (c) 2017 Cisco and/or its affiliates.
47 + Licensed under the Apache License, Version 2.0 (the "License");
48 + you may not use this file except in compliance with the License.
49 + You may obtain a copy of the License at:
51 + http://www.apache.org/licenses/LICENSE-2.0
53 + Unless required by applicable law or agreed to in writing, software
54 + distributed under the License is distributed on an "AS IS" BASIS,
55 + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
56 + See the License for the specific language governing permissions and
57 + limitations under the License.
58 +--><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">
61 + <groupId>io.fd.hc2vpp.common</groupId>
62 + <artifactId>hc2vpp-parent</artifactId>
63 + <version>1.17.04.1-SNAPSHOT</version>
64 + <relativePath>../common/hc2vpp-parent</relativePath>
67 + <groupId>io.fd.hc2vpp.ves</groupId>
68 + <artifactId>ves-agent</artifactId>
69 + <version>1.17.04.1-SNAPSHOT</version>
70 + <name>ves-agent</name>
71 + <packaging>pom</packaging>
72 + <modelVersion>4.0.0</modelVersion>
73 + <description>Agent for VNF Event Stream plugin</description>
76 + <module>ves-api</module>
77 + <module>ves-impl</module>
80 + <!-- DO NOT install or deploy the repo root pom as it's only needed to initiate a build -->
84 + <groupId>org.apache.maven.plugins</groupId>
85 + <artifactId>maven-deploy-plugin</artifactId>
91 + <groupId>org.apache.maven.plugins</groupId>
92 + <artifactId>maven-install-plugin</artifactId>
100 diff --git a/ves/ves-api/asciidoc/Readme.adoc b/ves/ves-api/asciidoc/Readme.adoc
102 index 0000000..b561268
104 +++ b/ves/ves-api/asciidoc/Readme.adoc
108 +Overview of vesagent-api
109 \ No newline at end of file
110 diff --git a/ves/ves-api/pom.xml b/ves/ves-api/pom.xml
112 index 0000000..78bf47b
114 +++ b/ves/ves-api/pom.xml
116 +<?xml version="1.0" encoding="UTF-8"?>
118 + Copyright (c) 2017 Cisco and/or its affiliates.
119 + Licensed under the Apache License, Version 2.0 (the "License");
120 + you may not use this file except in compliance with the License.
121 + You may obtain a copy of the License at:
123 + http://www.apache.org/licenses/LICENSE-2.0
125 + Unless required by applicable law or agreed to in writing, software
126 + distributed under the License is distributed on an "AS IS" BASIS,
127 + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
128 + See the License for the specific language governing permissions and
129 + limitations under the License.
130 +--><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">
132 + <groupId>io.fd.hc2vpp.common</groupId>
133 + <artifactId>api-parent</artifactId>
134 + <version>1.17.04.1-SNAPSHOT</version>
135 + <relativePath>../../common/api-parent</relativePath>
138 + <modelVersion>4.0.0</modelVersion>
139 + <groupId>io.fd.hc2vpp.ves</groupId>
140 + <artifactId>ves-api</artifactId>
141 + <name>ves-api</name>
142 + <version>1.17.04.1-SNAPSHOT</version>
143 + <packaging>bundle</packaging>
147 + <groupId>org.opendaylight.mdsal.model</groupId>
148 + <artifactId>iana-if-type-2014-05-08</artifactId>
151 + <groupId>org.opendaylight.mdsal.model</groupId>
152 + <artifactId>ietf-yang-types-20130715</artifactId>
155 + <groupId>org.opendaylight.mdsal.model</groupId>
156 + <artifactId>ietf-interfaces</artifactId>
159 + <groupId>org.opendaylight.mdsal.model</groupId>
160 + <artifactId>ietf-inet-types-2013-07-15</artifactId>
163 + <groupId>org.opendaylight.mdsal.model</groupId>
164 + <artifactId>yang-ext</artifactId>
168 diff --git a/ves/ves-api/src/main/yang/vesagent.yang b/ves/ves-api/src/main/yang/vesagent.yang
170 index 0000000..dde09c2
172 +++ b/ves/ves-api/src/main/yang/vesagent.yang
177 + namespace "urn:opendaylight:params:xml:ns:yang:vpp:vesagent";
181 + "This YANG module defines the generic configuration and
182 + operational data for VES Agent in VPP";
184 + revision "2017-08-01" {
186 + "Initial revision of VES Agent model";
189 + import ietf-inet-types {
193 + grouping vesagent-attributes {
196 + "VNF Event Stream Agent configuration";
199 + type inet:ipv4-address;
201 + "VES Collector's IP address.";
207 + "VES Collector's Server Port.";
210 + leaf read-interval {
213 + "Seconds of time period for each loop.";
219 + "0-Delete VES agent, NonZero-Start VES agent.";
225 + "VNF Event Stream Agent Working Mode.";
227 + leaf base-packet-loss {
230 + "Base packet Loss for Demo Mode";
233 + leaf working-mode {
236 + "VES Working Mode, Demo Or Real Only.";
242 + "Override for the sourceName field in the VES event";
247 + container vesagent {
248 + uses vesagent-attributes;
251 diff --git a/ves/ves-impl/asciidoc/Readme.adoc b/ves/ves-impl/asciidoc/Readme.adoc
253 index 0000000..e07fb05
255 +++ b/ves/ves-impl/asciidoc/Readme.adoc
259 +Overview of vesagent-impl
260 \ No newline at end of file
261 diff --git a/ves/ves-impl/pom.xml b/ves/ves-impl/pom.xml
263 index 0000000..5ed2c1b
265 +++ b/ves/ves-impl/pom.xml
267 +<?xml version="1.0" encoding="UTF-8"?>
269 + Copyright (c) 2017 Cisco and/or its affiliates.
270 + Licensed under the Apache License, Version 2.0 (the "License");
271 + you may not use this file except in compliance with the License.
272 + You may obtain a copy of the License at:
274 + http://www.apache.org/licenses/LICENSE-2.0
276 + Unless required by applicable law or agreed to in writing, software
277 + distributed under the License is distributed on an "AS IS" BASIS,
278 + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
279 + See the License for the specific language governing permissions and
280 + limitations under the License.
281 +--><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">
283 + <groupId>io.fd.hc2vpp.common</groupId>
284 + <artifactId>vpp-impl-parent</artifactId>
285 + <version>1.17.04.1-SNAPSHOT</version>
286 + <relativePath>../../vpp-common/vpp-impl-parent</relativePath>
289 + <modelVersion>4.0.0</modelVersion>
290 + <groupId>io.fd.hc2vpp.ves</groupId>
291 + <artifactId>ves-impl</artifactId>
292 + <name>${project.artifactId}</name>
293 + <version>1.17.04.1-SNAPSHOT</version>
294 + <packaging>bundle</packaging>
297 + <honeycomb.infra.version>1.17.04.1-SNAPSHOT</honeycomb.infra.version>
298 + <hc2vpp.common.version>1.17.04.1-SNAPSHOT</hc2vpp.common.version>
303 + <groupId>${project.groupId}</groupId>
304 + <artifactId>ves-api</artifactId>
305 + <version>${project.version}</version>
310 + <groupId>io.fd.hc2vpp.common</groupId>
311 + <artifactId>vpp-translate-utils</artifactId>
316 + <groupId>io.fd.vpp</groupId>
317 + <artifactId>jvpp-registry</artifactId>
320 + <groupId>io.fd.vpp</groupId>
321 + <artifactId>jvpp-ves</artifactId>
322 + <version>17.04.2-SNAPSHOT</version>
325 + <!-- Honeycomb infrastructure-->
327 + <groupId>io.fd.honeycomb</groupId>
328 + <artifactId>minimal-distribution</artifactId>
329 + <version>${honeycomb.infra.version}</version>
333 + <groupId>io.fd.honeycomb</groupId>
334 + <artifactId>translate-api</artifactId>
335 + <version>${honeycomb.infra.version}</version>
339 + <groupId>io.fd.honeycomb</groupId>
340 + <artifactId>translate-spi</artifactId>
341 + <version>${honeycomb.infra.version}</version>
345 + <groupId>io.fd.honeycomb</groupId>
346 + <artifactId>cfg-init</artifactId>
347 + <version>${honeycomb.infra.version}</version>
350 + <!-- Translation -->
352 + <groupId>io.fd.hc2vpp.common</groupId>
353 + <artifactId>vpp-translate-utils</artifactId>
358 + <groupId>com.google.inject</groupId>
359 + <artifactId>guice</artifactId>
362 + <groupId>net.jmob</groupId>
363 + <artifactId>guice.conf</artifactId>
366 + <groupId>com.google.inject.extensions</groupId>
367 + <artifactId>guice-multibindings</artifactId>
370 + <groupId>io.fd.honeycomb</groupId>
371 + <artifactId>translate-impl</artifactId>
372 + <version>1.17.04.1-SNAPSHOT</version>
376 + <!-- Testing dependencies-->
378 + <groupId>com.google.inject</groupId>
379 + <artifactId>guice</artifactId>
382 + <groupId>net.jmob</groupId>
383 + <artifactId>guice.conf</artifactId>
386 + <groupId>com.google.inject.extensions</groupId>
387 + <artifactId>guice-multibindings</artifactId>
391 + <groupId>junit</groupId>
392 + <artifactId>junit</artifactId>
393 + <scope>test</scope>
396 + <groupId>io.fd.hc2vpp.common</groupId>
397 + <artifactId>vpp-translate-test</artifactId>
398 + <version>${hc2vpp.common.version}</version>
399 + <scope>test</scope>
402 + <groupId>org.mockito</groupId>
403 + <artifactId>mockito-core</artifactId>
404 + <scope>test</scope>
407 + <groupId>com.google.inject.extensions</groupId>
408 + <artifactId>guice-testlib</artifactId>
409 + <scope>test</scope>
412 + <groupId>org.hamcrest</groupId>
413 + <artifactId>hamcrest-all</artifactId>
414 + <scope>test</scope>
417 + <groupId>io.fd.honeycomb.infra</groupId>
418 + <artifactId>test-tools</artifactId>
419 + <version>${project.version}</version>
420 + <scope>test</scope>
424 diff --git a/ves/ves-impl/src/main/java/io/fd/hc2vpp/ves/VesModule.java b/ves/ves-impl/src/main/java/io/fd/hc2vpp/ves/VesModule.java
426 index 0000000..0cd6006
428 +++ b/ves/ves-impl/src/main/java/io/fd/hc2vpp/ves/VesModule.java
431 + * Copyright (c) 2017 Intel Corp and/or its affiliates.
433 + * Licensed under the Apache License, Version 2.0 (the "License");
434 + * you may not use this file except in compliance with the License.
435 + * You may obtain a copy of the License at:
437 + * http://www.apache.org/licenses/LICENSE-2.0
439 + * Unless required by applicable law or agreed to in writing, software
440 + * distributed under the License is distributed on an "AS IS" BASIS,
441 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
442 + * See the License for the specific language governing permissions and
443 + * limitations under the License.
446 +package io.fd.hc2vpp.ves;
448 +import com.google.common.annotations.VisibleForTesting;
449 +import com.google.inject.AbstractModule;
450 +import com.google.inject.Provider;
451 +import com.google.inject.Singleton;
452 +import com.google.inject.multibindings.Multibinder;
453 +import io.fd.hc2vpp.ves.jvpp.JVppVesProvider;
454 +import io.fd.hc2vpp.ves.read.VesReaderFactory;
455 +import io.fd.hc2vpp.ves.write.VesWriterFactory;
456 +import io.fd.honeycomb.translate.read.ReaderFactory;
457 +import io.fd.honeycomb.translate.write.WriterFactory;
458 +import io.fd.vpp.jvpp.ves.future.FutureJVppVesFacade;
459 +import org.slf4j.Logger;
460 +import org.slf4j.LoggerFactory;
463 + * VesModule class instantiating ves plugin components.
465 +public final class VesModule extends AbstractModule {
467 + private static final Logger LOG = LoggerFactory.getLogger(VesModule.class);
468 + private final Class<? extends Provider<FutureJVppVesFacade>> jvppVesProviderClass;
470 + public VesModule() {
471 + this(JVppVesProvider.class);
475 + VesModule(Class<? extends Provider<FutureJVppVesFacade>> jvppVesProvider) {
476 + this.jvppVesProviderClass = jvppVesProvider;
480 + protected void configure() {
481 + LOG.info("Installing VES Agent module");
483 + // Bind to Plugin's JVPP
484 + bind(FutureJVppVesFacade.class).toProvider(jvppVesProviderClass).in(Singleton.class);
486 + LOG.info("Injecting writers factories");
487 + final Multibinder<WriterFactory> writerFactoryBinder = Multibinder.newSetBinder(binder(), WriterFactory.class);
488 + writerFactoryBinder.addBinding().to(VesWriterFactory.class);
490 + LOG.info("Injecting readers factories");
491 + final Multibinder<ReaderFactory> readerFactoryBinder = Multibinder.newSetBinder(binder(), ReaderFactory.class);
492 + readerFactoryBinder.addBinding().to(VesReaderFactory.class);
494 + LOG.info("Module VES Agent successfully configured");
497 diff --git a/ves/ves-impl/src/main/java/io/fd/hc2vpp/ves/jvpp/JVppVesProvider.java b/ves/ves-impl/src/main/java/io/fd/hc2vpp/ves/jvpp/JVppVesProvider.java
499 index 0000000..8afed84
501 +++ b/ves/ves-impl/src/main/java/io/fd/hc2vpp/ves/jvpp/JVppVesProvider.java
504 + * Copyright (c) 2017 Intel Corp and/or its affiliates.
506 + * Licensed under the Apache License, Version 2.0 (the "License");
507 + * you may not use this file except in compliance with the License.
508 + * You may obtain a copy of the License at:
510 + * http://www.apache.org/licenses/LICENSE-2.0
512 + * Unless required by applicable law or agreed to in writing, software
513 + * distributed under the License is distributed on an "AS IS" BASIS,
514 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
515 + * See the License for the specific language governing permissions and
516 + * limitations under the License.
519 +package io.fd.hc2vpp.ves.jvpp;
521 +import com.google.inject.Inject;
522 +import io.fd.honeycomb.infra.distro.ProviderTrait;
523 +import io.fd.vpp.jvpp.JVppRegistry;
524 +import io.fd.vpp.jvpp.ves.JVppVesImpl;
525 +import io.fd.vpp.jvpp.ves.future.FutureJVppVesFacade;
526 +import java.io.IOException;
527 +import org.slf4j.Logger;
528 +import org.slf4j.LoggerFactory;
531 + * Provides future API for jvpp-ves plugin. Must be a singleton due to shutdown hook usage.
532 + * Registers shutdown hook to free plugin's resources on shutdown.
534 +public final class JVppVesProvider extends ProviderTrait<FutureJVppVesFacade> {
536 + private static final Logger LOG = LoggerFactory.getLogger(JVppVesProvider.class);
539 + private JVppRegistry registry;
542 + protected FutureJVppVesFacade create() {
544 + final JVppVesImpl jvppVes = new JVppVesImpl();
545 + Runtime.getRuntime().addShutdownHook(new Thread() {
547 + public void run() {
548 + LOG.info("Unloading jvpp-ves plugin");
550 + LOG.info("Successfully unloaded jvpp-ves plugin");
554 + LOG.info("Successfully loaded jvpp-ves plugin");
555 + return new FutureJVppVesFacade(registry, jvppVes);
556 + } catch (IOException e) {
557 + throw new IllegalStateException("Unable to open VPP management connection", e);
562 diff --git a/ves/ves-impl/src/main/java/io/fd/hc2vpp/ves/read/VesReaderFactory.java b/ves/ves-impl/src/main/java/io/fd/hc2vpp/ves/read/VesReaderFactory.java
564 index 0000000..bef652f
566 +++ b/ves/ves-impl/src/main/java/io/fd/hc2vpp/ves/read/VesReaderFactory.java
569 + * Copyright (c) 2017 Intel Corp and/or its affiliates.
571 + * Licensed under the Apache License, Version 2.0 (the "License");
572 + * you may not use this file except in compliance with the License.
573 + * You may obtain a copy of the License at:
575 + * http://www.apache.org/licenses/LICENSE-2.0
577 + * Unless required by applicable law or agreed to in writing, software
578 + * distributed under the License is distributed on an "AS IS" BASIS,
579 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
580 + * See the License for the specific language governing permissions and
581 + * limitations under the License.
584 +package io.fd.hc2vpp.ves.read;
586 +import com.google.inject.Inject;
587 +import io.fd.honeycomb.translate.read.ReaderFactory;
588 +import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder;
589 +import io.fd.vpp.jvpp.core.future.FutureJVppCore;
590 +import javax.annotation.Nonnull;
591 +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vesagent.rev170801.Vesagent;
592 +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vesagent.rev170801.VesagentBuilder;
593 +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vesagent.rev170801.vesagent.attributes.Config;
594 +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vesagent.rev170801.vesagent.attributes.ConfigBuilder;
595 +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vesagent.rev170801.vesagent.attributes.Mode;
596 +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vesagent.rev170801.vesagent.attributes.ModeBuilder;
597 +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
600 + * Factory producing writers for VES Agent plugin's data.
602 +public final class VesReaderFactory implements ReaderFactory {
604 + private static final InstanceIdentifier<Vesagent> VESAGENT_ID = InstanceIdentifier.create(Vesagent.class);
605 + private static final InstanceIdentifier<Config> CONFIG_ID = InstanceIdentifier.create(Config.class);
606 + private static final InstanceIdentifier<Mode> MODE_ID = InstanceIdentifier.create(Mode.class);
609 + private FutureJVppCore vppApi;
612 + public void init(@Nonnull final ModifiableReaderRegistryBuilder registry) {
613 + registry.addStructuralReader(VESAGENT_ID, VesagentBuilder.class);
614 + registry.addStructuralReader(CONFIG_ID, ConfigBuilder.class);
615 + registry.addStructuralReader(MODE_ID, ModeBuilder.class);
618 diff --git a/ves/ves-impl/src/main/java/io/fd/hc2vpp/ves/write/VesConfigCustomizer.java b/ves/ves-impl/src/main/java/io/fd/hc2vpp/ves/write/VesConfigCustomizer.java
620 index 0000000..e06afa7
622 +++ b/ves/ves-impl/src/main/java/io/fd/hc2vpp/ves/write/VesConfigCustomizer.java
625 + * Copyright (c) 2017 Intel Corp and/or its affiliates.
627 + * Licensed under the Apache License, Version 2.0 (the "License");
628 + * you may not use this file except in compliance with the License.
629 + * You may obtain a copy of the License at:
631 + * http://www.apache.org/licenses/LICENSE-2.0
633 + * Unless required by applicable law or agreed to in writing, software
634 + * distributed under the License is distributed on an "AS IS" BASIS,
635 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
636 + * See the License for the specific language governing permissions and
637 + * limitations under the License.
640 +package io.fd.hc2vpp.ves.write;
642 +import static com.google.common.base.Preconditions.checkArgument;
644 +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
645 +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer;
646 +import io.fd.hc2vpp.common.translate.util.Ipv4Translator;
647 +import io.fd.hc2vpp.common.translate.util.Ipv6Translator;
648 +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer;
649 +import io.fd.honeycomb.translate.spi.write.WriterCustomizer;
650 +import io.fd.honeycomb.translate.write.WriteContext;
651 +import io.fd.honeycomb.translate.write.WriteFailedException;
652 +import io.fd.vpp.jvpp.core.future.FutureJVppCore;
653 +//import io.fd.vpp.jvpp.ves.future.FutureJVppVes;
654 +import io.fd.vpp.jvpp.ves.dto.VesAgentConfig;
655 +import io.fd.vpp.jvpp.ves.future.FutureJVppVesFacade;
656 +import javax.annotation.Nonnull;
657 +//import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vesagent.rev170801.Vesagent;
658 +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vesagent.rev170801.vesagent.attributes.Config;
659 +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vesagent.rev170801.vesagent.attributes.ConfigBuilder;
660 +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
661 +import org.slf4j.Logger;
662 +import org.slf4j.LoggerFactory;
664 +final class VesConfigCustomizer extends FutureJVppCustomizer implements WriterCustomizer<Config>,
665 + JvppReplyConsumer, ByteDataTranslator, Ipv6Translator, Ipv4Translator {
666 + private static final Logger LOG = LoggerFactory.getLogger(VesConfigCustomizer.class);
668 + private final FutureJVppVesFacade jvppVes;
670 + VesConfigCustomizer(final FutureJVppCore vppApi, final FutureJVppVesFacade jvppVes) {
672 + this.jvppVes = jvppVes;
676 + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Config> iid, @Nonnull final Config dataAfter,
677 + @Nonnull final WriteContext writeContext) throws WriteFailedException {
678 + ConfigBuilder configBuilder = new ConfigBuilder();
679 + InstanceIdentifier<Config> id = iid;
681 + LOG.debug("Writing VES Agent Config {} dataAfter={}", id, dataAfter);
682 + checkArgument(dataAfter.getServerAddr() != null && dataAfter.getServerAddr().getValue() != null
683 + && dataAfter.getServerPort() != 0, "VES Server Address and Port need to be configured");
685 + configBuilder.setServerAddr(dataAfter.getServerAddr())
686 + .setServerPort(dataAfter.getServerPort())
687 + .setReadInterval(dataAfter.getReadInterval())
690 + setVesAgentConfig(id, configBuilder.build());
694 + public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<Config> iid, @Nonnull final Config dataBefore,
695 + @Nonnull final Config dataAfter, @Nonnull final WriteContext writeContext)
696 + throws WriteFailedException {
697 + ConfigBuilder configBuilder = new ConfigBuilder();
698 + InstanceIdentifier<Config> id = iid;
700 + checkArgument(dataBefore.getServerAddr() != null && dataBefore.getServerAddr().getValue() != null
701 + && dataBefore.getServerPort() != 0, "VES Server Address and Port need to be configured");
702 + checkArgument(dataAfter.getServerAddr() != null && dataAfter.getServerAddr().getValue() != null
703 + && dataAfter.getServerPort() != 0, "VES Server Address and Port need to be configured");
705 + // remove old configuration:
706 + configBuilder.setServerAddr(dataBefore.getServerAddr())
707 + .setServerPort(dataBefore.getServerPort())
708 + .setReadInterval(dataBefore.getReadInterval())
710 + setVesAgentConfig(id, configBuilder.build());
712 + // and add new one:
713 + configBuilder.setServerAddr(dataAfter.getServerAddr())
714 + .setServerPort(dataAfter.getServerPort())
715 + .setReadInterval(dataAfter.getReadInterval())
717 + setVesAgentConfig(id, configBuilder.build());
721 + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Config> iid, @Nonnull final Config dataBefore,
722 + @Nonnull final WriteContext writeContext) throws WriteFailedException {
723 + ConfigBuilder configBuilder = new ConfigBuilder();
724 + InstanceIdentifier<Config> id = iid;
725 + LOG.debug("Removing VES Agent {} dataBefore={}", id, dataBefore);
727 + checkArgument(dataBefore.getServerAddr() != null && dataBefore.getServerAddr().getValue() != null
728 + && dataBefore.getServerPort() != 0, "VES Server Address and Port need to be dataBeforeured");
730 + configBuilder.setServerAddr(dataBefore.getServerAddr())
731 + .setServerPort(dataBefore.getServerPort())
732 + .setReadInterval(dataBefore.getReadInterval())
735 + setVesAgentConfig(id, configBuilder.build());
738 + private void setVesAgentConfig(final InstanceIdentifier<Config> id, final Config config)
739 + throws WriteFailedException {
740 + final VesAgentConfig request = new VesAgentConfig();
742 + request.serverPort = config.getServerPort().byteValue();
743 + request.readInterval = config.getReadInterval().byteValue();
744 + request.isAdd = config.getIsAdd().byteValue();
745 + request.serverAddr = ipv4AddressNoZoneToArray(config.getServerAddr().getValue());
747 + LOG.debug("VES agent config change id={} request={}", id, request);
748 + getReplyForWrite(jvppVes.vesAgentConfig(request).toCompletableFuture(), id);
751 diff --git a/ves/ves-impl/src/main/java/io/fd/hc2vpp/ves/write/VesModeCustomizer.java b/ves/ves-impl/src/main/java/io/fd/hc2vpp/ves/write/VesModeCustomizer.java
753 index 0000000..248d819
755 +++ b/ves/ves-impl/src/main/java/io/fd/hc2vpp/ves/write/VesModeCustomizer.java
758 + * Copyright (c) 2017 Intel Corp and/or its affiliates.
760 + * Licensed under the Apache License, Version 2.0 (the "License");
761 + * you may not use this file except in compliance with the License.
762 + * You may obtain a copy of the License at:
764 + * http://www.apache.org/licenses/LICENSE-2.0
766 + * Unless required by applicable law or agreed to in writing, software
767 + * distributed under the License is distributed on an "AS IS" BASIS,
768 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
769 + * See the License for the specific language governing permissions and
770 + * limitations under the License.
773 +package io.fd.hc2vpp.ves.write;
775 +import static com.google.common.base.Preconditions.checkArgument;
777 +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
778 +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer;
779 +import io.fd.hc2vpp.common.translate.util.Ipv4Translator;
780 +import io.fd.hc2vpp.common.translate.util.Ipv6Translator;
781 +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer;
782 +import io.fd.honeycomb.translate.spi.write.WriterCustomizer;
783 +import io.fd.honeycomb.translate.write.WriteContext;
784 +import io.fd.honeycomb.translate.write.WriteFailedException;
785 +import io.fd.vpp.jvpp.core.future.FutureJVppCore;
786 +//import io.fd.vpp.jvpp.ves.future.FutureJVppVes;
787 +import io.fd.vpp.jvpp.ves.dto.VesAgentMode;
788 +import io.fd.vpp.jvpp.ves.future.FutureJVppVesFacade;
789 +import javax.annotation.Nonnull;
790 +//import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vesagent.rev170801.Vesagent;
791 +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vesagent.rev170801.vesagent.attributes.Mode;
792 +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vesagent.rev170801.vesagent.attributes.ModeBuilder;
793 +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
794 +import org.slf4j.Logger;
795 +import org.slf4j.LoggerFactory;
797 +final class VesModeCustomizer extends FutureJVppCustomizer implements WriterCustomizer<Mode>,
798 + JvppReplyConsumer, ByteDataTranslator, Ipv6Translator, Ipv4Translator {
799 + private static final Logger LOG = LoggerFactory.getLogger(VesModeCustomizer.class);
801 + private final FutureJVppVesFacade jvppVes;
803 + VesModeCustomizer(final FutureJVppCore vppApi, final FutureJVppVesFacade jvppVes) {
805 + this.jvppVes = jvppVes;
809 + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Mode> iid, @Nonnull final Mode dataAfter,
810 + @Nonnull final WriteContext writeContext) throws WriteFailedException {
811 + LOG.debug("Writing VES Agent Working Mode {} dataAfter={}", iid, dataAfter);
813 + checkArgument(dataAfter.getSourceName() != null && dataAfter.getWorkingMode() != null && dataAfter.getBasePacketLoss() <= 100,
814 + "VES Agent Working Mode need to be correctly configured.");
816 + setVesAgentMode(iid, dataAfter);
820 + public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<Mode> iid, @Nonnull final Mode dataBefore,
821 + @Nonnull final Mode dataAfter, @Nonnull final WriteContext writeContext)
822 + throws WriteFailedException {
823 + LOG.debug("Writing VES Agent Working Mode {} {}-->{}", iid, dataBefore, dataAfter);
825 + checkArgument(dataAfter.getSourceName() != null && dataAfter.getWorkingMode() != null && dataAfter.getBasePacketLoss() <= 100,
826 + "VES Agent Working Mode need to be correctly configured.");
828 + setVesAgentMode(iid, dataAfter);
832 + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Mode> iid, @Nonnull final Mode dataBefore,
833 + @Nonnull final WriteContext writeContext) throws WriteFailedException {
834 + ModeBuilder modeBuilder = new ModeBuilder();
835 + LOG.debug("Restoring VES Mode {} dataBefore={} to default.", iid, dataBefore);
837 + modeBuilder.setWorkingMode("Real")
838 + .setBasePacketLoss(0L)
839 + .setSourceName("");
841 + setVesAgentMode(iid, modeBuilder.build());
844 + private void setVesAgentMode(final InstanceIdentifier<Mode> id, final Mode mode)
845 + throws WriteFailedException {
846 + final VesAgentMode request = new VesAgentMode();
848 + request.pktLossRate = mode.getBasePacketLoss().byteValue();
849 + request.workMode = mode.getWorkingMode().getBytes();
850 + request.sourceName = mode.getSourceName().getBytes();
852 + LOG.debug("VES agent working mode change id={} request={}", id, request);
853 + getReplyForWrite(jvppVes.vesAgentMode(request).toCompletableFuture(), id);
856 diff --git a/ves/ves-impl/src/main/java/io/fd/hc2vpp/ves/write/VesWriterFactory.java b/ves/ves-impl/src/main/java/io/fd/hc2vpp/ves/write/VesWriterFactory.java
858 index 0000000..581f046
860 +++ b/ves/ves-impl/src/main/java/io/fd/hc2vpp/ves/write/VesWriterFactory.java
863 + * Copyright (c) 2017 Intel Corp and/or its affiliates.
865 + * Licensed under the Apache License, Version 2.0 (the "License");
866 + * you may not use this file except in compliance with the License.
867 + * You may obtain a copy of the License at:
869 + * http://www.apache.org/licenses/LICENSE-2.0
871 + * Unless required by applicable law or agreed to in writing, software
872 + * distributed under the License is distributed on an "AS IS" BASIS,
873 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
874 + * See the License for the specific language governing permissions and
875 + * limitations under the License.
878 +package io.fd.hc2vpp.ves.write;
880 +import com.google.common.collect.ImmutableSet;
881 +import com.google.inject.Inject;
882 +import io.fd.honeycomb.translate.impl.write.GenericWriter;
883 +import io.fd.honeycomb.translate.write.WriterFactory;
884 +import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder;
885 +import io.fd.vpp.jvpp.core.future.FutureJVppCore;
886 +import io.fd.vpp.jvpp.ves.future.FutureJVppVesFacade;
887 +import javax.annotation.Nonnull;
888 +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vesagent.rev170801.Vesagent;
889 +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vesagent.rev170801.vesagent.attributes.Config;
890 +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vesagent.rev170801.vesagent.attributes.Mode;
891 +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
894 + * Factory producing writers for VES Agent plugin's data.
896 +public final class VesWriterFactory implements WriterFactory {
898 + private static final InstanceIdentifier<Vesagent> VESAGENT_ID = InstanceIdentifier.create(Vesagent.class);
901 + private FutureJVppCore vppApi;
904 + protected FutureJVppVesFacade futureVesFacade;
907 + public void init(@Nonnull final ModifiableWriterRegistryBuilder registry) {
908 + registry.add(new GenericWriter<>(VESAGENT_ID,
909 + new VesagentCustomizer(vppApi, futureVesFacade)));
910 + registry.add(new GenericWriter<>(VESAGENT_ID.child(Config.class),
911 + new VesConfigCustomizer(vppApi, futureVesFacade)));
912 + registry.add(new GenericWriter<>(VESAGENT_ID.child(Mode.class),
913 + new VesModeCustomizer(vppApi, futureVesFacade)));
916 diff --git a/ves/ves-impl/src/main/java/io/fd/hc2vpp/ves/write/VesagentCustomizer.java b/ves/ves-impl/src/main/java/io/fd/hc2vpp/ves/write/VesagentCustomizer.java
918 index 0000000..62e46cd
920 +++ b/ves/ves-impl/src/main/java/io/fd/hc2vpp/ves/write/VesagentCustomizer.java
923 + * Copyright (c) 2017 Intel Corp and/or its affiliates.
925 + * Licensed under the Apache License, Version 2.0 (the "License");
926 + * you may not use this file except in compliance with the License.
927 + * You may obtain a copy of the License at:
929 + * http://www.apache.org/licenses/LICENSE-2.0
931 + * Unless required by applicable law or agreed to in writing, software
932 + * distributed under the License is distributed on an "AS IS" BASIS,
933 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
934 + * See the License for the specific language governing permissions and
935 + * limitations under the License.
938 +package io.fd.hc2vpp.ves.write;
940 +import static com.google.common.base.Preconditions.checkArgument;
942 +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
943 +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer;
944 +import io.fd.hc2vpp.common.translate.util.Ipv4Translator;
945 +import io.fd.hc2vpp.common.translate.util.Ipv6Translator;
946 +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer;
947 +import io.fd.honeycomb.translate.spi.write.WriterCustomizer;
948 +import io.fd.honeycomb.translate.write.WriteContext;
949 +import io.fd.honeycomb.translate.write.WriteFailedException;
950 +import io.fd.vpp.jvpp.core.future.FutureJVppCore;
951 +//import io.fd.vpp.jvpp.ves.future.FutureJVppVes;
952 +import io.fd.vpp.jvpp.ves.dto.VesAgentConfig;
953 +import io.fd.vpp.jvpp.ves.future.FutureJVppVesFacade;
954 +import javax.annotation.Nonnull;
955 +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vesagent.rev170801.Vesagent;
956 +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vesagent.rev170801.vesagent.attributes.Config;
957 +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vesagent.rev170801.vesagent.attributes.ConfigBuilder;
958 +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
959 +import org.slf4j.Logger;
960 +import org.slf4j.LoggerFactory;
962 +final class VesagentCustomizer extends FutureJVppCustomizer implements WriterCustomizer<Vesagent>,
963 + JvppReplyConsumer, ByteDataTranslator, Ipv6Translator, Ipv4Translator {
964 + private static final Logger LOG = LoggerFactory.getLogger(VesagentCustomizer.class);
966 + private final FutureJVppVesFacade jvppVes;
968 + VesagentCustomizer(final FutureJVppCore vppApi, final FutureJVppVesFacade jvppVes) {
970 + this.jvppVes = jvppVes;
974 + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Vesagent> iid, @Nonnull final Vesagent dataAfter,
975 + @Nonnull final WriteContext writeContext) throws WriteFailedException {
976 + Config config = dataAfter.getConfig();
977 + ConfigBuilder configBuilder = new ConfigBuilder();
978 + InstanceIdentifier<Config> id = iid.child(Config.class);
980 + LOG.debug("Writing VES Agent Config {} dataAfter={}", id, config);
981 + checkArgument(config.getServerAddr() != null && config.getServerAddr().getValue() != null
982 + && config.getServerPort() != 0, "VES Server Address and Port need to be configured");
984 + configBuilder.setServerAddr(config.getServerAddr())
985 + .setServerPort(config.getServerPort())
986 + .setReadInterval(config.getReadInterval())
989 + setVesAgentConfig(id, configBuilder.build());
993 + public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<Vesagent> iid, @Nonnull final Vesagent dataBefore,
994 + @Nonnull final Vesagent dataAfter, @Nonnull final WriteContext writeContext)
995 + throws WriteFailedException {
996 + Config configBefore = dataBefore.getConfig();
997 + Config configAfter = dataAfter.getConfig();
998 + ConfigBuilder configBuilder = new ConfigBuilder();
999 + InstanceIdentifier<Config> id = iid.child(Config.class);
1001 + checkArgument(configBefore.getServerAddr() != null && configBefore.getServerAddr().getValue() != null
1002 + && configBefore.getServerPort() != 0, "VES Server Address and Port need to be configured");
1003 + checkArgument(configAfter.getServerAddr() != null && configAfter.getServerAddr().getValue() != null
1004 + && configAfter.getServerPort() != 0, "VES Server Address and Port need to be configured");
1006 + // remove old configuration:
1007 + configBuilder.setServerAddr(configBefore.getServerAddr())
1008 + .setServerPort(configBefore.getServerPort())
1009 + .setReadInterval(configBefore.getReadInterval())
1011 + setVesAgentConfig(id, configBuilder.build());
1013 + // and add new one:
1014 + configBuilder.setServerAddr(configAfter.getServerAddr())
1015 + .setServerPort(configAfter.getServerPort())
1016 + .setReadInterval(configAfter.getReadInterval())
1018 + setVesAgentConfig(id, configBuilder.build());
1022 + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Vesagent> iid, @Nonnull final Vesagent dataBefore,
1023 + @Nonnull final WriteContext writeContext) throws WriteFailedException {
1024 + Config config = dataBefore.getConfig();
1025 + InstanceIdentifier<Config> id = iid.child(Config.class);
1026 + LOG.debug("Removing VES Agent {} dataBefore={}", id, config);
1028 + checkArgument(config.getServerAddr() != null && config.getServerAddr().getValue() != null
1029 + && config.getServerPort() != 0, "VES Server Address and Port need to be configured");
1031 + ConfigBuilder configBuilder = new ConfigBuilder();
1032 + configBuilder.setServerAddr(config.getServerAddr())
1033 + .setServerPort(config.getServerPort())
1034 + .setReadInterval(config.getReadInterval())
1037 + setVesAgentConfig(id, configBuilder.build());
1040 + private void setVesAgentConfig(final InstanceIdentifier<Config> id, final Config config)
1041 + throws WriteFailedException {
1042 + final VesAgentConfig request = new VesAgentConfig();
1044 + request.serverPort = config.getServerPort().byteValue();
1045 + request.readInterval = config.getReadInterval().byteValue();
1046 + request.isAdd = config.getIsAdd().byteValue();
1047 + request.serverAddr = ipv4AddressNoZoneToArray(config.getServerAddr().getValue());
1049 + LOG.debug("VES agent config change id={} request={}", id, request);
1050 + getReplyForWrite(jvppVes.vesAgentConfig(request).toCompletableFuture(), id);
1053 diff --git a/vpp-integration/minimal-distribution/pom.xml b/vpp-integration/minimal-distribution/pom.xml
1054 index e126114..ca0e5b2 100644
1055 --- a/vpp-integration/minimal-distribution/pom.xml
1056 +++ b/vpp-integration/minimal-distribution/pom.xml
1058 <routing.version>1.17.04.1-SNAPSHOT</routing.version>
1059 <acl.version>1.17.04.1-SNAPSHOT</acl.version>
1060 <dhcp.version>1.17.04.1-SNAPSHOT</dhcp.version>
1061 + <vesagent.version>1.17.04.1-SNAPSHOT</vesagent.version>
1062 <vpp.classifier.version>1.17.04.1-SNAPSHOT</vpp.classifier.version>
1063 <l3-impl.version>1.17.04.1-SNAPSHOT</l3-impl.version>
1064 <vpp-management-impl.version>1.17.04.1-SNAPSHOT</vpp-management-impl.version>
1066 io.fd.hc2vpp.routing.RoutingModule,
1067 io.fd.hc2vpp.acl.AclModule,
1068 io.fd.hc2vpp.dhcp.DhcpModule,
1069 + io.fd.hc2vpp.ves.VesModule,
1070 io.fd.hc2vpp.policer.PolicerModule,
1071 // io.fd.hc2vpp.vppnsh.impl.VppNshModule,
1072 <!-- Nsh module by default disabled, because it needs vpp-nsh plugin, which is not part of vpp codebase.-->
1073 @@ -151,6 +153,11 @@
1074 <version>${dhcp.version}</version>
1077 + <groupId>io.fd.hc2vpp.ves</groupId>
1078 + <artifactId>ves-impl</artifactId>
1079 + <version>${vesagent.version}</version>
1082 <groupId>io.fd.hc2vpp.management</groupId>
1083 <artifactId>vpp-management-impl</artifactId>
1084 <version>${vpp-management-impl.version}</version>