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 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv4.unicast.routing.rev170917.routing.routing.instance.routing.protocols.routing.protocol._static.routes.ipv4.route.VppIpv4Route;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv4.unicast.routing.rev170917.routing.routing.instance.routing.protocols.routing.protocol._static.routes.ipv4.route.next.hop.options.next.hop.list.next.hop.list.NextHop;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv6.unicast.routing.rev170917.routing.routing.instance.routing.protocols.routing.protocol._static.routes.ipv6.route.VppIpv6Route;
33 import javax.annotation.Nonnull;
37 * Factory for creating requests to create route with multiple hops
39 public class MultipathHopRequestFactory extends BasicHopRequestFactory implements RouteRequestProducer {
41 private MultipathHopRequestFactory(final VppClassifierContextManager classifierContextManager,
42 final NamingContext interfaceContext,
43 final NamingContext routingProtocolContext) {
44 super(classifierContextManager, interfaceContext, routingProtocolContext);
47 public static MultipathHopRequestFactory forContexts(
48 @Nonnull final VppClassifierContextManager classifierContextManager,
49 @Nonnull final NamingContext interfaceContext,
50 @Nonnull final NamingContext routingProtocolContext) {
51 return new MultipathHopRequestFactory(classifierContextManager, interfaceContext, routingProtocolContext);
54 public IpAddDelRoute createIpv4MultipathHopRequest(final boolean add,
55 @Nonnull final String parentProtocolName,
56 @Nonnull final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv4.unicast.routing.rev170917.routing.routing.instance.routing.protocols.routing.protocol._static.routes.ipv4.Route route,
57 @Nonnull final NextHop hop,
58 @Nonnull final MappingContext mappingContext) {
59 final VppIpv4Route routingAttributes = route.getVppIpv4Route();
61 final int nextHopInterfaceIndex =
62 getInterfaceNamingContext().getIndex(hop.getOutgoingInterface(), mappingContext);
64 if (routingAttributes != null && classifyTablePresent(routingAttributes.getClassifyTable(), getVppClassifierContextManager(),
66 return getMultipathHopRequest(add,
67 route.getDestinationPrefix(),
68 nextHopInterfaceIndex,
70 toByte(hop.getWeight()),
71 getRoutingProtocolContext().getIndex(parentProtocolName, mappingContext),
73 classifyTableIndex(routingAttributes.getClassifyTable(), getVppClassifierContextManager(),
77 return getMultipathHopRequest(add,
78 route.getDestinationPrefix(),
79 nextHopInterfaceIndex,
81 toByte(hop.getWeight()),
82 getRoutingProtocolContext().getIndex(parentProtocolName, mappingContext),
89 public IpAddDelRoute createIpv6MultipathHopRequest(final boolean add,
90 @Nonnull final String parentProtocolName,
91 @Nonnull final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv6.unicast.routing.rev170917.routing.routing.instance.routing.protocols.routing.protocol._static.routes.ipv6.Route route,
92 @Nonnull final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ipv6.unicast.routing.rev170917.routing.routing.instance.routing.protocols.routing.protocol._static.routes.ipv6.route.next.hop.options.next.hop.list.next.hop.list.NextHop hop,
93 @Nonnull final MappingContext mappingContext) {
94 final VppIpv6Route routingAttributes = route.getVppIpv6Route();
96 final int nextHopInterfaceIndex =
97 getInterfaceNamingContext().getIndex(hop.getOutgoingInterface(), mappingContext);
99 if (routingAttributes != null && classifyTablePresent(routingAttributes.getClassifyTable(), getVppClassifierContextManager(),
101 return getMultipathHopRequest(add,
102 route.getDestinationPrefix(),
103 nextHopInterfaceIndex,
105 toByte(hop.getWeight()),
106 getRoutingProtocolContext().getIndex(parentProtocolName, mappingContext),
108 classifyTableIndex(routingAttributes.getClassifyTable(), getVppClassifierContextManager(),
112 return getMultipathHopRequest(add,
113 route.getDestinationPrefix(),
114 nextHopInterfaceIndex,
116 toByte(hop.getWeight()),
117 getRoutingProtocolContext().getIndex(parentProtocolName, mappingContext),
125 private IpAddDelRoute getMultipathHopRequest(final boolean isAdd, @Nonnull final Ipv6Prefix destinationAddress,
126 final int nextHopInterfaceIndex,
127 @Nonnull final Ipv6Address nextHopAddress,
128 final byte nextHopWeight,
129 final int primaryVrf, final int secondaryVrf,
130 final int classifyTableIndex, final boolean classifyIndexSet) {
131 return flaglessAddDelRouteRequest(booleanToByte(isAdd), nextHopInterfaceIndex,
132 ipv6AddressNoZoneToArray(nextHopAddress), nextHopWeight, toByte(1),
133 ipv6AddressPrefixToArray(destinationAddress), extractPrefix(destinationAddress.getValue()), toByte(1),
134 primaryVrf, secondaryVrf, classifyTableIndex,
135 booleanToByte(classifyIndexSet));
138 private IpAddDelRoute getMultipathHopRequest(final boolean isAdd, @Nonnull final Ipv4Prefix destinationAddress,
139 final int nextHopInterfaceIndex,
140 @Nonnull final Ipv4Address nextHopAddress,
141 final byte nextHopWeight,
142 final int primaryVrf, final int secondaryVrf,
143 final int classifyTableIndex, final boolean classifyIndexSet) {
144 return flaglessAddDelRouteRequest(booleanToByte(isAdd), nextHopInterfaceIndex,
145 ipv4AddressNoZoneToArray(nextHopAddress.getValue()), nextHopWeight, toByte(0),
146 ipv4AddressPrefixToArray(destinationAddress), extractPrefix(destinationAddress.getValue()), toByte(1),
147 primaryVrf, secondaryVrf, classifyTableIndex,
148 booleanToByte(classifyIndexSet));