Search in sources :

Example 1 with RpdCapabilityTlv

use of org.onosproject.bgpio.types.RpdCapabilityTlv in project onos by opennetworkinglab.

the class BgpChannelHandler method capabilityValidation.

/**
 * Capability Validation.
 *
 * @param h channel handler
 * @param openmsg open message
 * @return success or failure
 * @throws BgpParseException
 */
private boolean capabilityValidation(BgpChannelHandler h, BgpOpenMsg openmsg) throws BgpParseException {
    log.debug("capability validation");
    boolean isFourOctetCapabilityExits = false;
    boolean isRpdCapabilityExits = false;
    int capAsNum = 0;
    byte sendReceive = 0;
    List<BgpValueType> capabilityTlv = openmsg.getCapabilityTlv();
    ListIterator<BgpValueType> listIterator = capabilityTlv.listIterator();
    List<BgpValueType> unSupportedCapabilityTlv = new CopyOnWriteArrayList<BgpValueType>();
    ListIterator<BgpValueType> unSupportedCaplistIterator = unSupportedCapabilityTlv.listIterator();
    BgpValueType tempTlv;
    boolean isLargeAsCapabilityCfg = h.bgpconfig.getLargeASCapability();
    boolean isFlowSpecRpdCapabilityCfg = h.bgpconfig.flowSpecRpdCapability();
    boolean isLsCapabilityCfg = h.bgpconfig.getLsCapability();
    boolean isFlowSpecIpv4CapabilityCfg = false;
    boolean isFlowSpecVpnv4CapabilityCfg = false;
    MultiProtocolExtnCapabilityTlv tempCapability;
    boolean isMultiProtocolLsCapability = false;
    boolean isMultiProtocolFlowSpecCapability = false;
    boolean isMultiProtocolVpnFlowSpecCapability = false;
    BgpCfg.FlowSpec flowSpec = h.bgpconfig.flowSpecCapability();
    boolean isEvpnCapability = false;
    boolean isEvpnCapabilityCfg = h.bgpconfig.getEvpnCapability();
    if (flowSpec == BgpCfg.FlowSpec.IPV4) {
        isFlowSpecIpv4CapabilityCfg = true;
    } else if (flowSpec == BgpCfg.FlowSpec.VPNV4) {
        isFlowSpecVpnv4CapabilityCfg = true;
    } else if (flowSpec == BgpCfg.FlowSpec.IPV4_VPNV4) {
        isFlowSpecIpv4CapabilityCfg = true;
        isFlowSpecVpnv4CapabilityCfg = true;
    }
    while (listIterator.hasNext()) {
        BgpValueType tlv = listIterator.next();
        if (tlv.getType() == MULTI_PROTOCOL_EXTN_CAPA_TYPE) {
            tempCapability = (MultiProtocolExtnCapabilityTlv) tlv;
            if (Constants.SAFI_FLOWSPEC_VALUE == tempCapability.getSafi()) {
                isMultiProtocolFlowSpecCapability = true;
            }
            if (Constants.SAFI_EVPN_VALUE == tempCapability.getSafi()) {
                isEvpnCapability = true;
            }
            if (Constants.VPN_SAFI_FLOWSPEC_VALUE == tempCapability.getSafi()) {
                isMultiProtocolVpnFlowSpecCapability = true;
            }
            if (SAFI == tempCapability.getSafi()) {
                isMultiProtocolLsCapability = true;
            }
        }
        if (tlv.getType() == FOUR_OCTET_AS_NUM_CAPA_TYPE) {
            isFourOctetCapabilityExits = true;
            capAsNum = ((FourOctetAsNumCapabilityTlv) tlv).getInt();
        }
        if (tlv.getType() == RpdCapabilityTlv.TYPE) {
            isRpdCapabilityExits = true;
            sendReceive = ((RpdCapabilityTlv) tlv).sendReceive();
        }
    }
    if (isFourOctetCapabilityExits) {
        if (capAsNum > MAX_AS2_NUM) {
            if (openmsg.getAsNumber() != AS_TRANS) {
                throw new BgpParseException(BgpErrorType.OPEN_MESSAGE_ERROR, BgpErrorType.BAD_PEER_AS, null);
            }
        } else {
            if (capAsNum != openmsg.getAsNumber()) {
                throw new BgpParseException(BgpErrorType.OPEN_MESSAGE_ERROR, BgpErrorType.BAD_PEER_AS, null);
            }
        }
    }
    if (isRpdCapabilityExits) {
        if (sendReceive > 2) {
            throw new BgpParseException(BgpErrorType.OPEN_MESSAGE_ERROR, BgpErrorType.UNSUPPORTED_CAPABILITY, null);
        }
    }
    if ((isLsCapabilityCfg)) {
        if (!isMultiProtocolLsCapability) {
            tempTlv = new MultiProtocolExtnCapabilityTlv(AFI, RES, SAFI);
            unSupportedCapabilityTlv.add(tempTlv);
        }
    }
    if (isFlowSpecIpv4CapabilityCfg) {
        if (!isMultiProtocolFlowSpecCapability) {
            tempTlv = new MultiProtocolExtnCapabilityTlv(Constants.AFI_FLOWSPEC_VALUE, RES, Constants.SAFI_FLOWSPEC_VALUE);
            unSupportedCapabilityTlv.add(tempTlv);
        }
    }
    if (isEvpnCapabilityCfg) {
        if (!isEvpnCapability) {
            tempTlv = new MultiProtocolExtnCapabilityTlv(Constants.AFI_EVPN_VALUE, RES, Constants.SAFI_EVPN_VALUE);
            unSupportedCapabilityTlv.add(tempTlv);
        }
    }
    if (isFlowSpecVpnv4CapabilityCfg) {
        if (!isMultiProtocolVpnFlowSpecCapability) {
            tempTlv = new MultiProtocolExtnCapabilityTlv(Constants.AFI_FLOWSPEC_VALUE, RES, Constants.VPN_SAFI_FLOWSPEC_VALUE);
            unSupportedCapabilityTlv.add(tempTlv);
        }
    }
    if ((isLargeAsCapabilityCfg)) {
        if (!isFourOctetCapabilityExits) {
            tempTlv = new FourOctetAsNumCapabilityTlv(h.bgpconfig.getAsNumber());
            unSupportedCapabilityTlv.add(tempTlv);
        }
    }
    if ((isFlowSpecRpdCapabilityCfg)) {
        if (!isRpdCapabilityExits) {
            tempTlv = new RpdCapabilityTlv(Constants.RPD_CAPABILITY_SEND_VALUE);
            unSupportedCapabilityTlv.add(tempTlv);
        }
    }
    if (unSupportedCapabilityTlv.size() == MAX_UNSUPPORTED_CAPABILITY) {
        ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
        while (unSupportedCaplistIterator.hasNext()) {
            BgpValueType tlv = unSupportedCaplistIterator.next();
            tlv.write(buffer);
        }
        throw new BgpParseException(BgpErrorType.OPEN_MESSAGE_ERROR, BgpErrorType.UNSUPPORTED_CAPABILITY, buffer);
    } else {
        return true;
    }
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) MultiProtocolExtnCapabilityTlv(org.onosproject.bgpio.types.MultiProtocolExtnCapabilityTlv) BgpCfg(org.onosproject.bgp.controller.BgpCfg) BgpParseException(org.onosproject.bgpio.exceptions.BgpParseException) RpdCapabilityTlv(org.onosproject.bgpio.types.RpdCapabilityTlv) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) FourOctetAsNumCapabilityTlv(org.onosproject.bgpio.types.FourOctetAsNumCapabilityTlv) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 2 with RpdCapabilityTlv

