Search in sources :

Example 1 with SubnetKey

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

the class DhcpServiceUtils method isIpv4Subnet.

public static boolean isIpv4Subnet(DataBroker broker, Uuid subnetUuid) {
    final SubnetKey subnetkey = new SubnetKey(subnetUuid);
    final InstanceIdentifier<Subnet> subnetidentifier = InstanceIdentifier.create(Neutron.class).child(Subnets.class).child(Subnet.class, subnetkey);
    final Optional<Subnet> subnet = MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, subnetidentifier);
    if (subnet.isPresent()) {
        Class<? extends IpVersionBase> ipVersionBase = subnet.get().getIpVersion();
        if (ipVersionBase.equals(IpVersionV4.class)) {
            return true;
        }
    }
    return false;
}
Also used : Subnets(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.Subnets) 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 2 with SubnetKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.SubnetKey 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 3 with SubnetKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.SubnetKey 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 4 with SubnetKey

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

the class VpnUtil method getVpnSubnetGatewayIp.

public static Optional<String> getVpnSubnetGatewayIp(DataBroker dataBroker, final Uuid subnetUuid) {
    Optional<String> gwIpAddress = Optional.absent();
    final SubnetKey subnetkey = new SubnetKey(subnetUuid);
    final InstanceIdentifier<Subnet> subnetidentifier = InstanceIdentifier.create(Neutron.class).child(Subnets.class).child(Subnet.class, subnetkey);
    final Optional<Subnet> subnet = read(dataBroker, LogicalDatastoreType.CONFIGURATION, subnetidentifier);
    if (subnet.isPresent()) {
        Class<? extends IpVersionBase> ipVersionBase = subnet.get().getIpVersion();
        if (ipVersionBase.equals(IpVersionV4.class)) {
            LOG.trace("getVpnSubnetGatewayIp: Obtained subnet {} for vpn interface", subnet.get().getUuid().getValue());
            IpAddress gwIp = subnet.get().getGatewayIp();
            if (gwIp != null && gwIp.getIpv4Address() != null) {
                gwIpAddress = Optional.of(gwIp.getIpv4Address().getValue());
            }
        }
    }
    return gwIpAddress;
}
Also used : ExternalSubnets(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalSubnets) Subnets(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.Subnets) SubnetKey(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.SubnetKey) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) Subnet(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet)

Example 5 with SubnetKey

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

the class NatUtil method getSubnetGwMac.

public static String getSubnetGwMac(DataBroker broker, Uuid subnetId, String vpnName) {
    if (subnetId == null) {
        LOG.error("getSubnetGwMac : subnetID is null");
        return null;
    }
    InstanceIdentifier<Subnet> subnetInst = InstanceIdentifier.create(Neutron.class).child(Subnets.class).child(Subnet.class, new SubnetKey(subnetId));
    Optional<Subnet> subnetOpt = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker, LogicalDatastoreType.CONFIGURATION, subnetInst);
    if (!subnetOpt.isPresent()) {
        LOG.error("getSubnetGwMac : unable to obtain Subnet for id : {}", subnetId);
        return null;
    }
    IpAddress gatewayIp = subnetOpt.get().getGatewayIp();
    if (gatewayIp == null) {
        LOG.warn("getSubnetGwMac : No GW ip found for subnet {}", subnetId.getValue());
        return null;
    }
    InstanceIdentifier<VpnPortipToPort> portIpInst = InstanceIdentifier.builder(NeutronVpnPortipPortData.class).child(VpnPortipToPort.class, new VpnPortipToPortKey(gatewayIp.getIpv4Address().getValue(), vpnName)).build();
    Optional<VpnPortipToPort> portIpToPortOpt = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker, LogicalDatastoreType.CONFIGURATION, portIpInst);
    if (portIpToPortOpt.isPresent()) {
        return portIpToPortOpt.get().getMacAddress();
    }
    InstanceIdentifier<LearntVpnVipToPort> learntIpInst = InstanceIdentifier.builder(LearntVpnVipToPortData.class).child(LearntVpnVipToPort.class, new LearntVpnVipToPortKey(gatewayIp.getIpv4Address().getValue(), vpnName)).build();
    Optional<LearntVpnVipToPort> learntIpToPortOpt = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker, LogicalDatastoreType.OPERATIONAL, learntIpInst);
    if (learntIpToPortOpt.isPresent()) {
        return learntIpToPortOpt.get().getMacAddress();
    }
    LOG.info("getSubnetGwMac : No resolution was found to GW ip {} in subnet {}", gatewayIp, subnetId.getValue());
    return null;
}
Also used : VpnPortipToPort(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPort) ExternalSubnets(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalSubnets) Subnets(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.Subnets) SubnetKey(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.SubnetKey) VpnPortipToPortKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPortKey) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) LearntVpnVipToPort(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort) Subnet(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet) LearntVpnVipToPortKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPortKey)

Aggregations

Subnets (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.Subnets)5 Subnet (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet)5 SubnetKey (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.SubnetKey)5 ExternalSubnets (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalSubnets)4 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)2 UnknownHostException (java.net.UnknownHostException)1 ExecutionException (java.util.concurrent.ExecutionException)1 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)1 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)1 LearntVpnVipToPort (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort)1 LearntVpnVipToPortKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPortKey)1 VpnPortipToPort (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPort)1 VpnPortipToPortKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPortKey)1