Search in sources :

Example 1 with BgpValueType

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

the class BgpDpid method add.

/**
 * Obtains instance of this class by appending stringBuilder with node descriptor value.
 *
 * @param value node descriptor
 * @return instance of this class
 */
public BgpDpid add(final NodeDescriptors value) {
    log.debug("BgpDpid :: add function");
    if (value != null) {
        List<BgpValueType> subTlvs = value.getSubTlvs();
        ListIterator<BgpValueType> listIterator = subTlvs.listIterator();
        while (listIterator.hasNext()) {
            BgpValueType tlv = listIterator.next();
            if (tlv.getType() == AutonomousSystemTlv.TYPE) {
                this.stringBuilder.append(":ASN=").append(((AutonomousSystemTlv) tlv).getAsNum());
            } else if (tlv.getType() == BgpLSIdentifierTlv.TYPE) {
                this.stringBuilder.append(":DOMAINID=").append(((BgpLSIdentifierTlv) tlv).getBgpLsIdentifier());
            } else if (tlv.getType() == NodeDescriptors.IGP_ROUTERID_TYPE) {
                if (tlv instanceof IsIsNonPseudonode) {
                    this.stringBuilder.append(":ISOID=").append(isoNodeIdString(((IsIsNonPseudonode) tlv).getIsoNodeId()));
                } else if (tlv instanceof IsIsPseudonode) {
                    IsIsPseudonode isisPseudonode = ((IsIsPseudonode) tlv);
                    this.stringBuilder.append(":ISOID=").append(isoNodeIdString(((IsIsPseudonode) tlv).getIsoNodeId()));
                    this.stringBuilder.append(":PSN=").append(isisPseudonode.getPsnIdentifier());
                } else if (tlv instanceof OspfNonPseudonode) {
                    this.stringBuilder.append(":RID=").append(((OspfNonPseudonode) tlv).getrouterID());
                } else if (tlv instanceof OspfPseudonode) {
                    this.stringBuilder.append(":RID=").append(((OspfPseudonode) tlv).getrouterID());
                }
            }
        }
    }
    return this;
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType) IsIsPseudonode(org.onosproject.bgpio.types.IsIsPseudonode) OspfPseudonode(org.onosproject.bgpio.types.OspfPseudonode) BgpLSIdentifierTlv(org.onosproject.bgpio.types.BgpLSIdentifierTlv) OspfNonPseudonode(org.onosproject.bgpio.types.OspfNonPseudonode) IsIsNonPseudonode(org.onosproject.bgpio.types.IsIsNonPseudonode)

Example 2 with BgpValueType

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

the class BgpPrefixLSIdentifier method compareTo.

@Override
public int compareTo(Object o) {
    if (this.equals(o)) {
        return 0;
    }
    int result = this.localNodeDescriptors.compareTo(((BgpPrefixLSIdentifier) o).localNodeDescriptors);
    boolean tlvFound = false;
    if (result != 0) {
        return result;
    } else {
        int countOtherSubTlv = ((BgpPrefixLSIdentifier) o).prefixDescriptor.size();
        int countObjSubTlv = prefixDescriptor.size();
        if (countOtherSubTlv != countObjSubTlv) {
            if (countOtherSubTlv > countObjSubTlv) {
                return 1;
            } else {
                return -1;
            }
        }
        ListIterator<BgpValueType> listIterator = prefixDescriptor.listIterator();
        while (listIterator.hasNext()) {
            BgpValueType tlv1 = listIterator.next();
            for (BgpValueType tlv : ((BgpPrefixLSIdentifier) o).prefixDescriptor) {
                if (tlv.getType() == tlv1.getType()) {
                    result = prefixDescriptor.get(prefixDescriptor.indexOf(tlv1)).compareTo(((BgpPrefixLSIdentifier) o).prefixDescriptor.get(((BgpPrefixLSIdentifier) o).prefixDescriptor.indexOf(tlv)));
                    if (result != 0) {
                        return result;
                    }
                    tlvFound = true;
                    break;
                }
            }
            if (!tlvFound) {
                return 1;
            }
        }
    }
    return 0;
}
Also used : BgpValueType(org.onosproject.bgpio.types.BgpValueType)

Example 3 with BgpValueType

use of org.onosproject.bgpio.types.BgpValueType 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 4 with BgpValueType

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

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

the class NodeDescriptors method equals.

@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (obj instanceof NodeDescriptors) {
        int countObjSubTlv = 0;
        int countOtherSubTlv = 0;
        boolean isCommonSubTlv = true;
        NodeDescriptors other = (NodeDescriptors) obj;
        Iterator<BgpValueType> objListIterator = other.subTlvs.iterator();
        countOtherSubTlv = other.subTlvs.size();
        countObjSubTlv = subTlvs.size();
        if (countObjSubTlv != countOtherSubTlv) {
            return false;
        } else {
            while (objListIterator.hasNext() && isCommonSubTlv) {
                BgpValueType subTlv = objListIterator.next();
                if (subTlvs.contains(subTlv) && other.subTlvs.contains(subTlv)) {
                    isCommonSubTlv = Objects.equals(subTlvs.get(subTlvs.indexOf(subTlv)), other.subTlvs.get(other.subTlvs.indexOf(subTlv)));
                } else {
                    isCommonSubTlv = false;
                }
            }
            return isCommonSubTlv;
        }
    }
    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