List of usage examples for io.netty.buffer ByteBuf writeMedium
public abstract ByteBuf writeMedium(int value);
From source file:org.eclipse.scada.protocol.iec60870.asdu.types.InformationObjectAddress.java
License:Open Source License
@Override public String toString() { final ByteBuf buf = Unpooled.buffer(4); buf.writeMedium(this.address); return String.format("[%d-%d-%d # %d]", buf.getUnsignedByte(0), buf.getUnsignedByte(1), buf.getUnsignedByte(2), this.address); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmPbbIsidSerializer.java
License:Open Source License
@Override public void serialize(MatchEntry entry, ByteBuf outBuffer) { super.serialize(entry, outBuffer); PbbIsidCase entryValue = (PbbIsidCase) entry.getMatchEntryValue(); outBuffer.writeMedium(entryValue.getPbbIsid().getIsid().intValue()); if (entry.isHasMask()) { writeMask(entryValue.getPbbIsid().getMask(), outBuffer, getValueLength()); }// w w w . j a va 2 s . c o m }
From source file:org.opendaylight.openflowjava.protocol.impl.util.MatchSerializer.java
License:Open Source License
private static void encodeRest(MatchEntries entry, ByteBuf out) { int fieldValue = 0; Class<? extends MatchField> field = entry.getOxmMatchField(); if (field.isAssignableFrom(InPort.class)) { fieldValue = 0;/*ww w . ja v a 2 s .c om*/ writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_INT_IN_BYTES); out.writeInt(entry.getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue().intValue()); } else if (field.isAssignableFrom(InPhyPort.class)) { fieldValue = 1; writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_INT_IN_BYTES); out.writeInt(entry.getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue().intValue()); } else if (field.isAssignableFrom(Metadata.class)) { fieldValue = 2; writeMetadataRelatedEntry(entry, out, fieldValue); } else if (field.isAssignableFrom(EthDst.class)) { fieldValue = 3; writeMacAddressRelatedEntry(entry, out, fieldValue); } else if (field.isAssignableFrom(EthSrc.class)) { fieldValue = 4; writeMacAddressRelatedEntry(entry, out, fieldValue); } else if (field.isAssignableFrom(EthType.class)) { fieldValue = 5; writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); out.writeShort(entry.getAugmentation(EthTypeMatchEntry.class).getEthType().getValue().shortValue()); } else if (field.isAssignableFrom(VlanVid.class)) { fieldValue = 6; VlanVidMatchEntry vlanVid = entry.getAugmentation(VlanVidMatchEntry.class); int vlanVidValue = vlanVid.getVlanVid(); if (vlanVid.isCfiBit()) { short cfi = 1 << 12; // 13-th bit vlanVidValue = vlanVidValue | cfi; } writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), EncodeConstants.SIZE_OF_SHORT_IN_BYTES); out.writeShort(vlanVidValue); writeMask(entry, out, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); } else if (field.isAssignableFrom(VlanPcp.class)) { fieldValue = 7; writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); out.writeByte(entry.getAugmentation(VlanPcpMatchEntry.class).getVlanPcp().byteValue()); } else if (field.isAssignableFrom(IpDscp.class)) { fieldValue = 8; writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); out.writeByte(entry.getAugmentation(DscpMatchEntry.class).getDscp().getValue()); } else if (field.isAssignableFrom(IpEcn.class)) { fieldValue = 9; writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); out.writeByte(entry.getAugmentation(EcnMatchEntry.class).getEcn()); } else if (field.isAssignableFrom(IpProto.class)) { fieldValue = 10; writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); out.writeByte(entry.getAugmentation(ProtocolNumberMatchEntry.class).getProtocolNumber()); } else if (field.isAssignableFrom(Ipv4Src.class)) { fieldValue = 11; writeIpv4AddressRelatedEntry(entry, out, fieldValue); } else if (field.isAssignableFrom(Ipv4Dst.class)) { fieldValue = 12; writeIpv4AddressRelatedEntry(entry, out, fieldValue); } else if (field.isAssignableFrom(TcpSrc.class)) { fieldValue = 13; writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue()); } else if (field.isAssignableFrom(TcpDst.class)) { fieldValue = 14; writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue()); } else if (field.isAssignableFrom(UdpSrc.class)) { fieldValue = 15; writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue()); } else if (field.isAssignableFrom(UdpDst.class)) { fieldValue = 16; writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue()); } else if (field.isAssignableFrom(SctpSrc.class)) { fieldValue = 17; writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue()); } else if (field.isAssignableFrom(SctpDst.class)) { fieldValue = 18; writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue()); } else if (field.isAssignableFrom(Icmpv4Type.class)) { fieldValue = 19; writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); out.writeByte(entry.getAugmentation(Icmpv4TypeMatchEntry.class).getIcmpv4Type()); } else if (field.isAssignableFrom(Icmpv4Code.class)) { fieldValue = 20; writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); out.writeByte(entry.getAugmentation(Icmpv4CodeMatchEntry.class).getIcmpv4Code()); } else if (field.isAssignableFrom(ArpOp.class)) { fieldValue = 21; writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); out.writeShort(entry.getAugmentation(OpCodeMatchEntry.class).getOpCode()); } else if (field.isAssignableFrom(ArpSpa.class)) { fieldValue = 22; writeIpv4AddressRelatedEntry(entry, out, fieldValue); } else if (field.isAssignableFrom(ArpTpa.class)) { fieldValue = 23; writeIpv4AddressRelatedEntry(entry, out, fieldValue); } else if (field.isAssignableFrom(ArpSha.class)) { fieldValue = 24; writeMacAddressRelatedEntry(entry, out, fieldValue); } else if (field.isAssignableFrom(ArpTha.class)) { fieldValue = 25; writeMacAddressRelatedEntry(entry, out, fieldValue); } else if (field.isAssignableFrom(Ipv6Src.class)) { fieldValue = 26; writeIpv6AddressRelatedEntry(entry, out, fieldValue); } else if (field.isAssignableFrom(Ipv6Dst.class)) { fieldValue = 27; writeIpv6AddressRelatedEntry(entry, out, fieldValue); } else if (field.isAssignableFrom(Ipv6Flabel.class)) { fieldValue = 28; writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), EncodeConstants.SIZE_OF_INT_IN_BYTES); out.writeInt(entry.getAugmentation(Ipv6FlabelMatchEntry.class).getIpv6Flabel().getValue().intValue()); writeMask(entry, out, EncodeConstants.SIZE_OF_INT_IN_BYTES); } else if (field.isAssignableFrom(Icmpv6Type.class)) { fieldValue = 29; writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); out.writeByte(entry.getAugmentation(Icmpv6TypeMatchEntry.class).getIcmpv6Type()); } else if (field.isAssignableFrom(Icmpv6Code.class)) { fieldValue = 30; writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); out.writeByte(entry.getAugmentation(Icmpv6CodeMatchEntry.class).getIcmpv6Code()); } else if (field.isAssignableFrom(Ipv6NdTarget.class)) { fieldValue = 31; writeIpv6AddressRelatedEntry(entry, out, fieldValue); } else if (field.isAssignableFrom(Ipv6NdSll.class)) { fieldValue = 32; writeMacAddressRelatedEntry(entry, out, fieldValue); } else if (field.isAssignableFrom(Ipv6NdTll.class)) { fieldValue = 33; writeMacAddressRelatedEntry(entry, out, fieldValue); } else if (field.isAssignableFrom(MplsLabel.class)) { fieldValue = 34; writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_INT_IN_BYTES); out.writeInt(entry.getAugmentation(MplsLabelMatchEntry.class).getMplsLabel().intValue()); } else if (field.isAssignableFrom(MplsTc.class)) { fieldValue = 35; writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); out.writeByte(entry.getAugmentation(TcMatchEntry.class).getTc()); } else if (field.isAssignableFrom(MplsBos.class)) { fieldValue = 36; writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES); out.writeBoolean(entry.getAugmentation(BosMatchEntry.class).isBos().booleanValue()); } else if (field.isAssignableFrom(PbbIsid.class)) { fieldValue = 37; writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), EncodeConstants.SIZE_OF_3_BYTES); out.writeMedium(entry.getAugmentation(IsidMatchEntry.class).getIsid().intValue()); writeMask(entry, out, EncodeConstants.SIZE_OF_3_BYTES); } else if (field.isAssignableFrom(TunnelId.class)) { fieldValue = 38; writeMetadataRelatedEntry(entry, out, fieldValue); } else if (field.isAssignableFrom(Ipv6Exthdr.class)) { fieldValue = 39; Ipv6ExthdrFlags pseudoField = entry.getAugmentation(PseudoFieldMatchEntry.class).getPseudoField(); Map<Integer, Boolean> map = new HashMap<>(); map.put(0, pseudoField.isNonext()); map.put(1, pseudoField.isEsp()); map.put(2, pseudoField.isAuth()); map.put(3, pseudoField.isDest()); map.put(4, pseudoField.isFrag()); map.put(5, pseudoField.isRouter()); map.put(6, pseudoField.isHop()); map.put(7, pseudoField.isUnrep()); map.put(8, pseudoField.isUnseq()); int bitmap = ByteBufUtils.fillBitMaskFromMap(map); writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), EncodeConstants.SIZE_OF_SHORT_IN_BYTES); out.writeShort(bitmap); writeMask(entry, out, EncodeConstants.SIZE_OF_SHORT_IN_BYTES); } }
From source file:org.opendaylight.protocol.bgp.labeled.unicast.OriginatorSrgbTlvParser.java
License:Open Source License
@Override public void serializeBgpPrefixSidTlv(final BgpPrefixSidTlv tlv, final ByteBuf valueBuf) { Preconditions.checkArgument(tlv instanceof LuOriginatorSrgbTlv, "Incoming TLV is not LuOriginatorSrgbTlv"); final LuOriginatorSrgbTlv luTlv = (LuOriginatorSrgbTlv) tlv; valueBuf.writeZero(ORIGINATOR_FLAGS_BYTES); for (final SrgbValue val : luTlv.getSrgbValue()) { valueBuf.writeMedium(val.getBase().getValue().intValue()); valueBuf.writeMedium(val.getRange().getValue().intValue()); }/*from ww w . j av a 2 s . com*/ }
From source file:org.opendaylight.protocol.bgp.linkstate.attribute.sr.SrNodeAttributesParser.java
License:Open Source License
public static void serializeSrCapabilities(final SrCapabilities caps, final ByteBuf buffer) { final BitArray bs = new BitArray(FLAGS_SIZE); bs.set(MPLS_IPV4, caps.isMplsIpv4()); bs.set(MPLS_IPV6, caps.isMplsIpv6()); bs.set(SR_IPV6, caps.isSrIpv6());//from w ww. j a v a2s. c o m bs.toByteBuf(buffer); buffer.writeZero(RESERVERED); buffer.writeMedium(caps.getRangeSize().intValue()); TlvUtil.writeTLV(SidLabelIndexParser.SID_TYPE, SidLabelIndexParser.serializeSidValue(caps.getSidLabelIndex()), buffer); }
From source file:org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.SrNodeAttributesParser.java
License:Open Source License
public static void serializeSrCapabilities(final SrCapabilities caps, final ByteBuf buffer) { final BitArray bs = new BitArray(FLAGS_SIZE); bs.set(MPLS_IPV4, caps.isMplsIpv4()); bs.set(MPLS_IPV6, caps.isMplsIpv6()); bs.set(SR_IPV6, caps.isSrIpv6());//w w w .j a va 2s .c o m bs.toByteBuf(buffer); buffer.writeZero(RESERVERED); buffer.writeMedium(caps.getRangeSize().intValue()); TlvUtil.writeTLV(SID_TYPE, SidLabelIndexParser.serializeSidValue(caps.getSidLabelIndex()), buffer); }
From source file:org.opendaylight.protocol.util.ByteBufWriteUtil.java
License:Open Source License
/** * Writes 24-bit integer <code>value</code> if not null, otherwise writes * zeros to the <code>output</code> ByteBuf. ByteBuf's writerIndex is * increased by 3./*w w w . jav a2 s. co m*/ * * @param value * Medium value to be written to the output. * @param output * ByteBuf, where value or zeros are written. */ public static void writeMedium(final Integer value, final ByteBuf output) { if (value != null) { output.writeMedium(value); } else { output.writeZero(MEDIUM_BYTES_LENGTH); } }
From source file:org.traccar.protocol.At2000FrameDecoder.java
License:Apache License
private void sendResponse(Channel channel) { if (channel != null) { ByteBuf response = Unpooled.buffer(2 * BLOCK_LENGTH); response.writeByte(At2000ProtocolDecoder.MSG_ACKNOWLEDGEMENT); response.writeMedium(1); response.writeByte(0x00); // success response.writerIndex(2 * BLOCK_LENGTH); channel.writeAndFlush(new NetworkMessage(response, channel.remoteAddress())); }//from w w w . j ava2s .c o m }
From source file:org.traccar.protocol.At2000ProtocolDecoder.java
License:Apache License
private static void sendRequest(Channel channel) { if (channel != null) { ByteBuf response = Unpooled.buffer(BLOCK_LENGTH); response.writeByte(MSG_TRACK_REQUEST); response.writeMedium(0); response.writerIndex(BLOCK_LENGTH); channel.writeAndFlush(new NetworkMessage(response, channel.remoteAddress())); }/* w w w .j a va 2 s . co m*/ }
From source file:org.traccar.protocol.CalAmpProtocolDecoder.java
License:Apache License
private void sendResponse(Channel channel, SocketAddress remoteAddress, int type, int index, int result) { if (channel != null) { ByteBuf response = Unpooled.buffer(10); response.writeByte(SERVICE_RESPONSE); response.writeByte(MSG_ACK);/*from w w w.j av a 2 s .c om*/ response.writeShort(index); response.writeByte(type); response.writeByte(result); response.writeByte(0); response.writeMedium(0); channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); } }