Search in sources :

Example 1 with BgpParseException

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

the class BgpLinkLSIdentifier method parseLinkDescriptors.

/**
 * 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, length);
                count++;
                log.debug("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;
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) BgpParseException(org.onosproject.bgpio.exceptions.BgpParseException) LinkedList(java.util.LinkedList) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 2 with BgpParseException

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

the class BgpNodeLSIdentifier method parseLocalNodeDescriptors.

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

Example 3 with BgpParseException

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

the class As4Path method read.

/**
 * 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);
}
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 4 with BgpParseException

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

the class NodeDescriptors method read.

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

Example 5 with BgpParseException

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

the class BgpExtendedCommunity method read.

/**
 * 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_ROUTE_TARGET_AS:
                case Constants.BGP_ROUTE_TARGET_IP:
                case Constants.BGP_ROUTE_TARGET_LARGEAS:
                    fsActionTlv = RouteTarget.read(actionType, actionBuf);
                    break;
                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);
}
Also used : Validation(org.onosproject.bgpio.util.Validation) BgpParseException(org.onosproject.bgpio.exceptions.BgpParseException) LinkedList(java.util.LinkedList) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

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