use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.port._case.Ports 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.@Nullable NetworkType networkType, long segmentationId, boolean isExternalNw) {
try {
InstanceIdentifier<Subnetmap> subnetMapIdentifier = NeutronvpnUtils.buildSubnetMapIdentifier(subnetId);
final ReentrantLock lock = lockForUuid(subnetId);
lock.lock();
try {
LOG.info("createSubnetmapNode: subnet ID {}", subnetId.getValue());
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().withKey(new SubnetmapKey(subnetId)).setId(subnetId).setSubnetIp(subnetIp).setTenantId(tenantId).setNetworkId(networkId).setNetworkType(networkType).setSegmentationId(segmentationId).setExternal(isExternalNw);
LOG.debug("createSubnetmapNode: Adding a new subnet node in Subnetmaps DS for subnet {}", subnetId.getValue());
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, subnetMapIdentifier, subnetmapBuilder.build());
} finally {
lock.unlock();
}
} catch (TransactionCommitFailedException | ExecutionException | InterruptedException 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());
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.port._case.Ports in project netvirt by opendaylight.
the class NeutronPortChangeListener method setExternalGwMac.
private void setExternalGwMac(Port routerGwPort, Uuid routerId) {
// During full-sync networking-odl syncs routers before ports. As such,
// the MAC of the router's gw port is not available to be set when the
// router is written. We catch that here.
InstanceIdentifier<Routers> routersId = NeutronvpnUtils.buildExtRoutersIdentifier(routerId);
Optional<Routers> optionalRouter = null;
try {
optionalRouter = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, routersId);
if (!optionalRouter.isPresent()) {
return;
}
Routers extRouters = optionalRouter.get();
if (extRouters.getExtGwMacAddress() != null) {
return;
}
RoutersBuilder builder = new RoutersBuilder(extRouters);
builder.setExtGwMacAddress(routerGwPort.getMacAddress().getValue());
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routersId, builder.build());
} catch (ExecutionException | InterruptedException e) {
LOG.error("setExternalGwMac: failed to read EXT-Routers for router Id {} rout-Gw port {} due to exception", routerId, routerGwPort, e);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.port._case.Ports in project netvirt by opendaylight.
the class NeutronFloatingToFixedIpMappingChangeListener method clearFromFloatingIpInfo.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void clearFromFloatingIpInfo(String routerName, String fixedNeutronPortName, String fixedIpAddress) {
InstanceIdentifier.InstanceIdentifierBuilder<RouterPorts> routerPortsIdentifierBuilder = InstanceIdentifier.builder(FloatingIpInfo.class).child(RouterPorts.class, new RouterPortsKey(routerName));
try {
Optional<RouterPorts> optionalRouterPorts = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsIdentifierBuilder.build());
if (optionalRouterPorts.isPresent()) {
RouterPorts routerPorts = optionalRouterPorts.get();
Map<PortsKey, Ports> keyPortsMap = routerPorts.nonnullPorts();
Map<InternalToExternalPortMapKey, InternalToExternalPortMap> keyInternalToExternalPortMapMap = new HashMap<InternalToExternalPortMapKey, InternalToExternalPortMap>();
for (Ports ports : keyPortsMap.values()) {
if (Objects.equals(ports.getPortName(), fixedNeutronPortName)) {
keyInternalToExternalPortMapMap = ports.nonnullInternalToExternalPortMap();
break;
}
}
if (keyInternalToExternalPortMapMap.size() == 1) {
removeRouterPortsOrPortsNode(routerName, routerPortsIdentifierBuilder, new ArrayList<Ports>(keyPortsMap.values()), fixedNeutronPortName);
} else {
for (InternalToExternalPortMap intToExtMap : keyInternalToExternalPortMapMap.values()) {
if (Objects.equals(intToExtMap.getInternalIp(), fixedIpAddress)) {
InstanceIdentifier<InternalToExternalPortMap> intExtPortMapIdentifier = routerPortsIdentifierBuilder.child(Ports.class, new PortsKey(fixedNeutronPortName)).child(InternalToExternalPortMap.class, new InternalToExternalPortMapKey(fixedIpAddress)).build();
try (AcquireResult lock = tryRouterLock(fixedIpAddress)) {
if (!lock.wasAcquired()) {
// FIXME: why do we even bother with locking if we do not honor it?!
logTryLockFailure(fixedIpAddress);
}
// remove particular internal-to-external-port-map
LOG.debug("removing particular internal-to-external-port-map {}", keyInternalToExternalPortMapMap);
try {
MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, intExtPortMapIdentifier);
} catch (Exception e) {
LOG.error("Failure in deletion of internal-to-external-port-map {}", keyInternalToExternalPortMapMap, e);
}
}
}
}
}
LOG.debug("Deletion from FloatingIpInfo DS successful for fixedIp {} ", fixedIpAddress);
} else {
LOG.warn("routerPorts for router {} - fixedIp {} not found", routerName, fixedIpAddress);
}
} catch (RuntimeException | ExecutionException | InterruptedException e) {
LOG.error("Failed to delete internal-to-external-port-map from FloatingIpInfo DS for fixed Ip {}", fixedIpAddress, e);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.port._case.Ports in project netvirt by opendaylight.
the class NeutronFloatingToFixedIpMappingChangeListener method removeRouterPortsOrPortsNode.
private void removeRouterPortsOrPortsNode(String routerName, InstanceIdentifier.InstanceIdentifierBuilder<RouterPorts> routerPortsIdentifierBuilder, List<Ports> portsList, String fixedNeutronPortName) {
if (portsList.size() == 1) {
// remove entire routerPorts node
try (AcquireResult lock = tryRouterLock(routerName)) {
if (!lock.wasAcquired()) {
// FIXME: why do we even bother with locking if we do not honor it?!
logTryLockFailure(routerName);
}
LOG.debug("removing routerPorts node: {} ", routerName);
MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsIdentifierBuilder.build());
}
} else {
// remove entire ports node under this routerPorts node
try (AcquireResult lock = tryRouterLock(fixedNeutronPortName)) {
if (!lock.wasAcquired()) {
// FIXME: why do we even bother with locking if we do not honor it?!
logTryLockFailure(fixedNeutronPortName);
}
LOG.debug("removing ports node {} under routerPorts node {}", fixedNeutronPortName, routerName);
MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsIdentifierBuilder.child(Ports.class, new PortsKey(fixedNeutronPortName)).build());
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.port._case.Ports in project netvirt by opendaylight.
the class NeutronFloatingToFixedIpMappingChangeListener method dissociatefixedIPFromFloatingIP.
protected void dissociatefixedIPFromFloatingIP(String fixedNeutronPortName) {
InstanceIdentifier.InstanceIdentifierBuilder<FloatingIpInfo> floatingIpInfoIdentifierBuilder = InstanceIdentifier.builder(FloatingIpInfo.class);
try {
Optional<FloatingIpInfo> optionalFloatingIPInfo = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, floatingIpInfoIdentifierBuilder.build());
if (optionalFloatingIPInfo.isPresent()) {
Map<RouterPortsKey, RouterPorts> keyRouterPortsMap = optionalFloatingIPInfo.get().getRouterPorts();
if (keyRouterPortsMap != null && !keyRouterPortsMap.isEmpty()) {
for (RouterPorts routerPorts : keyRouterPortsMap.values()) {
Map<PortsKey, Ports> keyPortsMap = routerPorts.getPorts();
if (keyPortsMap != null && !keyPortsMap.isEmpty()) {
for (Ports ports : keyPortsMap.values()) {
if (Objects.equals(ports.getPortName(), fixedNeutronPortName)) {
String routerName = routerPorts.getRouterId();
InstanceIdentifier.InstanceIdentifierBuilder<RouterPorts> routerPortsIdentifierBuilder = floatingIpInfoIdentifierBuilder.child(RouterPorts.class, new RouterPortsKey(routerName));
removeRouterPortsOrPortsNode(routerName, routerPortsIdentifierBuilder, new ArrayList<Ports>(keyPortsMap.values()), fixedNeutronPortName);
LOG.debug("Deletion from FloatingIpInfo DS successful for fixedIP neutron port {} ", fixedNeutronPortName);
break;
}
}
}
}
} else {
LOG.debug("No router present containing fixed to floating IP association(s)");
}
} else {
LOG.debug("FloatingIPInfo DS empty. Hence, no router present containing fixed to floating IP " + "association(s)");
}
} catch (ExecutionException | InterruptedException e) {
LOG.error("Failed to dissociate fixedIP from FloatingIpInfo DS for neutron port {}", fixedNeutronPortName, e);
}
}
Aggregations