List of usage examples for io.netty.buffer ByteBuf readSlice
public abstract ByteBuf readSlice(int length);
From source file:org.opendaylight.protocol.bgp.linkstate.impl.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.linkstate.attribute.UnreservedBandwidth> unreservedBandwidth = new ArrayList<>( UNRESERVED_BW_COUNT);/* www . ja v a 2s . c om*/ 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.impl.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(); final RangeSubTlv subTlvCase; final int type = buffer.readUnsignedShort(); final int length = buffer.readUnsignedShort(); switch (type) { case PREFIX_SID: subTlvCase = new PrefixSidTlvCaseBuilder( SrPrefixAttributesParser.parseSrPrefix(buffer.readSlice(length), protocolId)).build(); break; case IPV6_PREFIX_SID: subTlvCase = new Ipv6PrefixSidTlvCaseBuilder( Ipv6SrPrefixAttributesParser.parseSrIpv6Prefix(buffer.readSlice(length))).build(); break; case BINDING_SID: subTlvCase = new BindingSidTlvCaseBuilder( BindingSidLabelParser.parseBindingSidLabel(buffer.readSlice(length), protocolId)).build(); break; case SID_TYPE: subTlvCase = new SidLabelTlvCaseBuilder().setSidLabelIndex( SidLabelIndexParser.parseSidLabelIndex(Size.forValue(length), buffer.readSlice(length))) .build();/*from w w w . j av a 2 s . c o m*/ 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.impl.attribute.TeLspAttributesParser.java
License:Open Source License
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 {//from www. 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(); }
From source file:org.opendaylight.protocol.bgp.linkstate.nlri.LinkNlriParser.java
License:Open Source License
static LinkDescriptors parseLinkDescriptors(final ByteBuf buffer) throws BGPParsingException { final LinkDescriptorsBuilder builder = new LinkDescriptorsBuilder(); while (buffer.isReadable()) { final int type = buffer.readUnsignedShort(); final int length = buffer.readUnsignedShort(); final ByteBuf value = buffer.readSlice(length); LOG.trace("Parsing Link Descriptor: {}", ByteBufUtil.hexDump(value)); switch (type) { case LINK_LR_IDENTIFIERS: builder.setLinkLocalIdentifier(value.readUnsignedInt()); builder.setLinkRemoteIdentifier(value.readUnsignedInt()); LOG.debug("Parsed link local {} remote {} Identifiers.", builder.getLinkLocalIdentifier(), builder.getLinkRemoteIdentifier()); break; case IPV4_IFACE_ADDRESS: final Ipv4InterfaceIdentifier lipv4 = new Ipv4InterfaceIdentifier( Ipv4Util.addressForByteBuf(value)); builder.setIpv4InterfaceAddress(lipv4); LOG.debug("Parsed IPv4 interface address {}.", lipv4); break; case IPV4_NEIGHBOR_ADDRESS: final Ipv4InterfaceIdentifier ripv4 = new Ipv4InterfaceIdentifier( Ipv4Util.addressForByteBuf(value)); builder.setIpv4NeighborAddress(ripv4); LOG.debug("Parsed IPv4 neighbor address {}.", ripv4); break; case IPV6_IFACE_ADDRESS: final Ipv6InterfaceIdentifier lipv6 = new Ipv6InterfaceIdentifier( Ipv6Util.addressForByteBuf(value)); builder.setIpv6InterfaceAddress(lipv6); LOG.debug("Parsed IPv6 interface address {}.", lipv6); break; case IPV6_NEIGHBOR_ADDRESS: final Ipv6InterfaceIdentifier ripv6 = new Ipv6InterfaceIdentifier( Ipv6Util.addressForByteBuf(value)); builder.setIpv6NeighborAddress(ripv6); LOG.debug("Parsed IPv6 neighbor address {}.", ripv6); break; case TlvUtil.MULTI_TOPOLOGY_ID: final TopologyIdentifier topId = new TopologyIdentifier( value.readUnsignedShort() & TlvUtil.TOPOLOGY_ID_OFFSET); builder.setMultiTopologyId(topId); LOG.debug("Parsed topology identifier {}.", topId); break; default://from w w w. j a v a2 s . c o m throw new BGPParsingException("Link Descriptor not recognized, type: " + type); } } LOG.trace("Finished parsing Link descriptors."); return builder.build(); }
From source file:org.opendaylight.protocol.bgp.linkstate.nlri.LinkstateNlriParser.java
License:Open Source License
private static org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NodeIdentifier parseLink( final CLinkstateDestinationBuilder builder, final ByteBuf buffer, final LocalNodeDescriptors localDescriptors) throws BGPParsingException { final int type = buffer.readUnsignedShort(); final int length = buffer.readUnsignedShort(); final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NodeIdentifier remote = null; RemoteNodeDescriptors remoteDescriptors = null; if (type == REMOTE_NODE_DESCRIPTORS_TYPE) { remoteDescriptors = (RemoteNodeDescriptors) NodeNlriParser .parseNodeDescriptors(buffer.readSlice(length), NlriType.Link, false); }// w w w . j a v a 2s .c o m builder.setObjectType(new LinkCaseBuilder().setLocalNodeDescriptors(localDescriptors) .setRemoteNodeDescriptors(remoteDescriptors) .setLinkDescriptors(LinkNlriParser.parseLinkDescriptors(buffer.slice())).build()); return remote; }
From source file:org.opendaylight.protocol.bgp.linkstate.nlri.LinkstateNlriParser.java
License:Open Source License
/** * Parses common parts for Link State Nodes, Links and Prefixes, that includes protocol ID and identifier tlv. * * @param nlri as byte array//from w w w .j a v a2 s. c om * @param isVpn flag which determines that destination has route distinguisher * @return {@link CLinkstateDestination} * @throws BGPParsingException if parsing was unsuccessful */ public static List<CLinkstateDestination> parseNlri(final ByteBuf nlri, final boolean isVpn) throws BGPParsingException { final List<CLinkstateDestination> dests = new ArrayList<>(); while (nlri.isReadable()) { final CLinkstateDestinationBuilder builder = new CLinkstateDestinationBuilder(); final NlriType type = NlriType.forValue(nlri.readUnsignedShort()); // length means total length of the tlvs including route distinguisher not including the type field final int length = nlri.readUnsignedShort(); RouteDistinguisher distinguisher = null; if (isVpn) { // this parses route distinguisher distinguisher = new RouteDistinguisher(BigInteger.valueOf(nlri.readLong())); builder.setDistinguisher(distinguisher); } // parse source protocol final ProtocolId sp = ProtocolId.forValue(nlri.readByte()); builder.setProtocolId(sp); // parse identifier final Identifier identifier = new Identifier(BigInteger.valueOf(nlri.readLong())); builder.setIdentifier(identifier); // if we are dealing with linkstate nodes/links, parse local node descriptor org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NodeIdentifier localDescriptor = null; ByteBuf rest = null; if (!type.equals(NlriType.Ipv4TeLsp) && !type.equals(NlriType.Ipv6TeLsp)) { final int localtype = nlri.readUnsignedShort(); final int locallength = nlri.readUnsignedShort(); if (localtype == LOCAL_NODE_DESCRIPTORS_TYPE) { localDescriptor = NodeNlriParser.parseNodeDescriptors(nlri.readSlice(locallength), type, true); } final int restLength = length - (isVpn ? ROUTE_DISTINGUISHER_LENGTH : 0) - PROTOCOL_ID_LENGTH - IDENTIFIER_LENGTH - TYPE_LENGTH - LENGTH_SIZE - locallength; LOG.trace("Restlength {}", restLength); rest = nlri.readSlice(restLength); } setObjectType(nlri, builder, type, localDescriptor, rest); dests.add(builder.build()); } return dests; }
From source file:org.opendaylight.protocol.bgp.linkstate.nlri.NodeNlriParser.java
License:Open Source License
static org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NodeIdentifier parseNodeDescriptors( final ByteBuf buffer, final NlriType nlriType, final boolean local) throws BGPParsingException { AsNumber asnumber = null;//from w w w. j av a 2 s.co m DomainIdentifier bgpId = null; AreaIdentifier ai = null; CRouterIdentifier routerId = null; AsNumber memberAsn = null; Ipv4Address bgpRouterId = null; while (buffer.isReadable()) { final int type = buffer.readUnsignedShort(); final int length = buffer.readUnsignedShort(); final ByteBuf value = buffer.readSlice(length); if (LOG.isTraceEnabled()) { LOG.trace("Parsing Node Descriptor: {}", ByteBufUtil.hexDump(value)); } switch (type) { case AS_NUMBER: asnumber = new AsNumber(value.readUnsignedInt()); LOG.debug("Parsed {}", asnumber); break; case BGP_LS_ID: bgpId = new DomainIdentifier(value.readUnsignedInt()); LOG.debug("Parsed {}", bgpId); break; case AREA_ID: ai = new AreaIdentifier(value.readUnsignedInt()); LOG.debug("Parsed area identifier {}", ai); break; case IGP_ROUTER_ID: routerId = parseRouterId(value); LOG.debug("Parsed Router Identifier {}", routerId); break; case BGP_ROUTER_ID: bgpRouterId = Ipv4Util.addressForByteBuf(value); LOG.debug("Parsed BGP Router Identifier {}", bgpRouterId); break; case MEMBER_AS_NUMBER: memberAsn = new AsNumber(value.readUnsignedInt()); LOG.debug("Parsed Member AsNumber {}", memberAsn); break; default: throw new BGPParsingException("Node Descriptor not recognized, type: " + type); } } LOG.trace("Finished parsing Node descriptors."); return correctType(nlriType, local, asnumber, ai, routerId, bgpId, bgpRouterId, memberAsn); }
From source file:org.opendaylight.protocol.bgp.linkstate.nlri.PrefixNlriParser.java
License:Open Source License
static PrefixDescriptors parsePrefixDescriptors(final ByteBuf buffer, final boolean ipv4) throws BGPParsingException { final PrefixDescriptorsBuilder builder = new PrefixDescriptorsBuilder(); while (buffer.isReadable()) { final int type = buffer.readUnsignedShort(); final int length = buffer.readUnsignedShort(); final ByteBuf value = buffer.readSlice(length); if (LOG.isTraceEnabled()) { LOG.trace("Parsing Prefix Descriptor: {}", ByteBufUtil.hexDump(value)); }/*from www . j av a 2 s . com*/ switch (type) { case TlvUtil.MULTI_TOPOLOGY_ID: final TopologyIdentifier topologyId = new TopologyIdentifier( value.readShort() & TlvUtil.TOPOLOGY_ID_OFFSET); builder.setMultiTopologyId(topologyId); LOG.trace("Parsed Topology Identifier: {}", topologyId); break; case OSPF_ROUTE_TYPE: final int rt = value.readByte(); final OspfRouteType routeType = OspfRouteType.forValue(rt); if (routeType == null) { throw new BGPParsingException("Unknown OSPF Route Type: " + rt); } builder.setOspfRouteType(routeType); LOG.trace("Parser RouteType: {}", routeType); break; case IP_REACHABILITY: final IpPrefix prefix = (ipv4) ? new IpPrefix(Ipv4Util.prefixForByteBuf(value)) : new IpPrefix(Ipv6Util.prefixForByteBuf(value)); builder.setIpReachabilityInformation(prefix); LOG.trace("Parsed IP reachability info: {}", prefix); break; default: throw new BGPParsingException("Prefix Descriptor not recognized, type: " + type); } } LOG.debug("Finished parsing Prefix descriptors."); return builder.build(); }
From source file:org.opendaylight.protocol.bgp.linkstate.spi.pojo.SimpleBindingSubTlvsRegistry.java
License:Open Source License
public List<BindingSubTlvs> parseBindingSubTlvs(final ByteBuf buffer, final ProtocolId protocolId) { final List<BindingSubTlvs> subTlvs = new ArrayList<>(); if (buffer != null) { while (buffer.isReadable()) { final int type = buffer.readUnsignedShort(); final int length = buffer.readUnsignedShort(); final ByteBuf slice = buffer.readSlice(length); final BindingSubTlvsParser parser = this.handlers.getParser(type); if (parser == null) { return null; }/*from ww w .ja va 2 s .co m*/ subTlvs.add(new BindingSubTlvsBuilder().setBindingSubTlv(parser.parseSubTlv(slice, protocolId)) .build()); } } return subTlvs; }
From source file:org.opendaylight.protocol.bgp.linkstate.spi.pojo.SimpleNlriTypeRegistry.java
License:Open Source License
public CLinkstateDestination parseNlriType(final ByteBuf buffer) { final int type = buffer.readUnsignedShort(); final int length = buffer.readUnsignedShort(); final NlriTypeCaseParser parser = this.nlriRegistry.getParser(type); if (parser == null) { LOG.warn("Linkstate NLRI parser for Type: {} was not found.", type); return null; }//from www. j av a 2 s. c o m return parser.parseTypeNlri(buffer.readSlice(length)); }