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
9 package org.opendaylight.protocol.bgp.evpn.impl;
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.attributes.PMSITunnelAttributeHandler;
15 import org.opendaylight.protocol.bgp.evpn.impl.esi.types.ESIActivator;
16 import org.opendaylight.protocol.bgp.evpn.impl.extended.communities.DefaultGatewayExtCom;
17 import org.opendaylight.protocol.bgp.evpn.impl.extended.communities.ESILabelExtCom;
18 import org.opendaylight.protocol.bgp.evpn.impl.extended.communities.ESImpRouteTargetExtCom;
19 import org.opendaylight.protocol.bgp.evpn.impl.extended.communities.Layer2AttributesExtCom;
20 import org.opendaylight.protocol.bgp.evpn.impl.extended.communities.MACMobExtCom;
21 import org.opendaylight.protocol.bgp.evpn.impl.nlri.EvpnNlriParser;
22 import org.opendaylight.protocol.bgp.evpn.impl.nlri.NlriActivator;
23 import org.opendaylight.protocol.bgp.parser.spi.AbstractBGPExtensionProviderActivator;
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.rev171213.EvpnSubsequentAddressFamily;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.L2vpnAddressFamily;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.evpn.routes.EvpnRoutes;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.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.rev171213.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.rev171213.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.rev171213.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.rev171213.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.rev130919.next.hop.c.next.hop.Ipv4NextHopCase;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv6NextHopCase;
37 public final class BGPActivator extends AbstractBGPExtensionProviderActivator {
39 static final int L2VPN_AFI = 25;
41 static final int EVPN_SAFI = 70;
44 protected List<AutoCloseable> startImpl(final BGPExtensionProviderContext context) {
45 final List<AutoCloseable> regs = new ArrayList<>();
47 regs.add(context.registerSubsequentAddressFamily(EvpnSubsequentAddressFamily.class, EVPN_SAFI));
48 regs.add(context.registerAddressFamily(L2vpnAddressFamily.class, L2VPN_AFI));
50 registerNlriHandler(context, regs);
51 NlriActivator.registerNlriParsers(regs);
52 registerExtendedCommunities(context, regs);
53 ESIActivator.registerEsiTypeParsers(regs);
55 registerAttributesHandler(context, regs);
59 private static void registerAttributesHandler(final BGPExtensionProviderContext context,
60 final List<AutoCloseable> regs) {
61 final PMSITunnelAttributeHandler pmsiParser =
62 new PMSITunnelAttributeHandler(context.getAddressFamilyRegistry());
63 regs.add(context.registerAttributeParser(pmsiParser.getType(), pmsiParser));
64 regs.add(context.registerAttributeSerializer(pmsiParser.getClazz(), pmsiParser));
67 private static void registerNlriHandler(final BGPExtensionProviderContext context, final List<AutoCloseable> regs) {
68 final NextHopParserSerializer nextHopParser = new NextHopParserSerializer() {};
69 final EvpnNlriParser nlriHandler = new EvpnNlriParser();
70 regs.add(context.registerNlriParser(L2vpnAddressFamily.class, EvpnSubsequentAddressFamily.class,
71 nlriHandler, nextHopParser, Ipv4NextHopCase.class, Ipv6NextHopCase.class));
72 regs.add(context.registerNlriSerializer(EvpnRoutes.class, nlriHandler));
75 private static void registerExtendedCommunities(final BGPExtensionProviderContext context,
76 final List<AutoCloseable> regs) {
77 final DefaultGatewayExtCom defGEC = new DefaultGatewayExtCom();
78 regs.add(context.registerExtendedCommunityParser(defGEC.getType(true), defGEC.getSubType(), defGEC));
79 regs.add(context.registerExtendedCommunitySerializer(DefaultGatewayExtendedCommunityCase.class, defGEC));
81 final ESILabelExtCom esiLEC = new ESILabelExtCom();
82 regs.add(context.registerExtendedCommunityParser(esiLEC.getType(true), esiLEC.getSubType(), esiLEC));
83 regs.add(context.registerExtendedCommunitySerializer(EsiLabelExtendedCommunityCase.class, esiLEC));
85 final ESImpRouteTargetExtCom esImpEC = new ESImpRouteTargetExtCom();
86 regs.add(context.registerExtendedCommunityParser(esImpEC.getType(true),
87 esImpEC.getSubType(), esImpEC));
88 regs.add(context.registerExtendedCommunitySerializer(EsImportRouteExtendedCommunityCase.class, esImpEC));
90 final MACMobExtCom macEC = new MACMobExtCom();
91 regs.add(context.registerExtendedCommunityParser(macEC.getType(true), macEC.getSubType(), macEC));
92 regs.add(context.registerExtendedCommunitySerializer(MacMobilityExtendedCommunityCase.class, macEC));
94 final Layer2AttributesExtCom l2a = new Layer2AttributesExtCom();
95 regs.add(context.registerExtendedCommunityParser(l2a.getType(false), l2a.getSubType(), l2a));
96 regs.add(context.registerExtendedCommunitySerializer(Layer2AttributesExtendedCommunityCase.class, l2a));