d25d56a4077388f8e54eb8159ecb509f003491ec
[bgpcep.git] / bgp / parser-impl / src / main / java / org / opendaylight / protocol / bgp / parser / impl / BGPActivator.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.bgp.parser.impl;
9
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.BGPRouteRefreshMessageParser;
16 import org.opendaylight.protocol.bgp.parser.impl.message.BGPUpdateMessageParser;
17 import org.opendaylight.protocol.bgp.parser.impl.message.open.AddPathCapabilityHandler;
18 import org.opendaylight.protocol.bgp.parser.impl.message.open.As4CapabilityHandler;
19 import org.opendaylight.protocol.bgp.parser.impl.message.open.BgpExtendedMessageCapabilityHandler;
20 import org.opendaylight.protocol.bgp.parser.impl.message.open.CapabilityParameterParser;
21 import org.opendaylight.protocol.bgp.parser.impl.message.open.GracefulCapabilityHandler;
22 import org.opendaylight.protocol.bgp.parser.impl.message.open.MultiProtocolCapabilityHandler;
23 import org.opendaylight.protocol.bgp.parser.impl.message.open.RouteRefreshCapabilityHandler;
24 import org.opendaylight.protocol.bgp.parser.impl.message.update.AS4AggregatorAttributeParser;
25 import org.opendaylight.protocol.bgp.parser.impl.message.update.AS4PathAttributeParser;
26 import org.opendaylight.protocol.bgp.parser.impl.message.update.AdvertizedRoutesSerializer;
27 import org.opendaylight.protocol.bgp.parser.impl.message.update.AggregatorAttributeParser;
28 import org.opendaylight.protocol.bgp.parser.impl.message.update.AigpAttributeParser;
29 import org.opendaylight.protocol.bgp.parser.impl.message.update.AsPathAttributeParser;
30 import org.opendaylight.protocol.bgp.parser.impl.message.update.AtomicAggregateAttributeParser;
31 import org.opendaylight.protocol.bgp.parser.impl.message.update.BgpPrefixSidAttributeParser;
32 import org.opendaylight.protocol.bgp.parser.impl.message.update.ClusterIdAttributeParser;
33 import org.opendaylight.protocol.bgp.parser.impl.message.update.CommunitiesAttributeParser;
34 import org.opendaylight.protocol.bgp.parser.impl.message.update.ExtendedCommunitiesAttributeParser;
35 import org.opendaylight.protocol.bgp.parser.impl.message.update.Ipv4NlriParser;
36 import org.opendaylight.protocol.bgp.parser.impl.message.update.Ipv6NlriParser;
37 import org.opendaylight.protocol.bgp.parser.impl.message.update.LocalPreferenceAttributeParser;
38 import org.opendaylight.protocol.bgp.parser.impl.message.update.MPReachAttributeParser;
39 import org.opendaylight.protocol.bgp.parser.impl.message.update.MPUnreachAttributeParser;
40 import org.opendaylight.protocol.bgp.parser.impl.message.update.MultiExitDiscriminatorAttributeParser;
41 import org.opendaylight.protocol.bgp.parser.impl.message.update.NextHopAttributeParser;
42 import org.opendaylight.protocol.bgp.parser.impl.message.update.OriginAttributeParser;
43 import org.opendaylight.protocol.bgp.parser.impl.message.update.OriginatorIdAttributeParser;
44 import org.opendaylight.protocol.bgp.parser.impl.message.update.UnrecognizedAttributesSerializer;
45 import org.opendaylight.protocol.bgp.parser.impl.message.update.WithdrawnRoutesSerializer;
46 import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.AsTwoOctetSpecificEcHandler;
47 import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.EncapsulationEC;
48 import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.Ipv4SpecificEcHandler;
49 import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.LinkBandwidthEC;
50 import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.OpaqueEcHandler;
51 import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.RouteOriginAsTwoOctetEcHandler;
52 import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.RouteOriginIpv4EcHandler;
53 import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.RouteTargetAsTwoOctetEcHandler;
54 import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.RouteTargetIpv4EcHandler;
55 import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.four.octect.as.specific.Generic4OctASEcHandler;
56 import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.four.octect.as.specific.RouteOrigin4OctectASEcHandler;
57 import org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.four.octect.as.specific.RouteTarget4OctectASEcHandler;
58 import org.opendaylight.protocol.bgp.parser.impl.message.update.next.hop.Ipv4NextHopParserSerializer;
59 import org.opendaylight.protocol.bgp.parser.impl.message.update.next.hop.Ipv6NextHopParserSerializer;
60 import org.opendaylight.protocol.bgp.parser.spi.AbstractBGPExtensionProviderActivator;
61 import org.opendaylight.protocol.bgp.parser.spi.AddressFamilyRegistry;
62 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
63 import org.opendaylight.protocol.bgp.parser.spi.NlriRegistry;
64 import org.opendaylight.protocol.bgp.parser.spi.SubsequentAddressFamilyRegistry;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Keepalive;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Notify;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Open;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.BgpParameters;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.bgp.parameters.optional.capabilities.c.parameters.As4BytesCapability;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.bgp.parameters.optional.capabilities.c.parameters.BgpExtendedMessageCapability;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.Aggregator;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.Aigp;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.AsPath;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.AtomicAggregate;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.BgpPrefixSid;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.ClusterId;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.Communities;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.ExtendedCommunities;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.LocalPref;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.MultiExitDisc;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.Origin;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.OriginatorId;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.UnrecognizedAttributes;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.message.WithdrawnRoutes;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.RouteRefresh;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.mp.capabilities.AddPathCapability;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.mp.capabilities.GracefulRestartCapability;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.mp.capabilities.MultiprotocolCapability;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.mp.capabilities.RouteRefreshCapability;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpReachNlri;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpUnreachNlri;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutes;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.MplsLabeledVpnSubsequentAddressFamily;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.NextHop;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.As4GenericSpecExtendedCommunityCase;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.As4RouteOriginExtendedCommunityCase;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.As4RouteTargetExtendedCommunityCase;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.AsSpecificExtendedCommunityCase;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.EncapsulationCase;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.Inet4SpecificExtendedCommunityCase;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.LinkBandwidthCase;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.OpaqueExtendedCommunityCase;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.RouteOriginExtendedCommunityCase;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.RouteOriginIpv4Case;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.RouteTargetExtendedCommunityCase;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.RouteTargetIpv4Case;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCase;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv6NextHopCase;
113
114 public final class BGPActivator extends AbstractBGPExtensionProviderActivator {
115
116     private static final int IPV4_AFI = 1;
117     private static final int IPV6_AFI = 2;
118
119     private static final int UNICAST_SAFI = 1;
120     private static final int VPN_SAFI = 128;
121
122     @Override
123     protected List<AutoCloseable> startImpl(final BGPExtensionProviderContext context) {
124         final List<AutoCloseable> regs = new ArrayList<>();
125
126         regs.add(context.registerNlriSerializer(AdvertizedRoutes.class, new AdvertizedRoutesSerializer()));
127         regs.add(context.registerNlriSerializer(WithdrawnRoutes.class, new WithdrawnRoutesSerializer()));
128
129         regs.add(context.registerAddressFamily(Ipv4AddressFamily.class, IPV4_AFI));
130         regs.add(context.registerAddressFamily(Ipv6AddressFamily.class, IPV6_AFI));
131
132         regs.add(context.registerSubsequentAddressFamily(UnicastSubsequentAddressFamily.class, UNICAST_SAFI));
133         regs.add(context.registerSubsequentAddressFamily(MplsLabeledVpnSubsequentAddressFamily.class, VPN_SAFI));
134
135         final Ipv4NextHopParserSerializer ipv4NextHopParser = new Ipv4NextHopParserSerializer();
136         regs.add(context.registerNlriParser(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class,
137             new Ipv4NlriParser(), ipv4NextHopParser, Ipv4NextHopCase.class, Ipv6NextHopCase.class));
138
139         final Ipv6NextHopParserSerializer ipv6NextHopParser = new Ipv6NextHopParserSerializer();
140         regs.add(context.registerNlriParser(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class, new
141             Ipv6NlriParser(), ipv6NextHopParser, Ipv4NextHopCase.class, Ipv6NextHopCase.class));
142
143         this.registerExtendedCommunities(regs, context);
144         this.registerCapabilityParsers(regs, context);
145         this.registerAttributeParsers(regs, context);
146         this.registerMessageParsers(regs, context);
147         return regs;
148     }
149
150     private void registerCapabilityParsers(final List<AutoCloseable> regs, final BGPExtensionProviderContext context) {
151         final AddressFamilyRegistry afiReg = context.getAddressFamilyRegistry();
152         final SubsequentAddressFamilyRegistry safiReg = context.getSubsequentAddressFamilyRegistry();
153
154         final MultiProtocolCapabilityHandler multi = new MultiProtocolCapabilityHandler(afiReg, safiReg);
155         regs.add(context.registerCapabilityParser(MultiProtocolCapabilityHandler.CODE, multi));
156         regs.add(context.registerCapabilitySerializer(MultiprotocolCapability.class, multi));
157
158         final AddPathCapabilityHandler addPath = new AddPathCapabilityHandler(afiReg, safiReg);
159         regs.add(context.registerCapabilityParser(AddPathCapabilityHandler.CODE, addPath));
160         regs.add(context.registerCapabilitySerializer(AddPathCapability.class, addPath));
161
162         final RouteRefreshCapabilityHandler routeRefresh = new RouteRefreshCapabilityHandler();
163         regs.add(context.registerCapabilityParser(RouteRefreshCapabilityHandler.CODE, routeRefresh));
164         regs.add(context.registerCapabilitySerializer(RouteRefreshCapability.class, routeRefresh));
165
166         final As4CapabilityHandler as4 = new As4CapabilityHandler();
167         regs.add(context.registerCapabilityParser(As4CapabilityHandler.CODE, as4));
168         regs.add(context.registerCapabilitySerializer(As4BytesCapability.class, as4));
169
170         final GracefulCapabilityHandler grace = new GracefulCapabilityHandler(afiReg, safiReg);
171         regs.add(context.registerCapabilitySerializer(GracefulRestartCapability.class, grace));
172         regs.add(context.registerCapabilityParser(GracefulCapabilityHandler.CODE, grace));
173
174         final CapabilityParameterParser cpp = new CapabilityParameterParser(context.getCapabilityRegistry());
175         regs.add(context.registerParameterParser(CapabilityParameterParser.TYPE, cpp));
176         regs.add(context.registerParameterSerializer(BgpParameters.class, cpp));
177
178         final BgpExtendedMessageCapabilityHandler bgpextmessage = new BgpExtendedMessageCapabilityHandler();
179         regs.add(context.registerCapabilityParser(BgpExtendedMessageCapabilityHandler.CODE, bgpextmessage));
180         regs.add(context.registerCapabilitySerializer(BgpExtendedMessageCapability.class, bgpextmessage));
181     }
182
183     private void registerAttributeParsers(final List<AutoCloseable> regs, final BGPExtensionProviderContext context) {
184         final BgpPrefixSidAttributeParser prefixSidAttributeParser = new BgpPrefixSidAttributeParser(context.getBgpPrefixSidTlvRegistry());
185         regs.add(context.registerAttributeSerializer(BgpPrefixSid.class, prefixSidAttributeParser));
186         regs.add(context.registerAttributeParser(BgpPrefixSidAttributeParser.TYPE, prefixSidAttributeParser));
187
188         final OriginAttributeParser originAttributeParser = new OriginAttributeParser();
189         regs.add(context.registerAttributeSerializer(Origin.class, originAttributeParser));
190         regs.add(context.registerAttributeParser(OriginAttributeParser.TYPE, originAttributeParser));
191
192         final AigpAttributeParser aigpAttributeParser = new AigpAttributeParser();
193         regs.add(context.registerAttributeSerializer(Aigp.class, aigpAttributeParser));
194         regs.add(context.registerAttributeParser(AigpAttributeParser.TYPE, aigpAttributeParser));
195
196         final AsPathAttributeParser asPathAttributeParser = new AsPathAttributeParser(context.getReferenceCache());
197         regs.add(context.registerAttributeSerializer(AsPath.class, asPathAttributeParser));
198         regs.add(context.registerAttributeParser(AsPathAttributeParser.TYPE, asPathAttributeParser));
199
200         final NextHopAttributeParser nextHopAttributeParser = new NextHopAttributeParser();
201         regs.add(context.registerAttributeSerializer(NextHop.class, nextHopAttributeParser));
202         regs.add(context.registerAttributeParser(NextHopAttributeParser.TYPE, nextHopAttributeParser));
203
204         final MultiExitDiscriminatorAttributeParser multiExitDiscriminatorAttributeParser = new MultiExitDiscriminatorAttributeParser();
205         regs.add(context.registerAttributeSerializer(MultiExitDisc.class, multiExitDiscriminatorAttributeParser));
206         regs.add(context.registerAttributeParser(MultiExitDiscriminatorAttributeParser.TYPE, multiExitDiscriminatorAttributeParser));
207
208         final LocalPreferenceAttributeParser localPreferenceAttributeParser = new LocalPreferenceAttributeParser();
209         regs.add(context.registerAttributeSerializer(LocalPref.class, localPreferenceAttributeParser));
210         regs.add(context.registerAttributeParser(LocalPreferenceAttributeParser.TYPE, localPreferenceAttributeParser));
211
212         final AtomicAggregateAttributeParser atomicAggregateAttributeParser = new AtomicAggregateAttributeParser();
213         regs.add(context.registerAttributeSerializer(AtomicAggregate.class, atomicAggregateAttributeParser));
214         regs.add(context.registerAttributeParser(AtomicAggregateAttributeParser.TYPE, atomicAggregateAttributeParser));
215
216         final AggregatorAttributeParser as4AggregatorAttributeParser = new AggregatorAttributeParser(context.getReferenceCache());
217         regs.add(context.registerAttributeSerializer(Aggregator.class, as4AggregatorAttributeParser));
218         regs.add(context.registerAttributeParser(AggregatorAttributeParser.TYPE, as4AggregatorAttributeParser));
219
220         final CommunitiesAttributeParser communitiesAttributeParser = new CommunitiesAttributeParser(context.getReferenceCache());
221         regs.add(context.registerAttributeSerializer(Communities.class, communitiesAttributeParser));
222         regs.add(context.registerAttributeParser(CommunitiesAttributeParser.TYPE, communitiesAttributeParser));
223
224         final OriginatorIdAttributeParser originatorIdAttributeParser = new OriginatorIdAttributeParser();
225         regs.add(context.registerAttributeSerializer(OriginatorId.class, originatorIdAttributeParser));
226         regs.add(context.registerAttributeParser(OriginatorIdAttributeParser.TYPE, originatorIdAttributeParser));
227
228         final ClusterIdAttributeParser clusterIdAttributeParser = new ClusterIdAttributeParser();
229         regs.add(context.registerAttributeSerializer(ClusterId.class, clusterIdAttributeParser));
230         regs.add(context.registerAttributeParser(ClusterIdAttributeParser.TYPE, clusterIdAttributeParser));
231
232         final NlriRegistry nlriReg = context.getNlriRegistry();
233
234         final MPReachAttributeParser mpReachAttributeParser = new MPReachAttributeParser(nlriReg);
235         regs.add(context.registerAttributeSerializer(MpReachNlri.class, mpReachAttributeParser));
236         regs.add(context.registerAttributeParser(MPReachAttributeParser.TYPE, mpReachAttributeParser));
237
238         final MPUnreachAttributeParser mpUnreachAttributeParser = new MPUnreachAttributeParser(nlriReg);
239         regs.add(context.registerAttributeSerializer(MpUnreachNlri.class, mpUnreachAttributeParser));
240         regs.add(context.registerAttributeParser(MPUnreachAttributeParser.TYPE, mpUnreachAttributeParser));
241
242         final ExtendedCommunitiesAttributeParser extendedCommunitiesAttributeParser = new ExtendedCommunitiesAttributeParser(context.getExtendedCommunityReistry());
243         regs.add(context.registerAttributeSerializer(ExtendedCommunities.class, extendedCommunitiesAttributeParser));
244         regs.add(context.registerAttributeParser(ExtendedCommunitiesAttributeParser.TYPE, extendedCommunitiesAttributeParser));
245
246         regs.add(context.registerAttributeParser(AS4AggregatorAttributeParser.TYPE, new AS4AggregatorAttributeParser()));
247         regs.add(context.registerAttributeParser(AS4PathAttributeParser.TYPE, new AS4PathAttributeParser()));
248
249         regs.add(context.registerAttributeSerializer(UnrecognizedAttributes.class, new UnrecognizedAttributesSerializer()));
250     }
251
252     private void registerMessageParsers(final List<AutoCloseable> regs, final BGPExtensionProviderContext context) {
253         final BGPOpenMessageParser omp = new BGPOpenMessageParser(context.getParameterRegistry());
254         regs.add(context.registerMessageParser(BGPOpenMessageParser.TYPE, omp));
255         regs.add(context.registerMessageSerializer(Open.class, omp));
256
257         final BGPUpdateMessageParser ump = new BGPUpdateMessageParser(context.getAttributeRegistry());
258         regs.add(context.registerMessageParser(BGPUpdateMessageParser.TYPE, ump));
259         regs.add(context.registerMessageSerializer(Update.class, ump));
260
261         final BGPNotificationMessageParser nmp = new BGPNotificationMessageParser();
262         regs.add(context.registerMessageParser(BGPNotificationMessageParser.TYPE, nmp));
263         regs.add(context.registerMessageSerializer(Notify.class, nmp));
264
265         final BGPKeepAliveMessageParser kamp = new BGPKeepAliveMessageParser();
266         regs.add(context.registerMessageParser(BGPKeepAliveMessageParser.TYPE, kamp));
267         regs.add(context.registerMessageSerializer(Keepalive.class, kamp));
268
269         final AddressFamilyRegistry afiReg = context.getAddressFamilyRegistry();
270         final SubsequentAddressFamilyRegistry safiReg = context.getSubsequentAddressFamilyRegistry();
271         final BGPRouteRefreshMessageParser rrmp = new BGPRouteRefreshMessageParser(afiReg, safiReg);
272         regs.add(context.registerMessageParser(BGPRouteRefreshMessageParser.TYPE, rrmp));
273         regs.add(context.registerMessageSerializer(RouteRefresh.class, rrmp));
274     }
275
276     private void registerExtendedCommunities(final List<AutoCloseable> regs, final BGPExtensionProviderContext context) {
277         final AsTwoOctetSpecificEcHandler twoOctetSpecificEcHandler = new AsTwoOctetSpecificEcHandler();
278         regs.add(context.registerExtendedCommunityParser(twoOctetSpecificEcHandler.getType(true), twoOctetSpecificEcHandler.getSubType(),
279             twoOctetSpecificEcHandler));
280         regs.add(context.registerExtendedCommunityParser(twoOctetSpecificEcHandler.getType(false), twoOctetSpecificEcHandler.getSubType(),
281             twoOctetSpecificEcHandler));
282         regs.add(context.registerExtendedCommunitySerializer(AsSpecificExtendedCommunityCase.class, twoOctetSpecificEcHandler));
283
284         final Ipv4SpecificEcHandler ipv4SpecificEcHandler = new Ipv4SpecificEcHandler();
285         regs.add(context.registerExtendedCommunityParser(ipv4SpecificEcHandler.getType(true), ipv4SpecificEcHandler.getSubType(),
286             ipv4SpecificEcHandler));
287         regs.add(context.registerExtendedCommunityParser(ipv4SpecificEcHandler.getType(false), ipv4SpecificEcHandler.getSubType(),
288             ipv4SpecificEcHandler));
289         regs.add(context.registerExtendedCommunitySerializer(Inet4SpecificExtendedCommunityCase.class, ipv4SpecificEcHandler));
290
291         final OpaqueEcHandler opaqueEcHandler = new OpaqueEcHandler();
292         regs.add(context.registerExtendedCommunityParser(opaqueEcHandler.getType(true), opaqueEcHandler.getSubType(),
293             opaqueEcHandler));
294         regs.add(context.registerExtendedCommunityParser(opaqueEcHandler.getType(false), opaqueEcHandler.getSubType(),
295             opaqueEcHandler));
296         regs.add(context.registerExtendedCommunitySerializer(OpaqueExtendedCommunityCase.class, opaqueEcHandler));
297
298         final RouteOriginAsTwoOctetEcHandler routeOriginAS2bEcHandler = new RouteOriginAsTwoOctetEcHandler();
299         regs.add(context.registerExtendedCommunityParser(routeOriginAS2bEcHandler.getType(true), routeOriginAS2bEcHandler.getSubType(),
300             routeOriginAS2bEcHandler));
301         regs.add(context.registerExtendedCommunityParser(routeOriginAS2bEcHandler.getType(false), routeOriginAS2bEcHandler.getSubType(),
302             routeOriginAS2bEcHandler));
303         regs.add(context.registerExtendedCommunitySerializer(RouteOriginExtendedCommunityCase.class, routeOriginAS2bEcHandler));
304
305         final RouteTargetAsTwoOctetEcHandler routeTargetAS2bEcHandler = new RouteTargetAsTwoOctetEcHandler();
306         regs.add(context.registerExtendedCommunityParser(routeTargetAS2bEcHandler.getType(true), routeTargetAS2bEcHandler.getSubType(),
307             routeTargetAS2bEcHandler));
308         regs.add(context.registerExtendedCommunityParser(routeTargetAS2bEcHandler.getType(false), routeTargetAS2bEcHandler.getSubType(),
309             routeTargetAS2bEcHandler));
310         regs.add(context.registerExtendedCommunitySerializer(RouteTargetExtendedCommunityCase.class, routeTargetAS2bEcHandler));
311
312         final RouteOriginIpv4EcHandler routeOriginIpv4EcHandler = new RouteOriginIpv4EcHandler();
313         regs.add(context.registerExtendedCommunityParser(routeOriginIpv4EcHandler.getType(true), routeOriginIpv4EcHandler.getSubType(),
314             routeOriginIpv4EcHandler));
315         regs.add(context.registerExtendedCommunityParser(routeOriginIpv4EcHandler.getType(false), routeOriginIpv4EcHandler.getSubType(),
316             routeOriginIpv4EcHandler));
317         regs.add(context.registerExtendedCommunitySerializer(RouteOriginIpv4Case.class, routeOriginIpv4EcHandler));
318
319         final RouteTargetIpv4EcHandler routeTargetIpv4EcHandler = new RouteTargetIpv4EcHandler();
320         regs.add(context.registerExtendedCommunityParser(routeTargetIpv4EcHandler.getType(true), routeTargetIpv4EcHandler.getSubType(),
321             routeTargetIpv4EcHandler));
322         regs.add(context.registerExtendedCommunityParser(routeTargetIpv4EcHandler.getType(false), routeTargetIpv4EcHandler.getSubType(),
323             routeTargetIpv4EcHandler));
324         regs.add(context.registerExtendedCommunitySerializer(RouteTargetIpv4Case.class, routeTargetIpv4EcHandler));
325
326         final LinkBandwidthEC linkBandwidthECHandler = new LinkBandwidthEC();
327         regs.add(context.registerExtendedCommunityParser(linkBandwidthECHandler.getType(false), linkBandwidthECHandler.getSubType(),
328             linkBandwidthECHandler));
329         regs.add(context.registerExtendedCommunitySerializer(LinkBandwidthCase.class, linkBandwidthECHandler));
330
331         final Generic4OctASEcHandler gen4OctASEcHandler = new Generic4OctASEcHandler();
332         regs.add(context.registerExtendedCommunityParser(gen4OctASEcHandler.getType(true), gen4OctASEcHandler.getSubType(), gen4OctASEcHandler));
333         regs.add(context.registerExtendedCommunityParser(gen4OctASEcHandler.getType(false), gen4OctASEcHandler.getSubType(), gen4OctASEcHandler));
334         regs.add(context.registerExtendedCommunitySerializer(As4GenericSpecExtendedCommunityCase.class, gen4OctASEcHandler));
335
336         final RouteTarget4OctectASEcHandler rt4ASHandler = new RouteTarget4OctectASEcHandler();
337         regs.add(context.registerExtendedCommunityParser(rt4ASHandler.getType(true), rt4ASHandler.getSubType(), rt4ASHandler));
338         regs.add(context.registerExtendedCommunitySerializer(As4RouteTargetExtendedCommunityCase.class, rt4ASHandler));
339
340         final RouteOrigin4OctectASEcHandler rOrig4Oct = new RouteOrigin4OctectASEcHandler();
341         regs.add(context.registerExtendedCommunityParser(rOrig4Oct.getType(true), rOrig4Oct.getSubType(), rOrig4Oct));
342         regs.add(context.registerExtendedCommunitySerializer(As4RouteOriginExtendedCommunityCase.class, rOrig4Oct));
343
344         final EncapsulationEC encapsulationECHandler = new EncapsulationEC();
345         regs.add(context.registerExtendedCommunityParser(encapsulationECHandler.getType(true), encapsulationECHandler.getSubType(),
346                 encapsulationECHandler));
347         regs.add(context.registerExtendedCommunitySerializer(EncapsulationCase.class, encapsulationECHandler));
348     }
349 }