summaryrefslogtreecommitdiffstats
path: root/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util
diff options
context:
space:
mode:
authorMichal Cmarada <michal.cmarada@pantheon.tech>2018-06-15 13:12:53 +0200
committerMarek Gradzki <mgradzki@cisco.com>2018-06-19 18:56:53 +0000
commitb77a5725338dc700873b36c98af85d70acd7bbe4 (patch)
tree6006938757b2f3ac28eabc90eff821b3290f50af /srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util
parenta0884f2792c31a3a93fb1654ceea754b6c612920 (diff)
HC2VPP-304 - add SRv6 policy module
new models: - hc2vpp-oc-srte-policy@2017-09-18.yang (ietf draft for srte-policies) - vpp-oc-srte-policy@2018-05-14.yang (augments oc-srte-policy model with VPP specific configuration) - policy-context@2018-06-07.yang defines policy contexts for policies and candidate paths new features: - adds support for writing/reading SRv6 policies - adds support for writing/reading L2 steering - adds support for writing/reading L3 steering - implements support for FIB table management (HC2VPP-345) Change-Id: Ie83ac8ecdcc0e46086e1ecdaecbb811746151c2f Signed-off-by: Michal Cmarada <michal.cmarada@pantheon.tech>
Diffstat (limited to 'srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util')
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/CandidatePathContextManager.java61
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/CandidatePathContextManagerImpl.java112
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/NoopCustomizer.java46
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/PolicyContextManager.java68
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/PolicyContextManagerImpl.java108
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/Srv6Util.java99
-rw-r--r--srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/EndDX2FunctionBinder.java2
7 files changed, 496 insertions, 0 deletions
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/CandidatePathContextManager.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/CandidatePathContextManager.java
new file mode 100644
index 000000000..d0b6479be
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/CandidatePathContextManager.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;
+
+import io.fd.honeycomb.translate.MappingContext;
+import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.http.cisco.com.ns.yang.oc.srte.policy.rev170918.ProvisioningMethodType;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.policy.context.rev180607.srv6.candidate.path.context.attributes.srv6.candidate.path.mappings.Srv6CandidatePathMapping;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
+
+/**
+ * Manages metadata for SRv6 policy plugin
+ */
+public interface CandidatePathContextManager {
+ /**
+ * Creates metadata for candidate path. Existing mapping is overwritten if exists.
+ *
+ * @param bsid candidate path bsid
+ * @param name candidate path name
+ * @param provisioningMethod candidate path provisioning method
+ * @param preference candidate path preference
+ * @param distinguisher candidate path distinguisher
+ * @param ctx mapping context providing context data for current transaction
+ */
+ void addCandidatePath(@Nonnull Ipv6Address bsid, @Nonnull final String name,
+ @Nonnull final Class<? extends ProvisioningMethodType> provisioningMethod,
+ @Nonnull Long preference, @Nonnull Long distinguisher, @Nonnull final MappingContext ctx);
+
+ /**
+ * Retrieves candidate path for given name. If not present it will generate artificial mapping
+ *
+ * @param bsid candidate path BSID
+ * @param ctx mapping context providing context data for current transaction
+ * @return candidate path matching supplied candidate path BSID if present, artificial mapping otherwise
+ */
+ @Nonnull
+ Srv6CandidatePathMapping getCandidatePath(@Nonnull final Ipv6Address bsid, @Nonnull final MappingContext ctx);
+
+ /**
+ * Removes candidate path metadata from current context.
+ *
+ * @param bsid candidate path BSID
+ * @param ctx mapping context providing context data for current transaction
+ */
+ void removeCandidatePath(@Nonnull final Ipv6Address bsid, @Nonnull final MappingContext ctx);
+
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/CandidatePathContextManagerImpl.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/CandidatePathContextManagerImpl.java
new file mode 100644
index 000000000..15fb5c0ff
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/CandidatePathContextManagerImpl.java
@@ -0,0 +1,112 @@
+/*
+ * 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.base.Optional;
+import io.fd.honeycomb.translate.MappingContext;
+import java.util.concurrent.atomic.AtomicLong;
+import javax.annotation.Nonnull;
+import javax.annotation.concurrent.ThreadSafe;
+import org.opendaylight.yang.gen.v1.http.cisco.com.ns.yang.oc.srte.policy.rev170918.ProvisioningMethodConfig;
+import org.opendaylight.yang.gen.v1.http.cisco.com.ns.yang.oc.srte.policy.rev170918.ProvisioningMethodType;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.Contexts;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.policy.context.rev180607.Srv6PolicyContextAugmentation;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.policy.context.rev180607.srv6.candidate.path.context.attributes.Srv6CandidatePathMappings;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.policy.context.rev180607.srv6.candidate.path.context.attributes.srv6.candidate.path.mappings.Srv6CandidatePathMapping;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.policy.context.rev180607.srv6.candidate.path.context.attributes.srv6.candidate.path.mappings.Srv6CandidatePathMappingBuilder;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.policy.context.rev180607.srv6.candidate.path.context.attributes.srv6.candidate.path.mappings.Srv6CandidatePathMappingKey;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+
+/**
+ * Facade on top of {@link MappingContext} that manages {@link Srv6CandidatePathMappings}.
+ */
+@ThreadSafe
+public class CandidatePathContextManagerImpl implements CandidatePathContextManager {
+
+ private static final long DEFAULT_PREFERENCE = 100L;
+ private AtomicLong distinguisher;
+
+ private final InstanceIdentifier<Srv6CandidatePathMappings> ctxIid;
+
+ public CandidatePathContextManagerImpl() {
+ this.ctxIid = InstanceIdentifier.create(Contexts.class)
+ .augmentation(Srv6PolicyContextAugmentation.class)
+ .child(Srv6CandidatePathMappings.class);
+ distinguisher = new AtomicLong(0L);
+ }
+
+ @Override
+ public void addCandidatePath(@Nonnull Ipv6Address bsid, @Nonnull final String name,
+ @Nonnull final Class<? extends ProvisioningMethodType> provisioningMethod,
+ @Nonnull Long preference, @Nonnull Long distinguisher,
+ @Nonnull final MappingContext ctx) {
+ final KeyedInstanceIdentifier<Srv6CandidatePathMapping, Srv6CandidatePathMappingKey> mappingIid =
+ getCandidatePathIid(bsid);
+ final Srv6CandidatePathMappingBuilder builder =
+ new Srv6CandidatePathMappingBuilder().setKey(new Srv6CandidatePathMappingKey(bsid))
+ .setProvisioningMethod(provisioningMethod).setPreference(preference)
+ .setDistinguisher(distinguisher).setBsid(bsid).setName(name);
+ ctx.put(mappingIid, builder.build());
+ }
+
+ private KeyedInstanceIdentifier<Srv6CandidatePathMapping, Srv6CandidatePathMappingKey> getCandidatePathIid(
+ final Ipv6Address bsid) {
+ return ctxIid.child(Srv6CandidatePathMapping.class, new Srv6CandidatePathMappingKey(bsid));
+ }
+
+ @Override
+ @Nonnull
+ public synchronized Srv6CandidatePathMapping getCandidatePath(@Nonnull final Ipv6Address bsid,
+ @Nonnull final MappingContext ctx) {
+ final Optional<Srv6CandidatePathMappings> read = ctx.read(ctxIid);
+ if (read.isPresent()) {
+ java.util.Optional<Srv6CandidatePathMapping> mappingOpt = read.get().getSrv6CandidatePathMapping().stream()
+ .filter(srv6CandidatePathMapping -> srv6CandidatePathMapping.getBsid().getValue()
+ .equals(bsid.getValue())).findAny();
+ if (mappingOpt.isPresent()) {
+ return mappingOpt.get();
+ }
+ }
+ return getArtificialMapping(bsid, ctx, bsid.getValue());
+ }
+
+ private Srv6CandidatePathMapping getArtificialMapping(final @Nonnull Ipv6Address bsid,
+ final @Nonnull MappingContext ctx, final String name) {
+ // if not present we need to generate artificial mapping
+ // for given policy only one candidate path can be selected and be configured on the device.
+ Srv6CandidatePathMapping mapping =
+ new Srv6CandidatePathMappingBuilder()
+ .setProvisioningMethod(ProvisioningMethodConfig.class)
+ .setBsid(bsid) //when we read name from VPP it is always the BSID value
+ .setPreference(DEFAULT_PREFERENCE)
+ .setDistinguisher(distinguisher.incrementAndGet())
+ .build();
+ addCandidatePath(mapping.getBsid(), name, mapping.getProvisioningMethod(), mapping.getPreference(),
+ mapping.getDistinguisher(), ctx);
+ return mapping;
+ }
+
+ @Override
+ public void removeCandidatePath(@Nonnull final Ipv6Address bsid, @Nonnull final MappingContext ctx) {
+ final KeyedInstanceIdentifier<Srv6CandidatePathMapping, Srv6CandidatePathMappingKey> mappingIid =
+ getCandidatePathIid(bsid);
+ ctx.delete(mappingIid);
+ }
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/NoopCustomizer.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/NoopCustomizer.java
new file mode 100644
index 000000000..dd0f2615e
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/NoopCustomizer.java
@@ -0,0 +1,46 @@
+/*
+ * 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.honeycomb.translate.spi.write.WriterCustomizer;
+import io.fd.honeycomb.translate.write.WriteContext;
+import javax.annotation.Nonnull;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NoopCustomizer<T extends DataObject> implements WriterCustomizer<T> {
+
+ private static final Logger LOG = LoggerFactory.getLogger(NoopCustomizer.class);
+
+ public NoopCustomizer() {
+ super();
+ }
+
+ @Override
+ public void writeCurrentAttributes(@Nonnull InstanceIdentifier<T> instanceIdentifier, @Nonnull T data,
+ @Nonnull WriteContext writeContext) {
+ LOG.trace("Noop write called for IId: {}, data: {}", instanceIdentifier, data);
+ }
+
+ @Override
+ public void deleteCurrentAttributes(@Nonnull InstanceIdentifier<T> instanceIdentifier, @Nonnull T data,
+ @Nonnull WriteContext writeContext) {
+ LOG.trace("Noop delete called for IId: {}, data: {}", instanceIdentifier, data);
+ }
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/PolicyContextManager.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/PolicyContextManager.java
new file mode 100644
index 000000000..3a07fe024
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/PolicyContextManager.java
@@ -0,0 +1,68 @@
+/*
+ * 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.honeycomb.translate.MappingContext;
+import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.policy.context.rev180607.srv6.policy.context.attributes.srv6.policy.mappings.Srv6PolicyMapping;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
+
+/**
+ * Manages metadata for SRv6 policy plugin
+ */
+public interface PolicyContextManager {
+ /**
+ * Creates metadata for policy. Existing mapping is overwritten if exists.
+ *
+ * @param name policy name
+ * @param color policy color
+ * @param endpoint policy endpoint
+ * @param bsid policy bsid
+ * @param ctx mapping context providing context data for current transaction
+ */
+ void addPolicy(@Nonnull final String name, @Nonnull Long color, @Nonnull Ipv6Address endpoint,
+ @Nonnull Ipv6Address bsid, @Nonnull final MappingContext ctx);
+
+ /**
+ * Retrieves policy for given policy BSID. If not present it wil generate artificial mapping
+ *
+ * @param bsid policy BSID
+ * @param ctx mapping context providing context data for current transaction
+ * @return policy matching supplied policy BSID if present, or artificial mapping if not
+ */
+ @Nonnull
+ Srv6PolicyMapping getPolicy(@Nonnull final Ipv6Address bsid, @Nonnull final MappingContext ctx);
+
+ /**
+ * Retrieves policy BSID for given policy color and endpoint.
+ *
+ * @param color policy color
+ * @param endpoint policy endpoint
+ * @param ctx mapping context providing context data for current transaction
+ * @return policy BSID matching supplied policy color and endpoint if present, null otherwise
+ */
+ Ipv6Address getPolicyBsid(@Nonnull Long color, @Nonnull Ipv6Address endpoint, @Nonnull final MappingContext ctx);
+
+ /**
+ * Removes policy metadata from current context.
+ *
+ * @param bsid policy BSID
+ * @param ctx mapping context providing context data for current transaction
+ */
+ void removePolicy(@Nonnull final Ipv6Address bsid, @Nonnull final MappingContext ctx);
+
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/PolicyContextManagerImpl.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/PolicyContextManagerImpl.java
new file mode 100644
index 000000000..1997043e2
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/PolicyContextManagerImpl.java
@@ -0,0 +1,108 @@
+/*
+ * 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.base.Optional;
+import io.fd.honeycomb.translate.MappingContext;
+import javax.annotation.Nonnull;
+import javax.annotation.concurrent.ThreadSafe;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.naming.context.rev160513.Contexts;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.policy.context.rev180607.Srv6PolicyContextAugmentation;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.policy.context.rev180607.srv6.policy.context.attributes.Srv6PolicyMappings;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.policy.context.rev180607.srv6.policy.context.attributes.srv6.policy.mappings.Srv6PolicyMapping;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.policy.context.rev180607.srv6.policy.context.attributes.srv6.policy.mappings.Srv6PolicyMappingBuilder;
+import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.policy.context.rev180607.srv6.policy.context.attributes.srv6.policy.mappings.Srv6PolicyMappingKey;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+
+/**
+ * Facade on top of {@link MappingContext} that manages {@link Srv6PolicyMappings}.
+ */
+@ThreadSafe
+public class PolicyContextManagerImpl implements PolicyContextManager {
+
+ private final InstanceIdentifier<Srv6PolicyMappings> ctxIid;
+ // 2001:db8::/32 This address range is used for documentation and example source code. We can use it as dummy
+ // addresses for our artificial policies
+ private static final String DUMMY_EP = "2001:db8::";
+ private Long artificialColor;
+
+ public PolicyContextManagerImpl() {
+ this.ctxIid = InstanceIdentifier.create(Contexts.class)
+ .augmentation(Srv6PolicyContextAugmentation.class)
+ .child(Srv6PolicyMappings.class);
+ this.artificialColor = 0L;
+ }
+
+ @Override
+ public void addPolicy(@Nonnull final String name, @Nonnull final Long color, @Nonnull final Ipv6Address endpoint,
+ @Nonnull final Ipv6Address bsid, @Nonnull final MappingContext ctx) {
+ final KeyedInstanceIdentifier<Srv6PolicyMapping, Srv6PolicyMappingKey> mappingIid = getPolicyIid(bsid);
+ final Srv6PolicyMappingBuilder builder =
+ new Srv6PolicyMappingBuilder().setKey(new Srv6PolicyMappingKey(bsid)).setColor(color)
+ .setEndpoint(endpoint).setBsid(bsid).setName(name);
+ ctx.put(mappingIid, builder.build());
+ }
+
+ private KeyedInstanceIdentifier<Srv6PolicyMapping, Srv6PolicyMappingKey> getPolicyIid(final Ipv6Address bsid) {
+ return ctxIid.child(Srv6PolicyMapping.class, new Srv6PolicyMappingKey(bsid));
+ }
+
+ @Nonnull
+ public synchronized Srv6PolicyMapping getPolicy(@Nonnull final Ipv6Address bsid,
+ @Nonnull final MappingContext ctx) {
+ final Optional<Srv6PolicyMapping> read = ctx.read(getPolicyIid(bsid));
+ if (read.isPresent()) {
+ return read.get();
+ }
+
+ //if not present we need to generate artificial mapping
+ Long nextArtificialColor = getNextArtificialColor();
+ Ipv6Address endpoint = new Ipv6Address(DUMMY_EP + nextArtificialColor);
+ Srv6PolicyMapping mapping =
+ new Srv6PolicyMappingBuilder().setBsid(bsid).setColor(nextArtificialColor).setEndpoint(endpoint)
+ .setName(bsid.getValue()).build();
+ addPolicy(mapping.getName(), mapping.getColor(), mapping.getEndpoint(), mapping.getBsid(), ctx);
+ return mapping;
+ }
+
+ @Override
+ public Ipv6Address getPolicyBsid(@Nonnull Long color, @Nonnull Ipv6Address endpoint,
+ @Nonnull final MappingContext ctx) {
+ Optional<Srv6PolicyMappings> read = ctx.read(ctxIid);
+ if (read.isPresent()) {
+ return read.get().getSrv6PolicyMapping().stream()
+ .filter(srv6PolicyMapping -> srv6PolicyMapping.getColor().equals(color) &&
+ srv6PolicyMapping.getEndpoint().equals(endpoint))
+ .map(Srv6PolicyMapping::getBsid).findFirst().orElse(null);
+ }
+ return null;
+ }
+
+ @Override
+ public void removePolicy(@Nonnull final Ipv6Address bsid, @Nonnull final MappingContext ctx) {
+ final KeyedInstanceIdentifier<Srv6PolicyMapping, Srv6PolicyMappingKey> mappingIid = getPolicyIid(bsid);
+ ctx.delete(mappingIid);
+ }
+
+ private synchronized Long getNextArtificialColor() {
+ artificialColor++;
+ return artificialColor;
+ }
+}
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/Srv6Util.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/Srv6Util.java
new file mode 100644
index 000000000..ea308efcf
--- /dev/null
+++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/Srv6Util.java
@@ -0,0 +1,99 @@
+/*
+ * 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.base.Optional;
+import io.fd.honeycomb.translate.util.RWUtils;
+import io.fd.honeycomb.translate.write.WriteContext;
+import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.http.cisco.com.ns.yang.oc.srte.policy.rev170918.DataplaneType;
+import org.opendaylight.yang.gen.v1.http.cisco.com.ns.yang.oc.srte.policy.rev170918.policies.policies.Policy;
+import org.opendaylight.yang.gen.v1.urn.hc2vpp.params.xml.ns.yang.vpp.oc.srte.policy.rev180514.VppSrPolicyAugmentation;
+import org.opendaylight.yang.gen.v1.urn.hc2vpp.params.xml.ns.yang.vpp.oc.srte.policy.rev180514.segment.routing.traffic.engineering.policies.policy.VppSrPolicy;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public final class Srv6Util {
+
+ /**
+ * Constructs unique name for candidate path based on binding sid and weight
+ *
+ * @param bsid binding sid associated with candidate path
+ * @param weight weight of actual sidList
+ * @return candidate path name
+ */
+ public static String getCandidatePathName(final Ipv6Address bsid, final long weight) {
+ return bsid.getValue() + "-" + weight;
+ }
+
+ /**
+ * Extracts BSID from policy, based on read/write operation it uses dataBefore/dataAfter while reading config
+ *
+ * @param instanceIdentifier identifier used to extract path of policy
+ * @param writeContext used to store any useful information later utilized by customizers
+ * @param isWrite condition whether this is a write or delete operation
+ * @return BSID in form of IPv6 address or null if not resolved
+ */
+ public static <T extends DataObject> Ipv6Address extractBsid(
+ final @Nonnull InstanceIdentifier<T> instanceIdentifier, final @Nonnull WriteContext writeContext,
+ boolean isWrite) {
+ Optional<Policy> policyOptional = isWrite
+ ? writeContext.readAfter(RWUtils.cutId(instanceIdentifier, Policy.class))
+ : writeContext.readBefore(RWUtils.cutId(instanceIdentifier, Policy.class));
+
+ if (policyOptional.isPresent() && policyOptional.get().getBindingSid() != null &&
+ policyOptional.get().getBindingSid().getConfig() != null) {
+ org.opendaylight.yang.gen.v1.http.cisco.com.ns.yang.oc.srte.policy.rev170918.binding.sid.properties.binding.sid.Config
+ config = policyOptional.get().getBindingSid().getConfig();
+ if (config.getType() == DataplaneType.Srv6 && config.getValue() != null &&
+ config.getValue().getIpAddress() != null &&
+ config.getValue().getIpAddress().getIpv6Address() != null) {
+ return config.getValue().getIpAddress().getIpv6Address();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Extracts VRF FIB from Policy.
+ *
+ * @param instanceIdentifier identifier used to extract path of policy
+ * @param writeContext used to store any useful information later utilized by customizers
+ * @param isWrite condition whether this is a write or delete operation
+ * @return VRF FIB id when resolved, default VRF FIB (0) otherwise
+ */
+ public static <T extends DataObject> int extractVrfFib(final @Nonnull InstanceIdentifier<T> instanceIdentifier,
+ final @Nonnull WriteContext writeContext, boolean isWrite) {
+ Optional<Policy> policyOptional = isWrite
+ ? writeContext.readAfter(RWUtils.cutId(instanceIdentifier, Policy.class))
+ : writeContext.readBefore(RWUtils.cutId(instanceIdentifier, Policy.class));
+
+ if (policyOptional.isPresent() && policyOptional.get().getAugmentation(VppSrPolicyAugmentation.class) != null &&
+ policyOptional.get().getAugmentation(VppSrPolicyAugmentation.class).getVppSrPolicy() != null) {
+
+ VppSrPolicy vppSrPolicy =
+ policyOptional.get().getAugmentation(VppSrPolicyAugmentation.class).getVppSrPolicy();
+ if (vppSrPolicy.getConfig() != null && vppSrPolicy.getConfig().getTableId() != null) {
+ return vppSrPolicy.getConfig().getTableId().getValue().intValue();
+ }
+ }
+ // returning default Vrf Fib table
+ return 0;
+ }
+}
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
index 551a211dd..5321bffcf 100644
--- 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
@@ -52,6 +52,8 @@ public class EndDX2FunctionBinder extends XConnectFunctionBinder {
"Failed to map data: {} for request: {}", data, request);
request.setOutgoingInterfaceIndex(getInterfaceIndex(ctx.getMappingContext(), outInterface));
request.setFunction(getBehaviourFunctionType());
+ // TODO (HC2VPP-357): check model for ENDDX2V support, when added we can set the VLAN index
+ // request.setVlanIndex(getVLanIndex(ctx.getMappingContext(), ));
return request;
}