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.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.AggregatorAttributeParser;
23 import org.opendaylight.protocol.bgp.parser.impl.message.update.AsPathAttributeParser;
24 import org.opendaylight.protocol.bgp.parser.impl.message.update.AtomicAggregateAttributeParser;
25 import org.opendaylight.protocol.bgp.parser.impl.message.update.ClusterIdAttributeParser;
26 import org.opendaylight.protocol.bgp.parser.impl.message.update.CommunitiesAttributeParser;
27 import org.opendaylight.protocol.bgp.parser.impl.message.update.ExtendedCommunitiesAttributeParser;
28 import org.opendaylight.protocol.bgp.parser.impl.message.update.Ipv4NlriParser;
29 import org.opendaylight.protocol.bgp.parser.impl.message.update.Ipv6NlriParser;
30 import org.opendaylight.protocol.bgp.parser.impl.message.update.LocalPreferenceAttributeParser;
31 import org.opendaylight.protocol.bgp.parser.impl.message.update.MPReachAttributeParser;
32 import org.opendaylight.protocol.bgp.parser.impl.message.update.MPUnreachAttributeParser;
33 import org.opendaylight.protocol.bgp.parser.impl.message.update.MultiExitDiscriminatorAttributeParser;
34 import org.opendaylight.protocol.bgp.parser.impl.message.update.NextHopAttributeParser;
35 import org.opendaylight.protocol.bgp.parser.impl.message.update.OriginAttributeParser;
36 import org.opendaylight.protocol.bgp.parser.impl.message.update.OriginatorIdAttributeParser;
37 import org.opendaylight.protocol.bgp.parser.spi.AddressFamilyRegistry;
38 import org.opendaylight.protocol.bgp.parser.spi.AttributeRegistry;
39 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderActivator;
40 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
41 import org.opendaylight.protocol.bgp.parser.spi.CapabilityRegistry;
42 import org.opendaylight.protocol.bgp.parser.spi.NlriRegistry;
43 import org.opendaylight.protocol.bgp.parser.spi.ParameterRegistry;
44 import org.opendaylight.protocol.bgp.parser.spi.SubsequentAddressFamilyRegistry;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Keepalive;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Notify;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Open;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParameters;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.c.parameters.CAs4Bytes;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.open.bgp.parameters.c.parameters.CMultiprotocol;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.MplsLabeledVpnSubsequentAddressFamily;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
55 import org.slf4j.Logger;
56 import org.slf4j.LoggerFactory;
58 import com.google.common.base.Preconditions;
60 public final class Activator implements BGPExtensionProviderActivator {
61 private static final Logger logger = LoggerFactory.getLogger(Activator.class);
62 private List<AutoCloseable> registrations;
65 public synchronized void start(final BGPExtensionProviderContext context) {
66 Preconditions.checkState(this.registrations == null);
67 final List<AutoCloseable> regs = new ArrayList<>();
69 final AddressFamilyRegistry afiReg = context.getAddressFamilyRegistry();
70 regs.add(context.registerAddressFamily(Ipv4AddressFamily.class, 1));
71 regs.add(context.registerAddressFamily(Ipv6AddressFamily.class, 2));
73 final SubsequentAddressFamilyRegistry safiReg = context.getSubsequentAddressFamilyRegistry();
74 regs.add(context.registerSubsequentAddressFamily(UnicastSubsequentAddressFamily.class, 1));
75 regs.add(context.registerSubsequentAddressFamily(MplsLabeledVpnSubsequentAddressFamily.class, 128));
77 final NlriRegistry nlriReg = context.getNlriRegistry();
78 regs.add(context.registerNlriParser(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, new Ipv4NlriParser()));
79 regs.add(context.registerNlriParser(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class, new Ipv6NlriParser()));
81 final AttributeRegistry attrReg = context.getAttributeRegistry();
82 regs.add(context.registerAttributeParser(OriginAttributeParser.TYPE, new OriginAttributeParser()));
83 regs.add(context.registerAttributeParser(AsPathAttributeParser.TYPE, new AsPathAttributeParser()));
84 regs.add(context.registerAttributeParser(NextHopAttributeParser.TYPE, new NextHopAttributeParser()));
85 regs.add(context.registerAttributeParser(MultiExitDiscriminatorAttributeParser.TYPE, new MultiExitDiscriminatorAttributeParser()));
86 regs.add(context.registerAttributeParser(LocalPreferenceAttributeParser.TYPE, new LocalPreferenceAttributeParser()));
87 regs.add(context.registerAttributeParser(AtomicAggregateAttributeParser.TYPE, new AtomicAggregateAttributeParser()));
88 regs.add(context.registerAttributeParser(AggregatorAttributeParser.TYPE, new AggregatorAttributeParser()));
89 regs.add(context.registerAttributeParser(CommunitiesAttributeParser.TYPE, new CommunitiesAttributeParser()));
90 regs.add(context.registerAttributeParser(OriginatorIdAttributeParser.TYPE, new OriginatorIdAttributeParser()));
91 regs.add(context.registerAttributeParser(ClusterIdAttributeParser.TYPE, new ClusterIdAttributeParser()));
92 regs.add(context.registerAttributeParser(MPReachAttributeParser.TYPE, new MPReachAttributeParser(nlriReg)));
93 regs.add(context.registerAttributeParser(MPUnreachAttributeParser.TYPE, new MPUnreachAttributeParser(nlriReg)));
94 regs.add(context.registerAttributeParser(ExtendedCommunitiesAttributeParser.TYPE, new ExtendedCommunitiesAttributeParser()));
95 regs.add(context.registerAttributeParser(AS4AggregatorAttributeParser.TYPE, new AS4AggregatorAttributeParser()));
96 regs.add(context.registerAttributeParser(AS4PathAttributeParser.TYPE, new AS4PathAttributeParser()));
98 final CapabilityRegistry capReg = context.getCapabilityRegistry();
99 final MultiProtocolCapabilityHandler multi = new MultiProtocolCapabilityHandler(afiReg, safiReg);
100 regs.add(context.registerCapabilityParser(MultiProtocolCapabilityHandler.CODE, multi));
101 regs.add(context.registerCapabilitySerializer(CMultiprotocol.class, multi));
103 final As4CapabilityHandler as4 = new As4CapabilityHandler();
104 regs.add(context.registerCapabilityParser(As4CapabilityHandler.CODE, as4));
105 regs.add(context.registerCapabilitySerializer(CAs4Bytes.class, as4));
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));
112 final BGPOpenMessageParser omp = new BGPOpenMessageParser(paramReg);
113 regs.add(context.registerMessageParser(BGPOpenMessageParser.TYPE, omp));
114 regs.add(context.registerMessageSerializer(Open.class, omp));
116 final BGPUpdateMessageParser ump = new BGPUpdateMessageParser(attrReg);
117 regs.add(context.registerMessageParser(BGPUpdateMessageParser.TYPE, ump));
118 // Serialization of Update message is not supported
120 final BGPNotificationMessageParser nmp = new BGPNotificationMessageParser();
121 regs.add(context.registerMessageParser(BGPNotificationMessageParser.TYPE, nmp));
122 regs.add(context.registerMessageSerializer(Notify.class, nmp));
124 final BGPKeepAliveMessageParser kamp = new BGPKeepAliveMessageParser();
125 regs.add(context.registerMessageParser(BGPKeepAliveMessageParser.TYPE, kamp));
126 regs.add(context.registerMessageSerializer(Keepalive.class, kamp));
128 this.registrations = regs;
132 public synchronized void stop() {
133 Preconditions.checkState(this.registrations != null);
135 for (final AutoCloseable r : this.registrations) {
138 } catch (final Exception e) {
139 logger.warn("Failed to close registration", e);
143 this.registrations = null;