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

The following examples show how to use org.jboss.netty.buffer.ChannelBuffer#writeLong() . 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: BgpEvpnRouteType2Nlri.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public int write(ChannelBuffer cb) {
    int iLenStartIndex = cb.writerIndex();
    cb.writeLong(rd.getRouteDistinguisher());
    esi.write(cb);
    cb.writeInt(ethernetTagID);
    cb.writeByte(macAddressLength);
    cb.writeBytes(macAddress.toBytes());
    cb.writeByte(ipAddressLength);
    if (ipAddressLength > 0) {
        cb.writeBytes(ipAddress.getAddress());
    }
    mplsLabel1.write(cb);
    if (mplsLabel2 != null) {
        mplsLabel2.write(cb);
    }
    return cb.writerIndex() - iLenStartIndex;
}
 
Example 2
Source File: MemcachedBinaryResponseEncoder.java    From fqueue with Apache License 2.0 6 votes vote down vote up
public ChannelBuffer constructHeader(MemcachedBinaryCommandDecoder.BinaryCommand bcmd, ChannelBuffer extrasBuffer, ChannelBuffer keyBuffer, ChannelBuffer valueBuffer, short responseCode, int opaqueValue, long casUnique) {
    // take the ResponseMessage and turn it into a binary payload.
    ChannelBuffer header = ChannelBuffers.buffer(ByteOrder.BIG_ENDIAN, 24);
    header.writeByte((byte)0x81);  // magic
    header.writeByte(bcmd.code); // opcode
    short keyLength = (short) (keyBuffer != null ? keyBuffer.capacity() :0);

    header.writeShort(keyLength);
    int extrasLength = extrasBuffer != null ? extrasBuffer.capacity() : 0;
    header.writeByte((byte) extrasLength); // extra length = flags + expiry
    header.writeByte((byte)0); // data type unused
    header.writeShort(responseCode); // status code

    int dataLength = valueBuffer != null ? valueBuffer.capacity() : 0;
    header.writeInt(dataLength + keyLength + extrasLength); // data length
    header.writeInt(opaqueValue); // opaque

    header.writeLong(casUnique);

    return header;
}
 
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: OFFlowMod.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(command);
    data.writeShort(idleTimeout);
    data.writeShort(hardTimeout);
    data.writeShort(priority);
    data.writeInt(bufferId);
    data.writeShort(outPort);
    data.writeShort(flags);
    if (actions != null) {
        for (OFAction action : actions) {
            action.writeTo(data);
        }
    }
}
 
Example 5
Source File: OFFlowStatisticsReply.java    From floodlight_with_topoguard with Apache License 2.0 6 votes vote down vote up
@Override
public void writeTo(ChannelBuffer data) {
    data.writeShort(this.length);
    data.writeByte(this.tableId);
    data.writeByte((byte) 0);
    this.match.writeTo(data);
    data.writeInt(this.durationSeconds);
    data.writeInt(this.durationNanoseconds);
    data.writeShort(this.priority);
    data.writeShort(this.idleTimeout);
    data.writeShort(this.hardTimeout);
    data.writeInt(0); // pad
    data.writeShort((short)0); // pad
    data.writeLong(this.cookie);
    data.writeLong(this.packetCount);
    data.writeLong(this.byteCount);
    if (actions != null) {
        for (OFAction action : actions) {
            action.writeTo(data);
        }
    }
}
 
Example 6
Source File: OFPortStatisticsReply.java    From floodlight_with_topoguard with Apache License 2.0 6 votes vote down vote up
@Override
public void writeTo(ChannelBuffer data) {
    data.writeShort(this.portNumber);
    data.writeShort((short) 0); // pad
    data.writeInt(0); // pad
    data.writeLong(this.receivePackets);
    data.writeLong(this.transmitPackets);
    data.writeLong(this.receiveBytes);
    data.writeLong(this.transmitBytes);
    data.writeLong(this.receiveDropped);
    data.writeLong(this.transmitDropped);
    data.writeLong(this.receiveErrors);
    data.writeLong(this.transmitErrors);
    data.writeLong(this.receiveFrameErrors);
    data.writeLong(this.receiveOverrunErrors);
    data.writeLong(this.receiveCRCErrors);
    data.writeLong(this.collisions);
}
 
