當前位置: 首頁>>代碼示例>>Java>>正文


Java ChannelBuffer.copy方法代碼示例

本文整理匯總了Java中org.jboss.netty.buffer.ChannelBuffer.copy方法的典型用法代碼示例。如果您正苦於以下問題:Java ChannelBuffer.copy方法的具體用法?Java ChannelBuffer.copy怎麽用?Java ChannelBuffer.copy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jboss.netty.buffer.ChannelBuffer的用法示例。


在下文中一共展示了ChannelBuffer.copy方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: parseNodeDescriptors

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
 * Parses Local/Remote node descriptors.
 *
 * @param cb ChannelBuffer
 * @param desType descriptor type
 * @param protocolId protocol identifier
 * @return object of NodeDescriptors
 * @throws BgpParseException while parsing Local/Remote node descriptors
 */
public static NodeDescriptors parseNodeDescriptors(ChannelBuffer cb, short desType, byte protocolId)
        throws BgpParseException {
    log.debug("parse Node descriptors");
    ChannelBuffer tempBuf = cb.copy();
    short type = cb.readShort();
    short length = cb.readShort();
    if (cb.readableBytes() < length) {
        throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.OPTIONAL_ATTRIBUTE_ERROR,
                tempBuf.readBytes(cb.readableBytes() + Constants.TYPE_AND_LEN_AS_SHORT));
    }
    NodeDescriptors nodeIdentifier = new NodeDescriptors();
    ChannelBuffer tempCb = cb.readBytes(length);

    if (type == desType) {
        nodeIdentifier = NodeDescriptors.read(tempCb, length, desType, protocolId);
    } else {
        throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.MALFORMED_ATTRIBUTE_LIST, null);
    }
    return nodeIdentifier;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:30,代碼來源:BgpLinkLSIdentifier.java

示例2: parseLocalNodeDescriptors

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
 * Parse local node descriptors.
 *
 * @param cb ChannelBuffer
 * @param protocolId protocol identifier
 * @return object of this BGPNodeLSIdentifier
 * @throws BgpParseException while parsing local node descriptors
 */
public static BgpNodeLSIdentifier parseLocalNodeDescriptors(ChannelBuffer cb, byte protocolId)
        throws BgpParseException {
    log.debug("parse Local node descriptor");
    ChannelBuffer tempBuf = cb.copy();
    short type = cb.readShort();
    short length = cb.readShort();
    if (cb.readableBytes() < length) {
        throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.OPTIONAL_ATTRIBUTE_ERROR,
                                    tempBuf.readBytes(cb.readableBytes() + Constants.TYPE_AND_LEN));
    }
    NodeDescriptors nodeDescriptors = new NodeDescriptors();
    ChannelBuffer tempCb = cb.readBytes(length);

    if (type == NodeDescriptors.LOCAL_NODE_DES_TYPE) {
        nodeDescriptors = NodeDescriptors.read(tempCb, length, type, protocolId);
    } else {
        throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.MALFORMED_ATTRIBUTE_LIST, null);
    }
    return new BgpNodeLSIdentifier(nodeDescriptors);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:29,代碼來源:BgpNodeLSIdentifier.java

示例3: parseLocalNodeDescriptors

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
 * Parse local node descriptors.
 *
 * @param cb ChannelBuffer
 * @param protocolId protocol identifier
 * @return LocalNodeDescriptors
 * @throws BgpParseException while parsing local node descriptors
 */
public static NodeDescriptors parseLocalNodeDescriptors(ChannelBuffer cb, byte protocolId)
                                                             throws BgpParseException {
    ChannelBuffer tempBuf = cb.copy();
    short type = cb.readShort();
    short length = cb.readShort();
    if (cb.readableBytes() < length) {
        //length + 4 implies data contains type, length and value
        throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.OPTIONAL_ATTRIBUTE_ERROR,
                tempBuf.readBytes(cb.readableBytes() + TYPE_AND_LEN));
    }
    NodeDescriptors localNodeDescriptors = new NodeDescriptors();
    ChannelBuffer tempCb = cb.readBytes(length);

    if (type == NodeDescriptors.LOCAL_NODE_DES_TYPE) {
        localNodeDescriptors = NodeDescriptors.read(tempCb, length, type, protocolId);
    } else {
        throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR,
                                       BgpErrorType.MALFORMED_ATTRIBUTE_LIST, null);
    }
    return localNodeDescriptors;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:30,代碼來源:BgpPrefixLSIdentifier.java

示例4: read

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
 * Reads the channel buffer and returns object of Med.
 *
 * @param cb ChannelBuffer
 * @return object of Med
 * @throws BgpParseException while parsing Med path attribute
 */
