/*
- * Copyright (c) 2015, 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2015, 2017 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,
private HwvtepGlobalAugmentation initialCreatedData = null;
private HwvtepDeviceInfo deviceInfo;
private DataBroker dataBroker;
+ private final HwvtepConnectionManager hwvtepConnectionManager;
- HwvtepConnectionInstance (ConnectionInfo key, OvsdbClient client,
+ HwvtepConnectionInstance (HwvtepConnectionManager hwvtepConnectionManager, ConnectionInfo key, OvsdbClient client,
InstanceIdentifier<Node> iid, TransactionInvoker txInvoker, DataBroker dataBroker) {
+ this.hwvtepConnectionManager = hwvtepConnectionManager;
this.connectionInfo = key;
this.client = client;
this.instanceIdentifier = iid;
public void setInstanceIdentifier(InstanceIdentifier<Node> iid) {
this.instanceIdentifier = iid;
+ hwvtepConnectionManager.putConnectionInstance(instanceIdentifier, this);
}
public Entity getConnectedEntity() {
/*
- * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2015, 2017 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,
private EntityOwnershipService entityOwnershipService;
private HwvtepDeviceEntityOwnershipListener hwvtepDeviceEntityOwnershipListener;
private final ReconciliationManager reconciliationManager;
+ private final Map<InstanceIdentifier<Node>, HwvtepConnectionInstance> nodeIidVsConnectionInstance =
+ new ConcurrentHashMap<>();
public HwvtepConnectionManager(DataBroker db, TransactionInvoker txInvoker,
EntityOwnershipService entityOwnershipService) {
//Controller initiated connection can be terminated from switch side.
//So cleanup the instance identifier cache.
removeInstanceIdentifier(key);
+ removeConnectionInstance(hwvtepConnectionInstance.getInstanceIdentifier());
retryConnection(hwvtepConnectionInstance.getInstanceIdentifier(),
hwvtepConnectionInstance.getHwvtepGlobalAugmentation(),
ConnectionReconciliationTriggers.ON_DISCONNECT);
removeConnectionInstance(key);
}
- hwvtepConnectionInstance = new HwvtepConnectionInstance(key, externalClient, getInstanceIdentifier(key),
+ hwvtepConnectionInstance = new HwvtepConnectionInstance(this, key, externalClient, getInstanceIdentifier(key),
txInvoker, db);
hwvtepConnectionInstance.createTransactInvokers();
return hwvtepConnectionInstance;
return clients.get(connectionInfo);
}
+ public HwvtepConnectionInstance getConnectionInstanceFromNodeIid(final InstanceIdentifier<Node> nodeIid) {
+ HwvtepConnectionInstance hwvtepConnectionInstance = nodeIidVsConnectionInstance.get(nodeIid);
+ if (hwvtepConnectionInstance != null) {
+ return hwvtepConnectionInstance;
+ }
+ InstanceIdentifier<Node> globalNodeIid = HwvtepSouthboundUtil.getGlobalNodeIid(nodeIid);
+ if (globalNodeIid != null) {
+ return nodeIidVsConnectionInstance.get(globalNodeIid);
+ }
+ return null;
+ }
+
public HwvtepConnectionInstance getConnectionInstance(Node node) {
Preconditions.checkNotNull(node);
HwvtepGlobalAugmentation hwvtepGlobal = node.getAugmentation(HwvtepGlobalAugmentation.class);
return entityConnectionMap.get(entity);
}
+ void putConnectionInstance(final InstanceIdentifier<Node> nodeIid,
+ final HwvtepConnectionInstance connectionInstance) {
+ nodeIidVsConnectionInstance.put(nodeIid, connectionInstance);
+ }
+
+ private void removeConnectionInstance(final InstanceIdentifier<Node> nodeIid) {
+ if (nodeIid != null) {
+ nodeIidVsConnectionInstance.remove(nodeIid);
+ }
+ }
+
private class HwvtepDeviceEntityOwnershipListener implements EntityOwnershipListener {
private HwvtepConnectionManager hcm;
private EntityOwnershipListenerRegistration listenerRegistration;
/*
- * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2015, 2017 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,
final DataObjectModification<Node> mod = change.getRootNode();
//From original node to get connection instance
Node node = mod.getDataBefore()!=null ? mod.getDataBefore() : mod.getDataAfter();
- HwvtepConnectionInstance connection = hcm.getConnectionInstance(node);
- if(connection == null) {
- //Let us try getting it from Operational DS
- final ReadWriteTransaction transaction = db.newReadWriteTransaction();
- InstanceIdentifier<Node> connectionIid = HwvtepSouthboundMapper.createInstanceIdentifier(node.getNodeId());
- Optional<Node> optionalNode = HwvtepSouthboundUtil.readNode(transaction, connectionIid);
- LOG.trace("Node in Operational DataStore for user node {} is {}", node, optionalNode);
- if(optionalNode.isPresent()) {
- connection = hcm.getConnectionInstance(optionalNode.get());
- }
- }
+ HwvtepConnectionInstance connection = hcm.getConnectionInstanceFromNodeIid(
+ change.getRootPath().getRootIdentifier());
if (connection != null) {
if (!result.containsKey(connection)) {
List<DataTreeModification<Node>> tempChanges= new ArrayList<DataTreeModification<Node>>();
/*
- * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2015, 2017 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,
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.RemoteUcastMacs;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.Identifiable;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
public static boolean isEmptyMap(Map map) {
return map == null || map.isEmpty();
}
+
+ public static InstanceIdentifier<Node> getGlobalNodeIid(final InstanceIdentifier<Node> physicalNodeIid) {
+ String nodeId = physicalNodeIid.firstKeyOf(Node.class).getNodeId().getValue();
+ int physicalSwitchIndex = nodeId.indexOf(HwvtepSouthboundConstants.PSWITCH_URI_PREFIX);
+ if (physicalSwitchIndex > 0) {
+ nodeId = nodeId.substring(0, physicalSwitchIndex - 1);
+ } else {
+ return null;
+ }
+ return physicalNodeIid.firstIdentifierOf(Topology.class).child(Node.class , new NodeKey(new NodeId(nodeId)));
+ }
}
/*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2016, 2017 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,
field(HwvtepConnectionManager.class, "txInvoker").set(hwvtepConnectionManager, transactionInvoker);
field(HwvtepConnectionManager.class, "entityOwnershipService").set(hwvtepConnectionManager, entityOwnershipService);
suppress(PowerMockito.method(HwvtepConnectionManager.class, "getConnectionInstance", HwvtepPhysicalSwitchAttributes.class));
+ suppress(PowerMockito.method(HwvtepConnectionManager.class, "getConnectionInstanceFromNodeIid",
+ InstanceIdentifier.class));
when(hwvtepConnectionManager.getConnectionInstance(Mockito.any(HwvtepPhysicalSwitchAttributes.class))).
thenReturn(connectionInstance);
when(hwvtepConnectionManager.getConnectionInstance(Mockito.any(Node.class))).
thenReturn(connectionInstance);
+ when(hwvtepConnectionManager.getConnectionInstanceFromNodeIid(Mockito.any(InstanceIdentifier.class)))
+ .thenReturn(connectionInstance);
}
void mockConnectionInstance() throws IllegalAccessException {