use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPortsKey in project netvirt by opendaylight.
the class RouterPortsListener method add.
@Override
protected void add(final InstanceIdentifier<RouterPorts> identifier, final RouterPorts routerPorts) {
LOG.trace("add : key:{} value:{}", routerPorts.getKey(), routerPorts);
Optional<RouterPorts> optRouterPorts = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, identifier);
if (optRouterPorts.isPresent()) {
RouterPorts ports = optRouterPorts.get();
String routerName = ports.getRouterId();
MDSALUtil.syncUpdate(dataBroker, LogicalDatastoreType.OPERATIONAL, identifier, new RouterPortsBuilder().setKey(new RouterPortsKey(routerName)).setRouterId(routerName).setExternalNetworkId(routerPorts.getExternalNetworkId()).build());
} else {
String routerName = routerPorts.getRouterId();
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, identifier, new RouterPortsBuilder().setKey(new RouterPortsKey(routerName)).setRouterId(routerName).setExternalNetworkId(routerPorts.getExternalNetworkId()).build());
}
// Check if the router is associated with any BGP VPN and update the association
String routerName = routerPorts.getRouterId();
Uuid vpnName = NatUtil.getVpnForRouter(dataBroker, routerName);
if (vpnName != null) {
InstanceIdentifier<Routermapping> routerMappingId = NatUtil.getRouterVpnMappingId(routerName);
Optional<Routermapping> optRouterMapping = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, routerMappingId);
if (!optRouterMapping.isPresent()) {
Long vpnId = NatUtil.getVpnId(dataBroker, vpnName.getValue());
LOG.debug("add : Updating router {} to VPN {} association with Id {}", routerName, vpnName, vpnId);
Routermapping routerMapping = new RoutermappingBuilder().setKey(new RoutermappingKey(routerName)).setRouterName(routerName).setVpnName(vpnName.getValue()).setVpnId(vpnId).build();
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, routerMappingId, routerMapping);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPortsKey in project netvirt by opendaylight.
the class NeutronFloatingToFixedIpMappingChangeListener method dissociatefixedIPFromFloatingIP.
protected void dissociatefixedIPFromFloatingIP(String fixedNeutronPortName) {
boolean isLockAcquired = false;
InstanceIdentifier.InstanceIdentifierBuilder<FloatingIpInfo> floatingIpInfoIdentifierBuilder = InstanceIdentifier.builder(FloatingIpInfo.class);
try {
Optional<FloatingIpInfo> optionalFloatingIPInfo = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, floatingIpInfoIdentifierBuilder.build());
if (optionalFloatingIPInfo.isPresent()) {
List<RouterPorts> routerPortsList = optionalFloatingIPInfo.get().getRouterPorts();
if (routerPortsList != null && !routerPortsList.isEmpty()) {
for (RouterPorts routerPorts : routerPortsList) {
List<Ports> portsList = routerPorts.getPorts();
if (portsList != null && !portsList.isEmpty()) {
for (Ports ports : portsList) {
if (ports.getPortName().equals(fixedNeutronPortName)) {
String routerName = routerPorts.getRouterId();
InstanceIdentifier.InstanceIdentifierBuilder<RouterPorts> routerPortsIdentifierBuilder = floatingIpInfoIdentifierBuilder.child(RouterPorts.class, new RouterPortsKey(routerName));
removeRouterPortsOrPortsNode(routerName, routerPortsIdentifierBuilder, portsList, fixedNeutronPortName, isLockAcquired);
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 (ReadFailedException e) {
LOG.error("Failed to dissociate fixedIP from FloatingIpInfo DS for neutron port {}", fixedNeutronPortName, e);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPortsKey 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) {
boolean isLockAcquired = false;
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();
List<Ports> portsList = routerPorts.getPorts();
List<InternalToExternalPortMap> intExtPortMap = new ArrayList<>();
for (Ports ports : portsList) {
if (ports.getPortName().equals(fixedNeutronPortName)) {
intExtPortMap = ports.getInternalToExternalPortMap();
break;
}
}
if (intExtPortMap.size() == 1) {
removeRouterPortsOrPortsNode(routerName, routerPortsIdentifierBuilder, portsList, fixedNeutronPortName, isLockAcquired);
} else {
for (InternalToExternalPortMap intToExtMap : intExtPortMap) {
if (intToExtMap.getInternalIp().equals(fixedIpAddress)) {
InstanceIdentifier<InternalToExternalPortMap> intExtPortMapIdentifier = routerPortsIdentifierBuilder.child(Ports.class, new PortsKey(fixedNeutronPortName)).child(InternalToExternalPortMap.class, new InternalToExternalPortMapKey(fixedIpAddress)).build();
try {
// remove particular internal-to-external-port-map
isLockAcquired = routerLock.tryLock(fixedIpAddress, LOCK_WAIT_TIME, TimeUnit.SECONDS);
LOG.debug("removing particular internal-to-external-port-map {}", intExtPortMap);
MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, intExtPortMapIdentifier);
} catch (Exception e) {
LOG.error("Failure in deletion of internal-to-external-port-map {}", intExtPortMap, e);
} finally {
if (isLockAcquired) {
routerLock.unlock(fixedIpAddress);
}
}
}
}
}
LOG.debug("Deletion from FloatingIpInfo DS successful for fixedIp {} ", fixedIpAddress);
} else {
LOG.warn("routerPorts for router {} - fixedIp {} not found", routerName, fixedIpAddress);
}
} catch (RuntimeException | ReadFailedException 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.netvirt.natservice.rev160111.floating.ip.info.RouterPortsKey in project netvirt by opendaylight.
the class NeutronFloatingToFixedIpMappingChangeListener method addToFloatingIpInfo.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void addToFloatingIpInfo(String routerName, Uuid extNetworkId, String fixedNeutronPortName, String fixedIpAddress, String floatingIpAddress, Uuid floatingIpId) {
RouterPortsBuilder routerPortsBuilder;
boolean isLockAcquired = false;
InstanceIdentifier<RouterPorts> routerPortsIdentifier = InstanceIdentifier.builder(FloatingIpInfo.class).child(RouterPorts.class, new RouterPortsKey(routerName)).build();
try {
Optional<RouterPorts> optionalRouterPorts = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsIdentifier);
if (optionalRouterPorts.isPresent()) {
LOG.debug("Updating routerPorts node {} in floatingIpInfo DS for floating IP {} on fixed " + "neutron port {} : ", routerName, floatingIpAddress, fixedNeutronPortName);
routerPortsBuilder = new RouterPortsBuilder(optionalRouterPorts.get());
} else {
LOG.debug("Creating new routerPorts node {} in floatingIpInfo DS for floating IP {} on fixed " + "neutron port {} : ", routerName, floatingIpAddress, fixedNeutronPortName);
routerPortsBuilder = new RouterPortsBuilder().setKey(new RouterPortsKey(routerName)).setRouterId(routerName);
}
if (extNetworkId != null) {
routerPortsBuilder.setExternalNetworkId(extNetworkId);
}
if (fixedNeutronPortName != null) {
List<Ports> portsList = routerPortsBuilder.getPorts();
if (portsList == null) {
portsList = new ArrayList<>();
}
PortsBuilder fixedNeutronPortBuilder = null;
for (Ports neutronPort : portsList) {
if (neutronPort.getPortName().equals(fixedNeutronPortName)) {
fixedNeutronPortBuilder = new PortsBuilder(neutronPort);
break;
}
}
if (fixedNeutronPortBuilder == null) {
fixedNeutronPortBuilder = new PortsBuilder().setKey(new PortsKey(fixedNeutronPortName)).setPortName(fixedNeutronPortName);
}
if (fixedIpAddress != null) {
List<InternalToExternalPortMap> intExtPortMapList = fixedNeutronPortBuilder.getInternalToExternalPortMap();
if (intExtPortMapList == null) {
intExtPortMapList = new ArrayList<>();
}
InternalToExternalPortMap intExtPortMap = new InternalToExternalPortMapBuilder().setKey(new InternalToExternalPortMapKey(fixedIpAddress)).setInternalIp(fixedIpAddress).setExternalIp(floatingIpAddress).setExternalId(floatingIpId).setLabel(null).build();
intExtPortMapList.add(intExtPortMap);
fixedNeutronPortBuilder.setInternalToExternalPortMap(intExtPortMapList);
}
portsList.add(fixedNeutronPortBuilder.build());
routerPortsBuilder.setPorts(portsList);
}
isLockAcquired = routerLock.tryLock(routerName, LOCK_WAIT_TIME, TimeUnit.SECONDS);
LOG.debug("Creating/Updating routerPorts node {} in floatingIpInfo DS for floating IP {} on fixed " + "neutron port {} : ", routerName, floatingIpAddress, fixedNeutronPortName);
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsIdentifier, routerPortsBuilder.build());
LOG.debug("FloatingIpInfo DS updated for floating IP {} ", floatingIpAddress);
} catch (ReadFailedException | RuntimeException e) {
LOG.error("addToFloatingIpInfo failed for floating IP: {} ", floatingIpAddress, e);
} finally {
if (isLockAcquired) {
routerLock.unlock(routerName);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPortsKey in project netvirt by opendaylight.
the class NeutronvpnNatManager method removeRouterFromFloatingIpInfo.
private void removeRouterFromFloatingIpInfo(Router update, DataBroker broker) {
Uuid routerId = update.getUuid();
InstanceIdentifier.InstanceIdentifierBuilder<RouterPorts> routerPortsIdentifierBuilder = InstanceIdentifier.builder(FloatingIpInfo.class).child(RouterPorts.class, new RouterPortsKey(routerId.getValue()));
try {
Optional<RouterPorts> optionalRouterPorts = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsIdentifierBuilder.build());
if (optionalRouterPorts.isPresent()) {
SingleTransactionDataBroker.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, routerPortsIdentifierBuilder.build());
}
} catch (ReadFailedException | TransactionCommitFailedException e) {
LOG.error("Failed to read from FloatingIpInfo DS for routerid {}", routerId, e);
}
}
Aggregations