Search in sources :

Example 1 with BgpExtendedCommunity

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

the class BgpPathAttributes method write.

/**
 * Write path attributes to channelBuffer.
 *
 * @param cb channelBuffer
 * @return object of BgpPathAttributes
 * @throws BgpParseException while parsing BGP path attributes
 */
public int write(ChannelBuffer cb) throws BgpParseException {
    if (pathAttribute == null) {
        return 0;
    }
    int iLenStartIndex = cb.writerIndex();
    ListIterator<BgpValueType> iterator = pathAttribute.listIterator();
    int pathAttributeIndx = cb.writerIndex();
    cb.writeShort(0);
    while (iterator.hasNext()) {
        BgpValueType attr = iterator.next();
        switch(attr.getType()) {
            case Origin.ORIGIN_TYPE:
                Origin origin = (Origin) attr;
                origin.write(cb);
                break;
            case AsPath.ASPATH_TYPE:
                AsPath asPath = (AsPath) attr;
                asPath.write(cb);
                break;
            case As4Path.AS4PATH_TYPE:
                As4Path as4Path = (As4Path) attr;
                as4Path.write(cb);
                break;
            case NextHop.NEXTHOP_TYPE:
                NextHop nextHop = (NextHop) attr;
                nextHop.write(cb);
                break;
            case Med.MED_TYPE:
                Med med = (Med) attr;
                med.write(cb);
                break;
            case LocalPref.LOCAL_PREF_TYPE:
                LocalPref localPref = (LocalPref) attr;
                localPref.write(cb);
                break;
            case Constants.BGP_EXTENDED_COMMUNITY:
                BgpExtendedCommunity extendedCommunity = (BgpExtendedCommunity) attr;
                extendedCommunity.write(cb);
                break;
            case WideCommunity.TYPE:
                WideCommunity wideCommunity = (WideCommunity) attr;
                wideCommunity.write(cb);
                break;
            case MpReachNlri.MPREACHNLRI_TYPE:
                MpReachNlri mpReach = (MpReachNlri) attr;
                mpReach.write(cb);
                break;
            case MpUnReachNlri.MPUNREACHNLRI_TYPE:
                MpUnReachNlri mpUnReach = (MpUnReachNlri) attr;
                mpUnReach.write(cb);
                break;
            case LINK_STATE_ATTRIBUTE_TYPE:
                LinkStateAttributes linkState = (LinkStateAttributes) attr;
                linkState.write(cb);
                break;
            default:
                return cb.writerIndex() - iLenStartIndex;
        }
    }
    int pathAttrLen = cb.writerIndex() - pathAttributeIndx;
    cb.setShort(pathAttributeIndx, (short) (pathAttrLen - 2));
    return cb.writerIndex() - iLenStartIndex;
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) Origin(org.onosproject.bgpio.types.Origin) MpUnReachNlri(org.onosproject.bgpio.types.MpUnReachNlri) NextHop(org.onosproject.bgpio.types.NextHop) BgpExtendedCommunity(org.onosproject.bgpio.types.BgpExtendedCommunity) Med(org.onosproject.bgpio.types.Med) LinkStateAttributes(org.onosproject.bgpio.types.LinkStateAttributes) AsPath(org.onosproject.bgpio.types.AsPath) As4Path(org.onosproject.bgpio.types.As4Path) LocalPref(org.onosproject.bgpio.types.LocalPref) WideCommunity(org.onosproject.bgpio.types.attr.WideCommunity) MpReachNlri(org.onosproject.bgpio.types.MpReachNlri)

Example 2 with BgpExtendedCommunity

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

the class BgpPeerImpl method sendFlowSpecUpdateMessageToPeer.

/**
 * Send flow specification update message to peer.
 *
 * @param operType operation type
 * @param routeKey flow rule key
 * @param flowSpec flow specification details
 * @param wideCommunity for route policy
 */
