use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.Subnetmaps in project netvirt by opendaylight.
the class VpnUtil method getAllSubnetGatewayMacAddressesforVpn.
static List<String> getAllSubnetGatewayMacAddressesforVpn(DataBroker broker, String vpnName) {
List<String> macAddresses = new ArrayList<>();
Optional<Subnetmaps> subnetMapsData = read(broker, LogicalDatastoreType.CONFIGURATION, buildSubnetMapsWildCardPath());
if (subnetMapsData.isPresent()) {
List<Subnetmap> subnetMapList = subnetMapsData.get().getSubnetmap();
if (subnetMapList != null && !subnetMapList.isEmpty()) {
for (Subnetmap subnet : subnetMapList) {
if (subnet.getVpnId() != null && subnet.getVpnId().equals(Uuid.getDefaultInstance(vpnName))) {
String routerIntfMacAddress = subnet.getRouterIntfMacAddress();
if (routerIntfMacAddress != null && !routerIntfMacAddress.isEmpty()) {
macAddresses.add(subnet.getRouterIntfMacAddress());
}
}
}
}
}
return macAddresses;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.Subnetmaps in project netvirt by opendaylight.
the class VpnUtil method getElanInstanceRouterPortMap.
public static Map<String, String> getElanInstanceRouterPortMap(DataBroker dataBroker, String vpnName) {
Map<String, String> elanInstanceRouterPortMap = new HashMap<String, String>();
Optional<Subnetmaps> subnetMapsData = read(dataBroker, LogicalDatastoreType.CONFIGURATION, buildSubnetMapsWildCardPath());
if (subnetMapsData.isPresent()) {
List<Subnetmap> subnetMapList = subnetMapsData.get().getSubnetmap();
if (subnetMapList != null && !subnetMapList.isEmpty()) {
for (Subnetmap subnet : subnetMapList) {
if (subnet.getVpnId() != null && subnet.getVpnId().getValue().equals(vpnName) && subnet.getNetworkType().equals(NetworkType.VLAN)) {
if (subnet.getRouterInterfacePortId() == null || subnet.getNetworkId() == null) {
LOG.warn("The RouterInterfacePortId or NetworkId is null");
continue;
}
String routerInterfacePortUuid = subnet.getRouterInterfacePortId().getValue();
if (routerInterfacePortUuid != null && !routerInterfacePortUuid.isEmpty()) {
elanInstanceRouterPortMap.put(subnet.getNetworkId().getValue(), routerInterfacePortUuid);
}
}
}
}
}
return elanInstanceRouterPortMap;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.Subnetmaps in project netvirt by opendaylight.
the class NeutronvpnUtils method getIpVersionChoicesFromRouterUuid.
/**
* Method to get an ipVersionChosen as IPV4 and/or IPV6 or undefined from the subnetmaps of the router.
* @param routerUuid the Uuid for which find out the IP version associated
* @return an IpVersionChoice used by the router from its attached subnetmaps. IpVersionChoice.UNDEFINED if any
*/
public IpVersionChoice getIpVersionChoicesFromRouterUuid(Uuid routerUuid) {
IpVersionChoice rep = IpVersionChoice.UNDEFINED;
if (routerUuid == null) {
return rep;
}
List<Subnetmap> subnetmapList = getNeutronRouterSubnetMaps(routerUuid);
if (subnetmapList.isEmpty()) {
return rep;
}
for (Subnetmap sn : subnetmapList) {
if (sn.getSubnetIp() != null) {
IpVersionChoice ipVers = getIpVersionFromString(sn.getSubnetIp());
if (rep.choice != ipVers.choice) {
rep = rep.addVersion(ipVers);
}
if (rep.choice == IpVersionChoice.IPV4AND6.choice) {
return rep;
}
}
}
return rep;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.Subnetmaps in project netvirt by opendaylight.
the class NeutronPortChangeListener method handleNeutronPortCreated.
private void handleNeutronPortCreated(final Port port) {
final String portName = port.getUuid().getValue();
final Uuid portId = port.getUuid();
final List<FixedIps> portIpAddrsList = port.getFixedIps();
if (NeutronConstants.IS_ODL_DHCP_PORT.test(port)) {
return;
}
jobCoordinator.enqueueJob("PORT- " + portName, () -> {
// add direct port to subnetMaps config DS
if (!(NeutronUtils.isPortVnicTypeNormal(port) || (isPortTypeSwitchdev(port) && isSupportedVnicTypeByHost(port, NeutronConstants.VNIC_TYPE_DIRECT)))) {
for (FixedIps ip : portIpAddrsList) {
nvpnManager.updateSubnetmapNodeWithPorts(ip.getSubnetId(), null, portId);
}
LOG.info("Port {} is not a normal and not a direct with switchdev VNIC type ;" + "OF Port interfaces are not created", portName);
return Collections.emptyList();
}
return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
LOG.info("Of-port-interface creation for port {}", portName);
// Create of-port interface for this neutron port
String portInterfaceName = createOfPortInterface(port, tx);
LOG.debug("Creating ELAN Interface for port {}", portName);
createElanInterface(port, portInterfaceName, tx);
Set<Uuid> vpnIdList = new HashSet<>();
Set<Uuid> routerIds = new HashSet<>();
for (FixedIps ip : portIpAddrsList) {
Subnetmap subnetMap = nvpnManager.updateSubnetmapNodeWithPorts(ip.getSubnetId(), portId, null);
if (subnetMap != null && subnetMap.getInternetVpnId() != null) {
if (!vpnIdList.contains(subnetMap.getInternetVpnId())) {
vpnIdList.add(subnetMap.getInternetVpnId());
}
}
if (subnetMap != null && subnetMap.getVpnId() != null) {
// can't use NeutronvpnUtils.getVpnForNetwork to optimise here, because it gives BGPVPN id
// obtained subnetMaps belongs to one network => vpnId must be the same for each port Ip
Uuid vpnId = subnetMap.getVpnId();
if (vpnId != null) {
vpnIdList.add(vpnId);
}
}
if (subnetMap != null && subnetMap.getRouterId() != null) {
routerIds.add(subnetMap.getRouterId());
}
}
if (!vpnIdList.isEmpty()) {
// create new vpn-interface for neutron port
LOG.debug("handleNeutronPortCreated: Adding VPN Interface for port {} from network {}", portName, port.getNetworkId().toString());
nvpnManager.createVpnInterface(vpnIdList, port, tx);
if (!routerIds.isEmpty()) {
for (Uuid routerId : routerIds) {
nvpnManager.addToNeutronRouterInterfacesMap(routerId, port.getUuid().getValue());
}
}
}
}));
});
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.Subnetmaps in project netvirt by opendaylight.
the class NeutronvpnManager method createSubnetmapNode.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
protected void createSubnetmapNode(Uuid subnetId, String subnetIp, Uuid tenantId, Uuid networkId, NetworkAttributes.NetworkType networkType, long segmentationId) {
try {
InstanceIdentifier<Subnetmap> subnetMapIdentifier = NeutronvpnUtils.buildSubnetMapIdentifier(subnetId);
synchronized (subnetId.getValue().intern()) {
LOG.info("createSubnetmapNode: subnet ID {}", subnetId.toString());
Optional<Subnetmap> sn = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, subnetMapIdentifier);
if (sn.isPresent()) {
LOG.error("createSubnetmapNode: Subnetmap node for subnet ID {} already exists, returning", subnetId.getValue());
return;
}
SubnetmapBuilder subnetmapBuilder = new SubnetmapBuilder().setKey(new SubnetmapKey(subnetId)).setId(subnetId).setSubnetIp(subnetIp).setTenantId(tenantId).setNetworkId(networkId).setNetworkType(networkType).setSegmentationId(segmentationId);
LOG.debug("createSubnetmapNode: Adding a new subnet node in Subnetmaps DS for subnet {}", subnetId.getValue());
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, subnetMapIdentifier, subnetmapBuilder.build());
}
} catch (TransactionCommitFailedException | ReadFailedException e) {
LOG.error("createSubnetmapNode: Creating subnetmap node failed for subnet {}", subnetId.getValue());
}
// check if there are ports to update for already created Subnetmap node
LOG.debug("createSubnetmapNode: Update created Subnetmap for subnet {} with ports", subnetId.getValue());
for (Map.Entry<Uuid, Uuid> entry : unprocessedPortsMap.entrySet()) {
if (entry.getValue().getValue().equals(subnetId.getValue())) {
updateSubnetmapNodeWithPorts(subnetId, entry.getKey(), null);
unprocessedPortsMap.remove(entry.getKey());
}
}
}
Aggregations