List of usage examples for io.netty.buffer ByteBuf writeShort
public abstract ByteBuf writeShort(int value);
From source file:org.bgp4j.netty.protocol.open.CapabilityCodec.java
License:Apache License
private static void encodeOutboundRouteFilteringCapability(ByteBuf buffer, OutboundRouteFilteringCapability cap) { buffer.writeByte(5 + 2 * cap.getFilters().size()); buffer.writeShort(cap.getAddressFamily().toCode()); buffer.writeByte(0);/*from w ww. ja va 2 s . co m*/ buffer.writeByte(cap.getSubsequentAddressFamily().toCode()); buffer.writeByte(cap.getFilters().size()); for (ORFType type : cap.getFilters().keySet()) { buffer.writeByte(type.toCode()); buffer.writeByte(cap.getFilters().get(type).toCode()); } }
From source file:org.bgp4j.netty.protocol.open.CapabilityCodec.java
License:Apache License
private static ByteBuf encodeMultiprotocolCapability(ByteBuf buffer, MultiProtocolCapability cap) { buffer.writeByte(4);/* w w w. j av a 2s . c o m*/ if (cap.getAfi() != null) buffer.writeShort(cap.getAfi().toCode()); else buffer.writeShort(AddressFamily.RESERVED.toCode()); buffer.writeByte(0); // reserved if (cap.getSafi() != null) buffer.writeByte(cap.getSafi().toCode()); else buffer.writeByte(0); return buffer; }
From source file:org.bgp4j.netty.protocol.open.OpenPacket.java
License:Apache License
@Override protected void encodePayload(ByteBuf buffer) { buffer.writeByte(getProtocolVersion()); buffer.writeShort(getAutonomousSystem()); buffer.writeShort(getHoldTime());// w w w.j a va 2 s . co m buffer.writeInt((int) getBgpIdentifier()); if (!capabilities.isEmpty()) { int capabilityLengthIndex = buffer.writerIndex(); buffer.writeByte(0); // placeholder for capability length buffer.writeByte(BGPv4Constants.BGP_OPEN_PARAMETER_TYPE_CAPABILITY); // type byte int parameterLengthIndex = buffer.writerIndex(); buffer.writeByte(0); // placeholder for parameter length CapabilityCodec.encodeCapabilities(buffer, getCapabilities()); buffer.setByte(capabilityLengthIndex, buffer.writerIndex() - capabilityLengthIndex - 1); buffer.setByte(parameterLengthIndex, buffer.writerIndex() - parameterLengthIndex - 1); } else { buffer.writeByte(0); // no capabilites encoded --> optional parameter length equals 0 } }
From source file:org.bgp4j.netty.protocol.open.UnsupportedVersionNumberNotificationPacket.java
License:Apache License
@Override protected void encodeAdditionalPayload(ByteBuf buffer) { buffer.writeShort(this.supportedProtocolVersion); }
From source file:org.bgp4j.netty.protocol.refresh.RouteRefreshPacket.java
License:Apache License
@Override protected void encodePayload(ByteBuf buffer) { buffer.writeShort(getAddressFamily().toCode()); buffer.writeByte(0);/*w w w . j av a 2 s .c o m*/ buffer.writeByte(getSubsequentAddressFamily().toCode()); if (outboundRouteFilter != null) { buffer.writeByte(outboundRouteFilter.getRefreshType().toCode()); for (ORFType type : outboundRouteFilter.getEntries().keySet()) { buffer.writeByte(type.toCode()); int entriesLengthIndex = buffer.writerIndex(); buffer.writeShort(0); // placeholder for entries length for (ORFEntry entry : outboundRouteFilter.getEntries().get(type)) { ORFEntryCodec.encodeORFEntry(buffer, entry); } buffer.setShort(entriesLengthIndex, buffer.writerIndex() - entriesLengthIndex - 2); } } }
From source file:org.bgp4j.netty.protocol.update.AggregatorPathAttributeCodecHandler.java
License:Apache License
@Override public void encodeValue(ByteBuf buffer, AggregatorPathAttribute attr) { if (attr.isFourByteASNumber()) buffer.writeInt(attr.getAsNumber()); else//from www . j a v a 2s.c om buffer.writeShort(attr.getAsNumber()); buffer.writeBytes(attr.getAggregator().getAddress()); }
From source file:org.bgp4j.netty.protocol.update.CommunityPathAttributeCodecHandler.java
License:Apache License
@Override public void encodeValue(ByteBuf buffer, CommunityPathAttribute attr) { buffer.writeInt(attr.getCommunity()); if (attr.getMembers() != null) { for (CommunityMember member : attr.getMembers()) { buffer.writeShort(member.getAsNumber()); buffer.writeShort(member.getMemberFlags()); }// ww w . j a v a 2s .c om } }
From source file:org.bgp4j.netty.protocol.update.MultiProtocolReachableNLRICodecHandler.java
License:Apache License
@Override public void encodeValue(ByteBuf buffer, MultiProtocolReachableNLRI attr) { buffer.writeShort(attr.getAddressFamily().toCode()); buffer.writeByte(attr.getSubsequentAddressFamily().toCode()); if (attr.getNextHop() != null) { buffer.writeByte(attr.getNextHop().getAddress().length); buffer.writeBytes(attr.getNextHop().getAddress()); } else {//from w ww . j a v a 2s .c om buffer.writeByte(0); } buffer.writeByte(0); // write reserved field if (attr.getNlris() != null) { for (NetworkLayerReachabilityInformation nlri : attr.getNlris()) NLRICodec.encodeNLRI(buffer, nlri); } }
From source file:org.bgp4j.netty.protocol.update.MultiProtocolUnreachableNLRICodecHandler.java
License:Apache License
@Override public void encodeValue(ByteBuf buffer, MultiProtocolUnreachableNLRI attr) { buffer.writeShort(attr.getAddressFamily().toCode()); buffer.writeByte(attr.getSubsequentAddressFamily().toCode()); if (attr.getNlris() != null) { for (NetworkLayerReachabilityInformation nlri : attr.getNlris()) NLRICodec.encodeNLRI(buffer, nlri); }// w ww . j a va 2 s.com }
From source file:org.bgp4j.netty.protocol.update.PathAttributeCodec.java
License:Apache License
/** * encode the path attribute for network transmission * // w w w . j a v a 2 s. c o m * @return an encoded formatted path attribute */ public static void encodePathAttribute(ByteBuf buffer, PathAttribute attr) { ByteBuf valueBuffer = allocator.buffer().order(ByteOrder.BIG_ENDIAN); encodeValue(valueBuffer, attr); int valueLength = valueBuffer.readableBytes(); int attrFlagsCode = 0; if (attr.isOptional()) attrFlagsCode |= BGPv4Constants.BGP_PATH_ATTRIBUTE_OPTIONAL_BIT; if (attr.isTransitive()) attrFlagsCode |= BGPv4Constants.BGP_PATH_ATTRIBUTE_TRANSITIVE_BIT; if (attr.isPartial()) attrFlagsCode |= BGPv4Constants.BGP_PATH_ATTRIBUTE_PARTIAL_BIT; if (valueLength > 255) attrFlagsCode |= BGPv4Constants.BGP_PATH_ATTRIBUTE_EXTENDED_LENGTH_BIT; attrFlagsCode |= (typeCode(attr) & BGPv4Constants.BGP_PATH_ATTRIBUTE_TYPE_MASK); buffer.writeShort(attrFlagsCode); if (valueLength > 255) buffer.writeShort(valueLength); else buffer.writeByte(valueLength); if (valueLength > 0) buffer.writeBytes(valueBuffer); }