List of usage examples for io.netty.buffer ByteBuf isReadable
public abstract boolean isReadable();
From source file:org.opendaylight.protocol.pcep.impl.object.PCEPPccIdReqIPv6ObjectParser.java
License:Open Source License
@Override public Object 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."); final PccIdReqBuilder builder = new PccIdReqBuilder(); builder.setIpAddress(new IpAddress(Ipv6Util.addressForByteBuf(buffer))); return builder.build(); }
From source file:org.opendaylight.protocol.pcep.impl.object.PCEPPceIdIPv4ObjectParser.java
License:Open Source License
@Override public Object 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."); final PceIdBuilder builder = new PceIdBuilder(); builder.setIpAddress(new IpAddress(Ipv4Util.addressForByteBuf(buffer))); return builder.build(); }
From source file:org.opendaylight.protocol.pcep.impl.object.PCEPPceIdIPv6ObjectParser.java
License:Open Source License
@Override public Object 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."); final PceIdBuilder builder = new PceIdBuilder(); builder.setIpAddress(new IpAddress(Ipv6Util.addressForByteBuf(buffer))); return builder.build(); }
From source file:org.opendaylight.protocol.pcep.impl.object.PCEPProcTimeObjectParser.java
License:Open Source License
@Override public Object 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."); final ProcTimeBuilder builder = new ProcTimeBuilder(); buffer.skipBytes(RESERVED);/* www . j av a 2 s.c o m*/ final BitArray flagBits = BitArray.valueOf(buffer, FLAGS); builder.setEstimated(flagBits.get(E_FLAG_POSITION)); builder.setCurrentProcTime(buffer.readUnsignedInt()); builder.setMinProcTime(buffer.readUnsignedInt()); builder.setMaxProcTime(buffer.readUnsignedInt()); builder.setAverageProcTime(buffer.readUnsignedInt()); builder.setVarianceProcTime(buffer.readUnsignedInt()); return builder.build(); }
From source file:org.opendaylight.protocol.pcep.impl.object.PCEPReportedRouteObjectParser.java
License:Open Source License
@Override public Rro 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 RroBuilder builder = new RroBuilder(); builder.setIgnore(header.isIgnore()); builder.setProcessingRule(header.isProcessingRule()); builder.setSubobject(parseSubobjects(bytes.slice())); return builder.build(); }
From source file:org.opendaylight.protocol.pcep.impl.object.PCEPRequestParameterObjectParser.java
License:Open Source License
@Override public Object 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 BitArray flags = BitArray.valueOf(bytes, FLAGS_SIZE); final RpBuilder builder = new RpBuilder(); builder.setIgnore(header.isIgnore()); builder.setProcessingRule(header.isProcessingRule()); short priority = 0; priority |= flags.get(PRI_SF_OFFSET + 2) ? 1 : 0; priority |= (flags.get(PRI_SF_OFFSET + 1) ? 1 : 0) << 1; priority |= (flags.get(PRI_SF_OFFSET) ? 1 : 0) << 2; if (priority != 0) { builder.setPriority(priority);//w ww . j a va 2 s . co m } builder.setFragmentation(flags.get(F_FLAG_OFFSET)); builder.setP2mp(flags.get(N_FLAG_OFFSET)); builder.setEroCompression(flags.get(E_FLAG_OFFSET)); builder.setMakeBeforeBreak(flags.get(M_FLAG_OFFSET)); builder.setOrder(flags.get(D_FLAG_OFFSET)); builder.setPathKey(flags.get(P_FLAG_OFFSET)); builder.setSupplyOf(flags.get(S_FLAG_OFFSET)); builder.setLoose(flags.get(O_FLAG_OFFSET)); builder.setBiDirectional(flags.get(B_FLAG_OFFSET)); builder.setReoptimization(flags.get(R_FLAG_OFFSET)); builder.setRequestId(new RequestId(bytes.readUnsignedInt())); final TlvsBuilder tlvsBuilder = new TlvsBuilder(); parseTlvs(tlvsBuilder, bytes.slice()); builder.setTlvs(tlvsBuilder.build()); return builder.build(); }
From source file:org.opendaylight.protocol.pcep.impl.object.PCEPSvecObjectParser.java
License:Open Source License
@Override public Svec 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 ww w. j a va 2 s . c o m bytes.skipBytes(FLAGS_F_OFFSET); final BitArray flags = BitArray.valueOf(bytes, FLAGS_SIZE); final List<RequestId> requestIDs = Lists.newArrayList(); while (bytes.isReadable()) { requestIDs.add(new RequestId(bytes.readUnsignedInt())); } if (requestIDs.isEmpty()) { throw new PCEPDeserializerException("Empty Svec Object - no request ids."); } final SvecBuilder builder = new SvecBuilder(); builder.setIgnore(header.isIgnore()); builder.setProcessingRule(header.isProcessingRule()); builder.setLinkDiverse(flags.get(L_FLAG_OFFSET)); builder.setNodeDiverse(flags.get(N_FLAG_OFFSET)); builder.setSrlgDiverse(flags.get(S_FLAG_OFFSET)); builder.setRequestsIds(requestIDs); return builder.build(); }
From source file:org.opendaylight.protocol.pcep.impl.PCEPByteToMessageDecoder.java
License:Open Source License
@Override protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out) { if (!in.isReadable()) { LOG.debug("No more content in incoming buffer."); return;// w ww . j a va 2 s. c o m } in.markReaderIndex(); LOG.trace("Received to decode: {}", ByteBufUtil.hexDump(in)); final List<Message> errors = new ArrayList<>(); try { out.add(parse(in, errors)); } catch (final PCEPDeserializerException e) { LOG.debug("Failed to decode protocol message", e); } in.discardReadBytes(); if (!errors.isEmpty()) { // We have a bunch of messages, send them out for (final Object e : errors) { ctx.channel().writeAndFlush(e).addListener(new ChannelFutureListener() { @Override public void operationComplete(final ChannelFuture f) { if (!f.isSuccess()) { LOG.warn("Failed to send message {} to socket {}", e, ctx.channel(), f.cause()); } else { LOG.trace("Message {} sent to socket {}", e, ctx.channel()); } } }); } } }
From source file:org.opendaylight.protocol.pcep.impl.subobject.AsNumberCaseParser.java
License:Open Source License
static AsNumberCase parseSubobject(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() != CONTENT_LENGTH) { throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: " + CONTENT_LENGTH + "."); }//from ww w . j av a 2 s . c o m return new AsNumberCaseBuilder() .setAsNumber( new AsNumberBuilder().setAsNumber(new AsNumber((long) buffer.readUnsignedShort())).build()) .build(); }
From source file:org.opendaylight.protocol.pcep.impl.subobject.EROExplicitExclusionRouteSubobjectParser.java
License:Open Source License
@Override public Subobject parseSubobject(final ByteBuf buffer, final boolean loose) throws PCEPDeserializerException { Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); final SubobjectBuilder builder = new SubobjectBuilder(); builder.setLoose(loose);//w ww .java2 s. co m final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.Subobject> list = parseSubobject( buffer); final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.exrs._case.exrs.Exrs> exrss = Lists .newArrayList(); for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.Subobject s : list) { final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.exrs._case.exrs.ExrsBuilder b = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.subobject.type.exrs._case.exrs.ExrsBuilder(); b.setAttribute(s.getAttribute()); b.setMandatory(s.isMandatory()); b.setSubobjectType(s.getSubobjectType()); exrss.add(b.build()); } builder.setSubobjectType(new ExrsCaseBuilder().setExrs(new ExrsBuilder().setExrs(exrss).build()).build()); return builder.build(); }