Example 7
Source File: OpKillCursors.java    From usergrid with Apache License 2.0 6 votes vote down vote up
@Override
public ChannelBuffer encode( ChannelBuffer buffer ) {
    int l = 24; // (6 ints * 4 bytes)

    numberOfCursorIDs = 0;
    if ( cursorIDs != null ) {
        numberOfCursorIDs = cursorIDs.size();
        l += numberOfCursorIDs * 8;
    }
    messageLength = l;

    buffer = super.encode( buffer );

    buffer.writeInt( 0 );

    buffer.writeInt( numberOfCursorIDs );

    if ( cursorIDs != null ) {
        for ( Long cursorID : cursorIDs ) {
            buffer.writeLong( cursorID );
        }
    }

    return buffer;
}
 
Example 8
Source File: OFFeaturesReply.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.writeLong(this.datapathId);
    data.writeInt(this.buffers);
    data.writeByte(this.tables);
    data.writeShort((short) 0); // pad
    data.writeByte((byte) 0); // pad
    data.writeInt(this.capabilities);
    data.writeInt(this.actions);
    if (this.ports != null)
        for (OFPhysicalPort port : this.ports) {
            port.writeTo(data);
        }
}
 
Example 9
Source File: RoutingUniverseTlv.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.writeLong(rawValue);
    return c.writerIndex() - iLenStartIndex;
}
 
Example 10
Source File: OFTableStatistics.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
@Override
public void writeTo(ChannelBuffer data) {
    data.writeByte(this.tableId);
    data.writeByte((byte) 0); // pad
    data.writeByte((byte) 0); // pad
    data.writeByte((byte) 0); // pad
    StringByteSerializer.writeTo(data, MAX_TABLE_NAME_LEN, this.name);
    data.writeInt(this.wildcards);
    data.writeInt(this.maximumEntries);
    data.writeInt(this.activeCount);
    data.writeLong(this.lookupCount);
    data.writeLong(this.matchedCount);
}
 
Example 11
Source File: OFBsnPktinSuppressionSetRequestVendorData.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(suppressionEnabled ? 1 : 0);
    data.writeByte(0); // pad
    data.writeShort(idleTimeout);
    data.writeShort(hardTimeout);
    data.writeShort(priority);
    data.writeLong(cookie);
}
 
Example 12
Source File: StatefulLspDbVerTlv.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public int write(ChannelBuffer c) {
    c.writeShort(TYPE);
    c.writeShort(LENGTH);
    c.writeLong(rawValue);
    return c.writerIndex();
}
 
Example 13
Source File: PlayHandler.java    From restcommander with Apache License 2.0 5 votes vote down vote up
private void upgradeResponseHixie76(HttpRequest req, HttpResponse res) {
    res.setStatus(new HttpResponseStatus(101, "Web Socket Protocol Handshake"));
    res.addHeader(UPGRADE, WEBSOCKET);
    res.addHeader(CONNECTION, UPGRADE);
    res.addHeader(SEC_WEBSOCKET_ORIGIN, req.getHeader(ORIGIN));
    res.addHeader(SEC_WEBSOCKET_LOCATION, getWebSocketLocation(req));
    String protocol = req.getHeader(SEC_WEBSOCKET_PROTOCOL);
    if (protocol != null) {
        res.addHeader(SEC_WEBSOCKET_PROTOCOL, protocol);
    }

    // Calculate the answer of the challenge.
    String key1 = req.getHeader(SEC_WEBSOCKET_KEY1);
    String key2 = req.getHeader(SEC_WEBSOCKET_KEY2);
    int a = (int) (Long.parseLong(key1.replaceAll("[^0-9]", "")) / key1.replaceAll("[^ ]", "").length());
    int b = (int) (Long.parseLong(key2.replaceAll("[^0-9]", "")) / key2.replaceAll("[^ ]", "").length());
    long c = req.getContent().readLong();
    ChannelBuffer input = ChannelBuffers.buffer(16);
    input.writeInt(a);
    input.writeInt(b);
    input.writeLong(c);
    try {
        ChannelBuffer output = ChannelBuffers.wrappedBuffer(
                MessageDigest.getInstance("MD5").digest(input.array()));
        res.setContent(output);
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    }
}
 
Example 14
Source File: PcepLabelDbVerTlv.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.writeLong(rawValue);
    return c.writerIndex() - iLenStartIndex;
}
 
Example 15
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;
}
 
