Search in sources :

Example 16 with BgpParseException

use of org.onosproject.bgpio.exceptions.BgpParseException in project onos by opennetworkinglab.

the class BgpPrefixLSIdentifier method parseLocalNodeDescriptors.

/**
 * 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;
}
Also used : BgpParseException(org.onosproject.bgpio.exceptions.BgpParseException) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 17 with BgpParseException

use of org.onosproject.bgpio.exceptions.BgpParseException in project onos by opennetworkinglab.

the class BgpLinkLSIdentifier method parseNodeDescriptors.

/**
 * 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;
}
Also used : BgpParseException(org.onosproject.bgpio.exceptions.BgpParseException) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 18 with BgpParseException

use of org.onosproject.bgpio.exceptions.BgpParseException in project onos by opennetworkinglab.

the class BgpOpenMsgVer4 method parseCapabilityTlv.

/**
 * Parsing capabilities.
 *
 * @param cb of type channel buffer
 * @return capabilityTlv of open message
 * @throws BgpParseException while parsing capabilities
 */
protected static LinkedList<BgpValueType> parseCapabilityTlv(ChannelBuffer cb) throws BgpParseException {
    LinkedList<BgpValueType> capabilityTlv = new LinkedList<>();
    while (cb.readableBytes() > 0) {
        BgpValueType tlv;
        short type = cb.readByte();
        short length = cb.readByte();
        switch(type) {
            case FourOctetAsNumCapabilityTlv.TYPE:
                log.debug("FourOctetAsNumCapabilityTlv");
                if (FourOctetAsNumCapabilityTlv.LENGTH != length) {
                    throw new BgpParseException("Invalid length received for FourOctetAsNumCapabilityTlv.");
                }
                if (length > cb.readableBytes()) {
                    throw new BgpParseException("Four octet as num tlv length" + " is more than readableBytes.");
                }
                int as4Num = cb.readInt();
                tlv = new FourOctetAsNumCapabilityTlv(as4Num);
                break;
            case RpdCapabilityTlv.TYPE:
                log.debug("RpdCapability");
                if (RpdCapabilityTlv.LENGTH != length) {
                    throw new BgpParseException("Invalid length received for RpdCapability.");
                }
                if (length > cb.readableBytes()) {
                    throw new BgpParseException("Four octet as num TLV length" + " is more than readableBytes.");
                }
                short rpdAfi = cb.readShort();
                byte rpdAsafi = cb.readByte();
                byte sendReceive = cb.readByte();
                tlv = new RpdCapabilityTlv(sendReceive);
                break;
            case MultiProtocolExtnCapabilityTlv.TYPE:
                log.debug("MultiProtocolExtnCapabilityTlv");
                if (MultiProtocolExtnCapabilityTlv.LENGTH != length) {
                    throw new BgpParseException("Invalid length received for MultiProtocolExtnCapabilityTlv.");
                }
                if (length > cb.readableBytes()) {
                    throw new BgpParseException("BGP LS tlv length is more than readableBytes.");
                }
                short afi = cb.readShort();
                byte res = cb.readByte();
                byte safi = cb.readByte();
                tlv = new MultiProtocolExtnCapabilityTlv(afi, res, safi);
                break;
            case RouteRefreshCapabilityTlv.TYPE:
                log.debug("RouteRefreshCapabilityTlv");
                if (RouteRefreshCapabilityTlv.LENGTH != length) {
                    throw new BgpParseException("Invalid length received for RouteRefreshCapabilityTlv.");
                }
                tlv = new RouteRefreshCapabilityTlv(true);
                break;
            default:
                log.debug("Warning: Unsupported TLV: " + type);
                cb.skipBytes(length);
                continue;
        }
        capabilityTlv.add(tlv);
    }
    return capabilityTlv;
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) RouteRefreshCapabilityTlv(org.onosproject.bgpio.types.RouteRefreshCapabilityTlv) MultiProtocolExtnCapabilityTlv(org.onosproject.bgpio.types.MultiProtocolExtnCapabilityTlv) BgpParseException(org.onosproject.bgpio.exceptions.BgpParseException) FourOctetAsNumCapabilityTlv(org.onosproject.bgpio.types.FourOctetAsNumCapabilityTlv) RpdCapabilityTlv(org.onosproject.bgpio.types.RpdCapabilityTlv) LinkedList(java.util.LinkedList)

Example 19 with BgpParseException

use of org.onosproject.bgpio.exceptions.BgpParseException in project onos by opennetworkinglab.

the class AsPath method read.

/**
 * 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);
}
Also used : Validation(org.onosproject.bgpio.util.Validation) BgpParseException(org.onosproject.bgpio.exceptions.BgpParseException) ArrayList(java.util.ArrayList) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 20 with BgpParseException

use of org.onosproject.bgpio.exceptions.BgpParseException in project onos by opennetworkinglab.

the class IPv6AddressTlv method read.

/**
 * Reads the channel buffer and returns object of IPv6AddressTlv.
 *
 * @param cb channelBuffer
 * @param type address type
 * @return object of IPv6AddressTlv
 * @throws BgpParseException while parsing IPv6AddressTlv
 */
public static IPv6AddressTlv read(ChannelBuffer cb, short type) throws BgpParseException {
    InetAddress ipAddress = Validation.toInetAddress(LENGTH, cb);
    if (ipAddress.isMulticastAddress()) {
        throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, (byte) 0, null);
    }
    Ip6Address address = Ip6Address.valueOf(ipAddress);
    return IPv6AddressTlv.of(address, type);
}
Also used : Ip6Address(org.onlab.packet.Ip6Address) BgpParseException(org.onosproject.bgpio.exceptions.BgpParseException) InetAddress(java.net.InetAddress)

Aggregations

BgpParseException (org.onosproject.bgpio.exceptions.BgpParseException)24 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)21 Validation (org.onosproject.bgpio.util.Validation)10 LinkedList (java.util.LinkedList)7 BgpValueType (org.onosproject.bgpio.types.BgpValueType)5 InetAddress (java.net.InetAddress)4 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Ip4Address (org.onlab.packet.Ip4Address)2 BgpEvpnNlri (org.onosproject.bgpio.protocol.BgpEvpnNlri)2 BgpLSNlri (org.onosproject.bgpio.protocol.BgpLSNlri)2 BgpFlowSpecNlri (org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecNlri)2 FourOctetAsNumCapabilityTlv (org.onosproject.bgpio.types.FourOctetAsNumCapabilityTlv)2 MultiProtocolExtnCapabilityTlv (org.onosproject.bgpio.types.MultiProtocolExtnCapabilityTlv)2 RpdCapabilityTlv (org.onosproject.bgpio.types.RpdCapabilityTlv)2 IOException (java.io.IOException)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 Ip6Address (org.onlab.packet.Ip6Address)1