List of usage examples for io.netty.buffer ByteBuf readUnsignedShort
public abstract int readUnsignedShort();
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); }//from w ww. ja v a2 s .c om 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 a 2 s .co m * @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.LinkstateNlriParser.java
License:Open Source License
private static TeLspCase parseIpv6TeLsp(final ByteBuf nlri) { final Ipv6CaseBuilder ipv6Builder = new Ipv6CaseBuilder(); ipv6Builder.setIpv6TunnelSenderAddress(Ipv6Util.addressForByteBuf(nlri)); final TunnelId tunnelId6 = new TunnelId(nlri.readUnsignedShort()); final LspId lspId6 = new LspId((long) nlri.readUnsignedShort()); ipv6Builder.setIpv6TunnelEndpointAddress(Ipv6Util.addressForByteBuf(nlri)); return new TeLspCaseBuilder().setAddressFamily(ipv6Builder.build()).setLspId(lspId6).setTunnelId(tunnelId6) .build();//from w w w . j a v a 2 s . co m }
From source file:org.opendaylight.protocol.bgp.linkstate.nlri.LinkstateNlriParser.java
License:Open Source License
private static TeLspCase parseIpv4TeLsp(final ByteBuf nlri) { final Ipv4CaseBuilder ipv4Builder = new Ipv4CaseBuilder(); ipv4Builder.setIpv4TunnelSenderAddress(Ipv4Util.addressForByteBuf(nlri)); final TunnelId tunnelId = new TunnelId(nlri.readUnsignedShort()); final LspId lspId = new LspId((long) nlri.readUnsignedShort()); ipv4Builder.setIpv4TunnelEndpointAddress(Ipv4Util.addressForByteBuf(nlri)); return new TeLspCaseBuilder().setAddressFamily(ipv4Builder.build()).setLspId(lspId).setTunnelId(tunnelId) .build();/* w ww. j ava 2 s . co m*/ }
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 ww w. j a v a 2s. c o 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)); }// ww w.ja v a2 s . co m 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; }//w ww .jav a 2 s. c o 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 a v a 2 s . com*/ return parser.parseTypeNlri(buffer.readSlice(length)); }
From source file:org.opendaylight.protocol.bgp.linkstate.spi.pojo.SimpleNlriTypeRegistry.java
License:Open Source License
private <T> LinkstateTlvParser<T> getParser(final ByteBuf buffer) { Preconditions.checkArgument(buffer != null && buffer.isReadable()); final int type = buffer.readUnsignedShort(); final LinkstateTlvParser<T> parser = (LinkstateTlvParser<T>) this.tlvParsers.get(type); if (parser == null) { LOG.warn("Linkstate TLV parser for Type: {} was not found.", type); }/*from w w w . j ava2s .co m*/ return parser; }
From source file:org.opendaylight.protocol.bgp.linkstate.spi.pojo.SimpleNlriTypeRegistry.java
License:Open Source License
private static <T> T parseTlv(final ByteBuf buffer, final LinkstateTlvParser<T> parser) { if (parser == null) { return null; }//from www .j av a2 s. com Preconditions.checkArgument(buffer != null && buffer.isReadable()); final int length = buffer.readUnsignedShort(); return parser.parseTlvBody(buffer.readSlice(length)); }