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;
13 import org.opendaylight.protocol.bgp.parser.impl.message.BGPKeepAliveMessageParser;
14 import org.opendaylight.protocol.bgp.parser.impl.message.BGPNotificationMessageParser;
15 import org.opendaylight.protocol.bgp.parser.impl.message.BGPOpenMessageParser;
16 import org.opendaylight.protocol.bgp.parser.impl.message.BGPUpdateMessageParser;
17 import org.opendaylight.protocol.bgp.parser.impl.message.open.As4CapabilityHandler;
18 import org.opendaylight.protocol.bgp.parser.impl.message.open.CapabilityParameterParser;
19 import org.opendaylight.protocol.bgp.parser.impl.message.open.GracefulCapabilityHandler;
20 import org.opendaylight.protocol.bgp.parser.impl.message.open.MultiProtocolCapabilityHandler;
21 import org.opendaylight.protocol.bgp.parser.impl.message.update.AS4AggregatorAttributeParser;
22 import org.opendaylight.protocol.bgp.parser.impl.message.update.AS4PathAttributeParser;
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.spi.AbstractBGPExtensionProviderActivator;
39 import org.opendaylight.protocol.bgp.parser.spi.AddressFamilyRegistry;
40 import org.opendaylight.protocol.bgp.parser.spi.AttributeRegistry;
41 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
42 import org.opendaylight.protocol.bgp.parser.spi.CapabilityRegistry;
43 import org.opendaylight.protocol.bgp.parser.spi.NlriRegistry;
44 import org.opendaylight.protocol.bgp.parser.spi.ParameterRegistry;
45 import org.opendaylight.protocol.bgp.parser.spi.SubsequentAddressFamilyRegistry;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Keepalive;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Notify;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Open;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.BgpParameters;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.bgp.parameters.c.parameters.As4BytesCase;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Aggregator;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AsPath;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AtomicAggregate;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Communities;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.ExtendedCommunities;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.LocalPref;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.MultiExitDisc;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Origin;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.c.parameters.GracefulRestartCase;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.c.parameters.MultiprotocolCase;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.MplsLabeledVpnSubsequentAddressFamily;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.NextHop;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
68 public final class BGPActivator extends AbstractBGPExtensionProviderActivator {
71 protected List<AutoCloseable> startImpl(final BGPExtensionProviderContext context) {
72 final List<AutoCloseable> regs = new ArrayList<>();
74 final AddressFamilyRegistry afiReg = context.getAddressFamilyRegistry();
75 regs.add(context.registerAddressFamily(Ipv4AddressFamily.class, 1));
76 regs.add(context.registerAddressFamily(Ipv6AddressFamily.class, 2));
78 final SubsequentAddressFamilyRegistry safiReg = context.getSubsequentAddressFamilyRegistry();
79 regs.add(context.registerSubsequentAddressFamily(UnicastSubsequentAddressFamily.class, 1));
80 regs.add(context.registerSubsequentAddressFamily(MplsLabeledVpnSubsequentAddressFamily.class, 128));
82 regs.add(context.registerNlriParser(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, new Ipv4NlriParser()));
83 regs.add(context.registerNlriParser(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class, new Ipv6NlriParser()));
85 final AttributeRegistry attrReg = context.getAttributeRegistry();
86 final NlriRegistry nlriReg = context.getNlriRegistry();
88 final OriginAttributeParser originAttributeParser = new OriginAttributeParser();
89 regs.add(context.registerAttributeSerializer(Origin.class, originAttributeParser));
90 regs.add(context.registerAttributeParser(OriginAttributeParser.TYPE, originAttributeParser));
92 final AsPathAttributeParser asPathAttributeParser = new AsPathAttributeParser(context.getReferenceCache());
93 regs.add(context.registerAttributeSerializer(AsPath.class, asPathAttributeParser));
94 regs.add(context.registerAttributeParser(AsPathAttributeParser.TYPE, asPathAttributeParser));
96 final NextHopAttributeParser nextHopAttributeParser = new NextHopAttributeParser();
97 regs.add(context.registerAttributeSerializer(NextHop.class, nextHopAttributeParser));
98 regs.add(context.registerAttributeParser(NextHopAttributeParser.TYPE, nextHopAttributeParser));
100 final MultiExitDiscriminatorAttributeParser multiExitDiscriminatorAttributeParser = new MultiExitDiscriminatorAttributeParser();
101 regs.add(context.registerAttributeSerializer(MultiExitDisc.class, multiExitDiscriminatorAttributeParser));
102 regs.add(context.registerAttributeParser(MultiExitDiscriminatorAttributeParser.TYPE, multiExitDiscriminatorAttributeParser));
104 final LocalPreferenceAttributeParser localPreferenceAttributeParser = new LocalPreferenceAttributeParser();
105 regs.add(context.registerAttributeSerializer(LocalPref.class, localPreferenceAttributeParser));
106 regs.add(context.registerAttributeParser(LocalPreferenceAttributeParser.TYPE, localPreferenceAttributeParser));
108 final AtomicAggregateAttributeParser atomicAggregateAttributeParser = new AtomicAggregateAttributeParser();
109 regs.add(context.registerAttributeSerializer(AtomicAggregate.class, atomicAggregateAttributeParser));
110 regs.add(context.registerAttributeParser(AtomicAggregateAttributeParser.TYPE, atomicAggregateAttributeParser));
112 final AggregatorAttributeParser as4AggregatorAttributeParser = new AggregatorAttributeParser(context.getReferenceCache());
113 regs.add(context.registerAttributeSerializer(Aggregator.class, as4AggregatorAttributeParser));
114 regs.add(context.registerAttributeParser(AggregatorAttributeParser.TYPE, as4AggregatorAttributeParser));
116 final CommunitiesAttributeParser communitiesAttributeParser = new CommunitiesAttributeParser(context.getReferenceCache());
117 regs.add(context.registerAttributeSerializer(Communities.class, communitiesAttributeParser));
118 regs.add(context.registerAttributeParser(CommunitiesAttributeParser.TYPE, communitiesAttributeParser));
120 final OriginatorIdAttributeParser originatorIdAttributeParser = new OriginatorIdAttributeParser();
121 regs.add(context.registerAttributeParser(OriginatorIdAttributeParser.TYPE, originatorIdAttributeParser));
123 final ClusterIdAttributeParser clusterIdAttributeParser = new ClusterIdAttributeParser();
124 regs.add(context.registerAttributeParser(ClusterIdAttributeParser.TYPE, clusterIdAttributeParser));
126 regs.add(context.registerAttributeParser(MPReachAttributeParser.TYPE, new MPReachAttributeParser(nlriReg)));
127 regs.add(context.registerAttributeParser(MPUnreachAttributeParser.TYPE, new MPUnreachAttributeParser(nlriReg)));
129 final ExtendedCommunitiesAttributeParser extendedCommunitiesAttributeParser = new ExtendedCommunitiesAttributeParser(context.getReferenceCache());
130 regs.add(context.registerAttributeSerializer(ExtendedCommunities.class, extendedCommunitiesAttributeParser));
131 regs.add(context.registerAttributeParser(ExtendedCommunitiesAttributeParser.TYPE, extendedCommunitiesAttributeParser));
133 regs.add(context.registerAttributeParser(AS4AggregatorAttributeParser.TYPE, new AS4AggregatorAttributeParser()));
134 regs.add(context.registerAttributeParser(AS4PathAttributeParser.TYPE, new AS4PathAttributeParser()));
136 final CapabilityRegistry capReg = context.getCapabilityRegistry();
137 final MultiProtocolCapabilityHandler multi = new MultiProtocolCapabilityHandler(afiReg, safiReg);
138 regs.add(context.registerCapabilityParser(MultiProtocolCapabilityHandler.CODE, multi));
139 regs.add(context.registerCapabilitySerializer(MultiprotocolCase.class, multi));
141 final As4CapabilityHandler as4 = new As4CapabilityHandler();
142 regs.add(context.registerCapabilityParser(As4CapabilityHandler.CODE, as4));
143 regs.add(context.registerCapabilitySerializer(As4BytesCase.class, as4));
145 final GracefulCapabilityHandler grace = new GracefulCapabilityHandler(afiReg, safiReg);
146 regs.add(context.registerCapabilitySerializer(GracefulRestartCase.class, grace));
147 regs.add(context.registerCapabilityParser(GracefulCapabilityHandler.CODE, grace));
149 final ParameterRegistry paramReg = context.getParameterRegistry();
150 final CapabilityParameterParser cpp = new CapabilityParameterParser(capReg);
151 regs.add(context.registerParameterParser(CapabilityParameterParser.TYPE, cpp));
152 regs.add(context.registerParameterSerializer(BgpParameters.class, cpp));
154 final BGPOpenMessageParser omp = new BGPOpenMessageParser(paramReg);
155 regs.add(context.registerMessageParser(BGPOpenMessageParser.TYPE, omp));
156 regs.add(context.registerMessageSerializer(Open.class, omp));
158 final BGPUpdateMessageParser ump = new BGPUpdateMessageParser(attrReg);
159 regs.add(context.registerMessageParser(BGPUpdateMessageParser.TYPE, ump));
160 regs.add(context.registerMessageSerializer(Update.class, ump));
162 final BGPNotificationMessageParser nmp = new BGPNotificationMessageParser();
163 regs.add(context.registerMessageParser(BGPNotificationMessageParser.TYPE, nmp));
164 regs.add(context.registerMessageSerializer(Notify.class, nmp));
166 final BGPKeepAliveMessageParser kamp = new BGPKeepAliveMessageParser();
167 regs.add(context.registerMessageParser(BGPKeepAliveMessageParser.TYPE, kamp));
168 regs.add(context.registerMessageSerializer(Keepalive.class, kamp));