public final void sendFlowSpecUpdateMessageToPeer(FlowSpecOperation operType, BgpFlowSpecRouteKey routeKey, BgpFlowSpecNlri flowSpec, WideCommunity wideCommunity) {
    List<BgpValueType> attributesList = new LinkedList<>();
    byte sessionType = sessionInfo.isIbgpSession() ? (byte) 0 : (byte) 1;
    byte sAfi = Constants.SAFI_FLOWSPEC_VALUE;
    boolean isFsCapabilitySet = isCapabilitySupported(MultiProtocolExtnCapabilityTlv.TYPE, Constants.AFI_FLOWSPEC_VALUE, Constants.SAFI_FLOWSPEC_VALUE);
    boolean isVpnFsCapabilitySet = isCapabilitySupported(MultiProtocolExtnCapabilityTlv.TYPE, Constants.AFI_FLOWSPEC_VALUE, Constants.VPN_SAFI_FLOWSPEC_VALUE);
    boolean isRpdCapabilitySet = isCapabilitySupported(RpdCapabilityTlv.TYPE, Constants.AFI_FLOWSPEC_RPD_VALUE, Constants.SAFI_FLOWSPEC_RPD_VALUE);
    boolean isVpnRpdCapabilitySet = isCapabilitySupported(RpdCapabilityTlv.TYPE, Constants.AFI_FLOWSPEC_RPD_VALUE, Constants.VPN_SAFI_FLOWSPEC_RDP_VALUE);
    if ((!isFsCapabilitySet) && (!isVpnFsCapabilitySet) && (!isRpdCapabilitySet) && (!isVpnRpdCapabilitySet)) {
        log.debug("Peer do not support BGP flow spec capability", channel.getRemoteAddress());
        return;
    }
    if (isVpnFsCapabilitySet) {
        sAfi = Constants.VPN_SAFI_FLOWSPEC_VALUE;
    } else if (isVpnRpdCapabilitySet) {
        sAfi = Constants.VPN_SAFI_FLOWSPEC_RDP_VALUE;
    }
    attributesList.add(new Origin((byte) 0));
    if (sessionType != 0) {
        // EBGP
        if (!bgpController.getConfig().getLargeASCapability()) {
            List<Short> aspathSet = new ArrayList<>();
            List<Short> aspathSeq = new ArrayList<>();
            aspathSeq.add((short) bgpController.getConfig().getAsNumber());
            AsPath asPath = new AsPath(aspathSet, aspathSeq);
            attributesList.add(asPath);
        } else {
            List<Integer> aspathSet = new ArrayList<>();
            List<Integer> aspathSeq = new ArrayList<>();
            aspathSeq.add(bgpController.getConfig().getAsNumber());
            As4Path as4Path = new As4Path(aspathSet, aspathSeq);
            attributesList.add(as4Path);
        }
        attributesList.add(new Med(0));
    } else {
        attributesList.add(new AsPath());
        attributesList.add(new Med(0));
        attributesList.add(new LocalPref(100));
    }
    attributesList.add(new BgpExtendedCommunity(flowSpec.fsActionTlv()));
    if (wideCommunity != null) {
        attributesList.add(wideCommunity);
    }
    if (operType == FlowSpecOperation.ADD) {
        attributesList.add(new MpReachNlri(flowSpec, Constants.AFI_FLOWSPEC_VALUE, sAfi));
    } else if (operType == FlowSpecOperation.DELETE) {
        attributesList.add(new MpUnReachNlri(flowSpec, Constants.AFI_FLOWSPEC_VALUE, sAfi));
    }
    BgpMessage msg = Controller.getBgpMessageFactory4().updateMessageBuilder().setBgpPathAttributes(attributesList).build();
    log.debug("Sending flow spec update message to {}", channel.getRemoteAddress());
    channel.write(Collections.singletonList(msg));
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) Origin(org.onosproject.bgpio.types.Origin) MpUnReachNlri(org.onosproject.bgpio.types.MpUnReachNlri) BgpMessage(org.onosproject.bgpio.protocol.BgpMessage) BgpExtendedCommunity(org.onosproject.bgpio.types.BgpExtendedCommunity) ArrayList(java.util.ArrayList) Med(org.onosproject.bgpio.types.Med) LinkedList(java.util.LinkedList) AsPath(org.onosproject.bgpio.types.AsPath) As4Path(org.onosproject.bgpio.types.As4Path) LocalPref(org.onosproject.bgpio.types.LocalPref) MpReachNlri(org.onosproject.bgpio.types.MpReachNlri)

