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 io.netty.buffer.ByteBuf;
11 import io.netty.buffer.Unpooled;
12 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
13 import org.opendaylight.protocol.bgp.parser.BGPError;
14 import org.opendaylight.protocol.bgp.parser.BGPTreatAsWithdrawException;
15 import org.opendaylight.protocol.bgp.parser.spi.AbstractAttributeParser;
16 import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
17 import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
18 import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
19 import org.opendaylight.protocol.bgp.parser.spi.RevisedErrorHandling;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.MultiExitDisc;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.MultiExitDiscBuilder;
25 public final class MultiExitDiscriminatorAttributeParser extends AbstractAttributeParser
26 implements AttributeSerializer {
27 public static final int TYPE = 4;
30 public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder,
31 final RevisedErrorHandling errorHandling, final PeerSpecificParserConstraint constraint)
32 throws BGPDocumentedException, BGPTreatAsWithdrawException {
33 final int readable = buffer.readableBytes();
35 throw errorHandling.reportError(BGPError.ATTR_LENGTH_ERROR,
36 "MULTI_EXIT_DISC has to have length 4, but has %s", readable);
38 builder.setMultiExitDisc(new MultiExitDiscBuilder().setMed(buffer.readUnsignedInt()).build());
42 public void serializeAttribute(final Attributes attribute, final ByteBuf byteAggregator) {
43 final MultiExitDisc multiExitDisc = attribute.getMultiExitDisc();
44 if (multiExitDisc != null) {
45 final Long med = multiExitDisc.getMed();
47 AttributeUtil.formatAttribute(AttributeUtil.OPTIONAL, TYPE, Unpooled.copyInt(med.intValue()),