Java Code Examples for org.jboss.netty.buffer.ChannelBuffer#writeShort()

The following examples show how to use org.jboss.netty.buffer.ChannelBuffer#writeShort() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PcepOpenMsgVer1.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void write(ChannelBuffer cb, PcepOpenMsgVer1 message) throws PcepParseException {
    int startIndex = cb.writerIndex();
    // first 3 bits set to version
    cb.writeByte((byte) (PACKET_VERSION << PcepMessageVer1.SHIFT_FLAG));
    // message type
    cb.writeByte(MSG_TYPE.getType());
    // length is length of variable message, will be updated at the end
    // Store the position of message
    // length in buffer

    int msgLenIndex = cb.writerIndex();
    cb.writeShort(0);

    message.getPcepOpenObject().write(cb);

    // update message length field
    int iLength = cb.writerIndex() - startIndex;
    cb.setShort(msgLenIndex, (short) iLength);
}
 
Example 2
Source File: MplsProtocolMaskSubTlv.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public int write(ChannelBuffer c) {
    int iLenStartIndex = c.writerIndex();
    c.writeShort(TYPE);
    c.writeShort(LENGTH);
    if (isRawValueSet) {
        c.writeByte(rawValue);
    } else {
        byte temp = 0;
        if (bLFlag) {
            temp = (byte) (temp | LFLAG_SET);
        }
        if (bRFlag) {
            temp = (byte) (temp | RFLAG_SET);
        }
        c.writeByte(temp);
    }
    return c.writerIndex() - iLenStartIndex;
}
 
Example 3
Source File: OFFlowRemoved.java    From floodlight_with_topoguard with Apache License 2.0 6 votes vote down vote up
@Override
public void writeTo(ChannelBuffer data) {
    super.writeTo(data);
    this.match.writeTo(data);
    data.writeLong(cookie);
    data.writeShort(priority);
    data.writeByte((byte) this.reason.ordinal());
    data.writeByte((byte) 0);
    data.writeInt(this.durationSeconds);
    data.writeInt(this.durationNanoseconds);
    data.writeShort(idleTimeout);
    data.writeByte((byte) 0); // pad
    data.writeByte((byte) 0); // pad
    data.writeLong(this.packetCount);
    data.writeLong(this.byteCount);
}
 
Example 4
Source File: OspfNonPseudonode.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public int write(ChannelBuffer c) {
    int iLenStartIndex = c.writerIndex();
    c.writeShort(TYPE);
    c.writeShort(LENGTH);
    c.writeInt(routerID);
    return c.writerIndex() - iLenStartIndex;
}
 
Example 5
Source File: OpaqueLinkAttributeSubTlv.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public int write(ChannelBuffer c) {
    int iLenStartIndex = c.writerIndex();
    c.writeShort(TYPE);
    c.writeShort(hLength);
    c.writeBytes(rawValue);
    return c.writerIndex() - iLenStartIndex;
}
 
Example 6
Source File: IPv6InterfaceAddressSubTlv.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public int write(ChannelBuffer c) {
    int iLenStartIndex = c.writerIndex();
    c.writeShort(TYPE);
    c.writeShort(LENGTH);
    c.writeBytes(rawValue);
    return c.writerIndex() - iLenStartIndex;
}
 
Example 7
Source File: OFActionNetworkTypeOfService.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
@Override
public void writeTo(ChannelBuffer data) {
    super.writeTo(data);
    data.writeByte(this.networkTypeOfService);
    data.writeShort((short) 0);
    data.writeByte((byte) 0);
}
 
Example 8
Source File: RouteTarget.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public int write(ChannelBuffer cb) {
    int iLenStartIndex = cb.writerIndex();
    cb.writeShort(type);
    cb.writeBytes(routeTarget);
    return cb.writerIndex() - iLenStartIndex;
}
 
