List of usage examples for io.netty.buffer ByteBuf readUnsignedInt
public abstract long readUnsignedInt();
From source file:org.opendaylight.protocol.pcep.impl.subobject.XROSRLGSubobjectParser.java
License:Open Source License
@Override public Subobject parseSubobject(final ByteBuf buffer, final boolean mandatory) throws PCEPDeserializerException { Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); if (buffer.readableBytes() != CONTENT_LENGTH) { throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: " + CONTENT_LENGTH + "."); }//w w w . j a v a2s . c o m final SubobjectBuilder builder = new SubobjectBuilder(); builder.setMandatory(mandatory); builder.setSubobjectType(new SrlgCaseBuilder() .setSrlg(new SrlgBuilder().setSrlgId(new SrlgId(buffer.readUnsignedInt())).build()).build()); buffer.readByte(); builder.setAttribute(ExcludeRouteSubobjects.Attribute.forValue(buffer.readUnsignedByte())); return builder.build(); }
From source file:org.opendaylight.protocol.pcep.impl.subobject.XROUnnumberedInterfaceSubobjectParser.java
License:Open Source License
@Override public Subobject parseSubobject(final ByteBuf buffer, final boolean mandatory) throws PCEPDeserializerException { Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); if (buffer.readableBytes() != CONTENT_LENGTH) { throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: " + CONTENT_LENGTH + "."); }// w w w. j a v a 2 s . com buffer.readerIndex(buffer.readerIndex() + RESERVED); final SubobjectBuilder builder = new SubobjectBuilder(); builder.setMandatory(mandatory); builder.setAttribute(Attribute.forValue(buffer.readUnsignedByte())); final UnnumberedBuilder ubuilder = new UnnumberedBuilder(); ubuilder.setRouterId(buffer.readUnsignedInt()); ubuilder.setInterfaceId(buffer.readUnsignedInt()); builder.setSubobjectType(new UnnumberedCaseBuilder().setUnnumbered(ubuilder.build()).build()); return builder.build(); }
From source file:org.opendaylight.protocol.pcep.impl.tlv.AbstractVendorSpecificTlvParser.java
License:Open Source License
@Override public VsTlv parseTlv(final ByteBuf buffer) throws PCEPDeserializerException { if (buffer == null) { return null; }/*from w ww .java 2 s .c o m*/ final VsTlvBuilder vsTlvBuider = new VsTlvBuilder(); final long en = buffer.readUnsignedInt(); if (en == getEnterpriseNumber()) { vsTlvBuider.setEnterpriseNumber(new EnterpriseNumber(getEnterpriseNumber())); VendorPayload vendorPayload = null; if (buffer.isReadable()) { final ByteBuf payloadBytes = buffer.slice(); vendorPayload = parseVendorPayload(payloadBytes); if (vendorPayload != null) { vsTlvBuider.setVendorPayload(vendorPayload); } } } return vsTlvBuider.build(); }
From source file:org.opendaylight.protocol.pcep.impl.tlv.OrderTlvParser.java
License:Open Source License
@Override public Order parseTlv(final ByteBuf buffer) throws PCEPDeserializerException { if (buffer == null) { return null; }/*w ww. ja v a2s .c o m*/ return new OrderBuilder().setDelete(buffer.readUnsignedInt()).setSetup(buffer.readUnsignedInt()).build(); }
From source file:org.opendaylight.protocol.pcep.impl.tlv.OverloadedDurationTlvParser.java
License:Open Source License
@Override public OverloadDuration parseTlv(final ByteBuf buffer) throws PCEPDeserializerException { if (buffer == null) { return null; }// w ww . j a v a2 s . co m return new OverloadDurationBuilder().setDuration(buffer.readUnsignedInt()).build(); }
From source file:org.opendaylight.protocol.pcep.impl.tlv.ReqMissingTlvParser.java
License:Open Source License
@Override public ReqMissing parseTlv(final ByteBuf buffer) throws PCEPDeserializerException { if (buffer == null) { return null; }//from w w w. j av a2 s. c o m return new ReqMissingBuilder().setRequestId(new RequestId(buffer.readUnsignedInt())).build(); }
From source file:org.opendaylight.protocol.pcep.pcecc.PceccLabelObjectParser.java
License:Open Source License
@Override public Label parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException { Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); if (bytes.readableBytes() < MIN_SIZE) { throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.readableBytes() + "; Expected: >=" + MIN_SIZE + "."); }/* www . j av a 2 s.c o m*/ final LabelBuilder builder = new LabelBuilder(); builder.setIgnore(header.isIgnore()); builder.setProcessingRule(header.isProcessingRule()); bytes.skipBytes(RESERVED + SKIP_BYTE); byte outLabel = bytes.readByte(); if ((byte) (outLabel & OUT_LABEL_BYTE) == OUT_LABEL_BYTE) { builder.setOutLabel(true); } else { builder.setOutLabel(false); } ByteBuf lableBuff = bytes.readBytes((LABEL_SIZE + RESERVED_LABEL) / Byte.SIZE); builder.setLabelNum(new LabelNumber(lableBuff.readUnsignedInt() >> RESERVED_LABEL)); final TlvsBuilder tlvsBuilder = new TlvsBuilder(); ByteBuf tlvBytes = bytes.slice(); parseTlvs(tlvsBuilder, tlvBytes); builder.setTlvs(tlvsBuilder.build()); return builder.build(); }
From source file:org.opendaylight.protocol.pcep.segment.routing.AbstractSrSubobjectParser.java
License:Open Source License
private static Nai parseNai(final SidType sidType, final ByteBuf buffer) { switch (sidType) { case Ipv4NodeId: return new IpNodeIdBuilder().setIpAddress(new IpAddress(Ipv4Util.addressForByteBuf(buffer))).build(); case Ipv6NodeId: return new IpNodeIdBuilder().setIpAddress(new IpAddress(Ipv6Util.addressForByteBuf(buffer))).build(); case Ipv4Adjacency: return new IpAdjacencyBuilder().setLocalIpAddress(new IpAddress(Ipv4Util.addressForByteBuf(buffer))) .setRemoteIpAddress(new IpAddress(Ipv4Util.addressForByteBuf(buffer))).build(); case Ipv6Adjacency: return new IpAdjacencyBuilder().setLocalIpAddress(new IpAddress(Ipv6Util.addressForByteBuf(buffer))) .setRemoteIpAddress(new IpAddress(Ipv6Util.addressForByteBuf(buffer))).build(); case Unnumbered: return new UnnumberedAdjacencyBuilder().setLocalNodeId(buffer.readUnsignedInt()) .setLocalInterfaceId(buffer.readUnsignedInt()).setRemoteNodeId(buffer.readUnsignedInt()) .setRemoteInterfaceId(buffer.readUnsignedInt()).build(); default:/*from ww w . j a va2 s. com*/ return null; } }
From source file:org.opendaylight.protocol.pcep.segment.routing.AbstractSrSubobjectParser.java
License:Open Source License
protected static SrSubobject parseSrSubobject(final ByteBuf buffer) throws PCEPDeserializerException { final int sidTypeByte = buffer.readByte() >> SID_TYPE_BITS_OFFSET; final SidType sidType = SidType.forValue(sidTypeByte); final BitArray bitSet = BitArray.valueOf(buffer.readByte()); final boolean f = bitSet.get(F_FLAG_POSITION); final boolean s = bitSet.get(S_FLAG_POSITION); final boolean c = bitSet.get(C_FLAG_POSITION); final boolean m = bitSet.get(M_FLAG_POSITION); if (f && s) { throw new PCEPDeserializerException("Both SID and NAI are absent in SR subobject."); }// www . j a v a2s . c om Long tmp = null; if (!s) { if (m) { tmp = buffer.readUnsignedInt() >>> MPLS_LABEL_OFFSET; } else { tmp = buffer.readUnsignedInt(); } } final Long sid = tmp; final Nai nai; if (sidType != null && !f) { nai = parseNai(sidType, buffer); } else { nai = null; } return new SrSubobjectImpl(m, c, sidType, sid, nai); }
From source file:org.opendaylight.protocol.pcep.spi.AbstractMessageParser.java
License:Open Source License
private List<Object> parseObjects(final ByteBuf bytes) throws PCEPDeserializerException { final List<Object> objs = new ArrayList<>(); while (bytes.isReadable()) { if (bytes.readableBytes() < COMMON_OBJECT_HEADER_LENGTH) { throw new PCEPDeserializerException("Too few bytes in passed array. Passed: " + bytes.readableBytes() + " Expected: >= " + COMMON_OBJECT_HEADER_LENGTH + "."); }//from ww w .ja va 2 s. c o m final int objClass = bytes.readUnsignedByte(); final byte flagsByte = bytes.readByte(); final BitArray flags = BitArray.valueOf(flagsByte); final int objType = UnsignedBytes.toInt(ByteArray.copyBitsRange(flagsByte, OT_SF_OFFSET, OT_SF_LENGTH)); final int objLength = bytes.readUnsignedShort(); if (bytes.readableBytes() < objLength - COMMON_OBJECT_HEADER_LENGTH) { throw new PCEPDeserializerException("Too few bytes in passed array. Passed: " + bytes.readableBytes() + " Expected: >= " + objLength + "."); } // copy bytes for deeper parsing final ByteBuf bytesToPass = bytes.readSlice(objLength - COMMON_OBJECT_HEADER_LENGTH); final ObjectHeader header = new ObjectHeaderImpl(flags.get(PROCESSED), flags.get(IGNORED)); if (VendorInformationUtil.isVendorInformationObject(objClass, objType)) { final EnterpriseNumber enterpriseNumber = new EnterpriseNumber(bytesToPass.readUnsignedInt()); final Optional<? extends Object> obj = this.registry.parseVendorInformationObject(enterpriseNumber, header, bytesToPass); if (obj.isPresent()) { objs.add(obj.get()); } } else { // parseObject is required to return null for P=0 errored objects final Object o = this.registry.parseObject(objClass, objType, header, bytesToPass); if (o != null) { objs.add(o); } } } return objs; }