use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.dhcp_allocation_pool.rev161214.dhcp_allocation_pool.Network in project netvirt by opendaylight.
the class NeutronNetworkChangeListener method update.
@Override
protected void update(InstanceIdentifier<Network> identifier, Network original, Network update) {
LOG.trace("Updating Network : key: {}, original value={}, update value={}", identifier, original, update);
neutronvpnUtils.addToNetworkCache(update);
String elanInstanceName = original.getUuid().getValue();
Class<? extends SegmentTypeBase> origSegmentType = NeutronvpnUtils.getSegmentTypeFromNeutronNetwork(original);
String origSegmentationId = NeutronvpnUtils.getSegmentationIdFromNeutronNetwork(original);
String origPhysicalNetwork = NeutronvpnUtils.getPhysicalNetworkName(original);
Class<? extends SegmentTypeBase> updateSegmentType = NeutronvpnUtils.getSegmentTypeFromNeutronNetwork(update);
String updateSegmentationId = NeutronvpnUtils.getSegmentationIdFromNeutronNetwork(update);
String updatePhysicalNetwork = NeutronvpnUtils.getPhysicalNetworkName(update);
Boolean origExternal = NeutronvpnUtils.getIsExternal(original);
Boolean updateExternal = NeutronvpnUtils.getIsExternal(update);
Boolean origIsFlatOrVlanNetwork = NeutronvpnUtils.isFlatOrVlanNetwork(original);
Boolean updateIsFlatOrVlanNetwork = NeutronvpnUtils.isFlatOrVlanNetwork(update);
if (!Objects.equals(origSegmentType, updateSegmentType) || !Objects.equals(origSegmentationId, updateSegmentationId) || !Objects.equals(origPhysicalNetwork, updatePhysicalNetwork) || !Objects.equals(origExternal, updateExternal)) {
if (origExternal && origIsFlatOrVlanNetwork && (!updateExternal || !updateIsFlatOrVlanNetwork)) {
nvpnManager.removeExternalVpnInterfaces(original.getUuid());
nvpnManager.removeVpn(original.getUuid());
nvpnNatManager.removeExternalNetwork(original);
}
ElanInstance elanInstance = elanService.getElanInstance(elanInstanceName);
if (elanInstance != null) {
elanService.deleteExternalElanNetwork(elanInstance);
elanInstance = updateElanInstance(elanInstanceName, updateSegmentType, updateSegmentationId, updatePhysicalNetwork, update);
if (updateExternal) {
elanService.updateExternalElanNetwork(elanInstance);
}
}
if (updateExternal && updateIsFlatOrVlanNetwork && !origExternal) {
nvpnNatManager.addExternalNetwork(update);
nvpnManager.createL3InternalVpn(update.getUuid(), null, null, null, null, null, null, null);
nvpnManager.createExternalVpnInterfaces(update.getUuid());
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.dhcp_allocation_pool.rev161214.dhcp_allocation_pool.Network in project netvirt by opendaylight.
the class NeutronNetworkChangeListener method buildSegments.
@Nonnull
private List<ElanSegments> buildSegments(Network input) {
Long numSegments = NeutronUtils.getNumberSegmentsFromNeutronNetwork(input);
List<ElanSegments> segments = new ArrayList<>();
for (long index = 0L; index < numSegments; index++) {
ElanSegmentsBuilder elanSegmentsBuilder = new ElanSegmentsBuilder();
elanSegmentsBuilder.setSegmentationId(0L);
if (NeutronUtils.getSegmentationIdFromNeutronNetworkSegment(input, index) != null) {
try {
elanSegmentsBuilder.setSegmentationId(Long.valueOf(NeutronUtils.getSegmentationIdFromNeutronNetworkSegment(input, index)));
} catch (NumberFormatException error) {
LOG.error("Failed to get the segment id for network {}", input);
}
}
if (NeutronUtils.isNetworkSegmentType(input, index, NetworkTypeVxlan.class)) {
elanSegmentsBuilder.setSegmentType(SegmentTypeVxlan.class);
} else if (NeutronUtils.isNetworkSegmentType(input, index, NetworkTypeVlan.class)) {
elanSegmentsBuilder.setSegmentType(SegmentTypeVlan.class);
} else if (NeutronUtils.isNetworkSegmentType(input, index, NetworkTypeFlat.class)) {
elanSegmentsBuilder.setSegmentType(SegmentTypeFlat.class);
}
elanSegmentsBuilder.setSegmentationIndex(index);
segments.add(elanSegmentsBuilder.build());
LOG.debug("Added segment {} to ELANInstance", segments.get((int) index - 1));
}
return segments;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.dhcp_allocation_pool.rev161214.dhcp_allocation_pool.Network 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.dhcp_allocation_pool.rev161214.dhcp_allocation_pool.Network in project netvirt by opendaylight.
the class NeutronPortChangeListener method handleRouterInterfaceAdded.
private void handleRouterInterfaceAdded(Port routerPort) {
if (routerPort.getDeviceId() != null) {
Uuid routerId = new Uuid(routerPort.getDeviceId());
Uuid infNetworkId = routerPort.getNetworkId();
Uuid existingVpnId = neutronvpnUtils.getVpnForNetwork(infNetworkId);
elanService.addKnownL3DmacAddress(routerPort.getMacAddress().getValue(), infNetworkId.getValue());
if (existingVpnId == null) {
Set<Uuid> listVpnIds = new HashSet<>();
Uuid vpnId = neutronvpnUtils.getVpnForRouter(routerId, true);
if (vpnId == null) {
vpnId = routerId;
}
listVpnIds.add(vpnId);
Uuid internetVpnId = neutronvpnUtils.getInternetvpnUuidBoundToRouterId(routerId);
List<Subnetmap> subnetMapList = new ArrayList<>();
List<FixedIps> portIps = routerPort.getFixedIps();
boolean portIsIpv6 = false;
for (FixedIps portIP : portIps) {
// and addSubnetToVpn here
if (internetVpnId != null && portIP.getIpAddress().getIpv6Address() != null) {
portIsIpv6 = true;
}
String ipValue = String.valueOf(portIP.getIpAddress().getValue());
Uuid subnetId = portIP.getSubnetId();
nvpnManager.updateSubnetNodeWithFixedIp(subnetId, routerId, routerPort.getUuid(), ipValue, routerPort.getMacAddress().getValue(), vpnId);
Subnetmap sn = neutronvpnUtils.getSubnetmap(subnetId);
subnetMapList.add(sn);
}
if (portIsIpv6) {
listVpnIds.add(internetVpnId);
if (neutronvpnUtils.shouldVpnHandleIpVersionChoiceChangeToAdd(IpVersionChoice.IPV6, internetVpnId)) {
neutronvpnUtils.updateVpnInstanceWithIpFamily(internetVpnId.getValue(), IpVersionChoice.IPV6, true);
neutronvpnUtils.updateVpnInstanceWithFallback(internetVpnId.getValue(), true);
}
}
if (!subnetMapList.isEmpty()) {
nvpnManager.createVpnInterface(listVpnIds, routerPort, null);
}
for (FixedIps portIP : routerPort.getFixedIps()) {
String ipValue = String.valueOf(portIP.getIpAddress().getValue());
IpVersionChoice version = neutronvpnUtils.getIpVersionFromString(ipValue);
if (neutronvpnUtils.shouldVpnHandleIpVersionChoiceChangeToAdd(version, vpnId)) {
neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), version, true);
}
if (version.isIpVersionChosen(IpVersionChoice.IPV4)) {
nvpnManager.addSubnetToVpn(vpnId, portIP.getSubnetId(), null);
} else {
nvpnManager.addSubnetToVpn(vpnId, portIP.getSubnetId(), internetVpnId);
}
LOG.trace("NeutronPortChangeListener Add Subnet Gateway IP {} MAC {} Interface {} VPN {}", ipValue, routerPort.getMacAddress(), routerPort.getUuid().getValue(), vpnId.getValue());
}
nvpnManager.addToNeutronRouterInterfacesMap(routerId, routerPort.getUuid().getValue());
nvpnNatManager.handleSubnetsForExternalRouter(routerId);
WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
String portInterfaceName = createOfPortInterface(routerPort, wrtConfigTxn);
createElanInterface(routerPort, portInterfaceName, wrtConfigTxn);
wrtConfigTxn.submit();
} else {
LOG.error("Neutron network {} corresponding to router interface port {} for neutron router {}" + " already associated to VPN {}", infNetworkId.getValue(), routerPort.getUuid().getValue(), routerId.getValue(), existingVpnId.getValue());
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.dhcp_allocation_pool.rev161214.dhcp_allocation_pool.Network in project netvirt by opendaylight.
the class NeutronPortChangeListener method remove.
@Override
protected void remove(InstanceIdentifier<Port> identifier, Port input) {
LOG.trace("Removing Port : key: {}, value={}", identifier, input);
Network network = neutronvpnUtils.getNeutronNetwork(input.getNetworkId());
if (network == null || !NeutronvpnUtils.isNetworkTypeSupported(network)) {
String portName = input.getUuid().getValue();
LOG.warn("neutron vpn received a port remove() for a network without a provider extension augmentation " + "or with an unsupported network type for the port {} which is part of network {}", portName, network);
return;
}
neutronvpnUtils.removeFromPortCache(input);
NeutronUtils.deletePortStatus(input.getUuid().getValue(), dataBroker);
if (!Strings.isNullOrEmpty(input.getDeviceOwner()) && !Strings.isNullOrEmpty(input.getDeviceId())) {
if (input.getDeviceOwner().equals(NeutronConstants.DEVICE_OWNER_ROUTER_INF)) {
handleRouterInterfaceRemoved(input);
/* nothing else to do here */
return;
} else if (NeutronConstants.DEVICE_OWNER_GATEWAY_INF.equals(input.getDeviceOwner()) || NeutronConstants.DEVICE_OWNER_FLOATING_IP.equals(input.getDeviceOwner())) {
elanService.removeKnownL3DmacAddress(input.getMacAddress().getValue(), input.getNetworkId().getValue());
}
}
if (input.getFixedIps() != null) {
handleNeutronPortDeleted(input);
}
}
Aggregations