Search in sources :

Example 21 with L2GatewayDevice

use of org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice in project netvirt by opendaylight.

the class DhcpUCastMacListener method add.

@Override
protected void add(InstanceIdentifier<LocalUcastMacs> identifier, LocalUcastMacs add) {
    NodeId torNodeId = identifier.firstKeyOf(Node.class).getNodeId();
    InstanceIdentifier<LogicalSwitches> logicalSwitchRef = (InstanceIdentifier<LogicalSwitches>) add.getLogicalSwitchRef().getValue();
    Optional<LogicalSwitches> logicalSwitchOptional = MDSALUtil.read(broker, LogicalDatastoreType.OPERATIONAL, logicalSwitchRef);
    if (!logicalSwitchOptional.isPresent()) {
        LOG.error("Logical Switch ref doesn't have data {}", logicalSwitchRef);
        return;
    }
    LogicalSwitches logicalSwitch = logicalSwitchOptional.get();
    String elanInstanceName = logicalSwitch.getHwvtepNodeName().getValue();
    String macAddress = add.getMacEntryKey().getValue();
    BigInteger vni = new BigInteger(logicalSwitch.getTunnelKey());
    Port port = dhcpExternalTunnelManager.readVniMacToPortCache(vni, macAddress);
    if (port == null) {
        LOG.trace("No neutron port created for macAddress {}, tunnelKey {}", macAddress, vni);
        return;
    }
    L2GatewayDevice device = ElanL2GwCacheUtils.getL2GatewayDeviceFromCache(elanInstanceName, torNodeId.getValue());
    if (device == null) {
        LOG.error("Logical Switch Device with name {} is not present in L2GWCONN cache", elanInstanceName);
        return;
    }
    IpAddress tunnelIp = device.getTunnelIp();
    Subnet subnet = dhcpManager.getNeutronSubnet(port);
    if (null != subnet && !subnet.isEnableDhcp()) {
        dhcpExternalTunnelManager.updateExistingVMTunnelIPCache(tunnelIp, elanInstanceName, macAddress);
        LOG.warn("DhcpUCastMacListener add: flag for the subnetId {} is False so Table 18 entries are not added", subnet.getUuid());
        return;
    }
    BigInteger designatedDpnId = dhcpExternalTunnelManager.readDesignatedSwitchesForExternalTunnel(tunnelIp, elanInstanceName);
    if (designatedDpnId == null || designatedDpnId.equals(DhcpMConstants.INVALID_DPID)) {
        LOG.trace("Unable to install flows for macAddress {}. TunnelIp {}, elanInstanceName {}, designatedDpn {} ", macAddress, tunnelIp, elanInstanceName, designatedDpnId);
        dhcpExternalTunnelManager.updateLocalCache(tunnelIp, elanInstanceName, macAddress);
        return;
    }
    dhcpExternalTunnelManager.installDhcpFlowsForVms(tunnelIp, elanInstanceName, DhcpServiceUtils.getListOfDpns(broker), designatedDpnId, macAddress);
}
Also used : LogicalSwitches(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) Port(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) BigInteger(java.math.BigInteger) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) Subnet(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet) L2GatewayDevice(org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice)

Example 22 with L2GatewayDevice

use of org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice in project netvirt by opendaylight.

the class AddL2GwDevicesToTransportZoneJob method call.

/*
     * (non-Javadoc)
     *
     * @see java.util.concurrent.Callable#call()
     */
@Override
@SuppressWarnings("checkstyle:IllegalCatch")
public List<ListenableFuture<Void>> call() {
    LOG.debug("Running AddL2GwDevicesToTransportZone job for {}", this.transportZone.getZoneName());
    try {
        // transport zone. Doesn't matter if tz already has data or not.
        for (L2GatewayDevice l2gwDevice : l2GatewayCache.getAll()) {
            if (!l2gwDevice.getL2GatewayIds().isEmpty()) {
                LOG.debug("Adding l2gw device [{}] to transport zone [{}]", l2gwDevice.getDeviceName(), this.transportZone.getZoneName());
                L2GatewayUtils.createItmTunnels(itmRpcService, l2gwDevice.getHwvtepNodeId(), l2gwDevice.getDeviceName(), l2gwDevice.getTunnelIp());
            }
        }
    } catch (Exception e) {
        LOG.error("Failed during AddL2GwDevicesToTransportZone job ", e);
    }
    return Collections.emptyList();
}
Also used : L2GatewayDevice(org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice)

Example 23 with L2GatewayDevice

use of org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice in project netvirt by opendaylight.

the class L2GatewayListener method update.

