Search in sources :

Example 11 with Operations

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.ops.rev170711.service.ops.services.Operations in project genius by opendaylight.

the class OvsdbNodeListener method update.

@Override
public void update(@Nonnull Node originalOvsdbNode, Node updatedOvsdbNode) {
    String newLocalIp = null;
    String oldLocalIp = null;
    String tzName = null;
    String oldTzName = null;
    String oldDpnBridgeName = null;
    String newDpnBridgeName = null;
    boolean newOfTunnel = false;
    boolean isTepInfoUpdated = false;
    boolean isTepInfoDeleted = false;
    boolean isLocalIpAdded = false;
    boolean isLocalIpRemoved = false;
    boolean isLocalIpUpdated;
    boolean isTzChanged = false;
    boolean isDpnBrChanged = false;
    LOG.trace("OvsdbNodeListener called for Ovsdb Node ({}) Update.", originalOvsdbNode.getNodeId().getValue());
    LOG.trace("Update: originalOvsdbNode: {}  updatedOvsdbNode: {}", originalOvsdbNode, updatedOvsdbNode);
    // addTep, as TEP would not be added in node add case above
    if (isBridgeDpIdAdded(originalOvsdbNode, updatedOvsdbNode)) {
        processBridgeUpdate(updatedOvsdbNode);
        return;
    }
    // get OVSDB TEP info from old ovsdb node
    OvsdbTepInfo newTepInfoObj = getOvsdbTepInfo(updatedOvsdbNode.getAugmentation(OvsdbNodeAugmentation.class));
    // get OVSDB TEP info from new ovsdb node
    OvsdbTepInfo oldTepInfoObj = getOvsdbTepInfo(originalOvsdbNode.getAugmentation(OvsdbNodeAugmentation.class));
    if (oldTepInfoObj == null && newTepInfoObj == null) {
        LOG.trace("Tep Info is not received in old and new Ovsdb Nodes.");
        return;
    }
    if (oldTepInfoObj != null && newTepInfoObj == null) {
        isTepInfoDeleted = true;
        LOG.trace("Tep Info is deleted from Ovsdb node: {}", originalOvsdbNode.getNodeId().getValue());
    }
    // store TEP info required parameters
    if (newTepInfoObj != null) {
        tzName = newTepInfoObj.getTzName();
        newLocalIp = newTepInfoObj.getLocalIp();
        newDpnBridgeName = newTepInfoObj.getBrName();
        newOfTunnel = newTepInfoObj.getOfTunnel();
    }
    if (oldTepInfoObj != null) {
        oldLocalIp = oldTepInfoObj.getLocalIp();
        oldDpnBridgeName = oldTepInfoObj.getBrName();
        oldTzName = oldTepInfoObj.getTzName();
    }
    // handle case when TEP parameters are not configured from switch side
    if (newLocalIp == null && oldLocalIp == null) {
        LOG.trace("TEP info Local IP parameters are not specified in old and new Ovsdb Nodes.");
        return;
    }
    if (!isTepInfoDeleted) {
        isLocalIpRemoved = isLocalIpRemoved(oldLocalIp, newLocalIp);
        isLocalIpAdded = isLocalIpAdded(oldLocalIp, newLocalIp);
        isLocalIpUpdated = isLocalIpUpdated(oldLocalIp, newLocalIp);
        if (isLocalIpUpdated) {
            LOG.info("Local IP cannot be updated. First delete the Local IP and then add again.");
            return;
        }
        if (isLocalIpAdded || isLocalIpRemoved) {
            isTepInfoUpdated = true;
        }
        if (isTzUpdated(oldTzName, tzName)) {
            isTepInfoUpdated = true;
            if (oldLocalIp != null && newLocalIp != null) {
                isTzChanged = true;
                LOG.trace("tzname is changed from {} to {} for Local IP: {}", oldTzName, tzName, newLocalIp);
            }
        }
        if (isDpnUpdated(oldDpnBridgeName, newDpnBridgeName)) {
            isTepInfoUpdated = true;
            if (oldLocalIp != null && newLocalIp != null) {
                isDpnBrChanged = true;
                LOG.trace("dpn-br-name is changed from {} to {} for Local IP: {}", oldDpnBridgeName, newDpnBridgeName, newLocalIp);
            }
        }
        if (!isTepInfoUpdated) {
            LOG.trace("No updates in the TEP Info parameters. Nothing to do.");
            return;
        }
    }
    String strOldDpnId;
    String strNewDpnId;
    // handle TEP-remove in remove case, TZ change case, Bridge change case
    if (isTepInfoDeleted || isLocalIpRemoved || isTzChanged || isDpnBrChanged) {
        // if flag is OFF, then no need to add TEP into ITM config DS.
        if (oldTzName == null || oldTzName.equals(ITMConstants.DEFAULT_TRANSPORT_ZONE)) {
            boolean defTzEnabled = itmConfig.isDefTzEnabled();
            if (!defTzEnabled) {
                LOG.info("TEP ({}) cannot be removed from {} when def-tz-enabled flag is false.", oldLocalIp, ITMConstants.DEFAULT_TRANSPORT_ZONE);
                return;
            }
            oldTzName = ITMConstants.DEFAULT_TRANSPORT_ZONE;
        }
        // TBD: Move this time taking operations into DataStoreJobCoordinator
        strOldDpnId = ItmUtils.getBridgeDpid(updatedOvsdbNode, oldDpnBridgeName, dataBroker);
        if (strOldDpnId == null || strOldDpnId.isEmpty()) {
            LOG.error("TEP {} cannot be deleted. DPID for bridge {} is NULL.", oldLocalIp, oldDpnBridgeName);
            return;
        }
        // remove TEP
        LOG.trace("Update case: Removing TEP-IP: {}, TZ name: {}, Bridge Name: {}, Bridge DPID: {}", oldLocalIp, oldTzName, oldDpnBridgeName, strOldDpnId);
        // Enqueue 'remove TEP from TZ' operation into DataStoreJobCoordinator
        jobCoordinator.enqueueJob(oldLocalIp, new OvsdbTepRemoveWorker(oldLocalIp, strOldDpnId, oldTzName, dataBroker));
    }
    // handle TEP-add in add case, TZ change case, Bridge change case
    if (isLocalIpAdded || isTzChanged || isDpnBrChanged) {
        // if flag is OFF, then no need to add TEP into ITM config DS.
        if (tzName == null || tzName.equals(ITMConstants.DEFAULT_TRANSPORT_ZONE)) {
            boolean defTzEnabled = itmConfig.isDefTzEnabled();
            if (!defTzEnabled) {
                LOG.info("TEP ({}) cannot be added into {} when def-tz-enabled flag is false.", newLocalIp, ITMConstants.DEFAULT_TRANSPORT_ZONE);
                return;
            }
            tzName = ITMConstants.DEFAULT_TRANSPORT_ZONE;
        }
        // TBD: Move this time taking operations into DataStoreJobCoordinator
        // get Datapath ID for bridge
        strNewDpnId = ItmUtils.getBridgeDpid(updatedOvsdbNode, newDpnBridgeName, dataBroker);
        if (strNewDpnId == null || strNewDpnId.isEmpty()) {
            LOG.error("TEP {} cannot be added. DPID for bridge {} is NULL.", newLocalIp, newDpnBridgeName);
            return;
        }
        LOG.trace("Update case: Adding TEP-IP: {}, TZ name: {}, Bridge Name: {}, Bridge DPID: {}," + "of-tunnel: {}", newLocalIp, tzName, newDpnBridgeName, strNewDpnId, newOfTunnel);
        // Enqueue 'add TEP into new TZ' operation into DataStoreJobCoordinator
        jobCoordinator.enqueueJob(newLocalIp, new OvsdbTepAddWorker(newLocalIp, strNewDpnId, tzName, newOfTunnel, dataBroker));
    }
}
Also used : OvsdbNodeAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation) OvsdbTepRemoveWorker(org.opendaylight.genius.itm.confighelpers.OvsdbTepRemoveWorker) OvsdbTepInfo(org.opendaylight.genius.itm.commons.OvsdbTepInfo) OvsdbTepAddWorker(org.opendaylight.genius.itm.confighelpers.OvsdbTepAddWorker)

Aggregations

TepsInNotHostedTransportZone (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.not.hosted.transport.zones.TepsInNotHostedTransportZone)5 UnknownVteps (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.not.hosted.transport.zones.tepsinnothostedtransportzone.UnknownVteps)4 TransportZone (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone)3 Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)3 BigInteger (java.math.BigInteger)2 ExecutionException (java.util.concurrent.ExecutionException)2 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)2 OvsdbTepInfo (org.opendaylight.genius.itm.commons.OvsdbTepInfo)2 OvsdbTepAddWorker (org.opendaylight.genius.itm.confighelpers.OvsdbTepAddWorker)2 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)2 IpPrefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix)2 Subnets (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.Subnets)2 Vteps (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.Vteps)2 Operations (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.ops.rev170711.service.ops.services.Operations)2 OperationsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.srm.ops.rev170711.service.ops.services.OperationsBuilder)2 OvsdbNodeAugmentation (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation)2 ArrayList (java.util.ArrayList)1 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)1 OvsdbTepRemoveWorker (org.opendaylight.genius.itm.confighelpers.OvsdbTepRemoveWorker)1 TepsInNotHostedTransportZoneKey (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.not.hosted.transport.zones.TepsInNotHostedTransportZoneKey)1