Merge "Randomize port to allow concurrent execution"
[bgpcep.git] / bgp / parser-impl / src / main / java / org / opendaylight / protocol / bgp / parser / impl / message / update / OriginAttributeParser.java
1 package org.opendaylight.protocol.bgp.parser.impl.message.update;
2
3 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
4 import org.opendaylight.protocol.bgp.parser.BGPError;
5 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
6 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.OriginBuilder;
7 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributesBuilder;
8 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
9
10 import com.google.common.primitives.UnsignedBytes;
11
12 final class OriginAttributeParser implements AttributeParser {
13         static final int TYPE = 1;
14
15         @Override
16         public void parseAttribute(final byte[] bytes, final PathAttributesBuilder builder) throws BGPDocumentedException {
17                 final BgpOrigin borigin = BgpOrigin.forValue(UnsignedBytes.toInt(bytes[0]));
18                 if (borigin == null) {
19                         throw new BGPDocumentedException("Unknown Origin type.", BGPError.ORIGIN_ATTR_NOT_VALID, new byte[] { (byte) 0x01, (byte) 0x01, bytes[0] });
20                 }
21
22                 builder.setOrigin(new OriginBuilder().setValue(borigin).build());
23         }
24 }