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