if (j == (i + MARKER_LENGTH)) { final int length = ByteArray.bytesToInt(new byte[]{ byteArray[j], byteArray[j + 1] });
public static List<byte[]> parseMessages(final String c) { final String content = clearWhiteSpaceToUpper(c); final int sixteen = 16; final int four = 4; // search for 16 FFs final List<byte[]> messages = Lists.newLinkedList(); int idx = content.indexOf(FF_16, 0); while (idx > -1) { // next 2 bytes are length final int lengthIdx = idx + sixteen * 2; final int messageIdx = lengthIdx + four; final String hexLength = content.substring(lengthIdx, messageIdx); final byte[] byteLength = BaseEncoding.base16().decode(hexLength); final int length = ByteArray.bytesToInt(byteLength); final int messageEndIdx = idx + length * 2; // Assert that message is longer than minimum 19(header.length == 19) // If length in BGP message would be 0, loop would never end Preconditions.checkArgument(length >= MINIMAL_LENGTH, "Invalid message at index " + idx + ", length atribute is lower than " + MINIMAL_LENGTH); final String hexMessage = content.substring(idx, messageEndIdx); final byte[] message = BaseEncoding.base16().decode(hexMessage); messages.add(message); idx = messageEndIdx; idx = content.indexOf(FF_16, idx); } LOG.info("Succesfully extracted {} messages", messages.size()); return messages; }
private static List<Ports> parsePort(final ByteBuf nlri) { final List<Ports> ports = new ArrayList<>(); boolean end = false; // we can do this as all fields will be rewritten in the cycle final PortsBuilder builder = new PortsBuilder(); while (!end) { final byte b = nlri.readByte(); final NumericOperand op = NumericOneByteOperandParser.INSTANCE.parse(b); builder.setOp(op); final short length = AbstractOperandParser.parseLength(b); builder.setValue(ByteArray.bytesToInt(ByteArray.readBytes(nlri, length))); end = op.isEndOfList(); ports.add(builder.build()); } return ports; } }
private static List<PacketLengths> parsePacketLength(final ByteBuf nlri) { final List<PacketLengths> packetLengths = new ArrayList<>(); boolean end = false; // we can do this as all fields will be rewritten in the cycle final PacketLengthsBuilder builder = new PacketLengthsBuilder(); while (!end) { final byte b = nlri.readByte(); final NumericOperand op = NumericOneByteOperandParser.INSTANCE.parse(b); builder.setOp(op); final short length = AbstractOperandParser.parseLength(b); builder.setValue(ByteArray.bytesToInt(ByteArray.readBytes(nlri, length))); end = op.isEndOfList(); packetLengths.add(builder.build()); } return packetLengths; } }
private static List<DestinationPorts> parseDestinationPort(final ByteBuf nlri) { final List<DestinationPorts> ports = new ArrayList<>(); boolean end = false; // we can do this as all fields will be rewritten in the cycle final DestinationPortsBuilder builder = new DestinationPortsBuilder(); while (!end) { final byte b = nlri.readByte(); final NumericOperand op = NumericOneByteOperandParser.INSTANCE.parse(b); builder.setOp(op); final short length = AbstractOperandParser.parseLength(b); builder.setValue(ByteArray.bytesToInt(ByteArray.readBytes(nlri, length))); end = op.isEndOfList(); ports.add(builder.build()); } return ports; } }
private static List<TcpFlags> parseTcpFlags(final ByteBuf nlri) { final List<TcpFlags> flags = new ArrayList<>(); boolean end = false; // we can do this as all fields will be rewritten in the cycle final TcpFlagsBuilder builder = new TcpFlagsBuilder(); while (!end) { final byte b = nlri.readByte(); final BitmaskOperand op = BitmaskOperandParser.INSTANCE.parse(b); builder.setOp(op); final short length = AbstractOperandParser.parseLength(b); builder.setValue(ByteArray.bytesToInt(ByteArray.readBytes(nlri, length))); end = op.isEndOfList(); flags.add(builder.build()); } return flags; } }
private static List<SourcePorts> parseSourcePort(final ByteBuf nlri) { final List<SourcePorts> ports = new ArrayList<>(); boolean end = false; // we can do this as all fields will be rewritten in the cycle final SourcePortsBuilder builder = new SourcePortsBuilder(); while (!end) { final byte b = nlri.readByte(); final NumericOperand op = NumericOneByteOperandParser.INSTANCE.parse(b); builder.setOp(op); final short length = AbstractOperandParser.parseLength(b); builder.setValue(ByteArray.bytesToInt(ByteArray.readBytes(nlri, length))); end = op.isEndOfList(); ports.add(builder.build()); } return ports; } }