/*
- * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2015, 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
package org.opendaylight.ovsdb.hwvtepsouthbound.transactions.md;
import java.util.Collection;
+import java.util.Map;
import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepConnectionInstance;
import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundConstants;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundMapper;
import org.opendaylight.ovsdb.lib.message.TableUpdates;
+import org.opendaylight.ovsdb.lib.notation.UUID;
import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
+import org.opendaylight.ovsdb.schema.hardwarevtep.LogicalSwitch;
import org.opendaylight.ovsdb.schema.hardwarevtep.McastMacsLocal;
import org.opendaylight.ovsdb.schema.hardwarevtep.McastMacsRemote;
import org.opendaylight.ovsdb.schema.hardwarevtep.UcastMacsLocal;
import org.opendaylight.ovsdb.schema.hardwarevtep.UcastMacsRemote;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepLogicalSwitchRef;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalMcastMacs;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalMcastMacsKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalUcastMacs;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalUcastMacsKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacs;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacsKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteUcastMacs;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteUcastMacsKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class MacEntriesRemoveCommand extends AbstractTransactionCommand {
+ private static final Logger LOG = LoggerFactory.getLogger(MacEntriesRemoveCommand.class);
+ Map<UUID, LogicalSwitch> lSwitchUpdatedRows;
+
public MacEntriesRemoveCommand(HwvtepConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
super(key, updates, dbSchema);
+ lSwitchUpdatedRows = TyperUtils.extractRowsUpdated(LogicalSwitch.class, getUpdates(), getDbSchema());
}
+
@Override
public void execute(ReadWriteTransaction transaction) {
removeUcastMacsLocal(transaction);
Collection<UcastMacsLocal> deletedLUMRows =
TyperUtils.extractRowsRemoved(UcastMacsLocal.class, getUpdates(), getDbSchema()).values();
for (UcastMacsLocal lum : deletedLUMRows) {
- InstanceIdentifier<LocalUcastMacs> lumId = getOvsdbConnectionInstance().getInstanceIdentifier()
- .augmentation(HwvtepGlobalAugmentation.class)
- .child(LocalUcastMacs.class, new LocalUcastMacsKey(new MacAddress(lum.getMac())));
- transaction.delete(LogicalDatastoreType.OPERATIONAL, lumId);
+ if(lum.getMac() != null && lum.getLogicalSwitchColumn() != null &&
+ lum.getLogicalSwitchColumn().getData() != null) {
+ InstanceIdentifier<LocalUcastMacs> lumId = getOvsdbConnectionInstance().getInstanceIdentifier()
+ .augmentation(HwvtepGlobalAugmentation.class).child(LocalUcastMacs.class,
+ new LocalUcastMacsKey(getLogicalSwitchRef(lum.getLogicalSwitchColumn().getData()),
+ getMacAddress(lum.getMac())));
+ transaction.delete(LogicalDatastoreType.OPERATIONAL, lumId);
+ } else {
+ LOG.debug("Failed to delete UcastMacLocal entry {}", lum.getUuid());
+ }
}
}
private void removeUcastMacsRemote(ReadWriteTransaction transaction) {
Collection<UcastMacsRemote> deletedUMRRows =
TyperUtils.extractRowsRemoved(UcastMacsRemote.class, getUpdates(), getDbSchema()).values();
- for (UcastMacsRemote lum : deletedUMRRows) {
- InstanceIdentifier<RemoteUcastMacs> lumId = getOvsdbConnectionInstance().getInstanceIdentifier()
- .augmentation(HwvtepGlobalAugmentation.class)
- .child(RemoteUcastMacs.class, new RemoteUcastMacsKey(new MacAddress(lum.getMac())));
- transaction.delete(LogicalDatastoreType.OPERATIONAL, lumId);
+ for (UcastMacsRemote rum : deletedUMRRows) {
+ if(rum.getMac() != null && rum.getLogicalSwitchColumn() != null &&
+ rum.getLogicalSwitchColumn().getData() != null) {
+ InstanceIdentifier<RemoteUcastMacs> rumId = getOvsdbConnectionInstance().getInstanceIdentifier()
+ .augmentation(HwvtepGlobalAugmentation.class).child(RemoteUcastMacs.class,
+ new RemoteUcastMacsKey(getLogicalSwitchRef(rum.getLogicalSwitchColumn().getData()),
+ getMacAddress(rum.getMac())));
+ transaction.delete(LogicalDatastoreType.OPERATIONAL, rumId);
+ } else {
+ LOG.debug("Failed to delete UcastMacRemote entry {}", rum.getUuid());
+ }
}
}
Collection<McastMacsLocal> deletedLMMRows =
TyperUtils.extractRowsRemoved(McastMacsLocal.class, getUpdates(), getDbSchema()).values();
for (McastMacsLocal lmm : deletedLMMRows) {
- InstanceIdentifier<LocalMcastMacs> lumId = getOvsdbConnectionInstance().getInstanceIdentifier()
+ if(lmm.getMac() != null && lmm.getLogicalSwitchColumn() != null &&
+ lmm.getLogicalSwitchColumn().getData() != null) {
+ InstanceIdentifier<LocalMcastMacs> lumId = getOvsdbConnectionInstance().getInstanceIdentifier()
.augmentation(HwvtepGlobalAugmentation.class)
- .child(LocalMcastMacs.class, new LocalMcastMacsKey(getMacAddress(lmm.getMac())));
- transaction.delete(LogicalDatastoreType.OPERATIONAL, lumId);
+ .child(LocalMcastMacs.class,
+ new LocalMcastMacsKey(getLogicalSwitchRef(lmm.getLogicalSwitchColumn().getData()),
+ getMacAddress(lmm.getMac())));
+ transaction.delete(LogicalDatastoreType.OPERATIONAL, lumId);
+ } else {
+ LOG.debug("Failed to delete McastMacLocal entry {}", lmm.getUuid());
+ }
}
}
private void removeMcastMacsRemote(ReadWriteTransaction transaction) {
Collection<McastMacsRemote> deletedMMRRows =
TyperUtils.extractRowsRemoved(McastMacsRemote.class, getUpdates(), getDbSchema()).values();
- for (McastMacsRemote lum : deletedMMRRows) {
- InstanceIdentifier<RemoteMcastMacs> lumId = getOvsdbConnectionInstance().getInstanceIdentifier()
+ for (McastMacsRemote rmm : deletedMMRRows) {
+ if(rmm.getMac() != null && rmm.getLogicalSwitchColumn() != null &&
+ rmm.getLogicalSwitchColumn().getData() != null) {
+ InstanceIdentifier<RemoteMcastMacs> lumId = getOvsdbConnectionInstance().getInstanceIdentifier()
.augmentation(HwvtepGlobalAugmentation.class)
- .child(RemoteMcastMacs.class, new RemoteMcastMacsKey(getMacAddress(lum.getMac())));
- transaction.delete(LogicalDatastoreType.OPERATIONAL, lumId);
+ .child(RemoteMcastMacs.class,
+ new RemoteMcastMacsKey(getLogicalSwitchRef(rmm.getLogicalSwitchColumn().getData()),
+ getMacAddress(rmm.getMac())));
+ transaction.delete(LogicalDatastoreType.OPERATIONAL, lumId);
+ } else {
+ LOG.debug("Failed to delete McastMacRemote entry {}", rmm.getUuid());
+ }
+ }
+ }
+
+ private HwvtepLogicalSwitchRef getLogicalSwitchRef(UUID switchUUID) {
+ LogicalSwitch logicalSwitch = lSwitchUpdatedRows.get(switchUUID);
+ if (logicalSwitch != null) {
+ InstanceIdentifier<LogicalSwitches> lSwitchIid =
+ HwvtepSouthboundMapper.createInstanceIdentifier(getOvsdbConnectionInstance(), logicalSwitch);
+ return new HwvtepLogicalSwitchRef(lSwitchIid);
}
+ return null;
}
private MacAddress getMacAddress(String mac) {