Example 9
Source File: NexthopUnnumberedIPv4IDTlv.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public int write(ChannelBuffer c) {
    int iLenStartIndex = c.writerIndex();
    c.writeShort(TYPE);
    c.writeShort(LENGTH);

    c.writeInt(nodeID);
    c.writeInt(interfaceID);

    return c.writerIndex() - iLenStartIndex;
}
 
Example 10
Source File: NodeAttributesTlv.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public int write(ChannelBuffer c) {
    int tlvStartIndex = c.writerIndex();
    c.writeShort(TYPE);
    int tlvLenIndex = c.writerIndex();
    hLength = 0;
    c.writeShort(hLength);

    ListIterator<PcepValueType> listIterator = llNodeAttributesSubTLVs.listIterator();

    while (listIterator.hasNext()) {
        PcepValueType tlv = listIterator.next();

        tlv.write(c);

        // need to take care of padding
        int pad = tlv.getLength() % 4;

        if (0 != pad) {
            pad = 4 - pad;
            for (int i = 0; i < pad; ++i) {
                c.writeByte((byte) 0);
            }
        }
    }

    hLength = (short) (c.writerIndex() - tlvStartIndex);
    c.setShort(tlvLenIndex, (hLength - TLV_HEADER_LENGTH));

    return c.writerIndex() - tlvStartIndex;
}
 
Example 11
Source File: ControlHandshakePacket.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public ChannelBuffer toBuffer() {

    ChannelBuffer header = ChannelBuffers.buffer(2 + 4 + 4);
    header.writeShort(PacketType.CONTROL_HANDSHAKE);
    header.writeInt(getRequestId());

    return PayloadPacket.appendPayload(header, payload);
}
 
Example 12
Source File: StreamCreatePacket.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public ChannelBuffer toBuffer() {
    ChannelBuffer header = ChannelBuffers.buffer(2 + 4 + 4);
    header.writeShort(getPacketType());
    header.writeInt(getStreamChannelId());

    return PayloadPacket.appendPayload(header, payload);
}
 
Example 13
Source File: OFQueueVendorData.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
/**
 * Write the queue message data to the ChannelBuffer
 * @param data the channel buffer to which we're serializing
 */
public void writeTo(ChannelBuffer data) {
    super.writeTo(data);
    data.writeShort(this.portNumber);
    data.writeInt(0);   // pad
    data.writeShort(0); // pad

    for (OFPacketQueue queue : queues) {
        queue.writeTo(data);
    }
}
 
Example 14
Source File: StreamPingPacket.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public ChannelBuffer toBuffer() {
    ChannelBuffer header = ChannelBuffers.buffer(2 + 4 + 4);
    header.writeShort(getPacketType());
    header.writeInt(getStreamChannelId());
    header.writeInt(requestId);

    return header;
}
 
Example 15
Source File: TraceSendAckPacket.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public ChannelBuffer toBuffer() {
    ChannelBuffer header = ChannelBuffers.buffer(2 + 4);
    header.writeShort(PacketType.APPLICATION_TRACE_SEND_ACK);
    header.writeInt(traceId);

    return header;
}
 
Example 16
Source File: SendPacket.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public ChannelBuffer toBuffer() {
    ChannelBuffer header = ChannelBuffers.buffer(2 + 4);
    header.writeShort(PacketType.APPLICATION_SEND);


    return PayloadPacket.appendPayload(header, payload);
}
 
Example 17
Source File: BgpLSIdentifierTlv.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public int write(ChannelBuffer c) {
    int iLenStartIndex = c.writerIndex();
    c.writeShort(TYPE);
    c.writeShort(LENGTH);
    c.writeInt(bgpLsIdentifier);
    return c.writerIndex() - iLenStartIndex;
}
 
