summaryrefslogtreecommitdiffstats
path: root/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/SpecialNextHopRequestFactory.java
diff options
context:
space:
mode:
Diffstat (limited to 'routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/SpecialNextHopRequestFactory.java')
-rw-r--r--routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/SpecialNextHopRequestFactory.java120
1 files changed, 120 insertions, 0 deletions
diff --git a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/SpecialNextHopRequestFactory.java b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/SpecialNextHopRequestFactory.java
new file mode 100644
index 000000000..2a5ab9821
--- /dev/null
+++ b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/SpecialNextHopRequestFactory.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.routing.write.factory;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import io.fd.hc2vpp.routing.write.factory.base.ClassifierContextHolder;
+import io.fd.hc2vpp.routing.write.trait.RouteRequestProducer;
+import io.fd.hc2vpp.v3po.vppclassifier.VppClassifierContextManager;
+import io.fd.honeycomb.translate.MappingContext;
+import io.fd.vpp.jvpp.core.dto.IpAddDelRoute;
+import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.SpecialNextHopGrouping;
+
+public class SpecialNextHopRequestFactory extends ClassifierContextHolder
+ implements RouteRequestProducer {
+
+ private SpecialNextHopRequestFactory(final VppClassifierContextManager classifierContextManager) {
+ super(classifierContextManager);
+ }
+
+ public static SpecialNextHopRequestFactory forClassifierContext(
+ @Nonnull final VppClassifierContextManager classifierContextManager) {
+ return new SpecialNextHopRequestFactory(classifierContextManager);
+ }
+
+ public IpAddDelRoute createIpv4SpecialHopRequest(final boolean add,
+ @Nonnull final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv4.unicast.routing.rev140524.routing.routing.instance.routing.protocols.routing.protocol._static.routes.ipv4.Route route,
+ @Nonnull final MappingContext mappingContext,
+ @Nonnull final SpecialNextHopGrouping.SpecialNextHop flagsVariant) {
+ checkNotNull(route, "Route cannot be null");
+ checkNotNull(mappingContext, "Mapping Context cannot be null");
+ checkNotNull(flagsVariant, "Flags variant cannot be null");
+
+ return resolveFlags(getSpecialHopRequest(add, route.getDestinationPrefix()), flagsVariant);
+ }
+
+ public IpAddDelRoute createIpv6SpecialHopRequest(final boolean add,
+ @Nonnull final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv6.unicast.routing.rev140525.routing.routing.instance.routing.protocols.routing.protocol._static.routes.ipv6.Route route,
+ @Nonnull final MappingContext mappingContext,
+ @Nonnull final SpecialNextHopGrouping.SpecialNextHop flagsVariant) {
+
+ checkNotNull(route, "Route cannot be null");
+ checkNotNull(mappingContext, "Mapping Context cannot be null");
+ checkNotNull(flagsVariant, "Flags variant cannot be null");
+
+ return resolveFlags(getSpecialHopRequest(add, route.getDestinationPrefix()), flagsVariant);
+ }
+
+ private IpAddDelRoute getSpecialHopRequest(final boolean isAdd, @Nonnull final Ipv6Prefix destinationAddress) {
+
+ return flaglessAddDelRouteRequest(booleanToByte(isAdd), 0, null, DEFAULT_HOP_WEIGHT, BYTE_TRUE,
+ ipv6AddressPrefixToArray(destinationAddress), extractPrefix(destinationAddress.getValue()), BYTE_FALSE,
+ DEFAULT_VNI, DEFAULT_VNI, DEFAULT_CLASSIFY_TABLE_INDEX, BYTE_FALSE);
+ }
+
+ private IpAddDelRoute getSpecialHopRequest(final boolean isAdd, @Nonnull final Ipv4Prefix destinationAddress) {
+ return flaglessAddDelRouteRequest(booleanToByte(isAdd), 0, null, DEFAULT_HOP_WEIGHT, BYTE_FALSE,
+ ipv4AddressPrefixToArray(destinationAddress), extractPrefix(destinationAddress.getValue()), BYTE_FALSE,
+ DEFAULT_VNI, DEFAULT_VNI, DEFAULT_CLASSIFY_TABLE_INDEX, BYTE_FALSE);
+ }
+
+ private IpAddDelRoute resolveFlags(IpAddDelRoute request,
+ final SpecialNextHopGrouping.SpecialNextHop flagsVariant) {
+ switch (flagsVariant) {
+ case Blackhole:
+ return resolveAsBlackholeVariant(request);
+ case Unreachable:
+ return resolveAsUnreachableVariant(request);
+ case Prohibit:
+ return resolveAsProhibitedVariant(request);
+ case Receive:
+ return resolveAsReceiveVariant(request);
+ default:
+ throw new IllegalArgumentException("Unsupported type");
+ }
+ }
+
+ private IpAddDelRoute resolveAsBlackholeVariant(IpAddDelRoute request) {
+ return bindFlags(request, true, false, false, false);
+ }
+
+ private IpAddDelRoute resolveAsReceiveVariant(IpAddDelRoute request) {
+ return bindFlags(request, false, true, false, false);
+ }
+
+ private IpAddDelRoute resolveAsUnreachableVariant(IpAddDelRoute request) {
+ return bindFlags(request, false, false, true, false);
+ }
+
+ private IpAddDelRoute resolveAsProhibitedVariant(IpAddDelRoute request) {
+ return bindFlags(request, false, false, false, true);
+ }
+
+ private IpAddDelRoute bindFlags(IpAddDelRoute request, final boolean isDrop, final boolean isReceive,
+ final boolean isUnreachable, final boolean isProhibited) {
+ request.isDrop = booleanToByte(isDrop);
+ request.isLocal = booleanToByte(isReceive);
+ request.isUnreach = booleanToByte(isUnreachable);
+ request.isProhibit = booleanToByte(isProhibited);
+
+ return request;
+ }
+}