use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps in project netvirt by opendaylight.
the class NeutronvpnNatManager method addExternalRouter.
public void addExternalRouter(Router update) {
Uuid routerId = update.getUuid();
Uuid extNetId = update.getExternalGatewayInfo().getExternalNetworkId();
Uuid gatewayPortId = update.getGatewayPortId();
// Create and add Routers object for this Router to the ExtRouters list
// Create a Routers object
InstanceIdentifier<Routers> routersIdentifier = NeutronvpnUtils.buildExtRoutersIdentifier(routerId);
try {
Network input = neutronvpnUtils.getNeutronNetwork(extNetId);
ProviderTypes providerNwType = NeutronvpnUtils.getProviderNetworkType(input);
if (providerNwType == null) {
LOG.error("Unable to get Network Provider Type for network {}", input.getUuid().getValue());
return;
}
Optional<Routers> optionalRouters = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier);
LOG.trace("Creating/Updating a new Routers node: {}", routerId.getValue());
RoutersBuilder builder = null;
if (optionalRouters.isPresent()) {
builder = new RoutersBuilder(optionalRouters.get());
} else {
builder = new RoutersBuilder().setKey(new RoutersKey(routerId.getValue()));
}
builder.setRouterName(routerId.getValue());
builder.setNetworkId(extNetId);
builder.setEnableSnat(update.getExternalGatewayInfo().isEnableSnat());
ArrayList<ExternalIps> externalIps = new ArrayList<>();
for (ExternalFixedIps fixedIps : update.getExternalGatewayInfo().getExternalFixedIps()) {
addExternalFixedIpToExternalIpsList(externalIps, fixedIps);
}
builder.setExternalIps(externalIps);
if (gatewayPortId != null) {
LOG.trace("Setting/Updating gateway Mac for router {}", routerId.getValue());
Port port = neutronvpnUtils.getNeutronPort(gatewayPortId);
if (port != null && port.getDeviceOwner().equals(NeutronConstants.DEVICE_OWNER_GATEWAY_INF)) {
builder.setExtGwMacAddress(port.getMacAddress().getValue());
}
}
List<Uuid> subList = neutronvpnUtils.getNeutronRouterSubnetIds(routerId);
builder.setSubnetIds(subList);
Routers routers = builder.build();
// Add Routers object to the ExtRouters list
LOG.trace("Creating extrouters {}", routers);
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier, builder.build());
LOG.trace("Wrote successfully Routers to CONFIG Datastore");
} catch (ReadFailedException | TransactionCommitFailedException ex) {
LOG.error("Creation of extrouters failed for router {} failed", routerId.getValue(), ex);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps in project netvirt by opendaylight.
the class NeutronvpnUtils method buildStaticMacEntry.
public static List<StaticMacEntries> buildStaticMacEntry(Port port) {
PhysAddress physAddress = new PhysAddress(port.getMacAddress().getValue());
List<FixedIps> fixedIps = port.getFixedIps();
IpAddress ipAddress = null;
if (isNotEmpty(fixedIps)) {
ipAddress = port.getFixedIps().get(0).getIpAddress();
}
StaticMacEntriesBuilder staticMacEntriesBuilder = new StaticMacEntriesBuilder();
List<StaticMacEntries> staticMacEntries = new ArrayList<>();
if (ipAddress != null) {
staticMacEntries.add(staticMacEntriesBuilder.setMacAddress(physAddress).setIpPrefix(ipAddress).build());
} else {
staticMacEntries.add(staticMacEntriesBuilder.setMacAddress(physAddress).build());
}
return staticMacEntries;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps in project netvirt by opendaylight.
the class NeutronPortChangeListener method update.
@Override
protected void update(InstanceIdentifier<Port> identifier, Port original, Port update) {
// in order to validate the supported vnic types from the hostconfig
if (isPortTypeSwitchdev(original) && !isPortBound(original) && isPortBound(update)) {
handleNeutronPortCreated(update);
}
final String portName = update.getUuid().getValue();
Network network = neutronvpnUtils.getNeutronNetwork(update.getNetworkId());
LOG.info("Update port {} from network {}", portName, update.getNetworkId().toString());
if (network == null || !NeutronvpnUtils.isNetworkTypeSupported(network)) {
LOG.error("neutron vpn received a port update() 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.addToPortCache(update);
if ((Strings.isNullOrEmpty(original.getDeviceOwner()) || Strings.isNullOrEmpty(original.getDeviceId()) || NeutronConstants.FLOATING_IP_DEVICE_ID_PENDING.equalsIgnoreCase(original.getDeviceId())) && !Strings.isNullOrEmpty(update.getDeviceOwner()) && !Strings.isNullOrEmpty(update.getDeviceId())) {
if (update.getDeviceOwner().equals(NeutronConstants.DEVICE_OWNER_ROUTER_INF)) {
handleRouterInterfaceAdded(update);
return;
}
if (NeutronConstants.DEVICE_OWNER_GATEWAY_INF.equals(update.getDeviceOwner())) {
handleRouterGatewayUpdated(update);
} else if (NeutronConstants.DEVICE_OWNER_FLOATING_IP.equals(update.getDeviceOwner())) {
handleFloatingIpPortUpdated(original, update);
}
} else {
Set<FixedIps> oldIPs = getFixedIpSet(original.getFixedIps());
Set<FixedIps> newIPs = getFixedIpSet(update.getFixedIps());
if (!oldIPs.equals(newIPs)) {
handleNeutronPortUpdated(original, update);
}
}
// check if port security enabled/disabled as part of port update
boolean origSecurityEnabled = NeutronvpnUtils.getPortSecurityEnabled(original);
boolean updatedSecurityEnabled = NeutronvpnUtils.getPortSecurityEnabled(update);
if (origSecurityEnabled || updatedSecurityEnabled) {
InstanceIdentifier<Interface> interfaceIdentifier = NeutronvpnUtils.buildVlanInterfaceIdentifier(portName);
jobCoordinator.enqueueJob("PORT- " + portName, () -> {
WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
try {
Optional<Interface> optionalInf = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, interfaceIdentifier);
if (optionalInf.isPresent()) {
InterfaceBuilder interfaceBuilder = new InterfaceBuilder(optionalInf.get());
InterfaceAcl infAcl = handlePortSecurityUpdated(original, update, origSecurityEnabled, updatedSecurityEnabled, interfaceBuilder).build();
interfaceBuilder.addAugmentation(InterfaceAcl.class, infAcl);
LOG.info("update: Of-port-interface updation for port {}", portName);
// Update OFPort interface for this neutron port
wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, interfaceIdentifier, interfaceBuilder.build());
} else {
LOG.warn("update: Interface {} is not present", portName);
}
} catch (ReadFailedException e) {
LOG.error("update: Failed to update interface {}", portName, e);
}
List<ListenableFuture<Void>> futures = new ArrayList<>();
futures.add(wrtConfigTxn.submit());
return futures;
});
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps in project netvirt by opendaylight.
the class NeutronPortChangeListener method handleNeutronPortDeleted.
private void handleNeutronPortDeleted(final Port port) {
final String portName = port.getUuid().getValue();
final Uuid portId = port.getUuid();
final List<FixedIps> portIpsList = port.getFixedIps();
jobCoordinator.enqueueJob("PORT- " + portName, () -> {
WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
List<ListenableFuture<Void>> futures = new ArrayList<>();
if (!(NeutronUtils.isPortVnicTypeNormal(port) || isPortTypeSwitchdev(port))) {
for (FixedIps ip : portIpsList) {
// remove direct port from subnetMaps config DS
nvpnManager.removePortsFromSubnetmapNode(ip.getSubnetId(), null, portId);
}
LOG.info("Port {} is not a normal and not a direct with switchdev VNIC type ;" + "Skipping OF Port interfaces removal", portName);
return futures;
}
Uuid vpnId = null;
Set<Uuid> routerIds = new HashSet<>();
Uuid internetVpnId = null;
for (FixedIps ip : portIpsList) {
Subnetmap subnetMap = nvpnManager.removePortsFromSubnetmapNode(ip.getSubnetId(), portId, null);
if (subnetMap == null) {
continue;
}
if (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
vpnId = subnetMap.getVpnId();
}
if (subnetMap.getRouterId() != null) {
routerIds.add(subnetMap.getRouterId());
}
internetVpnId = subnetMap.getInternetVpnId();
}
if (vpnId != null || internetVpnId != null) {
// remove vpn-interface for this neutron port
LOG.debug("removing VPN Interface for port {}", portName);
if (!routerIds.isEmpty()) {
for (Uuid routerId : routerIds) {
nvpnManager.removeFromNeutronRouterInterfacesMap(routerId, portName);
}
}
nvpnManager.deleteVpnInterface(portName, null, /* vpn-id */
wrtConfigTxn);
}
// Remove of-port interface for this neutron port
// ELAN interface is also implicitly deleted as part of this operation
LOG.debug("Of-port-interface removal for port {}", portName);
deleteOfPortInterface(port, wrtConfigTxn);
// dissociate fixedIP from floatingIP if associated
nvpnManager.dissociatefixedIPFromFloatingIP(port.getUuid().getValue());
futures.add(wrtConfigTxn.submit());
return futures;
});
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps in project netvirt by opendaylight.
the class NeutronPortChangeListener method handleNeutronPortUpdated.
private void handleNeutronPortUpdated(final Port portoriginal, final Port portupdate) {
final List<FixedIps> portoriginalIps = portoriginal.getFixedIps();
final List<FixedIps> portupdateIps = portupdate.getFixedIps();
if (portoriginalIps == null || portoriginalIps.isEmpty()) {
handleNeutronPortCreated(portupdate);
return;
}
if (portupdateIps == null || portupdateIps.isEmpty()) {
LOG.info("Ignoring portUpdate (fixed_ip removal) for port {} as this case is handled " + "during subnet deletion event.", portupdate.getUuid().getValue());
return;
}
jobCoordinator.enqueueJob("PORT- " + portupdate.getUuid().getValue(), () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
final List<Uuid> originalSnMapsIds = portoriginalIps.stream().map(FixedIps::getSubnetId).collect(Collectors.toList());
final List<Uuid> updateSnMapsIds = portupdateIps.stream().map(FixedIps::getSubnetId).collect(Collectors.toList());
Set<Uuid> originalRouterIds = new HashSet<>();
Set<Uuid> oldVpnIds = new HashSet<Uuid>();
Uuid oldRouterId = null;
for (Uuid snId : originalSnMapsIds) {
if (!updateSnMapsIds.remove(snId)) {
// snId was present in originalSnMapsIds, but not in updateSnMapsIds
Subnetmap subnetMapOld = nvpnManager.removePortsFromSubnetmapNode(snId, portoriginal.getUuid(), null);
if (subnetMapOld != null && subnetMapOld.getVpnId() != null) {
oldVpnIds.add(subnetMapOld.getVpnId());
}
if (subnetMapOld != null && subnetMapOld.getInternetVpnId() != null) {
oldVpnIds.add(subnetMapOld.getInternetVpnId());
}
if (subnetMapOld != null && subnetMapOld.getRouterId() != null) {
originalRouterIds.add(subnetMapOld.getRouterId());
}
}
}
Set<Uuid> newVpnIds = new HashSet();
Set<Uuid> newRouterIds = new HashSet<>();
for (Uuid snId : updateSnMapsIds) {
Subnetmap subnetMapNew = nvpnManager.updateSubnetmapNodeWithPorts(snId, portupdate.getUuid(), null);
if (subnetMapNew != null) {
if (subnetMapNew.getVpnId() != null) {
newVpnIds.add(subnetMapNew.getVpnId());
}
if (subnetMapNew.getInternetVpnId() != null) {
newVpnIds.add(subnetMapNew.getInternetVpnId());
}
if (subnetMapNew.getRouterId() != null) {
newRouterIds.add(subnetMapNew.getRouterId());
}
}
}
WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
if (!oldVpnIds.isEmpty()) {
LOG.info("removing VPN Interface for port {}", portoriginal.getUuid().getValue());
if (!originalRouterIds.isEmpty()) {
for (Uuid routerId : originalRouterIds) {
nvpnManager.removeFromNeutronRouterInterfacesMap(routerId, portoriginal.getUuid().getValue());
}
}
nvpnManager.deleteVpnInterface(portoriginal.getUuid().getValue(), null, /* vpn-id */
wrtConfigTxn);
}
if (!newVpnIds.isEmpty()) {
LOG.info("Adding VPN Interface for port {}", portupdate.getUuid().getValue());
nvpnManager.createVpnInterface(newVpnIds, portupdate, wrtConfigTxn);
if (!newRouterIds.isEmpty()) {
for (Uuid routerId : newRouterIds) {
nvpnManager.addToNeutronRouterInterfacesMap(routerId, portupdate.getUuid().getValue());
}
}
}
})));
}
Aggregations