List of usage examples for io.netty.buffer ByteBuf readUnsignedByte
public abstract short readUnsignedByte();
From source file:org.opendaylight.protocol.bgp.flowspec.FSIpv6NextHeaderHandler.java
License:Open Source License
private static List<NextHeaders> parseNextHeader(final ByteBuf nlri) { final List<NextHeaders> headers = new ArrayList<>(); boolean end = false; // we can do this as all fields will be rewritten in the cycle final NextHeadersBuilder builder = new NextHeadersBuilder(); while (!end) { final byte b = nlri.readByte(); final NumericOperand op = NumericOneByteOperandParser.INSTANCE.parse(b); builder.setOp(op);/*from w ww. j a v a2s . co m*/ builder.setValue(nlri.readUnsignedByte()); end = op.isEndOfList(); headers.add(builder.build()); } return headers; }
From source file:org.opendaylight.protocol.bgp.flowspec.FSIpv6NlriParser.java
License:Open Source License
private static Ipv6Prefix parseIpv6Prefix(final ByteBuf nlri) { final int bitLength = nlri.readUnsignedByte(); // in case of ipv6 prefix we don't need to skip offset nlri.readUnsignedByte();/* w ww . j a v a 2 s . c o m*/ return Ipv6Util.prefixForBytes(ByteArray.readBytes(nlri, bitLength / Byte.SIZE), bitLength); }
From source file:org.opendaylight.protocol.bgp.flowspec.handlers.FSIpv6SourcePrefixHandler.java
License:Open Source License
static Ipv6Prefix parseIpv6Prefix(final ByteBuf nlri) { final int bitLength = nlri.readUnsignedByte(); nlri.readUnsignedByte();// www. j a v a2s.com // FIXME: this does not look right if bitLenght % Byte.SIZE != 0 return Ipv6Util.prefixForBytes(ByteArray.readBytes(nlri, bitLength / Byte.SIZE), bitLength); }
From source file:org.opendaylight.protocol.bgp.flowspec.SimpleFlowspecTypeRegistry.java
License:Open Source License
public FlowspecType parseFlowspecType(ByteBuf buffer) { final short type = buffer.readUnsignedByte(); final FlowspecTypeParser parser = getFlowspecTypeParser(type); Preconditions.checkNotNull(parser, "parser for flowspec type %s is not registered", type); return parser.parseType(buffer); }
From source file:org.opendaylight.protocol.bgp.l3vpn.AbstractVpnNlriParser.java
License:Open Source License
private static List<VpnDestination> parseNlri(final ByteBuf nlri, final Class<? extends AddressFamily> afi) { if (!nlri.isReadable()) { return null; }//from w w w . ja va2 s . com final List<VpnDestination> dests = new ArrayList<>(); while (nlri.isReadable()) { final VpnDestinationBuilder builder = new VpnDestinationBuilder(); final short length = nlri.readUnsignedByte(); builder.setLabelStack(LUNlriParser.parseLabel(nlri)); final int labelNum = builder.getLabelStack().size(); final int prefixLen = length - (LUNlriParser.LABEL_LENGTH * Byte.SIZE * labelNum) - (RouteDistinguisherUtil.RD_LENGTH * Byte.SIZE); builder.setRouteDistinguisher(RouteDistinguisherUtil.parseRouteDistinguisher(nlri)); Preconditions.checkState(prefixLen > 0, "A valid VPN IP prefix is required."); builder.setPrefix(LUNlriParser.parseIpPrefix(nlri, prefixLen, afi)); dests.add(builder.build()); } return dests; }
From source file:org.opendaylight.protocol.bgp.labeled.unicast.LUNlriParser.java
License:Open Source License
private static List<CLabeledUnicastDestination> parseNlri(final ByteBuf nlri, final Class<? extends AddressFamily> afi, final boolean mPathSupported) { if (!nlri.isReadable()) { return null; }/*from w w w. j a v a 2s .c o m*/ final List<CLabeledUnicastDestination> dests = new ArrayList<>(); while (nlri.isReadable()) { final CLabeledUnicastDestinationBuilder builder = new CLabeledUnicastDestinationBuilder(); if (mPathSupported) { builder.setPathId(PathIdUtil.readPathId(nlri)); } final short length = nlri.readUnsignedByte(); builder.setLabelStack(parseLabel(nlri)); final int labelNum = builder.getLabelStack().size(); final int prefixLen = length - (LABEL_LENGTH * Byte.SIZE * labelNum); builder.setPrefix(parseIpPrefix(nlri, prefixLen, afi)); dests.add(builder.build()); } return dests; }
From source file:org.opendaylight.protocol.bgp.linkstate.attribute.sr.BindingSidLabelParser.java
License:Open Source License
public static SrBindingSidLabels parseBindingSidLabel(final ByteBuf buffer, final ProtocolId protocolId) { final SrBindingSidLabelsBuilder bindingSid = new SrBindingSidLabelsBuilder(); bindingSid.setWeight(new Weight(buffer.readUnsignedByte())); final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE); bindingSid.setFlags(parseBindingSidFlags(flags, protocolId)); buffer.skipBytes(RESERVED_BINDING_SID); bindingSid.setBindingSubTlvs(parseBindingSubTlvs(buffer, protocolId)); return bindingSid.build(); }
From source file:org.opendaylight.protocol.bgp.linkstate.attribute.sr.SrLinkAttributesParser.java
License:Open Source License
public static AdjSidTlv parseAdjacencySegmentIdentifier(final ByteBuf buffer, final ProtocolId protocolId) { final Flags adjFlags; final Weight weight; final SidLabelIndex sidValue; if (buffer.isReadable()) { final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE); adjFlags = parseFlags(flags, protocolId); weight = new Weight(buffer.readUnsignedByte()); buffer.skipBytes(RESERVED);/*from w w w. j ava 2s .c o m*/ sidValue = SidLabelIndexParser.parseSidLabelIndex(Size.forValue(buffer.readableBytes()), buffer); } else { adjFlags = null; weight = null; sidValue = null; } return new AdjSidTlv() { @Override public Class<? extends DataContainer> getImplementedInterface() { return AdjSidTlv.class; } @Override public Weight getWeight() { return weight; } @Override public SidLabelIndex getSidLabelIndex() { return sidValue; } @Override public Flags getFlags() { return adjFlags; } }; }
From source file:org.opendaylight.protocol.bgp.linkstate.attribute.sr.SrLinkAttributesParser.java
License:Open Source License
public static SrLanAdjIds parseLanAdjacencySegmentIdentifier(final ByteBuf buffer, final ProtocolId protocolId) { if (!buffer.isReadable()) { return new SrLanAdjIdsBuilder().build(); }//from w w w. j a va 2s . co m final SrLanAdjIdsBuilder srLanAdjIdBuilder = new SrLanAdjIdsBuilder(); final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE); srLanAdjIdBuilder.setFlags(parseFlags(flags, protocolId)); srLanAdjIdBuilder.setWeight(new Weight(buffer.readUnsignedByte())); buffer.skipBytes(RESERVED); if (protocolId.equals(ProtocolId.IsisLevel1) || protocolId.equals(ProtocolId.IsisLevel2)) { srLanAdjIdBuilder .setIsoSystemId(new IsoSystemIdentifier(ByteArray.readBytes(buffer, ISO_SYSTEM_ID_SIZE))); } else if (protocolId.equals(ProtocolId.Ospf)) { srLanAdjIdBuilder.setNeighborId(Ipv4Util.addressForByteBuf(buffer)); } // length determines a type of next field, which is used for parsing srLanAdjIdBuilder.setSidLabelIndex( SidLabelIndexParser.parseSidLabelIndex(Size.forValue(buffer.readableBytes()), buffer)); return srLanAdjIdBuilder.build(); }
From source file:org.opendaylight.protocol.bgp.linkstate.attribute.sr.SrNodeAttributesParser.java
License:Open Source License
public static SrAlgorithm parseSrAlgorithms(final ByteBuf buffer) { final SrAlgorithmBuilder builder = new SrAlgorithmBuilder(); final List<Algorithm> algs = new ArrayList<>(); while (buffer.isReadable()) { algs.add(Algorithm.forValue(buffer.readUnsignedByte())); }// w w w. ja va 2s . com builder.setAlgorithms(algs); return builder.build(); }