List of usage examples for io.netty.buffer ByteBuf readUnsignedByte
public abstract short readUnsignedByte();
From source file:org.opendaylight.protocol.bgp.evpn.spi.pojo.SimpleEvpnNlriRegistryTest.java
License:Open Source License
@Test public void registryTest() { final ByteBuf buff = SimpleEvpnNlriRegistry.getInstance().serializeEvpn(ETHERNET_AD_ROUTE_CASE, Unpooled.wrappedBuffer(ROUDE_DISTIN)); assertArrayEquals(EthADRParserTest.RESULT, ByteArray.getAllBytes(buff)); final EvpnChoice resultModel = SimpleEvpnNlriRegistry.getInstance().serializeEvpnModel(createEthADRModel()); assertEquals(ETHERNET_AD_ROUTE_CASE, resultModel); final NlriType type = NlriType.forValue(buff.readUnsignedByte()); buff.skipBytes(VALUE_SIZE); // length + RD assertEquals(ETHERNET_AD_ROUTE_CASE, SimpleEvpnNlriRegistry.getInstance().parseEvpn(type, buff)); }
From source file:org.opendaylight.protocol.bgp.flowspec.AbstractFlowspecNlriParser.java
License:Open Source License
/** * This step is used to verify the NLRI length we read from BGP message * * @param nlri/*from www .j a v a2 s . com*/ */ private static final void verifyNlriLength(@Nonnull final ByteBuf nlri) { // length field can be one or two bytes (if needed) // check the length of nlri to see how many bytes we can skip int readableLength = nlri.readableBytes(); // read the length from field final int expectedLength; if (readableLength > MAX_NLRI_LENGTH_ONE_BYTE) { expectedLength = nlri.readUnsignedShort(); // deduct the two bytes of the NLRI length field readableLength -= NLRI_LENGTH_EXTENDED; } else { expectedLength = nlri.readUnsignedByte(); // deduct the one byte of the NLRI length field readableLength -= NLRI_LENGTH; } Preconditions.checkState(readableLength == expectedLength, "NLRI length read from message doesn't match. Length expected (read from NLRI) is %s, length readable is %s", expectedLength, readableLength); }
From source file:org.opendaylight.protocol.bgp.flowspec.AbstractFSNlriParser.java
License:Open Source License
/** * Parses Flowspec NLRI into list of Flowspec. * * @param nlri byte representation of NLRI which will be parsed * @return list of Flowspec// w w w.j av a 2s. c o m */ public final List<Flowspec> parseNlri(final ByteBuf nlri) throws BGPParsingException { if (!nlri.isReadable()) { return null; } final List<Flowspec> fss = new ArrayList<>(); // length field can be one or two bytes (if needed) // check the length of nlri to see how many bytes we can skip final int length = nlri.readableBytes(); nlri.skipBytes(length > MAX_NLRI_LENGTH_ONE_BYTE ? NLRI_LENGTH_EXTENDED : NLRI_LENGTH); while (nlri.isReadable()) { final FlowspecBuilder builder = new FlowspecBuilder(); final short type = nlri.readUnsignedByte(); setFlowspecType(builder, type, nlri); fss.add(builder.build()); } return fss; }
From source file:org.opendaylight.protocol.bgp.flowspec.AbstractFSNlriParser.java
License:Open Source License
private static List<Types> parseIcmpType(final ByteBuf nlri) { final List<Types> types = new ArrayList<>(); boolean end = false; // we can do this as all fields will be rewritten in the cycle final TypesBuilder builder = new TypesBuilder(); while (!end) { final byte b = nlri.readByte(); final NumericOperand op = NumericOneByteOperandParser.INSTANCE.parse(b); builder.setOp(op);/* w ww.j av a 2s .c o m*/ builder.setValue(nlri.readUnsignedByte()); end = op.isEndOfList(); types.add(builder.build()); } return types; }
From source file:org.opendaylight.protocol.bgp.flowspec.AbstractFSNlriParser.java
License:Open Source License
private static List<Codes> parseIcmpCode(final ByteBuf nlri) { final List<Codes> codes = new ArrayList<>(); boolean end = false; // we can do this as all fields will be rewritten in the cycle final CodesBuilder builder = new CodesBuilder(); while (!end) { final byte b = nlri.readByte(); final NumericOperand op = NumericOneByteOperandParser.INSTANCE.parse(b); builder.setOp(op);/* w w w .j a v a 2 s.co m*/ builder.setValue(nlri.readUnsignedByte()); end = op.isEndOfList(); codes.add(builder.build()); } return codes; }
From source file:org.opendaylight.protocol.bgp.flowspec.AbstractFSNlriParser.java
License:Open Source License
private static List<Dscps> parseDscp(final ByteBuf nlri) { final List<Dscps> dscps = new ArrayList<>(); boolean end = false; // we can do this as all fields will be rewritten in the cycle final DscpsBuilder builder = new DscpsBuilder(); while (!end) { final byte b = nlri.readByte(); // RFC does not specify operator final NumericOperand op = NumericOneByteOperandParser.INSTANCE.parse(b); builder.setOp(op);//ww w . j a va 2 s . co m builder.setValue( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.Dscp( nlri.readUnsignedByte())); end = op.isEndOfList(); dscps.add(builder.build()); } return dscps; }
From source file:org.opendaylight.protocol.bgp.flowspec.extended.communities.TrafficMarkingEcHandler.java
License:Open Source License
@Override public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) throws BGPDocumentedException, BGPParsingException { buffer.skipBytes(RESERVED);//from w w w . j a v a 2s . co m final Dscp dscp = new Dscp(buffer.readUnsignedByte()); return new TrafficMarkingExtendedCommunityCaseBuilder().setTrafficMarkingExtendedCommunity( new TrafficMarkingExtendedCommunityBuilder().setGlobalAdministrator(dscp).build()).build(); }
From source file:org.opendaylight.protocol.bgp.flowspec.FSDscpHandler.java
License:Open Source License
private static List<Dscps> parseDscps(final ByteBuf nlri) { final List<Dscps> dscps = new ArrayList<>(); boolean end = false; // we can do this as all fields will be rewritten in the cycle final DscpsBuilder builder = new DscpsBuilder(); while (!end) { final byte b = nlri.readByte(); // RFC does not specify operator final NumericOperand op = NumericOneByteOperandParser.INSTANCE.parse(b); builder.setOp(op);/*from w w w. j ava2 s . c o m*/ builder.setValue( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.Dscp( nlri.readUnsignedByte())); end = op.isEndOfList(); dscps.add(builder.build()); } return dscps; }
From source file:org.opendaylight.protocol.bgp.flowspec.FSIcmpTypeHandler.java
License:Open Source License
private static List<Types> parseIcmpType(final ByteBuf nlri) { final List<Types> icmps = new ArrayList<>(); boolean end = false; // we can do this as all fields will be rewritten in the cycle final TypesBuilder builder = new TypesBuilder(); while (!end) { final byte b = nlri.readByte(); final NumericOperand op = NumericOneByteOperandParser.INSTANCE.parse(b); builder.setOp(op);/*from w w w . j av a 2 s . co m*/ builder.setValue(nlri.readUnsignedByte()); end = op.isEndOfList(); icmps.add(builder.build()); } return icmps; }
From source file:org.opendaylight.protocol.bgp.flowspec.FSIpProtocolHandler.java
License:Open Source License
private static List<ProtocolIps> parseProtocolIp(final ByteBuf nlri) { final List<ProtocolIps> ips = new ArrayList<>(); boolean end = false; // we can do this as all fields will be rewritten in the cycle final ProtocolIpsBuilder builder = new ProtocolIpsBuilder(); while (!end) { final byte b = nlri.readByte(); final NumericOperand op = NumericOneByteOperandParser.INSTANCE.parse(b); builder.setOp(op);/*from w w w .j av a 2s. c o m*/ builder.setValue(nlri.readUnsignedByte()); end = op.isEndOfList(); ips.add(builder.build()); } return ips; }