diff options
Diffstat (limited to 'routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory')
5 files changed, 506 insertions, 0 deletions
diff --git a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/MultipathHopRequestFactory.java b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/MultipathHopRequestFactory.java new file mode 100644 index 000000000..4599c8b82 --- /dev/null +++ b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/MultipathHopRequestFactory.java @@ -0,0 +1,154 @@ +/* + * 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.common.translate.util.NamingContext; +import io.fd.hc2vpp.routing.write.factory.base.BasicHopRequestFactory; +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.Ipv4Address; +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.Ipv6Address; +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.ipv4.unicast.routing.rev140524.routing.routing.instance.routing.protocols.routing.protocol._static.routes.ipv4.route.VppIpv4Route; +import 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.next.hop.options.next.hop.list.next.hop.list.NextHop; +import 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.VppIpv6Route; + + +/** + * Factory for creating requests to create route with multiple hops + */ +public class MultipathHopRequestFactory extends BasicHopRequestFactory implements RouteRequestProducer { + + private MultipathHopRequestFactory(final VppClassifierContextManager classifierContextManager, + final NamingContext interfaceContext, + final NamingContext routingProtocolContext) { + super(classifierContextManager, interfaceContext, routingProtocolContext); + } + + public static MultipathHopRequestFactory forContexts( + @Nonnull final VppClassifierContextManager classifierContextManager, + @Nonnull final NamingContext interfaceContext, + @Nonnull final NamingContext routingProtocolContext) { + return new MultipathHopRequestFactory(classifierContextManager, interfaceContext, routingProtocolContext); + } + + public IpAddDelRoute createIpv4MultipathHopRequest(final boolean add, + @Nonnull final String parentProtocolName, + @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 NextHop hop, + @Nonnull final MappingContext mappingContext) { + + final VppIpv4Route routingAttributes = checkNotNull(route.getVppIpv4Route(), "VppIpv4Route not defined"); + + final int nextHopInterfaceIndex = + getInterfaceNamingContext().getIndex(hop.getOutgoingInterface(), mappingContext); + + if (classifyTablePresent(routingAttributes.getClassifyTable(), getVppClassifierContextManager(), + mappingContext)) { + return getMultipathHopRequest(add, + route.getDestinationPrefix(), + nextHopInterfaceIndex, + hop.getAddress(), + toByte(hop.getWeight()), + getRoutingProtocolContext().getIndex(parentProtocolName, mappingContext), + optionalVni(routingAttributes.getSecondaryVrf()), + classifyTableIndex(routingAttributes.getClassifyTable(), getVppClassifierContextManager(), + mappingContext), + true); + } else { + return getMultipathHopRequest(add, + route.getDestinationPrefix(), + nextHopInterfaceIndex, + hop.getAddress(), + toByte(hop.getWeight()), + getRoutingProtocolContext().getIndex(parentProtocolName, mappingContext), + optionalVni(routingAttributes.getSecondaryVrf()), + 0, + false); + } + } + + public IpAddDelRoute createIpv6MultipathHopRequest(final boolean add, + @Nonnull final String parentProtocolName, + @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 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.next.hop.options.next.hop.list.next.hop.list.NextHop hop, + @Nonnull final MappingContext mappingContext) { + final VppIpv6Route routingAttributes = checkNotNull(route.getVppIpv6Route(), "VppIpv6Route not defined"); + + final int nextHopInterfaceIndex = + getInterfaceNamingContext().getIndex(hop.getOutgoingInterface(), mappingContext); + + if (classifyTablePresent(routingAttributes.getClassifyTable(), getVppClassifierContextManager(), + mappingContext)) { + return getMultipathHopRequest(add, + route.getDestinationPrefix(), + nextHopInterfaceIndex, + hop.getAddress(), + toByte(hop.getWeight()), + getRoutingProtocolContext().getIndex(parentProtocolName, mappingContext), + optionalVni(routingAttributes.getSecondaryVrf()), + classifyTableIndex(routingAttributes.getClassifyTable(), getVppClassifierContextManager(), + mappingContext), + true); + } else { + return getMultipathHopRequest(add, + route.getDestinationPrefix(), + nextHopInterfaceIndex, + hop.getAddress(), + toByte(hop.getWeight()), + getRoutingProtocolContext().getIndex(parentProtocolName, mappingContext), + optionalVni(routingAttributes.getSecondaryVrf()), + 0, + false); + } + } + + + private IpAddDelRoute getMultipathHopRequest(final boolean isAdd, @Nonnull final Ipv6Prefix destinationAddress, + final int nextHopInterfaceIndex, + @Nonnull final Ipv6Address nextHopAddress, + final byte nextHopWeight, + final int primaryVrf, final int secondaryVrf, + final int classifyTableIndex, final boolean classifyIndexSet) { + return flaglessAddDelRouteRequest(booleanToByte(isAdd), nextHopInterfaceIndex, + ipv6AddressNoZoneToArray(nextHopAddress.getValue()), nextHopWeight, toByte(1), + ipv6AddressPrefixToArray(destinationAddress), extractPrefix(destinationAddress.getValue()), toByte(1), + primaryVrf, secondaryVrf, classifyTableIndex, + booleanToByte(classifyIndexSet)); + } + + private IpAddDelRoute getMultipathHopRequest(final boolean isAdd, @Nonnull final Ipv4Prefix destinationAddress, + final int nextHopInterfaceIndex, + @Nonnull final Ipv4Address nextHopAddress, + final byte nextHopWeight, + final int primaryVrf, final int secondaryVrf, + final int classifyTableIndex, final boolean classifyIndexSet) { + return flaglessAddDelRouteRequest(booleanToByte(isAdd), nextHopInterfaceIndex, + ipv4AddressNoZoneToArray(nextHopAddress.getValue()), nextHopWeight, toByte(0), + ipv4AddressPrefixToArray(destinationAddress), extractPrefix(destinationAddress.getValue()), toByte(1), + primaryVrf, secondaryVrf, classifyTableIndex, + booleanToByte(classifyIndexSet)); + } + + +} diff --git a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/SimpleHopRequestFactory.java b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/SimpleHopRequestFactory.java new file mode 100644 index 000000000..68a5f3d71 --- /dev/null +++ b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/SimpleHopRequestFactory.java @@ -0,0 +1,145 @@ +/* + * 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.common.translate.util.NamingContext; +import io.fd.hc2vpp.routing.write.factory.base.BasicHopRequestFactory; +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.Ipv4Address; +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.Ipv6Address; +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.ipv4.unicast.routing.rev140524.routing.routing.instance.routing.protocols.routing.protocol._static.routes.ipv4.route.VppIpv4Route; +import 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.next.hop.options.SimpleNextHop; +import 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.VppIpv6Route; + + +/** + * Factory for creating requests to create route with hop simple hop + */ +public class SimpleHopRequestFactory extends BasicHopRequestFactory implements RouteRequestProducer { + + private SimpleHopRequestFactory(final VppClassifierContextManager classifierContextManager, + final NamingContext interfaceContext, + final NamingContext routingProtocolContext) { + super(classifierContextManager, interfaceContext, routingProtocolContext); + } + + public static SimpleHopRequestFactory forContexts( + @Nonnull final VppClassifierContextManager classifierContextManager, + @Nonnull final NamingContext interfaceContext, + @Nonnull final NamingContext routingProtocolContext) { + return new SimpleHopRequestFactory(classifierContextManager, interfaceContext, routingProtocolContext); + } + + public IpAddDelRoute createIpv4SimpleHopRequest(final boolean add, + @Nonnull final String parentProtocolName, + @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) { + + final SimpleNextHop hop = SimpleNextHop.class.cast(route.getNextHopOptions()); + final VppIpv4Route routingAttributes = checkNotNull(route.getVppIpv4Route(), "VppIpv4Route not defined"); + final int nextHopInterfaceIndex = + getInterfaceNamingContext().getIndex(hop.getOutgoingInterface(), mappingContext); + + if (classifyTablePresent(routingAttributes.getClassifyTable(), getVppClassifierContextManager(), + mappingContext)) { + return getSimpleHopRequest(add, + route.getDestinationPrefix(), + nextHopInterfaceIndex, + hop.getNextHop(), + getRoutingProtocolContext().getIndex(parentProtocolName, mappingContext), + optionalVni(routingAttributes.getSecondaryVrf()), + classifyTableIndex(routingAttributes.getClassifyTable(), getVppClassifierContextManager(), + mappingContext), + true); + } else { + return getSimpleHopRequest(add, + route.getDestinationPrefix(), + nextHopInterfaceIndex, + hop.getNextHop(), + getRoutingProtocolContext().getIndex(parentProtocolName, mappingContext), + optionalVni(routingAttributes.getSecondaryVrf()), + 0, + false); + } + } + + public IpAddDelRoute createIpv6SimpleHopRequest(final boolean add, + @Nonnull final String parentProtocolName, + @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) { + 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.next.hop.options.SimpleNextHop + hop = + (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.next.hop.options.SimpleNextHop) route + .getNextHopOptions(); + final VppIpv6Route routingAttributes = checkNotNull(route.getVppIpv6Route(), "VppIpv6Route not defined"); + final int nextHopInterfaceIndex = + getInterfaceNamingContext().getIndex(hop.getOutgoingInterface(), mappingContext); + + if (classifyTablePresent(routingAttributes.getClassifyTable(), getVppClassifierContextManager(), + mappingContext)) { + return getSimpleHopRequest(add, + route.getDestinationPrefix(), + nextHopInterfaceIndex, + hop.getNextHop(), + getRoutingProtocolContext().getIndex(parentProtocolName, mappingContext), + optionalVni(routingAttributes.getSecondaryVrf()), + classifyTableIndex(routingAttributes.getClassifyTable(), getVppClassifierContextManager(), + mappingContext), + true); + } else { + return getSimpleHopRequest(add, + route.getDestinationPrefix(), + nextHopInterfaceIndex, + hop.getNextHop(), + getRoutingProtocolContext().getIndex(parentProtocolName, mappingContext), + optionalVni(routingAttributes.getSecondaryVrf()), + 0, + false); + } + } + + + private IpAddDelRoute getSimpleHopRequest(final boolean isAdd, @Nonnull final Ipv6Prefix destinationAddress, + final int nextHopInterfaceIndex, + @Nonnull final Ipv6Address nextHopAddress, + final int primaryVrf, final int secondaryVrf, + final int classifyTableIndex, final boolean classifyIndexSet) { + return flaglessAddDelRouteRequest(booleanToByte(isAdd), nextHopInterfaceIndex, + ipv6AddressNoZoneToArray(nextHopAddress.getValue()), DEFAULT_HOP_WEIGHT, BYTE_TRUE, + ipv6AddressPrefixToArray(destinationAddress), extractPrefix(destinationAddress.getValue()), BYTE_FALSE, + primaryVrf, secondaryVrf, classifyTableIndex, booleanToByte(classifyIndexSet)); + } + + private IpAddDelRoute getSimpleHopRequest(final boolean isAdd, @Nonnull final Ipv4Prefix destinationAddress, + final int nextHopInterfaceIndex, + @Nonnull final Ipv4Address nextHopAddress, + final int primaryVrf, final int secondaryVrf, + final int classifyTableIndex, final boolean classifyIndexSet) { + return flaglessAddDelRouteRequest(booleanToByte(isAdd), nextHopInterfaceIndex, + ipv4AddressNoZoneToArray(nextHopAddress.getValue()), DEFAULT_HOP_WEIGHT, BYTE_FALSE, + ipv4AddressPrefixToArray(destinationAddress), extractPrefix(destinationAddress.getValue()), BYTE_FALSE, + primaryVrf, secondaryVrf, classifyTableIndex, booleanToByte(classifyIndexSet)); + } +} 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; + } +} diff --git a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/base/BasicHopRequestFactory.java b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/base/BasicHopRequestFactory.java new file mode 100644 index 000000000..abaf0fa84 --- /dev/null +++ b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/base/BasicHopRequestFactory.java @@ -0,0 +1,49 @@ +/* + * 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.base; + +import static com.google.common.base.Preconditions.checkNotNull; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.vppclassifier.VppClassifierContextManager; +import javax.annotation.Nonnull; + +/** + * Extension to {@code ClassifierContextHolder} to hold also {@code NamingContext} + */ +public abstract class BasicHopRequestFactory extends ClassifierContextHolder { + + private final NamingContext interfaceNamingContext; + private final NamingContext routingProtocolContext; + + protected BasicHopRequestFactory( + @Nonnull final VppClassifierContextManager classifierContextManager, + @Nonnull final NamingContext interfaceContext, + @Nonnull final NamingContext routingProtocolContext) { + super(classifierContextManager); + this.interfaceNamingContext = checkNotNull(interfaceContext, "Interface context cannot be null"); + this.routingProtocolContext = checkNotNull(routingProtocolContext, "Routing protocol context cannot be null"); + } + + protected NamingContext getInterfaceNamingContext() { + return interfaceNamingContext; + } + + protected NamingContext getRoutingProtocolContext() { + return routingProtocolContext; + } +} diff --git a/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/base/ClassifierContextHolder.java b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/base/ClassifierContextHolder.java new file mode 100644 index 000000000..0b11a9b3b --- /dev/null +++ b/routing/routing-impl/src/main/java/io/fd/hc2vpp/routing/write/factory/base/ClassifierContextHolder.java @@ -0,0 +1,38 @@ +/* + * 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.base; + +import static com.google.common.base.Preconditions.checkNotNull; + +import io.fd.hc2vpp.v3po.vppclassifier.VppClassifierContextManager; +import javax.annotation.Nonnull; + +/** + * Holds reference for + */ +public abstract class ClassifierContextHolder { + + private final VppClassifierContextManager classifierContextManager; + + protected ClassifierContextHolder(@Nonnull final VppClassifierContextManager classifierContextManager) { + this.classifierContextManager = checkNotNull(classifierContextManager, "Classifier context cannot be null"); + } + + protected VppClassifierContextManager getVppClassifierContextManager() { + return this.classifierContextManager; + } +} |