Example 18
Source File: MpUnReachNlri.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public int write(ChannelBuffer cb) {
    int iLenStartIndex = cb.writerIndex();
    if ((afi == Constants.AFI_FLOWSPEC_VALUE) && ((safi == Constants.SAFI_FLOWSPEC_VALUE) ||
        (safi == Constants.VPN_SAFI_FLOWSPEC_VALUE))) {
        List<BgpValueType> flowSpec = bgpFlowSpecNlri.flowSpecComponents();
        ListIterator<BgpValueType> listIterator = flowSpec.listIterator();
        boolean isAllFlowTypesIdentical = true;

        cb.writeByte(FLAGS);
        cb.writeByte(MPUNREACHNLRI_TYPE);

        int mpUnReachIndx = cb.writerIndex();
        cb.writeShort(0);

        cb.writeShort(afi);
        cb.writeByte(safi);

        if (bgpFlowSpecNlri.routeDistinguisher() != null) {
            cb.writeLong(bgpFlowSpecNlri.routeDistinguisher().getRouteDistinguisher());
        }

        BgpValueType tlv1 = null;
        if (listIterator.hasNext()) {
            tlv1 = listIterator.next();
        }
        while (tlv1 != null && listIterator.hasNext()) {
            BgpValueType tlv = listIterator.next();
            if (tlv.getType() != tlv1.getType()) {
                isAllFlowTypesIdentical = false;
                break;
            }
        }

        if (isAllFlowTypesIdentical) {
            BgpFlowSpecNlri.updateBufferIdenticalFlowTypes(cb, bgpFlowSpecNlri());
        } else {
            BgpFlowSpecNlri.updateBufferNonIdenticalFlowTypes(cb, bgpFlowSpecNlri());
        }
        int fsNlriLen = cb.writerIndex() - mpUnReachIndx;
        cb.setShort(mpUnReachIndx, (short) (fsNlriLen - 2));
    } else if ((afi == Constants.AFI_EVPN_VALUE)
            && (safi == Constants.SAFI_EVPN_VALUE)) {

        cb.writeByte(FLAGS);
        cb.writeByte(MPUNREACHNLRI_TYPE);

        int mpUnReachDataIndex = cb.writerIndex();
        cb.writeShort(0);
        cb.writeShort(afi);
        cb.writeByte(safi);

        for (BgpEvpnNlri element : evpnNlri) {
            short routeType = element.getType();
            switch (routeType) {
                case Constants.BGP_EVPN_MAC_IP_ADVERTISEMENT:
                    cb.writeByte(element.getType());
                    int iSpecStartIndex = cb.writerIndex();
                    cb.writeByte(0);
                    BgpEvpnRouteType2Nlri macIpAdvNlri =
                            (BgpEvpnRouteType2Nlri) element
                                    .getNlri();

                    macIpAdvNlri.write(cb);
                    cb.setByte(iSpecStartIndex, (short) (cb.writerIndex()
                            - iSpecStartIndex - 1));
                    break;
                case Constants.BGP_EVPN_ETHERNET_AUTO_DISCOVERY:
                    break;
                case Constants.BGP_EVPN_INCLUSIVE_MULTICASE_ETHERNET:
                    break;
                case Constants.BGP_EVPN_ETHERNET_SEGMENT:
                    break;
                default:
                    break;
            }
        }

        int evpnNlriLen = cb.writerIndex() - mpUnReachDataIndex;
        cb.setShort(mpUnReachDataIndex, (short) (evpnNlriLen - 2));
    }

    return cb.writerIndex() - iLenStartIndex;
}
 
Example 19
Source File: OFActionNiciraVendor.java    From floodlight_with_topoguard with Apache License 2.0 4 votes vote down vote up
@Override
public void writeTo(ChannelBuffer data) {
    super.writeTo(data);
    data.writeShort(this.subtype);
}
 
