Search in sources :

Example 56 with BgpValueType

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

the class BgpLinkLSIdentifier method equals.

@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (obj instanceof BgpLinkLSIdentifier) {
        int countObjSubTlv = 0;
        int countOtherSubTlv = 0;
        boolean isCommonSubTlv = true;
        BgpLinkLSIdentifier other = (BgpLinkLSIdentifier) obj;
        Iterator<BgpValueType> objListIterator = other.linkDescriptor.iterator();
        countOtherSubTlv = other.linkDescriptor.size();
        countObjSubTlv = linkDescriptor.size();
        if (countObjSubTlv != countOtherSubTlv) {
            return false;
        } else {
            while (objListIterator.hasNext() && isCommonSubTlv) {
                BgpValueType subTlv = objListIterator.next();
                if (linkDescriptor.contains(subTlv) && other.linkDescriptor.contains(subTlv)) {
                    isCommonSubTlv = Objects.equals(linkDescriptor.get(linkDescriptor.indexOf(subTlv)), other.linkDescriptor.get(other.linkDescriptor.indexOf(subTlv)));
                } else {
                    isCommonSubTlv = false;
                }
            }
            return isCommonSubTlv && Objects.equals(this.localNodeDescriptors, other.localNodeDescriptors) && Objects.equals(this.remoteNodeDescriptors, other.remoteNodeDescriptors);
        }
    }
    return false;
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType)

Example 57 with BgpValueType

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

the class BgpPrefixLSIdentifier method equals.

@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (obj instanceof BgpPrefixLSIdentifier) {
        int countObjSubTlv = 0;
        int countOtherSubTlv = 0;
        boolean isCommonSubTlv = true;
        BgpPrefixLSIdentifier other = (BgpPrefixLSIdentifier) obj;
        Iterator<BgpValueType> objListIterator = other.prefixDescriptor.iterator();
        countOtherSubTlv = other.prefixDescriptor.size();
        countObjSubTlv = prefixDescriptor.size();
        if (countObjSubTlv != countOtherSubTlv) {
            return false;
        } else {
            while (objListIterator.hasNext() && isCommonSubTlv) {
                BgpValueType subTlv = objListIterator.next();
                if (prefixDescriptor.contains(subTlv) && other.prefixDescriptor.contains(subTlv)) {
                    isCommonSubTlv = Objects.equals(prefixDescriptor.get(prefixDescriptor.indexOf(subTlv)), other.prefixDescriptor.get(other.prefixDescriptor.indexOf(subTlv)));
                } else {
                    isCommonSubTlv = false;
                }
            }
            return isCommonSubTlv && Objects.equals(this.localNodeDescriptors, other.localNodeDescriptors);
        }
    }
    return false;
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType)

Example 58 with BgpValueType

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

the class BgpPrefixLSIdentifier method parsePrefixDescriptors.

/**
 * 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, length);
                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;
}
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 59 with BgpValueType

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

the class NodeDescriptors method compareTo.

/**
 * Compares this and o object.
 *
 * @param o object to be compared with this object
 * @return which object is greater
 */
