List of usage examples for io.netty.buffer ByteBuf readUnsignedShort
public abstract int readUnsignedShort();
From source file:org.opendaylight.protocol.bgp.evpn.impl.extended.communities.Layer2AttributesExtCom.java
License:Open Source License
@Override public ExtendedCommunity parseExtendedCommunity(final ByteBuf body) throws BGPDocumentedException, BGPParsingException { final Layer2AttributesExtendedCommunityBuilder builder = new Layer2AttributesExtendedCommunityBuilder(); final BitArray flags = BitArray.valueOf(body, FLAGS_SIZE); builder.setPrimaryPe(flags.get(PRIMARY_PE_OFFSET)); builder.setBackupPe(flags.get(BACKUP_PE_OFFSET)); builder.setControlWord(flags.get(CONTROL_WORD_OFFSET)); builder.setL2Mtu(body.readUnsignedShort()); body.skipBytes(RESERVED);/*from w w w . ja v a2s. c o m*/ return new Layer2AttributesExtendedCommunityCaseBuilder() .setLayer2AttributesExtendedCommunity(builder.build()).build(); }
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/* w ww . j a v a 2 s. c om*/ */ 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.extended.communities.RedirectAsFourOctetEcHandler.java
License:Open Source License
@Override public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) throws BGPDocumentedException, BGPParsingException { final RedirectAs4Builder builder = new RedirectAs4Builder(); builder.setGlobalAdministrator(new AsNumber(buffer.readUnsignedInt())); builder.setLocalAdministrator(buffer.readUnsignedShort()); return new RedirectAs4ExtendedCommunityCaseBuilder().setRedirectAs4(builder.build()).build(); }
From source file:org.opendaylight.protocol.bgp.flowspec.extended.communities.RedirectAsTwoOctetEcHandler.java
License:Open Source License
@Override public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) throws BGPDocumentedException, BGPParsingException { final ShortAsNumber as1 = new ShortAsNumber((long) buffer.readUnsignedShort()); final byte[] byteValue = ByteArray.readBytes(buffer, TRAFFIC_RATE_SIZE); return new RedirectExtendedCommunityCaseBuilder() .setRedirectExtendedCommunity(new RedirectExtendedCommunityBuilder().setGlobalAdministrator(as1) .setLocalAdministrator(byteValue).build()) .build();// www.java 2 s. com }
From source file:org.opendaylight.protocol.bgp.flowspec.extended.communities.RedirectIpNextHopEcHandler.java
License:Open Source License
@Override public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) throws BGPDocumentedException, BGPParsingException { final RedirectIpNhExtendedCommunityBuilder builder = new RedirectIpNhExtendedCommunityBuilder(); if (buffer.readableBytes() > Ipv6Util.IPV6_LENGTH) { builder.setNextHopAddress(new IpAddress(Ipv6Util.addressForByteBuf(buffer))); } else {// ww w . j a v a 2 s . c om builder.setNextHopAddress(new IpAddress(Ipv4Util.addressForByteBuf(buffer))); } builder.setCopy((buffer.readUnsignedShort() & COPY) == 1); return new RedirectIpNhExtendedCommunityCaseBuilder().setRedirectIpNhExtendedCommunity(builder.build()) .build(); }
From source file:org.opendaylight.protocol.bgp.flowspec.extended.communities.RedirectIpv4EcHandler.java
License:Open Source License
@Override public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) throws BGPDocumentedException, BGPParsingException { final RedirectIpv4Builder builder = new RedirectIpv4Builder(); builder.setGlobalAdministrator(Ipv4Util.addressForByteBuf(buffer)); builder.setLocalAdministrator(buffer.readUnsignedShort()); return new RedirectIpv4ExtendedCommunityCaseBuilder().setRedirectIpv4(builder.build()).build(); }
From source file:org.opendaylight.protocol.bgp.flowspec.extended.communities.RedirectIpv6EcHandler.java
License:Open Source License
@Override public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) throws BGPDocumentedException, BGPParsingException { return new RedirectIpv6ExtendedCommunityCaseBuilder().setRedirectIpv6( new RedirectIpv6Builder().setGlobalAdministrator(Ipv6Util.addressForByteBuf(buffer)) .setLocalAdministrator(buffer.readUnsignedShort()).build()) .build();/*from w w w .j av a2 s .co m*/ }
From source file:org.opendaylight.protocol.bgp.flowspec.extended.communities.TrafficRateEcHandler.java
License:Open Source License
@Override public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) throws BGPDocumentedException, BGPParsingException { final ShortAsNumber as = new ShortAsNumber((long) buffer.readUnsignedShort()); final Bandwidth value = new Bandwidth(ByteArray.readBytes(buffer, TRAFFIC_RATE_SIZE)); return new TrafficRateExtendedCommunityCaseBuilder().setTrafficRateExtendedCommunity( new TrafficRateExtendedCommunityBuilder().setInformativeAs(as).setLocalAdministrator(value).build()) .build();/*from w w w . j a va 2 s . com*/ }
From source file:org.opendaylight.protocol.bgp.linkstate.attribute.LinkstateAttributeParser.java
License:Open Source License
private static Multimap<Integer, ByteBuf> getAttributesMap(final ByteBuf buffer) { /*/* ww w .jav a 2s.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.NodeAttributesParser.java
License:Open Source License
private static void parseTopologyId(final List<TopologyIdentifier> topologyMembership, final ByteBuf value) { while (value.isReadable()) { final TopologyIdentifier topId = new TopologyIdentifier( value.readUnsignedShort() & TlvUtil.TOPOLOGY_ID_OFFSET); topologyMembership.add(topId);/*from www. j a v a 2 s. c o m*/ LOG.debug("Parsed Topology Identifier: {}", topId); } }