@Override
protected void update(InstanceIdentifier<L2gateway> identifier, L2gateway original, L2gateway update) {
    LOG.trace("Updating L2gateway : key: {}, original value={}, update value={}", identifier, original, update);
    List<L2gatewayConnection> connections = l2gwService.getAssociatedL2GwConnections(Sets.newHashSet(update.getUuid()));
    if (connections == null) {
        LOG.warn("There are no connections associated with l2 gateway uuid {} name {}", update.getUuid(), update.getName());
        return;
    }
    if (original.getDevices() == null) {
        connections.forEach((connection) -> l2gwService.addL2GatewayConnection(connection));
        return;
    }
    jobCoordinator.enqueueJob("l2gw.update", () -> {
        ReadWriteTransaction transaction = dataBroker.newReadWriteTransaction();
        DeviceInterfaces updatedDeviceInterfaces = new DeviceInterfaces(update);
        List<ListenableFuture<Void>> fts = new ArrayList<>();
        original.getDevices().stream().filter((originalDevice) -> originalDevice.getInterfaces() != null).forEach((originalDevice) -> {
            String deviceName = originalDevice.getDeviceName();
            L2GatewayDevice l2GwDevice = l2GatewayCache.get(deviceName);
            NodeId physicalSwitchNodeId = HwvtepSouthboundUtils.createManagedNodeId(new NodeId(l2GwDevice.getHwvtepNodeId()), deviceName);
            originalDevice.getInterfaces().stream().filter((intf) -> !updatedDeviceInterfaces.containsInterface(deviceName, intf.getInterfaceName())).forEach((intf) -> {
                connections.forEach((connection) -> {
                    Integer vlanId = connection.getSegmentId();
                    if (intf.getSegmentationIds() != null && !intf.getSegmentationIds().isEmpty()) {
                        for (Integer vlan : intf.getSegmentationIds()) {
                            HwvtepUtils.deleteVlanBinding(transaction, physicalSwitchNodeId, intf.getInterfaceName(), vlan);
                        }
                    } else {
                        LOG.debug("Deleting vlan binding {} {} {}", physicalSwitchNodeId, intf.getInterfaceName(), vlanId);
                        HwvtepUtils.deleteVlanBinding(transaction, physicalSwitchNodeId, intf.getInterfaceName(), vlanId);
                    }
                });
            });
        });
        fts.add(transaction.submit());
        Futures.addCallback(fts.get(0), new FutureCallback<Void>() {

            @Override
            public void onSuccess(Void success) {
                LOG.debug("Successfully deleted vlan bindings for l2gw update {}", update);
                connections.forEach((l2GwConnection) -> l2gwService.addL2GatewayConnection(l2GwConnection, null, update));
            }

            @Override
            public void onFailure(Throwable throwable) {
                LOG.error("Failed to delete vlan bindings as part of l2gw udpate {}", update);
            }
        }, MoreExecutors.directExecutor());
        return fts;
    }, SystemPropertyReader.getDataStoreJobCoordinatorMaxRetries());
}
Also used : HwvtepSouthboundConstants(org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundConstants) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) IL2gwService(org.opendaylight.netvirt.elanmanager.api.IL2gwService) L2gatewayConnection(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.l2gatewayconnections.L2gatewayConnection) Interfaces(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.devices.Interfaces) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) L2gateways(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.L2gateways) L2gateway(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.l2gateways.L2gateway) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Singleton(javax.inject.Singleton) EntityOwnershipService(org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService) Neutron(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron) HwvtepUtils(org.opendaylight.genius.utils.hwvtep.HwvtepUtils) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) AsyncClusteredDataTreeChangeListenerBase(org.opendaylight.genius.datastoreutils.AsyncClusteredDataTreeChangeListenerBase) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) Map(java.util.Map) MDSALUtil(org.opendaylight.genius.mdsalutil.MDSALUtil) HwvtepSouthboundUtils(org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundUtils) Devices(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices) Logger(org.slf4j.Logger) EntityOwnershipUtils(org.opendaylight.genius.utils.clustering.EntityOwnershipUtils) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) JobCoordinator(org.opendaylight.infrautils.jobcoordinator.JobCoordinator) Set(java.util.Set) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) SystemPropertyReader(org.opendaylight.genius.utils.SystemPropertyReader) Sets(com.google.common.collect.Sets) FutureCallback(com.google.common.util.concurrent.FutureCallback) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) PostConstruct(javax.annotation.PostConstruct) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) L2gatewayConnections(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.L2gatewayConnections) L2GatewayCache(org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayCache) L2GatewayDevice(org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) ItmRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService) ArrayList(java.util.ArrayList) L2GatewayDevice(org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) L2gatewayConnection(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.l2gatewayconnections.L2gatewayConnection)

Example 24 with L2GatewayDevice

use of org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice in project netvirt by opendaylight.

the class ElanL2GatewayUtils method getOtherDevicesMacs.

