Merge "Bug 611 - MessageUtil uses ByteBuf instead of byte[]"
[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
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.AdvertizedRoutesSerializer;
24 import org.opendaylight.protocol.bgp.parser.impl.message.update.AggregatorAttributeParser;
25 import org.opendaylight.protocol.bgp.parser.impl.message.update.AsPathAttributeParser;
26 import org.opendaylight.protocol.bgp.parser.impl.message.update.AtomicAggregateAttributeParser;
27 import org.opendaylight.protocol.bgp.parser.impl.message.update.ClusterIdAttributeParser;
28 import org.opendaylight.protocol.bgp.parser.impl.message.update.CommunitiesAttributeParser;
29 import org.opendaylight.protocol.bgp.parser.impl.message.update.ExtendedCommunitiesAttributeParser;
30 import org.opendaylight.protocol.bgp.parser.impl.message.update.Ipv4NlriParser;
31 import org.opendaylight.protocol.bgp.parser.impl.message.update.Ipv6NlriParser;
32 import org.opendaylight.protocol.bgp.parser.impl.message.update.LocalPreferenceAttributeParser;
33 import org.opendaylight.protocol.bgp.parser.impl.message.update.MPReachAttributeParser;
34 import org.opendaylight.protocol.bgp.parser.impl.message.update.MPUnreachAttributeParser;
35 import org.opendaylight.protocol.bgp.parser.impl.message.update.MultiExitDiscriminatorAttributeParser;
36 import org.opendaylight.protocol.bgp.parser.impl.message.update.NextHopAttributeParser;
37 import org.opendaylight.protocol.bgp.parser.impl.message.update.OriginAttributeParser;
38 import org.opendaylight.protocol.bgp.parser.impl.message.update.OriginatorIdAttributeParser;
39 import org.opendaylight.protocol.bgp.parser.impl.message.update.WithdrawnRoutesSerializer;
40 import org.opendaylight.protocol.bgp.parser.spi.AbstractBGPExtensionProviderActivator;
41 import org.opendaylight.protocol.bgp.parser.spi.AddressFamilyRegistry;
42 import org.opendaylight.protocol.bgp.parser.spi.AttributeRegistry;
43 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
44 import org.opendaylight.protocol.bgp.parser.spi.CapabilityRegistry;
45 import org.opendaylight.protocol.bgp.parser.spi.NlriRegistry;
46 import org.opendaylight.protocol.bgp.parser.spi.ParameterRegistry;
47 import org.opendaylight.protocol.bgp.parser.spi.SubsequentAddressFamilyRegistry;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Keepalive;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Notify;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Open;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.BgpParameters;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.bgp.parameters.c.parameters.As4BytesCase;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Aggregator;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AsPath;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AtomicAggregate;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Communities;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.ExtendedCommunities;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.LocalPref;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.MultiExitDisc;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Origin;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.WithdrawnRoutes;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.c.parameters.GracefulRestartCase;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.c.parameters.MultiprotocolCase;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpReachNlri;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpUnreachNlri;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.mp.reach.nlri.AdvertizedRoutes;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.MplsLabeledVpnSubsequentAddressFamily;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.NextHop;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
73
74 public final class BGPActivator extends AbstractBGPExtensionProviderActivator {
75
76     @Override
77     protected List<AutoCloseable> startImpl(final BGPExtensionProviderContext context) {
78         final List<AutoCloseable> regs = new ArrayList<>();
79
80         regs.add(context.registerNlriSerializer(AdvertizedRoutes.class, new AdvertizedRoutesSerializer()));
81         regs.add(context.registerNlriSerializer(WithdrawnRoutes.class, new WithdrawnRoutesSerializer()));
82
83         final AddressFamilyRegistry afiReg = context.getAddressFamilyRegistry();
84         regs.add(context.registerAddressFamily(Ipv4AddressFamily.class, 1));
85         regs.add(context.registerAddressFamily(Ipv6AddressFamily.class, 2));
86
87         final SubsequentAddressFamilyRegistry safiReg = context.getSubsequentAddressFamilyRegistry();
88         regs.add(context.registerSubsequentAddressFamily(UnicastSubsequentAddressFamily.class, 1));
89         regs.add(context.registerSubsequentAddressFamily(MplsLabeledVpnSubsequentAddressFamily.class, 128));
90
91         regs.add(context.registerNlriParser(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, new Ipv4NlriParser()));
92         regs.add(context.registerNlriParser(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class, new Ipv6NlriParser()));
93
94         final AttributeRegistry attrReg = context.getAttributeRegistry();
95         final NlriRegistry nlriReg = context.getNlriRegistry();
96
97         final OriginAttributeParser originAttributeParser = new OriginAttributeParser();
98         regs.add(context.registerAttributeSerializer(Origin.class, originAttributeParser));
99         regs.add(context.registerAttributeParser(OriginAttributeParser.TYPE, originAttributeParser));
100
101         final AsPathAttributeParser asPathAttributeParser = new AsPathAttributeParser(context.getReferenceCache());
102         regs.add(context.registerAttributeSerializer(AsPath.class, asPathAttributeParser));
103         regs.add(context.registerAttributeParser(AsPathAttributeParser.TYPE, asPathAttributeParser));
104
105         final NextHopAttributeParser nextHopAttributeParser = new NextHopAttributeParser();
106         regs.add(context.registerAttributeSerializer(NextHop.class, nextHopAttributeParser));
107         regs.add(context.registerAttributeParser(NextHopAttributeParser.TYPE, nextHopAttributeParser));
108
109         final MultiExitDiscriminatorAttributeParser multiExitDiscriminatorAttributeParser = new MultiExitDiscriminatorAttributeParser();
110         regs.add(context.registerAttributeSerializer(MultiExitDisc.class, multiExitDiscriminatorAttributeParser));
111         regs.add(context.registerAttributeParser(MultiExitDiscriminatorAttributeParser.TYPE, multiExitDiscriminatorAttributeParser));
112
113         final LocalPreferenceAttributeParser localPreferenceAttributeParser = new LocalPreferenceAttributeParser();
114         regs.add(context.registerAttributeSerializer(LocalPref.class, localPreferenceAttributeParser));
115         regs.add(context.registerAttributeParser(LocalPreferenceAttributeParser.TYPE, localPreferenceAttributeParser));
116
117         final AtomicAggregateAttributeParser atomicAggregateAttributeParser = new AtomicAggregateAttributeParser();
118         regs.add(context.registerAttributeSerializer(AtomicAggregate.class, atomicAggregateAttributeParser));
119         regs.add(context.registerAttributeParser(AtomicAggregateAttributeParser.TYPE, atomicAggregateAttributeParser));
120
121         final AggregatorAttributeParser as4AggregatorAttributeParser = new AggregatorAttributeParser(context.getReferenceCache());
122         regs.add(context.registerAttributeSerializer(Aggregator.class, as4AggregatorAttributeParser));
123         regs.add(context.registerAttributeParser(AggregatorAttributeParser.TYPE, as4AggregatorAttributeParser));
124
125         final CommunitiesAttributeParser communitiesAttributeParser = new CommunitiesAttributeParser(context.getReferenceCache());
126         regs.add(context.registerAttributeSerializer(Communities.class, communitiesAttributeParser));
127         regs.add(context.registerAttributeParser(CommunitiesAttributeParser.TYPE, communitiesAttributeParser));
128
129         final OriginatorIdAttributeParser originatorIdAttributeParser = new OriginatorIdAttributeParser();
130         regs.add(context.registerAttributeParser(OriginatorIdAttributeParser.TYPE, originatorIdAttributeParser));
131
132         final ClusterIdAttributeParser clusterIdAttributeParser = new ClusterIdAttributeParser();
133         regs.add(context.registerAttributeParser(ClusterIdAttributeParser.TYPE, clusterIdAttributeParser));
134
135         MPReachAttributeParser mpReachAttributeParser = new MPReachAttributeParser(nlriReg);
136         regs.add(context.registerAttributeSerializer(MpReachNlri.class, mpReachAttributeParser));
137         regs.add(context.registerAttributeParser(MPReachAttributeParser.TYPE, mpReachAttributeParser));
138
139         MPUnreachAttributeParser mpUnreachAttributeParser = new MPUnreachAttributeParser(nlriReg);
140         regs.add(context.registerAttributeSerializer(MpUnreachNlri.class, mpUnreachAttributeParser));
141         regs.add(context.registerAttributeParser(MPUnreachAttributeParser.TYPE, mpUnreachAttributeParser));
142
143         final ExtendedCommunitiesAttributeParser extendedCommunitiesAttributeParser = new ExtendedCommunitiesAttributeParser(context.getReferenceCache());
144         regs.add(context.registerAttributeSerializer(ExtendedCommunities.class, extendedCommunitiesAttributeParser));
145         regs.add(context.registerAttributeParser(ExtendedCommunitiesAttributeParser.TYPE, extendedCommunitiesAttributeParser));
146
147         regs.add(context.registerAttributeParser(AS4AggregatorAttributeParser.TYPE, new AS4AggregatorAttributeParser()));
148         regs.add(context.registerAttributeParser(AS4PathAttributeParser.TYPE, new AS4PathAttributeParser()));
149
150
151         final CapabilityRegistry capReg = context.getCapabilityRegistry();
152         final MultiProtocolCapabilityHandler multi = new MultiProtocolCapabilityHandler(afiReg, safiReg);
153         regs.add(context.registerCapabilityParser(MultiProtocolCapabilityHandler.CODE, multi));
154         regs.add(context.registerCapabilitySerializer(MultiprotocolCase.class, multi));
155
156         final As4CapabilityHandler as4 = new As4CapabilityHandler();
157         regs.add(context.registerCapabilityParser(As4CapabilityHandler.CODE, as4));
158         regs.add(context.registerCapabilitySerializer(As4BytesCase.class, as4));
159
160         final GracefulCapabilityHandler grace = new GracefulCapabilityHandler(afiReg, safiReg);
161         regs.add(context.registerCapabilitySerializer(GracefulRestartCase.class, grace));
162         regs.add(context.registerCapabilityParser(GracefulCapabilityHandler.CODE, grace));
163
164         final ParameterRegistry paramReg = context.getParameterRegistry();
165         final CapabilityParameterParser cpp = new CapabilityParameterParser(capReg);
166         regs.add(context.registerParameterParser(CapabilityParameterParser.TYPE, cpp));
167         regs.add(context.registerParameterSerializer(BgpParameters.class, cpp));
168
169         final BGPOpenMessageParser omp = new BGPOpenMessageParser(paramReg);
170         regs.add(context.registerMessageParser(BGPOpenMessageParser.TYPE, omp));
171         regs.add(context.registerMessageSerializer(Open.class, omp));
172
173         final BGPUpdateMessageParser ump = new BGPUpdateMessageParser(attrReg);
174         regs.add(context.registerMessageParser(BGPUpdateMessageParser.TYPE, ump));
175         regs.add(context.registerMessageSerializer(Update.class, ump));
176
177         final BGPNotificationMessageParser nmp = new BGPNotificationMessageParser();
178         regs.add(context.registerMessageParser(BGPNotificationMessageParser.TYPE, nmp));
179         regs.add(context.registerMessageSerializer(Notify.class, nmp));
180
181         final BGPKeepAliveMessageParser kamp = new BGPKeepAliveMessageParser();
182         regs.add(context.registerMessageParser(BGPKeepAliveMessageParser.TYPE, kamp));
183         regs.add(context.registerMessageSerializer(Keepalive.class, kamp));
184
185         return regs;
186     }
187 }