Use OSGi DS in bgp-parser-spi
[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 java.util.ArrayList;
11 import java.util.List;
12 import javax.inject.Inject;
13 import javax.inject.Singleton;
14 import org.kohsuke.MetaInfServices;
15 import org.opendaylight.protocol.bgp.flowspec.FlowspecTypeRegistries.SAFI;
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.BGPExtensionProviderActivator;
29 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.FlowspecL3vpnSubsequentAddressFamily;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.FlowspecSubsequentAddressFamily;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.bgp.rib.route.attributes.extended.communities.extended.community.RedirectAs4ExtendedCommunityCase;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.bgp.rib.route.attributes.extended.communities.extended.community.RedirectExtendedCommunityCase;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.bgp.rib.route.attributes.extended.communities.extended.community.RedirectIpNhExtendedCommunityCase;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.bgp.rib.route.attributes.extended.communities.extended.community.RedirectIpv4ExtendedCommunityCase;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.bgp.rib.route.attributes.extended.communities.extended.community.RedirectIpv6ExtendedCommunityCase;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.bgp.rib.route.attributes.extended.communities.extended.community.TrafficActionExtendedCommunityCase;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.bgp.rib.route.attributes.extended.communities.extended.community.TrafficMarkingExtendedCommunityCase;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.bgp.rib.route.attributes.extended.communities.extended.community.TrafficRateExtendedCommunityCase;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.ipv6.routes.FlowspecIpv6Routes;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.l3vpn.ipv4.routes.FlowspecL3vpnIpv4Routes;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.l3vpn.ipv6.routes.FlowspecL3vpnIpv6Routes;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.routes.FlowspecRoutes;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv4AddressFamily;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv6AddressFamily;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.Ipv4NextHopCase;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.Ipv6NextHopCase;
48 import org.opendaylight.yangtools.concepts.Registration;
49 import org.osgi.service.component.annotations.Component;
50
51 @Singleton
52 @Component(immediate = true, property = "type=org.opendaylight.protocol.bgp.flowspec.BGPActivator")
53 @MetaInfServices
54 public final class BGPActivator implements BGPExtensionProviderActivator {
55     private static final int FLOWSPEC_SAFI = 133;
56     private static final int FLOWSPEC_L3VPN_SAFI = 134;
57
58     @Inject
59     public BGPActivator() {
60         // Exposed for DI
61     }
62
63     @Override
64     public List<Registration> start(final BGPExtensionProviderContext context) {
65         final List<Registration> regs = new ArrayList<>();
66         regs.add(context.registerSubsequentAddressFamily(FlowspecSubsequentAddressFamily.class, FLOWSPEC_SAFI));
67         regs.add(context.registerSubsequentAddressFamily(FlowspecL3vpnSubsequentAddressFamily.class,
68             FLOWSPEC_L3VPN_SAFI));
69
70         final Ipv4NextHopParserSerializer ipv4NextHopParser = new Ipv4NextHopParserSerializer();
71         final Ipv6NextHopParserSerializer ipv6NextHopParser = new Ipv6NextHopParserSerializer();
72
73         final SimpleFlowspecIpv4NlriParser fsIpv4Handler = new SimpleFlowspecIpv4NlriParser(SAFI.FLOWSPEC);
74         final SimpleFlowspecIpv6NlriParser fsIpv6Handler = new SimpleFlowspecIpv6NlriParser(SAFI.FLOWSPEC);
75         regs.add(context.registerNlriParser(Ipv4AddressFamily.class, FlowspecSubsequentAddressFamily.class,
76             fsIpv4Handler, ipv4NextHopParser, Ipv4NextHopCase.class));
77         regs.add(context.registerNlriParser(Ipv6AddressFamily.class, FlowspecSubsequentAddressFamily.class,
78             fsIpv6Handler, ipv6NextHopParser, Ipv6NextHopCase.class));
79         regs.add(context.registerNlriSerializer(FlowspecRoutes.class, fsIpv4Handler));
80         regs.add(context.registerNlriSerializer(FlowspecIpv6Routes.class, fsIpv6Handler));
81
82         final FlowspecL3vpnIpv4NlriParser fsL3vpnIpv4Handler = new FlowspecL3vpnIpv4NlriParser(SAFI.FLOWSPEC_VPN);
83         final FlowspecL3vpnIpv6NlriParser fsL3vpnIpv6Handler = new FlowspecL3vpnIpv6NlriParser(SAFI.FLOWSPEC_VPN);
84         regs.add(context.registerNlriParser(Ipv4AddressFamily.class, FlowspecL3vpnSubsequentAddressFamily.class,
85             fsL3vpnIpv4Handler, ipv4NextHopParser, Ipv4NextHopCase.class));
86         regs.add(context.registerNlriParser(Ipv6AddressFamily.class, FlowspecL3vpnSubsequentAddressFamily.class,
87             fsL3vpnIpv6Handler, ipv6NextHopParser, Ipv6NextHopCase.class));
88         regs.add(context.registerNlriSerializer(FlowspecL3vpnIpv4Routes.class, fsL3vpnIpv4Handler));
89         regs.add(context.registerNlriSerializer(FlowspecL3vpnIpv6Routes.class, fsL3vpnIpv6Handler));
90
91         final RedirectAsTwoOctetEcHandler redirect2bHandler = new RedirectAsTwoOctetEcHandler();
92         regs.add(context.registerExtendedCommunityParser(redirect2bHandler.getType(true),
93             redirect2bHandler.getSubType(), redirect2bHandler));
94         regs.add(context.registerExtendedCommunitySerializer(RedirectExtendedCommunityCase.class, redirect2bHandler));
95
96         final TrafficActionEcHandler trafficActionHandler = new TrafficActionEcHandler();
97         regs.add(context.registerExtendedCommunityParser(trafficActionHandler.getType(true),
98             trafficActionHandler.getSubType(), trafficActionHandler));
99         regs.add(context.registerExtendedCommunitySerializer(TrafficActionExtendedCommunityCase.class,
100             trafficActionHandler));
101
102         final TrafficMarkingEcHandler trafficMarkingHandler = new TrafficMarkingEcHandler();
103         regs.add(context.registerExtendedCommunityParser(trafficMarkingHandler.getType(true),
104             trafficMarkingHandler.getSubType(), trafficMarkingHandler));
105         regs.add(context.registerExtendedCommunitySerializer(TrafficMarkingExtendedCommunityCase.class,
106             trafficMarkingHandler));
107
108         final TrafficRateEcHandler trafficRateEcHandler = new TrafficRateEcHandler();
109         regs.add(context.registerExtendedCommunityParser(trafficRateEcHandler.getType(true),
110             trafficRateEcHandler.getSubType(), trafficRateEcHandler));
111         regs.add(context.registerExtendedCommunitySerializer(TrafficRateExtendedCommunityCase.class,
112             trafficRateEcHandler));
113
114         final RedirectIpv6EcHandler redirectIpv6EcHandler = new RedirectIpv6EcHandler();
115         regs.add(context.registerExtendedCommunityParser(redirectIpv6EcHandler.getType(true),
116             redirectIpv6EcHandler.getSubType(), redirectIpv6EcHandler));
117         regs.add(context.registerExtendedCommunitySerializer(RedirectIpv6ExtendedCommunityCase.class,
118             redirectIpv6EcHandler));
119
120         final RedirectAsFourOctetEcHandler redirect4bHandler = new RedirectAsFourOctetEcHandler();
121         regs.add(context.registerExtendedCommunityParser(redirect4bHandler.getType(true),
122             redirect4bHandler.getSubType(), redirect4bHandler));
123         regs.add(context.registerExtendedCommunitySerializer(RedirectAs4ExtendedCommunityCase.class,
124             redirect4bHandler));
125
126         final RedirectIpv4EcHandler redirectIpv4Handler = new RedirectIpv4EcHandler();
127         regs.add(context.registerExtendedCommunityParser(redirectIpv4Handler.getType(true),
128             redirectIpv4Handler.getSubType(), redirectIpv4Handler));
129         regs.add(context.registerExtendedCommunitySerializer(RedirectIpv4ExtendedCommunityCase.class,
130             redirectIpv4Handler));
131
132         final RedirectIpNextHopEcHandler redirectIpNhHandler = new RedirectIpNextHopEcHandler();
133         regs.add(context.registerExtendedCommunityParser(redirectIpNhHandler.getType(true),
134             redirectIpNhHandler.getSubType(), redirectIpNhHandler));
135         regs.add(context.registerExtendedCommunitySerializer(RedirectIpNhExtendedCommunityCase.class,
136             redirectIpNhHandler));
137
138         return regs;
139     }
140 }