List of usage examples for io.netty.buffer ByteBuf readSlice
public abstract ByteBuf readSlice(int length);
From source file:org.opendaylight.protocol.bgp.evpn.impl.nlri.EthSegRParser.java
License:Open Source License
@Override public EvpnChoice parseEvpn(final ByteBuf buffer) { Preconditions.checkArgument(/*from www.j a v a 2 s . c om*/ buffer.readableBytes() == CONTENT_LENGTH || buffer.readableBytes() == CONTENT_LENGTH2, "Wrong length of array of bytes. Passed: %s ;", buffer); final Esi esi = SimpleEsiTypeRegistry.getInstance().parseEsi(buffer.readSlice(ESI_SIZE)); final IpAddress ip = Preconditions.checkNotNull(parseOrigRouteIp(buffer)); final EsRouteBuilder builder = new EsRouteBuilder().setEsi(esi).setOrigRouteIp(ip); return new EsRouteCaseBuilder().setEsRoute(builder.build()).build(); }
From source file:org.opendaylight.protocol.bgp.evpn.impl.nlri.EvpnNlriParser.java
License:Open Source License
@Nullable private List<EvpnDestination> parseNlri(final ByteBuf nlri) { if (!nlri.isReadable()) { return null; }//from ww w .j a va 2s. c o m final List<EvpnDestination> dests = new ArrayList<>(); while (nlri.isReadable()) { final EvpnDestinationBuilder builder = new EvpnDestinationBuilder(); final NlriType type = NlriType.forValue(nlri.readUnsignedByte()); final int length = nlri.readUnsignedByte(); final ByteBuf nlriBuf = nlri.readSlice(length); builder.setRouteDistinguisher(parseRouteDistinguisher(nlriBuf)); builder.setEvpnChoice(SimpleEvpnNlriRegistry.getInstance().parseEvpn(type, nlriBuf)); dests.add(builder.build()); } return dests; }
From source file:org.opendaylight.protocol.bgp.evpn.impl.nlri.MACIpAdvRParser.java
License:Open Source License
@Override public EvpnChoice parseEvpn(final ByteBuf buffer) { final Esi esi = SimpleEsiTypeRegistry.getInstance().parseEsi(buffer.readSlice(ESI_SIZE)); final EthernetTagId eti = new EthernetTagIdBuilder().setVlanId(buffer.readUnsignedInt()).build(); buffer.skipBytes(1);/*www.j ava 2 s. c om*/ final MacAddress mac = IetfYangUtil.INSTANCE.macAddressFor(ByteArray.readBytes(buffer, MAC_ADDRESS_LENGTH)); final IpAddress ip = parseIp(buffer); final MplsLabel label1 = mplsLabelForByteBuf(buffer); MplsLabel label2; if (buffer.readableBytes() > 0) { label2 = mplsLabelForByteBuf(buffer); } else { label2 = null; } final MacIpAdvRouteBuilder builder = new MacIpAdvRouteBuilder().setEsi(esi).setEthernetTagId(eti) .setMacAddress(mac).setIpAddress(ip).setMplsLabel1(label1).setMplsLabel2(label2); return new MacIpAdvRouteCaseBuilder().setMacIpAdvRoute(builder.build()).build(); }
From source file:org.opendaylight.protocol.bgp.evpn.spi.pojo.SimpleEsiTypeRegistry.java
License:Open Source License
@Override public Esi parseEsi(final ByteBuf buffer) { Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); Preconditions.checkArgument(buffer.readableBytes() == CONTENT_LENGTH, "Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";"); final EsiParser parser = this.handlers.getParser(EsiType.forValue(buffer.readByte()).getIntValue()); if (parser == null) { return null; }//from w w w . jav a 2s.c om return parser.parseEsi(buffer.readSlice(ESI_LENGTH)); }
From source file:org.opendaylight.protocol.bgp.labeled.unicast.LUNlriParser.java
License:Open Source License
public static List<LabelStack> parseLabel(final ByteBuf nlri) { if (!nlri.isReadable()) { return null; }/*from www .j av a2 s . co m*/ final List<LabelStack> labels = new ArrayList<>(); boolean bottomBit; do { final ByteBuf slice = nlri.readSlice(LABEL_LENGTH); bottomBit = MplsLabelUtil.getBottomBit(slice); labels.add(new LabelStackBuilder().setLabelValue(MplsLabelUtil.mplsLabelForByteBuf(slice)).build()); } while (!bottomBit); return labels; }
From source file:org.opendaylight.protocol.bgp.linkstate.attribute.LinkAttributesParser.java
License:Open Source License
private static void parseUnreservedBandwidth(final ByteBuf value, final LinkAttributesBuilder builder) { final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.link.state.UnreservedBandwidth> unreservedBandwidth = new ArrayList<>( UNRESERVED_BW_COUNT);/*from ww w . j av a 2 s .com*/ for (int i = 0; i < UNRESERVED_BW_COUNT; i++) { final ByteBuf v = value.readSlice(BANDWIDTH_LENGTH); unreservedBandwidth.add(new UnreservedBandwidthBuilder() .setBandwidth(new Bandwidth(ByteArray.readAllBytes(v))).setPriority((short) i).build()); } builder.setUnreservedBandwidth(unreservedBandwidth); LOG.debug("Parsed Unreserved Bandwidth {}", builder.getUnreservedBandwidth()); }
From source file:org.opendaylight.protocol.bgp.linkstate.attribute.LinkstateAttributeParser.java
License:Open Source License
private static Multimap<Integer, ByteBuf> getAttributesMap(final ByteBuf buffer) { /*/* w w w.j a v a2s. c om*/ * e.g. IS-IS Area Identifier TLV can occur multiple times */ final Multimap<Integer, ByteBuf> map = HashMultimap.create(); while (buffer.isReadable()) { final int type = buffer.readUnsignedShort(); final int length = buffer.readUnsignedShort(); final ByteBuf value = buffer.readSlice(length); map.put(type, value); } return map; }
From source file:org.opendaylight.protocol.bgp.linkstate.attribute.sr.BindingSidLabelParser.java
License:Open Source License
private static List<BindingSubTlvs> parseBindingSubTlvs(final ByteBuf buffer, final ProtocolId protocolId) { final List<BindingSubTlvs> subTlvs = new ArrayList<BindingSubTlvs>(); while (buffer.isReadable()) { final int type = buffer.readUnsignedShort(); final int length = buffer.readUnsignedShort(); final ByteBuf slice = buffer.readSlice(length); final BindingSubTlvsBuilder builder = new BindingSubTlvsBuilder(); parseSubTlv(type, slice, builder, protocolId); subTlvs.add(builder.build());/*from ww w . j a va 2 s. co m*/ } return subTlvs; }
From source file:org.opendaylight.protocol.bgp.linkstate.attribute.sr.RangeTlvParser.java
License:Open Source License
private static List<SubTlvs> parseRangeSubTlvs(final ByteBuf buffer, final ProtocolId protocolId) { final List<SubTlvs> subTlvs = new ArrayList<>(); while (buffer.isReadable()) { final SubTlvsBuilder subTlv = new SubTlvsBuilder(); RangeSubTlv subTlvCase = null;/*ww w. j a v a2 s. c o m*/ final int type = buffer.readUnsignedShort(); final int length = buffer.readUnsignedShort(); switch (type) { case PrefixAttributesParser.PREFIX_SID: subTlvCase = new PrefixSidTlvCaseBuilder( SrPrefixAttributesParser.parseSrPrefix(buffer.readSlice(length), protocolId)).build(); break; case PrefixAttributesParser.BINDING_SID: subTlvCase = new BindingSidTlvCaseBuilder( BindingSidLabelParser.parseBindingSidLabel(buffer.readSlice(length), protocolId)).build(); break; case SidLabelIndexParser.SID_TYPE: subTlvCase = new SidLabelTlvCaseBuilder().setSidLabelIndex( SidLabelIndexParser.parseSidLabelIndex(Size.forValue(length), buffer.readSlice(length))) .build(); break; default: LOG.info("Unknown type of range sub-tlv: {}", type); buffer.skipBytes(length); continue; } subTlvs.add(subTlv.setRangeSubTlv(subTlvCase).build()); } return subTlvs; }
From source file:org.opendaylight.protocol.bgp.linkstate.attribute.TeLspAttributesParser.java
License:Open Source License
public static LinkStateAttribute parseTeLspAttributes(final RSVPTeObjectRegistry registry, final ByteBuf attributes) throws BGPParsingException { final TeLspAttributesBuilder builder = new TeLspAttributesBuilder(); LOG.trace("Initiated parsing TE LSP Objects."); while (attributes.isReadable()) { final int length = attributes.readUnsignedShort(); final int classNum = attributes.readUnsignedByte(); final int cType = attributes.readUnsignedByte(); final ByteBuf value = attributes.readSlice(length); try {/*w w w .j a va 2 s . c o m*/ addObject(builder, registry.parseRSPVTe(classNum, cType, value)); } catch (final RSVPParsingException e) { LOG.debug("Parsering TE LSP Object error. class number: {} cType: {} value: {}", classNum, cType, value, e); throw new BGPParsingException(e.getMessage()); } } LOG.trace("Finished parsing TE LSP Objects."); return new TeLspAttributesCaseBuilder().setTeLspAttributes(builder.build()).build(); }