2 * Copyright (c) 2016 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package io.fd.hc2vpp.routing.write.factory;
19 import io.fd.hc2vpp.common.translate.util.NamingContext;
20 import io.fd.hc2vpp.routing.write.factory.base.BasicHopRequestFactory;
21 import io.fd.hc2vpp.routing.write.trait.RouteRequestProducer;
22 import io.fd.hc2vpp.vpp.classifier.context.VppClassifierContextManager;
23 import io.fd.honeycomb.translate.MappingContext;
24 import io.fd.vpp.jvpp.core.dto.IpAddDelRoute;
25 import javax.annotation.Nonnull;
26 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.ipv4.unicast.routing.rev180319.VppIpv4NextHopAugmentation;
27 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.ipv4.unicast.routing.rev180319.VppIpv4RouteAttributesAugmentation;
28 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.ipv4.unicast.routing.rev180319.routing.control.plane.protocols.control.plane.protocol._static.routes.ipv4.route.VppIpv4Route;
29 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.ipv6.unicast.routing.rev180319.VppIpv6NextHopAugmentation;
30 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.ipv6.unicast.routing.rev180319.VppIpv6RouteAttributesAugmentation;
31 import org.opendaylight.yang.gen.v1.http.fd.io.hc2vpp.yang.vpp.ipv6.unicast.routing.rev180319.routing.control.plane.protocols.control.plane.protocol._static.routes.ipv6.route.VppIpv6Route;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv4.unicast.routing.rev180313.routing.control.plane.protocols.control.plane.protocol._static.routes.ipv4.Route;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv4.unicast.routing.rev180313.routing.control.plane.protocols.control.plane.protocol._static.routes.ipv4.route.next.hop.NextHop1;
38 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.next.hop.content.next.hop.options.next.hop.list.next.hop.list.NextHop;
41 * Factory for creating requests to create route with multiple hops
43 public class MultipathHopRequestFactory extends BasicHopRequestFactory implements RouteRequestProducer {
45 private MultipathHopRequestFactory(final VppClassifierContextManager classifierContextManager,
46 final NamingContext interfaceContext,
47 final NamingContext routingProtocolContext) {
48 super(classifierContextManager, interfaceContext, routingProtocolContext);
51 public static MultipathHopRequestFactory forContexts(
52 @Nonnull final VppClassifierContextManager classifierContextManager,
53 @Nonnull final NamingContext interfaceContext,
54 @Nonnull final NamingContext routingProtocolContext) {
55 return new MultipathHopRequestFactory(classifierContextManager, interfaceContext, routingProtocolContext);
58 public IpAddDelRoute createIpv4MultipathHopRequest(final boolean add,
59 @Nonnull final String parentProtocolName,
60 @Nonnull final Route route,
61 @Nonnull final NextHop hop,
62 @Nonnull final MappingContext mappingContext) {
64 final VppIpv4Route routingAttributes = route.augmentation(VppIpv4RouteAttributesAugmentation.class) != null ?
65 route.augmentation(VppIpv4RouteAttributesAugmentation.class).getVppIpv4Route() : null;
67 final int nextHopInterfaceIndex =
68 getInterfaceNamingContext().getIndex(hop.getOutgoingInterface(), mappingContext);
70 if (routingAttributes != null && classifyTablePresent(routingAttributes.getClassifyTable(), getVppClassifierContextManager(),
72 return getMultipathHopRequest(add,
73 route.getDestinationPrefix(),
74 nextHopInterfaceIndex,
75 hop.augmentation(NextHop1.class).getNextHopAddress(),
76 hop.augmentation(VppIpv4NextHopAugmentation.class).getWeight().byteValue(),
77 getRoutingProtocolContext().getIndex(parentProtocolName, mappingContext),
79 classifyTableIndex(routingAttributes.getClassifyTable(), getVppClassifierContextManager(),
83 return getMultipathHopRequest(add,
84 route.getDestinationPrefix(),
85 nextHopInterfaceIndex,
86 hop.augmentation(NextHop1.class).getNextHopAddress(),
87 hop.augmentation(VppIpv4NextHopAugmentation.class).getWeight().byteValue(),
88 getRoutingProtocolContext().getIndex(parentProtocolName, mappingContext),
95 public IpAddDelRoute createIpv6MultipathHopRequest(final boolean add,
96 @Nonnull final String parentProtocolName,
97 @Nonnull final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv6.unicast.routing.rev180313.routing.control.plane.protocols.control.plane.protocol._static.routes.ipv6.Route route,
98 @Nonnull final NextHop hop,
99 @Nonnull final MappingContext mappingContext) {
100 final VppIpv6Route routingAttributes = route.augmentation(VppIpv6RouteAttributesAugmentation.class) != null ?
101 route.augmentation(VppIpv6RouteAttributesAugmentation.class).getVppIpv6Route() : null;
103 final int nextHopInterfaceIndex =
104 getInterfaceNamingContext().getIndex(hop.getOutgoingInterface(), mappingContext);
106 if (routingAttributes != null && classifyTablePresent(routingAttributes.getClassifyTable(), getVppClassifierContextManager(),
108 return getMultipathHopRequest(add,
109 route.getDestinationPrefix(),
110 nextHopInterfaceIndex,
111 hop.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv6.unicast.routing.rev180313.routing.control.plane.protocols.control.plane.protocol._static.routes.ipv6.route.next.hop.NextHop1.class).getNextHopAddress(),
112 hop.augmentation(VppIpv6NextHopAugmentation.class).getWeight().byteValue(),
113 getRoutingProtocolContext().getIndex(parentProtocolName, mappingContext),
115 classifyTableIndex(routingAttributes.getClassifyTable(), getVppClassifierContextManager(),
119 return getMultipathHopRequest(add,
120 route.getDestinationPrefix(),
121 nextHopInterfaceIndex,
122 hop.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv6.unicast.routing.rev180313.routing.control.plane.protocols.control.plane.protocol._static.routes.ipv6.route.next.hop.NextHop1.class).getNextHopAddress(),
123 hop.augmentation(VppIpv6NextHopAugmentation.class).getWeight().byteValue(),
124 getRoutingProtocolContext().getIndex(parentProtocolName, mappingContext),
132 private IpAddDelRoute getMultipathHopRequest(final boolean isAdd, @Nonnull final Ipv6Prefix destinationAddress,
133 final int nextHopInterfaceIndex,
134 @Nonnull final Ipv6Address nextHopAddress,
135 final byte nextHopWeight,
136 final int primaryVrf, final int secondaryVrf,
137 final int classifyTableIndex, final boolean classifyIndexSet) {
138 return flaglessAddDelRouteRequest(booleanToByte(isAdd), nextHopInterfaceIndex,
139 ipv6AddressNoZoneToArray(nextHopAddress), nextHopWeight, (byte)1,
140 ipv6AddressPrefixToArray(destinationAddress), extractPrefix(destinationAddress.getValue()), (byte)1,
141 primaryVrf, secondaryVrf, classifyTableIndex,
142 booleanToByte(classifyIndexSet));
145 private IpAddDelRoute getMultipathHopRequest(final boolean isAdd, @Nonnull final Ipv4Prefix destinationAddress,
146 final int nextHopInterfaceIndex,
147 @Nonnull final Ipv4Address nextHopAddress,
148 final byte nextHopWeight,
149 final int primaryVrf, final int secondaryVrf,
150 final int classifyTableIndex, final boolean classifyIndexSet) {
151 return flaglessAddDelRouteRequest(booleanToByte(isAdd), nextHopInterfaceIndex,
152 ipv4AddressNoZoneToArray(nextHopAddress.getValue()), nextHopWeight, (byte)0,
153 ipv4AddressPrefixToArray(destinationAddress), extractPrefix(destinationAddress.getValue()), (byte)1,
154 primaryVrf, secondaryVrf, classifyTableIndex,
155 booleanToByte(classifyIndexSet));