/**
 * Gets the l2 gateway devices ucast local macs as remote ucast macs.
 *
 * @param elanName
 *            the elan name
 * @param l2GatewayDeviceToBeConfigured
 *            the l2 gateway device to be configured
 * @param hwVtepNodeId
 *            the hw vtep node Id to be configured
 * @param logicalSwitchName
 *            the logical switch name
 * @return the l2 gateway devices macs as remote ucast macs
 */
public static List<RemoteUcastMacs> getOtherDevicesMacs(String elanName, L2GatewayDevice l2GatewayDeviceToBeConfigured, NodeId hwVtepNodeId, String logicalSwitchName) {
    List<RemoteUcastMacs> lstRemoteUcastMacs = new ArrayList<>();
    ConcurrentMap<String, L2GatewayDevice> elanL2GwDevicesFromCache = ElanL2GwCacheUtils.getInvolvedL2GwDevices(elanName);
    if (elanL2GwDevicesFromCache != null) {
        for (L2GatewayDevice otherDevice : elanL2GwDevicesFromCache.values()) {
            if (l2GatewayDeviceToBeConfigured.getHwvtepNodeId().equals(otherDevice.getHwvtepNodeId())) {
                continue;
            }
            if (!areMLAGDevices(l2GatewayDeviceToBeConfigured, otherDevice)) {
                for (LocalUcastMacs localUcastMac : otherDevice.getUcastLocalMacs()) {
                    HwvtepPhysicalLocatorAugmentation physLocatorAug = HwvtepSouthboundUtils.createHwvtepPhysicalLocatorAugmentation(String.valueOf(otherDevice.getTunnelIp().getValue()));
                    RemoteUcastMacs remoteUcastMac = HwvtepSouthboundUtils.createRemoteUcastMac(hwVtepNodeId, localUcastMac.getMacEntryKey().getValue().toLowerCase(Locale.getDefault()), localUcastMac.getIpaddr(), logicalSwitchName, physLocatorAug);
                    lstRemoteUcastMacs.add(remoteUcastMac);
                }
            }
        }
    }
    return lstRemoteUcastMacs;
}
Also used : LocalUcastMacs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalUcastMacs) RemoteUcastMacs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteUcastMacs) HwvtepPhysicalLocatorAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalLocatorAugmentation) ArrayList(java.util.ArrayList) L2GatewayDevice(org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice)

Example 25 with L2GatewayDevice

use of org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice in project netvirt by opendaylight.

the class ElanL2GatewayUtils method deleteElanL2GwDevicesUcastLocalMacsFromDpn.

/**
 * Delete elan l2 gateway devices ucast local macs from dpn.
 *
 * @param elanName
 *            the elan name
 * @param dpnId
 *            the dpn id
 */
public void deleteElanL2GwDevicesUcastLocalMacsFromDpn(final String elanName, final BigInteger dpnId) {
    ConcurrentMap<String, L2GatewayDevice> elanL2GwDevices = ElanL2GwCacheUtils.getInvolvedL2GwDevices(elanName);
    if (elanL2GwDevices == null || elanL2GwDevices.isEmpty()) {
        LOG.trace("No L2 gateway devices in Elan [{}] cache.", elanName);
        return;
    }
    final ElanInstance elan = elanInstanceCache.get(elanName).orNull();
    if (elan == null) {
        LOG.error("Could not find Elan by name: {}", elanName);
        return;
    }
    LOG.info("Deleting Elan [{}] L2GatewayDevices UcastLocalMacs from Dpn [{}]", elanName, dpnId);
    final Long elanTag = elan.getElanTag();
    for (final L2GatewayDevice l2GwDevice : elanL2GwDevices.values()) {
        getL2GwDeviceLocalMacsAndRunCallback(elan.getElanInstanceName(), l2GwDevice, (localMacs) -> {
            for (MacAddress mac : localMacs) {
                String jobKey = elanName + ":" + mac.getValue();
                elanClusterUtils.runOnlyInOwnerNode(jobKey, () -> elanDmacUtils.deleteDmacFlowsToExternalMac(elanTag, dpnId, l2GwDevice.getHwvtepNodeId(), mac.getValue()));
            }
            return null;
        });
    }
}
Also used : ElanInstance(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) L2GatewayDevice(org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice)

Aggregations

L2GatewayDevice (org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice)41 NodeId (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId)16 ArrayList (java.util.ArrayList)12 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)12 Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)11 ElanInstance (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance)10 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)7 BigInteger (java.math.BigInteger)7 Devices (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices)7 LogicalSwitches (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches)7 List (java.util.List)5 Set (java.util.Set)5 Inject (javax.inject.Inject)5 Singleton (javax.inject.Singleton)5 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)5 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)5 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)5 MDSALUtil (org.opendaylight.genius.mdsalutil.MDSALUtil)5 HwvtepSouthboundUtils (org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundUtils)5 HwvtepUtils (org.opendaylight.genius.utils.hwvtep.HwvtepUtils)5