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 java.util.ArrayList;
11 import java.util.List;
12 import org.opendaylight.protocol.bgp.flowspec.handlers.FSIpv4DestinationPrefixHandler;
13 import org.opendaylight.protocol.bgp.flowspec.handlers.FSIpv4FragmentHandler;
14 import org.opendaylight.protocol.bgp.flowspec.handlers.FSIpv4SourcePrefixHandler;
15 import org.opendaylight.protocol.bgp.flowspec.handlers.FSIpv6DestinationPrefixHandler;
16 import org.opendaylight.protocol.bgp.flowspec.handlers.FSIpv6FragmentHandler;
17 import org.opendaylight.protocol.bgp.flowspec.handlers.FSIpv6SourcePrefixHandler;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.DestinationPortCase;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.DscpCase;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.FragmentCase;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.IcmpCodeCase;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.IcmpTypeCase;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.PacketLengthCase;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.PortCase;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.SourcePortCase;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.TcpFlagsCase;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.group.ipv4.flowspec.flowspec.type.DestinationPrefixCase;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.group.ipv4.flowspec.flowspec.type.ProtocolIpCase;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.group.ipv4.flowspec.flowspec.type.SourcePrefixCase;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.group.ipv6.flowspec.flowspec.type.DestinationIpv6PrefixCase;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.group.ipv6.flowspec.flowspec.type.FlowLabelCase;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.group.ipv6.flowspec.flowspec.type.NextHeaderCase;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.group.ipv6.flowspec.flowspec.type.SourceIpv6PrefixCase;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
37 public final class FlowspecActivator implements AutoCloseable {
38 private static final Logger LOG = LoggerFactory.getLogger(FlowspecActivator.class);
40 private final List<AutoCloseable> registrations = new ArrayList<>();
42 public FlowspecActivator(final SimpleFlowspecExtensionProviderContext context) {
43 for (SimpleFlowspecExtensionProviderContext.SAFI safi : SimpleFlowspecExtensionProviderContext.SAFI.values()) {
44 registerCommonFlowspecTypeHandlers(
45 SimpleFlowspecExtensionProviderContext.AFI.IPV4,
50 registerIpv4FlowspecTypeHandlers(
51 SimpleFlowspecExtensionProviderContext.AFI.IPV4,
57 registerCommonFlowspecTypeHandlers(
58 SimpleFlowspecExtensionProviderContext.AFI.IPV6,
63 registerIpv6FlowspecTypeHandlers(
64 SimpleFlowspecExtensionProviderContext.AFI.IPV6,
73 * Register the common flowspec type handlers
78 private void registerCommonFlowspecTypeHandlers(
79 final SimpleFlowspecExtensionProviderContext.AFI afi,
80 final SimpleFlowspecExtensionProviderContext.SAFI safi,
81 final List<AutoCloseable> regs,
82 final SimpleFlowspecExtensionProviderContext context
84 final SimpleFlowspecTypeRegistry flowspecTypeRegistry = context.getFlowspecTypeRegistry(afi, safi);
86 final FSPortHandler portHandler = new FSPortHandler();
87 regs.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSPortHandler.PORT_VALUE, portHandler));
88 regs.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(PortCase.class, portHandler));
90 final FSDestinationPortHandler destinationPortHandler = new FSDestinationPortHandler();
91 regs.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSDestinationPortHandler.DESTINATION_PORT_VALUE, destinationPortHandler));
92 regs.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(DestinationPortCase.class, destinationPortHandler));
94 final FSSourcePortHandler sourcePortHandler = new FSSourcePortHandler();
95 regs.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSSourcePortHandler.SOURCE_PORT_VALUE, sourcePortHandler));
96 regs.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(SourcePortCase.class, sourcePortHandler));
98 final FSIcmpTypeHandler icmpTypeHandler = new FSIcmpTypeHandler();
99 regs.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSIcmpTypeHandler.ICMP_TYPE_VALUE, icmpTypeHandler));
100 regs.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(IcmpTypeCase.class, icmpTypeHandler));
102 final FSIcmpCodeHandler icmpCodeHandler = new FSIcmpCodeHandler();
103 regs.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSIcmpCodeHandler.ICMP_CODE_VALUE, icmpCodeHandler));
104 regs.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(IcmpCodeCase.class, icmpCodeHandler));
106 final FSTcpFlagsHandler tcpFlagsHandler = new FSTcpFlagsHandler();
107 regs.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSTcpFlagsHandler.TCP_FLAGS_VALUE, tcpFlagsHandler));
108 regs.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(TcpFlagsCase.class, tcpFlagsHandler));
110 final FSPacketLengthHandler packetlengthHandler = new FSPacketLengthHandler();
111 regs.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSPacketLengthHandler.PACKET_LENGTH_VALUE, packetlengthHandler));
112 regs.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(PacketLengthCase.class, packetlengthHandler));
114 final FSDscpHandler dscpHandler = new FSDscpHandler();
115 regs.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSDscpHandler.DSCP_VALUE, dscpHandler));
116 regs.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(DscpCase.class, dscpHandler));
119 protected void registerIpv4FlowspecTypeHandlers(
120 final SimpleFlowspecExtensionProviderContext.AFI afi,
121 final SimpleFlowspecExtensionProviderContext.SAFI safi,
122 final List<AutoCloseable> regs,
123 final SimpleFlowspecExtensionProviderContext context
125 final SimpleFlowspecTypeRegistry flowspecTypeRegistry = context.getFlowspecTypeRegistry(afi, safi);
127 final FSIpv4DestinationPrefixHandler destinationPrefixHandler = new FSIpv4DestinationPrefixHandler();
128 regs.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSIpv4DestinationPrefixHandler.DESTINATION_PREFIX_VALUE, destinationPrefixHandler));
129 regs.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(DestinationPrefixCase.class, destinationPrefixHandler));
131 final FSIpv4SourcePrefixHandler sourcePrefixHandler = new FSIpv4SourcePrefixHandler();
132 regs.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSIpv4SourcePrefixHandler.SOURCE_PREFIX_VALUE, sourcePrefixHandler));
133 regs.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(SourcePrefixCase.class, sourcePrefixHandler));
135 final FSIpProtocolHandler ipProtocolHandler = new FSIpProtocolHandler();
136 regs.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSIpProtocolHandler.IP_PROTOCOL_VALUE, ipProtocolHandler));
137 regs.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(ProtocolIpCase.class, ipProtocolHandler));
139 final FSIpv4FragmentHandler fragmentHandler = new FSIpv4FragmentHandler();
140 regs.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSIpv4FragmentHandler.FRAGMENT_VALUE, fragmentHandler));
141 regs.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(FragmentCase.class, fragmentHandler));
144 protected void registerIpv6FlowspecTypeHandlers(
145 final SimpleFlowspecExtensionProviderContext.AFI afi,
146 final SimpleFlowspecExtensionProviderContext.SAFI safi,
147 final List<AutoCloseable> regs,
148 final SimpleFlowspecExtensionProviderContext context
150 final SimpleFlowspecTypeRegistry flowspecTypeRegistry = context.getFlowspecTypeRegistry(afi, safi);
152 final FSIpv6DestinationPrefixHandler destinationPrefixHandler = new FSIpv6DestinationPrefixHandler();
153 regs.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSIpv6DestinationPrefixHandler.IPV6_DESTINATION_PREFIX_VALUE, destinationPrefixHandler));
154 regs.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(DestinationIpv6PrefixCase.class, destinationPrefixHandler));
156 final FSIpv6SourcePrefixHandler sourcePrefixHandler = new FSIpv6SourcePrefixHandler();
157 regs.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSIpv6SourcePrefixHandler.SOURCE_PREFIX_VALUE, sourcePrefixHandler));
158 regs.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(SourceIpv6PrefixCase.class, sourcePrefixHandler));
160 final FSIpv6NextHeaderHandler nextHeaderHandler = new FSIpv6NextHeaderHandler();
161 regs.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSIpv6NextHeaderHandler.NEXT_HEADER_VALUE, nextHeaderHandler));
162 regs.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(NextHeaderCase.class, nextHeaderHandler));
164 final FSIpv6FragmentHandler fragmentHandler = new FSIpv6FragmentHandler();
165 regs.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSIpv6FragmentHandler.FRAGMENT_VALUE, fragmentHandler));
166 regs.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(FragmentCase.class, fragmentHandler));
168 final FSIpv6FlowLabelHandler flowlabelHandler = new FSIpv6FlowLabelHandler();
169 regs.add(flowspecTypeRegistry.registerFlowspecTypeParser(FSIpv6FlowLabelHandler.FLOW_LABEL_VALUE, flowlabelHandler));
170 regs.add(flowspecTypeRegistry.registerFlowspecTypeSerializer(FlowLabelCase.class, flowlabelHandler));
174 public void close() {
175 if (this.registrations == null) {
178 for (final AutoCloseable r : this.registrations) {
181 } catch (final Exception e) {
182 LOG.warn("Failed to close registration", e);