List of usage examples for io.netty.buffer ByteBuf isReadable
public abstract boolean isReadable();
From source file:org.opendaylight.protocol.pcep.impl.tlv.AbstractVendorInformationTlvParser.java
License:Open Source License
@Override public final VendorInformationTlv parseTlv(final ByteBuf buffer) throws PCEPDeserializerException { if (buffer == null) { return null; }/* w w w . ja v a 2 s . co m*/ final VendorInformationTlvBuilder viTlvBuider = new VendorInformationTlvBuilder(); viTlvBuider.setEnterpriseNumber(getEnterpriseNumber()); if (buffer.isReadable()) { final EnterpriseSpecificInformation esInformation = parseEnterpriseSpecificInformation(buffer.slice()); if (esInformation != null) { viTlvBuider.setEnterpriseSpecificInformation(esInformation); } } return viTlvBuider.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; }/*w ww.j a v a2s . c om*/ 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.OFListTlvParser.java
License:Open Source License
@Override public OfList parseTlv(final ByteBuf buffer) throws PCEPDeserializerException { if (buffer == null) { return null; }/*from w w w.j a v a2s . c o m*/ if (buffer.readableBytes() % OF_CODE_ELEMENT_LENGTH != 0) { throw new PCEPDeserializerException( "Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "."); } final List<OfId> ofCodes = Lists.newArrayList(); while (buffer.isReadable()) { ofCodes.add(new OfId(buffer.readUnsignedShort())); } return new OfListBuilder().setCodes(ofCodes).build(); }
From source file:org.opendaylight.protocol.pcep.parser.object.PCEPExistingBandwidthObjectParser.java
License:Open Source License
@Override public ReoptimizationBandwidth 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() != PCEPBandwidthObjectParser.BANDWIDTH_F_LENGTH) { throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.readableBytes() + "; Expected: " + PCEPBandwidthObjectParser.BANDWIDTH_F_LENGTH + "."); }//from w ww. j a v a 2s . c o m final ReoptimizationBandwidthBuilder builder = new ReoptimizationBandwidthBuilder(); builder.setIgnore(header.isIgnore()); builder.setProcessingRule(header.isProcessingRule()); builder.setBandwidth( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth( ByteArray.getAllBytes(bytes))); return builder.build(); }
From source file:org.opendaylight.protocol.pcep.parser.object.PCEPIncludeRouteObjectParser.java
License:Open Source License
@Override public Iro 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."); final IroBuilder builder = new IroBuilder(); builder.setIgnore(header.isIgnore()); builder.setProcessingRule(header.isProcessingRule()); final List<Subobject> subs = new ArrayList<>(); for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject s : parseSubobjects( bytes)) {//ww w . j a v a 2s .co m subs.add(new SubobjectBuilder().setLoose(s.isLoose()).setSubobjectType(s.getSubobjectType()).build()); } builder.setSubobject(subs); return builder.build(); }
From source file:org.opendaylight.protocol.pcep.pcc.mock.PCCEndPointIpv4ObjectParser.java
License:Open Source License
@Override public Object parseObject(ObjectHeader header, ByteBuf bytes) throws PCEPDeserializerException { Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); final EndpointsObjBuilder builder = new EndpointsObjBuilder(); if (bytes.readableBytes() != Ipv4Util.IP4_LENGTH * 2) { throw new PCEPDeserializerException("Wrong length of array of bytes."); }//from w ww. j ava 2 s . c o m builder.setIgnore(header.isIgnore()); builder.setProcessingRule(header.isProcessingRule()); final Ipv4Builder b = new Ipv4Builder(); b.setSourceIpv4Address(Ipv4Util.addressForByteBuf(bytes)); b.setDestinationIpv4Address((Ipv4Util.addressForByteBuf(bytes))); builder.setAddressFamily(new Ipv4CaseBuilder().setIpv4(b.build()).build()); return builder.build(); }
From source file:org.opendaylight.protocol.pcep.pcecc.PceccFecIpv4AdjacencyObjectParser.java
License:Open Source License
@Override public Fec parseObject(final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException { Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); if (buffer.readableBytes() < MIN_SIZE) { throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >=" + MIN_SIZE + "."); }//from w w w.j av a2 s . c o m final FecBuilder builder = new FecBuilder(); builder.setIgnore(header.isIgnore()); builder.setProcessingRule(header.isProcessingRule()); final Ipv4AdjacencyCaseBuilder IpAdjacencybuilder = new Ipv4AdjacencyCaseBuilder(); IpAdjacencybuilder.setLocalIpAddress(Ipv4Util.addressForByteBuf(buffer)); IpAdjacencybuilder.setRemoteIpAddress(Ipv4Util.addressForByteBuf(buffer)); builder.setFec(IpAdjacencybuilder.build()); return builder.build(); }
From source file:org.opendaylight.protocol.pcep.pcecc.PceccFecIpv4ObjectParser.java
License:Open Source License
@Override public Fec 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 + "."); }/*from w w w . j a v a2 s .co m*/ final FecBuilder builder = new FecBuilder(); builder.setIgnore(header.isIgnore()); builder.setProcessingRule(header.isProcessingRule()); final Ipv4NodeIdCaseBuilder Ipbuilder = new Ipv4NodeIdCaseBuilder(); Ipbuilder.setNodeId(Ipv4Util.addressForByteBuf(bytes)); builder.setFec(Ipbuilder.build()); return builder.build(); }
From source file:org.opendaylight.protocol.pcep.pcecc.PceccFecObjectParser.java
License:Open Source License
@Override public Fec 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 + "."); }/*from w ww .jav a 2 s . co m*/ final FecBuilder builder = new FecBuilder(); return builder.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 + "."); }// w w w . j a v a 2 s. c om 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(); }