use of org.onosproject.bgpio.types.RpdCapabilityTlv in project onos by opennetworkinglab.

the class BgpPeerImpl method isCapabilitySupported.

/**
 * Check if peer support capability.
 *
 * @param type capability type
 * @param afi address family identifier
 * @param sAfi subsequent address family identifier
 * @return true if capability is supported, otherwise false
 */
public final boolean isCapabilitySupported(short type, short afi, byte sAfi) {
    List<BgpValueType> capability = sessionInfo.remoteBgpCapability();
    ListIterator<BgpValueType> listIterator = capability.listIterator();
    while (listIterator.hasNext()) {
        BgpValueType tlv = listIterator.next();
        if (tlv.getType() == type) {
            if (tlv.getType() == MultiProtocolExtnCapabilityTlv.TYPE) {
                MultiProtocolExtnCapabilityTlv temp = (MultiProtocolExtnCapabilityTlv) tlv;
                if ((temp.getAfi() == afi) && (temp.getSafi() == sAfi)) {
                    log.debug("Multi prorotcol extension capabality TLV is true");
                    return true;
                }
            } else if (tlv.getType() == RpdCapabilityTlv.TYPE) {
                RpdCapabilityTlv temp = (RpdCapabilityTlv) tlv;
                if ((temp.getAfi() == afi) && (temp.getSafi() == sAfi)) {
                    log.debug("RPD capabality TLV is true");
                    return true;
                }
            }
        }
    }
    log.debug("IS capabality is not supported ");
    return false;
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) MultiProtocolExtnCapabilityTlv(org.onosproject.bgpio.types.MultiProtocolExtnCapabilityTlv) RpdCapabilityTlv(org.onosproject.bgpio.types.RpdCapabilityTlv)

Example 3 with RpdCapabilityTlv

use of org.onosproject.bgpio.types.RpdCapabilityTlv 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)

Aggregations

BgpValueType (org.onosproject.bgpio.types.BgpValueType)3 MultiProtocolExtnCapabilityTlv (org.onosproject.bgpio.types.MultiProtocolExtnCapabilityTlv)3 RpdCapabilityTlv (org.onosproject.bgpio.types.RpdCapabilityTlv)3 BgpParseException (org.onosproject.bgpio.exceptions.BgpParseException)2 FourOctetAsNumCapabilityTlv (org.onosproject.bgpio.types.FourOctetAsNumCapabilityTlv)2 LinkedList (java.util.LinkedList)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)1 BgpCfg (org.onosproject.bgp.controller.BgpCfg)1 RouteRefreshCapabilityTlv (org.onosproject.bgpio.types.RouteRefreshCapabilityTlv)1