public static Med read(ChannelBuffer cb) throws BgpParseException {
    int med;
    ChannelBuffer tempCb = cb.copy();
    Validation parseFlags = Validation.parseAttributeHeader(cb);

    if ((parseFlags.getLength() > MED_MAX_LEN) || cb.readableBytes() < parseFlags.getLength()) {
        Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
                parseFlags.getLength());
    }
    int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : parseFlags
            .getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
    ChannelBuffer data = tempCb.readBytes(len);
    if (!parseFlags.getFirstBit() && parseFlags.getSecondBit() && parseFlags.getThirdBit()) {
        throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_FLAGS_ERROR, data);
    }

    med = cb.readInt();
    return new Med(med);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:27,代碼來源:Med.java

示例5: read

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
 * Reads the channel buffer and returns object of LocalPref.
 *
 * @param cb channelBuffer
 * @return object of LocalPref
 * @throws BgpParseException while parsing localPref attribute
 */
public static LocalPref read(ChannelBuffer cb) throws BgpParseException {
    int localPref;
    ChannelBuffer tempCb = cb.copy();
    Validation parseFlags = Validation.parseAttributeHeader(cb);
    if ((parseFlags.getLength() > LOCAL_PREF_MAX_LEN) || cb.readableBytes() < parseFlags.getLength()) {
        Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
                parseFlags.getLength());
    }

    int len = parseFlags.isShort() ? parseFlags.getLength() +
              Constants.TYPE_AND_LEN_AS_SHORT : parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
    ChannelBuffer data = tempCb.readBytes(len);
    if (parseFlags.getFirstBit()) {
        throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_FLAGS_ERROR, data);
    }

    localPref = cb.readInt();
    return new LocalPref(localPref);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:27,代碼來源:LocalPref.java

示例6: read

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
 * Reads from ChannelBuffer and parses NextHop.
 *
 * @param cb ChannelBuffer
 * @return object of NextHop
 * @throws BgpParseException while parsing nexthop attribute
 */
public static NextHop read(ChannelBuffer cb) throws BgpParseException {
    Ip4Address nextHop;
    ChannelBuffer tempCb = cb.copy();
    Validation parseFlags = Validation.parseAttributeHeader(cb);

    if (cb.readableBytes() < parseFlags.getLength()) {
        Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
                parseFlags.getLength());
    }
    int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : parseFlags
            .getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
    ChannelBuffer data = tempCb.readBytes(len);
    if (parseFlags.getFirstBit() && !parseFlags.getSecondBit() && parseFlags.getThirdBit()) {
        throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_FLAGS_ERROR, data);
    }

     InetAddress ipAddress = Validation.toInetAddress(parseFlags.getLength(), cb);
    if (ipAddress.isMulticastAddress()) {
        throw new BgpParseException("Multicast address is not supported");
    }

    nextHop = Ip4Address.valueOf(ipAddress);
    return new NextHop(nextHop);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:32,代碼來源:NextHop.java

示例7: read

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
 * Reads from ChannelBuffer and parses Origin.
 *
 * @param cb ChannelBuffer
 * @return object of Origin
 * @throws BgpParseException while parsing Origin path attribute
 */
public static Origin read(ChannelBuffer cb) throws BgpParseException {
    ChannelBuffer tempCb = cb.copy();
    Validation parseFlags = Validation.parseAttributeHeader(cb);

    int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : parseFlags
            .getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
    ChannelBuffer data = tempCb.readBytes(len);
    if ((parseFlags.getLength() > ORIGIN_VALUE_LEN) || (cb.readableBytes() < parseFlags.getLength())) {
        Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
                parseFlags.getLength());
    }
    if (parseFlags.getFirstBit() && !parseFlags.getSecondBit() && parseFlags.getThirdBit()) {
        throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_FLAGS_ERROR, data);
    }

    byte originValue;
    originValue = cb.readByte();
    if ((originValue != OriginType.INCOMPLETE.value) && (originValue != OriginType.IGP.value) &&
          (originValue != OriginType.EGP.value)) {
        throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.INVALID_ORIGIN_ATTRIBUTE, data);
    }
    return new Origin(originValue);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:31,代碼來源:Origin.java

示例8: read

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
 * Reads node descriptors Sub-TLVs.
 *
 * @param cb ChannelBuffer
 * @param desLength node descriptor length
 * @param desType local node descriptor or remote node descriptor type
 * @param protocolId protocol ID
 * @return object of NodeDescriptors
 * @throws BgpParseException while parsing node descriptors
 */
