Search in sources :

Example 56 with Subnet

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet in project netvirt by opendaylight.

the class NeutronvpnUtils method getIPPrefixFromPort.

// TODO Clean up the exception handling and the console output
@SuppressWarnings({ "checkstyle:IllegalCatch", "checkstyle:RegexpSinglelineJava" })
protected Short getIPPrefixFromPort(Port port) {
    try {
        Uuid subnetUUID = port.getFixedIps().get(0).getSubnetId();
        SubnetKey subnetkey = new SubnetKey(subnetUUID);
        InstanceIdentifier<Subnet> subnetidentifier = InstanceIdentifier.create(Neutron.class).child(Subnets.class).child(Subnet.class, subnetkey);
        Optional<Subnet> subnet = read(LogicalDatastoreType.CONFIGURATION, subnetidentifier);
        if (subnet.isPresent()) {
            String cidr = String.valueOf(subnet.get().getCidr().getValue());
            // Extract the prefix length from cidr
            String[] parts = cidr.split("/");
            if (parts.length == 2) {
                return Short.valueOf(parts[1]);
            } else {
                LOG.trace("Could not retrieve prefix from subnet CIDR");
            }
        } else {
            LOG.trace("Unable to read on subnet datastore");
        }
    } catch (Exception e) {
        LOG.error("Failed to retrieve IP prefix from port for port {}", port.getUuid().getValue(), e);
    }
    LOG.error("Failed for port {}", port.getUuid().getValue());
    return null;
}
Also used : Subnets(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.Subnets) ExternalSubnets(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalSubnets) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) SubnetKey(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.SubnetKey) Subnet(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)

Example 57 with Subnet

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet in project netvirt by opendaylight.

the class NeutronvpnUtils method getNeutronSubnet.

protected Subnet getNeutronSubnet(Uuid subnetId) {
    Subnet subnet = subnetMap.get(subnetId);
    if (subnet != null) {
        return subnet;
    }
    InstanceIdentifier<Subnet> inst = InstanceIdentifier.create(Neutron.class).child(Subnets.class).child(Subnet.class, new SubnetKey(subnetId));
    Optional<Subnet> sn = read(LogicalDatastoreType.CONFIGURATION, inst);
    if (sn.isPresent()) {
        subnet = sn.get();
    }
    return subnet;
}
Also used : Subnets(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.Subnets) ExternalSubnets(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalSubnets) SubnetKey(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.SubnetKey) Subnet(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet)

Example 58 with Subnet

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet in project netvirt by opendaylight.

the class NeutronSubnetChangeListener method handleNeutronSubnetCreated.

private void handleNeutronSubnetCreated(Subnet subnet, Network network) {
    Uuid networkId = network.getUuid();
    Uuid subnetId = subnet.getUuid();
    ProviderTypes providerType = NeutronvpnUtils.getProviderNetworkType(network);
    String segmentationId = NeutronvpnUtils.getSegmentationIdFromNeutronNetwork(network);
    nvpnManager.createSubnetmapNode(subnetId, String.valueOf(subnet.getCidr().getValue()), subnet.getTenantId(), networkId, providerType != null ? NetworkAttributes.NetworkType.valueOf(providerType.getName()) : null, segmentationId != null ? Long.parseLong(segmentationId) : 0L);
    createSubnetToNetworkMapping(subnetId, networkId);
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)

Example 59 with Subnet

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet in project netvirt by opendaylight.

the class NeutronSubnetChangeListener method remove.

@Override
protected void remove(InstanceIdentifier<Subnet> identifier, Subnet input) {
    LOG.trace("Removing subnet : key: {}, value={}", identifier, input);
    Uuid networkId = input.getNetworkId();
    Uuid subnetId = input.getUuid();
    Network network = neutronvpnUtils.getNeutronNetwork(networkId);
    if (network == null || !NeutronvpnUtils.isNetworkTypeSupported(network)) {
        LOG.warn("neutron vpn received a subnet remove() for a network without a provider extension augmentation " + "or with an unsupported network type for the subnet {} which is part of network {}", subnetId.getValue(), network);
        return;
    }
    handleNeutronSubnetDeleted(subnetId, networkId);
    externalSubnetHandler.handleExternalSubnetRemoved(network, subnetId);
    neutronvpnUtils.removeFromSubnetCache(input);
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Network(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network)

Example 60 with Subnet

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet in project netvirt by opendaylight.

the class NeutronSubnetChangeListener method add.

@Override
protected void add(InstanceIdentifier<Subnet> identifier, Subnet input) {
    LOG.trace("Adding Subnet : key: {}, value={}", identifier, input);
    Uuid networkId = input.getNetworkId();
    Uuid subnetId = input.getUuid();
    Network network = neutronvpnUtils.getNeutronNetwork(networkId);
    if (network == null || !NeutronvpnUtils.isNetworkTypeSupported(network)) {
        LOG.warn("neutron vpn received a subnet add() for a network without a provider extension augmentation " + "or with an unsupported network type for the subnet {} which is part of network {}", subnetId.getValue(), network);
        return;
    }
    neutronvpnUtils.addToSubnetCache(input);
    handleNeutronSubnetCreated(input, network);
    externalSubnetHandler.handleExternalSubnetAdded(network, subnetId, null);
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Network(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)72 ArrayList (java.util.ArrayList)44 BigInteger (java.math.BigInteger)30 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)28 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)25 SubnetOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry)17 Subnet (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet)15 SubnetOpDataEntryKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryKey)13 List (java.util.List)12 ExecutionException (java.util.concurrent.ExecutionException)12 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)12 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)11 FixedIps (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps)11 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)10 UnknownHostException (java.net.UnknownHostException)10 Vteps (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.Vteps)10 VpnInterface (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface)9 ExternalSubnets (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalSubnets)9 HashMap (java.util.HashMap)8 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)8