Example 20
Source File: MpReachNlri.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public int write(ChannelBuffer cb) {
    int iLenStartIndex = cb.writerIndex();

    if ((afi == Constants.AFI_FLOWSPEC_VALUE) && ((safi == Constants.SAFI_FLOWSPEC_VALUE)
        || (safi == Constants.VPN_SAFI_FLOWSPEC_VALUE))) {
        List<BgpValueType> flowSpec = bgpFlowSpecNlri.flowSpecComponents();
        ListIterator<BgpValueType> listIterator = flowSpec.listIterator();
        boolean isAllFlowTypesIdentical = true;

        cb.writeByte(FLAGS);
        cb.writeByte(MPREACHNLRI_TYPE);

        int mpReachDataIndx = cb.writerIndex();
        cb.writeShort(0);

        cb.writeShort(afi);
        cb.writeByte(safi);
        //next hop address
        cb.writeByte(0);
        //sub network points of attachment
        cb.writeByte(0);

        if (bgpFlowSpecNlri.routeDistinguisher() != null) {
            cb.writeLong(bgpFlowSpecNlri.routeDistinguisher().getRouteDistinguisher());
        }

        BgpValueType tlv1 = null;
        if (listIterator.hasNext()) {
            tlv1 = listIterator.next();
        }
        while (tlv1 != null && listIterator.hasNext()) {
            BgpValueType tlv = listIterator.next();
            if (tlv.getType() != tlv1.getType()) {
                isAllFlowTypesIdentical = false;
                break;
            }
        }

        if (isAllFlowTypesIdentical) {
            BgpFlowSpecNlri.updateBufferIdenticalFlowTypes(cb, bgpFlowSpecNlri());
        } else {
            BgpFlowSpecNlri.updateBufferNonIdenticalFlowTypes(cb, bgpFlowSpecNlri());
        }
        int fsNlriLen = cb.writerIndex() - mpReachDataIndx;
        cb.setShort(mpReachDataIndx, (short) (fsNlriLen - 2));

    } else if ((afi == Constants.AFI_EVPN_VALUE)
            && (safi == Constants.SAFI_EVPN_VALUE)) {

        cb.writeByte(FLAGS);
        cb.writeByte(MPREACHNLRI_TYPE);

        int mpReachDataIndex = cb.writerIndex();
        cb.writeShort(0);
        cb.writeShort(afi);
        cb.writeByte(safi);
        // ip address length and then octets
        byte[] ipnextHopOctets = ipNextHop.toOctets();
        byte ipAddrLen = (byte) (ipnextHopOctets.length);
        cb.writeByte(ipAddrLen);

        for (int temp = 0; temp < ipAddrLen; temp++) {
            cb.writeByte(ipnextHopOctets[temp]);
        }

        //sub network points of attachment
        cb.writeByte(0);

        for (BgpEvpnNlri element : evpnNlri) {
            short routeType = element.getType();
            switch (routeType) {
                case Constants.BGP_EVPN_MAC_IP_ADVERTISEMENT:
                    cb.writeByte(element.getType());
                    int iSpecStartIndex = cb.writerIndex();
                    cb.writeByte(0);
                    BgpEvpnRouteType2Nlri macIpAdvNlri = (BgpEvpnRouteType2Nlri) element
                            .getNlri();
                    macIpAdvNlri.write(cb);
                    cb.setByte(iSpecStartIndex, (byte) (cb.writerIndex()
                            - iSpecStartIndex - 1));
                    //ChannelBuffer temcb = cb.copy();
                    break;
                case Constants.BGP_EVPN_ETHERNET_AUTO_DISCOVERY:
                    break;
                case Constants.BGP_EVPN_INCLUSIVE_MULTICASE_ETHERNET:
                    break;
                case Constants.BGP_EVPN_ETHERNET_SEGMENT:
                    break;
                default:
                    break;
            }
        }
        int evpnNlriLen = cb.writerIndex() - mpReachDataIndex;
        cb.setShort(mpReachDataIndex, (short) (evpnNlriLen - 2));
    }

    return cb.writerIndex() - iLenStartIndex;
}