List of usage examples for io.netty.buffer ByteBuf readUnsignedInt
public abstract long readUnsignedInt();
From source file:org.opendaylight.bgp.concepts.RouteDistinguisherUtil.java
License:Open Source License
/** * Parses three types of route distinguisher from given ByteBuf. * * @param buffer/*from w w w .j ava2 s . c om*/ * @return RouteDistinguisher */ public static RouteDistinguisher parseRouteDistinguisher(final ByteBuf buffer) { Preconditions.checkState(buffer != null && buffer.isReadable(RD_LENGTH), "Cannot read Route Distinguisher from provided buffer."); final int type = buffer.readUnsignedShort(); final RD_TYPE rdType = RD_TYPE.valueOf(type); final StringBuilder routeDistiguisher = new StringBuilder(); switch (rdType) { case AS_2BYTE: routeDistiguisher.append(type); routeDistiguisher.append(SEPARATOR); routeDistiguisher.append(buffer.readUnsignedShort()); routeDistiguisher.append(SEPARATOR); routeDistiguisher.append(buffer.readUnsignedInt()); return new RouteDistinguisher(new RdTwoOctetAs(routeDistiguisher.toString())); case IPV4: routeDistiguisher.append(Ipv4Util.addressForByteBuf(buffer).getValue()); routeDistiguisher.append(SEPARATOR); routeDistiguisher.append(buffer.readUnsignedShort()); return new RouteDistinguisher(new RdIpv4(routeDistiguisher.toString())); case AS_4BYTE: routeDistiguisher.append(buffer.readUnsignedInt()); routeDistiguisher.append(SEPARATOR); routeDistiguisher.append(buffer.readUnsignedShort()); return new RouteDistinguisher(new RdAs(routeDistiguisher.toString())); default: // now that this RD type is not supported, we want to read the remain 6 bytes // in order to get the byte index correct for (int i = 0; i < 6; i++) { routeDistiguisher.append("0x").append(Integer.toHexString(buffer.readByte() & 0xFF)).append(" "); } LOG.debug("Invalid Route Distinguisher: type={}, rawRouteDistinguisherValue={}", type, routeDistiguisher.toString()); throw new IllegalArgumentException("Invalid Route Distinguisher type " + type); } }
From source file:org.opendaylight.capwap.ODLCapwapControlMessage.java
License:Open Source License
int decode(ByteBuf buf) { //ByteBuf bbuf = Unpooled.wrappedBuffer(buf); //ByteBuf tmpbuf = bbuf.readerIndex(pos); this.msgType = buf.readUnsignedInt(); this.seqNo = buf.readUnsignedByte(); this.msgLen = buf.readUnsignedShort(); this.flags = buf.readUnsignedByte(); return 0;/*w w w .j a va 2 s . c o m*/ }
From source file:org.opendaylight.ext.impl.FooActionDeserializer.java
License:Open Source License
@Override public Action deserialize(ByteBuf input) { input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); // we know the type of action input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES); // we don't need length ActionBuilder actionBuilder = new ActionBuilder(); actionBuilder.setExperimenterId(new ExperimenterId(input.readUnsignedInt())); ActionFooBuilder actionFooBuilder = new ActionFooBuilder(); ExtActionFooBuilder extActionFooBuilder = new ExtActionFooBuilder(); extActionFooBuilder.setFirst(input.readUnsignedShort()); extActionFooBuilder.setSecond(input.readUnsignedShort()); input.skipBytes(4); // padding actionFooBuilder.setExtActionFoo(extActionFooBuilder.build()); actionBuilder.setActionChoice(actionFooBuilder.build()); return actionBuilder.build(); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.deserialization.factories.BarrierInputMessageFactory.java
License:Open Source License
@Override public BarrierInput deserialize(ByteBuf rawMessage) { BarrierInputBuilder builder = new BarrierInputBuilder(); builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); return builder.build(); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.deserialization.factories.FlowModInputMessageFactory.java
License:Open Source License
@Override public FlowModInput deserialize(ByteBuf rawMessage) { FlowModInputBuilder builder = new FlowModInputBuilder(); builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; rawMessage.readBytes(cookie);//from w w w .j a v a 2 s . c om builder.setCookie(new BigInteger(1, cookie)); byte[] cookie_mask = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; rawMessage.readBytes(cookie_mask); builder.setCookieMask(new BigInteger(1, cookie_mask)); builder.setTableId(new TableId((long) rawMessage.readUnsignedByte())); builder.setCommand(FlowModCommand.forValue(rawMessage.readUnsignedByte())); builder.setIdleTimeout(rawMessage.readUnsignedShort()); builder.setHardTimeout(rawMessage.readUnsignedShort()); builder.setPriority(rawMessage.readUnsignedShort()); builder.setBufferId(rawMessage.readUnsignedInt()); builder.setOutPort(new PortNumber(rawMessage.readUnsignedInt())); builder.setOutGroup(rawMessage.readUnsignedInt()); builder.setFlags(createFlowModFlagsFromBitmap(rawMessage.readUnsignedShort())); rawMessage.skipBytes(PADDING); OFDeserializer<Match> matchDeserializer = registry.getDeserializer( new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Match.class)); builder.setMatch(matchDeserializer.deserialize(rawMessage)); CodeKeyMaker keyMaker = CodeKeyMakerFactory.createInstructionsKeyMaker(EncodeConstants.OF13_VERSION_ID); List<Instruction> instructions = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID, rawMessage.readableBytes(), rawMessage, keyMaker, registry); builder.setInstruction(instructions); return builder.build(); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.deserialization.factories.GetAsyncRequestMessageFactory.java
License:Open Source License
@Override public GetAsyncInput deserialize(ByteBuf rawMessage) { GetAsyncInputBuilder builder = new GetAsyncInputBuilder(); builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); builder.setXid((rawMessage.readUnsignedInt())); return builder.build(); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.deserialization.factories.GetConfigInputMessageFactory.java
License:Open Source License
@Override public GetConfigInput deserialize(ByteBuf rawMessage) { GetConfigInputBuilder builder = new GetConfigInputBuilder(); builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); return builder.build(); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.deserialization.factories.GetFeaturesInputMessageFactory.java
License:Open Source License
@Override public GetFeaturesInput deserialize(ByteBuf rawMessage) { GetFeaturesInputBuilder builder = new GetFeaturesInputBuilder(); builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); return builder.build(); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.deserialization.factories.GetQueueConfigInputMessageFactory.java
License:Open Source License
@Override public GetQueueConfigInput deserialize(ByteBuf rawMessage) { GetQueueConfigInputBuilder builder = new GetQueueConfigInputBuilder(); builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); builder.setXid((rawMessage.readUnsignedInt())); builder.setPort(new PortNumber(rawMessage.readUnsignedInt())); return builder.build(); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.deserialization.factories.GroupModInputMessageFactory.java
License:Open Source License
@Override public GroupModInput deserialize(ByteBuf rawMessage) { GroupModInputBuilder builder = new GroupModInputBuilder(); builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); builder.setCommand(GroupModCommand.forValue(rawMessage.readUnsignedShort())); builder.setType(GroupType.forValue(rawMessage.readUnsignedByte())); rawMessage.skipBytes(PADDING);/*from w ww. j a v a 2 s .c om*/ builder.setGroupId(new GroupId(rawMessage.readUnsignedInt())); List<BucketsList> bucketsList = new ArrayList<>(); while (rawMessage.readableBytes() > 0) { BucketsListBuilder bucketsBuilder = new BucketsListBuilder(); int bucketsLength = rawMessage.readUnsignedShort(); bucketsBuilder.setWeight(rawMessage.readUnsignedShort()); bucketsBuilder.setWatchPort(new PortNumber(rawMessage.readUnsignedInt())); bucketsBuilder.setWatchGroup(rawMessage.readUnsignedInt()); rawMessage.skipBytes(PADDING_IN_BUCKETS_HEADER); CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF13_VERSION_ID); List<Action> actions = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID, bucketsLength - BUCKETS_HEADER_LENGTH, rawMessage, keyMaker, registry); bucketsBuilder.setAction(actions); bucketsList.add(bucketsBuilder.build()); } builder.setBucketsList(bucketsList); return builder.build(); }