public int compareTo(Object o) {
    if (this.equals(o)) {
        return 0;
    }
    ListIterator<BgpValueType> listIterator = subTlvs.listIterator();
    int countOtherSubTlv = ((NodeDescriptors) o).subTlvs.size();
    int countObjSubTlv = subTlvs.size();
    boolean tlvFound = false;
    if (countOtherSubTlv != countObjSubTlv) {
        if (countOtherSubTlv > countObjSubTlv) {
            return 1;
        } else {
            return -1;
        }
    } else {
        while (listIterator.hasNext()) {
            BgpValueType tlv1 = listIterator.next();
            log.debug("NodeDescriptor compare subtlv's");
            for (BgpValueType tlv : ((NodeDescriptors) o).subTlvs) {
                if (tlv.getType() == tlv1.getType()) {
                    if (tlv.getType() == IGP_ROUTERID_TYPE) {
                        if ((tlv1 instanceof IsIsNonPseudonode && tlv instanceof IsIsPseudonode) || (tlv1 instanceof IsIsPseudonode && tlv instanceof IsIsNonPseudonode) || (tlv1 instanceof OspfNonPseudonode && tlv instanceof OspfPseudonode) || (tlv1 instanceof OspfPseudonode && tlv instanceof OspfNonPseudonode)) {
                            continue;
                        }
                    }
                    int result = subTlvs.get(subTlvs.indexOf(tlv1)).compareTo(((NodeDescriptors) o).subTlvs.get(((NodeDescriptors) o).subTlvs.indexOf(tlv)));
                    if (result != 0) {
                        return result;
                    }
                    tlvFound = true;
                    break;
                }
            }
            if (!tlvFound) {
                return 1;
            }
        }
    }
    return 0;
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) IsIsPseudonode(org.onosproject.bgpio.types.IsIsPseudonode) OspfPseudonode(org.onosproject.bgpio.types.OspfPseudonode) OspfNonPseudonode(org.onosproject.bgpio.types.OspfNonPseudonode) IsIsNonPseudonode(org.onosproject.bgpio.types.IsIsNonPseudonode)

Example 60 with BgpValueType

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

the class PathAttrNlriDetails method equals.

@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (obj instanceof PathAttrNlriDetails) {
        int countObjSubTlv = 0;
        int countOtherSubTlv = 0;
        boolean isCommonSubTlv = true;
        PathAttrNlriDetails other = (PathAttrNlriDetails) obj;
        Iterator<BgpValueType> objListIterator = other.pathAttributes.iterator();
        countOtherSubTlv = other.pathAttributes.size();
        countObjSubTlv = pathAttributes.size();
        if (countObjSubTlv != countOtherSubTlv) {
            return false;
        } else {
            while (objListIterator.hasNext() && isCommonSubTlv) {
                BgpValueType subTlv = objListIterator.next();
                if (pathAttributes.contains(subTlv) && other.pathAttributes.contains(subTlv)) {
                    isCommonSubTlv = Objects.equals(pathAttributes.get(pathAttributes.indexOf(subTlv)), other.pathAttributes.get(other.pathAttributes.indexOf(subTlv)));
                } else {
                    isCommonSubTlv = false;
                }
            }
            return isCommonSubTlv && Objects.equals(identifier, other.identifier) && Objects.equals(protocolID, other.protocolID);
        }
    }
    return false;
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType)

Aggregations

BgpValueType (org.onosproject.bgpio.types.BgpValueType)83 Test (org.junit.Test)57 LinkedList (java.util.LinkedList)52 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)50 BgpHeader (org.onosproject.bgpio.types.BgpHeader)33 MpReachNlri (org.onosproject.bgpio.types.MpReachNlri)31 AsPath (org.onosproject.bgpio.types.AsPath)29 Origin (org.onosproject.bgpio.types.Origin)29 Med (org.onosproject.bgpio.types.Med)27 BgpPathAttributes (org.onosproject.bgpio.protocol.ver4.BgpPathAttributes)26 OriginType (org.onosproject.bgpio.types.Origin.OriginType)26 ProtocolType (org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType)24 LinkStateAttributes (org.onosproject.bgpio.types.LinkStateAttributes)24 IpPrefix (org.onlab.packet.IpPrefix)21 MultiProtocolExtnCapabilityTlv (org.onosproject.bgpio.types.MultiProtocolExtnCapabilityTlv)16 NodeDescriptors (org.onosproject.bgpio.protocol.linkstate.NodeDescriptors)13 Ip4Address (org.onlab.packet.Ip4Address)12 PathAttrNlriDetails (org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails)11 PathAttrNlriDetailsLocalRib (org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetailsLocalRib)11 IpAddress (org.onlab.packet.IpAddress)10