Search in sources :

Example 6 with IPAddressString

use of inet.ipaddr.IPAddressString in project onos by opennetworkinglab.

the class KubevirtIpPool method getRangedIps.

/**
 * Obtains the IP address list from the given start and end range.
 *
 * @param start start range
 * @param end   end range
 * @return IP address list from the given start and end range
 * @throws AddressStringException exception
 */
public Set<IpAddress> getRangedIps(String start, String end) throws AddressStringException {
    Set<IpAddress> ips = new HashSet<>();
    IPAddress lower = new IPAddressString(start).toAddress();
    IPAddress upper = new IPAddressString(end).toAddress();
    IPAddressSeqRange range = lower.toSequentialRange(upper);
    for (IPAddress addr : range.getIterable()) {
        ips.add(IpAddress.valueOf(addr.toString()));
    }
    return ips;
}
Also used : IPAddressSeqRange(inet.ipaddr.IPAddressSeqRange) IpAddress(org.onlab.packet.IpAddress) IPAddress(inet.ipaddr.IPAddress) HashSet(java.util.HashSet) IPAddressString(inet.ipaddr.IPAddressString)

Example 7 with IPAddressString

use of inet.ipaddr.IPAddressString in project so by onap.

the class HeatBridgeImpl method updateLInterfaceIps.

protected void updateLInterfaceIps(final Port port, final LInterface lIf) {
    for (IP ip : port.getFixedIps()) {
        String ipAddress = ip.getIpAddress();
        if (InetAddressValidator.getInstance().isValidInet4Address(ipAddress)) {
            Subnet subnet = osClient.getSubnetById(ip.getSubnetId());
            IPAddressString cidr = new IPAddressString(subnet.getCidr());
            L3InterfaceIpv4AddressList lInterfaceIp = new L3InterfaceIpv4AddressList();
            lInterfaceIp.setIsFloating(false);
            lInterfaceIp.setL3InterfaceIpv4Address(ipAddress);
            lInterfaceIp.setNeutronNetworkId(port.getNetworkId());
            lInterfaceIp.setNeutronSubnetId(ip.getSubnetId());
            lInterfaceIp.setL3InterfaceIpv4PrefixLength(Long.parseLong(cidr.getNetworkPrefixLength().toString()));
            transaction.createIfNotExists(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(cloudOwner, cloudRegionId).tenant(tenantId).vserver(port.getDeviceId()).lInterface(lIf.getInterfaceName()).l3InterfaceIpv4AddressList(ipAddress)), Optional.of(lInterfaceIp));
        } else if (InetAddressValidator.getInstance().isValidInet6Address(ipAddress)) {
            Subnet subnet = osClient.getSubnetById(ip.getSubnetId());
            IPAddressString cidr = new IPAddressString(subnet.getCidr());
            L3InterfaceIpv6AddressList ipv6 = new L3InterfaceIpv6AddressList();
            ipv6.setIsFloating(false);
            ipv6.setL3InterfaceIpv6Address(ipAddress);
            ipv6.setNeutronNetworkId(port.getNetworkId());
            ipv6.setNeutronSubnetId(ip.getSubnetId());
            ipv6.setL3InterfaceIpv6PrefixLength(Long.parseLong(cidr.getNetworkPrefixLength().toString()));
            transaction.createIfNotExists(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(cloudOwner, cloudRegionId).tenant(tenantId).vserver(port.getDeviceId()).lInterface(lIf.getInterfaceName()).l3InterfaceIpv6AddressList(ipAddress)), Optional.of(ipv6));
        }
    }
}
Also used : IP(org.openstack4j.model.network.IP) L3InterfaceIpv4AddressList(org.onap.aai.domain.yang.L3InterfaceIpv4AddressList) IPAddressString(inet.ipaddr.IPAddressString) Subnet(org.openstack4j.model.network.Subnet) L3InterfaceIpv6AddressList(org.onap.aai.domain.yang.L3InterfaceIpv6AddressList) IPAddressString(inet.ipaddr.IPAddressString)

Aggregations

IPAddressString (inet.ipaddr.IPAddressString)7 IPAddress (inet.ipaddr.IPAddress)3 Test (org.junit.jupiter.api.Test)2 WithMockUser (org.springframework.security.test.context.support.WithMockUser)2 AddressStringException (inet.ipaddr.AddressStringException)1 IPAddressSeqRange (inet.ipaddr.IPAddressSeqRange)1 HashSet (java.util.HashSet)1 L3InterfaceIpv4AddressList (org.onap.aai.domain.yang.L3InterfaceIpv4AddressList)1 L3InterfaceIpv6AddressList (org.onap.aai.domain.yang.L3InterfaceIpv6AddressList)1 IpAddress (org.onlab.packet.IpAddress)1 IP (org.openstack4j.model.network.IP)1 Subnet (org.openstack4j.model.network.Subnet)1