summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarek Gradzki <mgradzki@cisco.com>2017-02-13 17:01:02 +0100
committerMarek Gradzki <mgradzki@cisco.com>2017-02-14 09:30:55 +0100
commitbdccd390b46bddc22d5c3e6459c473d148442af1 (patch)
treefbff7ebdaa77aa0077e0486b008243eecbd2840a
parentbe1ce465c60ccc80abf691c41be13090f2d53a6f (diff)
DHCP relay support (HC2VPP-71, HC2VPP-72)
Change-Id: Icea50f1444356c0c107dd31dfa47137c9866312e Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
-rw-r--r--dhcp/asciidoc/Readme.adoc3
-rw-r--r--dhcp/dhcp-impl/asciidoc/Readme.adoc12
-rw-r--r--dhcp/dhcp-impl/pom.xml110
-rw-r--r--dhcp/dhcp-impl/src/main/java/io/fd/hc2vpp/dhcp/DhcpModule.java44
-rw-r--r--dhcp/dhcp-impl/src/main/java/io/fd/hc2vpp/dhcp/write/DhcpRelayCustomizer.java89
-rw-r--r--dhcp/dhcp-impl/src/main/java/io/fd/hc2vpp/dhcp/write/DhcpWriterFactory.java44
-rw-r--r--dhcp/dhcp-impl/src/test/java/io/fd/hc2vpp/dhcp/DhcpModuleTest.java80
-rw-r--r--dhcp/dhcp-impl/src/test/java/io/fd/hc2vpp/dhcp/helpers/SchemaContextTestHelper.java34
-rw-r--r--dhcp/dhcp-impl/src/test/java/io/fd/hc2vpp/dhcp/write/DhcpRelayCustomizerTest.java108
-rw-r--r--dhcp/dhcp-impl/src/test/resources/relay/ipv4DhcpRelay.json13
-rw-r--r--dhcp/dhcp-impl/src/test/resources/relay/ipv6DhcpRelay.json14
-rw-r--r--dhcp/dhcp_postman_collection.json139
-rw-r--r--dhcp/pom.xml1
-rw-r--r--vpp-integration/minimal-distribution/pom.xml7
14 files changed, 698 insertions, 0 deletions
diff --git a/dhcp/asciidoc/Readme.adoc b/dhcp/asciidoc/Readme.adoc
new file mode 100644
index 000000000..3427844fc
--- /dev/null
+++ b/dhcp/asciidoc/Readme.adoc
@@ -0,0 +1,3 @@
+= dhcp-aggregator
+
+Overview of dhcp-aggregator \ No newline at end of file
diff --git a/dhcp/dhcp-impl/asciidoc/Readme.adoc b/dhcp/dhcp-impl/asciidoc/Readme.adoc
new file mode 100644
index 000000000..793e40d36
--- /dev/null
+++ b/dhcp/dhcp-impl/asciidoc/Readme.adoc
@@ -0,0 +1,12 @@
+= dhcp-impl
+
+Provides translation layer for YANG models defined in dhcp-api
+
+== DHCP Relay
+DHCP Relay configuration CUD requests are mapped to dhcp_proxy_config_2 message:
+https://git.fd.io/vpp/tree/src/vnet/dhcp/dhcp.api#n48
+
+Operational read is not supported (missing VPP binary api for read).
+
+Examples of request can be found in:
+https://git.fd.io/cgit/hc2vpp/tree/dhcp/dhcp_postman_collection.json \ No newline at end of file
diff --git a/dhcp/dhcp-impl/pom.xml b/dhcp/dhcp-impl/pom.xml
new file mode 100644
index 000000000..2ede7a520
--- /dev/null
+++ b/dhcp/dhcp-impl/pom.xml
@@ -0,0 +1,110 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2017 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.
+--><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <groupId>io.fd.hc2vpp.common</groupId>
+ <artifactId>vpp-impl-parent</artifactId>
+ <version>1.17.04-SNAPSHOT</version>
+ <relativePath>../../vpp-common/vpp-impl-parent</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>io.fd.hc2vpp.dhcp</groupId>
+ <artifactId>dhcp-impl</artifactId>
+ <name>dhcp-impl</name>
+ <version>1.17.04-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>dhcp-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <!-- Honeycomb infrastructure-->
+ <dependency>
+ <groupId>io.fd.honeycomb</groupId>
+ <artifactId>translate-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>io.fd.honeycomb</groupId>
+ <artifactId>translate-spi</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <!-- Translation -->
+ <dependency>
+ <groupId>io.fd.hc2vpp.common</groupId>
+ <artifactId>vpp-translate-utils</artifactId>
+ </dependency>
+
+ <!-- DI -->
+ <dependency>
+ <groupId>com.google.inject</groupId>
+ <artifactId>guice</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>net.jmob</groupId>
+ <artifactId>guice.conf</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.google.inject.extensions</groupId>
+ <artifactId>guice-multibindings</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.fd.honeycomb</groupId>
+ <artifactId>translate-impl</artifactId>
+ <version>1.17.04-SNAPSHOT</version>
+ </dependency>
+
+
+ <!-- Testing dependencies-->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-all</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.google.inject.extensions</groupId>
+ <artifactId>guice-testlib</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>io.fd.hc2vpp.common</groupId>
+ <artifactId>vpp-translate-test</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>io.fd.honeycomb.infra</groupId>
+ <artifactId>test-tools</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/dhcp/dhcp-impl/src/main/java/io/fd/hc2vpp/dhcp/DhcpModule.java b/dhcp/dhcp-impl/src/main/java/io/fd/hc2vpp/dhcp/DhcpModule.java
new file mode 100644
index 000000000..09514df9b
--- /dev/null
+++ b/dhcp/dhcp-impl/src/main/java/io/fd/hc2vpp/dhcp/DhcpModule.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2017 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.hc2vpp.dhcp;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.multibindings.Multibinder;
+import io.fd.hc2vpp.dhcp.write.DhcpWriterFactory;
+import io.fd.honeycomb.translate.write.WriterFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * DhcpModule class instantiating dhcp plugin components.
+ */
+public final class DhcpModule extends AbstractModule {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DhcpModule.class);
+
+ @Override
+ protected void configure() {
+ LOG.info("Installing DHCP module");
+
+ LOG.info("Injecting writers factories");
+ // create writer factory binding
+ final Multibinder<WriterFactory> writerFactoryBinder = Multibinder.newSetBinder(binder(), WriterFactory.class);
+ writerFactoryBinder.addBinding().to(DhcpWriterFactory.class);
+
+ LOG.info("Module DHCP successfully configured");
+ }
+}
diff --git a/dhcp/dhcp-impl/src/main/java/io/fd/hc2vpp/dhcp/write/DhcpRelayCustomizer.java b/dhcp/dhcp-impl/src/main/java/io/fd/hc2vpp/dhcp/write/DhcpRelayCustomizer.java
new file mode 100644
index 000000000..ca4e20b95
--- /dev/null
+++ b/dhcp/dhcp-impl/src/main/java/io/fd/hc2vpp/dhcp/write/DhcpRelayCustomizer.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2017 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.hc2vpp.dhcp.write;
+
+import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
+import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer;
+import io.fd.hc2vpp.common.translate.util.Ipv4Translator;
+import io.fd.hc2vpp.common.translate.util.Ipv6Translator;
+import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer;
+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.DhcpProxyConfig2;
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.dhcp.rev170315.Ipv6;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.dhcp.rev170315.dhcp.attributes.relays.Relay;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.dhcp.rev170315.dhcp.attributes.relays.RelayKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+final class DhcpRelayCustomizer extends FutureJVppCustomizer implements ListWriterCustomizer<Relay, RelayKey>,
+ JvppReplyConsumer, ByteDataTranslator, Ipv6Translator, Ipv4Translator {
+ private static final Logger LOG = LoggerFactory.getLogger(DhcpRelayCustomizer.class);
+
+ DhcpRelayCustomizer(final FutureJVppCore vppApi) {
+ super(vppApi);
+ }
+
+ @Override
+ public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Relay> id, @Nonnull final Relay dataAfter,
+ @Nonnull final WriteContext writeContext) throws WriteFailedException {
+ LOG.debug("Writing Relay {} dataAfter={}", id, dataAfter);
+ setRelay(id, dataAfter, writeContext, true);
+ }
+
+ @Override
+ public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<Relay> id, @Nonnull final Relay dataBefore,
+ @Nonnull final Relay dataAfter, @Nonnull final WriteContext writeContext)
+ throws WriteFailedException {
+ LOG.debug("Updating Relay {} before={} after={}", id, dataBefore, dataAfter);
+ setRelay(id, dataAfter, writeContext, true);
+ }
+
+ @Override
+ public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Relay> id, @Nonnull final Relay dataBefore,
+ @Nonnull final WriteContext writeContext) throws WriteFailedException {
+ LOG.debug("Removing Relay {} dataBefore={}", id, dataBefore);
+ setRelay(id, dataBefore, writeContext, false);
+ }
+
+ private void setRelay(final InstanceIdentifier<Relay> id, final Relay relay, final WriteContext writeContext,
+ final boolean isAdd) throws WriteFailedException {
+ final DhcpProxyConfig2 request = new DhcpProxyConfig2();
+ request.rxVrfId = relay.getRxVrfId().byteValue();
+ final boolean isIpv6 = Ipv6.class == relay.getAddressType();
+ request.isIpv6 = booleanToByte(isIpv6);
+ request.serverVrfId = relay.getServerVrfId().intValue();
+ request.isAdd = booleanToByte(isAdd);
+ request.insertCircuitId = booleanToByte(relay.isInsertCircuitId());
+ request.dhcpServer = parseAddress(relay.getServerAddress(), isIpv6);
+ request.dhcpSrcAddress = parseAddress(relay.getGatewayAddress(), isIpv6);
+ getReplyForWrite(getFutureJVpp().dhcpProxyConfig2(request).toCompletableFuture(), id);
+ }
+
+ private byte[] parseAddress(@Nonnull final IpAddressNoZone address, final boolean isIpv6) {
+ if (isIpv6) {
+ return ipv6AddressNoZoneToArray(address.getIpv6AddressNoZone());
+ } else {
+ return ipv4AddressNoZoneToArray(address.getIpv4AddressNoZone());
+ }
+ }
+}
diff --git a/dhcp/dhcp-impl/src/main/java/io/fd/hc2vpp/dhcp/write/DhcpWriterFactory.java b/dhcp/dhcp-impl/src/main/java/io/fd/hc2vpp/dhcp/write/DhcpWriterFactory.java
new file mode 100644
index 000000000..93dc8048e
--- /dev/null
+++ b/dhcp/dhcp-impl/src/main/java/io/fd/hc2vpp/dhcp/write/DhcpWriterFactory.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2017 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.hc2vpp.dhcp.write;
+
+import com.google.inject.Inject;
+import io.fd.honeycomb.translate.impl.write.GenericListWriter;
+import io.fd.honeycomb.translate.write.WriterFactory;
+import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder;
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.dhcp.rev170315.Dhcp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.dhcp.rev170315.dhcp.attributes.Relays;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.dhcp.rev170315.dhcp.attributes.relays.Relay;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Factory producing writers for DHCP plugin's data.
+ */
+public final class DhcpWriterFactory implements WriterFactory {
+
+ private static final InstanceIdentifier<Relay> RELAY_ID = InstanceIdentifier.create(Dhcp.class).child(Relays.class).child(Relay.class);
+
+ @Inject
+ private FutureJVppCore vppApi;
+
+ @Override
+ public void init(@Nonnull final ModifiableWriterRegistryBuilder registry) {
+ registry.add(new GenericListWriter<>(RELAY_ID, new DhcpRelayCustomizer(vppApi)));
+ }
+}
diff --git a/dhcp/dhcp-impl/src/test/java/io/fd/hc2vpp/dhcp/DhcpModuleTest.java b/dhcp/dhcp-impl/src/test/java/io/fd/hc2vpp/dhcp/DhcpModuleTest.java
new file mode 100644
index 000000000..998f75fb5
--- /dev/null
+++ b/dhcp/dhcp-impl/src/test/java/io/fd/hc2vpp/dhcp/DhcpModuleTest.java
@@ -0,0 +1,80 @@
+/*
+ * 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.hc2vpp.dhcp;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.Matchers.empty;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import com.google.inject.Guice;
+import com.google.inject.Inject;
+import com.google.inject.name.Named;
+import com.google.inject.testing.fieldbinder.Bind;
+import com.google.inject.testing.fieldbinder.BoundFieldModule;
+import io.fd.hc2vpp.dhcp.write.DhcpWriterFactory;
+import io.fd.honeycomb.translate.impl.write.registry.FlatWriterRegistryBuilder;
+import io.fd.honeycomb.translate.write.WriterFactory;
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import java.util.HashSet;
+import java.util.Set;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+
+public class DhcpModuleTest {
+
+ @Named("honeycomb-context")
+ @Bind
+ @Mock
+ private DataBroker honeycombContext;
+
+ @Named("honeycomb-initializer")
+ @Bind
+ @Mock
+ private DataBroker honeycombInitializer;
+
+ @Bind
+ @Mock
+ private FutureJVppCore futureJVppCore;
+
+ @Inject
+ private Set<WriterFactory> writerFactories = new HashSet<>();
+
+ @Before
+ public void setUp() {
+ initMocks(this);
+ Guice.createInjector(new DhcpModule(), BoundFieldModule.of(this)).injectMembers(this);
+ }
+
+ @Test
+ public void testWriterFactories() throws Exception {
+ assertThat(writerFactories, is(not(empty())));
+
+ // Test registration process (all dependencies present, topological order of writers does exist, etc.)
+ final FlatWriterRegistryBuilder registryBuilder = new FlatWriterRegistryBuilder();
+ writerFactories.stream().forEach(factory -> factory.init(registryBuilder));
+ assertNotNull(registryBuilder.build());
+ assertEquals(1, writerFactories.size());
+ assertTrue(writerFactories.iterator().next() instanceof DhcpWriterFactory);
+ }
+}
diff --git a/dhcp/dhcp-impl/src/test/java/io/fd/hc2vpp/dhcp/helpers/SchemaContextTestHelper.java b/dhcp/dhcp-impl/src/test/java/io/fd/hc2vpp/dhcp/helpers/SchemaContextTestHelper.java
new file mode 100644
index 000000000..f7890b356
--- /dev/null
+++ b/dhcp/dhcp-impl/src/test/java/io/fd/hc2vpp/dhcp/helpers/SchemaContextTestHelper.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2017 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.hc2vpp.dhcp.helpers;
+
+import com.google.common.collect.ImmutableSet;
+import io.fd.honeycomb.test.tools.annotations.InjectablesProcessor;
+import io.fd.honeycomb.test.tools.annotations.SchemaContextProvider;
+import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext;
+
+public interface SchemaContextTestHelper extends InjectablesProcessor {
+
+ @SchemaContextProvider
+ default ModuleInfoBackedContext getSchemaContext() {
+ return provideSchemaContextFor(ImmutableSet.of(
+ // dhcp
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.dhcp.rev170315.$YangModuleInfoImpl
+ .getInstance()
+ ));
+ }
+}
diff --git a/dhcp/dhcp-impl/src/test/java/io/fd/hc2vpp/dhcp/write/DhcpRelayCustomizerTest.java b/dhcp/dhcp-impl/src/test/java/io/fd/hc2vpp/dhcp/write/DhcpRelayCustomizerTest.java
new file mode 100644
index 000000000..629c8d893
--- /dev/null
+++ b/dhcp/dhcp-impl/src/test/java/io/fd/hc2vpp/dhcp/write/DhcpRelayCustomizerTest.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2017 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.hc2vpp.dhcp.write;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
+import io.fd.hc2vpp.dhcp.helpers.SchemaContextTestHelper;
+import io.fd.honeycomb.test.tools.HoneycombTestRunner;
+import io.fd.honeycomb.test.tools.annotations.InjectTestData;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.vpp.jvpp.core.dto.DhcpProxyConfig2;
+import io.fd.vpp.jvpp.core.dto.DhcpProxyConfig2Reply;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.dhcp.rev170315.AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.dhcp.rev170315.Dhcp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.dhcp.rev170315.Ipv4;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.dhcp.rev170315.Ipv6;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.dhcp.rev170315.dhcp.attributes.Relays;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.dhcp.rev170315.dhcp.attributes.relays.Relay;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.dhcp.rev170315.dhcp.attributes.relays.RelayKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+@RunWith(HoneycombTestRunner.class)
+public class DhcpRelayCustomizerTest extends WriterCustomizerTest implements SchemaContextTestHelper {
+
+ private static final String RELAYS_PATH = "/dhcp:dhcp/dhcp:relays";
+ private static final InstanceIdentifier<Relays> RELAYS_IID = InstanceIdentifier.create(Dhcp.class).child(Relays.class);
+
+ private DhcpRelayCustomizer customizer;
+
+ @Override
+ protected void setUpTest() throws Exception {
+ customizer = new DhcpRelayCustomizer(api);
+ when(api.dhcpProxyConfig2(any())).thenReturn(future(new DhcpProxyConfig2Reply()));
+ }
+
+ @Test
+ public void testWrite(@InjectTestData(resourcePath = "/relay/ipv4DhcpRelay.json", id = RELAYS_PATH) Relays relays)
+ throws WriteFailedException {
+ final Relay data = relays.getRelay().get(0);
+ final int rxVrfId = 0;
+ customizer.writeCurrentAttributes(getId(rxVrfId, Ipv4.class), data, writeContext);
+ final DhcpProxyConfig2 request = new DhcpProxyConfig2();
+ request.rxVrfId = rxVrfId;
+ request.isIpv6 = 0;
+ request.isAdd = 1;
+ request.insertCircuitId = 1;
+ request.dhcpServer = new byte[]{1,2,3,4};
+ request.dhcpSrcAddress = new byte[]{5,6,7,8};
+ verify(api).dhcpProxyConfig2(request);
+ }
+
+ @Test
+ public void testUpdate(@InjectTestData(resourcePath = "/relay/ipv6DhcpRelay.json", id = RELAYS_PATH) Relays relays)
+ throws WriteFailedException {
+ final Relay data = relays.getRelay().get(0);
+ final int rxVrfId = 1;
+ customizer.updateCurrentAttributes(getId(rxVrfId, Ipv6.class), mock(Relay.class), data, writeContext);
+ final DhcpProxyConfig2 request = new DhcpProxyConfig2();
+ request.rxVrfId = rxVrfId;
+ request.serverVrfId = 2;
+ request.isIpv6 = 1;
+ request.isAdd = 1;
+ request.insertCircuitId = 1;
+ request.dhcpServer = new byte[]{0x20, 0x01, 0, 0, 0, 0, 0, 0, 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0x01};
+ request.dhcpSrcAddress = new byte[]{0x20, 0x01, 0, 0, 0, 0, 0, 0, 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0x02};
+ verify(api).dhcpProxyConfig2(request);
+ }
+
+ @Test
+ public void testDelete(@InjectTestData(resourcePath = "/relay/ipv4DhcpRelay.json", id = RELAYS_PATH) Relays relays)
+ throws WriteFailedException {
+ final Relay data = relays.getRelay().get(0);
+ final int rxVrfId = 0;
+ customizer.deleteCurrentAttributes(getId(rxVrfId, Ipv4.class), data, writeContext);
+ final DhcpProxyConfig2 request = new DhcpProxyConfig2();
+ request.rxVrfId = rxVrfId;
+ request.isIpv6 = 0;
+ request.isAdd = 0;
+ request.insertCircuitId = 1;
+ request.dhcpServer = new byte[]{1,2,3,4};
+ request.dhcpSrcAddress = new byte[]{5,6,7,8};
+ verify(api).dhcpProxyConfig2(request);
+ }
+
+ private InstanceIdentifier<Relay> getId(final long rxVrfId, final Class<? extends AddressFamily> addressType) {
+ return RELAYS_IID.child(Relay.class, new RelayKey(addressType, rxVrfId));
+ }
+} \ No newline at end of file
diff --git a/dhcp/dhcp-impl/src/test/resources/relay/ipv4DhcpRelay.json b/dhcp/dhcp-impl/src/test/resources/relay/ipv4DhcpRelay.json
new file mode 100644
index 000000000..3af4a43ff
--- /dev/null
+++ b/dhcp/dhcp-impl/src/test/resources/relay/ipv4DhcpRelay.json
@@ -0,0 +1,13 @@
+{
+ "relays": {
+ "relay": [
+ {
+ "address-type": "ipv4",
+ "rx-vrf-id": 0,
+ "server-address": "1.2.3.4",
+ "gateway-address": "5.6.7.8",
+ "insert-circuit-id": "true"
+ }
+ ]
+ }
+}
diff --git a/dhcp/dhcp-impl/src/test/resources/relay/ipv6DhcpRelay.json b/dhcp/dhcp-impl/src/test/resources/relay/ipv6DhcpRelay.json
new file mode 100644
index 000000000..5a1180d13
--- /dev/null
+++ b/dhcp/dhcp-impl/src/test/resources/relay/ipv6DhcpRelay.json
@@ -0,0 +1,14 @@
+{
+ "relays": {
+ "relay": [
+ {
+ "address-type": "ipv6",
+ "rx-vrf-id": 1,
+ "server-address": "2001::1",
+ "server-vrf-id": 2,
+ "gateway-address": "2001::2",
+ "insert-circuit-id": "true"
+ }
+ ]
+ }
+}
diff --git a/dhcp/dhcp_postman_collection.json b/dhcp/dhcp_postman_collection.json
new file mode 100644
index 000000000..dab109e92
--- /dev/null
+++ b/dhcp/dhcp_postman_collection.json
@@ -0,0 +1,139 @@
+{
+ "id": "a38b7e49-665c-4646-723d-d78bbf27080e",
+ "name": "DHCP",
+ "description": "Provides DHCP configuration examples for hc2vpp.",
+ "order": [
+ "e718ef1d-ec09-23a6-f644-7306545453bd",
+ "80aae885-6a8b-09b2-f3cc-8c52fa4e081e",
+ "8362683a-c911-27fa-c0bd-8a3515cc4bae",
+ "a76f4dce-f094-ecff-d1c1-28217de33494",
+ "c56f4661-f9ff-38ee-cf0b-0863e5809f4e",
+ "43ee4aca-717c-bfdb-7152-520474e5eef6"
+ ],
+ "folders": [],
+ "timestamp": 1487055938314,
+ "owner": "567303",
+ "public": false,
+ "requests": [
+ {
+ "id": "43ee4aca-717c-bfdb-7152-520474e5eef6",
+ "headers": "Authorization: Basic YWRtaW46YWRtaW4=\nContent-Type: application/json\n",
+ "url": "http://localhost:8183/restconf/config/dhcp:dhcp/relays/",
+ "preRequestScript": null,
+ "pathVariables": {},
+ "method": "GET",
+ "data": [],
+ "dataMode": "raw",
+ "version": 2,
+ "tests": null,
+ "currentHelper": "normal",
+ "helperAttributes": {},
+ "time": 1487059202453,
+ "name": "Show DHCP Relay cfg",
+ "description": "",
+ "collectionId": "a38b7e49-665c-4646-723d-d78bbf27080e",
+ "responses": [],
+ "rawModeData": "{\n\t\"relay\": [\n\t\t{\n\t\t\t\"address-type\": \"ipv4\",\n\t\t\t\"rx-vrf-id\": 0,\n\t\t\t\"server-address\": \"1.2.3.4\",\n\t\t\t\"gateway-address\": \"5.6.7.8\",\n\t\t\t\"insert-circuit-id\": \"true\"\n\t\t}\n\t]\n}\n"
+ },
+ {
+ "id": "80aae885-6a8b-09b2-f3cc-8c52fa4e081e",
+ "headers": "Authorization: Basic YWRtaW46YWRtaW4=\nContent-Type: application/json\n",
+ "url": "http://localhost:8183/restconf/config/dhcp:dhcp/relays/relay/dhcp:ipv4/1",
+ "preRequestScript": null,
+ "pathVariables": {},
+ "method": "PUT",
+ "data": [],
+ "dataMode": "raw",
+ "version": 2,
+ "tests": null,
+ "currentHelper": "normal",
+ "helperAttributes": {},
+ "time": 1487059355510,
+ "name": "Add IP4 DHCP Relay #2",
+ "description": "Equivalent of\n\nvppctl set dhcp proxy server 1.2.3.5 src-address 5.6.7.9 add-option-82\n\ncan be verified with\n\nvppctl show dhcp proxy",
+ "collectionId": "a38b7e49-665c-4646-723d-d78bbf27080e",
+ "responses": [],
+ "rawModeData": "{\n\t\"relay\": [\n\t\t{\n\t\t\t\"address-type\": \"ipv4\",\n\t\t\t\"rx-vrf-id\": 1,\n\t\t\t\"server-address\": \"1.2.3.5\",\n\t\t\t\"gateway-address\": \"5.6.7.9\",\n\t\t\t\"insert-circuit-id\": \"true\"\n\t\t}\n\t]\n}\n"
+ },
+ {
+ "id": "8362683a-c911-27fa-c0bd-8a3515cc4bae",
+ "headers": "Authorization: Basic YWRtaW46YWRtaW4=\nContent-Type: application/json\n",
+ "url": "http://localhost:8183/restconf/config/dhcp:dhcp/relays/relay/dhcp:ipv6/1",
+ "preRequestScript": null,
+ "pathVariables": {},
+ "method": "PUT",
+ "data": [],
+ "dataMode": "raw",
+ "version": 2,
+ "tests": null,
+ "currentHelper": "normal",
+ "helperAttributes": {},
+ "time": 1487056567412,
+ "name": "Configure IP6 DHCP Relay",
+ "description": "Configuration of IP6 DHCP proxy is not supported trough CLI",
+ "collectionId": "a38b7e49-665c-4646-723d-d78bbf27080e",
+ "responses": [],
+ "rawModeData": "{\n\t\"relay\": [\n\t\t{\n\t \"address-type\": \"ipv6\",\n\t \"rx-vrf-id\": 1,\n\t \"server-address\": \"2001::1\",\n\t \"server-vrf-id\": 2,\n\t \"gateway-address\": \"2001::2\",\n\t \"insert-circuit-id\": \"true\"\n\t\t}\n\t]\n}\n"
+ },
+ {
+ "id": "a76f4dce-f094-ecff-d1c1-28217de33494",
+ "headers": "Authorization: Basic YWRtaW46YWRtaW4=\nContent-Type: application/json\n",
+ "url": "http://localhost:8183/restconf/config/dhcp:dhcp/relays/relay/dhcp:ipv4/0",
+ "preRequestScript": null,
+ "pathVariables": {},
+ "method": "DELETE",
+ "data": [],
+ "dataMode": "raw",
+ "version": 2,
+ "tests": null,
+ "currentHelper": "normal",
+ "helperAttributes": {},
+ "time": 1487059058881,
+ "name": "Delete IP4 DHCP Relay #1",
+ "description": "Equivalent of\n\nvppctl set dhcp proxy del server 1.2.3.4\n\nvppctl show dhcp proxy",
+ "collectionId": "a38b7e49-665c-4646-723d-d78bbf27080e",
+ "responses": [],
+ "rawModeData": ""
+ },
+ {
+ "id": "c56f4661-f9ff-38ee-cf0b-0863e5809f4e",
+ "headers": "Authorization: Basic YWRtaW46YWRtaW4=\nContent-Type: application/json\n",
+ "url": "http://localhost:8183/restconf/config/dhcp:dhcp/relays/relay/dhcp:ipv4/1",
+ "preRequestScript": null,
+ "pathVariables": {},
+ "method": "DELETE",
+ "data": [],
+ "dataMode": "raw",
+ "version": 2,
+ "tests": null,
+ "currentHelper": "normal",
+ "helperAttributes": {},
+ "time": 1487059316221,
+ "name": "Delete IP4 DHCP Relay #2",
+ "description": "Equivalent of\n\nvppctl set dhcp proxy del server 1.2.3.5\n\nvppctl show dhcp proxy",
+ "collectionId": "a38b7e49-665c-4646-723d-d78bbf27080e",
+ "responses": [],
+ "rawModeData": ""
+ },
+ {
+ "id": "e718ef1d-ec09-23a6-f644-7306545453bd",
+ "headers": "Authorization: Basic YWRtaW46YWRtaW4=\nContent-Type: application/json\n",
+ "url": "http://localhost:8183/restconf/config/dhcp:dhcp/relays/relay/dhcp:ipv4/0",
+ "preRequestScript": null,
+ "pathVariables": {},
+ "method": "PUT",
+ "data": [],
+ "dataMode": "raw",
+ "version": 2,
+ "tests": null,
+ "currentHelper": "normal",
+ "helperAttributes": {},
+ "time": 1487056454396,
+ "name": "Add IP4 DHCP Relay #1",
+ "description": "Equivalent of\n\nvppctl set dhcp proxy server 1.2.3.4 src-address 5.6.7.8 add-option-82\n\ncan be verified with\n\nvppctl show dhcp proxy",
+ "collectionId": "a38b7e49-665c-4646-723d-d78bbf27080e",
+ "responses": [],
+ "rawModeData": "{\n\t\"relay\": [\n\t\t{\n\t\t\t\"address-type\": \"ipv4\",\n\t\t\t\"rx-vrf-id\": 0,\n\t\t\t\"server-address\": \"1.2.3.4\",\n\t\t\t\"gateway-address\": \"5.6.7.8\",\n\t\t\t\"insert-circuit-id\": \"true\"\n\t\t}\n\t]\n}\n"
+ }
+ ]
+} \ No newline at end of file
diff --git a/dhcp/pom.xml b/dhcp/pom.xml
index d6e565265..1d602db37 100644
--- a/dhcp/pom.xml
+++ b/dhcp/pom.xml
@@ -29,6 +29,7 @@
<modules>
<module>dhcp-api</module>
+ <module>dhcp-impl</module>
</modules>
<!-- DO NOT install or deploy the repo root pom as it's only needed to initiate a build -->
diff --git a/vpp-integration/minimal-distribution/pom.xml b/vpp-integration/minimal-distribution/pom.xml
index d5b4d8d5b..d6f773dd6 100644
--- a/vpp-integration/minimal-distribution/pom.xml
+++ b/vpp-integration/minimal-distribution/pom.xml
@@ -38,6 +38,7 @@
<ioam.version>1.17.04-SNAPSHOT</ioam.version>
<routing.version>1.17.04-SNAPSHOT</routing.version>
<acl.version>1.17.04-SNAPSHOT</acl.version>
+ <dhcp.version>1.17.04-SNAPSHOT</dhcp.version>
<distribution.modules>
io.fd.hc2vpp.common.integration.VppCommonModule,
@@ -48,6 +49,7 @@
io.fd.hc2vpp.nat.NatModule,
io.fd.hc2vpp.routing.RoutingModule,
io.fd.hc2vpp.acl.AclModule,
+ io.fd.hc2vpp.dhcp.DhcpModule,
// io.fd.hc2vpp.vppnsh.impl.VppNshModule,
<!-- Nsh module by default disabled, because it needs vpp-nsh plugin, which is not part of vpp codebase.-->
// io.fd.hc2vpp.vppioam.impl.VppIoamModule
@@ -119,5 +121,10 @@
<artifactId>acl-impl</artifactId>
<version>${acl.version}</version>
</dependency>
+ <dependency>
+ <groupId>io.fd.hc2vpp.dhcp</groupId>
+ <artifactId>dhcp-impl</artifactId>
+ <version>${dhcp.version}</version>
+ </dependency>
</dependencies>
</project>