List of usage examples for io.netty.buffer ByteBuf isReadable
public abstract boolean isReadable();
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 .j a va2 s. c om return parser.parseEsi(buffer.readSlice(ESI_LENGTH)); }
From source file:org.opendaylight.protocol.bgp.evpn.spi.pojo.SimpleEvpnNlriRegistry.java
License:Open Source License
@Override public EvpnChoice parseEvpn(final NlriType type, final ByteBuf buffer) { Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); final EvpnParser parser = this.handlers.getParser(type.getIntValue()); if (parser == null) { return null; }//w ww . j a v a2 s . c o m return parser.parseEvpn(buffer); }
From source file:org.opendaylight.protocol.bgp.flowspec.AbstractFlowspecNlriParser.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/*from w w w . j a v a 2 s. c om*/ */ protected final List<Flowspec> parseNlriFlowspecList(@Nonnull final ByteBuf nlri) throws BGPParsingException { if (!nlri.isReadable()) { return null; } final List<Flowspec> fss = new ArrayList<>(); while (nlri.isReadable()) { final FlowspecBuilder builder = new FlowspecBuilder(); builder.setFlowspecType(this.flowspecTypeRegistry.parseFlowspecType(nlri)); fss.add(builder.build()); } return fss; }
From source file:org.opendaylight.protocol.bgp.flowspec.AbstractFlowspecNlriParser.java
License:Open Source License
@Override public final void parseNlri(@Nonnull final ByteBuf nlri, @Nonnull final MpReachNlriBuilder builder, @Nullable final PeerSpecificParserConstraint constraint) throws BGPParsingException { if (!nlri.isReadable()) { return;// ww w . j a va2 s . c om } final PathId pathId = readPathId(nlri, builder.getAfi(), builder.getSafi(), constraint); verifyNlriLength(nlri); final Object[] nlriFields = parseNlri(nlri); builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder() .setDestinationType(createAdvertizedRoutesDestinationType(nlriFields, pathId)).build()); }
From source file:org.opendaylight.protocol.bgp.flowspec.AbstractFlowspecNlriParser.java
License:Open Source License
@Override public final void parseNlri(@Nonnull final ByteBuf nlri, @Nonnull final MpUnreachNlriBuilder builder, @Nullable final PeerSpecificParserConstraint constraint) throws BGPParsingException { if (!nlri.isReadable()) { return;/*from w ww . j a v a2 s. com*/ } final PathId pathId = readPathId(nlri, builder.getAfi(), builder.getSafi(), constraint); verifyNlriLength(nlri); final Object[] nlriFields = parseNlri(nlri); builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder() .setDestinationType(createWithdrawnDestinationType(nlriFields, pathId)).build()); }
From source file:org.opendaylight.protocol.bgp.flowspec.AbstractFSNlriParser.java
License:Open Source License
@Override public final void parseNlri(final ByteBuf nlri, final MpUnreachNlriBuilder builder) throws BGPParsingException { if (!nlri.isReadable()) { return;//from www . j a v a 2 s . c o m } final List<Flowspec> dst = parseNlri(nlri); builder.setWithdrawnRoutes( new WithdrawnRoutesBuilder().setDestinationType(createWidthdrawnDestinationType(dst)).build()); }
From source file:org.opendaylight.protocol.bgp.flowspec.AbstractFSNlriParser.java
License:Open Source License
@Override public final void parseNlri(final ByteBuf nlri, final MpReachNlriBuilder builder) throws BGPParsingException { if (!nlri.isReadable()) { return;/*w w w . ja v a 2 s .c om*/ } final List<Flowspec> dst = parseNlri(nlri); builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder() .setDestinationType(createAdvertizedRoutesDestinationType(dst)).build()); }
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 2 s . c om */ 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.inet.codec.Ipv4NlriParser.java
License:Open Source License
private static DestinationIpv4 prefixes(final ByteBuf nlri, final PeerSpecificParserConstraint constraints, final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi) { final List<Ipv4Prefixes> prefixes = new ArrayList<>(); while (nlri.isReadable()) { final Ipv4PrefixesBuilder prefixesBuilder = new Ipv4PrefixesBuilder(); if (MultiPathSupportUtil.isTableTypeSupported(constraints, new BgpTableTypeImpl(afi, safi))) { prefixesBuilder.setPathId(PathIdUtil.readPathId(nlri)); }//ww w. ja v a2 s .c om prefixesBuilder.setPrefix(Ipv4Util.prefixForByteBuf(nlri)); prefixes.add(prefixesBuilder.build()); } return new DestinationIpv4Builder().setIpv4Prefixes(prefixes).build(); }
From source file:org.opendaylight.protocol.bgp.inet.codec.Ipv6NlriParser.java
License:Open Source License
private static DestinationIpv6 prefixes(final ByteBuf nlri, final PeerSpecificParserConstraint constraint, final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi) { final List<Ipv6Prefixes> prefixes = new ArrayList<>(); final boolean supported = MultiPathSupportUtil.isTableTypeSupported(constraint, new BgpTableTypeImpl(afi, safi)); while (nlri.isReadable()) { final Ipv6PrefixesBuilder prefixesBuilder = new Ipv6PrefixesBuilder(); if (supported) { prefixesBuilder.setPathId(PathIdUtil.readPathId(nlri)); }//from w w w.j a v a 2 s . co m prefixesBuilder.setPrefix(Ipv6Util.prefixForByteBuf(nlri)); prefixes.add(prefixesBuilder.build()); } return new DestinationIpv6Builder().setIpv6Prefixes(prefixes).build(); }