summaryrefslogtreecommitdiffstats
path: root/srv6/srv6-impl/src
diff options
context:
space:
mode:
Diffstat (limited to 'srv6/srv6-impl/src')
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/Srv6Configuration.java35
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/Srv6IIds.java96
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/Srv6Module.java48
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/JVppRequest.java38
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/LocalSidFunctionBinder.java70
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/LocalSidFunctionBindingRegistry.java50
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/LocalSidFunctionWriteBindingRegistry.java34
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/LocalSidFunctionWriteBindingRegistryProvider.java56
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/lookup/EndDT4FunctionBinder.java49
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/lookup/EndDT6FunctionBinder.java49
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/lookup/EndTFunctionBinder.java47
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/lookup/TableLookupFunctionBinder.java76
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/nofunction/EndFunctionBinder.java58
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/EndDX2FunctionBinder.java56
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/EndDX4FunctionBinder.java60
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/EndDX6FunctionBinder.java60
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/EndXFunctionBinder.java61
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/XConnectFunctionBinder.java65
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/DeleteRequest.java25
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/Srv6Customizer.java49
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/Srv6WriterFactory.java59
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/UpdateRequest.java25
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/WriteRequest.java25
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/encap/source/EncapsulationSourceCustomizer.java60
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/encap/source/request/EncapsulationSourceDeleteRequest.java39
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/encap/source/request/EncapsulationSourceWriteRequest.java58
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/LocatorCustomizer.java45
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/SidCustomizer.java136
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/request/LocalSidFunctionRequest.java133
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/request/NoProtocolLocalSidRequest.java29
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/request/TableLookupLocalSidRequest.java49
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/request/XConnectLocalSidRequest.java87
-rw-r--r--srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/Srv6ModuleTest.java98
-rw-r--r--srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/util/JvppRequestTest.java101
-rw-r--r--srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/util/function/LocalSidFunctionBindingRegistryTest.java246
-rw-r--r--srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/Srv6CustomizerTest.java42
-rw-r--r--srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/encap/source/EncapsulationSourceCustomizerTest.java72
-rw-r--r--srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/encap/source/request/EncapsulationSourceRequestTest.java78
-rw-r--r--srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/sid/SidCustomizerTest.java81
-rw-r--r--srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/sid/request/LocalSidRequestTest.java97
-rw-r--r--srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/sid/request/NoProtocolLocalSidRequestTest.java81
-rw-r--r--srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/sid/request/TableLookupLocalSidRequestTest.java76
-rw-r--r--srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/sid/request/XConnectLocalSidRequestTest.java90
43 files changed, 2889 insertions, 0 deletions
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/Srv6Configuration.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/Srv6Configuration.java
new file mode 100644
index 000000000..8d23b1703
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/Srv6Configuration.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6;
+
+public class Srv6Configuration {
+
+ /**
+ * Used to map Srv6 Sids to locator length values
+ */
+ public static final String LOCATOR_CONTEXT = "locator-context";
+
+ /**
+ * Locator length context child name for locator length
+ */
+ public static final String LOCATOR_LENGTH = "locator-length";
+
+ /**
+ * Locator length context child name for locator length
+ */
+ public static final String LOCATOR_IPV6_ADDRESS = "locator-ipv6-address";
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/Srv6IIds.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/Srv6IIds.java
new file mode 100644
index 000000000..53c0df6d1
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/Srv6IIds.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package io.fd.hc2vpp.srv6;
+
+import org.opendaylight.yang.gen.v1.urn.hc2vpp.params.xml.ns.yang.vpp.ietf.srv6.base.rev180613.VppSrv6FibLocatorAugment;
+import org.opendaylight.yang.gen.v1.urn.hc2vpp.params.xml.ns.yang.vpp.ietf.srv6.base.rev180613.vpp.srv6.fib.FibTable;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.Routing;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.Locator1;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.multi.paths.v6.Paths;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.multi.paths.v6.paths.Path;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.routing.srv6.locators.locator.Static;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.routing.srv6.locators.locator._static.LocalSids;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6._static.cfg.Sid;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.End;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndB6;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndB6Encaps;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndBm;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndDt4;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndDt46;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndDt6;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndDx2;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndDx4;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndDx6;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndT;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndX;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.Routing1;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.routing.Srv6;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.srv6.encap.Encapsulation;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.srv6.locators.Locators;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.srv6.locators.locators.Locator;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.srv6.locators.locators.locator.Prefix;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class Srv6IIds {
+ public final static InstanceIdentifier<Routing> RT = InstanceIdentifier.create(Routing.class);
+ public final static InstanceIdentifier<Routing1> RT_RT1_AUG = RT.augmentation(Routing1.class);
+ public final static InstanceIdentifier<Srv6> RT_SRV6 = RT_RT1_AUG.child(Srv6.class);
+ public final static InstanceIdentifier<Locators> RT_SRV6_LOCATORS = RT_SRV6.child(Locators.class);
+ public final static InstanceIdentifier<Locator> RT_SRV6_LOCS_LOCATOR = RT_SRV6_LOCATORS.child(Locator.class);
+ public final static InstanceIdentifier<Locator> LOCATOR = InstanceIdentifier.create(Locator.class);
+ public final static InstanceIdentifier<VppSrv6FibLocatorAugment> LOC_FT_AUG =
+ LOCATOR.augmentation(VppSrv6FibLocatorAugment.class);
+ public final static InstanceIdentifier<FibTable> LOC_FT = LOC_FT_AUG.child(FibTable.class);
+
+ public final static InstanceIdentifier<Prefix> LOC_PREFIX = LOCATOR.child(Prefix.class);
+ public final static InstanceIdentifier<Locator1> RT_SRV6_LOCS_LOC_AUG =
+ RT_SRV6_LOCS_LOCATOR.augmentation(Locator1.class);
+ public final static InstanceIdentifier<Static> RT_SRV6_LOCS_LOC_STATIC = RT_SRV6_LOCS_LOC_AUG.child(Static.class);
+ public final static InstanceIdentifier<LocalSids> RT_SRV6_LOCS_LOC_ST_LOCALSIDS =
+ RT_SRV6_LOCS_LOC_STATIC.child(LocalSids.class);
+ public final static InstanceIdentifier<Sid> RT_SRV6_LOCS_LOC_ST_LS_SID =
+ RT_SRV6_LOCS_LOC_ST_LOCALSIDS.child(Sid.class);
+ public final static InstanceIdentifier<Encapsulation> RT_SRV6_ENCAP = RT_SRV6.child(Encapsulation.class);
+
+ public final static InstanceIdentifier<Sid> SID = InstanceIdentifier.create(Sid.class);
+ public final static InstanceIdentifier<End> SID_END = SID.child(End.class);
+ public final static InstanceIdentifier<EndX> SID_END_X = SID.child(EndX.class);
+ public final static InstanceIdentifier<Paths> SID_END_X_PATHS = SID_END_X.child(Paths.class);
+ public final static InstanceIdentifier<Path> SID_END_X_PATHS_PATH = SID_END_X_PATHS.child(Path.class);
+ public final static InstanceIdentifier<EndT> SID_END_T = SID.child(EndT.class);
+ public final static InstanceIdentifier<EndB6> SID_END_B6 = SID.child(EndB6.class);
+ public final static InstanceIdentifier<EndB6Encaps> SID_END_B6ENCAP = SID.child(EndB6Encaps.class);
+ public final static InstanceIdentifier<EndBm> SID_END_BM = SID.child(EndBm.class);
+ public final static InstanceIdentifier<EndDt4> SID_END_DT4 = SID.child(EndDt4.class);
+ public final static InstanceIdentifier<EndDt6> SID_END_DT6 = SID.child(EndDt6.class);
+ public final static InstanceIdentifier<EndDt46> SID_END_DT46 = SID.child(EndDt46.class);
+ public final static InstanceIdentifier<EndDx2> SID_END_DX2 = SID.child(EndDx2.class);
+ public final static InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.end.dx2.Paths>
+ SID_END_DX2_PATHS = SID_END_DX2.child(
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.end.dx2.Paths.class);
+ public final static InstanceIdentifier<EndDx4> SID_END_DX4 = SID.child(EndDx4.class);
+ public final static InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.multi.paths.v4.Paths>
+ SID_END_DX4_PATHS = SID_END_DX4.child(
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.multi.paths.v4.Paths.class);
+ public final static InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.multi.paths.v4.paths.Path>
+ SID_END_DX4_PATHS_PATH = SID_END_DX4_PATHS.child(
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.multi.paths.v4.paths.Path.class);
+ public final static InstanceIdentifier<EndDx6> SID_END_DX6 = SID.child(EndDx6.class);
+ public final static InstanceIdentifier<Paths> SID_END_DX6_PATHS = SID_END_DX6.child(Paths.class);
+ public final static InstanceIdentifier<Path> SID_END_DX6_PATHS_PATH = SID_END_DX6_PATHS.child(Path.class);
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/Srv6Module.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/Srv6Module.java
new file mode 100644
index 000000000..5dd3e2097
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/Srv6Module.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Singleton;
+import com.google.inject.multibindings.Multibinder;
+import io.fd.hc2vpp.srv6.util.function.LocalSidFunctionWriteBindingRegistry;
+import io.fd.hc2vpp.srv6.util.function.LocalSidFunctionWriteBindingRegistryProvider;
+import io.fd.hc2vpp.srv6.write.Srv6WriterFactory;
+import io.fd.honeycomb.translate.write.WriterFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Srv6Module extends AbstractModule {
+
+ private static final Logger LOG = LoggerFactory.getLogger(Srv6Module.class);
+
+ @Override
+ protected void configure() {
+ LOG.info("Installing SRv6 module");
+ LOG.info("Reading SRv6 configuration");
+ requestInjection(Srv6Configuration.class);
+
+ bind(LocalSidFunctionWriteBindingRegistry.class).toProvider(LocalSidFunctionWriteBindingRegistryProvider.class)
+ .in(Singleton.class);
+
+ LOG.info("Injecting SRv6 writers");
+ final Multibinder<WriterFactory> writeBinder = Multibinder.newSetBinder(binder(), WriterFactory.class);
+ writeBinder.addBinding().to(Srv6WriterFactory.class);
+
+ LOG.info("SRv6 module successfully configured");
+ }
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/JVppRequest.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/JVppRequest.java
new file mode 100644
index 000000000..9ea9fff30
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/JVppRequest.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.util;
+
+import io.fd.hc2vpp.common.translate.util.AddressTranslator;
+import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer;
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+
+public abstract class JVppRequest implements AddressTranslator, JvppReplyConsumer {
+
+ private final FutureJVppCore api;
+
+ protected JVppRequest(final FutureJVppCore api) {
+ this.api = api;
+ }
+
+ protected FutureJVppCore getApi() {
+ return api;
+ }
+
+ public void checkValid() {
+ //noop
+ }
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/LocalSidFunctionBinder.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/LocalSidFunctionBinder.java
new file mode 100644
index 000000000..e51ee5ac5
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/LocalSidFunctionBinder.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.util.function;
+
+import io.fd.hc2vpp.srv6.write.sid.request.LocalSidFunctionRequest;
+import io.fd.honeycomb.translate.write.WriteContext;
+import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6._static.cfg.Sid;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.Srv6EndpointType;
+
+/**
+ * Binder interface, which is used to map yang model data classes of local sid functions to local sid function requests
+ * used to configure endpoint functions on VPP. It uses behavior function type integer value defined by VPP API, to find
+ * suitable binder. This value is translated to {@link Srv6EndpointType} in model, which represents the same endpoint
+ * function as defined by VPP API.
+ *
+ * @param <T> Type which extends general interface for {@link LocalSidFunctionRequest} and represents template binder
+ * that is used to process end function data represented by provided class type.
+ */
+public interface LocalSidFunctionBinder<T extends LocalSidFunctionRequest> {
+
+ /**
+ * Binds request accordingly to type of function implemented by this interface
+ *
+ * @return request with all attributes necessary for this function
+ */
+ @Nonnull
+ T createWriteRequestAndBind(@Nonnull final Sid data, @Nonnull final WriteContext ctx);
+
+ /**
+ * Provides Endpoint function type class.
+ * @return Endpoint function class
+ */
+ @Nonnull
+ Class<? extends Srv6EndpointType> getHandledFunctionType();
+
+ /**
+ * Provide behavior function type integer value.
+ *
+ * @return integer value of behaviour function type as defined in VPP api
+ */
+ int getBehaviourFunctionType();
+
+ /**
+ * Checks whether binder can handle provided data
+ *
+ * @param data sid function data to be checked
+ * @return true if function binder is able to process provided data, false otherwise
+ */
+ default boolean canHandle(final Sid data) {
+ if (data == null || data.getEndBehaviorType() == null) {
+ return false;
+ }
+ return data.getEndBehaviorType().equals(getHandledFunctionType());
+ }
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/LocalSidFunctionBindingRegistry.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/LocalSidFunctionBindingRegistry.java
new file mode 100644
index 000000000..d56656fb9
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/LocalSidFunctionBindingRegistry.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.util.function;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import io.fd.hc2vpp.srv6.write.sid.request.LocalSidFunctionRequest;
+import java.util.ArrayList;
+import java.util.List;
+import javax.annotation.Nonnull;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+abstract class LocalSidFunctionBindingRegistry<T extends LocalSidFunctionRequest> {
+
+ private static final Logger LOG = LoggerFactory.getLogger(LocalSidFunctionBindingRegistry.class);
+ final List<LocalSidFunctionBinder<T>> binders;
+
+ LocalSidFunctionBindingRegistry() {
+ binders = new ArrayList<>();
+ }
+
+ @SuppressWarnings("unchecked")
+ public void registerFunctionType(@Nonnull final LocalSidFunctionBinder binder) {
+ checkNotNull(binder, "Cannot register null binder");
+ if (!isFunctionRegistered(binder)) {
+ binders.add(binder);
+ } else {
+ LOG.warn("Binder for class already registered. Canceling registration for {}.", binder);
+ }
+ }
+
+ private boolean isFunctionRegistered(@Nonnull final LocalSidFunctionBinder binder) {
+ return binders.stream().parallel().anyMatch(locBinder -> locBinder.getClass().equals(binder.getClass()));
+ }
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/LocalSidFunctionWriteBindingRegistry.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/LocalSidFunctionWriteBindingRegistry.java
new file mode 100644
index 000000000..b74a7668b
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/LocalSidFunctionWriteBindingRegistry.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.util.function;
+
+import io.fd.hc2vpp.srv6.write.sid.request.LocalSidFunctionRequest;
+import io.fd.honeycomb.translate.util.RWUtils;
+import io.fd.honeycomb.translate.write.WriteContext;
+import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6._static.cfg.Sid;
+
+public class LocalSidFunctionWriteBindingRegistry<T extends LocalSidFunctionRequest>
+ extends LocalSidFunctionBindingRegistry<T> {
+
+ public LocalSidFunctionRequest bind(final Sid localSid, @Nonnull final WriteContext ctx) {
+ return binders.parallelStream()
+ .filter(toLocalSidFunctionBinder -> toLocalSidFunctionBinder.canHandle(localSid))
+ .map(binder -> binder.createWriteRequestAndBind(localSid, ctx))
+ .collect(RWUtils.singleItemCollector());
+ }
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/LocalSidFunctionWriteBindingRegistryProvider.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/LocalSidFunctionWriteBindingRegistryProvider.java
new file mode 100644
index 000000000..20189b702
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/LocalSidFunctionWriteBindingRegistryProvider.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.util.function;
+
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.srv6.util.function.lookup.EndDT4FunctionBinder;
+import io.fd.hc2vpp.srv6.util.function.lookup.EndDT6FunctionBinder;
+import io.fd.hc2vpp.srv6.util.function.lookup.EndTFunctionBinder;
+import io.fd.hc2vpp.srv6.util.function.nofunction.EndFunctionBinder;
+import io.fd.hc2vpp.srv6.util.function.xconnect.EndDX2FunctionBinder;
+import io.fd.hc2vpp.srv6.util.function.xconnect.EndDX4FunctionBinder;
+import io.fd.hc2vpp.srv6.util.function.xconnect.EndDX6FunctionBinder;
+import io.fd.hc2vpp.srv6.util.function.xconnect.EndXFunctionBinder;
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import javax.inject.Named;
+
+public class LocalSidFunctionWriteBindingRegistryProvider implements Provider<LocalSidFunctionWriteBindingRegistry> {
+
+ @Inject
+ @Named("interface-context")
+ private NamingContext interfaceContext;
+
+ @Inject
+ private FutureJVppCore api;
+ private final LocalSidFunctionWriteBindingRegistry registry = new LocalSidFunctionWriteBindingRegistry();
+
+ @Override
+ public LocalSidFunctionWriteBindingRegistry get() {
+ registry.registerFunctionType(new EndFunctionBinder(api));
+ registry.registerFunctionType(new EndTFunctionBinder(api));
+ registry.registerFunctionType(new EndDT4FunctionBinder(api));
+ registry.registerFunctionType(new EndDT6FunctionBinder(api));
+ registry.registerFunctionType(new EndXFunctionBinder(api, interfaceContext));
+ registry.registerFunctionType(new EndDX2FunctionBinder(api, interfaceContext));
+ registry.registerFunctionType(new EndDX4FunctionBinder(api, interfaceContext));
+ registry.registerFunctionType(new EndDX6FunctionBinder(api, interfaceContext));
+
+ return registry;
+ }
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/lookup/EndDT4FunctionBinder.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/lookup/EndDT4FunctionBinder.java
new file mode 100644
index 000000000..e8ea22419
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/lookup/EndDT4FunctionBinder.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.util.function.lookup;
+
+import com.google.common.base.Preconditions;
+import io.fd.hc2vpp.srv6.write.sid.request.TableLookupLocalSidRequest;
+import io.fd.honeycomb.translate.write.WriteContext;
+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.srv6._static.rev180301.srv6._static.cfg.Sid;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndDT4;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.Srv6EndpointType;
+
+public class EndDT4FunctionBinder extends TableLookupFunctionBinder {
+
+ public EndDT4FunctionBinder(@Nonnull final FutureJVppCore api) {
+ super(api);
+ }
+
+ @Nonnull
+ @Override
+ public TableLookupLocalSidRequest createWriteRequestAndBind(@Nonnull Sid data,
+ @Nonnull WriteContext ctx) {
+ Preconditions.checkNotNull(data.getEndDt4(), "EndDt4 data cannot be null.");
+ Preconditions.checkNotNull(data.getEndDt4().getLookupTableIpv4(), "EndDt4 lookup table cannot be null.");
+ int lookupTable = data.getEndDt4().getLookupTableIpv4().getValue().intValue();
+ return bindData(new TableLookupLocalSidRequest(getFutureJVpp()), lookupTable, false, ctx);
+ }
+
+ @Override
+ @Nonnull
+ public Class<? extends Srv6EndpointType> getHandledFunctionType() {
+ return EndDT4.class;
+ }
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/lookup/EndDT6FunctionBinder.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/lookup/EndDT6FunctionBinder.java
new file mode 100644
index 000000000..01e6c6bb2
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/lookup/EndDT6FunctionBinder.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.util.function.lookup;
+
+import com.google.common.base.Preconditions;
+import io.fd.hc2vpp.srv6.write.sid.request.TableLookupLocalSidRequest;
+import io.fd.honeycomb.translate.write.WriteContext;
+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.srv6._static.rev180301.srv6._static.cfg.Sid;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndDT6;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.Srv6EndpointType;
+
+public class EndDT6FunctionBinder extends TableLookupFunctionBinder {
+
+ public EndDT6FunctionBinder(@Nonnull final FutureJVppCore api) {
+ super(api);
+ }
+
+ @Nonnull
+ @Override
+ public TableLookupLocalSidRequest createWriteRequestAndBind(@Nonnull Sid data,
+ @Nonnull WriteContext ctx) {
+ Preconditions.checkNotNull(data.getEndDt6(), "EndDt6 data cannot be null.");
+ Preconditions.checkNotNull(data.getEndDt6().getLookupTableIpv6(), "EndDt6 lookup table cannot be null.");
+ int lookupTable = data.getEndDt6().getLookupTableIpv6().getValue().intValue();
+ return bindData(new TableLookupLocalSidRequest(getFutureJVpp()), lookupTable, true, ctx);
+ }
+
+ @Override
+ @Nonnull
+ public Class<? extends Srv6EndpointType> getHandledFunctionType() {
+ return EndDT6.class;
+ }
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/lookup/EndTFunctionBinder.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/lookup/EndTFunctionBinder.java
new file mode 100644
index 000000000..13a2d3bc7
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/lookup/EndTFunctionBinder.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.util.function.lookup;
+
+import com.google.common.base.Preconditions;
+import io.fd.hc2vpp.srv6.write.sid.request.TableLookupLocalSidRequest;
+import io.fd.honeycomb.translate.write.WriteContext;
+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.srv6._static.rev180301.srv6._static.cfg.Sid;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.Srv6EndpointType;
+
+public class EndTFunctionBinder extends TableLookupFunctionBinder {
+
+ public EndTFunctionBinder(@Nonnull FutureJVppCore api) {
+ super(api);
+ }
+
+ @Nonnull
+ @Override
+ public TableLookupLocalSidRequest createWriteRequestAndBind(@Nonnull Sid data, @Nonnull WriteContext ctx) {
+ Preconditions.checkNotNull(data.getEndT(), "EndT data cannot be null.");
+ Preconditions.checkNotNull(data.getEndT().getLookupTableIpv6(), "EndT lookup table cannot be null.");
+ int lookupTable = data.getEndT().getLookupTableIpv6().getValue().intValue();
+ return bindData(new TableLookupLocalSidRequest(getFutureJVpp()), lookupTable, true, ctx);
+ }
+
+ @Override
+ @Nonnull
+ public Class<? extends Srv6EndpointType> getHandledFunctionType() {
+ return org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndT.class;
+ }
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/lookup/TableLookupFunctionBinder.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/lookup/TableLookupFunctionBinder.java
new file mode 100644
index 000000000..8e6ab4f40
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/lookup/TableLookupFunctionBinder.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.util.function.lookup;
+
+import static com.google.common.base.Preconditions.checkState;
+
+import com.google.common.collect.ImmutableMap;
+import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer;
+import io.fd.hc2vpp.fib.management.FibManagementIIds;
+import io.fd.hc2vpp.srv6.util.function.LocalSidFunctionBinder;
+import io.fd.hc2vpp.srv6.write.sid.request.TableLookupLocalSidRequest;
+import io.fd.honeycomb.translate.write.WriteContext;
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import java.util.Map;
+import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndDT4;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndDT6;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndT;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.Srv6EndpointType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.AddressFamilyIdentity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.Ipv4;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.Ipv6;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.VniReference;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.Table;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.TableKey;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+
+abstract class TableLookupFunctionBinder extends FutureJVppCustomizer
+ implements LocalSidFunctionBinder<TableLookupLocalSidRequest> {
+
+ private static final Map<Class<? extends Srv6EndpointType>, Integer> REGISTER = ImmutableMap.of(
+ EndT.class, 3,
+ EndDT6.class, 8,
+ EndDT4.class, 9
+ );
+
+ TableLookupFunctionBinder(@Nonnull final FutureJVppCore api) {
+ super(api);
+ checkState(REGISTER.containsKey(getHandledFunctionType()),
+ "Unsupported type of Local SID function %s", getHandledFunctionType());
+ }
+
+ TableLookupLocalSidRequest bindData(TableLookupLocalSidRequest request, int tableIndex, final boolean isIpv6,
+ WriteContext ctx) {
+ // verify if the lookup table exists
+ Class<? extends AddressFamilyIdentity> adrFamily = isIpv6 ? Ipv6.class : Ipv4.class;
+ TableKey tableKey = new TableKey(adrFamily, new VniReference(Integer.toUnsignedLong(tableIndex)));
+ KeyedInstanceIdentifier<Table, TableKey> vrfIid = FibManagementIIds.FM_FIB_TABLES.child(Table.class, tableKey);
+ if (!ctx.readAfter(vrfIid).isPresent()) {
+ throw new IllegalArgumentException(
+ String.format("VRF lookup table: %s not found. Binding failed for request: %s", tableKey, request));
+ }
+ request.setLookupFibTable(tableIndex);
+ request.setFunction(getBehaviourFunctionType());
+ return request;
+ }
+
+ @Override
+ public int getBehaviourFunctionType() {
+ return REGISTER.get(getHandledFunctionType());
+ }
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/nofunction/EndFunctionBinder.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/nofunction/EndFunctionBinder.java
new file mode 100644
index 000000000..a1952e3c4
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/nofunction/EndFunctionBinder.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.util.function.nofunction;
+
+import com.google.common.base.Preconditions;
+import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer;
+import io.fd.hc2vpp.srv6.util.function.LocalSidFunctionBinder;
+import io.fd.hc2vpp.srv6.write.sid.request.NoProtocolLocalSidRequest;
+import io.fd.honeycomb.translate.write.WriteContext;
+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.srv6._static.rev180301.srv6._static.cfg.Sid;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.Srv6EndpointType;
+
+public class EndFunctionBinder extends FutureJVppCustomizer implements
+ LocalSidFunctionBinder<NoProtocolLocalSidRequest> {
+
+ private static final int END_FUNCTION_VALUE = 1;
+
+ public EndFunctionBinder(@Nonnull FutureJVppCore futureJVppCore) {
+ super(futureJVppCore);
+ }
+
+ @Nonnull
+ @Override
+ public NoProtocolLocalSidRequest createWriteRequestAndBind(@Nonnull Sid data,
+ @Nonnull WriteContext ctx) {
+ Preconditions.checkNotNull(data.getEnd(), "End data cannot be null.");
+ NoProtocolLocalSidRequest request = new NoProtocolLocalSidRequest(getFutureJVpp());
+ request.setFunction(END_FUNCTION_VALUE);
+ return request;
+ }
+
+ @Nonnull
+ @Override
+ public Class<? extends Srv6EndpointType> getHandledFunctionType() {
+ return org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.End.class;
+ }
+
+ @Override
+ public int getBehaviourFunctionType() {
+ return END_FUNCTION_VALUE;
+ }
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/EndDX2FunctionBinder.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/EndDX2FunctionBinder.java
new file mode 100644
index 000000000..63de40b9c
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/EndDX2FunctionBinder.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.util.function.xconnect;
+
+import com.google.common.base.Preconditions;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.srv6.write.sid.request.XConnectLocalSidRequest;
+import io.fd.honeycomb.translate.write.WriteContext;
+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.srv6._static.rev180301.srv6._static.cfg.Sid;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndDX2;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.Srv6EndpointType;
+
+public class EndDX2FunctionBinder extends XConnectFunctionBinder {
+
+ public EndDX2FunctionBinder(@Nonnull final FutureJVppCore api, @Nonnull final NamingContext interfaceContext) {
+ super(api, interfaceContext);
+ }
+
+ @Nonnull
+ @Override
+ public XConnectLocalSidRequest createWriteRequestAndBind(@Nonnull Sid data,
+ @Nonnull WriteContext ctx) {
+ Preconditions.checkNotNull(data.getEndDx2(), "EndDx2 data cannot be null.");
+ Preconditions.checkNotNull(data.getEndDx2().getPaths(), "EndDx2 paths cannot be null.");
+ Preconditions.checkNotNull(data.getEndDx2().getPaths().getInterface(), "EndDx2 Interface cannot be null.");
+ XConnectLocalSidRequest request = new XConnectLocalSidRequest(getFutureJVpp());
+ String outInterface = data.getEndDx2().getPaths().getInterface();
+ Preconditions.checkArgument(outInterface != null && !outInterface.isEmpty(),
+ "Failed to map data: {} for request: {}", data, request);
+ request.setOutgoingInterfaceIndex(getInterfaceIndex(ctx.getMappingContext(), outInterface));
+ request.setFunction(getBehaviourFunctionType());
+ return request;
+ }
+
+ @Nonnull
+ @Override
+ public Class<? extends Srv6EndpointType> getHandledFunctionType() {
+ return EndDX2.class;
+ }
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/EndDX4FunctionBinder.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/EndDX4FunctionBinder.java
new file mode 100644
index 000000000..51abc9876
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/EndDX4FunctionBinder.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.util.function.xconnect;
+
+import com.google.common.base.Preconditions;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.srv6.write.sid.request.XConnectLocalSidRequest;
+import io.fd.honeycomb.translate.write.WriteContext;
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import java.util.Optional;
+import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.multi.paths.v4.paths.Path;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6._static.cfg.Sid;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndDX4;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.Srv6EndpointType;
+
+public class EndDX4FunctionBinder extends XConnectFunctionBinder {
+
+ public EndDX4FunctionBinder(@Nonnull FutureJVppCore api, @Nonnull NamingContext interfaceContext) {
+ super(api, interfaceContext);
+ }
+
+ @Nonnull
+ @Override
+ public XConnectLocalSidRequest createWriteRequestAndBind(@Nonnull Sid data, @Nonnull WriteContext ctx) {
+ XConnectLocalSidRequest request = new XConnectLocalSidRequest(getFutureJVpp());
+ Preconditions.checkNotNull(data.getEndDx4(), "EndDx4 data cannot be null.");
+ Preconditions.checkNotNull(data.getEndDx4().getPaths(), "EndDx4 paths cannot be null.");
+ Preconditions.checkNotNull(data.getEndDx4().getPaths().getPath(), "EndDx4 list of paths cannot be null.");
+ Optional<Path> firstPathOptional = data.getEndDx4().getPaths().getPath().stream().findFirst();
+ Preconditions
+ .checkArgument(firstPathOptional.isPresent(), "Failed to map data: {} for request: {}", data, request);
+ request.setOutgoingInterfaceIndex(
+ getInterfaceIndex(ctx.getMappingContext(), firstPathOptional.get().getInterface()));
+ request.setNextHopAddress(new IpAddress(firstPathOptional.get().getNextHop()));
+ request.setFunction(getBehaviourFunctionType());
+ return request;
+ }
+
+ @Nonnull
+ @Override
+ public Class<? extends Srv6EndpointType> getHandledFunctionType() {
+ return EndDX4.class;
+ }
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/EndDX6FunctionBinder.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/EndDX6FunctionBinder.java
new file mode 100644
index 000000000..71194fbd4
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/EndDX6FunctionBinder.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.util.function.xconnect;
+
+import com.google.common.base.Preconditions;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.srv6.write.sid.request.XConnectLocalSidRequest;
+import io.fd.honeycomb.translate.write.WriteContext;
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import java.util.Optional;
+import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.multi.paths.v6.paths.Path;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6._static.cfg.Sid;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndDX6;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.Srv6EndpointType;
+
+public class EndDX6FunctionBinder extends XConnectFunctionBinder {
+
+ public EndDX6FunctionBinder(@Nonnull FutureJVppCore api, @Nonnull NamingContext interfaceContext) {
+ super(api, interfaceContext);
+ }
+
+ @Nonnull
+ @Override
+ public XConnectLocalSidRequest createWriteRequestAndBind(@Nonnull Sid data, @Nonnull WriteContext ctx) {
+ XConnectLocalSidRequest request = new XConnectLocalSidRequest(getFutureJVpp());
+ Preconditions.checkNotNull(data.getEndDx6(), "EndDx6 data cannot be null.");
+ Preconditions.checkNotNull(data.getEndDx6().getPaths(), "EndDx6 paths cannot be null.");
+ Preconditions.checkNotNull(data.getEndDx6().getPaths().getPath(), "EndDx6 list of paths cannot be null.");
+ Optional<Path> firstPathOptional = data.getEndDx6().getPaths().getPath().stream().findFirst();
+ Preconditions
+ .checkArgument(firstPathOptional.isPresent(), "Failed to map data: {} for request: {}", data, request);
+ request.setOutgoingInterfaceIndex(
+ getInterfaceIndex(ctx.getMappingContext(), firstPathOptional.get().getInterface()));
+ request.setNextHopAddress(new IpAddress(firstPathOptional.get().getNextHop()));
+ request.setFunction(getBehaviourFunctionType());
+ return request;
+ }
+
+ @Nonnull
+ @Override
+ public Class<? extends Srv6EndpointType> getHandledFunctionType() {
+ return EndDX6.class;
+ }
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/EndXFunctionBinder.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/EndXFunctionBinder.java
new file mode 100644
index 000000000..0b3af395c
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/EndXFunctionBinder.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.util.function.xconnect;
+
+import com.google.common.base.Preconditions;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.srv6.write.sid.request.XConnectLocalSidRequest;
+import io.fd.honeycomb.translate.write.WriteContext;
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import java.util.Optional;
+import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.multi.paths.v6.paths.Path;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6._static.cfg.Sid;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.Srv6EndpointType;
+
+public class EndXFunctionBinder extends XConnectFunctionBinder {
+
+ public EndXFunctionBinder(@Nonnull FutureJVppCore api, @Nonnull NamingContext interfaceContext) {
+ super(api, interfaceContext);
+ }
+
+ @Nonnull
+ @Override
+ public XConnectLocalSidRequest createWriteRequestAndBind(@Nonnull Sid data,
+ @Nonnull WriteContext ctx) {
+ XConnectLocalSidRequest request = new XConnectLocalSidRequest(getFutureJVpp());
+ Preconditions.checkNotNull(data.getEndX(), "EndX data cannot be null.");
+ Preconditions.checkNotNull(data.getEndX().getPaths(), "EndX paths cannot be null.");
+ Preconditions.checkNotNull(data.getEndX().getPaths().getPath(), "EndX list of paths cannot be null.");
+ Optional<Path> firstPathOptional = data.getEndX().getPaths().getPath().stream().findFirst();
+ Preconditions
+ .checkArgument(firstPathOptional.isPresent(), "Failed to map data: {} for request: {}", data, request);
+
+ request.setOutgoingInterfaceIndex(
+ getInterfaceIndex(ctx.getMappingContext(), firstPathOptional.get().getInterface()));
+ request.setNextHopAddress(new IpAddress(firstPathOptional.get().getNextHop()));
+ request.setFunction(getBehaviourFunctionType());
+ return request;
+ }
+
+ @Nonnull
+ @Override
+ public Class<? extends Srv6EndpointType> getHandledFunctionType() {
+ return org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndX.class;
+ }
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/XConnectFunctionBinder.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/XConnectFunctionBinder.java
new file mode 100644
index 000000000..9f69c9041
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/XConnectFunctionBinder.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.util.function.xconnect;
+
+import static com.google.common.base.Preconditions.checkState;
+import static java.lang.String.format;
+
+import com.google.common.collect.ImmutableMap;
+import io.fd.hc2vpp.common.translate.util.AddressTranslator;
+import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.srv6.util.function.LocalSidFunctionBinder;
+import io.fd.hc2vpp.srv6.write.sid.request.XConnectLocalSidRequest;
+import io.fd.honeycomb.translate.MappingContext;
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import java.util.Map;
+import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndDX2;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndDX4;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndDX6;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndX;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.Srv6EndpointType;
+
+abstract class XConnectFunctionBinder extends FutureJVppCustomizer
+ implements LocalSidFunctionBinder<XConnectLocalSidRequest>, AddressTranslator {
+
+ private static final Map<Class<? extends Srv6EndpointType>, Integer>
+ REGISTER = ImmutableMap.of(EndX.class, 2,
+ EndDX2.class, 5,
+ EndDX4.class, 7,
+ EndDX6.class, 6);
+
+ private final NamingContext interfaceContext;
+
+ XConnectFunctionBinder(@Nonnull final FutureJVppCore api, @Nonnull final NamingContext interfaceContext) {
+ super(api);
+ this.interfaceContext = interfaceContext;
+ checkState(REGISTER.containsKey(getHandledFunctionType()), "Unsupported type of Local SID function %s",
+ getHandledFunctionType());
+ }
+
+ @Override
+ public int getBehaviourFunctionType() {
+ return REGISTER.get(getHandledFunctionType());
+ }
+
+ int getInterfaceIndex(final MappingContext ctx, final String name) {
+ return interfaceContext.getIndex(name, ctx, () -> new IllegalArgumentException(
+ format("Interface with name %s not found", name)));
+ }
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/DeleteRequest.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/DeleteRequest.java
new file mode 100644
index 000000000..bd48e25df
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/DeleteRequest.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.write;
+
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public interface DeleteRequest {
+
+ void delete(final InstanceIdentifier<?> identifier) throws WriteFailedException;
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/Srv6Customizer.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/Srv6Customizer.java
new file mode 100644
index 000000000..a9cb8405d
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/Srv6Customizer.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package io.fd.hc2vpp.srv6.write;
+
+import io.fd.honeycomb.translate.spi.write.WriterCustomizer;
+import io.fd.honeycomb.translate.write.WriteContext;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.routing.Srv6;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Srv6Customizer implements WriterCustomizer<Srv6> {
+ private static final Logger LOG = LoggerFactory.getLogger(Srv6Customizer.class);
+
+ @Override
+ public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Srv6> instanceIdentifier,
+ @Nonnull final Srv6 srv6,
+ @Nonnull final WriteContext writeContext) throws WriteFailedException {
+ LOG.debug("Writing SRV6 configuration is not supported by VPP. SRV6 is always enabled");
+ throw new WriteFailedException.CreateFailedException(instanceIdentifier, srv6,
+ new UnsupportedOperationException("Changing SRV6 configuration is not supported by VPP."));
+ }
+
+ @Override
+ public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Srv6> instanceIdentifier,
+ @Nonnull final Srv6 srv6,
+ @Nonnull final WriteContext writeContext) throws WriteFailedException {
+ LOG.debug("Deleting SRV6 configuration is not supported by VPP. SRV6 is always enabled");
+ throw new WriteFailedException.DeleteFailedException(instanceIdentifier,
+ new UnsupportedOperationException("Changing SRV6 configuration is not supported by VPP."));
+ }
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/Srv6WriterFactory.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/Srv6WriterFactory.java
new file mode 100644
index 000000000..5dea50f48
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/Srv6WriterFactory.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.write;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.inject.Inject;
+import io.fd.hc2vpp.srv6.Srv6IIds;
+import io.fd.hc2vpp.srv6.util.function.LocalSidFunctionWriteBindingRegistry;
+import io.fd.hc2vpp.srv6.write.encap.source.EncapsulationSourceCustomizer;
+import io.fd.hc2vpp.srv6.write.sid.LocatorCustomizer;
+import io.fd.hc2vpp.srv6.write.sid.SidCustomizer;
+import io.fd.honeycomb.translate.impl.write.GenericListWriter;
+import io.fd.honeycomb.translate.impl.write.GenericWriter;
+import io.fd.honeycomb.translate.write.WriterFactory;
+import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder;
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import javax.annotation.Nonnull;
+
+public class Srv6WriterFactory implements WriterFactory {
+
+ @Inject
+ private FutureJVppCore futureJVppCore;
+ @Inject
+ private LocalSidFunctionWriteBindingRegistry bindingRegistry;
+
+ @Override
+ public void init(@Nonnull final ModifiableWriterRegistryBuilder registry) {
+
+ registry.add(new GenericWriter<>(Srv6IIds.RT_SRV6, new Srv6Customizer()));
+
+ registry.subtreeAdd(ImmutableSet.of(Srv6IIds.LOC_PREFIX, Srv6IIds.LOC_FT_AUG, Srv6IIds.LOC_FT),
+ new GenericWriter<>(Srv6IIds.RT_SRV6_LOCS_LOCATOR, new LocatorCustomizer(futureJVppCore)));
+
+ registry.add(new GenericWriter<>(Srv6IIds.RT_SRV6_ENCAP, new EncapsulationSourceCustomizer(futureJVppCore)));
+
+ registry.subtreeAdd(ImmutableSet
+ .of(Srv6IIds.SID_END, Srv6IIds.SID_END_X, Srv6IIds.SID_END_X_PATHS, Srv6IIds.SID_END_X_PATHS_PATH,
+ Srv6IIds.SID_END_T, Srv6IIds.SID_END_B6, Srv6IIds.SID_END_B6ENCAP, Srv6IIds.SID_END_BM,
+ Srv6IIds.SID_END_DT4, Srv6IIds.SID_END_DT6, Srv6IIds.SID_END_DT46, Srv6IIds.SID_END_DX2,
+ Srv6IIds.SID_END_DX4, Srv6IIds.SID_END_DX6, Srv6IIds.SID_END_DX6_PATHS,
+ Srv6IIds.SID_END_DX6_PATHS_PATH, Srv6IIds.SID_END_DX4_PATHS, Srv6IIds.SID_END_DX4_PATHS_PATH,
+ Srv6IIds.SID_END_DX2_PATHS), new GenericListWriter<>(Srv6IIds.RT_SRV6_LOCS_LOC_ST_LS_SID,
+ new SidCustomizer(futureJVppCore, bindingRegistry)));
+ }
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/UpdateRequest.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/UpdateRequest.java
new file mode 100644
index 000000000..545c1d24f
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/UpdateRequest.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.write;
+
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public interface UpdateRequest {
+
+ void update(final InstanceIdentifier<?> identifier) throws WriteFailedException;
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/WriteRequest.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/WriteRequest.java
new file mode 100644
index 000000000..f083c4ab8
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/WriteRequest.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.write;
+
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public interface WriteRequest {
+
+ void write(final InstanceIdentifier<?> identifier) throws WriteFailedException;
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/encap/source/EncapsulationSourceCustomizer.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/encap/source/EncapsulationSourceCustomizer.java
new file mode 100644
index 000000000..375aad0f9
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/encap/source/EncapsulationSourceCustomizer.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.write.encap.source;
+
+import com.google.common.annotations.VisibleForTesting;
+import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer;
+import io.fd.hc2vpp.srv6.write.encap.source.request.EncapsulationSourceDeleteRequest;
+import io.fd.hc2vpp.srv6.write.encap.source.request.EncapsulationSourceWriteRequest;
+import io.fd.honeycomb.translate.spi.write.WriterCustomizer;
+import io.fd.honeycomb.translate.write.WriteContext;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.srv6.encap.Encapsulation;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class EncapsulationSourceCustomizer extends FutureJVppCustomizer implements WriterCustomizer<Encapsulation> {
+
+ public EncapsulationSourceCustomizer(@Nonnull FutureJVppCore futureJVppCore) {
+ super(futureJVppCore);
+ }
+
+ @Override
+ public void writeCurrentAttributes(@Nonnull InstanceIdentifier<Encapsulation> instanceIdentifier,
+ @Nonnull Encapsulation encapsulation, @Nonnull WriteContext writeContext)
+ throws WriteFailedException {
+ bindEncapsulationSourceWriteRequest(encapsulation).write(instanceIdentifier);
+
+ }
+
+ private EncapsulationSourceWriteRequest bindEncapsulationSourceWriteRequest(Encapsulation encapsulation) {
+ return new EncapsulationSourceWriteRequest(getFutureJVpp()).setBsid(encapsulation.getSourceAddress());
+ }
+
+ @Override
+ public void deleteCurrentAttributes(@Nonnull InstanceIdentifier<Encapsulation> instanceIdentifier,
+ @Nonnull Encapsulation encapsulation, @Nonnull WriteContext writeContext)
+ throws WriteFailedException {
+ bindEncapsulationSourceDeleteRequest().delete(instanceIdentifier);
+ }
+
+ @VisibleForTesting
+ private EncapsulationSourceDeleteRequest bindEncapsulationSourceDeleteRequest() {
+ return new EncapsulationSourceDeleteRequest(getFutureJVpp());
+ }
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/encap/source/request/EncapsulationSourceDeleteRequest.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/encap/source/request/EncapsulationSourceDeleteRequest.java
new file mode 100644
index 000000000..e8877a956
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/encap/source/request/EncapsulationSourceDeleteRequest.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.write.encap.source.request;
+
+import io.fd.hc2vpp.srv6.util.JVppRequest;
+import io.fd.hc2vpp.srv6.write.DeleteRequest;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.vpp.jvpp.core.dto.SrSetEncapSource;
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class EncapsulationSourceDeleteRequest extends JVppRequest implements DeleteRequest {
+
+ public EncapsulationSourceDeleteRequest(final FutureJVppCore api) {
+ super(api);
+ }
+
+ @Override
+ public void delete(InstanceIdentifier<?> identifier) throws WriteFailedException {
+ checkValid();
+ final SrSetEncapSource request = new SrSetEncapSource();
+ request.encapsSource = null;
+ getReplyForDelete(getApi().srSetEncapSource(request).toCompletableFuture(), identifier);
+ }
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/encap/source/request/EncapsulationSourceWriteRequest.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/encap/source/request/EncapsulationSourceWriteRequest.java
new file mode 100644
index 000000000..0ecf13108
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/encap/source/request/EncapsulationSourceWriteRequest.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.write.encap.source.request;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import io.fd.hc2vpp.srv6.util.JVppRequest;
+import io.fd.hc2vpp.srv6.write.WriteRequest;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.vpp.jvpp.core.dto.SrSetEncapSource;
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class EncapsulationSourceWriteRequest extends JVppRequest implements WriteRequest {
+
+ private Ipv6Address bsid;
+
+ public EncapsulationSourceWriteRequest(final FutureJVppCore api) {
+ super(api);
+ }
+
+ @Override
+ public void checkValid() {
+ checkNotNull(bsid, "Binding SID must be set");
+ }
+
+ public Ipv6Address getBsid() {
+ return bsid;
+ }
+
+ public EncapsulationSourceWriteRequest setBsid(final Ipv6Address bsid) {
+ this.bsid = bsid;
+ return this;
+ }
+
+ @Override
+ public void write(final InstanceIdentifier<?> identifier) throws WriteFailedException {
+ checkValid();
+ final SrSetEncapSource request = new SrSetEncapSource();
+ request.encapsSource = ipv6AddressNoZoneToArray(bsid);
+ getReplyForWrite(getApi().srSetEncapSource(request).toCompletableFuture(), identifier);
+ }
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/LocatorCustomizer.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/LocatorCustomizer.java
new file mode 100644
index 000000000..86ab3599c
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/LocatorCustomizer.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.write.sid;
+
+import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer;
+import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer;
+import io.fd.honeycomb.translate.write.WriteContext;
+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.srv6.base.rev180301.srv6.locators.locators.Locator;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.srv6.locators.locators.LocatorKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class LocatorCustomizer extends FutureJVppCustomizer implements ListWriterCustomizer<Locator, LocatorKey> {
+
+ public LocatorCustomizer(@Nonnull final FutureJVppCore futureJVppCore) {
+ super(futureJVppCore);
+ }
+
+ @Override
+ public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Locator> instanceIdentifier,
+ @Nonnull final Locator locator, @Nonnull final WriteContext writeContext) {
+ // noop
+ }
+
+ @Override
+ public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Locator> instanceIdentifier,
+ @Nonnull final Locator locator, @Nonnull final WriteContext writeContext) {
+ // noop
+ }
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/SidCustomizer.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/SidCustomizer.java
new file mode 100644
index 000000000..c63205699
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/SidCustomizer.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.write.sid;
+
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.googlecode.ipv6.IPv6NetworkMask;
+import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer;
+import io.fd.hc2vpp.fib.management.FibManagementIIds;
+import io.fd.hc2vpp.srv6.util.function.LocalSidFunctionWriteBindingRegistry;
+import io.fd.hc2vpp.srv6.write.sid.request.LocalSidFunctionRequest;
+import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer;
+import io.fd.honeycomb.translate.util.RWUtils;
+import io.fd.honeycomb.translate.write.WriteContext;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.urn.hc2vpp.params.xml.ns.yang.vpp.ietf.srv6.base.rev180613.VppSrv6FibLocatorAugment;
+import org.opendaylight.yang.gen.v1.urn.hc2vpp.params.xml.ns.yang.vpp.ietf.srv6.base.rev180613.vpp.srv6.fib.FibTable;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6._static.cfg.Sid;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6._static.cfg.SidKey;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.srv6.locators.locators.Locator;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.srv6.locators.locators.locator.Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.Table;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.TableKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+
+public class SidCustomizer extends FutureJVppCustomizer implements ListWriterCustomizer<Sid, SidKey> {
+
+ private final LocalSidFunctionWriteBindingRegistry bindingRegistry;
+
+ public SidCustomizer(@Nonnull final FutureJVppCore futureJVppCore,
+ @Nonnull final LocalSidFunctionWriteBindingRegistry bindingRegistry) {
+ super(futureJVppCore);
+ this.bindingRegistry = bindingRegistry;
+ }
+
+ Ipv6Address resolveSidAddress(@Nonnull final Prefix locPrefix, @Nonnull Sid localSid) {
+ com.googlecode.ipv6.IPv6Address ip =
+ com.googlecode.ipv6.IPv6Address.fromString(locPrefix.getAddress().getValue());
+ IPv6NetworkMask mask = IPv6NetworkMask.fromPrefixLength(locPrefix.getLength().getValue());
+ // strip function part if present
+ ip = ip.maskWithNetworkMask(mask);
+ //add new function part based on opcode
+ String locIp = ip.add(localSid.getOpcode().getValue().intValue()).toString();
+ return new Ipv6Address(locIp);
+ }
+
+ @Override
+ public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Sid> instanceIdentifier,
+ @Nonnull final Sid localSid, @Nonnull final WriteContext writeContext)
+ throws WriteFailedException {
+ InstanceIdentifier<Locator> locatorIid = RWUtils.cutId(instanceIdentifier, Locator.class);
+ Optional<Locator> locatorOpt = writeContext.readAfter(locatorIid);
+ Table vrfTable = getVrfTable(instanceIdentifier, writeContext, locatorIid, locatorOpt);
+ LocalSidFunctionRequest request = bindRequest(extractLocPrefix(instanceIdentifier, locatorOpt, localSid),
+ localSid, vrfTable.getTableId().getValue().intValue(), writeContext);
+ if (request == null) {
+ throw new WriteFailedException(instanceIdentifier,
+ String.format("Cannot create write request for %s", localSid));
+ }
+ request.write(instanceIdentifier);
+ }
+
+ private Table getVrfTable(final @Nonnull InstanceIdentifier<Sid> iid, final @Nonnull WriteContext writeContext,
+ final InstanceIdentifier<Locator> locatorIid, final Optional<Locator> locatorOpt) {
+ Preconditions.checkArgument(locatorOpt.isPresent(), "Locator: {} for SID: {} was not found.", locatorIid, iid);
+ Preconditions.checkNotNull(locatorOpt.get().getAugmentation(VppSrv6FibLocatorAugment.class),
+ "Vpp FIB table augmentation was not found for SID: {}.", iid);
+ FibTable fibTable = locatorOpt.get().getAugmentation(VppSrv6FibLocatorAugment.class).getFibTable();
+ Preconditions.checkNotNull(fibTable, "Vpp FIB table configuration was not found for SID: {}.", iid);
+ TableKey tableKey = new TableKey(fibTable.getAddressFamily(), fibTable.getTableId());
+ KeyedInstanceIdentifier<Table, TableKey> vrfIid = FibManagementIIds.FM_FIB_TABLES.child(Table.class, tableKey);
+ if (!writeContext.readAfter(vrfIid).isPresent()) {
+ throw new IllegalArgumentException(
+ String.format("VRF table: %s not found. Create table before writing SID : %s.", tableKey, iid));
+ }
+ return writeContext.readAfter(vrfIid).get();
+ }
+
+ private Prefix extractLocPrefix(final @Nonnull InstanceIdentifier<Sid> instanceIdentifier,
+ Optional<Locator> locatorOpt, final @Nonnull Sid localSid)
+ throws WriteFailedException {
+ Preconditions.checkArgument(locatorOpt.isPresent(), "Cannot read locator for sid: {}, with IId: ", localSid,
+ instanceIdentifier);
+ Locator loc = locatorOpt.get();
+ if (loc.getPrefix() == null || loc.getPrefix() == null || loc.getPrefix().getAddress() == null ||
+ loc.getPrefix().getLength() == null) {
+ throw new WriteFailedException(instanceIdentifier,
+ String.format("Cannot parse locator prefix for local sid %s", localSid));
+ }
+ return loc.getPrefix();
+ }
+
+ @Override
+ public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Sid> instanceIdentifier,
+ @Nonnull final Sid localSid, @Nonnull final WriteContext writeContext)
+ throws WriteFailedException {
+ InstanceIdentifier<Locator> locatorIid = RWUtils.cutId(instanceIdentifier, Locator.class);
+ Optional<Locator> locatorOpt = writeContext.readBefore(locatorIid);
+ Table vrfTable = getVrfTable(instanceIdentifier, writeContext, locatorIid, locatorOpt);
+ LocalSidFunctionRequest request = bindRequest(extractLocPrefix(instanceIdentifier, locatorOpt, localSid),
+ localSid, vrfTable.getTableId().getValue().intValue(), writeContext);
+
+ if (request == null) {
+ throw new WriteFailedException(instanceIdentifier,
+ String.format("Cannot create delete request for %s", localSid));
+ }
+ request.delete(instanceIdentifier);
+ }
+
+ private LocalSidFunctionRequest bindRequest(final @Nonnull Prefix locPrefix, final @Nonnull Sid localSid,
+ final int installFibId, final @Nonnull WriteContext writeContext) {
+ LocalSidFunctionRequest request = bindingRegistry.bind(localSid, writeContext);
+ Ipv6Address sidAddress = resolveSidAddress(locPrefix, localSid);
+ request.setLocalSidAddress(sidAddress);
+ request.setInstallFibTable(installFibId);
+ return request;
+ }
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/request/LocalSidFunctionRequest.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/request/LocalSidFunctionRequest.java
new file mode 100644
index 000000000..e3d64ea6c
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/request/LocalSidFunctionRequest.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.write.sid.request;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
+
+import io.fd.hc2vpp.srv6.util.JVppRequest;
+import io.fd.hc2vpp.srv6.write.DeleteRequest;
+import io.fd.hc2vpp.srv6.write.WriteRequest;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.vpp.jvpp.core.dto.SrLocalsidAddDel;
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import io.fd.vpp.jvpp.core.types.Srv6Sid;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.Srv6SidConfig;
+import org.opendaylight.yangtools.yang.binding.ChildOf;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * General template for Local SID requests
+ */
+public abstract class LocalSidFunctionRequest<O extends ChildOf<Srv6SidConfig>> extends JVppRequest
+ implements WriteRequest, DeleteRequest {
+
+ /**
+ * Local SID
+ */
+ private Ipv6Address localSidAddress;
+
+ /**
+ * FIB table where Local SID will be installed
+ */
+ private int installFibTable;
+
+ /**
+ * Function that will be used for this Local SID
+ */
+ private int function;
+
+ /**
+ * Whether this node should remove segment routing header for incoming packets
+ */
+ private boolean isPsp;
+
+ LocalSidFunctionRequest(final FutureJVppCore api) {
+ super(api);
+ //Default behaviour is PSP. END,END.T and END.X function can set USP=true -> PSP=false
+ isPsp = true;
+ }
+
+ protected void bindRequest(final SrLocalsidAddDel request) {
+ Srv6Sid srv6Sid = new Srv6Sid();
+ srv6Sid.addr = ipv6AddressNoZoneToArray(getLocalSidAddress());
+ request.localsid = srv6Sid;
+ request.behavior = (byte) getFunction();
+ request.fibTable = getInstallFibTable();
+ request.endPsp = booleanToByte(isPsp());
+ }
+
+ @Override
+ public void checkValid() {
+ checkNotNull(getLocalSidAddress(), "Sid address not set");
+ checkState(getFunction() != 0, "No behavior set");
+ }
+
+ @Override
+ public void write(final InstanceIdentifier<?> identifier) throws WriteFailedException {
+ checkValid();
+
+ final SrLocalsidAddDel request = new SrLocalsidAddDel();
+ request.isDel = 0;
+ bindRequest(request);
+
+ getReplyForWrite(getApi().srLocalsidAddDel(request).toCompletableFuture(), identifier);
+ }
+
+ @Override
+ public void delete(final InstanceIdentifier<?> identifier) throws WriteFailedException {
+ checkValid();
+
+ final SrLocalsidAddDel request = new SrLocalsidAddDel();
+ request.isDel = 1;
+ bindRequest(request);
+ getReplyForDelete(getApi().srLocalsidAddDel(request).toCompletableFuture(), identifier);
+ }
+
+ public Ipv6Address getLocalSidAddress() {
+ return localSidAddress;
+ }
+
+ public void setLocalSidAddress(final Ipv6Address localSidAddress) {
+ this.localSidAddress = localSidAddress;
+ }
+
+ public int getInstallFibTable() {
+ return installFibTable;
+ }
+
+ public void setInstallFibTable(final int installFibTable) {
+ this.installFibTable = installFibTable;
+ }
+
+ public int getFunction() {
+ return function;
+ }
+
+ public void setFunction(final int function) {
+ this.function = function;
+ }
+
+ public boolean isPsp() {
+ return isPsp;
+ }
+
+ public void setPsp(final boolean psp) {
+ isPsp = psp;
+ }
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/request/NoProtocolLocalSidRequest.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/request/NoProtocolLocalSidRequest.java
new file mode 100644
index 000000000..18630ccc2
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/request/NoProtocolLocalSidRequest.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.write.sid.request;
+
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+
+/**
+ * Local SID using End function
+ */
+public class NoProtocolLocalSidRequest extends LocalSidFunctionRequest {
+
+ public NoProtocolLocalSidRequest(final FutureJVppCore api) {
+ super(api);
+ }
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/request/TableLookupLocalSidRequest.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/request/TableLookupLocalSidRequest.java
new file mode 100644
index 000000000..4642b3349
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/request/TableLookupLocalSidRequest.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.write.sid.request;
+
+import io.fd.vpp.jvpp.core.dto.SrLocalsidAddDel;
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+
+/**
+ * Request for Local SID using table lookup functions
+ */
+public class TableLookupLocalSidRequest extends LocalSidFunctionRequest {
+
+ /**
+ * FIB table where table lookup should be performed
+ */
+ private int lookupFibTable;
+
+ public TableLookupLocalSidRequest(final FutureJVppCore api) {
+ super(api);
+ }
+
+ @Override
+ protected void bindRequest(final SrLocalsidAddDel request) {
+ super.bindRequest(request);
+ request.swIfIndex = getLookupFibTable();
+ }
+
+ public int getLookupFibTable() {
+ return lookupFibTable;
+ }
+
+ public void setLookupFibTable(final int lookupFibTable) {
+ this.lookupFibTable = lookupFibTable;
+ }
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/request/XConnectLocalSidRequest.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/request/XConnectLocalSidRequest.java
new file mode 100644
index 000000000..38208aaf1
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/request/XConnectLocalSidRequest.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.write.sid.request;
+
+import io.fd.hc2vpp.common.translate.util.AddressTranslator;
+import io.fd.vpp.jvpp.core.dto.SrLocalsidAddDel;
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+
+/**
+ * Request for Local SID that should use x-connect functions
+ */
+public class XConnectLocalSidRequest extends LocalSidFunctionRequest {
+
+ /**
+ * L2 interface that should be use for forwarding traffic
+ */
+ private int outgoingInterfaceIndex;
+
+ /**
+ * Outgoing VLan tag
+ */
+ private int vlanIndex;
+
+ /**
+ * Address of the next hop
+ */
+ private IpAddress nextHopAddress;
+
+ public XConnectLocalSidRequest(final FutureJVppCore api) {
+ super(api);
+ }
+
+ @Override
+ protected void bindRequest(final SrLocalsidAddDel request) {
+ super.bindRequest(request);
+ request.swIfIndex = getOutgoingInterfaceIndex();
+ request.vlanIndex = getVlanIndex();
+ if (getNextHopAddress() != null) {
+ if (AddressTranslator.INSTANCE.isIpv6(getNextHopAddress())) {
+ request.nhAddr6 = ipAddressToArray(getNextHopAddress());
+ } else {
+ request.nhAddr4 = ipAddressToArray(getNextHopAddress());
+
+ }
+
+ }
+ }
+
+ public int getOutgoingInterfaceIndex() {
+ return outgoingInterfaceIndex;
+ }
+
+ public void setOutgoingInterfaceIndex(final int outgoingInterfaceIndex) {
+ this.outgoingInterfaceIndex = outgoingInterfaceIndex;
+ }
+
+ public int getVlanIndex() {
+ return vlanIndex;
+ }
+
+ public void setVlanIndex(final int vlanIndex) {
+ this.vlanIndex = vlanIndex;
+ }
+
+ public IpAddress getNextHopAddress() {
+ return nextHopAddress;
+ }
+
+ public void setNextHopAddress(final IpAddress nextHopAddress) {
+ this.nextHopAddress = nextHopAddress;
+ }
+}
diff --git a/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/Srv6ModuleTest.java b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/Srv6ModuleTest.java
new file mode 100644
index 000000000..c465dfbaf
--- /dev/null
+++ b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/Srv6ModuleTest.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6;
+
+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.common.translate.util.NamingContext;
+import io.fd.hc2vpp.srv6.write.Srv6WriterFactory;
+import io.fd.hc2vpp.vpp.classifier.context.VppClassifierContextManager;
+import io.fd.honeycomb.translate.ModificationCache;
+import io.fd.honeycomb.translate.impl.write.registry.FlatWriterRegistryBuilder;
+import io.fd.honeycomb.translate.util.YangDAG;
+import io.fd.honeycomb.translate.write.WriterFactory;
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import java.util.HashSet;
+import java.util.Set;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+
+public class Srv6ModuleTest {
+
+ @Bind
+ @Named("interface-context")
+ private NamingContext interfaceContext;
+
+ @Bind
+ @Mock
+ private FutureJVppCore futureJVppCore;
+
+ @Bind
+ @Mock
+ private ModificationCache modificationCache;
+
+ @Named("honeycomb-context")
+ @Bind
+ @Mock
+ private DataBroker honeycombContext;
+
+ @Named("honeycomb-initializer")
+ @Bind
+ @Mock
+ private DataBroker honeycombInitializer;
+
+ @Named("classify-table-context")
+ @Bind
+ @Mock
+ private VppClassifierContextManager classifierContextManager;
+
+ @Inject
+ private Set<WriterFactory> writerFactories = new HashSet<>();
+
+ @Before
+ public void setUp() {
+ initMocks(this);
+ interfaceContext = new NamingContext("interfaceContext", "interfaceContext");
+ Guice.createInjector(new Srv6Module(), BoundFieldModule.of(this)).injectMembers(this);
+ }
+
+ @Test
+ public void testWriterFactories() {
+ assertThat(writerFactories, is(not(empty())));
+
+ // Test registration process (all dependencies present, topological order of writers does exist, etc.)
+ final FlatWriterRegistryBuilder registryBuilder = new FlatWriterRegistryBuilder(new YangDAG());
+ writerFactories.forEach(factory -> factory.init(registryBuilder));
+ assertNotNull(registryBuilder.build());
+ assertEquals(1, writerFactories.size());
+ assertTrue(writerFactories.iterator().next() instanceof Srv6WriterFactory);
+ }
+}
diff --git a/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/util/JvppRequestTest.java b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/util/JvppRequestTest.java
new file mode 100644
index 000000000..0bc3f6b6d
--- /dev/null
+++ b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/util/JvppRequestTest.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.util;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.inject.Inject;
+import io.fd.hc2vpp.common.test.util.FutureProducer;
+import io.fd.hc2vpp.common.test.util.NamingContextHelper;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.hc2vpp.srv6.util.function.LocalSidFunctionWriteBindingRegistry;
+import io.fd.hc2vpp.srv6.util.function.lookup.EndDT4FunctionBinder;
+import io.fd.hc2vpp.srv6.util.function.lookup.EndDT6FunctionBinder;
+import io.fd.hc2vpp.srv6.util.function.lookup.EndTFunctionBinder;
+import io.fd.hc2vpp.srv6.util.function.nofunction.EndFunctionBinder;
+import io.fd.hc2vpp.srv6.util.function.xconnect.EndDX2FunctionBinder;
+import io.fd.hc2vpp.srv6.util.function.xconnect.EndDX4FunctionBinder;
+import io.fd.hc2vpp.srv6.util.function.xconnect.EndDX6FunctionBinder;
+import io.fd.hc2vpp.srv6.util.function.xconnect.EndXFunctionBinder;
+import io.fd.honeycomb.test.tools.HoneycombTestRunner;
+import io.fd.honeycomb.test.tools.annotations.SchemaContextProvider;
+import io.fd.honeycomb.translate.MappingContext;
+import io.fd.honeycomb.translate.write.WriteContext;
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import org.junit.Before;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext;
+
+@RunWith(HoneycombTestRunner.class)
+public abstract class JvppRequestTest implements FutureProducer, NamingContextHelper {
+ protected static final LocalSidFunctionWriteBindingRegistry WRITE_REGISTRY =
+ new LocalSidFunctionWriteBindingRegistry();
+
+ @Inject
+ @Mock
+ protected static FutureJVppCore api;
+
+ @Mock
+ protected static WriteContext ctx;
+
+ @Mock
+ protected static MappingContext mappingContext;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ NamingContext interfaceContext = new NamingContext("iface", "interface-context");
+
+ EndFunctionBinder endFunctionBinder = new EndFunctionBinder(api);
+ EndTFunctionBinder endTFunctionBinder = new EndTFunctionBinder(api);
+ EndDT4FunctionBinder endDT4FunctionBinder = new EndDT4FunctionBinder(api);
+ EndDT6FunctionBinder endDT6FunctionBinder = new EndDT6FunctionBinder(api);
+ EndXFunctionBinder endXFunctionBinder = new EndXFunctionBinder(api, interfaceContext);
+ EndDX2FunctionBinder endDX2FunctionBinder = new EndDX2FunctionBinder(api, interfaceContext);
+ EndDX4FunctionBinder endDX4FunctionBinder = new EndDX4FunctionBinder(api, interfaceContext);
+ EndDX6FunctionBinder endDX6FunctionBinder = new EndDX6FunctionBinder(api, interfaceContext);
+ WRITE_REGISTRY.registerFunctionType(endFunctionBinder);
+ WRITE_REGISTRY.registerFunctionType(endTFunctionBinder);
+ WRITE_REGISTRY.registerFunctionType(endDT4FunctionBinder);
+ WRITE_REGISTRY.registerFunctionType(endDT6FunctionBinder);
+ WRITE_REGISTRY.registerFunctionType(endXFunctionBinder);
+ WRITE_REGISTRY.registerFunctionType(endDX2FunctionBinder);
+ WRITE_REGISTRY.registerFunctionType(endDX4FunctionBinder);
+ WRITE_REGISTRY.registerFunctionType(endDX6FunctionBinder);
+ init();
+ }
+
+ @SchemaContextProvider
+ public ModuleInfoBackedContext createSchemaContext() {
+ ModuleInfoBackedContext mibContext = ModuleInfoBackedContext.create();
+ mibContext.addModuleInfos(ImmutableSet.of(
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.$YangModuleInfoImpl
+ .getInstance(),
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.$YangModuleInfoImpl
+ .getInstance(),
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.$YangModuleInfoImpl
+ .getInstance(),
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.$YangModuleInfoImpl
+ .getInstance(),
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.$YangModuleInfoImpl
+ .getInstance()));
+ return mibContext;
+ }
+
+ protected abstract void init();
+}
diff --git a/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/util/function/LocalSidFunctionBindingRegistryTest.java b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/util/function/LocalSidFunctionBindingRegistryTest.java
new file mode 100644
index 000000000..66ddf48db
--- /dev/null
+++ b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/util/function/LocalSidFunctionBindingRegistryTest.java
@@ -0,0 +1,246 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.util.function;
+
+import static org.mockito.Mockito.when;
+
+import com.google.common.base.Optional;
+import io.fd.hc2vpp.fib.management.FibManagementIIds;
+import io.fd.hc2vpp.srv6.util.JvppRequestTest;
+import io.fd.hc2vpp.srv6.write.sid.request.LocalSidFunctionRequest;
+import io.fd.hc2vpp.srv6.write.sid.request.NoProtocolLocalSidRequest;
+import io.fd.hc2vpp.srv6.write.sid.request.TableLookupLocalSidRequest;
+import io.fd.hc2vpp.srv6.write.sid.request.XConnectLocalSidRequest;
+import io.fd.honeycomb.translate.read.ReadContext;
+import java.util.Collections;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.multi.paths.v6.PathsBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.multi.paths.v6.paths.PathBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6._static.cfg.Sid;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6._static.cfg.SidBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.End;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndDt4;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndDt4Builder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndDt6;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndDt6Builder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndDx2;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndDx2Builder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndDx4;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndDx4Builder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndDx6;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndDx6Builder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndT;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndTBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndX;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndXBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.PathAttrsCmn;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndDT4;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndDT6;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndDX2;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndDX4;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndDX6;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.TableId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.Ipv4;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.Ipv6;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.VniReference;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.Table;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.TableBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.TableKey;
+
+public class LocalSidFunctionBindingRegistryTest extends JvppRequestTest {
+
+ private static final Ipv6Address A = new Ipv6Address("A::101");
+ private static final Ipv6AddressNoZone A_NO_ZONE = new Ipv6AddressNoZone("a::101");
+ private static final Ipv4Address V4HOP = new Ipv4Address("0.0.1.0");
+ private static final Ipv4AddressNoZone A_V4 = new Ipv4AddressNoZone("10.0.0.1");
+ private static final String LOCAL_0 = "local0";
+ private static final TableId TABLE_ID_4 = new TableId(4L);
+ private static final TableKey TABLE_4_IPV6_KEY = new TableKey(Ipv6.class, new VniReference(TABLE_ID_4.getValue()));
+ private static final TableKey TABLE_4_IPV4_KEY = new TableKey(Ipv4.class, new VniReference(TABLE_ID_4.getValue()));
+
+ @Mock
+ private ReadContext readCtx;
+
+ @Override
+ protected void init() {
+ MockitoAnnotations.initMocks(this);
+ defineMapping(mappingContext, "local0", 1, "interface-context");
+ defineMapping(mappingContext, "vlan0", 2, "interface-context");
+ when(ctx.getMappingContext()).thenReturn(mappingContext);
+ when(readCtx.getMappingContext()).thenReturn(mappingContext);
+ when(ctx.readAfter(FibManagementIIds.FM_FIB_TABLES.child(Table.class, TABLE_4_IPV6_KEY)))
+ .thenReturn(Optional.of(
+ new TableBuilder().setTableId(TABLE_4_IPV6_KEY.getTableId()).setKey(TABLE_4_IPV6_KEY)
+ .setAddressFamily(TABLE_4_IPV6_KEY.getAddressFamily()).build()));
+ when(ctx.readAfter(FibManagementIIds.FM_FIB_TABLES.child(Table.class, TABLE_4_IPV4_KEY)))
+ .thenReturn(Optional.of(
+ new TableBuilder().setTableId(TABLE_4_IPV4_KEY.getTableId()).setKey(TABLE_4_IPV4_KEY)
+ .setAddressFamily(TABLE_4_IPV4_KEY.getAddressFamily()).build()));
+ }
+
+ @Test
+ public void testEnd() {
+ End end = new EndBuilder().build();
+ Sid localSid = new SidBuilder()
+ .setEnd(end)
+ .setEndBehaviorType(
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.End.class)
+ .build();
+ LocalSidFunctionRequest request = WRITE_REGISTRY.bind(localSid, ctx);
+ Assert.assertTrue(request instanceof NoProtocolLocalSidRequest);
+ Assert.assertEquals(1, request.getFunction());
+ }
+
+ @Test
+ public void testEndX() {
+ EndX endX = new EndXBuilder()
+ .setPaths(new PathsBuilder().setPath(Collections.singletonList(
+ new PathBuilder().setRole(PathAttrsCmn.Role.PRIMARY)
+ .setWeight(1L)
+ .setPathIndex((short) 1)
+ .setInterface(LOCAL_0)
+ .setNextHop(A)
+ .build())).build())
+ .build();
+ Sid localSid = new SidBuilder()
+ .setEndX(endX)
+ .setEndBehaviorType(
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndX.class)
+ .build();
+ LocalSidFunctionRequest request = WRITE_REGISTRY.bind(localSid, ctx);
+ Assert.assertTrue(request instanceof XConnectLocalSidRequest);
+ Assert.assertEquals(2, request.getFunction());
+ XConnectLocalSidRequest xConnectRequest = XConnectLocalSidRequest.class.cast(request);
+ Assert.assertEquals(A, xConnectRequest.getNextHopAddress().getIpv6Address());
+ Assert.assertEquals(1, xConnectRequest.getOutgoingInterfaceIndex());
+ }
+
+ @Test
+ public void testEndDX2() {
+ EndDx2 endDx2 = new EndDx2Builder().setPaths(
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.end.dx2.PathsBuilder()
+ .setInterface(LOCAL_0)
+ .build()).build();
+ Sid localSid = new SidBuilder()
+ .setEndDx2(endDx2)
+ .setEndBehaviorType(EndDX2.class)
+ .build();
+ LocalSidFunctionRequest request = WRITE_REGISTRY.bind(localSid, ctx);
+ Assert.assertTrue(request instanceof XConnectLocalSidRequest);
+ Assert.assertEquals(5, request.getFunction());
+ XConnectLocalSidRequest xConnectRequest = XConnectLocalSidRequest.class.cast(request);
+ Assert.assertNull(xConnectRequest.getNextHopAddress());
+ Assert.assertEquals(1, xConnectRequest.getOutgoingInterfaceIndex());
+ }
+
+ @Test
+ public void testEndDX6() {
+ EndDx6 endDx6 = new EndDx6Builder()
+ .setPaths(new PathsBuilder()
+ .setPath(Collections.singletonList(new PathBuilder()
+ .setNextHop(A)
+ .setInterface(LOCAL_0)
+ .build()))
+ .build())
+ .build();
+ Sid localSid = new SidBuilder()
+ .setEndDx6(endDx6)
+ .setEndBehaviorType(EndDX6.class)
+ .build();
+ LocalSidFunctionRequest request = WRITE_REGISTRY.bind(localSid, ctx);
+ Assert.assertTrue(request instanceof XConnectLocalSidRequest);
+ Assert.assertEquals(6, request.getFunction());
+ XConnectLocalSidRequest xConnectRequest = XConnectLocalSidRequest.class.cast(request);
+ Assert.assertEquals(A, xConnectRequest.getNextHopAddress().getIpv6Address());
+ Assert.assertEquals(1, xConnectRequest.getOutgoingInterfaceIndex());
+ }
+
+ @Test
+ public void testEndDX4() {
+ EndDx4 endDx4 = new EndDx4Builder()
+ .setPaths(
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.multi.paths.v4.PathsBuilder()
+ .setPath(Collections.singletonList(
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.multi.paths.v4.paths.PathBuilder()
+ .setNextHop(V4HOP)
+ .setInterface(LOCAL_0)
+ .build()))
+ .build())
+ .build();
+ Sid localSid = new SidBuilder()
+ .setEndDx4(endDx4)
+ .setEndBehaviorType(EndDX4.class)
+ .build();
+ LocalSidFunctionRequest request = WRITE_REGISTRY.bind(localSid, ctx);
+ Assert.assertTrue(request instanceof XConnectLocalSidRequest);
+ Assert.assertEquals(7, request.getFunction());
+ XConnectLocalSidRequest xConnectRequest = XConnectLocalSidRequest.class.cast(request);
+ Assert.assertEquals(V4HOP, xConnectRequest.getNextHopAddress().getIpv4Address());
+ Assert.assertEquals(1, xConnectRequest.getOutgoingInterfaceIndex());
+ }
+
+ @Test
+ public void testEndT() {
+ EndT endT = new EndTBuilder().setLookupTableIpv6(TABLE_ID_4).build();
+ Sid localSid = new SidBuilder()
+ .setEndT(endT)
+ .setEndBehaviorType(
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndT.class)
+ .build();
+ LocalSidFunctionRequest request = WRITE_REGISTRY.bind(localSid, ctx);
+ Assert.assertTrue(request instanceof TableLookupLocalSidRequest);
+ Assert.assertEquals(3, request.getFunction());
+ TableLookupLocalSidRequest tableLookupRequest = TableLookupLocalSidRequest.class.cast(request);
+ Assert.assertEquals(TABLE_ID_4.getValue().intValue(), tableLookupRequest.getLookupFibTable());
+ }
+
+ @Test
+ public void testEndDT6() {
+ EndDt6 endDt6 = new EndDt6Builder().setLookupTableIpv6(TABLE_ID_4).build();
+ Sid localSid = new SidBuilder()
+ .setEndDt6(endDt6)
+ .setEndBehaviorType(EndDT6.class)
+ .build();
+ LocalSidFunctionRequest request = WRITE_REGISTRY.bind(localSid, ctx);
+ Assert.assertTrue(request instanceof TableLookupLocalSidRequest);
+ Assert.assertEquals(8, request.getFunction());
+ TableLookupLocalSidRequest tableLookupRequest = TableLookupLocalSidRequest.class.cast(request);
+ Assert.assertEquals(TABLE_ID_4.getValue().intValue(), tableLookupRequest.getLookupFibTable());
+ }
+
+ @Test
+ public void testEndDT4() {
+ EndDt4 endDt4 = new EndDt4Builder().setLookupTableIpv4(TABLE_ID_4).build();
+ Sid localSid = new SidBuilder()
+ .setEndDt4(endDt4)
+ .setEndBehaviorType(EndDT4.class)
+ .build();
+ LocalSidFunctionRequest request = WRITE_REGISTRY.bind(localSid, ctx);
+ Assert.assertTrue(request instanceof TableLookupLocalSidRequest);
+ Assert.assertEquals(9, request.getFunction());
+ TableLookupLocalSidRequest tableLookupRequest = TableLookupLocalSidRequest.class.cast(request);
+ Assert.assertEquals(TABLE_ID_4.getValue().intValue(), tableLookupRequest.getLookupFibTable());
+ }
+}
diff --git a/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/Srv6CustomizerTest.java b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/Srv6CustomizerTest.java
new file mode 100644
index 000000000..b4f5bf9b7
--- /dev/null
+++ b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/Srv6CustomizerTest.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package io.fd.hc2vpp.srv6.write;
+
+import io.fd.hc2vpp.srv6.Srv6IIds;
+import io.fd.hc2vpp.srv6.write.sid.request.LocalSidRequestTest;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.routing.Srv6;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.routing.Srv6Builder;
+
+public class Srv6CustomizerTest extends LocalSidRequestTest {
+
+ @Test(expected = WriteFailedException.class)
+ public void writeCurrentAttributesNullTest() throws WriteFailedException {
+ Srv6Customizer customizer = new Srv6Customizer();
+ Srv6 srv6 = new Srv6Builder().setEnable(true).build();
+ customizer.writeCurrentAttributes(Srv6IIds.RT_SRV6, srv6, ctx);
+ }
+
+ @Test(expected = WriteFailedException.class)
+ public void deleteCurrentAttributesNullTest() throws WriteFailedException {
+ Srv6Customizer customizer = new Srv6Customizer();
+ Srv6 srv6 = new Srv6Builder().setEnable(true).build();
+ customizer.deleteCurrentAttributes(Srv6IIds.RT_SRV6, srv6, ctx);
+ }
+}
diff --git a/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/encap/source/EncapsulationSourceCustomizerTest.java b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/encap/source/EncapsulationSourceCustomizerTest.java
new file mode 100644
index 000000000..0daef976a
--- /dev/null
+++ b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/encap/source/EncapsulationSourceCustomizerTest.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.write.encap.source;
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import io.fd.hc2vpp.common.test.util.FutureProducer;
+import io.fd.hc2vpp.srv6.Srv6IIds;
+import io.fd.hc2vpp.srv6.util.JvppRequestTest;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.vpp.jvpp.core.dto.SrSetEncapSource;
+import io.fd.vpp.jvpp.core.dto.SrSetEncapSourceReply;
+import java.util.Arrays;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.srv6.encap.Encapsulation;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.srv6.encap.EncapsulationBuilder;
+
+public class EncapsulationSourceCustomizerTest extends JvppRequestTest implements FutureProducer {
+
+ private static final byte[] BSID_BYTES = {0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
+ private static Ipv6Address A1 = new Ipv6Address("a::1");
+ private static EncapsulationSourceCustomizer sourceCustomizer;
+ private static Encapsulation encapsulation = new EncapsulationBuilder()
+ .setIpTtlPropagation(false)
+ .setSourceAddress(A1)
+ .build();
+
+ @Captor
+ private ArgumentCaptor<SrSetEncapSource> requestCaptor;
+
+ @Override
+ protected void init() {
+ MockitoAnnotations.initMocks(this);
+ sourceCustomizer = new EncapsulationSourceCustomizer(api);
+ when(api.srSetEncapSource(requestCaptor.capture())).thenReturn(future(new SrSetEncapSourceReply()));
+ }
+
+ @Test
+ public void writeCurrentAttributesTest() throws WriteFailedException {
+ sourceCustomizer.writeCurrentAttributes(Srv6IIds.RT_SRV6_ENCAP, encapsulation, ctx);
+ verify(api, Mockito.times(1)).srSetEncapSource(requestCaptor.capture());
+ Assert.assertTrue(Arrays.equals(BSID_BYTES, requestCaptor.getValue().encapsSource));
+ }
+
+ @Test
+ public void deleteCurrentAttributesTest() throws WriteFailedException {
+ sourceCustomizer.deleteCurrentAttributes(Srv6IIds.RT_SRV6_ENCAP, encapsulation, ctx);
+ verify(api, Mockito.times(1)).srSetEncapSource(requestCaptor.capture());
+ Assert.assertNull(requestCaptor.getValue().encapsSource);
+ }
+}
diff --git a/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/encap/source/request/EncapsulationSourceRequestTest.java b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/encap/source/request/EncapsulationSourceRequestTest.java
new file mode 100644
index 000000000..442b87cdd
--- /dev/null
+++ b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/encap/source/request/EncapsulationSourceRequestTest.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.write.encap.source.request;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+
+import io.fd.hc2vpp.srv6.Srv6IIds;
+import io.fd.hc2vpp.srv6.util.JvppRequestTest;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.vpp.jvpp.core.dto.SrSetEncapSource;
+import io.fd.vpp.jvpp.core.dto.SrSetEncapSourceReply;
+import java.util.Arrays;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mockito;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
+
+public class EncapsulationSourceRequestTest extends JvppRequestTest {
+
+ private static final Ipv6Address BSID = new Ipv6Address("C1::");
+ private static final byte[] BSID_BYTES = {0, -63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+
+ @Captor
+ private ArgumentCaptor<SrSetEncapSource> requestCaptor;
+
+ @Override
+ protected void init() {
+ Mockito.when(api.srSetEncapSource(any())).thenReturn(future(new SrSetEncapSourceReply()));
+ }
+
+ @Test
+ public void testWriteInvalid() throws WriteFailedException {
+ try {
+ new EncapsulationSourceWriteRequest(api).write(Srv6IIds.RT_SRV6_ENCAP);
+ } catch (NullPointerException e) {
+ verifyNoMoreInteractions(api);
+ return;
+ }
+ Assert.fail("NullPointerException was expected");
+ }
+
+ @Test
+ public void testWriteValid() throws WriteFailedException {
+ final EncapsulationSourceWriteRequest request = new EncapsulationSourceWriteRequest(api).setBsid(BSID);
+
+ request.write(Srv6IIds.RT_SRV6_ENCAP);
+ verify(api, Mockito.times(1)).srSetEncapSource(requestCaptor.capture());
+ Assert.assertEquals(BSID, request.getBsid());
+ Assert.assertTrue(Arrays.equals(BSID_BYTES, requestCaptor.getValue().encapsSource));
+ }
+
+ @Test
+ public void testDeleteValid() throws WriteFailedException {
+ final EncapsulationSourceDeleteRequest request = new EncapsulationSourceDeleteRequest(api);
+
+ request.delete(Srv6IIds.RT_SRV6_ENCAP);
+ verify(api, Mockito.times(1)).srSetEncapSource(requestCaptor.capture());
+ Assert.assertNull(requestCaptor.getValue().encapsSource);
+ }
+}
diff --git a/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/sid/SidCustomizerTest.java b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/sid/SidCustomizerTest.java
new file mode 100644
index 000000000..ae72161e5
--- /dev/null
+++ b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/sid/SidCustomizerTest.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.write.sid;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import com.google.common.base.Optional;
+import io.fd.hc2vpp.srv6.write.sid.request.LocalSidRequestTest;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6._static.cfg.Sid;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6._static.cfg.SidBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.srv6.locators.locators.locator.Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.srv6.locators.locators.locator.PrefixBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.End;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.Srv6LocatorLen;
+
+public class SidCustomizerTest extends LocalSidRequestTest {
+
+ private static final Ipv6Address IP_ADDRESS = new Ipv6Address("a::101");
+
+ @Before
+ public void setup() {
+ when(ctx.readAfter(any())).thenReturn(Optional.of(LOCATOR));
+ when(ctx.readBefore(any())).thenReturn(Optional.of(LOCATOR));
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void writeCurrentAttributesNullTest() throws WriteFailedException {
+ SidCustomizer customizer = new SidCustomizer(api, WRITE_REGISTRY);
+ Sid localSid = getSidNull();
+ customizer.writeCurrentAttributes(SID_A_101, localSid, ctx);
+ verify(api, times(0)).srLocalsidAddDel(any());
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void deleteCurrentAttributesNullTest() throws WriteFailedException {
+ SidCustomizer customizer = new SidCustomizer(api, WRITE_REGISTRY);
+ Sid localSid = getSidNull();
+ customizer.deleteCurrentAttributes(SID_A_101, localSid, ctx);
+ verify(api, times(0)).srLocalsidAddDel(any());
+ }
+
+ @Test
+ public void resolveSidAddressTest() {
+ Sid localSid = getSidNull();
+ SidCustomizer customizer = new SidCustomizer(api, WRITE_REGISTRY);
+ Prefix locPrefix = new PrefixBuilder().setAddress(new Ipv6Address("a::")).setLength(new Srv6LocatorLen(
+ (short) 64)).build();
+ Ipv6Address ipv6Address = customizer.resolveSidAddress(locPrefix, localSid);
+ assertTrue((IP_ADDRESS.equals(ipv6Address)));
+ }
+
+ private Sid getSidNull() {
+ return new SidBuilder()
+ .setOpcode(OPCODE_A_101)
+ .setEndBehaviorType(End.class)
+ .setEnd(null)
+ .build();
+ }
+}
diff --git a/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/sid/request/LocalSidRequestTest.java b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/sid/request/LocalSidRequestTest.java
new file mode 100644
index 000000000..80cf47aa0
--- /dev/null
+++ b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/sid/request/LocalSidRequestTest.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.write.sid.request;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+import io.fd.hc2vpp.common.translate.util.AddressTranslator;
+import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
+import io.fd.hc2vpp.srv6.Srv6IIds;
+import io.fd.hc2vpp.srv6.util.JvppRequestTest;
+import io.fd.vpp.jvpp.core.dto.SrLocalsidAddDel;
+import io.fd.vpp.jvpp.core.dto.SrLocalsidAddDelReply;
+import java.util.Arrays;
+import org.junit.Assert;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.Locator1;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.routing.srv6.locators.locator.Static;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.routing.srv6.locators.locator._static.LocalSids;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6._static.cfg.Sid;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6._static.cfg.SidKey;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.srv6.locators.locators.Locator;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.srv6.locators.locators.LocatorBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.srv6.locators.locators.LocatorKey;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.srv6.locators.locators.locator.PrefixBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.Srv6FuncOpcodeUnreserved;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.Srv6LocatorLen;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public abstract class LocalSidRequestTest extends JvppRequestTest {
+
+ protected static final Srv6FuncOpcodeUnreserved OPCODE_A_101 =
+ new Srv6FuncOpcodeUnreserved(257L); // 101 in hex format for IPv6
+ protected static final InstanceIdentifier<Sid> SID_A_101 =
+ Srv6IIds.RT_SRV6_LOCATORS.child(Locator.class, new LocatorKey("a::")).augmentation(Locator1.class)
+ .child(Static.class).child(LocalSids.class).child(Sid.class, new SidKey(OPCODE_A_101));
+ static final byte[] SID_BYTES = {0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+ static final Ipv6Address SID = new Ipv6Address("A::0");
+ protected static Locator LOCATOR = new LocatorBuilder().setName("a::").setPrefix(
+ new PrefixBuilder().setLength(new Srv6LocatorLen((short) 64)).setAddress(new Ipv6Address("a::")).build())
+ .build();
+
+ @Captor
+ ArgumentCaptor<SrLocalsidAddDel> requestcaptor;
+
+ static void assertIsCreate(final SrLocalsidAddDel request) {
+ assertEquals(0, request.isDel);
+ }
+
+ static void assertIsDelete(final SrLocalsidAddDel request) {
+ assertEquals(1, request.isDel);
+ }
+
+ static void assertBaseFields(final SrLocalsidAddDel request, final byte[] localSidAddress,
+ final int installFibTable, final int segmentRoutingBehavior,
+ final int isDecapsulationEnabled) {
+ assertEquals(installFibTable, request.fibTable);
+ assertEquals(isDecapsulationEnabled, request.endPsp);
+ assertEquals(segmentRoutingBehavior, request.behavior);
+ assertTrue(Arrays.equals(localSidAddress, request.localsid.addr));
+ }
+
+ public static void assertRequestEqual(SrLocalsidAddDel srLocalsidAddDel, int behaviour, boolean isWrite,
+ String localSid) {
+ //PSP is true whe USP is false and vice versa
+ Assert.assertFalse(!ByteDataTranslator.INSTANCE.byteToBoolean(srLocalsidAddDel.endPsp));
+ Assert.assertEquals(behaviour, (int) srLocalsidAddDel.behavior);
+ Assert.assertEquals(isWrite, !ByteDataTranslator.INSTANCE.byteToBoolean(srLocalsidAddDel.isDel));
+ IpAddress ipAddress = AddressTranslator.INSTANCE.arrayToIpAddress(true, srLocalsidAddDel.localsid.addr);
+ Assert.assertEquals(localSid.toLowerCase(), ipAddress.getIpv6Address().getValue().toLowerCase());
+ }
+
+ @Override
+ protected void init() {
+ when(api.srLocalsidAddDel(any())).thenReturn(future(new SrLocalsidAddDelReply()));
+ }
+}
diff --git a/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/sid/request/NoProtocolLocalSidRequestTest.java b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/sid/request/NoProtocolLocalSidRequestTest.java
new file mode 100644
index 000000000..a53fc09ba
--- /dev/null
+++ b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/sid/request/NoProtocolLocalSidRequestTest.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.write.sid.request;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import io.fd.hc2vpp.srv6.Srv6IIds;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.vpp.jvpp.core.dto.SrLocalsidAddDel;
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
+
+public class NoProtocolLocalSidRequestTest extends LocalSidRequestTest {
+
+ private static final int END_VALUE = 1;
+
+ private static void assertRequestBody(final SrLocalsidAddDel jvppRequest) {
+ assertNull(jvppRequest.nhAddr6);
+ assertNull(jvppRequest.nhAddr4);
+ assertEquals(0, jvppRequest.vlanIndex);
+ assertEquals(0, jvppRequest.swIfIndex);
+ }
+
+ private static NoProtocolLocalSidRequest createValidRequest(final FutureJVppCore api) {
+ final NoProtocolLocalSidRequest request = new NoProtocolLocalSidRequest(api);
+ request.setLocalSidAddress(new Ipv6Address("A::0"));
+ request.setFunction(END_VALUE);
+ request.setInstallFibTable(0);
+ return request;
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testNoAddress() throws WriteFailedException {
+ final NoProtocolLocalSidRequest request = new NoProtocolLocalSidRequest(api);
+ request.write(Srv6IIds.RT_SRV6_LOCS_LOC_ST_LS_SID);
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void testNoBehavior() throws WriteFailedException {
+ final NoProtocolLocalSidRequest request = new NoProtocolLocalSidRequest(api);
+ request.setLocalSidAddress(SID);
+ request.write(Srv6IIds.RT_SRV6_LOCS_LOC_ST_LS_SID);
+ }
+
+ @Test
+ public void testWriteValid() throws WriteFailedException {
+ createValidRequest(api).write(Srv6IIds.RT_SRV6_LOCS_LOC_ST_LS_SID);
+ verify(api, times(1)).srLocalsidAddDel(requestcaptor.capture());
+ final SrLocalsidAddDel jvppRequest = requestcaptor.getValue();
+ assertIsCreate(jvppRequest);
+ assertRequestBody(jvppRequest);
+ }
+
+ @Test
+ public void testDeleteValid() throws WriteFailedException {
+ createValidRequest(api).delete(Srv6IIds.RT_SRV6_LOCS_LOC_ST_LS_SID);
+ verify(api, times(1)).srLocalsidAddDel(requestcaptor.capture());
+ final SrLocalsidAddDel jvppRequest = requestcaptor.getValue();
+ assertIsDelete(jvppRequest);
+ assertBaseFields(jvppRequest, SID_BYTES, 0, END_VALUE, 1);
+ assertRequestBody(jvppRequest);
+ }
+}
diff --git a/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/sid/request/TableLookupLocalSidRequestTest.java b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/sid/request/TableLookupLocalSidRequestTest.java
new file mode 100644
index 000000000..0cedec73b
--- /dev/null
+++ b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/sid/request/TableLookupLocalSidRequestTest.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.write.sid.request;
+
+import static io.fd.vpp.jvpp.Assertions.assertEquals;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import io.fd.hc2vpp.srv6.Srv6IIds;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.vpp.jvpp.core.dto.SrLocalsidAddDel;
+import org.junit.Test;
+
+public class TableLookupLocalSidRequestTest extends LocalSidRequestTest {
+
+ private static final int END_T_VALUE = 3;
+
+ @Test(expected = NullPointerException.class)
+ public void testNoAddress() throws WriteFailedException {
+ final TableLookupLocalSidRequest request = new TableLookupLocalSidRequest(api);
+ request.write(Srv6IIds.RT_SRV6_LOCS_LOC_ST_LS_SID);
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void testNoBehavior() throws WriteFailedException {
+ final TableLookupLocalSidRequest request = new TableLookupLocalSidRequest(api);
+ request.setLocalSidAddress(SID);
+ request.write(Srv6IIds.RT_SRV6_LOCS_LOC_ST_LS_SID);
+ }
+
+ @Test
+ public void testWriteValid() throws WriteFailedException {
+ createValidRequest().write(Srv6IIds.RT_SRV6_LOCS_LOC_ST_LS_SID);
+ verify(api, times(1)).srLocalsidAddDel(requestcaptor.capture());
+ final SrLocalsidAddDel jvppRequest = requestcaptor.getValue();
+
+ assertIsCreate(jvppRequest);
+ assertBaseFields(jvppRequest, SID_BYTES, 0, END_T_VALUE, 1);
+ assertEquals(7, jvppRequest.swIfIndex);
+ }
+
+ @Test
+ public void testDeleteValid() throws WriteFailedException {
+ createValidRequest().delete(Srv6IIds.RT_SRV6_LOCS_LOC_ST_LS_SID);
+ verify(api, times(1)).srLocalsidAddDel(requestcaptor.capture());
+ final SrLocalsidAddDel jvppRequest = requestcaptor.getValue();
+
+ assertIsDelete(jvppRequest);
+ assertBaseFields(jvppRequest, SID_BYTES, 0, END_T_VALUE, 1);
+ assertEquals(7, jvppRequest.swIfIndex);
+ }
+
+ private TableLookupLocalSidRequest createValidRequest() {
+ final TableLookupLocalSidRequest request = new TableLookupLocalSidRequest(api);
+ request.setLookupFibTable(7);
+ request.setInstallFibTable(0);
+ request.setLocalSidAddress(SID);
+ request.setFunction(END_T_VALUE);
+ return request;
+ }
+
+}
diff --git a/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/sid/request/XConnectLocalSidRequestTest.java b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/sid/request/XConnectLocalSidRequestTest.java
new file mode 100644
index 000000000..970295001
--- /dev/null
+++ b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/sid/request/XConnectLocalSidRequestTest.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2018 Bell Canada, Pantheon Technologies and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.srv6.write.sid.request;
+
+import static io.fd.vpp.jvpp.Assertions.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import io.fd.hc2vpp.srv6.Srv6IIds;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.vpp.jvpp.core.dto.SrLocalsidAddDel;
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import java.util.Arrays;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
+
+public class XConnectLocalSidRequestTest extends LocalSidRequestTest {
+
+ private static final IpAddress NEXT_HOP_ADDRESS = new IpAddress(new Ipv6Address("B::0"));
+ private static final byte[] NEXT_HOP_ADDRESS_BYTES = new byte[]{0, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+ private static final int END_DX6_VALUE = 6;
+
+ private static XConnectLocalSidRequest createValidRequest(final FutureJVppCore api) {
+ final XConnectLocalSidRequest request = new XConnectLocalSidRequest(api);
+ request.setLocalSidAddress(SID);
+ request.setNextHopAddress(NEXT_HOP_ADDRESS);
+ request.setOutgoingInterfaceIndex(7);
+ request.setVlanIndex(4);
+ request.setInstallFibTable(0);
+ request.setFunction(END_DX6_VALUE);
+ return request;
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testNoAddress() throws WriteFailedException {
+ final XConnectLocalSidRequest request = new XConnectLocalSidRequest(api);
+ request.write(Srv6IIds.RT_SRV6_LOCS_LOC_ST_LS_SID);
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void testNoBehavior() throws WriteFailedException {
+ final XConnectLocalSidRequest request = new XConnectLocalSidRequest(api);
+ request.setLocalSidAddress(SID);
+ request.write(Srv6IIds.RT_SRV6_LOCS_LOC_ST_LS_SID);
+ }
+
+ @Test
+ public void testWriteValid() throws WriteFailedException {
+ createValidRequest(api).write(Srv6IIds.RT_SRV6_LOCS_LOC_ST_LS_SID);
+ verify(api, times(1)).srLocalsidAddDel(requestcaptor.capture());
+
+ final SrLocalsidAddDel jvppRequest = requestcaptor.getValue();
+
+ assertIsCreate(jvppRequest);
+ assertBaseFields(jvppRequest, SID_BYTES, 0, END_DX6_VALUE, 1);
+ assertEquals(7, jvppRequest.swIfIndex);
+ assertEquals(4, jvppRequest.vlanIndex);
+ assertTrue(Arrays.equals(NEXT_HOP_ADDRESS_BYTES, jvppRequest.nhAddr6));
+ }
+
+ @Test
+ public void testDeleteValid() throws WriteFailedException {
+ createValidRequest(api).delete(Srv6IIds.RT_SRV6_LOCS_LOC_ST_LS_SID);
+ verify(api, times(1)).srLocalsidAddDel(requestcaptor.capture());
+
+ final SrLocalsidAddDel jvppRequest = requestcaptor.getValue();
+
+ assertIsDelete(jvppRequest);
+ assertBaseFields(jvppRequest, SID_BYTES, 0, END_DX6_VALUE, 1);
+ assertEquals(7, jvppRequest.swIfIndex);
+ assertEquals(4, jvppRequest.vlanIndex);
+ assertTrue(Arrays.equals(NEXT_HOP_ADDRESS_BYTES, jvppRequest.nhAddr6));
+ }
+}