Java Code Examples for org.jboss.netty.buffer.ChannelBuffer#setByte()
The following examples show how to use
org.jboss.netty.buffer.ChannelBuffer#setByte() .
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: BgpEvpnNlriImpl.java From onos with Apache License 2.0 | 6 votes |
@Override public int write(ChannelBuffer cb) { int iLenStartIndex = cb.writerIndex(); cb.writeByte(routeType); int iSpecStartIndex = cb.writerIndex(); cb.writeByte(0); switch (routeType) { case BgpEvpnRouteType2Nlri.TYPE: ((BgpEvpnRouteType2Nlri) routeTypeSpec).write(cb); break; default: break; } cb.setByte(iSpecStartIndex, (short) (cb.writerIndex() - iSpecStartIndex + 1)); return cb.writerIndex() - iLenStartIndex; }
Example 2
Source File: As4Path.java From onos with Apache License 2.0 | 6 votes |
@Override public int write(ChannelBuffer cb) { int iLenStartIndex = cb.writerIndex(); cb.writeByte(FLAGS); cb.writeByte(getType()); if ((as4pathSet != null) && (as4pathSeq != null)) { int iAsLenIndex = cb.writerIndex(); cb.writeByte(0); if (!as4pathSeq.isEmpty()) { cb.writeByte(AsPath.ASPATH_SEQ_TYPE); cb.writeByte(as4pathSeq.size()); for (int j = 0; j < as4pathSeq.size(); j++) { cb.writeInt(as4pathSeq.get(j)); } int asLen = cb.writerIndex() - iAsLenIndex; cb.setByte(iAsLenIndex, (byte) (asLen - 1)); } } else { cb.writeByte(0); } return cb.writerIndex() - iLenStartIndex; }
Example 3
Source File: AsPath.java From onos with Apache License 2.0 | 6 votes |
@Override public int write(ChannelBuffer cb) { int iLenStartIndex = cb.writerIndex(); cb.writeByte(FLAGS); cb.writeByte(getType()); if (isaspathSet()) { int iAsLenIndex = cb.writerIndex(); cb.writeByte(0); if (!aspathSeq.isEmpty()) { cb.writeByte(ASPATH_SEQ_TYPE); cb.writeByte(aspathSeq.size()); for (int j = 0; j < aspathSeq.size(); j++) { cb.writeShort(aspathSeq.get(j)); } int asLen = cb.writerIndex() - iAsLenIndex; cb.setByte(iAsLenIndex, (byte) (asLen - 1)); } } else { cb.writeByte(0); } return cb.writerIndex() - iLenStartIndex; }
Example 4
Source File: NettyHeader.java From Elasticsearch with Apache License 2.0 | 5 votes |
public static void writeHeader(ChannelBuffer buffer, long requestId, byte status, Version version) { int index = buffer.readerIndex(); buffer.setByte(index, 'E'); index += 1; buffer.setByte(index, 'S'); index += 1; // write the size, the size indicates the remaining message size, not including the size int buffer.setInt(index, buffer.readableBytes() - 6); index += 4; buffer.setLong(index, requestId); index += 8; buffer.setByte(index, status); index += 1; buffer.setInt(index, version.id); }
Example 5
Source File: Hybi10WebSocketFrameDecoder.java From restcommander with Apache License 2.0 | 5 votes |
private void unmask(ChannelBuffer frame) { byte[] bytes = frame.array(); for (int i = 0; i < bytes.length; i++) { int b = frame.getByte(i) ^ maskingKey.getByte(i % 4); frame.setByte(i, b); } }
Example 6
Source File: SrEroSubObject.java From onos with Apache License 2.0 | 5 votes |
@Override public int write(ChannelBuffer c) { int iLenStartIndex = c.writerIndex(); c.writeByte(TYPE); // Store the position of object length int objectLenIndex = c.writerIndex(); c.writeByte(0); short temp = 0; if (bMFlag) { temp = (short) (temp | MFLAG_SET); } if (bCFlag) { temp = (short) (temp | CFLAG_SET); } if (bSFlag) { temp = (short) (temp | SFLAG_SET); } if (bFFlag) { temp = (short) (temp | FFLAG_SET); } short tempST = (short) (st << SHIFT_ST); temp = (short) (temp | tempST); c.writeShort(temp); if (bMFlag) { int tempSid = sid << 12; c.writeInt(tempSid); } else { c.writeInt(sid); } nai.write(c); c.setByte(objectLenIndex, (c.writerIndex() - iLenStartIndex)); return c.writerIndex() - iLenStartIndex; }
Example 7
Source File: BgpOpenMsgVer4.java From onos with Apache License 2.0 | 5 votes |
/** * returns length of capability tlvs. * * @param cb of type channel buffer * @param message of type BGPOpenMsgVer4 * @return capParaLen of open message */ protected int packCapabilityTlv(ChannelBuffer cb, BgpOpenMsgVer4 message) { int startIndex = cb.writerIndex(); int capParaLen = 0; int capParaLenIndex = 0; LinkedList<BgpValueType> capabilityTlv = message.capabilityTlv; ListIterator<BgpValueType> listIterator = capabilityTlv.listIterator(); if (listIterator.hasNext()) { // Set optional parameter type as 2 cb.writeByte(OPT_PARA_TYPE_CAPABILITY); // Store the index of capability parameter length and update length at the end capParaLenIndex = cb.writerIndex(); // Set capability parameter length as 0 cb.writeByte(0); // Update the startIndex to know the length of capability tlv startIndex = cb.writerIndex(); } while (listIterator.hasNext()) { BgpValueType tlv = listIterator.next(); if (tlv == null) { log.debug("Warning: TLV is null from CapabilityTlv list"); continue; } tlv.write(cb); } capParaLen = cb.writerIndex() - startIndex; if (capParaLen != 0) { // Update capability parameter length cb.setByte(capParaLenIndex, (byte) capParaLen); } return capParaLen; }
Example 8
Source File: BgpExtendedCommunity.java From onos with Apache License 2.0 | 5 votes |
@Override public int write(ChannelBuffer cb) { int iLenStartIndex = cb.writerIndex(); ListIterator<BgpValueType> listIterator = fsActionTlv().listIterator(); cb.writeByte(FLAGS); cb.writeByte(getType()); int iActionLenIndex = cb.writerIndex(); cb.writeByte(0); while (listIterator.hasNext()) { BgpValueType fsTlv = listIterator.next(); if (fsTlv.getType() == Constants.BGP_ROUTE_TARGET_AS || fsTlv.getType() == Constants.BGP_ROUTE_TARGET_IP || fsTlv.getType() == Constants.BGP_ROUTE_TARGET_LARGEAS) { RouteTarget routeTarget = (RouteTarget) fsTlv; routeTarget.write(cb); } else if (fsTlv.getType() == Constants .BGP_FLOWSPEC_ACTION_TRAFFIC_ACTION) { BgpFsActionTrafficAction trafficAction = (BgpFsActionTrafficAction) fsTlv; trafficAction.write(cb); } else if (fsTlv.getType() == Constants.BGP_FLOWSPEC_ACTION_TRAFFIC_MARKING) { BgpFsActionTrafficMarking trafficMarking = (BgpFsActionTrafficMarking) fsTlv; trafficMarking.write(cb); } else if (fsTlv.getType() == Constants.BGP_FLOWSPEC_ACTION_TRAFFIC_RATE) { BgpFsActionTrafficRate trafficRate = (BgpFsActionTrafficRate) fsTlv; trafficRate.write(cb); } else if (fsTlv.getType() == Constants.BGP_FLOWSPEC_ACTION_TRAFFIC_REDIRECT) { BgpFsActionReDirect trafficRedirect = (BgpFsActionReDirect) fsTlv; trafficRedirect.write(cb); } } int fsActionLen = cb.writerIndex() - iActionLenIndex; cb.setByte(iActionLenIndex, (byte) (fsActionLen - 1)); return cb.writerIndex() - iLenStartIndex; }
Example 9
Source File: BgpOpenMsgVer4.java From onos with Apache License 2.0 | 4 votes |
@Override public void write(ChannelBuffer cb, BgpOpenMsgVer4 message) throws BgpParseException { int optParaLen = 0; int as4num = 0; int startIndex = cb.writerIndex(); // write common header and get msg length index int msgLenIndex = message.bgpMsgHeader.write(cb); if (msgLenIndex <= 0) { throw new BgpParseException("Unable to write message header."); } // write version in 1-octet cb.writeByte(message.version); // get as4num if LS Capability is set if (message.isLargeAsCapabilitySet) { LinkedList<BgpValueType> capabilityTlv = message .getCapabilityTlv(); ListIterator<BgpValueType> listIterator = capabilityTlv .listIterator(); while (listIterator.hasNext()) { BgpValueType tlv = listIterator.next(); if (tlv.getType() == FOUR_OCTET_AS_NUM_CAPA_TYPE) { as4num = ((FourOctetAsNumCapabilityTlv) tlv).getInt(); break; } } } if ((message.isLargeAsCapabilitySet) && (as4num > 65535)) { // write As number as AS_TRANS cb.writeShort(AS_TRANS); } else { // write AS number in next 2-octet cb.writeShort((short) message.asNumber); } // write HoldTime in next 2-octet cb.writeShort(message.holdTime); // write BGP Identifier in next 4-octet cb.writeInt(message.bgpId); // store the index of Optional parameter length int optParaLenIndex = cb.writerIndex(); // set optional parameter length as 0 cb.writeByte(0); // Pack capability TLV optParaLen = message.packCapabilityTlv(cb, message); if (optParaLen != 0) { // Update optional parameter length cb.setByte(optParaLenIndex, (byte) (optParaLen + 2)); //+2 for optional parameter type. } // write OPEN Object Length int length = cb.writerIndex() - startIndex; cb.setShort(msgLenIndex, (short) length); message.bgpMsgHeader.setLength((short) length); }
Example 10
Source File: MpReachNlri.java From onos with Apache License 2.0 | 4 votes |
@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 11
Source File: MpUnReachNlri.java From onos with Apache License 2.0 | 4 votes |
@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; }