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.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.rev180329.EvpnSubsequentAddressFamily;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.L2vpnAddressFamily;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.evpn.routes.EvpnRoutes;
27 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;
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.EsImportRouteExtendedCommunityCase;
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.EsiLabelExtendedCommunityCase;
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.Layer2AttributesExtendedCommunityCase;
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.MacMobilityExtendedCommunityCase;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.Ipv4NextHopCase;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.Ipv6NextHopCase;
34 import org.opendaylight.yangtools.concepts.Registration;
36 public final class BGPActivator extends AbstractBGPExtensionProviderActivator {
38 static final int L2VPN_AFI = 25;
40 static final int EVPN_SAFI = 70;
43 protected List<Registration> startImpl(final BGPExtensionProviderContext context) {
44 final List<Registration> regs = new ArrayList<>();
46 regs.add(context.registerSubsequentAddressFamily(EvpnSubsequentAddressFamily.class, EVPN_SAFI));
47 regs.add(context.registerAddressFamily(L2vpnAddressFamily.class, L2VPN_AFI));
49 registerNlriHandler(context, regs);
50 NlriActivator.registerNlriParsers(regs);
51 registerExtendedCommunities(context, regs);
52 ESIActivator.registerEsiTypeParsers(regs);
57 private static void registerNlriHandler(final BGPExtensionProviderContext context, final List<Registration> 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));
65 private static void registerExtendedCommunities(final BGPExtensionProviderContext context,
66 final List<Registration> 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));
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));
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));
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));
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));