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 org.eclipse.jdt.annotation.NonNull;
15 import org.opendaylight.protocol.bgp.flowspec.extended.communities.RedirectAsFourOctetEcHandler;
16 import org.opendaylight.protocol.bgp.flowspec.extended.communities.RedirectAsTwoOctetEcHandler;
17 import org.opendaylight.protocol.bgp.flowspec.extended.communities.RedirectIpNextHopEcHandler;
18 import org.opendaylight.protocol.bgp.flowspec.extended.communities.RedirectIpv4EcHandler;
19 import org.opendaylight.protocol.bgp.flowspec.extended.communities.RedirectIpv6EcHandler;
20 import org.opendaylight.protocol.bgp.flowspec.extended.communities.TrafficActionEcHandler;
21 import org.opendaylight.protocol.bgp.flowspec.extended.communities.TrafficMarkingEcHandler;
22 import org.opendaylight.protocol.bgp.flowspec.extended.communities.TrafficRateEcHandler;
23 import org.opendaylight.protocol.bgp.flowspec.l3vpn.ipv4.FlowspecL3vpnIpv4NlriParser;
24 import org.opendaylight.protocol.bgp.flowspec.l3vpn.ipv6.FlowspecL3vpnIpv6NlriParser;
25 import org.opendaylight.protocol.bgp.inet.codec.nexthop.Ipv4NextHopParserSerializer;
26 import org.opendaylight.protocol.bgp.inet.codec.nexthop.Ipv6NextHopParserSerializer;
27 import org.opendaylight.protocol.bgp.parser.spi.AbstractBGPExtensionProviderActivator;
28 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.FlowspecL3vpnSubsequentAddressFamily;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.FlowspecSubsequentAddressFamily;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.route.attributes.extended.communities.extended.community.RedirectAs4ExtendedCommunityCase;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.route.attributes.extended.communities.extended.community.RedirectExtendedCommunityCase;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.route.attributes.extended.communities.extended.community.RedirectIpNhExtendedCommunityCase;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.route.attributes.extended.communities.extended.community.RedirectIpv4ExtendedCommunityCase;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.route.attributes.extended.communities.extended.community.RedirectIpv6ExtendedCommunityCase;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.route.attributes.extended.communities.extended.community.TrafficActionExtendedCommunityCase;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.route.attributes.extended.communities.extended.community.TrafficMarkingExtendedCommunityCase;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.route.attributes.extended.communities.extended.community.TrafficRateExtendedCommunityCase;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.ipv6.routes.FlowspecIpv6Routes;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.l3vpn.ipv4.routes.FlowspecL3vpnIpv4Routes;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.l3vpn.ipv6.routes.FlowspecL3vpnIpv6Routes;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.routes.FlowspecRoutes;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv4AddressFamily;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv6AddressFamily;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.Ipv4NextHopCase;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.Ipv6NextHopCase;
47 import org.opendaylight.yangtools.concepts.Registration;
49 public final class BGPActivator extends AbstractBGPExtensionProviderActivator {
51 private static final int FLOWSPEC_SAFI = 133;
52 private static final int FLOWSPEC_L3VPN_SAFI = 134;
54 private final FlowspecActivator activator;
56 public BGPActivator(final @NonNull FlowspecActivator activator) {
57 this.activator = requireNonNull(activator);
61 protected List<Registration> startImpl(final BGPExtensionProviderContext context) {
62 final List<Registration> regs = new ArrayList<>();
63 final SimpleFlowspecExtensionProviderContext flowspecContext = this.activator.getContext();
65 regs.add(context.registerSubsequentAddressFamily(FlowspecSubsequentAddressFamily.class, FLOWSPEC_SAFI));
66 regs.add(context.registerSubsequentAddressFamily(FlowspecL3vpnSubsequentAddressFamily.class,
67 FLOWSPEC_L3VPN_SAFI));
69 final Ipv4NextHopParserSerializer ipv4NextHopParser = new Ipv4NextHopParserSerializer();
70 final Ipv6NextHopParserSerializer ipv6NextHopParser = new Ipv6NextHopParserSerializer();
72 final SimpleFlowspecIpv4NlriParser fsIpv4Handler = new SimpleFlowspecIpv4NlriParser(
73 flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4,
74 SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC));
75 final SimpleFlowspecIpv6NlriParser fsIpv6Handler = new SimpleFlowspecIpv6NlriParser(
76 flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV6,
77 SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC));
78 regs.add(context.registerNlriParser(Ipv4AddressFamily.class, FlowspecSubsequentAddressFamily.class,
79 fsIpv4Handler, ipv4NextHopParser, Ipv4NextHopCase.class));
80 regs.add(context.registerNlriParser(Ipv6AddressFamily.class, FlowspecSubsequentAddressFamily.class,
81 fsIpv6Handler, ipv6NextHopParser, Ipv6NextHopCase.class));
82 regs.add(context.registerNlriSerializer(FlowspecRoutes.class, fsIpv4Handler));
83 regs.add(context.registerNlriSerializer(FlowspecIpv6Routes.class, fsIpv6Handler));
85 final FlowspecL3vpnIpv4NlriParser fsL3vpnIpv4Handler = new FlowspecL3vpnIpv4NlriParser(
86 flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4,
87 SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC_VPN));
88 final FlowspecL3vpnIpv6NlriParser fsL3vpnIpv6Handler = new FlowspecL3vpnIpv6NlriParser(
89 flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV6,
90 SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC_VPN));
91 regs.add(context.registerNlriParser(Ipv4AddressFamily.class, FlowspecL3vpnSubsequentAddressFamily.class,
92 fsL3vpnIpv4Handler, ipv4NextHopParser, Ipv4NextHopCase.class));
93 regs.add(context.registerNlriParser(Ipv6AddressFamily.class, FlowspecL3vpnSubsequentAddressFamily.class,
94 fsL3vpnIpv6Handler, ipv6NextHopParser, Ipv6NextHopCase.class));
95 regs.add(context.registerNlriSerializer(FlowspecL3vpnIpv4Routes.class, fsL3vpnIpv4Handler));
96 regs.add(context.registerNlriSerializer(FlowspecL3vpnIpv6Routes.class, fsL3vpnIpv6Handler));
98 final RedirectAsTwoOctetEcHandler redirect2bHandler = new RedirectAsTwoOctetEcHandler();
99 regs.add(context.registerExtendedCommunityParser(redirect2bHandler.getType(true),
100 redirect2bHandler.getSubType(), redirect2bHandler));
101 regs.add(context.registerExtendedCommunitySerializer(RedirectExtendedCommunityCase.class, redirect2bHandler));
103 final TrafficActionEcHandler trafficActionHandler = new TrafficActionEcHandler();
104 regs.add(context.registerExtendedCommunityParser(trafficActionHandler.getType(true),
105 trafficActionHandler.getSubType(), trafficActionHandler));
106 regs.add(context.registerExtendedCommunitySerializer(TrafficActionExtendedCommunityCase.class,
107 trafficActionHandler));
109 final TrafficMarkingEcHandler trafficMarkingHandler = new TrafficMarkingEcHandler();
110 regs.add(context.registerExtendedCommunityParser(trafficMarkingHandler.getType(true),
111 trafficMarkingHandler.getSubType(), trafficMarkingHandler));
112 regs.add(context.registerExtendedCommunitySerializer(TrafficMarkingExtendedCommunityCase.class,
113 trafficMarkingHandler));
115 final TrafficRateEcHandler trafficRateEcHandler = new TrafficRateEcHandler();
116 regs.add(context.registerExtendedCommunityParser(trafficRateEcHandler.getType(true),
117 trafficRateEcHandler.getSubType(), trafficRateEcHandler));
118 regs.add(context.registerExtendedCommunitySerializer(TrafficRateExtendedCommunityCase.class,
119 trafficRateEcHandler));
121 final RedirectIpv6EcHandler redirectIpv6EcHandler = new RedirectIpv6EcHandler();
122 regs.add(context.registerExtendedCommunityParser(redirectIpv6EcHandler.getType(true),
123 redirectIpv6EcHandler.getSubType(), redirectIpv6EcHandler));
124 regs.add(context.registerExtendedCommunitySerializer(RedirectIpv6ExtendedCommunityCase.class,
125 redirectIpv6EcHandler));
127 final RedirectAsFourOctetEcHandler redirect4bHandler = new RedirectAsFourOctetEcHandler();
128 regs.add(context.registerExtendedCommunityParser(redirect4bHandler.getType(true),
129 redirect4bHandler.getSubType(), redirect4bHandler));
130 regs.add(context.registerExtendedCommunitySerializer(RedirectAs4ExtendedCommunityCase.class,
133 final RedirectIpv4EcHandler redirectIpv4Handler = new RedirectIpv4EcHandler();
134 regs.add(context.registerExtendedCommunityParser(redirectIpv4Handler.getType(true),
135 redirectIpv4Handler.getSubType(), redirectIpv4Handler));
136 regs.add(context.registerExtendedCommunitySerializer(RedirectIpv4ExtendedCommunityCase.class,
137 redirectIpv4Handler));
139 final RedirectIpNextHopEcHandler redirectIpNhHandler = new RedirectIpNextHopEcHandler();
140 regs.add(context.registerExtendedCommunityParser(redirectIpNhHandler.getType(true),
141 redirectIpNhHandler.getSubType(), redirectIpNhHandler));
142 regs.add(context.registerExtendedCommunitySerializer(RedirectIpNhExtendedCommunityCase.class,
143 redirectIpNhHandler));