use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps in project netvirt by opendaylight.
the class NeutronPortChangeListener method addInterfaceInfo.
protected void addInterfaceInfo(Port port, FixedIps fixedip) {
if (port.getDeviceOwner().equalsIgnoreCase(Ipv6Constants.NETWORK_ROUTER_INTERFACE)) {
LOG.info("IPv6: addInterfaceInfo is invoked for a router interface {}, fixedIp: {}", port, fixedip);
// Add router interface
ifMgr.addRouterIntf(port.getUuid(), new Uuid(port.getDeviceId()), fixedip.getSubnetId(), port.getNetworkId(), fixedip.getIpAddress(), port.getMacAddress().getValue(), port.getDeviceOwner());
} else {
LOG.info("IPv6: addInterfaceInfo is invoked for a host interface {}, fixedIp: {}", port, fixedip);
// Add host interface
ifMgr.addHostIntf(port.getUuid(), fixedip.getSubnetId(), port.getNetworkId(), fixedip.getIpAddress(), port.getMacAddress().getValue(), port.getDeviceOwner());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps in project netvirt by opendaylight.
the class DhcpNeutronPortListener method update.
@Override
protected void update(InstanceIdentifier<Port> identifier, Port original, Port update) {
LOG.trace("Port changed to {}", update);
// With Ipv6 changes we can get ipv4 subnets later. The below check is to support such scenario.
if (original.getFixedIps().size() < update.getFixedIps().size()) {
final String interfaceName = update.getUuid().getValue();
List<FixedIps> updatedFixedIps = update.getFixedIps();
// Need to check only the newly added fixed ip.
updatedFixedIps.removeAll(original.getFixedIps());
Subnet subnet = dhcpManager.getNeutronSubnet(updatedFixedIps);
if (null == subnet || !subnet.isEnableDhcp()) {
LOG.trace("Subnet is null/not ipv4 or not enabled {}", subnet);
return;
}
// Binding the DHCP service for an existing port because of subnet change.
jobCoordinator.enqueueJob(DhcpServiceUtils.getJobKey(interfaceName), () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
LOG.debug("Binding DHCP service for interface {}", interfaceName);
DhcpServiceUtils.bindDhcpService(interfaceName, NwConstants.DHCP_TABLE, tx);
})), DhcpMConstants.RETRY_COUNT);
jobCoordinator.enqueueJob(DhcpServiceUtils.getJobKey(interfaceName), () -> {
BigInteger dpnId = interfaceManager.getDpnForInterface(interfaceName);
if (dpnId == null || dpnId.equals(DhcpMConstants.INVALID_DPID)) {
LOG.trace("Unable to install the DHCP flow since dpn is not available");
return Collections.emptyList();
}
return Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(tx -> dhcpManager.installDhcpEntries(dpnId, DhcpServiceUtils.getAndUpdateVmMacAddress(tx, interfaceName, dhcpManager), tx)));
}, DhcpMConstants.RETRY_COUNT);
}
if (!isVnicTypeDirectOrMacVtap(update)) {
LOG.trace("Port updated is normal {}", update.getUuid());
if (isVnicTypeDirectOrMacVtap(original)) {
LOG.trace("Original Port was direct/macvtap {} so removing flows and cache entry if any", update.getUuid());
removePort(original);
}
return;
}
if (!isVnicTypeDirectOrMacVtap(original)) {
LOG.trace("Original port was normal and updated is direct. Calling addPort()");
addPort(update);
return;
}
String macOriginal = getMacAddress(original);
String macUpdated = getMacAddress(update);
String segmentationIdOriginal = DhcpServiceUtils.getSegmentationId(original.getNetworkId(), broker);
String segmentationIdUpdated = DhcpServiceUtils.getSegmentationId(update.getNetworkId(), broker);
if (macOriginal != null && !macOriginal.equalsIgnoreCase(macUpdated) && segmentationIdOriginal != null && !segmentationIdOriginal.equalsIgnoreCase(segmentationIdUpdated)) {
LOG.trace("Mac/segment id has changed");
dhcpExternalTunnelManager.removeVniMacToPortCache(new BigInteger(segmentationIdOriginal), macOriginal);
dhcpExternalTunnelManager.updateVniMacToPortCache(new BigInteger(segmentationIdUpdated), macUpdated, update);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps in project netvirt by opendaylight.
the class NeutronvpnNatManager method handleExternalFixedIpsForRouter.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void handleExternalFixedIpsForRouter(Router update) {
Uuid routerId = update.getUuid();
InstanceIdentifier<Routers> routersIdentifier = NeutronvpnUtils.buildExtRoutersIdentifier(routerId);
try {
Optional<Routers> optionalRouters = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier);
LOG.trace("Updating External Fixed IPs Routers node {}", routerId.getValue());
if (optionalRouters.isPresent()) {
RoutersBuilder builder = new RoutersBuilder(optionalRouters.get());
List<ExternalIps> externalIps = new ArrayList<>();
for (ExternalFixedIps fixedIps : update.getExternalGatewayInfo().getExternalFixedIps()) {
addExternalFixedIpToExternalIpsList(externalIps, fixedIps);
}
builder.setExternalIps(externalIps);
updateExternalSubnetsForRouter(routerId, update.getExternalGatewayInfo().getExternalNetworkId(), update.getExternalGatewayInfo().getExternalFixedIps());
Routers routerss = builder.build();
LOG.trace("Updating external fixed ips for router {} with value {}", routerId.getValue(), routerss);
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIdentifier, routerss);
LOG.trace("Added External Fixed IPs successfully for Routers to CONFIG Datastore");
}
} catch (TransactionCommitFailedException | ReadFailedException ex) {
LOG.error("Updating extfixedips for {} in extrouters 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 NeutronvpnNatManager method externalFixedIpsChanged.
private boolean externalFixedIpsChanged(Router orig, Router update) {
ExternalGatewayInfo origExtGw = null;
ExternalGatewayInfo newExtGw = null;
if (orig != null && orig.getExternalGatewayInfo() != null) {
origExtGw = orig.getExternalGatewayInfo();
}
if (update != null && update.getExternalGatewayInfo() != null) {
newExtGw = update.getExternalGatewayInfo();
}
if (origExtGw == null && newExtGw != null && newExtGw.getExternalFixedIps() != null && !newExtGw.getExternalFixedIps().isEmpty()) {
return true;
}
if (newExtGw == null && origExtGw != null && origExtGw.getExternalFixedIps() != null && !origExtGw.getExternalFixedIps().isEmpty()) {
return true;
}
if (origExtGw != null && newExtGw != null) {
if (origExtGw.getExternalFixedIps() != null) {
if (!origExtGw.getExternalFixedIps().isEmpty()) {
if (newExtGw.getExternalFixedIps() != null && !newExtGw.getExternalFixedIps().isEmpty()) {
List<ExternalFixedIps> origExtFixedIps = origExtGw.getExternalFixedIps();
HashSet<String> origFixedIpSet = new HashSet<>();
for (ExternalFixedIps fixedIps : origExtFixedIps) {
origFixedIpSet.add(fixedIps.getIpAddress().getIpv4Address().getValue());
}
List<ExternalFixedIps> newExtFixedIps = newExtGw.getExternalFixedIps();
HashSet<String> updFixedIpSet = new HashSet<>();
for (ExternalFixedIps fixedIps : newExtFixedIps) {
updFixedIpSet.add(fixedIps.getIpAddress().getIpv4Address().getValue());
}
// returns true if external subnets have changed
return !origFixedIpSet.equals(updFixedIpSet) ? true : false;
}
return true;
} else if (newExtGw.getExternalFixedIps() != null && !newExtGw.getExternalFixedIps().isEmpty()) {
return true;
}
} else if (newExtGw.getExternalFixedIps() != null && !newExtGw.getExternalFixedIps().isEmpty()) {
return true;
}
}
return false;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps in project netvirt by opendaylight.
the class NeutronvpnUtils method getFixedIpsDelta.
/**
* Gets the fixed ips delta.
*
* @param port1FixedIps the port 1 fixed ips
* @param port2FixedIps the port 2 fixed ips
* @return the fixed ips delta
*/
protected static List<FixedIps> getFixedIpsDelta(List<FixedIps> port1FixedIps, List<FixedIps> port2FixedIps) {
if (port1FixedIps == null) {
return null;
}
if (port2FixedIps == null) {
return port1FixedIps;
}
List<FixedIps> list1 = new ArrayList<>(port1FixedIps);
List<FixedIps> list2 = new ArrayList<>(port2FixedIps);
for (Iterator<FixedIps> iterator = list1.iterator(); iterator.hasNext(); ) {
FixedIps fixedIps1 = iterator.next();
for (FixedIps fixedIps2 : list2) {
if (fixedIps1.getIpAddress().equals(fixedIps2.getIpAddress())) {
iterator.remove();
break;
}
}
}
return list1;
}
Aggregations