Code clean up
[bgpcep.git] / bgp / evpn / src / main / java / org / opendaylight / protocol / bgp / evpn / impl / BGPActivator.java
1 /*
2  * Copyright (c) 2016 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
9 package org.opendaylight.protocol.bgp.evpn.impl;
10
11 import com.google.common.annotations.VisibleForTesting;
12 import java.util.ArrayList;
13 import java.util.List;
14 import org.opendaylight.protocol.bgp.evpn.impl.esi.types.ESIActivator;
15 import org.opendaylight.protocol.bgp.evpn.impl.extended.communities.DefaultGatewayExtCom;
16 import org.opendaylight.protocol.bgp.evpn.impl.extended.communities.ESILabelExtCom;
17 import org.opendaylight.protocol.bgp.evpn.impl.extended.communities.ESImpRouteTargetExtCom;
18 import org.opendaylight.protocol.bgp.evpn.impl.extended.communities.Layer2AttributesExtCom;
19 import org.opendaylight.protocol.bgp.evpn.impl.extended.communities.MACMobExtCom;
20 import org.opendaylight.protocol.bgp.evpn.impl.nlri.EvpnNlriParser;
21 import org.opendaylight.protocol.bgp.evpn.impl.nlri.NlriActivator;
22 import org.opendaylight.protocol.bgp.parser.spi.AbstractBGPExtensionProviderActivator;
23 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
24 import org.opendaylight.protocol.bgp.parser.spi.NextHopParserSerializer;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.EvpnSubsequentAddressFamily;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.L2vpnAddressFamily;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.evpn.routes.EvpnRoutes;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.DefaultGatewayExtendedCommunityCase;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.EsImportRouteExtendedCommunityCase;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.EsiLabelExtendedCommunityCase;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.Layer2AttributesExtendedCommunityCase;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.MacMobilityExtendedCommunityCase;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.Ipv4NextHopCase;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.Ipv6NextHopCase;
35
36 public final class BGPActivator extends AbstractBGPExtensionProviderActivator {
37     @VisibleForTesting
38     static final int L2VPN_AFI = 25;
39     @VisibleForTesting
40     static final int EVPN_SAFI = 70;
41
42     @Override
43     protected List<AutoCloseable> startImpl(final BGPExtensionProviderContext context) {
44         final List<AutoCloseable> regs = new ArrayList<>();
45
46         regs.add(context.registerSubsequentAddressFamily(EvpnSubsequentAddressFamily.class, EVPN_SAFI));
47         regs.add(context.registerAddressFamily(L2vpnAddressFamily.class, L2VPN_AFI));
48
49         registerNlriHandler(context, regs);
50         NlriActivator.registerNlriParsers(regs);
51         registerExtendedCommunities(context, regs);
52         ESIActivator.registerEsiTypeParsers(regs);
53
54         return regs;
55     }
56
57     private static void registerNlriHandler(final BGPExtensionProviderContext context, final List<AutoCloseable> regs) {
58         final NextHopParserSerializer nextHopParser = new NextHopParserSerializer() {};
59         final EvpnNlriParser nlriHandler = new EvpnNlriParser();
60         regs.add(context.registerNlriParser(L2vpnAddressFamily.class, EvpnSubsequentAddressFamily.class,
61             nlriHandler, nextHopParser, Ipv4NextHopCase.class, Ipv6NextHopCase.class));
62         regs.add(context.registerNlriSerializer(EvpnRoutes.class, nlriHandler));
63     }
64
65     private static void registerExtendedCommunities(final BGPExtensionProviderContext context,
66             final List<AutoCloseable> regs) {
67         final DefaultGatewayExtCom defGEC = new DefaultGatewayExtCom();
68         regs.add(context.registerExtendedCommunityParser(defGEC.getType(true), defGEC.getSubType(), defGEC));
69         regs.add(context.registerExtendedCommunitySerializer(DefaultGatewayExtendedCommunityCase.class, defGEC));
70
71         final ESILabelExtCom esiLEC = new ESILabelExtCom();
72         regs.add(context.registerExtendedCommunityParser(esiLEC.getType(true), esiLEC.getSubType(), esiLEC));
73         regs.add(context.registerExtendedCommunitySerializer(EsiLabelExtendedCommunityCase.class, esiLEC));
74
75         final ESImpRouteTargetExtCom esImpEC = new ESImpRouteTargetExtCom();
76         regs.add(context.registerExtendedCommunityParser(esImpEC.getType(true),
77                 esImpEC.getSubType(), esImpEC));
78         regs.add(context.registerExtendedCommunitySerializer(EsImportRouteExtendedCommunityCase.class, esImpEC));
79
80         final MACMobExtCom macEC = new MACMobExtCom();
81         regs.add(context.registerExtendedCommunityParser(macEC.getType(true), macEC.getSubType(), macEC));
82         regs.add(context.registerExtendedCommunitySerializer(MacMobilityExtendedCommunityCase.class, macEC));
83
84         final Layer2AttributesExtCom l2a = new Layer2AttributesExtCom();
85         regs.add(context.registerExtendedCommunityParser(l2a.getType(false), l2a.getSubType(), l2a));
86         regs.add(context.registerExtendedCommunitySerializer(Layer2AttributesExtendedCommunityCase.class, l2a));
87     }
88 }