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.message.update;
10 import static java.util.Objects.requireNonNull;
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.Unpooled;
14 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
15 import org.opendaylight.protocol.bgp.parser.BGPError;
16 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
17 import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
18 import org.opendaylight.protocol.bgp.parser.spi.NlriRegistry;
19 import org.opendaylight.protocol.bgp.parser.spi.NlriSerializer;
20 import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
21 import org.opendaylight.protocol.bgp.parser.spi.RevisedErrorHandling;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2Builder;
27 public final class MPUnreachAttributeParser extends ReachAttributeParser {
28 public static final int TYPE = 15;
30 private final NlriRegistry reg;
32 public MPUnreachAttributeParser(final NlriRegistry reg) {
33 this.reg = requireNonNull(reg);
37 public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder,
38 final RevisedErrorHandling errorHandling, final PeerSpecificParserConstraint constraint)
39 throws BGPDocumentedException {
41 builder.addAugmentation(Attributes2.class, new Attributes2Builder()
42 .setMpUnreachNlri(reg.parseMpUnreach(buffer, constraint))
44 } catch (final BGPParsingException e) {
45 throw new BGPDocumentedException("Could not parse MP_UNREACH_NLRI", BGPError.OPT_ATTR_ERROR, e);
50 public void serializeAttribute(final Attributes attribute, final ByteBuf byteAggregator) {
51 final Attributes2 pathAttributes2 = attribute.augmentation(Attributes2.class);
52 if (pathAttributes2 != null) {
53 final ByteBuf unreachBuffer = Unpooled.buffer();
54 reg.serializeMpUnReach(pathAttributes2.getMpUnreachNlri(), unreachBuffer);
55 for (final NlriSerializer nlriSerializer : this.reg.getSerializers()) {
56 nlriSerializer.serializeAttribute(attribute, unreachBuffer);
58 AttributeUtil.formatAttribute(AttributeUtil.OPTIONAL, TYPE, unreachBuffer, byteAggregator);