List of usage examples for io.netty.buffer ByteBuf readUnsignedInt
public abstract long readUnsignedInt();
From source file:org.opendaylight.protocol.bgp.linkstate.impl.tlvs.AsNumTlvParser.java
License:Open Source License
@Override public AsNumber parseTlvBody(final ByteBuf value) { return new AsNumber(value.readUnsignedInt()); }
From source file:org.opendaylight.protocol.bgp.linkstate.impl.tlvs.DomainIdTlvParser.java
License:Open Source License
@Override public DomainIdentifier parseTlvBody(final ByteBuf value) { return new DomainIdentifier(value.readUnsignedInt()); }
From source file:org.opendaylight.protocol.bgp.linkstate.impl.tlvs.LinkIdTlvParser.java
License:Open Source License
@Override public LinkLrIdentifiers parseTlvBody(final ByteBuf value) { final long localId = value.readUnsignedInt(); final long remoteId = value.readUnsignedInt(); return new LinkLrIdentifiers() { @Override/*from w ww. jav a2 s . c o m*/ public Class<? extends DataContainer> getImplementedInterface() { return LinkLrIdentifiers.class; } @Override public Long getLinkRemoteIdentifier() { return remoteId; } @Override public Long getLinkLocalIdentifier() { return localId; } }; }
From source file:org.opendaylight.protocol.bgp.linkstate.impl.tlvs.RouterIdTlvParser.java
License:Open Source License
@Override public CRouterIdentifier parseTlvBody(final ByteBuf value) { if (value.readableBytes() == ISO_SYSTEM_ID_LENGTH || (value.readableBytes() == ISO_SYSTEM_ID_LENGTH + PSN_LENGTH && value.getByte(ISO_SYSTEM_ID_LENGTH) == 0)) { return new IsisNodeCaseBuilder().setIsisNode(new IsisNodeBuilder() .setIsoSystemId(new IsoSystemIdentifier(ByteArray.readBytes(value, ISO_SYSTEM_ID_LENGTH))) .build()).build();/*from w w w .j a v a2 s . c o m*/ } if (value.readableBytes() == ISO_SYSTEM_ID_LENGTH + PSN_LENGTH) { final IsIsRouterIdentifier iri = new IsIsRouterIdentifierBuilder() .setIsoSystemId(new IsoSystemIdentifier(ByteArray.readBytes(value, ISO_SYSTEM_ID_LENGTH))) .build(); return new IsisPseudonodeCaseBuilder().setIsisPseudonode(new IsisPseudonodeBuilder() .setIsIsRouterIdentifier(iri).setPsn((short) value.readByte()).build()).build(); } if (value.readableBytes() == OSPF_ROUTER_ID_LENGTH) { return new OspfNodeCaseBuilder() .setOspfNode(new OspfNodeBuilder().setOspfRouterId(value.readUnsignedInt()).build()).build(); } if (value.readableBytes() == OSPF_PSEUDONODE_ROUTER_ID_LENGTH) { return new OspfPseudonodeCaseBuilder() .setOspfPseudonode(new OspfPseudonodeBuilder().setOspfRouterId(value.readUnsignedInt()) .setLanInterface(new OspfInterfaceIdentifier(value.readUnsignedInt())).build()) .build(); } return null; }
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 va 2s . co 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.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;// w w w. j a va 2 s. c om 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.NodeNlriParser.java
License:Open Source License
private static CRouterIdentifier parseRouterId(final ByteBuf value) throws BGPParsingException { if (value.readableBytes() == ISO_SYSTEM_ID_LENGTH || (value.readableBytes() == ISO_SYSTEM_ID_LENGTH + PSN_LENGTH && value.getByte(ISO_SYSTEM_ID_LENGTH) == 0)) { return new IsisNodeCaseBuilder().setIsisNode(new IsisNodeBuilder() .setIsoSystemId(new IsoSystemIdentifier(ByteArray.readBytes(value, ISO_SYSTEM_ID_LENGTH))) .build()).build();/*from ww w . j a v a 2s . c o m*/ } if (value.readableBytes() == ISO_SYSTEM_ID_LENGTH + PSN_LENGTH) { final IsIsRouterIdentifier iri = new IsIsRouterIdentifierBuilder() .setIsoSystemId(new IsoSystemIdentifier(ByteArray.readBytes(value, ISO_SYSTEM_ID_LENGTH))) .build(); return new IsisPseudonodeCaseBuilder().setIsisPseudonode(new IsisPseudonodeBuilder() .setIsIsRouterIdentifier(iri).setPsn((short) value.readByte()).build()).build(); } if (value.readableBytes() == OSPF_ROUTER_ID_LENGTH) { return new OspfNodeCaseBuilder() .setOspfNode(new OspfNodeBuilder().setOspfRouterId(value.readUnsignedInt()).build()).build(); } if (value.readableBytes() == OSPF_PSEUDONODE_ROUTER_ID_LENGTH) { return new OspfPseudonodeCaseBuilder() .setOspfPseudonode(new OspfPseudonodeBuilder().setOspfRouterId(value.readUnsignedInt()) .setLanInterface(new OspfInterfaceIdentifier(value.readUnsignedInt())).build()) .build(); } throw new BGPParsingException("Router Id of invalid length " + value.readableBytes()); }
From source file:org.opendaylight.protocol.bgp.parser.impl.message.open.As4CapabilityHandler.java
License:Open Source License
@Override public CParameters parseCapability(final ByteBuf buffer) throws BGPDocumentedException, BGPParsingException { return new CParametersBuilder() .setAs4BytesCapability(/*from ww w . jav a2 s . c o m*/ new As4BytesCapabilityBuilder().setAsNumber(new AsNumber(buffer.readUnsignedInt())).build()) .build(); }
From source file:org.opendaylight.protocol.bgp.parser.impl.message.update.AggregatorAttributeParser.java
License:Open Source License
/** * Parse {@link Aggregator} from bytes/*from w w w . j a v a2 s.c o m*/ * * @param buffer byte buffer to be parsed * @param builder AttributesBuilder into which parsed {@link Aggregator} will be set */ @Override public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder) { final AsNumber asNumber = this.refCache.getSharedReference(new AsNumber(buffer.readUnsignedInt())); final Ipv4Address address = Ipv4Util.addressForByteBuf(buffer); builder.setAggregator(new AggregatorBuilder().setAsNumber(asNumber).setNetworkAddress(address).build()); }
From source file:org.opendaylight.protocol.bgp.parser.impl.message.update.AsPathSegmentParser.java
License:Open Source License
static List<AsNumber> parseAsSegment(final ReferenceCache refCache, final int count, final ByteBuf buffer) { final List<AsNumber> coll = new ArrayList<>(count); for (int i = 0; i < count; i++) { coll.add(refCache.getSharedReference(new AsNumber(buffer.readUnsignedInt()))); }// w ww .j ava 2 s . c o m return (coll.isEmpty()) ? Collections.<AsNumber>emptyList() : coll; }