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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations