2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.bgp.flowspec;
10 import static java.util.Objects.requireNonNull;
12 import java.util.ArrayList;
13 import java.util.List;
14 import javax.annotation.Nonnull;
15 import org.opendaylight.protocol.bgp.flowspec.handlers.FSIpv4DestinationPrefixHandler;
16 import org.opendaylight.protocol.bgp.flowspec.handlers.FSIpv4FragmentHandler;
17 import org.opendaylight.protocol.bgp.flowspec.handlers.FSIpv4SourcePrefixHandler;
18 import org.opendaylight.protocol.bgp.flowspec.handlers.FSIpv6DestinationPrefixHandler;
19 import org.opendaylight.protocol.bgp.flowspec.handlers.FSIpv6FragmentHandler;
20 import org.opendaylight.protocol.bgp.flowspec.handlers.FSIpv6SourcePrefixHandler;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.flowspec.flowspec.type.DestinationPortCase;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.flowspec.flowspec.type.DscpCase;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.flowspec.flowspec.type.FragmentCase;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.flowspec.flowspec.type.IcmpCodeCase;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.flowspec.flowspec.type.IcmpTypeCase;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.flowspec.flowspec.type.PacketLengthCase;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.flowspec.flowspec.type.PortCase;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.flowspec.flowspec.type.SourcePortCase;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.flowspec.flowspec.type.TcpFlagsCase;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.group.ipv4.flowspec.flowspec.type.DestinationPrefixCase;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.group.ipv4.flowspec.flowspec.type.ProtocolIpCase;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.group.ipv4.flowspec.flowspec.type.SourcePrefixCase;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.group.ipv6.flowspec.flowspec.type.DestinationIpv6PrefixCase;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.group.ipv6.flowspec.flowspec.type.FlowLabelCase;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.group.ipv6.flowspec.flowspec.type.NextHeaderCase;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.group.ipv6.flowspec.flowspec.type.SourceIpv6PrefixCase;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
40 public final class FlowspecActivator implements AutoCloseable {
41 private static final Logger LOG = LoggerFactory.getLogger(FlowspecActivator.class);
43 private final SimpleFlowspecExtensionProviderContext context;
44 private final List<AutoCloseable> registrations = new ArrayList<>();
46 public SimpleFlowspecExtensionProviderContext getContext() {
50 public FlowspecActivator(@Nonnull final SimpleFlowspecExtensionProviderContext context) {
51 this.context = requireNonNull(context);
53 for (SimpleFlowspecExtensionProviderContext.SAFI safi : SimpleFlowspecExtensionProviderContext.SAFI.values()) {
54 registerCommonFlowspecTypeHandlers(
55 SimpleFlowspecExtensionProviderContext.AFI.IPV4,
58 registerIpv4FlowspecTypeHandlers(
59 SimpleFlowspecExtensionProviderContext.AFI.IPV4,
63 registerCommonFlowspecTypeHandlers(
64 SimpleFlowspecExtensionProviderContext.AFI.IPV6,
67 registerIpv6FlowspecTypeHandlers(
68 SimpleFlowspecExtensionProviderContext.AFI.IPV6,
75 * Register the common flowspec type handlers.
77 private void registerCommonFlowspecTypeHandlers(
78 final SimpleFlowspecExtensionProviderContext.AFI afi,
79 final SimpleFlowspecExtensionProviderContext.SAFI safi
81 final SimpleFlowspecTypeRegistry flowspecTypeRegistry = this.context.getFlowspecTypeRegistry(afi, safi);
83 final FSPortHandler portHandler = new FSPortHandler();
84 this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSPortHandler.PORT_VALUE, portHandler));
85 this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(PortCase.class, portHandler));
87 final FSDestinationPortHandler destinationPortHandler = new FSDestinationPortHandler();
88 this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSDestinationPortHandler.DESTINATION_PORT_VALUE, destinationPortHandler));
89 this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(DestinationPortCase.class, destinationPortHandler));
91 final FSSourcePortHandler sourcePortHandler = new FSSourcePortHandler();
92 this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSSourcePortHandler.SOURCE_PORT_VALUE, sourcePortHandler));
93 this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(SourcePortCase.class, sourcePortHandler));
95 final FSIcmpTypeHandler icmpTypeHandler = new FSIcmpTypeHandler();
96 this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSIcmpTypeHandler.ICMP_TYPE_VALUE, icmpTypeHandler));
97 this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(IcmpTypeCase.class, icmpTypeHandler));
99 final FSIcmpCodeHandler icmpCodeHandler = new FSIcmpCodeHandler();
100 this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSIcmpCodeHandler.ICMP_CODE_VALUE, icmpCodeHandler));
101 this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(IcmpCodeCase.class, icmpCodeHandler));
103 final FSTcpFlagsHandler tcpFlagsHandler = new FSTcpFlagsHandler();
104 this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSTcpFlagsHandler.TCP_FLAGS_VALUE, tcpFlagsHandler));
105 this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(TcpFlagsCase.class, tcpFlagsHandler));
107 final FSPacketLengthHandler packetlengthHandler = new FSPacketLengthHandler();
108 this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSPacketLengthHandler.PACKET_LENGTH_VALUE, packetlengthHandler));
109 this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(PacketLengthCase.class, packetlengthHandler));
111 final FSDscpHandler dscpHandler = new FSDscpHandler();
112 this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSDscpHandler.DSCP_VALUE, dscpHandler));
113 this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(DscpCase.class, dscpHandler));
116 private void registerIpv4FlowspecTypeHandlers(
117 final SimpleFlowspecExtensionProviderContext.AFI afi,
118 final SimpleFlowspecExtensionProviderContext.SAFI safi
120 final SimpleFlowspecTypeRegistry flowspecTypeRegistry = this.context.getFlowspecTypeRegistry(afi, safi);
122 final FSIpv4DestinationPrefixHandler destinationPrefixHandler = new FSIpv4DestinationPrefixHandler();
123 this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSIpv4DestinationPrefixHandler.DESTINATION_PREFIX_VALUE, destinationPrefixHandler));
124 this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(DestinationPrefixCase.class, destinationPrefixHandler));
126 final FSIpv4SourcePrefixHandler sourcePrefixHandler = new FSIpv4SourcePrefixHandler();
127 this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSIpv4SourcePrefixHandler.SOURCE_PREFIX_VALUE, sourcePrefixHandler));
128 this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(SourcePrefixCase.class, sourcePrefixHandler));
130 final FSIpProtocolHandler ipProtocolHandler = new FSIpProtocolHandler();
131 this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSIpProtocolHandler.IP_PROTOCOL_VALUE, ipProtocolHandler));
132 this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(ProtocolIpCase.class, ipProtocolHandler));
134 final FSIpv4FragmentHandler fragmentHandler = new FSIpv4FragmentHandler();
135 this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSIpv4FragmentHandler.FRAGMENT_VALUE, fragmentHandler));
136 this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(FragmentCase.class, fragmentHandler));
139 private void registerIpv6FlowspecTypeHandlers(
140 final SimpleFlowspecExtensionProviderContext.AFI afi,
141 final SimpleFlowspecExtensionProviderContext.SAFI safi
143 final SimpleFlowspecTypeRegistry flowspecTypeRegistry = this.context.getFlowspecTypeRegistry(afi, safi);
145 final FSIpv6DestinationPrefixHandler destinationPrefixHandler = new FSIpv6DestinationPrefixHandler();
146 this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSIpv6DestinationPrefixHandler.IPV6_DESTINATION_PREFIX_VALUE, destinationPrefixHandler));
147 this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(DestinationIpv6PrefixCase.class, destinationPrefixHandler));
149 final FSIpv6SourcePrefixHandler sourcePrefixHandler = new FSIpv6SourcePrefixHandler();
150 this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSIpv6SourcePrefixHandler.SOURCE_PREFIX_VALUE, sourcePrefixHandler));
151 this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(SourceIpv6PrefixCase.class, sourcePrefixHandler));
153 final FSIpv6NextHeaderHandler nextHeaderHandler = new FSIpv6NextHeaderHandler();
154 this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSIpv6NextHeaderHandler.NEXT_HEADER_VALUE, nextHeaderHandler));
155 this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(NextHeaderCase.class, nextHeaderHandler));
157 final FSIpv6FragmentHandler fragmentHandler = new FSIpv6FragmentHandler();
158 this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSIpv6FragmentHandler.FRAGMENT_VALUE, fragmentHandler));
159 this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(FragmentCase.class, fragmentHandler));
161 final FSIpv6FlowLabelHandler flowlabelHandler = new FSIpv6FlowLabelHandler();
162 this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSIpv6FlowLabelHandler.FLOW_LABEL_VALUE, flowlabelHandler));
163 this.registrations.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(FlowLabelCase.class, flowlabelHandler));
167 public void close() {
168 if (this.registrations == null) {
171 for (final AutoCloseable r : this.registrations) {
174 } catch (final Exception e) {
175 LOG.warn("Failed to close registration", e);