2 * Copyright (c) 2016 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.evpn.impl;
10 import com.google.common.annotations.VisibleForTesting;
11 import java.util.ArrayList;
12 import java.util.List;
13 import org.kohsuke.MetaInfServices;
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.BGPExtensionProviderActivator;
24 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
25 import org.opendaylight.protocol.bgp.parser.spi.NextHopParserSerializer;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.EvpnSubsequentAddressFamily;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.L2vpnAddressFamily;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.evpn.routes.EvpnRoutes;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.DefaultGatewayExtendedCommunityCase;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.EsImportRouteExtendedCommunityCase;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.EsiLabelExtendedCommunityCase;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.Layer2AttributesExtendedCommunityCase;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.MacMobilityExtendedCommunityCase;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.Ipv4NextHopCase;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.next.hop.c.next.hop.Ipv6NextHopCase;
36 import org.opendaylight.yangtools.concepts.Registration;
38 @MetaInfServices(value = BGPExtensionProviderActivator.class)
39 public final class BGPActivator extends AbstractBGPExtensionProviderActivator {
41 static final int L2VPN_AFI = 25;
43 static final int EVPN_SAFI = 70;
46 protected List<Registration> startImpl(final BGPExtensionProviderContext context) {
47 final List<Registration> regs = new ArrayList<>();
49 regs.add(context.registerSubsequentAddressFamily(EvpnSubsequentAddressFamily.class, EVPN_SAFI));
50 regs.add(context.registerAddressFamily(L2vpnAddressFamily.class, L2VPN_AFI));
52 registerNlriHandler(context, regs);
53 NlriActivator.registerNlriParsers(regs);
54 registerExtendedCommunities(context, regs);
55 ESIActivator.registerEsiTypeParsers(regs);
60 private static void registerNlriHandler(final BGPExtensionProviderContext context, final List<Registration> regs) {
61 final NextHopParserSerializer nextHopParser = new NextHopParserSerializer() {};
62 final EvpnNlriParser nlriHandler = new EvpnNlriParser();
63 regs.add(context.registerNlriParser(L2vpnAddressFamily.class, EvpnSubsequentAddressFamily.class,
64 nlriHandler, nextHopParser, Ipv4NextHopCase.class, Ipv6NextHopCase.class));
65 regs.add(context.registerNlriSerializer(EvpnRoutes.class, nlriHandler));
68 private static void registerExtendedCommunities(final BGPExtensionProviderContext context,
69 final List<Registration> regs) {
70 final DefaultGatewayExtCom defGEC = new DefaultGatewayExtCom();
71 regs.add(context.registerExtendedCommunityParser(defGEC.getType(true), defGEC.getSubType(), defGEC));
72 regs.add(context.registerExtendedCommunitySerializer(DefaultGatewayExtendedCommunityCase.class, defGEC));
74 final ESILabelExtCom esiLEC = new ESILabelExtCom();
75 regs.add(context.registerExtendedCommunityParser(esiLEC.getType(true), esiLEC.getSubType(), esiLEC));
76 regs.add(context.registerExtendedCommunitySerializer(EsiLabelExtendedCommunityCase.class, esiLEC));
78 final ESImpRouteTargetExtCom esImpEC = new ESImpRouteTargetExtCom();
79 regs.add(context.registerExtendedCommunityParser(esImpEC.getType(true),
80 esImpEC.getSubType(), esImpEC));
81 regs.add(context.registerExtendedCommunitySerializer(EsImportRouteExtendedCommunityCase.class, esImpEC));
83 final MACMobExtCom macEC = new MACMobExtCom();
84 regs.add(context.registerExtendedCommunityParser(macEC.getType(true), macEC.getSubType(), macEC));
85 regs.add(context.registerExtendedCommunitySerializer(MacMobilityExtendedCommunityCase.class, macEC));
87 final Layer2AttributesExtCom l2a = new Layer2AttributesExtCom();
88 regs.add(context.registerExtendedCommunityParser(l2a.getType(false), l2a.getSubType(), l2a));
89 regs.add(context.registerExtendedCommunitySerializer(Layer2AttributesExtendedCommunityCase.class, l2a));