Remove hand-written ServiceLoader services
[bgpcep.git] / bgp / extensions / flowspec / src / main / java / org / opendaylight / protocol / bgp / flowspec / BGPActivator.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.bgp.flowspec;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.util.ArrayList;
13 import java.util.List;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.kohsuke.MetaInfServices;
16 import org.opendaylight.protocol.bgp.flowspec.extended.communities.RedirectAsFourOctetEcHandler;
17 import org.opendaylight.protocol.bgp.flowspec.extended.communities.RedirectAsTwoOctetEcHandler;
18 import org.opendaylight.protocol.bgp.flowspec.extended.communities.RedirectIpNextHopEcHandler;
19 import org.opendaylight.protocol.bgp.flowspec.extended.communities.RedirectIpv4EcHandler;
20 import org.opendaylight.protocol.bgp.flowspec.extended.communities.RedirectIpv6EcHandler;
21 import org.opendaylight.protocol.bgp.flowspec.extended.communities.TrafficActionEcHandler;
22 import org.opendaylight.protocol.bgp.flowspec.extended.communities.TrafficMarkingEcHandler;
23 import org.opendaylight.protocol.bgp.flowspec.extended.communities.TrafficRateEcHandler;
24 import org.opendaylight.protocol.bgp.flowspec.l3vpn.ipv4.FlowspecL3vpnIpv4NlriParser;
25 import org.opendaylight.protocol.bgp.flowspec.l3vpn.ipv6.FlowspecL3vpnIpv6NlriParser;
26 import org.opendaylight.protocol.bgp.inet.codec.nexthop.Ipv4NextHopParserSerializer;
27 import org.opendaylight.protocol.bgp.inet.codec.nexthop.Ipv6NextHopParserSerializer;
28 import org.opendaylight.protocol.bgp.parser.spi.AbstractBGPExtensionProviderActivator;
29 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderActivator;
30 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.FlowspecL3vpnSubsequentAddressFamily;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.FlowspecSubsequentAddressFamily;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.bgp.rib.route.attributes.extended.communities.extended.community.RedirectAs4ExtendedCommunityCase;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.bgp.rib.route.attributes.extended.communities.extended.community.RedirectExtendedCommunityCase;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.bgp.rib.route.attributes.extended.communities.extended.community.RedirectIpNhExtendedCommunityCase;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.bgp.rib.route.attributes.extended.communities.extended.community.RedirectIpv4ExtendedCommunityCase;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.bgp.rib.route.attributes.extended.communities.extended.community.RedirectIpv6ExtendedCommunityCase;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.bgp.rib.route.attributes.extended.communities.extended.community.TrafficActionExtendedCommunityCase;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.bgp.rib.route.attributes.extended.communities.extended.community.TrafficMarkingExtendedCommunityCase;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.bgp.rib.route.attributes.extended.communities.extended.community.TrafficRateExtendedCommunityCase;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.ipv6.routes.FlowspecIpv6Routes;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.l3vpn.ipv4.routes.FlowspecL3vpnIpv4Routes;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.l3vpn.ipv6.routes.FlowspecL3vpnIpv6Routes;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.routes.FlowspecRoutes;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv4AddressFamily;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv6AddressFamily;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.Ipv4NextHopCase;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.Ipv6NextHopCase;
49 import org.opendaylight.yangtools.concepts.Registration;
50
51 @MetaInfServices(value = BGPExtensionProviderActivator.class)
52 public final class BGPActivator extends AbstractBGPExtensionProviderActivator {
53     private static final int FLOWSPEC_SAFI = 133;
54     private static final int FLOWSPEC_L3VPN_SAFI = 134;
55
56     private final FlowspecActivator activator;
57
58     // FIXME: this needs proper injection
59     public BGPActivator(final @NonNull FlowspecActivator activator) {
60         this.activator = requireNonNull(activator);
61     }
62
63     @Override
64     protected List<Registration> startImpl(final BGPExtensionProviderContext context) {
65         final SimpleFlowspecExtensionProviderContext flowspecContext = activator.getContext();
66
67         final List<Registration> regs = new ArrayList<>();
68         regs.add(context.registerSubsequentAddressFamily(FlowspecSubsequentAddressFamily.class, FLOWSPEC_SAFI));
69         regs.add(context.registerSubsequentAddressFamily(FlowspecL3vpnSubsequentAddressFamily.class,
70             FLOWSPEC_L3VPN_SAFI));
71
72         final Ipv4NextHopParserSerializer ipv4NextHopParser = new Ipv4NextHopParserSerializer();
73         final Ipv6NextHopParserSerializer ipv6NextHopParser = new Ipv6NextHopParserSerializer();
74
75         final SimpleFlowspecIpv4NlriParser fsIpv4Handler = new SimpleFlowspecIpv4NlriParser(
76             flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4,
77                 SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC));
78         final SimpleFlowspecIpv6NlriParser fsIpv6Handler = new SimpleFlowspecIpv6NlriParser(
79             flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV6,
80                 SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC));
81         regs.add(context.registerNlriParser(Ipv4AddressFamily.class, FlowspecSubsequentAddressFamily.class,
82             fsIpv4Handler, ipv4NextHopParser, Ipv4NextHopCase.class));
83         regs.add(context.registerNlriParser(Ipv6AddressFamily.class, FlowspecSubsequentAddressFamily.class,
84             fsIpv6Handler, ipv6NextHopParser, Ipv6NextHopCase.class));
85         regs.add(context.registerNlriSerializer(FlowspecRoutes.class, fsIpv4Handler));
86         regs.add(context.registerNlriSerializer(FlowspecIpv6Routes.class, fsIpv6Handler));
87
88         final FlowspecL3vpnIpv4NlriParser fsL3vpnIpv4Handler = new FlowspecL3vpnIpv4NlriParser(
89             flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4,
90                 SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC_VPN));
91         final FlowspecL3vpnIpv6NlriParser fsL3vpnIpv6Handler = new FlowspecL3vpnIpv6NlriParser(
92             flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV6,
93                 SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC_VPN));
94         regs.add(context.registerNlriParser(Ipv4AddressFamily.class, FlowspecL3vpnSubsequentAddressFamily.class,
95             fsL3vpnIpv4Handler, ipv4NextHopParser, Ipv4NextHopCase.class));
96         regs.add(context.registerNlriParser(Ipv6AddressFamily.class, FlowspecL3vpnSubsequentAddressFamily.class,
97             fsL3vpnIpv6Handler, ipv6NextHopParser, Ipv6NextHopCase.class));
98         regs.add(context.registerNlriSerializer(FlowspecL3vpnIpv4Routes.class, fsL3vpnIpv4Handler));
99         regs.add(context.registerNlriSerializer(FlowspecL3vpnIpv6Routes.class, fsL3vpnIpv6Handler));
100
101         final RedirectAsTwoOctetEcHandler redirect2bHandler = new RedirectAsTwoOctetEcHandler();
102         regs.add(context.registerExtendedCommunityParser(redirect2bHandler.getType(true),
103             redirect2bHandler.getSubType(), redirect2bHandler));
104         regs.add(context.registerExtendedCommunitySerializer(RedirectExtendedCommunityCase.class, redirect2bHandler));
105
106         final TrafficActionEcHandler trafficActionHandler = new TrafficActionEcHandler();
107         regs.add(context.registerExtendedCommunityParser(trafficActionHandler.getType(true),
108             trafficActionHandler.getSubType(), trafficActionHandler));
109         regs.add(context.registerExtendedCommunitySerializer(TrafficActionExtendedCommunityCase.class,
110             trafficActionHandler));
111
112         final TrafficMarkingEcHandler trafficMarkingHandler = new TrafficMarkingEcHandler();
113         regs.add(context.registerExtendedCommunityParser(trafficMarkingHandler.getType(true),
114             trafficMarkingHandler.getSubType(), trafficMarkingHandler));
115         regs.add(context.registerExtendedCommunitySerializer(TrafficMarkingExtendedCommunityCase.class,
116             trafficMarkingHandler));
117
118         final TrafficRateEcHandler trafficRateEcHandler = new TrafficRateEcHandler();
119         regs.add(context.registerExtendedCommunityParser(trafficRateEcHandler.getType(true),
120             trafficRateEcHandler.getSubType(), trafficRateEcHandler));
121         regs.add(context.registerExtendedCommunitySerializer(TrafficRateExtendedCommunityCase.class,
122             trafficRateEcHandler));
123
124         final RedirectIpv6EcHandler redirectIpv6EcHandler = new RedirectIpv6EcHandler();
125         regs.add(context.registerExtendedCommunityParser(redirectIpv6EcHandler.getType(true),
126             redirectIpv6EcHandler.getSubType(), redirectIpv6EcHandler));
127         regs.add(context.registerExtendedCommunitySerializer(RedirectIpv6ExtendedCommunityCase.class,
128             redirectIpv6EcHandler));
129
130         final RedirectAsFourOctetEcHandler redirect4bHandler = new RedirectAsFourOctetEcHandler();
131         regs.add(context.registerExtendedCommunityParser(redirect4bHandler.getType(true),
132             redirect4bHandler.getSubType(), redirect4bHandler));
133         regs.add(context.registerExtendedCommunitySerializer(RedirectAs4ExtendedCommunityCase.class,
134             redirect4bHandler));
135
136         final RedirectIpv4EcHandler redirectIpv4Handler = new RedirectIpv4EcHandler();
137         regs.add(context.registerExtendedCommunityParser(redirectIpv4Handler.getType(true),
138             redirectIpv4Handler.getSubType(), redirectIpv4Handler));
139         regs.add(context.registerExtendedCommunitySerializer(RedirectIpv4ExtendedCommunityCase.class,
140             redirectIpv4Handler));
141
142         final RedirectIpNextHopEcHandler redirectIpNhHandler = new RedirectIpNextHopEcHandler();
143         regs.add(context.registerExtendedCommunityParser(redirectIpNhHandler.getType(true),
144             redirectIpNhHandler.getSubType(), redirectIpNhHandler));
145         regs.add(context.registerExtendedCommunitySerializer(RedirectIpNhExtendedCommunityCase.class,
146             redirectIpNhHandler));
147
148         return regs;
149     }
150 }