public static NodeDescriptors read(ChannelBuffer cb, short desLength, short desType, byte protocolId)
        throws BgpParseException {
    log.debug("Read NodeDescriptor");
    List<BgpValueType> subTlvs = new LinkedList<>();
    BgpValueType tlv = null;

    while (cb.readableBytes() > 0) {
        ChannelBuffer tempBuf = cb.copy();
        short type = cb.readShort();
        short length = cb.readShort();
        if (cb.readableBytes() < length) {
            throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.OPTIONAL_ATTRIBUTE_ERROR,
                    tempBuf.readBytes(cb.readableBytes() + TYPE_AND_LEN));
        }
        ChannelBuffer tempCb = cb.readBytes(length);
        switch (type) {
        case AutonomousSystemTlv.TYPE:
            tlv = AutonomousSystemTlv.read(tempCb);
            break;
        case BgpLSIdentifierTlv.TYPE:
            tlv = BgpLSIdentifierTlv.read(tempCb);
            break;
        case AreaIDTlv.TYPE:
            tlv = AreaIDTlv.read(tempCb);
            break;
        case IGP_ROUTERID_TYPE:
            if (protocolId == IS_IS_LEVEL_1_PROTOCOL_ID || protocolId == IS_IS_LEVEL_2_PROTOCOL_ID) {
                boolean isNonPseudoNode = true;
                if ((length == ISISPSEUDONODE_LEN) && (tempCb.getByte(ISISPSEUDONODE_LEN - 1) != 0)) {
                    isNonPseudoNode = false;
                }
                if (isNonPseudoNode) {
                    tlv = IsIsNonPseudonode.read(tempCb);
                } else {
                    tlv = IsIsPseudonode.read(tempCb);
                }
            } else if (protocolId == OSPF_V2_PROTOCOL_ID || protocolId == OSPF_V3_PROTOCOL_ID) {
                if (length == OSPFNONPSEUDONODE_LEN) {
                    tlv = OspfNonPseudonode.read(tempCb);
                } else if (length == OSPFPSEUDONODE_LEN) {
                    tlv = OspfPseudonode.read(tempCb);
                }
            }
            break;
        default:
            UnSupportedAttribute.skipBytes(tempCb, length);
        }
        subTlvs.add(tlv);
    }
    return new NodeDescriptors(subTlvs, desLength, desType);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:62,代碼來源:NodeDescriptors.java

示例9: parseLinkDescriptors

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
 * Parses link descriptors.
 *
 * @param cb ChannelBuffer
 * @return list of link descriptors
 * @throws BgpParseException while parsing link descriptors
 */
public static LinkedList<BgpValueType> parseLinkDescriptors(ChannelBuffer cb) throws BgpParseException {
    LinkedList<BgpValueType> linkDescriptor = new LinkedList<>();
    BgpValueType tlv = null;
    int count = 0;

    while (cb.readableBytes() > 0) {
        ChannelBuffer tempBuf = cb.copy();
        short type = cb.readShort();
        short length = cb.readShort();
        if (cb.readableBytes() < length) {
            throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.OPTIONAL_ATTRIBUTE_ERROR,
                    tempBuf.readBytes(cb.readableBytes() + Constants.TYPE_AND_LEN_AS_SHORT));
        }
        ChannelBuffer tempCb = cb.readBytes(length);
        switch (type) {
        case LinkLocalRemoteIdentifiersTlv.TYPE:
            tlv = LinkLocalRemoteIdentifiersTlv.read(tempCb);
            break;
        case IPV4_INTERFACE_ADDRESS_TYPE:
            tlv = IPv4AddressTlv.read(tempCb, IPV4_INTERFACE_ADDRESS_TYPE);
            break;
        case IPV4_NEIGHBOR_ADDRESS_TYPE:
            tlv = IPv4AddressTlv.read(tempCb, IPV4_NEIGHBOR_ADDRESS_TYPE);
            break;
        case IPV6_INTERFACE_ADDRESS_TYPE:
            tlv = IPv6AddressTlv.read(tempCb, IPV6_INTERFACE_ADDRESS_TYPE);
            break;
        case IPV6_NEIGHBOR_ADDRESS_TYPE:
            tlv = IPv6AddressTlv.read(tempCb, IPV6_NEIGHBOR_ADDRESS_TYPE);
            break;
        case BgpAttrNodeMultiTopologyId.ATTRNODE_MULTITOPOLOGY:
            tlv = BgpAttrNodeMultiTopologyId.read(tempCb);
            count = count++;
            //MultiTopologyId TLV cannot repeat more than once
            if (count > 1) {
                //length + 4 implies data contains type, length and value
                throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR,
                        BgpErrorType.OPTIONAL_ATTRIBUTE_ERROR, tempBuf.readBytes(length
                                + Constants.TYPE_AND_LEN_AS_SHORT));
            }
            break;
        default:
            UnSupportedAttribute.skipBytes(tempCb, length);
        }
        linkDescriptor.add(tlv);
    }
    return linkDescriptor;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:56,代碼來源:BgpLinkLSIdentifier.java