Example 16
Source File: PcepLSObjectVer1.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public int write(ChannelBuffer cb) throws PcepParseException {

    //write Object header
    int objStartIndex = cb.writerIndex();
    int objLenIndex = lsObjHeader.write(cb);

    if (objLenIndex <= 0) {
        throw new PcepParseException("ObjectLength Index is " + objLenIndex);
    }

    //write Protocol ID
    cb.writeByte(this.protocolId);

    //write Flag
    cb.writeShort(0);

    byte bTemp = 0;
    if (syncFlag) {
        bTemp = FLAG_SET_S_FLAG;
    }

    if (removeFlag) {
        bTemp = (byte) (bTemp | FLAG_SET_R_FLAG);
    }
    cb.writeByte(bTemp);

    //write LSId
    cb.writeLong(lsId);

    // Add optional TLV
    packOptionalTlv(cb);

    //Update object length now
    int length = cb.writerIndex() - objStartIndex;

    //will be helpful during print().
    lsObjHeader.setObjLen((short) length);

    cb.setShort(objLenIndex, (short) length);

    return cb.writerIndex();
}
 
Example 17
Source File: Hybi10WebSocketFrameEncoder.java    From restcommander with Apache License 2.0 4 votes vote down vote up
@Override
 protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {

     if (msg instanceof DefaultWebSocketFrame) {
         final DefaultWebSocketFrame frame = (DefaultWebSocketFrame) msg;

         ChannelBuffer data = frame.getBinaryData();
if (data == null) {
	data = ChannelBuffers.EMPTY_BUFFER;
}

         byte opcode;
         // TODO: Close and CONTINUATION
         if(frame instanceof Ping) {
             opcode = OPCODE_PING;
         } else if(frame instanceof Pong) {
             opcode = OPCODE_PONG;
         } else {
             opcode = frame.isText() ? OPCODE_TEXT : OPCODE_BINARY;
         }


         int length = data.readableBytes();

int b0 = 0;
   b0 |= (1 << 7);
         // TODO: RSV, for now it is set to 0
b0 |= (0 % 8) << 4;
b0 |= opcode % 128;

         ChannelBuffer header;
         ChannelBuffer body;


         // TODO: if there is no mask
         int maskLength = 4;
         if (length <= 125) {
             header = ChannelBuffers.buffer(2 + maskLength);
             header.writeByte(b0);
             byte b = (byte) (0x80 | (byte) length);
             header.writeByte(b);
         } else if (length <= 0xFFFF) {
             header = ChannelBuffers.buffer(4 + maskLength);
             header.writeByte(b0);
             header.writeByte(0x80 | 126);
             header.writeByte((length >>> 8) & 0xFF);
             header.writeByte((length) & 0xFF);
         } else {
             header = ChannelBuffers.buffer(10 + maskLength);
             header.writeByte(b0);
             header.writeByte(0x80 | 127);
             header.writeLong(length);
         }

         Integer random = (int) (Math.random() * Integer.MAX_VALUE);
         byte[] mask = ByteBuffer.allocate(4).putInt(random).array();
         header.writeBytes(mask);

         body = ChannelBuffers.buffer(length);
         int counter = 0;
         while (data.readableBytes() > 0) {
             byte byteData = data.readByte();
             body.writeByte(byteData ^ mask[+counter++ % 4]);
         }
         return ChannelBuffers.wrappedBuffer(header, body);
     }

     return msg;
 }
 
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: OpGetMore.java    From usergrid with Apache License 2.0 4 votes vote down vote up
@Override
public ChannelBuffer encode( ChannelBuffer buffer ) {
    int l = 32; // 8 ints * 4 bytes

    ByteBuffer fullCollectionNameBytes = getCString( fullCollectionName );
    l += fullCollectionNameBytes.capacity();

    messageLength = l;

    buffer = super.encode( buffer );

    buffer.writeInt( 0 );

    buffer.writeBytes( fullCollectionNameBytes );

    buffer.writeInt( numberToReturn );

    buffer.writeLong( cursorID );

    return buffer;
}
 
Example 20
Source File: BaseServerPacket.java    From aion-germany with GNU General Public License v3.0 2 votes vote down vote up
/**
 * @param buf
 * @param data
 */
protected final void writeQ(ChannelBuffer buf, long data) {
    buf.writeLong(data);
}