use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.provider.ext.rev150712.NetworkProviderExtension in project netvirt by opendaylight.
the class NeutronUtils method getNumberSegmentsFromNeutronNetwork.
public static Long getNumberSegmentsFromNeutronNetwork(Network network) {
NetworkProviderExtension providerExtension = network.getAugmentation(NetworkProviderExtension.class);
Integer numSegs = 0;
if (providerExtension != null) {
List<Segments> providerSegments = providerExtension.getSegments();
if (providerSegments != null) {
numSegs = providerSegments.size();
}
}
return Long.valueOf(numSegs);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.provider.ext.rev150712.NetworkProviderExtension in project netvirt by opendaylight.
the class NeutronvpnManager method associateNetworksToVpn.
/**
* Parses and associates networks list with given VPN.
*
* @param vpnId Uuid of given VPN.
* @param networks List list of network Ids (Uuid), which will be associated.
* @return list of formatted strings with detailed error messages.
*/
@Nonnull
protected List<String> associateNetworksToVpn(@Nonnull Uuid vpnId, @Nonnull List<Uuid> networks) {
List<String> failedNwList = new ArrayList<>();
HashSet<Uuid> passedNwList = new HashSet<>();
if (networks.isEmpty()) {
LOG.error("associateNetworksToVpn: Failed as given networks list is empty, VPN Id: {}", vpnId.getValue());
failedNwList.add(String.format("Failed to associate networks with VPN %s as given networks list is empty", vpnId.getValue()));
return failedNwList;
}
VpnInstance vpnInstance = VpnHelper.getVpnInstance(dataBroker, vpnId.getValue());
if (vpnInstance == null) {
LOG.error("associateNetworksToVpn: Can not find vpnInstance for VPN {} in ConfigDS", vpnId.getValue());
failedNwList.add(String.format("Failed to associate network: can not found vpnInstance for VPN %s " + "in ConfigDS", vpnId.getValue()));
return failedNwList;
}
try {
if (isVpnOfTypeL2(vpnInstance) && neutronEvpnUtils.isVpnAssociatedWithNetwork(vpnInstance)) {
LOG.error("associateNetworksToVpn: EVPN {} supports only one network to be associated with", vpnId.getValue());
failedNwList.add(String.format("Failed to associate network: EVPN %s supports only one network to be " + "associated with", vpnId.getValue()));
return failedNwList;
}
for (Uuid nw : networks) {
Network network = neutronvpnUtils.getNeutronNetwork(nw);
if (network == null) {
LOG.error("associateNetworksToVpn: Network {} not found in ConfigDS", nw.getValue());
failedNwList.add(String.format("Failed to associate network: network %s not found in ConfigDS", nw.getValue()));
continue;
}
NetworkProviderExtension providerExtension = network.getAugmentation(NetworkProviderExtension.class);
if (providerExtension.getSegments() != null && providerExtension.getSegments().size() > 1) {
LOG.error("associateNetworksToVpn: MultiSegmented network {} not supported in BGPVPN {}", nw.getValue(), vpnId.getValue());
failedNwList.add(String.format("Failed to associate multisegmented network %s with BGPVPN %s", nw.getValue(), vpnId.getValue()));
continue;
}
Uuid networkVpnId = neutronvpnUtils.getVpnForNetwork(nw);
if (networkVpnId != null) {
LOG.error("associateNetworksToVpn: Network {} already associated with another VPN {}", nw.getValue(), networkVpnId.getValue());
failedNwList.add(String.format("Failed to associate network %s as it is already associated to " + "another VPN %s", nw.getValue(), networkVpnId.getValue()));
continue;
}
if (neutronvpnUtils.getIsExternal(network)) {
if (associateExtNetworkToVpn(vpnId, network)) {
passedNwList.add(nw);
continue;
} else {
LOG.error("associateNetworksToVpn: Failed to associate Provider Network {} with VPN {}", nw.getValue(), vpnId.getValue());
failedNwList.add(String.format("Failed to associate Provider Network %s with VPN %s", nw.getValue(), vpnId.getValue()));
continue;
}
}
List<Uuid> networkSubnets = neutronvpnUtils.getSubnetIdsFromNetworkId(nw);
if (networkSubnets == null) {
passedNwList.add(nw);
continue;
}
for (Uuid subnet : networkSubnets) {
Uuid subnetVpnId = neutronvpnUtils.getVpnForSubnet(subnet);
if (subnetVpnId != null) {
LOG.error("associateNetworksToVpn: Failed to associate subnet {} with VPN {} as it is already " + "associated", subnet.getValue(), subnetVpnId.getValue());
failedNwList.add(String.format("Failed to associate subnet %s with VPN %s as it is already " + "associated", subnet.getValue(), vpnId.getValue()));
continue;
}
Subnetmap sm = neutronvpnUtils.getSubnetmap(subnet);
if (neutronvpnUtils.shouldVpnHandleIpVersionChangeToAdd(sm, vpnId)) {
neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), NeutronvpnUtils.getIpVersionFromString(sm.getSubnetIp()), true);
}
LOG.debug("associateNetworksToVpn: Add subnet {} to VPN {}", subnet.getValue(), vpnId.getValue());
addSubnetToVpn(vpnId, subnet, null);
passedNwList.add(nw);
}
}
} catch (ReadFailedException e) {
LOG.error("associateNetworksToVpn: Failed to associate VPN {} with networks {}: ", vpnId.getValue(), networks, e);
failedNwList.add(String.format("Failed to associate VPN %s with networks %s: %s", vpnId.getValue(), networks, e));
}
LOG.info("associateNetworksToVpn: update VPN {} with networks list: {}", vpnId.getValue(), passedNwList.toString());
updateVpnMaps(vpnId, null, null, null, new ArrayList<Uuid>(passedNwList));
return failedNwList;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.provider.ext.rev150712.NetworkProviderExtension in project netvirt by opendaylight.
the class NeutronvpnUtils method getSegmentationIdFromNeutronNetwork.
public static String getSegmentationIdFromNeutronNetwork(Network network) {
String segmentationId = null;
NetworkProviderExtension providerExtension = network.getAugmentation(NetworkProviderExtension.class);
if (providerExtension != null) {
Class<? extends NetworkTypeBase> networkType = providerExtension.getNetworkType();
segmentationId = NeutronUtils.getSegmentationIdFromNeutronNetwork(network, networkType);
}
return segmentationId;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.provider.ext.rev150712.NetworkProviderExtension in project netvirt by opendaylight.
the class NeutronvpnUtils method getProviderNetworkType.
static ProviderTypes getProviderNetworkType(Network network) {
if (network == null) {
LOG.error("Error in getting provider network type since network is null");
return null;
}
NetworkProviderExtension npe = network.getAugmentation(NetworkProviderExtension.class);
if (npe != null) {
Class<? extends NetworkTypeBase> networkTypeBase = npe.getNetworkType();
if (networkTypeBase != null) {
if (networkTypeBase.isAssignableFrom(NetworkTypeFlat.class)) {
return ProviderTypes.FLAT;
} else if (networkTypeBase.isAssignableFrom(NetworkTypeVlan.class)) {
return ProviderTypes.VLAN;
} else if (networkTypeBase.isAssignableFrom(NetworkTypeVxlan.class)) {
return ProviderTypes.VXLAN;
} else if (networkTypeBase.isAssignableFrom(NetworkTypeGre.class)) {
return ProviderTypes.GRE;
}
}
}
LOG.error("Error in getting provider network type since network provider extension is null for network " + "{}", network.getUuid().getValue());
return null;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.provider.ext.rev150712.NetworkProviderExtension in project netvirt by opendaylight.
the class NeutronUtils method isNetworkSegmentType.
public static <T extends NetworkTypeBase> boolean isNetworkSegmentType(Network network, Long index, Class<T> expectedNetworkType) {
Class<? extends NetworkTypeBase> segmentType = null;
NetworkProviderExtension providerExtension = network.getAugmentation(NetworkProviderExtension.class);
if (providerExtension != null) {
List<Segments> providerSegments = providerExtension.getSegments();
if (providerSegments != null && providerSegments.size() > 0) {
for (Segments providerSegment : providerSegments) {
if (Objects.equals(providerSegment.getSegmentationIndex(), index)) {
segmentType = providerSegment.getNetworkType();
break;
}
}
}
}
return segmentType != null && segmentType.isAssignableFrom(expectedNetworkType);
}
Aggregations