示例10: parsePrefixDescriptors

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
 * Parse list of prefix descriptors.
 *
 * @param cb ChannelBuffer
 * @return list of prefix descriptors
 * @throws BgpParseException while parsing list of prefix descriptors
 */
public static List<BgpValueType> parsePrefixDescriptors(ChannelBuffer cb) throws BgpParseException {
    LinkedList<BgpValueType> prefixDescriptor = new LinkedList<>();
    BgpValueType tlv = null;
    boolean isIpReachInfo = false;
    ChannelBuffer tempCb;
    int count = 0;

    while (cb.readableBytes() > 0) {
        ChannelBuffer tempBuf = cb.copy();
        short type = cb.readShort();
        short length = cb.readShort();
        if (cb.readableBytes() < length) {
            //length + 4 implies data contains type, length and value
            throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.OPTIONAL_ATTRIBUTE_ERROR,
                    tempBuf.readBytes(cb.readableBytes() + TYPE_AND_LEN));
        }
        tempCb = cb.readBytes(length);
        switch (type) {
        case OspfRouteTypeTlv.TYPE:
            tlv = OspfRouteTypeTlv.read(tempCb);
            break;
        case IPReachabilityInformationTlv.TYPE:
            tlv = IPReachabilityInformationTlv.read(tempCb, length);
            isIpReachInfo = true;
            break;
        case BgpAttrNodeMultiTopologyId.ATTRNODE_MULTITOPOLOGY:
            tlv = BgpAttrNodeMultiTopologyId.read(tempCb);
            count = count + 1;
            if (count > 1) {
                //length + 4 implies data contains type, length and value
                throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR,
                       BgpErrorType.OPTIONAL_ATTRIBUTE_ERROR, tempBuf.readBytes(length + TYPE_AND_LEN));
            }
            break;
        default:
            UnSupportedAttribute.skipBytes(tempCb, length);
        }
        prefixDescriptor.add(tlv);
    }

    if (!isIpReachInfo) {
        throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.OPTIONAL_ATTRIBUTE_ERROR,
                null);
    }
    return prefixDescriptor;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:54,代碼來源:BgpPrefixLSIdentifier.java

示例11: read

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
 * Reads from the channel buffer and parses As4Path.
 *
 * @param cb ChannelBuffer
 * @return object of As4Path
 * @throws BgpParseException while parsing As4Path
 */
public static As4Path read(ChannelBuffer cb) throws BgpParseException {
    List<Integer> as4pathSet = new ArrayList<>();
    List<Integer> as4pathSeq = new ArrayList<>();
    ChannelBuffer tempCb = cb.copy();
    Validation validation = Validation.parseAttributeHeader(cb);

    if (cb.readableBytes() < validation.getLength()) {
        Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
                validation.getLength());
    }
    //if fourth bit is set length is read as short otherwise as byte , len includes type, length and value
    int len = validation.isShort() ? validation.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : validation
            .getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
    ChannelBuffer data = tempCb.readBytes(len);
    if (validation.getFirstBit() && !validation.getSecondBit() && validation.getThirdBit()) {
        throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_FLAGS_ERROR, data);
    }

    ChannelBuffer tempBuf = cb.readBytes(validation.getLength());
    while (tempBuf.readableBytes() > 0) {
        byte pathSegType = tempBuf.readByte();
        //no of ASes
        byte pathSegLen = tempBuf.readByte();
        //length = no of Ases * ASnum size (4 bytes)
        int length = pathSegLen * ASNUM_SIZE;
        if (tempBuf.readableBytes() < length) {
            Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
                    BgpErrorType.ATTRIBUTE_LENGTH_ERROR, length);
        }
        ChannelBuffer aspathBuf = tempBuf.readBytes(length);
        while (aspathBuf.readableBytes() > 0) {
            int asNum;
            asNum = aspathBuf.readInt();
            switch (pathSegType) {
            case AsPath.ASPATH_SET_TYPE:
                as4pathSet.add(asNum);
                break;
            case AsPath.ASPATH_SEQ_TYPE:
                as4pathSeq.add(asNum);
                break;
            default: log.debug("Other type Not Supported:" + pathSegType);
            }
        }
    }
    return new As4Path(as4pathSet, as4pathSeq);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:54,代碼來源:As4Path.java

