X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=bgp%2Fparser-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fprotocol%2Fbgp%2Fparser%2Fimpl%2Fmessage%2Fupdate%2FOriginatorIdAttributeParser.java;h=b6318a993d8a5406a8becb12f4a3d4a7fa4d4c59;hb=6b4d2ffc2d63d4b10f5879a35963e570b2a1bc96;hp=d031ce6aa44cf8029b5a52015281e45e6d9d73df;hpb=2eaa881cbead58e3f7aec4b0f90dbcffde7a5788;p=bgpcep.git diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/OriginatorIdAttributeParser.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/OriginatorIdAttributeParser.java index d031ce6aa4..b6318a993d 100644 --- a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/OriginatorIdAttributeParser.java +++ b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/OriginatorIdAttributeParser.java @@ -7,18 +7,44 @@ */ package org.opendaylight.protocol.bgp.parser.impl.message.update; +import com.google.common.base.Preconditions; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; + +import org.opendaylight.protocol.bgp.parser.AttributeFlags; import org.opendaylight.protocol.bgp.parser.spi.AttributeParser; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributesBuilder; +import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer; +import org.opendaylight.protocol.concepts.Ipv4Util; +import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.PathAttributes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributesBuilder; +import org.opendaylight.yangtools.yang.binding.DataObject; + + +public final class OriginatorIdAttributeParser implements AttributeParser,AttributeSerializer { + + public static final int TYPE = 9; + public static final int ATTR_LENGTH = 4; -public final class OriginatorIdAttributeParser implements AttributeParser { - public static final int TYPE = 9; + @Override + public void parseAttribute(final ByteBuf buffer, final PathAttributesBuilder builder) { + Preconditions.checkArgument(buffer.readableBytes() == ATTR_LENGTH, "Length of byte array for ORIGINATOR_ID should be %s, but is %s", ATTR_LENGTH, buffer.readableBytes()); + builder.setOriginatorId(Ipv4Util.addressForBytes(ByteArray.readBytes(buffer, ATTR_LENGTH))); + } - @Override - public void parseAttribute(final byte[] bytes, final PathAttributesBuilder builder) { - if (bytes.length != 4) { - throw new IllegalArgumentException("Length of byte array for ORIGINATOR_ID should be 4, but is " + bytes.length); - } + @Override + public void serializeAttribute(DataObject attribute, ByteBuf byteAggregator) { + PathAttributes pathAttributes = (PathAttributes) attribute; + if (pathAttributes.getOriginatorId() == null) { + return; + } + ByteBuf originatorIdBuf = Unpooled.buffer(); + originatorIdBuf.writeBytes(Ipv4Util.bytesForAddress(pathAttributes.getOriginatorId())); + byteAggregator.writeByte(AttributeFlags.OPTIONAL); + byteAggregator.writeByte(TYPE); + byteAggregator.writeByte(originatorIdBuf.writerIndex()); + byteAggregator.writeBytes(originatorIdBuf); - builder.setOriginatorId(bytes); - } -} \ No newline at end of file + } +}