Java Code Examples for org.onlab.packet.IpPrefix#isIp6()

The following examples show how to use org.onlab.packet.IpPrefix#isIp6() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IpConcurrentRadixTree.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public V put(IpPrefix prefix, V value) {

    String prefixString = getPrefixString(prefix);

    if (prefix.isIp4()) {
        return ipv4Tree.put(prefixString, value);
    }
    if (prefix.isIp6()) {
        return ipv6Tree.put(prefixString, value);
    }

    return null;
}
 
Example 2
Source File: IpConcurrentRadixTree.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public V putIfAbsent(IpPrefix prefix, V value) {

    String prefixString = getPrefixString(prefix);

    if (prefix.isIp4()) {
        return ipv4Tree.put(prefixString, value);
    }

    if (prefix.isIp6()) {
        return ipv6Tree.put(prefixString, value);
    }

    return null;
}
 
Example 3
Source File: IpConcurrentRadixTree.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public boolean remove(IpPrefix prefix) {

    String prefixString = getPrefixString(prefix);

    if (prefix.isIp4()) {
        return ipv4Tree.remove(prefixString);
    }

    if (prefix.isIp6()) {
        return ipv6Tree.remove(prefixString);
    }

    return false;
}
 
Example 4
Source File: IpConcurrentRadixTree.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public V getValueForExactAddress(IpPrefix prefix) {

    String prefixString = getPrefixString(prefix);

    if (prefix.isIp4()) {
        return ipv4Tree.getValueForExactKey(prefixString);
    }

    if (prefix.isIp6()) {
        return ipv6Tree.getValueForExactKey(prefixString);
    }

    return null;
}
 
Example 5
Source File: IpConcurrentRadixTree.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public V getValueForClosestParentAddress(IpPrefix prefix) {

    if (prefix.isIp4()) {
        return getValueForClosestParentAddress(prefix, ipv4Tree);
    }

    if (prefix.isIp6()) {
        return getValueForClosestParentAddress(prefix, ipv6Tree);
    }

    return null;
}
 
Example 6
Source File: IpConcurrentRadixTree.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public List<V> getValuesForAddressesStartingWith(IpPrefix prefix) {

    String prefixString = getPrefixString(prefix);

    if (prefix.isIp4()) {
        return Lists.newArrayList(ipv4Tree.getValuesForKeysStartingWith(prefixString));
    }

    if (prefix.isIp6()) {
        return Lists.newArrayList(ipv6Tree.getValuesForKeysStartingWith(prefixString));
    }

    return null;
}
 
Example 7
Source File: LispMapUtil.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains the EID record from an IP prefix.
 *
 * @param prefix IP prefix
 * @return EID record
 */
public static LispEidRecord getEidRecordFromIpPrefix(IpPrefix prefix) {

    LispIpAddress eid = null;

    if (prefix.isIp4()) {
        eid = new LispIpv4Address(prefix.address());
    }

    if (prefix.isIp6()) {
        eid = new LispIpv6Address(prefix.address());
    }

    return new LispEidRecord((byte) prefix.prefixLength(), eid);
}
 
Example 8
Source File: LispMapUtil.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains the string formatted IP prefix.
 * For example, if the IP address is 10.1.1.1 and has 16 prefix length,
 * the resulting string is 10.1
 *
 * @param prefix IP prefix
 * @return string formatted IP prefix
 */
public static String getPrefixString(IpPrefix prefix) {
    String addressString = prefix.address().toString();
    StringBuilder sb = new StringBuilder();
    String delimiter = "";
    int numOfBlock = 0;

    if (prefix.isIp4()) {
        delimiter = IPV4_DELIMITER;
        numOfBlock = prefix.prefixLength() / IPV4_BLOCK_LENGTH;
    }

    if (prefix.isIp6()) {
        delimiter = IPV6_DELIMITER;
        numOfBlock = prefix.prefixLength() / IPV6_BLOCK_LENGTH;
    }

    String[] octets = StringUtils.split(addressString, delimiter);

    for (int i = 0; i < numOfBlock; i++) {
        sb.append(octets[i]);

        if (i < numOfBlock - 1) {
            sb.append(delimiter);
        }
    }

    return sb.toString();
}