Search in sources :

Example 1 with OvsdbTepInfo

use of org.opendaylight.genius.itm.commons.OvsdbTepInfo in project genius by opendaylight.

the class OvsdbNodeListener method getOvsdbTepInfo.

private OvsdbTepInfo getOvsdbTepInfo(OvsdbNodeAugmentation ovsdbNodeAugmentation) {
    if (ovsdbNodeAugmentation == null) {
        return null;
    }
    List<OpenvswitchOtherConfigs> ovsdbNodeOtherConfigsList = ovsdbNodeAugmentation.getOpenvswitchOtherConfigs();
    if (ovsdbNodeOtherConfigsList == null) {
        // Local IP is not configured
        LOG.debug("OtherConfigs list does not exist in the OVSDB Node Augmentation.");
        return null;
    }
    OvsdbTepInfo ovsdbTepInfoObj = new OvsdbTepInfo();
    for (OpenvswitchOtherConfigs otherConfigs : ovsdbNodeOtherConfigsList) {
        if (ITMConstants.OTH_CFG_TEP_PARAM_KEY_LOCAL_IP.equals(otherConfigs.getOtherConfigKey())) {
            String tepIp = otherConfigs.getOtherConfigValue();
            ovsdbTepInfoObj.setLocalIp(tepIp);
        }
    }
    List<OpenvswitchExternalIds> ovsdbNodeExternalIdsList = ovsdbNodeAugmentation.getOpenvswitchExternalIds();
    if (ovsdbNodeExternalIdsList == null) {
        LOG.debug("ExternalIds list does not exist in the OVSDB Node Augmentation.");
    } else {
        for (OpenvswitchExternalIds externalId : ovsdbNodeExternalIdsList) {
            switch(externalId.getExternalIdKey()) {
                case ITMConstants.EXT_ID_TEP_PARAM_KEY_TZNAME:
                    ovsdbTepInfoObj.setTzName(externalId.getExternalIdValue());
                    break;
                case ITMConstants.EXT_ID_TEP_PARAM_KEY_BR_NAME:
                    ovsdbTepInfoObj.setBrName(externalId.getExternalIdValue());
                    break;
                case ITMConstants.EXT_ID_TEP_PARAM_KEY_OF_TUNNEL:
                    ovsdbTepInfoObj.setOfTunnel(Boolean.parseBoolean(externalId.getExternalIdValue()));
                    break;
                default:
                    break;
            }
        }
    }
    LOG.trace("ovsdbTepInfo retrieved {}", ovsdbTepInfoObj);
    return ovsdbTepInfoObj;
}
Also used : OpenvswitchOtherConfigs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.OpenvswitchOtherConfigs) OpenvswitchExternalIds(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.OpenvswitchExternalIds) OvsdbTepInfo(org.opendaylight.genius.itm.commons.OvsdbTepInfo)

Example 2 with OvsdbTepInfo

use of org.opendaylight.genius.itm.commons.OvsdbTepInfo in project genius by opendaylight.

the class OvsdbNodeListener method processBridgeUpdate.

private void processBridgeUpdate(OvsdbBridgeAugmentation ovsdbNewBridgeAugmentation) {
    String bridgeName = null;
    String strDpnId = null;
    OvsdbNodeAugmentation ovsdbNewNodeAugmentation = null;
    if (ovsdbNewBridgeAugmentation != null) {
        bridgeName = ovsdbNewBridgeAugmentation.getBridgeName().getValue();
        // Read DPID from OVSDBBridgeAugmentation
        strDpnId = ItmUtils.getStrDatapathId(ovsdbNewBridgeAugmentation);
        if (strDpnId == null || strDpnId.isEmpty()) {
            LOG.info("OvsdbBridgeAugmentation processBridgeUpdate: DPID for bridge {} is NULL.", bridgeName);
            return;
        }
        // TBD: Move this time taking operations into DataStoreJobCoordinator
        Node ovsdbNodeFromBridge = ItmUtils.getOvsdbNode(ovsdbNewBridgeAugmentation, dataBroker);
        // check for OVSDB node
        if (ovsdbNodeFromBridge != null) {
            ovsdbNewNodeAugmentation = ovsdbNodeFromBridge.getAugmentation(OvsdbNodeAugmentation.class);
        } else {
            LOG.error("processBridgeUpdate: Ovsdb Node could not be fetched from Oper DS for bridge {}.", bridgeName);
            return;
        }
    }
    if (ovsdbNewNodeAugmentation != null) {
        OvsdbTepInfo ovsdbTepInfo = getOvsdbTepInfo(ovsdbNewNodeAugmentation);
        if (ovsdbTepInfo == null) {
            LOG.trace("processBridgeUpdate: No Tep Info");
            return;
        }
        // store TEP info required parameters
        String newLocalIp = ovsdbTepInfo.getLocalIp();
        String tzName = ovsdbTepInfo.getTzName();
        String newBridgeName = ovsdbTepInfo.getBrName();
        boolean ofTunnel = ovsdbTepInfo.getOfTunnel();
        // check if Local IP is configured or not
        if (newLocalIp != null && !newLocalIp.isEmpty()) {
            // if it is br-int, then add TEP into Config DS
            if (newBridgeName.equals(bridgeName)) {
                LOG.trace("Ovs Node with bridge {} is configured with Local IP.", bridgeName);
                // 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;
                    }
                }
                LOG.trace("Local-IP: {}, TZ name: {}, Bridge Name: {}, Bridge DPID: {}," + "of-tunnel flag: {}", newLocalIp, tzName, newBridgeName, strDpnId, ofTunnel);
                // Enqueue 'add TEP into new TZ' operation into DataStoreJobCoordinator
                jobCoordinator.enqueueJob(newLocalIp, new OvsdbTepAddWorker(newLocalIp, strDpnId, tzName, ofTunnel, dataBroker));
            } else {
                LOG.trace("TEP ({}) would be added later when bridge {} gets added into Ovs Node.", newLocalIp, newBridgeName);
            }
        } else {
            LOG.trace("Ovs Node with bridge {} is not configured with Local IP. Nothing to do.", bridgeName);
        }
    }
}
Also used : OvsdbNodeAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) OvsdbTepInfo(org.opendaylight.genius.itm.commons.OvsdbTepInfo) OvsdbTepAddWorker(org.opendaylight.genius.itm.confighelpers.OvsdbTepAddWorker)

Example 3 with OvsdbTepInfo

use of org.opendaylight.genius.itm.commons.OvsdbTepInfo 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

OvsdbTepInfo (org.opendaylight.genius.itm.commons.OvsdbTepInfo)3 OvsdbTepAddWorker (org.opendaylight.genius.itm.confighelpers.OvsdbTepAddWorker)2 OvsdbNodeAugmentation (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation)2 OvsdbTepRemoveWorker (org.opendaylight.genius.itm.confighelpers.OvsdbTepRemoveWorker)1 OpenvswitchExternalIds (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.OpenvswitchExternalIds)1 OpenvswitchOtherConfigs (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.OpenvswitchOtherConfigs)1 Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)1