2 * Copyright (c) 2013 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.parser.impl;
10 import java.util.ArrayList;
11 import java.util.List;
12 import org.opendaylight.protocol.bgp.parser.impl.message.BGPKeepAliveMessageParser;
13 import org.opendaylight.protocol.bgp.parser.impl.message.BGPNotificationMessageParser;
14 import org.opendaylight.protocol.bgp.parser.impl.message.BGPOpenMessageParser;
15 import org.opendaylight.protocol.bgp.parser.impl.message.BGPUpdateMessageParser;
16 import org.opendaylight.protocol.bgp.parser.impl.message.open.As4CapabilityHandler;
17 import org.opendaylight.protocol.bgp.parser.impl.message.open.CapabilityParameterParser;
18 import org.opendaylight.protocol.bgp.parser.impl.message.open.GracefulCapabilityHandler;
19 import org.opendaylight.protocol.bgp.parser.impl.message.open.MultiProtocolCapabilityHandler;
20 import org.opendaylight.protocol.bgp.parser.impl.message.update.AS4AggregatorAttributeParser;
21 import org.opendaylight.protocol.bgp.parser.impl.message.update.AS4PathAttributeParser;
22 import org.opendaylight.protocol.bgp.parser.impl.message.update.AdvertizedRoutesSerializer;
23 import org.opendaylight.protocol.bgp.parser.impl.message.update.AggregatorAttributeParser;
24 import org.opendaylight.protocol.bgp.parser.impl.message.update.AsPathAttributeParser;
25 import org.opendaylight.protocol.bgp.parser.impl.message.update.AtomicAggregateAttributeParser;
26 import org.opendaylight.protocol.bgp.parser.impl.message.update.ClusterIdAttributeParser;
27 import org.opendaylight.protocol.bgp.parser.impl.message.update.CommunitiesAttributeParser;
28 import org.opendaylight.protocol.bgp.parser.impl.message.update.ExtendedCommunitiesAttributeParser;
29 import org.opendaylight.protocol.bgp.parser.impl.message.update.Ipv4NlriParser;
30 import org.opendaylight.protocol.bgp.parser.impl.message.update.Ipv6NlriParser;
31 import org.opendaylight.protocol.bgp.parser.impl.message.update.LocalPreferenceAttributeParser;
32 import org.opendaylight.protocol.bgp.parser.impl.message.update.MPReachAttributeParser;
33 import org.opendaylight.protocol.bgp.parser.impl.message.update.MPUnreachAttributeParser;
34 import org.opendaylight.protocol.bgp.parser.impl.message.update.MultiExitDiscriminatorAttributeParser;
35 import org.opendaylight.protocol.bgp.parser.impl.message.update.NextHopAttributeParser;
36 import org.opendaylight.protocol.bgp.parser.impl.message.update.OriginAttributeParser;
37 import org.opendaylight.protocol.bgp.parser.impl.message.update.OriginatorIdAttributeParser;
38 import org.opendaylight.protocol.bgp.parser.impl.message.update.WithdrawnRoutesSerializer;
39 import org.opendaylight.protocol.bgp.parser.spi.AbstractBGPExtensionProviderActivator;
40 import org.opendaylight.protocol.bgp.parser.spi.AddressFamilyRegistry;
41 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
42 import org.opendaylight.protocol.bgp.parser.spi.NlriRegistry;
43 import org.opendaylight.protocol.bgp.parser.spi.SubsequentAddressFamilyRegistry;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Keepalive;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Notify;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Open;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.BgpParameters;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.bgp.parameters.optional.capabilities.c.parameters.As4BytesCase;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Aggregator;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AsPath;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AtomicAggregate;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.ClusterId;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Communities;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.ExtendedCommunities;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.LocalPref;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.MultiExitDisc;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Origin;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.OriginatorId;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.WithdrawnRoutes;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.optional.capabilities.c.parameters.GracefulRestartCase;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.optional.capabilities.c.parameters.MultiprotocolCase;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpReachNlri;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpUnreachNlri;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.mp.reach.nlri.AdvertizedRoutes;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.MplsLabeledVpnSubsequentAddressFamily;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.NextHop;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
72 public final class BGPActivator extends AbstractBGPExtensionProviderActivator {
74 private static final int IPV4_AFI = 1;
75 private static final int IPV6_AFI = 2;
77 private static final int UNICAST_SAFI = 1;
78 private static final int VPN_SAFI = 128;
81 protected List<AutoCloseable> startImpl(final BGPExtensionProviderContext context) {
82 final List<AutoCloseable> regs = new ArrayList<>();
84 regs.add(context.registerNlriSerializer(AdvertizedRoutes.class, new AdvertizedRoutesSerializer()));
85 regs.add(context.registerNlriSerializer(WithdrawnRoutes.class, new WithdrawnRoutesSerializer()));
87 regs.add(context.registerAddressFamily(Ipv4AddressFamily.class, IPV4_AFI));
88 regs.add(context.registerAddressFamily(Ipv6AddressFamily.class, IPV6_AFI));
90 regs.add(context.registerSubsequentAddressFamily(UnicastSubsequentAddressFamily.class, UNICAST_SAFI));
91 regs.add(context.registerSubsequentAddressFamily(MplsLabeledVpnSubsequentAddressFamily.class, VPN_SAFI));
93 regs.add(context.registerNlriParser(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, new Ipv4NlriParser()));
94 regs.add(context.registerNlriParser(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class, new Ipv6NlriParser()));
96 this.registerCapabilityParsers(regs, context);
97 this.registerAttributeParsers(regs, context);
98 this.registerMessageParsers(regs, context);
102 private void registerCapabilityParsers(final List<AutoCloseable> regs, final BGPExtensionProviderContext context) {
103 final AddressFamilyRegistry afiReg = context.getAddressFamilyRegistry();
104 final SubsequentAddressFamilyRegistry safiReg = context.getSubsequentAddressFamilyRegistry();
106 final MultiProtocolCapabilityHandler multi = new MultiProtocolCapabilityHandler(afiReg, safiReg);
107 regs.add(context.registerCapabilityParser(MultiProtocolCapabilityHandler.CODE, multi));
108 regs.add(context.registerCapabilitySerializer(MultiprotocolCase.class, multi));
110 final As4CapabilityHandler as4 = new As4CapabilityHandler();
111 regs.add(context.registerCapabilityParser(As4CapabilityHandler.CODE, as4));
112 regs.add(context.registerCapabilitySerializer(As4BytesCase.class, as4));
114 final GracefulCapabilityHandler grace = new GracefulCapabilityHandler(afiReg, safiReg);
115 regs.add(context.registerCapabilitySerializer(GracefulRestartCase.class, grace));
116 regs.add(context.registerCapabilityParser(GracefulCapabilityHandler.CODE, grace));
118 final CapabilityParameterParser cpp = new CapabilityParameterParser(context.getCapabilityRegistry());
119 regs.add(context.registerParameterParser(CapabilityParameterParser.TYPE, cpp));
120 regs.add(context.registerParameterSerializer(BgpParameters.class, cpp));
123 private void registerAttributeParsers(final List<AutoCloseable> regs, final BGPExtensionProviderContext context) {
124 final OriginAttributeParser originAttributeParser = new OriginAttributeParser();
125 regs.add(context.registerAttributeSerializer(Origin.class, originAttributeParser));
126 regs.add(context.registerAttributeParser(OriginAttributeParser.TYPE, originAttributeParser));
128 final AsPathAttributeParser asPathAttributeParser = new AsPathAttributeParser(context.getReferenceCache());
129 regs.add(context.registerAttributeSerializer(AsPath.class, asPathAttributeParser));
130 regs.add(context.registerAttributeParser(AsPathAttributeParser.TYPE, asPathAttributeParser));
132 final NextHopAttributeParser nextHopAttributeParser = new NextHopAttributeParser();
133 regs.add(context.registerAttributeSerializer(NextHop.class, nextHopAttributeParser));
134 regs.add(context.registerAttributeParser(NextHopAttributeParser.TYPE, nextHopAttributeParser));
136 final MultiExitDiscriminatorAttributeParser multiExitDiscriminatorAttributeParser = new MultiExitDiscriminatorAttributeParser();
137 regs.add(context.registerAttributeSerializer(MultiExitDisc.class, multiExitDiscriminatorAttributeParser));
138 regs.add(context.registerAttributeParser(MultiExitDiscriminatorAttributeParser.TYPE, multiExitDiscriminatorAttributeParser));
140 final LocalPreferenceAttributeParser localPreferenceAttributeParser = new LocalPreferenceAttributeParser();
141 regs.add(context.registerAttributeSerializer(LocalPref.class, localPreferenceAttributeParser));
142 regs.add(context.registerAttributeParser(LocalPreferenceAttributeParser.TYPE, localPreferenceAttributeParser));
144 final AtomicAggregateAttributeParser atomicAggregateAttributeParser = new AtomicAggregateAttributeParser();
145 regs.add(context.registerAttributeSerializer(AtomicAggregate.class, atomicAggregateAttributeParser));
146 regs.add(context.registerAttributeParser(AtomicAggregateAttributeParser.TYPE, atomicAggregateAttributeParser));
148 final AggregatorAttributeParser as4AggregatorAttributeParser = new AggregatorAttributeParser(context.getReferenceCache());
149 regs.add(context.registerAttributeSerializer(Aggregator.class, as4AggregatorAttributeParser));
150 regs.add(context.registerAttributeParser(AggregatorAttributeParser.TYPE, as4AggregatorAttributeParser));
152 final CommunitiesAttributeParser communitiesAttributeParser = new CommunitiesAttributeParser(context.getReferenceCache());
153 regs.add(context.registerAttributeSerializer(Communities.class, communitiesAttributeParser));
154 regs.add(context.registerAttributeParser(CommunitiesAttributeParser.TYPE, communitiesAttributeParser));
156 final OriginatorIdAttributeParser originatorIdAttributeParser = new OriginatorIdAttributeParser();
157 regs.add(context.registerAttributeSerializer(OriginatorId.class, originatorIdAttributeParser));
158 regs.add(context.registerAttributeParser(OriginatorIdAttributeParser.TYPE, originatorIdAttributeParser));
160 final ClusterIdAttributeParser clusterIdAttributeParser = new ClusterIdAttributeParser();
161 regs.add(context.registerAttributeSerializer(ClusterId.class, clusterIdAttributeParser));
162 regs.add(context.registerAttributeParser(ClusterIdAttributeParser.TYPE, clusterIdAttributeParser));
164 final NlriRegistry nlriReg = context.getNlriRegistry();
166 final MPReachAttributeParser mpReachAttributeParser = new MPReachAttributeParser(nlriReg);
167 regs.add(context.registerAttributeSerializer(MpReachNlri.class, mpReachAttributeParser));
168 regs.add(context.registerAttributeParser(MPReachAttributeParser.TYPE, mpReachAttributeParser));
170 final MPUnreachAttributeParser mpUnreachAttributeParser = new MPUnreachAttributeParser(nlriReg);
171 regs.add(context.registerAttributeSerializer(MpUnreachNlri.class, mpUnreachAttributeParser));
172 regs.add(context.registerAttributeParser(MPUnreachAttributeParser.TYPE, mpUnreachAttributeParser));
174 final ExtendedCommunitiesAttributeParser extendedCommunitiesAttributeParser = new ExtendedCommunitiesAttributeParser(context.getReferenceCache());
175 regs.add(context.registerAttributeSerializer(ExtendedCommunities.class, extendedCommunitiesAttributeParser));
176 regs.add(context.registerAttributeParser(ExtendedCommunitiesAttributeParser.TYPE, extendedCommunitiesAttributeParser));
178 regs.add(context.registerAttributeParser(AS4AggregatorAttributeParser.TYPE, new AS4AggregatorAttributeParser()));
179 regs.add(context.registerAttributeParser(AS4PathAttributeParser.TYPE, new AS4PathAttributeParser()));
182 private void registerMessageParsers(final List<AutoCloseable> regs, final BGPExtensionProviderContext context) {
183 final BGPOpenMessageParser omp = new BGPOpenMessageParser(context.getParameterRegistry());
184 regs.add(context.registerMessageParser(BGPOpenMessageParser.TYPE, omp));
185 regs.add(context.registerMessageSerializer(Open.class, omp));
187 final BGPUpdateMessageParser ump = new BGPUpdateMessageParser(context.getAttributeRegistry());
188 regs.add(context.registerMessageParser(BGPUpdateMessageParser.TYPE, ump));
189 regs.add(context.registerMessageSerializer(Update.class, ump));
191 final BGPNotificationMessageParser nmp = new BGPNotificationMessageParser();
192 regs.add(context.registerMessageParser(BGPNotificationMessageParser.TYPE, nmp));
193 regs.add(context.registerMessageSerializer(Notify.class, nmp));
195 final BGPKeepAliveMessageParser kamp = new BGPKeepAliveMessageParser();
196 regs.add(context.registerMessageParser(BGPKeepAliveMessageParser.TYPE, kamp));
197 regs.add(context.registerMessageSerializer(Keepalive.class, kamp));