示例12: read

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
 * Reads from the channel buffer and parses extended community.
 *
 * @param cb ChannelBuffer
 * @return object of BgpExtendedCommunity
 * @throws BgpParseException while parsing extended community
 */
public static BgpExtendedCommunity read(ChannelBuffer cb) throws BgpParseException {

    ChannelBuffer tempCb = cb.copy();
    Validation validation = Validation.parseAttributeHeader(cb);
    List<BgpValueType> fsActionTlvs = new LinkedList<>();

    if (cb.readableBytes() < validation.getLength()) {
        Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
                validation.getLength());
    }
    //if fourth bit is set, length is read as short otherwise as byte , len includes type, length and value
    int len = validation.isShort() ? validation.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : validation
            .getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
    ChannelBuffer data = tempCb.readBytes(len);
    if (validation.getFirstBit() && !validation.getSecondBit() && validation.getThirdBit()) {
        throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_FLAGS_ERROR, data);
    }

    ChannelBuffer tempBuf = cb.readBytes(validation.getLength());
    if (tempBuf.readableBytes() > 0) {
        BgpValueType fsActionTlv = null;
        ChannelBuffer actionBuf = tempBuf.readBytes(validation.getLength());

        while (actionBuf.readableBytes() > 0) {
            short actionType = actionBuf.readShort();
            switch (actionType) {
                case Constants.BGP_FLOWSPEC_ACTION_TRAFFIC_ACTION:
                    fsActionTlv = BgpFsActionTrafficAction.read(actionBuf);
                    break;
                case Constants.BGP_FLOWSPEC_ACTION_TRAFFIC_MARKING:
                    fsActionTlv = BgpFsActionTrafficMarking.read(actionBuf);
                    break;
                case Constants.BGP_FLOWSPEC_ACTION_TRAFFIC_RATE:
                    fsActionTlv = BgpFsActionTrafficRate.read(actionBuf);
                    break;
                case Constants.BGP_FLOWSPEC_ACTION_TRAFFIC_REDIRECT:
                    fsActionTlv = BgpFsActionReDirect.read(actionBuf);
                    break;
                default: log.debug("Other type Not Supported:" + actionType);
                    break;
            }
            if (fsActionTlv != null) {
                fsActionTlvs.add(fsActionTlv);
            }
        }
    }
    return new BgpExtendedCommunity(fsActionTlvs);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:56,代碼來源:BgpExtendedCommunity.java

示例13: read

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
 * Reads from the channel buffer and parses AsPath.
 *
 * @param cb ChannelBuffer
 * @return object of AsPath
 * @throws BgpParseException while parsing AsPath
 */
public static AsPath read(ChannelBuffer cb) throws BgpParseException {
    List<Short> aspathSet = new ArrayList<>();
    List<Short> aspathSeq = new ArrayList<>();
    ChannelBuffer tempCb = cb.copy();
    Validation validation = Validation.parseAttributeHeader(cb);

    if (cb.readableBytes() < validation.getLength()) {
        Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
                validation.getLength());
    }
    //if fourth bit is set, length is read as short otherwise as byte , len includes type, length and value
    int len = validation.isShort() ? validation.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : validation
            .getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
    ChannelBuffer data = tempCb.readBytes(len);
    if (validation.getFirstBit() && !validation.getSecondBit() && validation.getThirdBit()) {
        throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_FLAGS_ERROR, data);
    }

    ChannelBuffer tempBuf = cb.readBytes(validation.getLength());
    while (tempBuf.readableBytes() > 0) {
        byte pathSegType = tempBuf.readByte();
        //no of ASes
        byte pathSegLen = tempBuf.readByte();
        int length = pathSegLen * ASNUM_SIZE;
        if (tempBuf.readableBytes() < length) {
            Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
                    BgpErrorType.ATTRIBUTE_LENGTH_ERROR, length);
        }
        ChannelBuffer aspathBuf = tempBuf.readBytes(length);
        while (aspathBuf.readableBytes() > 0) {
            short asNum;
            asNum = aspathBuf.readShort();
            switch (pathSegType) {
            case ASPATH_SET_TYPE:
                aspathSet.add(asNum);
                break;
            case ASPATH_SEQ_TYPE:
                aspathSeq.add(asNum);
                break;
            default: log.debug("Other type Not Supported:" + pathSegType);
            }
        }
    }
    return new AsPath(aspathSet, aspathSeq);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:53,代碼來源:AsPath.java


注:本文中的org.jboss.netty.buffer.ChannelBuffer.copy方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。