9bbaedf33753426c930397d9d5c966ee986e2d15
[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.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.open.BgpParameters;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.bgp.parameters.c.parameters.As4BytesCase;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.c.parameters.GracefulRestartCase;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.c.parameters.MultiprotocolCase;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.MplsLabeledVpnSubsequentAddressFamily;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
57
58 public final class BGPActivator extends AbstractBGPExtensionProviderActivator {
59     @Override
60     protected List<AutoCloseable> startImpl(final BGPExtensionProviderContext context) {
61         final List<AutoCloseable> regs = new ArrayList<>();
62
63         final AddressFamilyRegistry afiReg = context.getAddressFamilyRegistry();
64         regs.add(context.registerAddressFamily(Ipv4AddressFamily.class, 1));
65         regs.add(context.registerAddressFamily(Ipv6AddressFamily.class, 2));
66
67         final SubsequentAddressFamilyRegistry safiReg = context.getSubsequentAddressFamilyRegistry();
68         regs.add(context.registerSubsequentAddressFamily(UnicastSubsequentAddressFamily.class, 1));
69         regs.add(context.registerSubsequentAddressFamily(MplsLabeledVpnSubsequentAddressFamily.class, 128));
70
71         final NlriRegistry nlriReg = context.getNlriRegistry();
72         regs.add(context.registerNlriParser(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, new Ipv4NlriParser()));
73         regs.add(context.registerNlriParser(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class, new Ipv6NlriParser()));
74
75         final AttributeRegistry attrReg = context.getAttributeRegistry();
76         regs.add(context.registerAttributeParser(OriginAttributeParser.TYPE, new OriginAttributeParser()));
77         regs.add(context.registerAttributeParser(AsPathAttributeParser.TYPE, new AsPathAttributeParser(context.getReferenceCache())));
78         regs.add(context.registerAttributeParser(NextHopAttributeParser.TYPE, new NextHopAttributeParser()));
79         regs.add(context.registerAttributeParser(MultiExitDiscriminatorAttributeParser.TYPE, new MultiExitDiscriminatorAttributeParser()));
80         regs.add(context.registerAttributeParser(LocalPreferenceAttributeParser.TYPE, new LocalPreferenceAttributeParser()));
81         regs.add(context.registerAttributeParser(AtomicAggregateAttributeParser.TYPE, new AtomicAggregateAttributeParser()));
82         regs.add(context.registerAttributeParser(AggregatorAttributeParser.TYPE, new AggregatorAttributeParser(context.getReferenceCache())));
83         regs.add(context.registerAttributeParser(CommunitiesAttributeParser.TYPE,
84                 new CommunitiesAttributeParser(context.getReferenceCache())));
85         regs.add(context.registerAttributeParser(OriginatorIdAttributeParser.TYPE, new OriginatorIdAttributeParser()));
86         regs.add(context.registerAttributeParser(ClusterIdAttributeParser.TYPE, new ClusterIdAttributeParser()));
87         regs.add(context.registerAttributeParser(MPReachAttributeParser.TYPE, new MPReachAttributeParser(nlriReg)));
88         regs.add(context.registerAttributeParser(MPUnreachAttributeParser.TYPE, new MPUnreachAttributeParser(nlriReg)));
89         regs.add(context.registerAttributeParser(ExtendedCommunitiesAttributeParser.TYPE,
90                 new ExtendedCommunitiesAttributeParser(context.getReferenceCache())));
91         regs.add(context.registerAttributeParser(AS4AggregatorAttributeParser.TYPE, new AS4AggregatorAttributeParser()));
92         regs.add(context.registerAttributeParser(AS4PathAttributeParser.TYPE, new AS4PathAttributeParser()));
93
94         final CapabilityRegistry capReg = context.getCapabilityRegistry();
95         final MultiProtocolCapabilityHandler multi = new MultiProtocolCapabilityHandler(afiReg, safiReg);
96         regs.add(context.registerCapabilityParser(MultiProtocolCapabilityHandler.CODE, multi));
97         regs.add(context.registerCapabilitySerializer(MultiprotocolCase.class, multi));
98
99         final As4CapabilityHandler as4 = new As4CapabilityHandler();
100         regs.add(context.registerCapabilityParser(As4CapabilityHandler.CODE, as4));
101         regs.add(context.registerCapabilitySerializer(As4BytesCase.class, as4));
102
103         final GracefulCapabilityHandler grace = new GracefulCapabilityHandler(afiReg, safiReg);
104         regs.add(context.registerCapabilitySerializer(GracefulRestartCase.class, grace));
105         regs.add(context.registerCapabilityParser(GracefulCapabilityHandler.CODE, grace));
106
107         final ParameterRegistry paramReg = context.getParameterRegistry();
108         final CapabilityParameterParser cpp = new CapabilityParameterParser(capReg);
109         regs.add(context.registerParameterParser(CapabilityParameterParser.TYPE, cpp));
110         regs.add(context.registerParameterSerializer(BgpParameters.class, cpp));
111
112         final BGPOpenMessageParser omp = new BGPOpenMessageParser(paramReg);
113         regs.add(context.registerMessageParser(BGPOpenMessageParser.TYPE, omp));
114         regs.add(context.registerMessageSerializer(Open.class, omp));
115
116         final BGPUpdateMessageParser ump = new BGPUpdateMessageParser(attrReg);
117         regs.add(context.registerMessageParser(BGPUpdateMessageParser.TYPE, ump));
118         // Serialization of Update message is not supported
119
120         final BGPNotificationMessageParser nmp = new BGPNotificationMessageParser();
121         regs.add(context.registerMessageParser(BGPNotificationMessageParser.TYPE, nmp));
122         regs.add(context.registerMessageSerializer(Notify.class, nmp));
123
124         final BGPKeepAliveMessageParser kamp = new BGPKeepAliveMessageParser();
125         regs.add(context.registerMessageParser(BGPKeepAliveMessageParser.TYPE, kamp));
126         regs.add(context.registerMessageSerializer(Keepalive.class, kamp));
127
128         return regs;
129     }
130 }