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.Attributes1;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1Builder;
27 public final class MPReachAttributeParser extends ReachAttributeParser {
28 public static final int TYPE = 14;
30 private final NlriRegistry reg;
32 public MPReachAttributeParser(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(Attributes1.class, new Attributes1Builder()
42 .setMpReachNlri(reg.parseMpReach(buffer, constraint))
44 } catch (final BGPParsingException e) {
45 throw new BGPDocumentedException("Could not parse MP_REACH_NLRI", BGPError.OPT_ATTR_ERROR, e);
50 public void serializeAttribute(final Attributes pathAttributes, final ByteBuf byteAggregator) {
51 final Attributes1 pathAttributes1 = pathAttributes.augmentation(Attributes1.class);
52 if (pathAttributes1 != null) {
53 final ByteBuf reachBuffer = Unpooled.buffer();
54 reg.serializeMpReach(pathAttributes1.getMpReachNlri(), reachBuffer);
56 for (final NlriSerializer nlriSerializer : reg.getSerializers()) {
57 nlriSerializer.serializeAttribute(pathAttributes, reachBuffer);
59 AttributeUtil.formatAttribute(AttributeUtil.OPTIONAL, TYPE, reachBuffer, byteAggregator);