Example 3 with BgpExtendedCommunity

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

the class BgpPeerImpl method sendEvpnUpdateMessageToPeer.

private void sendEvpnUpdateMessageToPeer(FlowSpecOperation operType, IpAddress nextHop, List<BgpValueType> extcommunity, List<BgpEvpnNlri> evpnNlris) {
    List<BgpValueType> attributesList = new LinkedList<>();
    byte sessionType = sessionInfo.isIbgpSession() ? (byte) 0 : (byte) 1;
    short afi = Constants.AFI_EVPN_VALUE;
    byte safi = Constants.SAFI_EVPN_VALUE;
    boolean isEvpnCapabilitySet = isCapabilitySupported(MultiProtocolExtnCapabilityTlv.TYPE, afi, safi);
    if (!isEvpnCapabilitySet) {
        log.debug("Peer do not support BGP Evpn capability", channel.getRemoteAddress());
        return;
    }
    attributesList.add(new Origin((byte) 0));
    if (sessionType != 0) {
        // EBGP
        if (!bgpController.getConfig().getLargeASCapability()) {
            List<Short> aspathSet = new ArrayList<>();
            List<Short> aspathSeq = new ArrayList<>();
            aspathSeq.add((short) bgpController.getConfig().getAsNumber());
            AsPath asPath = new AsPath(aspathSet, aspathSeq);
            attributesList.add(asPath);
        } else {
            List<Integer> aspathSet = new ArrayList<>();
            List<Integer> aspathSeq = new ArrayList<>();
            aspathSeq.add(bgpController.getConfig().getAsNumber());
            As4Path as4Path = new As4Path(aspathSet, aspathSeq);
            attributesList.add(as4Path);
        }
    } else {
        attributesList.add(new AsPath());
    }
    if (!extcommunity.isEmpty()) {
        attributesList.add(new BgpExtendedCommunity(extcommunity));
    }
    if (operType == FlowSpecOperation.ADD || operType == FlowSpecOperation.UPDATE) {
        attributesList.add(new MpReachNlri(evpnNlris, afi, safi, nextHop.getIp4Address()));
    } else if (operType == FlowSpecOperation.DELETE) {
        attributesList.add(new MpUnReachNlri(evpnNlris, afi, safi));
    }
    BgpMessage msg = Controller.getBgpMessageFactory4().updateMessageBuilder().setBgpPathAttributes(attributesList).build();
    channel.write(Collections.singletonList(msg));
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) Origin(org.onosproject.bgpio.types.Origin) MpUnReachNlri(org.onosproject.bgpio.types.MpUnReachNlri) BgpMessage(org.onosproject.bgpio.protocol.BgpMessage) BgpExtendedCommunity(org.onosproject.bgpio.types.BgpExtendedCommunity) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) AsPath(org.onosproject.bgpio.types.AsPath) As4Path(org.onosproject.bgpio.types.As4Path) MpReachNlri(org.onosproject.bgpio.types.MpReachNlri)

Aggregations

As4Path (org.onosproject.bgpio.types.As4Path)3 AsPath (org.onosproject.bgpio.types.AsPath)3 BgpExtendedCommunity (org.onosproject.bgpio.types.BgpExtendedCommunity)3 BgpValueType (org.onosproject.bgpio.types.BgpValueType)3 MpReachNlri (org.onosproject.bgpio.types.MpReachNlri)3 MpUnReachNlri (org.onosproject.bgpio.types.MpUnReachNlri)3 Origin (org.onosproject.bgpio.types.Origin)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 BgpMessage (org.onosproject.bgpio.protocol.BgpMessage)2 LocalPref (org.onosproject.bgpio.types.LocalPref)2 Med (org.onosproject.bgpio.types.Med)2 LinkStateAttributes (org.onosproject.bgpio.types.LinkStateAttributes)1 NextHop (org.onosproject.bgpio.types.NextHop)1 WideCommunity (org.onosproject.bgpio.types.attr.WideCommunity)1