*/
package org.opendaylight.alto.basic.impl;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
import org.opendaylight.alto.basic.manual.maps.ManualMapsUtils;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
-import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.address.tracker.rev140617.address.node.connector.Addresses;
import org.opendaylight.yang.gen.v1.urn.alto.manual.maps.networkmap.rev151021.EndpointAddressType;
import org.opendaylight.yang.gen.v1.urn.alto.manual.maps.networkmap.rev151021.endpoint.address.group.EndpointAddressGroup;
import org.opendaylight.yang.gen.v1.urn.alto.manual.maps.networkmap.rev151021.endpoint.address.group.EndpointAddressGroupBuilder;
import org.opendaylight.yang.gen.v1.urn.alto.types.rev150921.PidName;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.address.tracker.rev140617.address.node.connector.Addresses;
import org.opendaylight.yang.gen.v1.urn.opendaylight.host.tracker.rev140624.HostNode;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-public class AltoAutoMapsUpdateListener implements DataChangeListener, AutoCloseable {
+public class AltoAutoMapsUpdateListener implements DataTreeChangeListener<Topology>, AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(AltoAutoMapsUpdateListener.class);
private final DataBroker dataBroker;
- private ListenerRegistration<DataChangeListener> registration;
+ private final ListenerRegistration<?> registration;
private static final String TOPOLOGY_NAME = "flow:1";
private static final String DEFAULT_AUTO_NETWORKMAP = "default-auto-networkmap";
.child(Topology.class,
new TopologyKey(new TopologyId(TOPOLOGY_NAME)))
.build();
- this.registration = dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
- iid, this, AsyncDataBroker.DataChangeScope.BASE);
+ this.registration = dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(
+ LogicalDatastoreType.OPERATIONAL, iid), this);
}
@Override
- public void onDataChanged(AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event) {
- if (event == null) {
- return;
- }
-
- final ReadWriteTransaction rwx = dataBroker.newReadWriteTransaction();
-
- Map<InstanceIdentifier<?>, DataObject> original = event.getOriginalData();
-
- for (Map.Entry<InstanceIdentifier<?>, DataObject> entry : event.getCreatedData().entrySet()) {
- InstanceIdentifier<?> iid = entry.getKey();
- DataObject created = entry.getValue();
-
- if (created instanceof Topology) {
- createDefaultAutoNetworkMap((Topology) created, rwx);
- LOG.info("Create default auto networkmap");
- }
- }
-
- for (InstanceIdentifier<?> iid : event.getRemovedPaths()) {
- DataObject removed = original.get(iid);
-
- if (removed instanceof Topology) {
- emptyDefaultAutoNetworkMap(rwx);
- LOG.info("Empty default auto networkmap");
+ public void onDataTreeChanged(Collection<DataTreeModification<Topology>> changes) {
+ WriteTransaction writeTx = null;
+ for (DataTreeModification<Topology> change: changes) {
+ final DataObjectModification<Topology> rootNode = change.getRootNode();
+ switch (rootNode.getModificationType()) {
+ case WRITE:
+ if (writeTx == null) {
+ writeTx = dataBroker.newWriteOnlyTransaction();
+ }
+
+ if (rootNode.getDataBefore() == null) {
+ createDefaultAutoNetworkMap(rootNode.getDataAfter(), writeTx);
+ LOG.info("Create default auto networkmap");
+ } else {
+ updateDefaultAutoNetworkMap(rootNode.getDataAfter(), writeTx);
+ LOG.info("Update default auto networkmap");
+ }
+ break;
+ case DELETE:
+ if (writeTx == null) {
+ writeTx = dataBroker.newWriteOnlyTransaction();
+ }
+
+ emptyDefaultAutoNetworkMap(writeTx);
+ LOG.info("Empty default auto networkmap");
+ break;
+ default:
+ break;
}
}
- for (Map.Entry<InstanceIdentifier<?>, DataObject> entry : event.getUpdatedData().entrySet()) {
- InstanceIdentifier<?> iid = entry.getKey();
- DataObject updated = entry.getValue();
-
- if (updated instanceof Topology) {
- updateDefaultAutoNetworkMap((Topology) updated, rwx);
- LOG.info("Update default auto networkmap");
- }
+ if (writeTx != null) {
+ writeTx.submit();
}
-
- rwx.submit();
}
private void createDefaultAutoNetworkMap(Topology topology, final WriteTransaction wx) {
private List<IpPrefix> aggregateAddressesList(List<Addresses> addressesList) {
List<IpPrefix> prefixList = new LinkedList<>();
for (Addresses addresses : addressesList) {
- if (addresses.getIp() == null)
+ if (addresses.getIp() == null) {
continue;
+ }
String ipAddress = addresses.getIp().getIpv4Address().getValue();
IpPrefix prefix = new IpPrefix(new Ipv4Prefix(ipAddress + "/32"));
*/
package org.opendaylight.alto.basic.impl;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
+
+import java.util.Arrays;
+import java.util.Collections;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
-import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.address.tracker.rev140617.address.node.connector.AddressesBuilder;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
public class AltoAutoMapsUpdateListenerTest {
private static final String TOPOLOGY_NAME = "flow:1";
- private DataBroker dataBroker = mock(DataBroker.class);
- private ListenerRegistration<DataChangeListener> registration = mock(ListenerRegistration.class);
+ private final DataBroker dataBroker = mock(DataBroker.class);
+ private final ListenerRegistration<?> registration = mock(ListenerRegistration.class);
private AltoAutoMapsUpdateListener altoAutoMapsUpdateListener;
- private ReadWriteTransaction rwx = mock(ReadWriteTransaction.class);
- private InstanceIdentifier<Topology> iid = InstanceIdentifier
+ private final WriteTransaction rwx = mock(WriteTransaction.class);
+ private final InstanceIdentifier<Topology> iid = InstanceIdentifier
.builder(NetworkTopology.class)
.child(Topology.class,
new TopologyKey(new TopologyId(TOPOLOGY_NAME)))
.build();
- private AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> mockDataChangeEvent =
- mock(AsyncDataChangeEvent.class);
- private Map<InstanceIdentifier<?>, DataObject> original = new HashMap<>();
- private Map<InstanceIdentifier<?>, DataObject> createdData = new HashMap<>();
- private Set<InstanceIdentifier<?>> removedPaths = new HashSet<>();
- private Map<InstanceIdentifier<?>, DataObject> updatedData = new HashMap<>();
-
+ @SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
- when(dataBroker.registerDataChangeListener(
- any(LogicalDatastoreType.class),
- any(InstanceIdentifier.class),
- any(DataChangeListener.class),
- any(AsyncDataBroker.DataChangeScope.class)
+ when(dataBroker.registerDataTreeChangeListener(
+ any(DataTreeIdentifier.class),
+ any(AltoAutoMapsUpdateListener.class)
)).thenReturn(registration);
- when(dataBroker.newReadWriteTransaction()).thenReturn(rwx);
+ when(dataBroker.newWriteOnlyTransaction()).thenReturn(rwx);
altoAutoMapsUpdateListener = new AltoAutoMapsUpdateListener(dataBroker);
+ }
- original.put(iid, new TopologyBuilder().build());
- removedPaths.add(iid);
+ @After
+ public void tearDown() throws Exception {
- Topology testTopology = new TopologyBuilder()
- .setNode(Arrays.asList(new NodeBuilder().build()))
- .build();
- createdData.put(iid, testTopology);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testOnDataChanged() throws Exception {
+ DataTreeModification<Topology> mockDataTreeModification = mock(DataTreeModification.class);
+ DataObjectModification<Topology> mockModification = mock(DataObjectModification.class);
+ doReturn(mockModification).when(mockDataTreeModification).getRootNode();
+
+ // Created
+ Topology testTopology = new TopologyBuilder().setNode(Arrays.asList(new NodeBuilder().build())).build();
+ doReturn(testTopology).when(mockModification).getDataAfter();
+ doReturn(DataObjectModification.ModificationType.WRITE).when(mockModification).getModificationType();
+ altoAutoMapsUpdateListener.onDataTreeChanged(Collections.singletonList(mockDataTreeModification));
+ verify(rwx).submit();
+ reset(rwx);
+
+ // Updated
+ doReturn(testTopology).when(mockModification).getDataBefore();
Topology testTopologyWithHost = new TopologyBuilder()
.setNode(Arrays.asList(new NodeBuilder()
.build())
.build()))
.build();
- updatedData.put(iid, testTopologyWithHost);
-
- when(mockDataChangeEvent.getOriginalData()).thenReturn(original);
- when(mockDataChangeEvent.getCreatedData()).thenReturn(createdData);
- when(mockDataChangeEvent.getRemovedPaths()).thenReturn(removedPaths);
- when(mockDataChangeEvent.getUpdatedData()).thenReturn(updatedData);
- }
-
- @After
- public void tearDown() throws Exception {
-
- }
-
- @Test
- public void testOnNullDataChanged() throws Exception {
- altoAutoMapsUpdateListener.onDataChanged(null);
- verify(rwx, never()).submit();
- }
+ doReturn(testTopologyWithHost).when(mockModification).getDataAfter();
+ doReturn(DataObjectModification.ModificationType.WRITE).when(mockModification).getModificationType();
+ altoAutoMapsUpdateListener.onDataTreeChanged(Collections.singletonList(mockDataTreeModification));
+ verify(rwx).submit();
+ reset(rwx);
- @Test
- public void testOnDataChanged() throws Exception {
- altoAutoMapsUpdateListener.onDataChanged(mockDataChangeEvent);
+ // Deleted
+ doReturn(testTopologyWithHost).when(mockModification).getDataBefore();
+ doReturn(null).when(mockModification).getDataAfter();
+ doReturn(DataObjectModification.ModificationType.DELETE).when(mockModification).getModificationType();
+ altoAutoMapsUpdateListener.onDataTreeChanged(Collections.singletonList(mockDataTreeModification));
verify(rwx).submit();
+ reset(rwx, dataBroker);
+
+ // No-op
+ doReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED)
+ .when(mockModification).getModificationType();
+ altoAutoMapsUpdateListener.onDataTreeChanged(Collections.singletonList(mockDataTreeModification));
+ verifyNoMoreInteractions(dataBroker);
}
@Test
*/
package org.opendaylight.alto.basic.impl;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
import org.opendaylight.alto.basic.manual.maps.ManualMapsUtils;
import org.opendaylight.alto.basic.simpleird.SimpleIrdUtils;
import org.opendaylight.alto.core.northbound.route.costmap.AltoNbrCostmapUtils;
import org.opendaylight.alto.core.northbound.route.networkmap.AltoNbrNetworkmapUtils;
import org.opendaylight.alto.core.resourcepool.ResourcepoolUtils;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
import org.opendaylight.yang.gen.v1.urn.alto.manual.maps.costmap.rev151021.CostMap;
import org.opendaylight.yang.gen.v1.urn.alto.manual.maps.networkmap.rev151021.NetworkMap;
import org.opendaylight.yang.gen.v1.urn.alto.manual.maps.rev151021.ConfigContext;
+import org.opendaylight.yang.gen.v1.urn.alto.manual.maps.rev151021.config.context.ResourceCostMap;
+import org.opendaylight.yang.gen.v1.urn.alto.manual.maps.rev151021.config.context.ResourceNetworkMap;
import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.ServiceContext;
import org.opendaylight.yang.gen.v1.urn.alto.types.rev150921.ResourceId;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.config.rev151021.ResourceTypeConfig;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.costmap.rev151021.AltoModelCostmapService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.costmap.rev151021.ResourceTypeCostmap;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.networkmap.rev151021.AltoModelNetworkmapService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.networkmap.rev151021.ResourceTypeNetworkmap;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ExecutionException;
-
-public class ManualMapsListener implements AutoCloseable, DataChangeListener {
+public class ManualMapsListener implements AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(ManualMapsListener.class);
private DataBroker m_dataBroker = null;
- private InstanceIdentifier<ConfigContext> m_iid = null;
- private ListenerRegistration<DataChangeListener> m_reg = null;
+ private final List<ListenerRegistration<?>> m_regs = new ArrayList<>();;
private BindingAwareBroker.RoutedRpcRegistration<AltoModelNetworkmapService> m_networkmapServiceReg = null;
private BindingAwareBroker.RoutedRpcRegistration<AltoModelCostmapService> m_costmapServiceReg = null;
public ManualMapsListener() {
- m_iid = ManualMapsUtils.getContextListIID();
}
public void register(DataBroker dataBroker) {
m_dataBroker = dataBroker;
- m_reg = m_dataBroker.registerDataChangeListener(
- LogicalDatastoreType.CONFIGURATION, m_iid,
- this, AsyncDataBroker.DataChangeScope.SUBTREE
- );
+ final InstanceIdentifier<ConfigContext> contextListIID = ManualMapsUtils.getContextListIID();
+
+ m_regs.add(m_dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(
+ LogicalDatastoreType.CONFIGURATION, contextListIID), changes -> onConfigContextChanged(changes)));
+
+ m_regs.add(m_dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(
+ LogicalDatastoreType.CONFIGURATION, contextListIID.child(ResourceNetworkMap.class)),
+ changes -> onNetworkMapChanged(changes)));
+
+ m_regs.add(m_dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(
+ LogicalDatastoreType.CONFIGURATION, contextListIID.child(ResourceCostMap.class)),
+ changes -> onCostMapChanged(changes)));
}
public void setNetworkmapServiceReg(BindingAwareBroker.RoutedRpcRegistration<AltoModelNetworkmapService> reg) {
@Override
public void close() throws Exception {
- try {
- if (m_reg != null) {
- m_reg.close();
- }
- } catch (Exception e) {
- LOG.info("Error while closing the registration");
+ for (ListenerRegistration<?> reg: m_regs) {
+ reg.close();
}
}
- @Override
- public void onDataChanged(AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
+ private void onConfigContextChanged(Collection<DataTreeModification<ConfigContext>> changes) {
final ReadWriteTransaction rwx = m_dataBroker.newReadWriteTransaction();
- Map<InstanceIdentifier<?>, DataObject> original = change.getOriginalData();
-
- for (Map.Entry<InstanceIdentifier<?>, DataObject> entry : change.getUpdatedData().entrySet()) {
- DataObject origin = original.get(entry.getKey());
- InstanceIdentifier<?> updatedIID = entry.getKey();
- DataObject updated = entry.getValue();
-
- if (updated instanceof NetworkMap) {
- updateNetworkMap((NetworkMap) origin, (NetworkMap) updated,
- (InstanceIdentifier<NetworkMap>) updatedIID, rwx);
- LOG.info("Update NetworkMap data from OPERATIONAL");
- } else if (updated instanceof CostMap) {
- updateCostMap((CostMap) origin, (CostMap) updated,
- (InstanceIdentifier<CostMap>) updatedIID, rwx);
- LOG.info("Update CostMap data from OPERATIONAL");
+ for (DataTreeModification<ConfigContext> change: changes) {
+ final DataObjectModification<ConfigContext> rootNode = change.getRootNode();
+ final InstanceIdentifier<ConfigContext> identifier = change.getRootPath().getRootIdentifier();
+ switch (rootNode.getModificationType()) {
+ case WRITE:
+ if (rootNode.getDataBefore() == null) {
+ createConfigContext(rootNode.getDataAfter(), identifier, rwx);
+ LOG.info("Create new ConfigContext data into OPERATIONAL");
+ }
+ break;
+ case DELETE:
+ removeConfigContext(identifier, rootNode.getDataBefore(), rwx);
+ LOG.info("Remove ConfigContext data from OPERATIONAL");
+ break;
+ default:
+ break;
}
}
- for (InstanceIdentifier<?> iid : change.getRemovedPaths()) {
- DataObject removed = original.get(iid);
-
- if (removed instanceof NetworkMap) {
- removeNetworkMap((InstanceIdentifier<NetworkMap>) iid, (NetworkMap) removed, rwx);
- LOG.info("Remove NetworkMap data from OPERATIONAL");
- } else if (removed instanceof CostMap) {
- removeCostMap((InstanceIdentifier<CostMap>) iid, (CostMap) removed, rwx);
- LOG.info("Remove CostMap data from OPERATIONAL");
- } else if (removed instanceof ConfigContext) {
- removeConfigContext((InstanceIdentifier<ConfigContext>) iid, (ConfigContext) removed, rwx);
- LOG.info("Remove ConfigContext data from OPERATIONAL");
+ rwx.submit();
+ }
+
+ private void onCostMapChanged(Collection<DataTreeModification<ResourceCostMap>> changes) {
+ final ReadWriteTransaction rwx = m_dataBroker.newReadWriteTransaction();
+
+ for (DataTreeModification<ResourceCostMap> change: changes) {
+ final DataObjectModification<ResourceCostMap> rootNode = change.getRootNode();
+ final InstanceIdentifier<ResourceCostMap> identifier = change.getRootPath().getRootIdentifier();
+ switch (rootNode.getModificationType()) {
+ case WRITE:
+ case SUBTREE_MODIFIED:
+ final ResourceCostMap original = rootNode.getDataBefore();
+ final ResourceCostMap updated = rootNode.getDataAfter();
+ if (original == null) {
+ createCostMap(updated, identifier, rwx);
+ LOG.info("Create new CostMap data into OPERATIONAL");
+ } else {
+ updateCostMap(original, updated, identifier, rwx);
+ LOG.info("Update CostMap data from OPERATIONAL");
+ }
+ break;
+ case DELETE:
+ removeCostMap(identifier, rootNode.getDataBefore(), rwx);
+ LOG.info("Remove CostMap data from OPERATIONAL");
+ break;
+ default:
+ break;
}
}
- for (Map.Entry<InstanceIdentifier<?>, DataObject> entry : change.getCreatedData().entrySet()) {
- InstanceIdentifier<?> createdIID = entry.getKey();
- DataObject created = entry.getValue();
-
- if (created instanceof NetworkMap) {
- createNetworkMap((NetworkMap) created, (InstanceIdentifier<NetworkMap>) createdIID, rwx);
- LOG.info("Create new NetworkMap data into OPERATIONAL");
- } else if (created instanceof CostMap) {
- createCostMap((CostMap) created, (InstanceIdentifier<CostMap>) createdIID, rwx);
- LOG.info("Create new CostMap data into OPERATIONAL");
- } else if (created instanceof ConfigContext) {
- createConfigContext((ConfigContext) created, (InstanceIdentifier<ConfigContext>) createdIID, rwx);
- LOG.info("Create new ConfigContext data into OPERATIONAL");
+ rwx.submit();
+ }
+
+ private void onNetworkMapChanged(Collection<DataTreeModification<ResourceNetworkMap>> changes) {
+ final ReadWriteTransaction rwx = m_dataBroker.newReadWriteTransaction();
+
+ for (DataTreeModification<ResourceNetworkMap> change: changes) {
+ final DataObjectModification<ResourceNetworkMap> rootNode = change.getRootNode();
+ final InstanceIdentifier<ResourceNetworkMap> identifier = change.getRootPath().getRootIdentifier();
+ switch (rootNode.getModificationType()) {
+ case WRITE:
+ case SUBTREE_MODIFIED:
+ final ResourceNetworkMap original = rootNode.getDataBefore();
+ final ResourceNetworkMap updated = rootNode.getDataAfter();
+ if (original == null) {
+ createNetworkMap(updated, identifier, rwx);
+ LOG.info("Create new NetworkMap data into OPERATIONAL");
+ } else {
+ updateNetworkMap(original, updated, identifier, rwx);
+ LOG.info("Update NetworkMap data from OPERATIONAL");
+ }
+ break;
+ case DELETE:
+ removeNetworkMap(identifier, rootNode.getDataBefore(), rwx);
+ LOG.info("Remove NetworkMap data from OPERATIONAL");
+ break;
+ default:
+ break;
}
}
rwx.submit();
}
- private void updateNetworkMap(NetworkMap origin, NetworkMap updated, InstanceIdentifier<NetworkMap> updatedIID,
+ private <T extends NetworkMap> void updateNetworkMap(T origin, T updated, InstanceIdentifier<T> updatedIID,
final WriteTransaction wx) {
ResourceId rid = updated.getResourceId();
createNetworkMap(updated, updatedIID, wx);
}
- private void updateCostMap(CostMap origin, CostMap updated, InstanceIdentifier<CostMap> updatedIID,
+ private <T extends CostMap> void updateCostMap(T origin, T updated, InstanceIdentifier<T> updatedIID,
final WriteTransaction wx) {
ResourceId rid = updated.getResourceId();
createCostMap(updated, updatedIID, wx);
}
- private void removeNetworkMap(InstanceIdentifier<NetworkMap> mapIID, NetworkMap removed, final WriteTransaction wx) {
+ private <T extends NetworkMap> void removeNetworkMap(InstanceIdentifier<T> mapIID, T removed, final WriteTransaction wx) {
SimpleIrdUtils.deleteConfigEntry(removed.getResourceId(), wx);
String path = removed.getResourceId().getValue();
AltoNbrNetworkmapUtils.deleteRecord(path, wx);
removeMap(mapIID, wx);
}
- private void removeCostMap(InstanceIdentifier<CostMap> mapIID, CostMap removed, final WriteTransaction wx) {
+ private <T extends CostMap> void removeCostMap(InstanceIdentifier<T> mapIID, T removed, final WriteTransaction wx) {
SimpleIrdUtils.deleteConfigEntry(removed.getResourceId(), wx);
ManualMapsUtils.deleteResourceCostMap(new Uuid(ManualMapsUtils.DEFAULT_CONTEXT), removed.getResourceId(), wx);
m_costmapServiceReg.unregisterPath(ServiceContext.class,
wx.delete(LogicalDatastoreType.OPERATIONAL, mapIID);
}
- private void createNetworkMap(NetworkMap created, InstanceIdentifier<NetworkMap> createdIID, final WriteTransaction wx) {
+ private <T extends NetworkMap> void createNetworkMap(T created, InstanceIdentifier<T> createdIID, final WriteTransaction wx) {
ResourcepoolUtils.createResource(ManualMapsUtils.DEFAULT_CONTEXT,
created.getResourceId().getValue(),
ResourceTypeNetworkmap.class, wx);
created.getResourceId(), new Uuid(ManualMapsUtils.DEFAULT_CONTEXT), wx);
}
- private void createCostMap(CostMap created, InstanceIdentifier<CostMap> createdIID, final WriteTransaction wx) {
+ private <T extends CostMap> void createCostMap(T created, InstanceIdentifier<T> createdIID, final WriteTransaction wx) {
ResourcepoolUtils.createResource(ManualMapsUtils.DEFAULT_CONTEXT,
created.getResourceId().getValue(),
ResourceTypeCostmap.class, wx);
import java.util.concurrent.ExecutionException;
import org.opendaylight.alto.core.resourcepool.ResourcepoolUtils;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.context.Resource;
+import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.context.resource.ContextTag;
import org.opendaylight.yang.gen.v1.urn.alto.types.rev150921.ResourceId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rev151021.AltoModelEndpointcostService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rev151021.ResourceTypeEndpointcost;
private final DataBroker m_dataBroker;
private final BindingAwareBroker.RoutedRpcRegistration<AltoModelEndpointcostService> m_serviceReg;
- private ListenerRegistration<DataChangeListener> m_listener;
+ private ListenerRegistration<?> m_listener;
private static final String SERVICE_ENDPOINTCOST_NAME = "service-endpointcost";
private static final ResourceId SERVICE_ENDPOINTCOST_RID = new ResourceId(SERVICE_ENDPOINTCOST_NAME);
protected void setupListener() {
ResourcepoolUtils.ContextTagListener listener = new ResourcepoolUtils.ContextTagListener(m_testIID, m_serviceReg);
- m_listener = m_dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
- m_testIID,listener, AsyncDataBroker.DataChangeScope.SUBTREE);
+ m_listener = m_dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL,
+ m_testIID.child(ContextTag.class)), listener);
assert m_listener != null;
}
package org.opendaylight.alto.basic.endpointcostservice.suportservice.impl;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
import org.opendaylight.alto.basic.endpointcostservice.suportservice.service.HostNodeTrackerService;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.address.tracker.rev140617.address.node.connector.Addresses;
import org.opendaylight.yang.gen.v1.urn.opendaylight.host.tracker.rev140624.HostNode;
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.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-public class HostNodeTrackerImpl implements HostNodeTrackerService,DataChangeListener {
+public class HostNodeTrackerImpl implements HostNodeTrackerService, AutoCloseable {
private static final Logger log = LoggerFactory
.getLogger(HostNodeTrackerImpl.class);
private static final int CPUS = Runtime.getRuntime().availableProcessors();
- private ExecutorService exec = Executors.newFixedThreadPool(CPUS);
+ private final ExecutorService exec = Executors.newFixedThreadPool(CPUS);
private DataBroker dataBroker = null;
- private Map<String, String> macToIp;
- private Map<String, String> ipToMac;
+ private final Map<String, String> macToIp = new ConcurrentHashMap<>();
+ private final Map<String, String> ipToMac = new ConcurrentHashMap<>();
+
+ private ListenerRegistration<?> hostListener = null;
+ private ListenerRegistration<?> addressesListener = null;
- private ListenerRegistration<DataChangeListener> hostListener = null;
public HostNodeTrackerImpl (DataBroker dataBroker) {
this.log.info("AddressConvertServiceImpl initial.");
this.dataBroker = dataBroker;
- macToIp = new HashMap<String,String>();
- ipToMac = new HashMap<String,String>();
registerPortListener();
}
.child(Topology.class)
.child(Node.class).augmentation(HostNode.class).build();
this.hostListener = this.dataBroker
- .registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
- hostNodes, this, AsyncDataBroker.DataChangeScope.SUBTREE);
+ .registerDataTreeChangeListener(new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL,
+ hostNodes), changes -> onHostChanged(changes));
+
+ InstanceIdentifier<Addresses> addresses = InstanceIdentifier
+ .builder(NetworkTopology.class)
+ .child(Topology.class)
+ .child(Node.class).augmentation(HostNode.class).child(Addresses.class).build();
+ this.addressesListener = this.dataBroker
+ .registerDataTreeChangeListener(new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL,
+ addresses), changes -> onAddressesChanged(changes));
+ }
+
+ @Override
+ public void close() {
+ this.hostListener.close();
+ this.addressesListener.close();
}
+
+ @Override
public String getIpByMac(String macAddress) {
return this.macToIp.get(macAddress);
}
+ @Override
public String getMacByIp(String ipAddress) {
return this.ipToMac.get(ipAddress);
}
+ @Override
public Boolean isValidHost(String ipAddress) {
if(ipAddress != null) {
return this.ipToMac.containsKey(ipAddress);
}
}
- public void onDataChanged(final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
- exec.submit(new Runnable() {
- @Override
- public void run() {
- if (change == null) {
- log.info("In onDataChanged: No processing done as change even is null.");
- return;
- }
- Map<InstanceIdentifier<?>, DataObject> updatedData = change
- .getUpdatedData();
- Map<InstanceIdentifier<?>, DataObject> createdData = change
- .getCreatedData();
- Map<InstanceIdentifier<?>, DataObject> originalData = change
- .getOriginalData();
- Set<InstanceIdentifier<?>> deletedData = change
- .getRemovedPaths();
-
- for (InstanceIdentifier<?> iid : deletedData) {
- log.info("deletedData");
- if (iid.getTargetType().equals(Node.class)) {
- Node node = ((Node) originalData.get(iid));
- HostNode hostNode = node
- .getAugmentation(HostNode.class);
- if (hostNode != null) {
- List<Addresses> addrList = hostNode.getAddresses();
- for (Addresses eachAddress : addrList) {
- macToIp.remove(eachAddress.getMac().getValue());
- ipToMac.remove(eachAddress.getIp().getIpv4Address().getValue());
- }
+ private void onAddressesChanged(Collection<DataTreeModification<Addresses>> changes) {
+ exec.submit(() -> {
+ for (DataTreeModification<Addresses> change: changes) {
+ final DataObjectModification<Addresses> rootNode = change.getRootNode();
+ switch (rootNode.getModificationType()) {
+ case WRITE:
+ case SUBTREE_MODIFIED:
+ Addresses origAddresses = rootNode.getDataBefore();
+ Addresses newAddresses = rootNode.getDataAfter();
+ if (origAddresses == null) {
+ log.info("createdData addresses:" + newAddresses);
+ macToIp.put(newAddresses.getMac().getValue(),
+ newAddresses.getIp().getIpv4Address().getValue());
+ ipToMac.put(newAddresses.getIp().getIpv4Address().getValue(),
+ newAddresses.getMac().getValue());
+ } else {
+ log.info("updatedData addresses:" + newAddresses + "~~" + origAddresses);
+ macToIp.remove(origAddresses.getMac().getValue());
+ macToIp.put(newAddresses.getMac().getValue(),
+ newAddresses.getIp().getIpv4Address().getValue());
+ ipToMac.remove(origAddresses.getIp().getIpv4Address().getValue());
+ ipToMac.put(newAddresses.getIp().getIpv4Address().getValue(),
+ newAddresses.getMac().getValue());
}
- }
- }
-
- for (Map.Entry<InstanceIdentifier<?>, DataObject> entrySet : updatedData
- .entrySet()) {
- InstanceIdentifier<?> iiD = entrySet.getKey();
- final DataObject dataObject = entrySet.getValue();
- if (dataObject instanceof Addresses) {
- Addresses addrs = (Addresses) dataObject;
- Addresses origAddr = (Addresses) originalData.get(iiD);
- log.info("updatedData addresses:" + addrs + "~~" + origAddr);
- macToIp.remove(origAddr.getMac().getValue());
- macToIp.put(addrs.getMac().getValue(), addrs.getIp().getIpv4Address().getValue());
- ipToMac.remove(origAddr.getIp().getIpv4Address().getValue());
- ipToMac.put(addrs.getIp().getIpv4Address().getValue(), addrs.getMac().getValue());
- }
+ break;
+ default:
+ break;
}
+ }
+ });
+ }
- for (Map.Entry<InstanceIdentifier<?>, DataObject> entrySet : createdData
- .entrySet()) {
- InstanceIdentifier<?> iiD = entrySet.getKey();
- final DataObject dataObject = entrySet.getValue();
- if (dataObject instanceof Addresses) {
- Addresses addrs = (Addresses) dataObject;
- log.info("createdData addresses:" + addrs);
- macToIp.put(addrs.getMac().getValue(), addrs.getIp().getIpv4Address().getValue());
- ipToMac.put(addrs.getIp().getIpv4Address().getValue(), addrs.getMac().getValue());
- }
+ private void onHostChanged(Collection<DataTreeModification<HostNode>> changes) {
+ exec.submit(() -> {
+ for (DataTreeModification<HostNode> change: changes) {
+ final DataObjectModification<HostNode> rootNode = change.getRootNode();
+ switch (rootNode.getModificationType()) {
+ case DELETE:
+ log.info("deletedData");
+ HostNode deletedHostNode = rootNode.getDataBefore();
+ List<Addresses> addrList = deletedHostNode.getAddresses();
+ for (Addresses eachAddress : addrList) {
+ macToIp.remove(eachAddress.getMac().getValue());
+ ipToMac.remove(eachAddress.getIp().getIpv4Address().getValue());
+ }
+ break;
+ default:
+ break;
}
}
});
*/
package org.opendaylight.alto.basic.endpointcostservice.suportservice.impl;
+import java.util.Collection;
import java.util.List;
-import java.util.Map;
-import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.opendaylight.alto.basic.endpointcostservice.helper.DataStoreHelper;
import org.opendaylight.alto.basic.endpointcostservice.suportservice.service.NetworkHostNodeService;
import org.opendaylight.alto.basic.endpointcostservice.util.InstanceIdentifierUtils;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.host.tracker.rev140624.HostNode;
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.Link;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class NetworkElementImpl implements NetworkElementService, DataChangeListener, AutoCloseable {
+public class NetworkElementImpl implements NetworkElementService, AutoCloseable {
private static final Logger log = LoggerFactory
.getLogger(NetworkElementImpl.class);
private static final int CPUS = Runtime.getRuntime().availableProcessors();
private final ExecutorService exec = Executors.newFixedThreadPool(CPUS);
private final DataBroker dataBroker;
- private ListenerRegistration<DataChangeListener> hostNodeListRegistration;
- private ListenerRegistration<DataChangeListener> linkListRegistration;
+ private ListenerRegistration<?> hostNodeListRegistration;
+ private ListenerRegistration<?> linkListRegistration;
private final NetworkHostNodeService hostNodeService;
private final LinkService linkService;
}
}
@Override
- public void close() throws Exception {
+ public void close() {
this.hostNodeListRegistration.close();
this.linkListRegistration.close();
}
- @Override
- public void onDataChanged(final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
- exec.submit(new Runnable() {
- @Override
- public void run() {
- if (change == null) {
- log.info("In onDataChanged: Change event is null.");
- return;
- }
- onDataUpdated(change);
- onDataCreated(change);
- onDataDeleted(change);
- }
-
- private void onDataUpdated(
- AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
- Map<InstanceIdentifier<?>, DataObject> updatedData = change
- .getUpdatedData();
- if (updatedData.size() > 0) {
- log.info("In onDataUpdated");
- processUpdatedOrCreatedData(updatedData);
- }
- }
-
- private void onDataCreated(
- AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
- Map<InstanceIdentifier<?>, DataObject> createdData = change
- .getCreatedData();
- if (createdData.size() > 0) {
- log.info("In onDataCreated");
- processUpdatedOrCreatedData(createdData);
- }
- }
-
- private void processUpdatedOrCreatedData(
- Map<InstanceIdentifier<?>, DataObject> data) {
- for (Map.Entry<InstanceIdentifier<?>, DataObject> entrySet : data
- .entrySet()) {
- final DataObject dataObject = entrySet.getValue();
- if (dataObject instanceof HostNode) {
+ private void onHostNodeChanged(Collection<DataTreeModification<HostNode>> changes) {
+ exec.submit(() -> {
+ for (DataTreeModification<HostNode> change: changes) {
+ final DataObjectModification<HostNode> rootNode = change.getRootNode();
+ switch (rootNode.getModificationType()) {
+ case WRITE:
+ case SUBTREE_MODIFIED:
log.info("Mapping host nodes to switch");
- hostNodeService.addHostNode((HostNode) dataObject);
- } else if (dataObject instanceof Link) {
- log.info("Updating Links");
- linkService.addLink((Link) dataObject);
- }
- }
- }
-
- private void onDataDeleted(
- AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
- Map<InstanceIdentifier<?>, DataObject> originalData = change
- .getOriginalData();
- Set<InstanceIdentifier<?>> deletedData = change
- .getRemovedPaths();
- if (deletedData.size() > 0) {
- log.info("In onDataDeleted");
- processDeletedData(originalData, deletedData);
+ hostNodeService.addHostNode(rootNode.getDataAfter());
+ break;
+ case DELETE:
+ hostNodeService.deleteHostNode(rootNode.getDataBefore());
+ break;
+ default:
+ break;
}
}
+ });
+ }
- private void processDeletedData(
- Map<InstanceIdentifier<?>, DataObject> originalData,
- Set<InstanceIdentifier<?>> deletedData) {
- for (InstanceIdentifier<?> iid : deletedData) {
- if (iid.getTargetType().equals(HostNode.class)) {
- hostNodeService.deleteHostNode((HostNode) originalData.get(iid));
- } else if (iid.getTargetType().equals(Link.class)) {
- linkService.deleteLink((Link) originalData.get(iid));
- }
+ private void onLinkChanged(Collection<DataTreeModification<Link>> changes) {
+ exec.submit(() -> {
+ for (DataTreeModification<Link> change: changes) {
+ final DataObjectModification<Link> rootNode = change.getRootNode();
+ switch (rootNode.getModificationType()) {
+ case WRITE:
+ case SUBTREE_MODIFIED:
+ log.info("Updating Links");
+ linkService.addLink(rootNode.getDataAfter());
+ break;
+ case DELETE:
+ linkService.deleteLink(rootNode.getDataBefore());
+ break;
+ default:
+ break;
}
}
});
-
}
@Override
}
private void registerHostNodeListener() {
- this.hostNodeListRegistration = this.dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, InstanceIdentifierUtils.HOSTNODE, this, AsyncDataBroker.DataChangeScope.BASE);
+ this.hostNodeListRegistration = this.dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(
+ LogicalDatastoreType.OPERATIONAL, InstanceIdentifierUtils.HOSTNODE),
+ changes -> onHostNodeChanged(changes));
}
+
private void registerLinkListener() {
- this.linkListRegistration = this.dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,InstanceIdentifierUtils.LINK,this, AsyncDataBroker.DataChangeScope.BASE);
+ this.linkListRegistration = this.dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(
+ LogicalDatastoreType.OPERATIONAL, InstanceIdentifierUtils.LINK), changes -> onLinkChanged(changes));
}
}
*/
package org.opendaylight.alto.basic.endpointcostservice.suportservice.impl;
+import java.util.Collection;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
import org.opendaylight.alto.basic.endpointcostservice.suportservice.service.NetworkPortStatisticsService;
import org.opendaylight.alto.basic.endpointcostservice.util.InstanceIdentifierUtils;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.node.connector.statistics.Bytes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatisticsData;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.node.connector.statistics.Bytes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatisticsData;
-
-public class NetworkPortStatisticsServiceImpl implements NetworkPortStatisticsService, DataChangeListener, AutoCloseable{
+public class NetworkPortStatisticsServiceImpl implements NetworkPortStatisticsService,
+ DataTreeChangeListener<FlowCapableNodeConnectorStatisticsData>, AutoCloseable {
private static final Logger logger = LoggerFactory
.getLogger(NetworkPortStatisticsServiceImpl.class);
private static final int CPUS = Runtime.getRuntime().availableProcessors();
- private ExecutorService exec = Executors.newFixedThreadPool(CPUS);
+ private final ExecutorService exec = Executors.newFixedThreadPool(CPUS);
private DataBroker dataBroker = null;
private class nodeStatistic {
}
}
- private Map<String, nodeStatistic> nodeStatisticData = null;
- private ListenerRegistration<DataChangeListener> portListener = null;
+ private final Map<String, nodeStatistic> nodeStatisticData = new ConcurrentHashMap<>();
+ private ListenerRegistration<?> portListener = null;
public NetworkPortStatisticsServiceImpl(DataBroker dataBroker) {
this.logger.info("NetworkPortStatisticsServiceImpl initial.");
this.dataBroker = dataBroker;
- nodeStatisticData = new HashMap<String, nodeStatistic>();
registerPortListener();
}
private void registerPortListener() {
- this.portListener = this.dataBroker.registerDataChangeListener(
- LogicalDatastoreType.OPERATIONAL, InstanceIdentifierUtils.STATISTICS,
- this, AsyncDataBroker.DataChangeScope.SUBTREE
- );
+ this.portListener = this.dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(
+ LogicalDatastoreType.OPERATIONAL, InstanceIdentifierUtils.STATISTICS), this);
}
@Override
public void close() throws Exception {
}
@Override
- public void onDataChanged(final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
- exec.submit(new Runnable() {
- @Override
- public void run() {
- onDataUpdated(change);
- onDataDeleted(change);
- }
-
- private void onDataUpdated(final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
- Map<InstanceIdentifier<?>, DataObject> updated = change.getUpdatedData();
-
- for (Map.Entry<InstanceIdentifier<?>, DataObject> eachEntry : updated.entrySet()) {
- final DataObject dataObject = eachEntry.getValue();
- if (dataObject instanceof FlowCapableNodeConnectorStatisticsData) {
- final FlowCapableNodeConnectorStatisticsData statistic =
- (FlowCapableNodeConnectorStatisticsData) dataObject;
- Bytes bytes = statistic.getFlowCapableNodeConnectorStatistics().getBytes();
- if (bytes != null) {
- String id = eachEntry.getKey()
- .firstKeyOf(NodeConnector.class)
- .getId().getValue();
- nodeStatistic ns = null;
- if (nodeStatisticData.containsKey(id)) {
- ns = nodeStatisticData.get(id);
- } else {
- ns = new nodeStatistic();
- nodeStatisticData.put(id, ns);
- }
- ns.rxSpeed = (bytes.getReceived().longValue() - ns.rxHistory) /
- (statistic.getFlowCapableNodeConnectorStatistics()
- .getDuration().getSecond().getValue() - ns.timestamp);
- ns.txSpeed = (bytes.getTransmitted().longValue() - ns.txHistory) /
- (statistic.getFlowCapableNodeConnectorStatistics()
- .getDuration().getSecond().getValue() - ns.timestamp);
- ns.rxHistory = bytes.getReceived().longValue();
- ns.txHistory = bytes.getTransmitted().longValue();
- ns.timestamp =
- statistic.getFlowCapableNodeConnectorStatistics()
- .getDuration().getSecond().getValue();
- }
- }
+ public void onDataTreeChanged(Collection<DataTreeModification<FlowCapableNodeConnectorStatisticsData>> changes) {
+ exec.submit(() -> {
+ for (DataTreeModification<FlowCapableNodeConnectorStatisticsData> change: changes) {
+ final DataObjectModification<FlowCapableNodeConnectorStatisticsData> rootNode = change.getRootNode();
+ final InstanceIdentifier<FlowCapableNodeConnectorStatisticsData> identifier =
+ change.getRootPath().getRootIdentifier();
+ switch (rootNode.getModificationType()) {
+ case WRITE:
+ case SUBTREE_MODIFIED:
+ onFlowCapableNodeConnectorStatisticsDataUpdated(identifier, rootNode.getDataAfter());
+ break;
+ case DELETE:
+ onFlowCapableNodeConnectorStatisticsDataDeleted(identifier);
+ break;
+ default:
+ break;
}
}
+ });
+ }
- private void onDataDeleted(final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
- Set<InstanceIdentifier<?>> removed = change.getRemovedPaths();
- for (InstanceIdentifier<?> eachPath : removed) {
- if (eachPath.getTargetType() == FlowCapableNodeConnectorStatisticsData.class) {
- String name =
- eachPath.firstKeyOf(NodeConnector.class).getId().getValue();
- nodeStatisticData.remove(name);
- }
- }
+ private void onFlowCapableNodeConnectorStatisticsDataDeleted(
+ InstanceIdentifier<FlowCapableNodeConnectorStatisticsData> identifier) {
+ String name = identifier.firstKeyOf(NodeConnector.class, NodeConnectorKey.class).getId().getValue();
+ nodeStatisticData.remove(name);
+ }
+
+ private void onFlowCapableNodeConnectorStatisticsDataUpdated(
+ InstanceIdentifier<FlowCapableNodeConnectorStatisticsData> identifier,
+ FlowCapableNodeConnectorStatisticsData statistic) {
+ Bytes bytes = statistic.getFlowCapableNodeConnectorStatistics().getBytes();
+ if (bytes != null) {
+ String id = identifier.firstKeyOf(NodeConnector.class).getId().getValue();
+ nodeStatistic ns = null;
+ if (nodeStatisticData.containsKey(id)) {
+ ns = nodeStatisticData.get(id);
+ } else {
+ ns = new nodeStatistic();
+ nodeStatisticData.put(id, ns);
}
- });
+ ns.rxSpeed = (bytes.getReceived().longValue() - ns.rxHistory) /
+ (statistic.getFlowCapableNodeConnectorStatistics()
+ .getDuration().getSecond().getValue() - ns.timestamp);
+ ns.txSpeed = (bytes.getTransmitted().longValue() - ns.txHistory) /
+ (statistic.getFlowCapableNodeConnectorStatistics()
+ .getDuration().getSecond().getValue() - ns.timestamp);
+ ns.rxHistory = bytes.getReceived().longValue();
+ ns.txHistory = bytes.getTransmitted().longValue();
+ ns.timestamp =
+ statistic.getFlowCapableNodeConnectorStatistics()
+ .getDuration().getSecond().getValue();
+ }
}
@Override
public Long getCurrentTxSpeed(String tpId, Metric metric) {
if (nodeStatisticData.containsKey(tpId)) {
- if (metric == Metric.BITSPERSECOND)
+ if (metric == Metric.BITSPERSECOND) {
return nodeStatisticData.get(tpId).txSpeed * 8;
- else if (metric == Metric.BYTESPERSECOND)
+ } else if (metric == Metric.BYTESPERSECOND) {
return nodeStatisticData.get(tpId).txSpeed;
+ }
}
return null;
}
@Override
public Long getCurrentRxSpeed(String tpId, Metric metric) {
if (nodeStatisticData.containsKey(tpId)) {
- if (metric == Metric.BITSPERSECOND)
+ if (metric == Metric.BITSPERSECOND) {
return nodeStatisticData.get(tpId).rxSpeed * 8;
- else if (metric == Metric.BYTESPERSECOND)
+ } else if (metric == Metric.BYTESPERSECOND) {
return nodeStatisticData.get(tpId).rxSpeed;
+ }
}
return null;
}
*/
package org.opendaylight.alto.basic.impl;
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.SettableFuture;
+import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Future;
-
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.SettableFuture;
-
import org.opendaylight.alto.basic.simpleird.SimpleIrdUtils;
import org.opendaylight.alto.core.resourcepool.ResourcepoolUtils;
-
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
-
-import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.IrdInstance;
-import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.IrdInstanceBuilder;
-import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.IrdInstanceConfiguration;
-import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.ird.instance.IrdEntry;
-import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.ird.instance.IrdEntryBuilder;
-import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.ird.instance.configuration.IrdConfigurationEntry;
-
import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.Context;
import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.ContextKey;
import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.context.Resource;
import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.context.ResourceKey;
import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.context.resource.ContextTag;
import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.context.resource.ContextTagKey;
-
+import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.IrdInstance;
+import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.IrdInstanceBuilder;
+import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.IrdInstanceConfiguration;
+import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.ird.instance.IrdEntry;
+import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.ird.instance.IrdEntryBuilder;
+import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.ird.instance.configuration.IrdConfigurationEntry;
import org.opendaylight.yang.gen.v1.urn.alto.types.rev150921.ResourceId;
import org.opendaylight.yang.gen.v1.urn.alto.types.rev150921.Tag;
-
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.ird.rev151021.ResourceTypeIrd;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.costmap.rev151021.ResourceTypeCostmap;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.costmap.rev151021.ResourceTypeFilteredCostmap;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rev151021.ResourceTypeEndpointcost;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.ird.rev151021.ResourceTypeIrd;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.networkmap.rev151021.ResourceTypeFilteredNetworkmap;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.networkmap.rev151021.ResourceTypeNetworkmap;
-
import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* listener to it's resource list.
*
* */
-public class SimpleIrdEntryListener implements AutoCloseable, DataChangeListener {
+public class SimpleIrdEntryListener implements AutoCloseable, DataTreeChangeListener<IrdConfigurationEntry> {
private static final Logger LOG = LoggerFactory.getLogger(SimpleIrdEntryListener.class);
private DataBroker m_dataBroker = null;
- private ListenerRegistration<DataChangeListener> m_reg = null;
- private Map<InstanceIdentifier<?>, ListenerRegistration<DataChangeListener>> m_regs = null;
+ private ListenerRegistration<?> m_reg = null;
private InstanceIdentifier<IrdConfigurationEntry> m_iid = null;
private Uuid m_context = null;
m_context = instance.firstKeyOf(Context.class).getContextId();
m_resource = instance.firstKeyOf(Resource.class).getResourceId();
m_entryContext = entryContext;
- m_regs = new HashMap<InstanceIdentifier<?>, ListenerRegistration<DataChangeListener>>();
}
public void register(DataBroker dataBroker, InstanceIdentifier<IrdConfigurationEntry> iid) {
m_dataBroker = dataBroker;
m_iid = iid;
- m_reg = m_dataBroker.registerDataChangeListener(
- LogicalDatastoreType.CONFIGURATION, m_iid,
- this, DataChangeScope.SUBTREE
- );
+ m_reg = m_dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(
+ LogicalDatastoreType.CONFIGURATION, m_iid), this);
LOG.info("SimpleIrdEntryListener registered");
}
ResourceKey resourceKey = new ResourceKey(rid);
ContextKey iidContextKey = iid.firstKeyOf(Context.class);
- if ((contextKey.equals(iidContextKey)) || (entryContextKey.equals(iidContextKey))) {
+ if (contextKey.equals(iidContextKey) || entryContextKey.equals(iidContextKey)) {
if (resourceKey.equals(iid.firstKeyOf(Resource.class))) {
return rx.read(LogicalDatastoreType.OPERATIONAL, iid);
}
}
@Override
- public synchronized void onDataChanged(
- final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
+ public synchronized void onDataTreeChanged(Collection<DataTreeModification<IrdConfigurationEntry>> changes) {
/*
* We examine the dependencies and check whether the services are self-contained
- * */
+ */
ReadWriteTransaction rwx = m_dataBroker.newReadWriteTransaction();
- InstanceIdentifier<IrdInstanceConfiguration> configIID;
- configIID =SimpleIrdUtils.getInstanceConfigurationIID(m_resource);
+ InstanceIdentifier<IrdInstanceConfiguration> configIID = SimpleIrdUtils.getInstanceConfigurationIID(m_resource);
Optional<IrdInstanceConfiguration> config;
try {
protected Map<IrdConfigurationEntry, Resource> readEntries(
List<IrdConfigurationEntry> configs, ReadWriteTransaction rwx) {
Map<IrdConfigurationEntry, Future<Optional<Resource>>> futures;
- futures = new HashMap<IrdConfigurationEntry, Future<Optional<Resource>>>();
+ futures = new HashMap<>();
for (IrdConfigurationEntry entry: configs) {
ResourceId expected = entry.getEntryId();
try {
InstanceIdentifier<?> iid = entry.getInstance();
- if ((iid == null) || (!iid.getTargetType().equals(Resource.class))) {
+ if (iid == null || !iid.getTargetType().equals(Resource.class)) {
LOG.error("Invalid instance identifier for {}", expected.getValue());
return null;
}
}
Map<IrdConfigurationEntry, Resource> resources;
- resources = new HashMap<IrdConfigurationEntry, Resource>();
+ resources = new HashMap<>();
for (Map.Entry<IrdConfigurationEntry, Future<Optional<Resource>>> entry: futures.entrySet()) {
try {
protected Map<ResourceId, List<ResourceId>> resolveDependency(
Map<IrdConfigurationEntry, Resource> resources) {
- Map<ResourceId, Tag> resourceMap = new HashMap<ResourceId, Tag>();
+ Map<ResourceId, Tag> resourceMap = new HashMap<>();
for (Resource resource: resources.values()) {
resourceMap.put(resource.getResourceId(), resource.getDefaultTag());
}
Map<ResourceId, List<ResourceId>> dependencyMap;
- dependencyMap = new HashMap<ResourceId, List<ResourceId>>();
+ dependencyMap = new HashMap<>();
for (Resource resource: resources.values()) {
- if ((resource.getContextTag() == null) || (resource.getContextTag().isEmpty())) {
+ if (resource.getContextTag() == null || resource.getContextTag().isEmpty()) {
continue;
}
ResourceId resourceId = iid.firstKeyOf(Resource.class).getResourceId();
Tag contextTag = iid.firstKeyOf(ContextTag.class).getTag();
- if ((contextId == null) || (resourceId == null) || (contextTag == null)) {
+ if (contextId == null || resourceId == null || contextTag == null) {
LOG.error("Depends on a resource that doesn't exist!");
return null;
}
} catch (Exception e) {
LOG.info("Error while closing the registration");
}
- try {
- for (ListenerRegistration<DataChangeListener> reg: m_regs.values()) {
- reg.close();
- }
- m_regs.clear();
- } catch (Exception e) {
- LOG.info("Error while closing the registrations");
- }
+
LOG.info("SimpleIrdEntryListener closed");
}
}
*/
package org.opendaylight.alto.basic.impl;
+import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-
import org.opendaylight.alto.basic.impl.rfc7285.SimpleIrdRfc7285CostTypeListener;
import org.opendaylight.alto.basic.impl.rfc7285.SimpleIrdRfc7285DefaultNetworkMapListener;
import org.opendaylight.alto.basic.simpleird.SimpleIrdUtils;
import org.opendaylight.alto.core.resourcepool.ResourcepoolUtils;
-
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
-
+import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.Context;
+import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.ContextKey;
+import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.context.Resource;
import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.IrdInstance;
import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.IrdInstanceBuilder;
import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.IrdInstanceConfiguration;
import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.ird.instance.IrdEntry;
import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.ird.instance.configuration.IrdConfigurationEntry;
-
-import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.Context;
-import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.ContextKey;
-import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.context.Resource;
-
import org.opendaylight.yang.gen.v1.urn.alto.types.rev150921.ResourceId;
-
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.ird.rev151021.ResourceTypeIrd;
-
import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* listener to it's resource list.
*
* */
-public class SimpleIrdListener implements AutoCloseable, DataChangeListener {
+public class SimpleIrdListener implements AutoCloseable, DataTreeChangeListener<IrdInstanceConfiguration> {
private static final Logger LOG = LoggerFactory.getLogger(SimpleIrdListener.class);
private DataBroker m_dataBroker = null;
- private ListenerRegistration<DataChangeListener> m_reg = null;
+ private ListenerRegistration<?> m_reg = null;
private InstanceIdentifier<IrdInstanceConfiguration> m_iid = null;
private Uuid m_context = null;
private Map<ResourceId, SimpleIrdRfc7285CostTypeListener> m_ctListeners = null;
public SimpleIrdListener(Uuid context) {
- m_listeners = new HashMap<ResourceId, SimpleIrdEntryListener>();
- m_rfcListeners = new HashMap<ResourceId, SimpleIrdRfc7285DefaultNetworkMapListener>();
- m_ctListeners = new HashMap<ResourceId, SimpleIrdRfc7285CostTypeListener>();
+ m_listeners = new HashMap<>();
+ m_rfcListeners = new HashMap<>();
+ m_ctListeners = new HashMap<>();
m_context = context;
}
m_dataBroker = dataBroker;
m_iid = iid;
- m_reg = m_dataBroker.registerDataChangeListener(
- LogicalDatastoreType.CONFIGURATION, m_iid,
- this, DataChangeScope.ONE
- );
+ m_reg = m_dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(
+ LogicalDatastoreType.CONFIGURATION, m_iid), this);
LOG.info("SimpleIrdListener registered");
}
@Override
- public synchronized void onDataChanged(
- final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
- /**
- * Update the operational data store according to the configurations.
+ public synchronized void onDataTreeChanged(Collection<DataTreeModification<IrdInstanceConfiguration>> changes) {
+ /* Update the operational data store according to the configurations.
*
* 1. Ignore resource updates because the registered resource are
* managed by another listener. Report error when path/uuid changes.
*
* 2. Try to accept removals and try to accept the created.
*
- * */
+ */
WriteTransaction wx = m_dataBroker.newWriteOnlyTransaction();
- Map<InstanceIdentifier<?>, DataObject> original = change.getOriginalData();
-
- for (Map.Entry<InstanceIdentifier<?>, DataObject> entry: change.getUpdatedData().entrySet()) {
- DataObject _origin = original.get(entry.getKey());
- DataObject _updated = entry.getValue();
-
- if (!(_origin instanceof IrdInstanceConfiguration)) {
- continue;
- }
- if (!(_updated instanceof IrdInstanceConfiguration)) {
- continue;
- }
-
- IrdInstanceConfiguration origin = (IrdInstanceConfiguration)_origin;
- IrdInstanceConfiguration updated = (IrdInstanceConfiguration)_updated;
-
- updateIrd(origin, updated, wx);
- }
-
- for (InstanceIdentifier<?> iid: change.getRemovedPaths()) {
- DataObject _removed = original.get(iid);
-
- if (!(_removed instanceof IrdInstanceConfiguration)) {
- continue;
- }
-
- IrdInstanceConfiguration removed = (IrdInstanceConfiguration)_removed;
- removeIrd(removed, wx);
- }
-
- for (Map.Entry<InstanceIdentifier<?>, DataObject> entry: change.getCreatedData().entrySet()) {
- DataObject _created = entry.getValue();
-
- if (!(_created instanceof IrdInstanceConfiguration)) {
- continue;
+ for (DataTreeModification<IrdInstanceConfiguration> change: changes) {
+ final DataObjectModification<IrdInstanceConfiguration> rootNode = change.getRootNode();
+ switch (rootNode.getModificationType()) {
+ case WRITE:
+ case SUBTREE_MODIFIED:
+ final IrdInstanceConfiguration original = rootNode.getDataBefore();
+ final IrdInstanceConfiguration updated = rootNode.getDataAfter();
+ if (original == null) {
+ createIrd(updated, wx);
+ } else {
+ updateIrd(original, updated, wx);
+ }
+ break;
+ case DELETE:
+ removeIrd(rootNode.getDataBefore(), wx);
+ break;
+ default:
+ break;
}
-
- IrdInstanceConfiguration created = (IrdInstanceConfiguration)_created;
- createIrd(created, wx);
}
wx.submit();
List<IrdConfigurationEntry> entries = cfg.getIrdConfigurationEntry();
- if ((entries != null) && (!entries.isEmpty())) {
+ if (entries != null && !entries.isEmpty()) {
LOG.warn("Do not support adding resources while create Ird, will be ignored");
}
*/
package org.opendaylight.alto.basic.impl.rfc7285;
+import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
-
import org.opendaylight.alto.basic.simpleird.SimpleIrdUtils;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-
+import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.context.Resource;
import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.IrdInstance;
import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.ird.entry.data.EntryCapabilities;
import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.ird.instance.IrdEntry;
-
import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rfc7285.rev151021.Rfc7285CostTypeCapabilities;
import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rfc7285.rev151021.Rfc7285CostTypeCapabilitiesBuilder;
import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rfc7285.rev151021.Rfc7285IrdMetadata;
import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rfc7285.rev151021.ird.instance.MetaBuilder;
import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rfc7285.rev151021.rfc7285.ird.meta.CostType;
import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rfc7285.rev151021.rfc7285.ird.meta.CostTypeBuilder;
-
-import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.context.Resource;
-
import org.opendaylight.yang.gen.v1.urn.alto.types.rev150921.CostTypeData;
import org.opendaylight.yang.gen.v1.urn.alto.types.rev150921.ResourceId;
-
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.costmap.rev151021.ResourceTypeCostmap;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.costmap.rev151021.ResourceTypeFilteredCostmap;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rev151021.ResourceTypeEndpointcost;
-
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rev151021.CapabilitiesCostType;
-
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rev151021.ResourceTypeEndpointcost;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
*
* */
public final class SimpleIrdRfc7285CostTypeListener
- implements AutoCloseable, DataChangeListener {
+ implements AutoCloseable, DataTreeChangeListener<IrdEntry> {
private static final Logger LOG = LoggerFactory.getLogger(SimpleIrdRfc7285CostTypeListener.class);
private DataBroker m_dataBroker = null;
- private ListenerRegistration<DataChangeListener> m_reg = null;
- private InstanceIdentifier<IrdEntry> m_iid = null;
+ private ListenerRegistration<?> m_reg = null;
+ private final InstanceIdentifier<IrdEntry> m_iid = null;
private ResourceId m_instance = null;
public void register(DataBroker dataBroker, ResourceId instanceId) {
m_dataBroker = dataBroker;
m_instance = instanceId;
- m_iid = SimpleIrdUtils.getInstanceIID(instanceId).child(IrdEntry.class);
- m_reg = m_dataBroker.registerDataChangeListener(
- LogicalDatastoreType.OPERATIONAL, m_iid,
- this, DataChangeScope.SUBTREE
- );
+ m_reg = m_dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(
+ LogicalDatastoreType.OPERATIONAL, SimpleIrdUtils.getInstanceIID(instanceId).child(IrdEntry.class)),
+ this);
LOG.info("SimpleIrdRfc7285CostTypeListener registered");
}
@Override
- public void onDataChanged(final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
+ public void onDataTreeChanged(Collection<DataTreeModification<IrdEntry>> changes) {
final ReadWriteTransaction rwx = m_dataBroker.newReadWriteTransaction();
try {
setCostTypes(m_instance, costTypeList, rwx);
rwx.submit();
- } catch (Exception e) {
- LOG.error("Failed to update cost-types {}", m_instance);
- e.printStackTrace();
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Failed to update cost-types {}", m_instance, e);
}
}
InstanceIdentifier<IrdInstance> iid = SimpleIrdUtils.getInstanceIID(m_instance);
IrdInstance instance = rwx.read(LogicalDatastoreType.OPERATIONAL, iid).get().get();
- Map<String, CostType> result = new HashMap<String, CostType>();
+ Map<String, CostType> result = new HashMap<>();
for (IrdEntry entry: instance.getIrdEntry()) {
InstanceIdentifier<Resource> resourceIID;
resourceIID = (InstanceIdentifier<Resource>)entry.getInstance();
capabilities = resource.getCapabilities()
.getAugmentation(CapabilitiesCostType.class);
- if ((capabilities == null) || (capabilities.getCostType() == null)
- || (capabilities.getCostType().isEmpty())) {
+ if (capabilities == null || capabilities.getCostType() == null
+ || capabilities.getCostType().isEmpty()) {
LOG.warn("Missing cost-type information in {}", resource.getResourceId());
continue;
}
*/
package org.opendaylight.alto.basic.impl.rfc7285;
-import java.util.concurrent.ExecutionException;
-
import com.google.common.base.Optional;
-
+import java.util.Collection;
+import java.util.concurrent.ExecutionException;
import org.opendaylight.alto.basic.simpleird.SimpleIrdUtils;
-
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-
-import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.IrdInstanceConfiguration;
+import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.context.Resource;
import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.ird.instance.IrdEntry;
-
import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rfc7285.rev151021.Rfc7285IrdConfigurationMetadata;
import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rfc7285.rev151021.Rfc7285IrdMetadata;
import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rfc7285.rev151021.Rfc7285IrdMetadataBuilder;
import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rfc7285.rev151021.ird.instance.MetaBuilder;
-
-import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.context.Resource;
-
import org.opendaylight.yang.gen.v1.urn.alto.types.rev150921.ResourceId;
-
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.networkmap.rev151021.ResourceTypeNetworkmap;
-
import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
*
* */
public final class SimpleIrdRfc7285DefaultNetworkMapListener
- implements AutoCloseable, DataChangeListener {
+ implements AutoCloseable, DataTreeChangeListener<Rfc7285IrdConfigurationMetadata> {
private static final Logger LOG = LoggerFactory.getLogger(SimpleIrdRfc7285DefaultNetworkMapListener.class);
private DataBroker m_dataBroker = null;
- private ListenerRegistration<DataChangeListener> m_reg = null;
- private InstanceIdentifier<IrdInstanceConfiguration> m_iid = null;
+ private ListenerRegistration<?> m_reg = null;
private ResourceId m_instance = null;
public void register(DataBroker dataBroker, ResourceId instanceId) {
m_dataBroker = dataBroker;
m_instance = instanceId;
- m_iid = SimpleIrdUtils.getInstanceConfigurationIID(instanceId);
- m_reg = m_dataBroker.registerDataChangeListener(
- LogicalDatastoreType.CONFIGURATION, m_iid,
- this, DataChangeScope.SUBTREE
- );
+ m_reg = m_dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(
+ LogicalDatastoreType.CONFIGURATION, SimpleIrdUtils.getInstanceConfigurationIID(instanceId)
+ .augmentation(Rfc7285IrdConfigurationMetadata.class)), this);
LOG.info("SimpleIrdRfc7285DefaultNetworkMapListener registered");
}
@Override
- public void onDataChanged(final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
- ResourceId defaultNetworkmap = null;
-
- try {
- ReadWriteTransaction rwx = m_dataBroker.newReadWriteTransaction();
- defaultNetworkmap = onConfigurationChanged(change, rwx);
-
- setDefaultNetworkMap(m_instance, defaultNetworkmap, rwx);
- rwx.submit();
- } catch (Exception e) {
- LOG.error("Failed to update the default-network-map");
+ public void onDataTreeChanged(Collection<DataTreeModification<Rfc7285IrdConfigurationMetadata>> changes) {
+ for (DataTreeModification<Rfc7285IrdConfigurationMetadata> change: changes) {
+ final DataObjectModification<Rfc7285IrdConfigurationMetadata> rootNode = change.getRootNode();
+ switch (rootNode.getModificationType()) {
+ case WRITE:
+ case SUBTREE_MODIFIED:
+ Rfc7285IrdConfigurationMetadata metadata = rootNode.getDataAfter();
+
+ ReadWriteTransaction rwx = m_dataBroker.newReadWriteTransaction();
+ ResourceId defaultNetworkmap = onConfigurationChanged(metadata, rwx);
+
+ if (defaultNetworkmap != null) {
+ setDefaultNetworkMap(m_instance, defaultNetworkmap, rwx);
+ rwx.submit();
+ } else {
+ rwx.cancel();
+ }
+ break;
+ default:
+ break;
+ }
}
}
- synchronized ResourceId onConfigurationChanged(
- final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change,
- ReadTransaction rx) throws InterruptedException, ExecutionException {
+ private ResourceId onConfigurationChanged(
+ final Rfc7285IrdConfigurationMetadata metadata, ReadTransaction rx) {
/**
* Check if the resource exists and is a network map
* */
- IrdInstanceConfiguration config;
- config = (IrdInstanceConfiguration)change.getUpdatedSubtree();
-
- Rfc7285IrdConfigurationMetadata metadata;
- metadata = config.getAugmentation(Rfc7285IrdConfigurationMetadata.class);
ResourceId defaultNetworkMapId = metadata.getMetaConfiguration()
.getDefaultNetworkMap();
InstanceIdentifier<IrdEntry> iid;
iid = SimpleIrdUtils.getEntryIID(m_instance, defaultNetworkMapId);
- Optional<IrdEntry> entry = rx.read(LogicalDatastoreType.OPERATIONAL, iid).get();
- if (entry.isPresent()) {
- if (entry.get().getInstance().getTargetType().equals(Resource.class)) {
- InstanceIdentifier<Resource> resourceIID;
- resourceIID = (InstanceIdentifier<Resource>)entry.get().getInstance();
-
- Resource resource = rx.read(LogicalDatastoreType.OPERATIONAL, resourceIID).get().get();
- if (resource.getType().equals(ResourceTypeNetworkmap.class)) {
- return defaultNetworkMapId;
+ try {
+ Optional<IrdEntry> entry = rx.read(LogicalDatastoreType.OPERATIONAL, iid).get();
+ if (entry.isPresent()) {
+ if (entry.get().getInstance().getTargetType().equals(Resource.class)) {
+ InstanceIdentifier<Resource> resourceIID;
+ resourceIID = (InstanceIdentifier<Resource>)entry.get().getInstance();
+
+ Resource resource = rx.read(LogicalDatastoreType.OPERATIONAL, resourceIID).get().get();
+ if (resource.getType().equals(ResourceTypeNetworkmap.class)) {
+ return defaultNetworkMapId;
+ }
}
- }
- LOG.error("{} is not a network map!", defaultNetworkMapId);
- } else {
- LOG.error("{} doesn't exist", defaultNetworkMapId);
+ LOG.error("{} is not a network map!", defaultNetworkMapId);
+ } else {
+ LOG.error("{} doesn't exist", defaultNetworkMapId);
+ }
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Failed to read the default-network-map", e);
}
+
return null;
}
*/
package org.opendaylight.alto.basic.impl;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
import com.google.common.base.Optional;
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.Futures;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Future;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
-import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.IrdInstanceConfiguration;
-import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.IrdInstanceConfigurationBuilder;
-import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.IrdInstanceConfigurationKey;
-import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.ird.entry.configuration.data.location.FixedUrlBuilder;
-import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.ird.instance.configuration.IrdConfigurationEntry;
-import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.ird.instance.configuration.IrdConfigurationEntryBuilder;
import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.Context;
import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.ContextKey;
import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.context.Resource;
import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.context.ResourceKey;
import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.context.resource.ContextTag;
import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.context.resource.ContextTagBuilder;
+import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.IrdInstanceConfiguration;
+import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.IrdInstanceConfigurationBuilder;
+import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.IrdInstanceConfigurationKey;
+import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.ird.entry.configuration.data.location.FixedUrlBuilder;
+import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.ird.instance.configuration.IrdConfigurationEntry;
+import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.ird.instance.configuration.IrdConfigurationEntryBuilder;
import org.opendaylight.yang.gen.v1.urn.alto.types.rev150921.ResourceId;
import org.opendaylight.yang.gen.v1.urn.alto.types.rev150921.Tag;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.costmap.rev151021.ResourceTypeFilteredCostmap;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rev151021.ResourceTypeEndpointcost;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.ird.rev151021.ResourceTypeIrd;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.networkmap.rev151021.ResourceTypeFilteredNetworkmap;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.networkmap.rev151021.ResourceTypeNetworkmap;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.Future;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
public class SimpleIrdEntryListenerTest {
private static final String DEFAULT_CONTEXT_UUID = "00000000-0000-0000-0000-000000000001";
private static final String DEFAULT_POOL_RESOURCE = "DEFAULT_RESOURCE";
private static final String DEFAULT_IRD_CONFIGURATION_KEY = "DEFAULT_IRD_CONFIGURATION";
- private DataBroker m_dataBroker = mock(DataBroker.class);
- private ListenerRegistration<DataChangeListener> m_reg = mock(ListenerRegistration.class);
- private InstanceIdentifier<Context> contextIId = InstanceIdentifier.builder(Context.class, new ContextKey(new Uuid(DEFAULT_CONTEXT_UUID))).build();
- private InstanceIdentifier<Resource> resourceIID = contextIId.child(Resource.class, new ResourceKey(new ResourceId(DEFAULT_POOL_RESOURCE)));
+ private final DataBroker m_dataBroker = mock(DataBroker.class);
+ private final ListenerRegistration<?> m_reg = mock(ListenerRegistration.class);
+ private final InstanceIdentifier<Context> contextIId = InstanceIdentifier.builder(Context.class, new ContextKey(new Uuid(DEFAULT_CONTEXT_UUID))).build();
+ private final InstanceIdentifier<Resource> resourceIID = contextIId.child(Resource.class, new ResourceKey(new ResourceId(DEFAULT_POOL_RESOURCE)));
private static final Uuid ecUuid = new Uuid(DEFAULT_CONTEXT_UUID);
- private SimpleIrdEntryListener simpleIrdEntryListener = new SimpleIrdEntryListener(resourceIID, ecUuid);
- private ReadTransaction rx = mock(ReadTransaction.class);
- private ReadWriteTransaction rwx = mock(ReadWriteTransaction.class);
- private MockDataChangedEvent dataChangedEvent = new MockDataChangedEvent();
+ private final SimpleIrdEntryListener simpleIrdEntryListener = new SimpleIrdEntryListener(resourceIID, ecUuid);
+ private final ReadTransaction rx = mock(ReadTransaction.class);
+ private final ReadWriteTransaction rwx = mock(ReadWriteTransaction.class);
+ @SuppressWarnings("unchecked")
@Before
public void setUp() {
- when(m_dataBroker.registerDataChangeListener(
- any(LogicalDatastoreType.class),
- any(InstanceIdentifier.class),
- any(DataChangeListener.class),
- any(AsyncDataBroker.DataChangeScope.class)))
+ when(m_dataBroker.registerDataTreeChangeListener(
+ any(DataTreeIdentifier.class),
+ any(DataTreeChangeListener.class)))
.thenReturn(m_reg);
InstanceIdentifier<IrdConfigurationEntry> iiceIID = InstanceIdentifier.builder(IrdInstanceConfiguration.class
@Test
public void register() throws Exception {
- when(m_dataBroker.registerDataChangeListener(
- any(LogicalDatastoreType.class),
- any(InstanceIdentifier.class),
- any(DataChangeListener.class),
- any(AsyncDataBroker.DataChangeScope.class)))
- .thenReturn(m_reg);
-
InstanceIdentifier<IrdConfigurationEntry> iiceIID = InstanceIdentifier.builder(IrdInstanceConfiguration.class
, new IrdInstanceConfigurationKey(new ResourceId(DEFAULT_IRD_CONFIGURATION_KEY)))
.child(IrdConfigurationEntry.class).build();
simpleIrdEntryListener.register(m_dataBroker, iiceIID);
- verify(m_dataBroker,times(2)).registerDataChangeListener(LogicalDatastoreType.CONFIGURATION, iiceIID
- , this.simpleIrdEntryListener, AsyncDataBroker.DataChangeScope.SUBTREE);
+ verify(m_dataBroker,times(2)).registerDataTreeChangeListener(new DataTreeIdentifier<>(
+ LogicalDatastoreType.CONFIGURATION, iiceIID), this.simpleIrdEntryListener);
}
@Test
assertEquals(opReFuture, result);
}
+ @SuppressWarnings("unchecked")
@Test
public void onDataChanged() throws Exception {
InstanceIdentifier<IrdConfigurationEntry> iiceIID = InstanceIdentifier.builder(IrdInstanceConfiguration.class
when(m_dataBroker.newReadWriteTransaction()).thenReturn(rwx);
Optional<IrdInstanceConfiguration> iicOp = Optional.of(new IrdInstanceConfigurationBuilder().build());
- final CheckedFuture<Optional<IrdInstanceConfiguration>, ReadFailedException> iicOpFu;
- iicOpFu = Futures.immediateCheckedFuture(iicOp);
+ final CheckedFuture<Optional<IrdInstanceConfiguration>, ReadFailedException> iicOpFu =
+ Futures.immediateCheckedFuture(iicOp);
when(rwx.read(LogicalDatastoreType.CONFIGURATION, configIID)).thenReturn(iicOpFu);
- simpleIrdEntryListener.onDataChanged(dataChangedEvent);
+
+ DataTreeModification<IrdConfigurationEntry> mockDataTreeModification = mock(DataTreeModification.class);
+ DataObjectModification<IrdConfigurationEntry> mockModification = mock(DataObjectModification.class);
+ doReturn(mockModification).when(mockDataTreeModification).getRootNode();
+
+ simpleIrdEntryListener.onDataTreeChanged(Collections.singletonList(mockDataTreeModification));
verify(rwx).read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
}
simpleIrdEntryListener.close();
verify(m_reg).close();
}
-
- static class MockDataChangedEvent implements AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> {
- Map<InstanceIdentifier<?>,DataObject> created = new HashMap<>();
- Map<InstanceIdentifier<?>,DataObject> updated = new HashMap<>();
- Set<InstanceIdentifier<?>> removed = new HashSet<>();
-
- @Override
- public Map<InstanceIdentifier<?>, DataObject> getCreatedData() {
- return created;
- }
-
- @Override
- public Map<InstanceIdentifier<?>, DataObject> getUpdatedData() {
- return updated;
- }
-
- @Override
- public Set<InstanceIdentifier<?>> getRemovedPaths() {
- return removed;
- }
-
- @Override
- public Map<InstanceIdentifier<?>, DataObject> getOriginalData() {
- throw new UnsupportedOperationException("Not implemented by mock");
- }
-
- @Override
- public DataObject getOriginalSubtree() {
- throw new UnsupportedOperationException("Not implemented by mock");
- }
-
- @Override
- public DataObject getUpdatedSubtree() {
- throw new UnsupportedOperationException("Not implemented by mock");
- }
- }
-
-}
\ No newline at end of file
+}
package org.opendaylight.alto.basic.impl;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.Collections;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
-import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
+import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.Context;
+import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.ContextKey;
import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.IrdInstanceConfiguration;
import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.IrdInstanceConfigurationBuilder;
import org.opendaylight.yang.gen.v1.urn.alto.simple.ird.rev151021.IrdInstanceConfigurationKey;
-import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.Context;
-import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.ContextKey;
import org.opendaylight.yang.gen.v1.urn.alto.types.rev150921.ResourceId;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
public class SimpleIrdListenerTest {
- private DataBroker m_dataBroker = mock(DataBroker.class);
- private ListenerRegistration<DataChangeListener> m_reg = mock(ListenerRegistration.class);
- private SimpleIrdListener simpleIrdListener = new SimpleIrdListener(new Uuid(DEFAULT_UUID));
- private WriteTransaction wx = mock(WriteTransaction.class);
- private ReadWriteTransaction rwx = mock(ReadWriteTransaction.class);
- private MockDataChangedEvent dataChangedEvent = new MockDataChangedEvent();
+ private final DataBroker m_dataBroker = mock(DataBroker.class);
+ private final ListenerRegistration<?> m_reg = mock(ListenerRegistration.class);
+ private final SimpleIrdListener simpleIrdListener = new SimpleIrdListener(new Uuid(DEFAULT_UUID));
+ private final WriteTransaction wx = mock(WriteTransaction.class);
private static final String DEFAULT_UUID = "00000000-0000-0000-0000-000000000001";
private static final String DEFAULT_CONTEXT_UUID = "00000000-0000-0000-0000-000000000001";
private static String UPDATED_INSTANCE_ID="UPDATED_INSTANCE_ID";
private static String DEFAULT_INSTANCE_ID="DEFAULT_INSTANCE_ID";
+ @SuppressWarnings("unchecked")
@Before
public void setUp() {
- when(m_dataBroker.registerDataChangeListener(
- any(LogicalDatastoreType.class),
- any(InstanceIdentifier.class),
- any(DataChangeListener.class),
- any(AsyncDataBroker.DataChangeScope.class)))
+ when(m_dataBroker.registerDataTreeChangeListener(
+ any(DataTreeIdentifier.class),
+ any(DataTreeChangeListener.class)))
.thenReturn(m_reg);
InstanceIdentifier<IrdInstanceConfiguration> iicIID = InstanceIdentifier.builder(IrdInstanceConfiguration.class).build();
simpleIrdListener.register(m_dataBroker, iicIID);
}
+ @SuppressWarnings("unchecked")
@Test
public void register() throws Exception {
- when(m_dataBroker.registerDataChangeListener(
- any(LogicalDatastoreType.class),
- any(InstanceIdentifier.class),
- any(DataChangeListener.class),
- any(AsyncDataBroker.DataChangeScope.class)))
- .thenReturn(m_reg);
-
InstanceIdentifier<IrdInstanceConfiguration> iicIID = InstanceIdentifier.builder(IrdInstanceConfiguration.class).build();
simpleIrdListener.register(m_dataBroker, iicIID);
- verify(m_dataBroker, times(2)).registerDataChangeListener(LogicalDatastoreType.CONFIGURATION, iicIID
- , this.simpleIrdListener, AsyncDataBroker.DataChangeScope.ONE);
+ verify(m_dataBroker, times(2)).registerDataTreeChangeListener(new DataTreeIdentifier<>(
+ LogicalDatastoreType.CONFIGURATION, iicIID), this.simpleIrdListener);
}
+ @SuppressWarnings("unchecked")
@Test
public void onDataChanged() throws Exception {
+ DataTreeModification<IrdInstanceConfiguration> mockDataTreeModification = mock(DataTreeModification.class);
+ DataObjectModification<IrdInstanceConfiguration> mockModification = mock(DataObjectModification.class);
+ doReturn(mockModification).when(mockDataTreeModification).getRootNode();
+
+ IrdInstanceConfiguration iicb = new IrdInstanceConfigurationBuilder()
+ .setKey(new IrdInstanceConfigurationKey(new ResourceId("ORIGINAL_CONFIG"))).build();
+ doReturn(iicb).when(mockModification).getDataAfter();
+ doReturn(DataObjectModification.ModificationType.WRITE).when(mockModification).getModificationType();
+
when(m_dataBroker.newWriteOnlyTransaction()).thenReturn(wx);
- simpleIrdListener.onDataChanged(dataChangedEvent);
+ simpleIrdListener.onDataTreeChanged(Collections.singletonList(mockDataTreeModification));
//TBD
}
simpleIrdListener.close();
verify(m_reg).close();
}
-
- static class MockDataChangedEvent implements AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> {
- Map<InstanceIdentifier<?>,DataObject> created = new HashMap<>();
- Map<InstanceIdentifier<?>,DataObject> updated = new HashMap<>();
- Set<InstanceIdentifier<?>> removed = new HashSet<>();
-
- @Override
- public Map<InstanceIdentifier<?>, DataObject> getCreatedData() {
- return created;
- }
-
- @Override
- public Map<InstanceIdentifier<?>, DataObject> getUpdatedData() {
- Map<InstanceIdentifier<?>, DataObject> updated = new HashMap<>();
- InstanceIdentifier<IrdInstanceConfiguration> iicIID = InstanceIdentifier.builder(
- IrdInstanceConfiguration.class, new IrdInstanceConfigurationKey(new ResourceId("UPDATED_CONFIG"))).build();
- IrdInstanceConfigurationBuilder iicb = new IrdInstanceConfigurationBuilder()
- .setKey(new IrdInstanceConfigurationKey(new ResourceId("UPDATED_CONFIG")));
- updated.put(iicIID, iicb.build());
-
- return updated;
- }
-
- @Override
- public Set<InstanceIdentifier<?>> getRemovedPaths() {
- return removed;
- }
-
- @Override
- public Map<InstanceIdentifier<?>, DataObject> getOriginalData() {
- Map<InstanceIdentifier<?>, DataObject> originaled = new HashMap<>();
- InstanceIdentifier<IrdInstanceConfiguration> iicIID = InstanceIdentifier.builder(
- IrdInstanceConfiguration.class, new IrdInstanceConfigurationKey(new ResourceId("ORIGINAL_CONFIG"))).build();
- IrdInstanceConfigurationBuilder iicb = new IrdInstanceConfigurationBuilder()
- .setKey(new IrdInstanceConfigurationKey(new ResourceId("ORIGINAL_CONFIG")));
- originaled.put(iicIID, iicb.build());
- return originaled;
- }
-
- @Override
- public DataObject getOriginalSubtree() {
- throw new UnsupportedOperationException("Not implemented by mock");
- }
-
- @Override
- public DataObject getUpdatedSubtree() {
- throw new UnsupportedOperationException("Not implemented by mock");
- }
- }
-
-}
\ No newline at end of file
+}
package org.opendaylight.alto.core.resourcepool;
+import com.google.common.base.Optional;
import java.util.Arrays;
+import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
-
-import com.google.common.base.Optional;
-
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
-
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
-
-import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.ResourceType;
-import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.ServiceContext;
import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.Context;
import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.ContextBuilder;
import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.ContextKey;
+import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.ResourceType;
+import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.ServiceContext;
import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.context.Resource;
import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.context.ResourceBuilder;
import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.context.ResourceKey;
import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.context.resource.ContextTag;
import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.context.resource.ContextTagBuilder;
import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.context.resource.ContextTagKey;
-
import org.opendaylight.yang.gen.v1.urn.alto.types.rev150921.ResourceId;
import org.opendaylight.yang.gen.v1.urn.alto.types.rev150921.Tag;
-
-import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.RpcService;
Optional<Context> context;
context = rx.read(LogicalDatastoreType.OPERATIONAL, getContextIID(key)).get();
- return (context.isPresent());
+ return context.isPresent();
}
public static Uuid createRandomContext(final WriteTransaction wx) {
Optional<Resource> resource;
resource = rx.read(LogicalDatastoreType.OPERATIONAL, iid).get();
- return (resource.isPresent());
+ return resource.isPresent();
}
public static ResourceId createResource(String cid, String rid,
* Unfortunately the resources must handle the dependency resolving themselves
* */
if (dependencies == null) {
- dependencies = new LinkedList<InstanceIdentifier<?>>();
+ dependencies = new LinkedList<>();
}
ctBuilder.setDependency(dependencies);
return UUID.nameUUIDFromBytes(name.getBytes()).toString();
}
- public static final class ContextTagListener implements DataChangeListener {
+ public static final class ContextTagListener implements DataTreeChangeListener<ContextTag> {
private RoutedRpcRegistration<? extends RpcService> m_registration = null;
private InstanceIdentifier<Resource> m_iid = null;
}
@Override
- public void onDataChanged(final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
- for (InstanceIdentifier<?> path: change.getRemovedPaths()) {
- if (path.getTargetType().equals(ContextTag.class)) {
- if (m_iid.contains(path)) {
- // Only manage resource's own context tag
- m_registration.unregisterPath(ServiceContext.class, path);
- }
+ public void onDataTreeChanged(Collection<DataTreeModification<ContextTag>> changes) {
+ for (DataTreeModification<ContextTag> change: changes) {
+ final DataObjectModification<ContextTag> rootNode = change.getRootNode();
+ final InstanceIdentifier<ContextTag> identifier = change.getRootPath().getRootIdentifier();
+ if (!m_iid.contains(identifier)) {
+ // Only manage resource's own context tag
+ continue;
}
- }
- for (InstanceIdentifier<?> path: change.getCreatedData().keySet()) {
- if (path.getTargetType().equals(ContextTag.class)) {
- if (m_iid.contains(path)) {
- // Only manage resource's own context tag
- m_registration.registerPath(ServiceContext.class, path);
- }
+ switch (rootNode.getModificationType()) {
+ case WRITE:
+ if (rootNode.getDataBefore() == null) {
+ m_registration.registerPath(ServiceContext.class, identifier);
+ }
+ break;
+ case DELETE:
+ m_registration.unregisterPath(ServiceContext.class, identifier);
+ break;
+ default:
+ break;
}
}
}
*/
package org.opendaylight.alto.core.northbound.route.costmap.impl;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import javax.ws.rs.core.Response;
import org.junit.Test;
import org.opendaylight.alto.core.northbound.api.utils.rfc7285.RFC7285CostMap;
import org.opendaylight.alto.core.northbound.api.utils.rfc7285.RFC7285CostType;
-import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.context.resource.ContextTag;
import org.opendaylight.yang.gen.v1.urn.alto.types.rev150921.CostMetric;
import org.opendaylight.yang.gen.v1.urn.alto.types.rev150921.PidName;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.costmap.rfc7285.rev151021.costmap.filter.data.CostmapFilter;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.costmap.rfc7285.rev151021.query.input.request.costmap.request.costmap.params.filter.CostmapFilterData;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.costmap.rfc7285.rev151021.query.output.response.costmap.response.costmap.response.data.costmap.source.costmap.destination.cost.OrdinalBuilder;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.RpcResult;
-
-import javax.annotation.Nonnull;
-import javax.ws.rs.core.Response;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.anyObject;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
public class AltoNorthboundCostmapTest {
String filter = "{\"cost-type\": {\"cost-metric\": \"routingcost\", \"cost-mode\": \"numerical\"}, \"pids\": {\"dsts\": [ \"PID1\", \"PID2\", \"PID3\" ], \"srcs\": [ \"PID1\" ] }}";
//configure mock
doReturn(ctagIID).when(costmapSpy).getResourceByPath(eq(path),(ReadOnlyTransaction) anyObject());
- costmapSpy.setDataBroker(new DataBroker() {
- @Override
- public ReadOnlyTransaction newReadOnlyTransaction() {
- return null;
- }
-
- @Override
- public ReadWriteTransaction newReadWriteTransaction() {
- return null;
- }
-
- @Override
- public WriteTransaction newWriteOnlyTransaction() {
- return null;
- }
-
- @Override
- public ListenerRegistration<DataChangeListener> registerDataChangeListener(LogicalDatastoreType logicalDatastoreType, InstanceIdentifier<?> instanceIdentifier, DataChangeListener dataChangeListener, DataChangeScope dataChangeScope) {
- return null;
- }
-
- @Override
- public BindingTransactionChain createTransactionChain(TransactionChainListener transactionChainListener) {
- return null;
- }
+ costmapSpy.setDataBroker(mock(DataBroker.class));
- @Nonnull
- @Override
- public <T extends DataObject, L extends DataTreeChangeListener<T>> ListenerRegistration<L> registerDataTreeChangeListener(@Nonnull DataTreeIdentifier<T> dataTreeIdentifier, @Nonnull L l) {
- return null;
- }
- });
- costmapSpy.setMapService(new AltoModelCostmapService() {
- @Override
- public Future<RpcResult<QueryOutput>> query(QueryInput queryInput) {
- return null;
- }
- });
+ costmapSpy.setMapService(queryInput -> null);
//start test
costmapSpy.init();
CostmapParams params = request.getCostmapParams();
CostmapFilter costmapFilter=((CostmapFilterData)params.getFilter()).getCostmapFilter();
CostType costType = params.getCostType();
- List<PidName> pidNames1 = new LinkedList<PidName>();
+ List<PidName> pidNames1 = new LinkedList<>();
for (String pid:pid_source){
PidName p = new PidName(pid);
pidNames1.add(p);
}
- List<PidName> pidNames2 = new LinkedList<PidName>();
+ List<PidName> pidNames2 = new LinkedList<>();
for (String pid:pid_destination){
PidName p = new PidName(pid);
pidNames2.add(p);
RpcResult<QueryOutput> rpcResult = mock(RpcResult.class);
//build QueryOutput
int order = 0;
- LinkedList<CostmapSource> costmapSources = new LinkedList<CostmapSource>();
+ LinkedList<CostmapSource> costmapSources = new LinkedList<>();
for(String src:pid_source){
- LinkedList<CostmapDestination> costmapDestinations= new LinkedList<CostmapDestination>();
+ LinkedList<CostmapDestination> costmapDestinations= new LinkedList<>();
for (String dst : pid_destination){
CostmapDestinationBuilder costmapDestinationBuilder= new CostmapDestinationBuilder();
costmapSpy.setMapService(costmapService);
- costmapSpy.setDataBroker(new DataBroker() {
- @Override
- public ReadOnlyTransaction newReadOnlyTransaction() {
- return null;
- }
-
- @Override
- public ReadWriteTransaction newReadWriteTransaction() {
- return null;
- }
-
- @Override
- public WriteTransaction newWriteOnlyTransaction() {
- return null;
- }
-
- @Override
- public ListenerRegistration<DataChangeListener> registerDataChangeListener(LogicalDatastoreType logicalDatastoreType, InstanceIdentifier<?> instanceIdentifier, DataChangeListener dataChangeListener, DataChangeScope dataChangeScope) {
- return null;
- }
+ costmapSpy.setDataBroker(mock(DataBroker.class));
- @Override
- public BindingTransactionChain createTransactionChain(TransactionChainListener transactionChainListener) {
- return null;
- }
-
- @Nonnull
- @Override
- public <T extends DataObject, L extends DataTreeChangeListener<T>> ListenerRegistration<L> registerDataTreeChangeListener(@Nonnull DataTreeIdentifier<T> dataTreeIdentifier, @Nonnull L l) {
- return null;
- }
- });
doReturn(ctagIID).when(costmapSpy).getResourceByPath(eq(path),(ReadOnlyTransaction) anyObject());
RFC7285CostMap.Meta meta = new RFC7285CostMap.Meta();
RFC7285CostType rfc7285costType = new RFC7285CostType();
*/
package org.opendaylight.alto.core.northbound.route.endpointcost.impl;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import javax.ws.rs.core.Response;
import org.junit.Assert;
import org.junit.Test;
-import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.context.resource.ContextTag;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rev151021.AltoModelEndpointcostService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rev151021.QueryInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rev151021.QueryOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rfc7285.rev151021.query.output.response.endpointcost.response.endpointcost.data.EndpointCostmapDataBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rfc7285.rev151021.query.output.response.endpointcost.response.endpointcost.data.endpoint.costmap.data.endpoint.cost.map.endpoint.cost.cost.OrdinalBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rfc7285.rev151021.typed.address.data.Address;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.RpcResult;
-import javax.annotation.Nonnull;
-import javax.ws.rs.core.Response;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.anyObject;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-
public class AltoNorthboundEndpointcostTest {
String filter = "{\"cost-type\":{\"cost-mode\" : \"ordinal\",\"cost-metric\" : \"routingcost\"},\"endpoints\" : {\"srcs\": [ \"ipv4:192.0.2.2\" ],\"dsts\": [\"ipv4:192.0.2.89\",\"ipv4:198.51.100.34\",\"ipv4:203.0.113.45\"]}}";
//configure mock
doReturn(ctagIID).when(endpointcostSpy).getResourceByPath(eq(path),(ReadOnlyTransaction) anyObject());
- endpointcostSpy.setDataBroker(new DataBroker() {
- @Override
- public ReadOnlyTransaction newReadOnlyTransaction() {
- return null;
- }
-
- @Override
- public ReadWriteTransaction newReadWriteTransaction() {
- return null;
- }
-
- @Override
- public WriteTransaction newWriteOnlyTransaction() {
- return null;
- }
-
- @Override
- public ListenerRegistration<DataChangeListener> registerDataChangeListener(LogicalDatastoreType logicalDatastoreType, InstanceIdentifier<?> instanceIdentifier, DataChangeListener dataChangeListener, DataChangeScope dataChangeScope) {
- return null;
- }
-
- @Override
- public BindingTransactionChain createTransactionChain(TransactionChainListener transactionChainListener) {
- return null;
- }
-
- @Nonnull
- @Override
- public <T extends DataObject, L extends DataTreeChangeListener<T>> ListenerRegistration<L> registerDataTreeChangeListener(@Nonnull DataTreeIdentifier<T> dataTreeIdentifier, @Nonnull L l) {
- return null;
- }
- });
- endpointcostSpy.setMapService(new AltoModelEndpointcostService() {
- @Override
- public Future<RpcResult<QueryOutput>> query(QueryInput queryInput) {
- return null;
- }
- });
+ endpointcostSpy.setDataBroker(mock(DataBroker.class));
+ endpointcostSpy.setMapService(queryInput -> null);
//start test
endpointcostSpy.init();
AltoModelEndpointcostService endpointcostService = mock(AltoModelEndpointcostService.class);
Future<RpcResult<QueryOutput>> future = mock(Future.class);
RpcResult<QueryOutput> rpcResult = mock(RpcResult.class);
- List<Source> sources = new ArrayList<Source>();
- List<Destination> destinations = new ArrayList<Destination>();
+ List<Source> sources = new ArrayList<>();
+ List<Destination> destinations = new ArrayList<>();
for(String source : endpoints_source_ipv4){
SourceBuilder sourceBuilder = new SourceBuilder();
List<? extends TypedAddressData> destination = destinations;
int order = 0;
- LinkedList<EndpointCost> ecList = new LinkedList<EndpointCost>();
+ LinkedList<EndpointCost> ecList = new LinkedList<>();
for (TypedAddressData src: source) {
for (TypedAddressData dst: destination) {
org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rfc7285.rev151021.endpointcostmap.response.data.endpoint.cost.map.endpoint.cost.SourceBuilder srcBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rfc7285.rev151021.endpointcostmap.response.data.endpoint.cost.map.endpoint.cost.SourceBuilder();
when(future.get()).thenReturn(rpcResult);
when(endpointcostService.query((QueryInput)anyObject())).thenReturn(future);
- endpointcostSpy.setDataBroker(new DataBroker() {
- @Override
- public ReadOnlyTransaction newReadOnlyTransaction() {
- return null;
- }
-
- @Override
- public ReadWriteTransaction newReadWriteTransaction() {
- return null;
- }
-
- @Override
- public WriteTransaction newWriteOnlyTransaction() {
- return null;
- }
-
- @Override
- public ListenerRegistration<DataChangeListener> registerDataChangeListener(LogicalDatastoreType logicalDatastoreType, InstanceIdentifier<?> instanceIdentifier, DataChangeListener dataChangeListener, DataChangeScope dataChangeScope) {
- return null;
- }
-
- @Override
- public BindingTransactionChain createTransactionChain(TransactionChainListener transactionChainListener) {
- return null;
- }
-
- @Nonnull
- @Override
- public <T extends DataObject, L extends DataTreeChangeListener<T>> ListenerRegistration<L> registerDataTreeChangeListener(@Nonnull DataTreeIdentifier<T> dataTreeIdentifier, @Nonnull L l) {
- return null;
- }
- });
+ endpointcostSpy.setDataBroker(mock(DataBroker.class));
endpointcostSpy.setMapService(endpointcostService);
doReturn(ctagIID).when(endpointcostSpy).getResourceByPath(eq(path), (ReadOnlyTransaction)anyObject());
*/
package org.opendaylight.alto.core.northbound.route.endpointproperty.impl;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
+import java.io.IOException;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import javax.ws.rs.core.Response;
import org.junit.Test;
import org.opendaylight.alto.core.northbound.api.utils.rfc7285.RFC7285EndpointPropertyMap;
import org.opendaylight.alto.core.northbound.api.utils.rfc7285.RFC7285VersionTag;
-import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.context.resource.ContextTag;
import org.opendaylight.yang.gen.v1.urn.alto.types.rev150921.GlobalEndpointProperty;
import org.opendaylight.yang.gen.v1.urn.alto.types.rev150921.PidName;
import org.opendaylight.yang.gen.v1.urn.alto.types.rev150921.SpecificEndpointProperty;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointproperty.rev151021.AltoModelEndpointpropertyService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointproperty.rev151021.QueryInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointproperty.rev151021.QueryOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointproperty.rfc7285.rev151021.query.output.response.endpointproperty.response.endpointproperty.data.endpoint.propertymap.data.endpoint.property.map.endpoint.property.properties.property.container.property.OutputGlobalPropertyBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointproperty.rfc7285.rev151021.query.output.response.endpointproperty.response.endpointproperty.data.endpoint.propertymap.data.endpoint.property.map.endpoint.property.properties.property.container.property.OutputResourceSpecificPropertyBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointproperty.rfc7285.rev151021.query.output.response.endpointproperty.response.endpointproperty.data.endpoint.propertymap.data.endpoint.property.map.endpoint.property.properties.property.value.PidNameBuilder;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.RpcResult;
-import javax.annotation.Nonnull;
-import javax.ws.rs.core.Response;
-
-import java.io.IOException;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.anyObject;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
public class AltoNorthboundRouteEndpointpropertyTest {
static String ENDPOINTPROPERTY_FILTER = "{\"properties\" : [ \"my-default-networkmap.pid\","
+ " \"priv:ietf-example-prop\" ],"
doReturn(ctagIID)
.when(anbreSpy)
.getResourceByPath(eq(PATH), (ReadOnlyTransaction) anyObject());
- anbreSpy.setDataBroker(new DataBroker() {
- @Override public ReadOnlyTransaction newReadOnlyTransaction() {
- return null;
- }
-
- @Override public ReadWriteTransaction newReadWriteTransaction() {
- return null;
- }
-
- @Override public WriteTransaction newWriteOnlyTransaction() {
- return null;
- }
-
- @Override public ListenerRegistration<DataChangeListener> registerDataChangeListener(
- LogicalDatastoreType logicalDatastoreType, InstanceIdentifier<?> instanceIdentifier,
- DataChangeListener dataChangeListener, DataChangeScope dataChangeScope) {
- return null;
- }
-
- @Override public BindingTransactionChain createTransactionChain(
- TransactionChainListener transactionChainListener) {
- return null;
- }
-
- @Nonnull @Override
- public <T extends DataObject, L extends DataTreeChangeListener<T>> ListenerRegistration<L> registerDataTreeChangeListener(
- @Nonnull DataTreeIdentifier<T> dataTreeIdentifier, @Nonnull L l) {
- return null;
- }
- });
+ anbreSpy.setDataBroker(mock(DataBroker.class));
anbreSpy.init();
QueryInput input = anbreSpy.prepareInput(PATH, _properties.elements(), _endpoints.elements());
when(future.get()).thenReturn(rpcResult);
when(epService.query((QueryInput) anyObject())).thenReturn(future);
anbreSpy.setMapService(epService);
- anbreSpy.setDataBroker(new DataBroker() {
- @Override public ReadOnlyTransaction newReadOnlyTransaction() {
- return null;
- }
-
- @Override public ReadWriteTransaction newReadWriteTransaction() {
- return null;
- }
-
- @Override public WriteTransaction newWriteOnlyTransaction() {
- return null;
- }
-
- @Override public ListenerRegistration<DataChangeListener> registerDataChangeListener(
- LogicalDatastoreType logicalDatastoreType, InstanceIdentifier<?> instanceIdentifier,
- DataChangeListener dataChangeListener, DataChangeScope dataChangeScope) {
- return null;
- }
-
- @Override public BindingTransactionChain createTransactionChain(
- TransactionChainListener transactionChainListener) {
- return null;
- }
+ anbreSpy.setDataBroker(mock(DataBroker.class));
- @Nonnull @Override
- public <T extends DataObject, L extends DataTreeChangeListener<T>> ListenerRegistration<L> registerDataTreeChangeListener(
- @Nonnull DataTreeIdentifier<T> dataTreeIdentifier, @Nonnull L l) {
- return null;
- }
- });
doReturn(ctagIID).when(anbreSpy).getResourceByPath(eq(PATH), (ReadOnlyTransaction) anyObject());
RFC7285EndpointPropertyMap.Meta meta = new RFC7285EndpointPropertyMap.Meta();
RFC7285VersionTag vtag = new RFC7285VersionTag();
*/
package org.opendaylight.alto.core.northbound.route.networkmap.impl;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import javax.ws.rs.core.Response;
import org.junit.Test;
import org.opendaylight.alto.core.northbound.api.utils.rfc7285.RFC7285NetworkMap;
-import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.context.resource.ContextTag;
import org.opendaylight.yang.gen.v1.urn.alto.types.rev150921.PidName;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.networkmap.rev151021.AddressTypeBase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.networkmap.rev151021.AddressTypeIpv4;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.networkmap.rev151021.AddressTypeIpv6;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.networkmap.rfc7285.rev151021.Ipv4PrefixListBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.networkmap.rfc7285.rev151021.Ipv6PrefixList;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.networkmap.rfc7285.rev151021.Ipv6PrefixListBuilder;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.RpcResult;
-
-import javax.annotation.Nonnull;
-import javax.ws.rs.core.Response;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.anyObject;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
public class AltoNorthboundNetworkmapTest {
String path = "test-model-networkmap";
String filter = "{\n" +
doReturn(ctagIID).when(networkmapSpy).getResourceByPath(eq(path), (ReadOnlyTransaction) anyObject());
doReturn( AddressTypeIpv4.class).when(networkmapSpy).getAddressTypeByName(eq("ipv4"), eq(path), (ReadOnlyTransaction)anyObject());
doReturn( AddressTypeIpv6.class).when(networkmapSpy).getAddressTypeByName(eq("ipv6"), eq(path), (ReadOnlyTransaction)anyObject());
- networkmapSpy.setDataBroker(new DataBroker() {
- @Override
- public ReadOnlyTransaction newReadOnlyTransaction() {
- return null;
- }
-
- @Override
- public ReadWriteTransaction newReadWriteTransaction() {
- return null;
- }
-
- @Override
- public WriteTransaction newWriteOnlyTransaction() {
- return null;
- }
-
- @Override
- public ListenerRegistration<DataChangeListener> registerDataChangeListener(LogicalDatastoreType logicalDatastoreType, InstanceIdentifier<?> instanceIdentifier, DataChangeListener dataChangeListener, DataChangeScope dataChangeScope) {
- return null;
- }
-
- @Override
- public BindingTransactionChain createTransactionChain(TransactionChainListener transactionChainListener) {
- return null;
- }
+ networkmapSpy.setDataBroker(mock(DataBroker.class));
- @Nonnull
- @Override
- public <T extends DataObject, L extends DataTreeChangeListener<T>> ListenerRegistration<L> registerDataTreeChangeListener(@Nonnull DataTreeIdentifier<T> dataTreeIdentifier, @Nonnull L l) {
- return null;
- }
- });
- networkmapSpy.setMapService(new AltoModelNetworkmapService() {
- @Override
- public Future<RpcResult<QueryOutput>> query(QueryInput queryInput) {
- return null;
- }
- });
+ networkmapSpy.setMapService(queryInput -> null);
QueryInput input = networkmapSpy.prepareInput(path, pids, addressTypes);
NetworkmapRequest request = (NetworkmapRequest)input.getRequest();
partitionBuilder.setPid(new PidName(pid));
if (types.contains(AddressTypeIpv4.class)) {
- LinkedList<Ipv4Prefix> ipv4List = new LinkedList<Ipv4Prefix>();
+ LinkedList<Ipv4Prefix> ipv4List = new LinkedList<>();
ipv4List.add(new Ipv4Prefix("192.168." + index + ".0/24"));
Ipv4PrefixListBuilder v4Builder = new Ipv4PrefixListBuilder();
partitionBuilder.addAugmentation(Ipv4PrefixList.class, v4Builder.build());
}
if (types.contains(AddressTypeIpv6.class)) {
- LinkedList<Ipv6Prefix> ipv6List = new LinkedList<Ipv6Prefix>();
+ LinkedList<Ipv6Prefix> ipv6List = new LinkedList<>();
ipv6List.add(new Ipv6Prefix("2001:b8:ca2:" + index + "::0/64"));
Ipv6PrefixListBuilder v6Builder = new Ipv6PrefixListBuilder();
when(future.get()).thenReturn(rpcResult);
when(networkmapService.query((QueryInput)anyObject())).thenReturn(future);
networkmapSpy.setMapService(networkmapService);
- networkmapSpy.setDataBroker(new DataBroker() {
- @Override
- public ReadOnlyTransaction newReadOnlyTransaction() {
- return null;
- }
-
- @Override
- public ReadWriteTransaction newReadWriteTransaction() {
- return null;
- }
-
- @Override
- public WriteTransaction newWriteOnlyTransaction() {
- return null;
- }
-
- @Override
- public ListenerRegistration<DataChangeListener> registerDataChangeListener(LogicalDatastoreType logicalDatastoreType, InstanceIdentifier<?> instanceIdentifier, DataChangeListener dataChangeListener, DataChangeScope dataChangeScope) {
- return null;
- }
-
- @Override
- public BindingTransactionChain createTransactionChain(TransactionChainListener transactionChainListener) {
- return null;
- }
-
- @Nonnull
- @Override
- public <T extends DataObject, L extends DataTreeChangeListener<T>> ListenerRegistration<L> registerDataTreeChangeListener(@Nonnull DataTreeIdentifier<T> dataTreeIdentifier, @Nonnull L l) {
- return null;
- }
- });
+ networkmapSpy.setDataBroker(mock(DataBroker.class));
doReturn(new RFC7285NetworkMap.Meta()).when(networkmapSpy).buildMeta((InstanceIdentifier<?>)anyObject());
//start test
package org.opendaylight.alto.multicost.impl;
import java.util.Collection;
-
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.multicost.rev170302.MulticostData;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.multicost.rev170302.MulticostDataBuilder;
private final DataBroker db;
- private MulticostService service;
+ private final MulticostService service;
public MulticostRequestListener(final DataBroker db, final MulticostService service) {
this.db = db;
*/
package org.opendaylight.alto.spce.network.impl;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
import org.opendaylight.alto.spce.network.api.AddressConvertService;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.address.tracker.rev140617.address.node.connector.Addresses;
import org.opendaylight.yang.gen.v1.urn.opendaylight.host.tracker.rev140624.HostNode;
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.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-public class AddressConvertServiceImpl implements AddressConvertService, DataChangeListener, AutoCloseable {
-
+public class AddressConvertServiceImpl implements AddressConvertService, AutoCloseable {
private static final Logger logger = LoggerFactory
.getLogger(AddressConvertServiceImpl.class);
private static final int CPUS = Runtime.getRuntime().availableProcessors();
- private ExecutorService exec = Executors.newFixedThreadPool(CPUS);
+ private final ExecutorService exec = Executors.newFixedThreadPool(CPUS);
private DataBroker dataBroker = null;
- private Map<String, String> macToIp;
- private Map<String, String> ipToMac;
+ private final Map<String, String> macToIp = new ConcurrentHashMap<>();
+ private final Map<String, String> ipToMac = new ConcurrentHashMap<>();
- private ListenerRegistration<DataChangeListener> hostListener = null;
+ private ListenerRegistration<?> hostListener = null;
+ private ListenerRegistration<?> addressesListener = null;
public AddressConvertServiceImpl(DataBroker dataBroker) {
- this.logger.info("AddressConvertServiceImpl initial.");
+ logger.info("AddressConvertServiceImpl initial.");
this.dataBroker = dataBroker;
- macToIp = new HashMap<>();
- ipToMac = new HashMap<>();
- registerPortListener();
+ registerListeners();
}
- private void registerPortListener() {
+ private void registerListeners() {
InstanceIdentifier<HostNode> hostNodes = InstanceIdentifier
.builder(NetworkTopology.class)
.child(Topology.class)
.child(Node.class).augmentation(HostNode.class).build();
this.hostListener = this.dataBroker
- .registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
- hostNodes, this, AsyncDataBroker.DataChangeScope.SUBTREE);
+ .registerDataTreeChangeListener(new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL,
+ hostNodes), changes -> onHostChanged(changes));
+
+ InstanceIdentifier<Addresses> addresses = InstanceIdentifier
+ .builder(NetworkTopology.class)
+ .child(Topology.class)
+ .child(Node.class).augmentation(HostNode.class).child(Addresses.class).build();
+ this.addressesListener = this.dataBroker
+ .registerDataTreeChangeListener(new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL,
+ addresses), changes -> onAddressesChanged(changes));
}
@Override
}
@Override
- public void close() throws Exception {
+ public void close() {
this.hostListener.close();
+ this.addressesListener.close();
}
- @Override
- public void onDataChanged(
- final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
- exec.submit(new Runnable() {
- @Override
- public void run() {
- if (change == null) {
- logger.info("In onDataChanged: No processing done as change even is null.");
- return;
- }
- Map<InstanceIdentifier<?>, DataObject> updatedData = change
- .getUpdatedData();
- Map<InstanceIdentifier<?>, DataObject> createdData = change
- .getCreatedData();
- Map<InstanceIdentifier<?>, DataObject> originalData = change
- .getOriginalData();
- Set<InstanceIdentifier<?>> deletedData = change
- .getRemovedPaths();
-
- for (InstanceIdentifier<?> iid : deletedData) {
- logger.info("deletedData");
- if (iid.getTargetType().equals(Node.class)) {
- Node node = ((Node) originalData.get(iid));
- HostNode hostNode = node
- .getAugmentation(HostNode.class);
- if (hostNode != null) {
- List<Addresses> addrList = hostNode.getAddresses();
- for (Addresses eachAddress : addrList) {
- macToIp.remove(eachAddress.getMac().getValue());
- ipToMac.remove(eachAddress.getIp().getIpv4Address().getValue());
- }
+ private void onAddressesChanged(Collection<DataTreeModification<Addresses>> changes) {
+ exec.submit(() -> {
+ for (DataTreeModification<Addresses> change: changes) {
+ final DataObjectModification<Addresses> rootNode = change.getRootNode();
+ switch (rootNode.getModificationType()) {
+ case WRITE:
+ case SUBTREE_MODIFIED:
+ Addresses origAddresses = rootNode.getDataBefore();
+ Addresses newAddresses = rootNode.getDataAfter();
+ if (origAddresses == null) {
+ logger.info("createdData addresses:" + newAddresses);
+ macToIp.put(newAddresses.getMac().getValue(),
+ newAddresses.getIp().getIpv4Address().getValue());
+ ipToMac.put(newAddresses.getIp().getIpv4Address().getValue(),
+ newAddresses.getMac().getValue());
+ } else {
+ logger.info("updatedData addresses:" + newAddresses + "~~" + origAddresses);
+ macToIp.remove(origAddresses.getMac().getValue());
+ macToIp.put(newAddresses.getMac().getValue(),
+ newAddresses.getIp().getIpv4Address().getValue());
+ ipToMac.remove(origAddresses.getIp().getIpv4Address().getValue());
+ ipToMac.put(newAddresses.getIp().getIpv4Address().getValue(),
+ newAddresses.getMac().getValue());
}
- }
- }
-
- for (Map.Entry<InstanceIdentifier<?>, DataObject> entrySet : updatedData
- .entrySet()) {
- InstanceIdentifier<?> iiD = entrySet.getKey();
- final DataObject dataObject = entrySet.getValue();
- if (dataObject instanceof Addresses) {
- Addresses addrs = (Addresses) dataObject;
- Addresses origAddr = (Addresses) originalData.get(iiD);
- logger.info("updatedData addresses:" + addrs + "~~" + origAddr);
- macToIp.remove(origAddr.getMac().getValue());
- macToIp.put(addrs.getMac().getValue(), addrs.getIp().getIpv4Address().getValue());
- ipToMac.remove(origAddr.getIp().getIpv4Address().getValue());
- ipToMac.put(addrs.getIp().getIpv4Address().getValue(), addrs.getMac().getValue());
- }
+ break;
+ default:
+ break;
}
+ }
+ });
+ }
- for (Map.Entry<InstanceIdentifier<?>, DataObject> entrySet : createdData
- .entrySet()) {
- InstanceIdentifier<?> iiD = entrySet.getKey();
- final DataObject dataObject = entrySet.getValue();
- if (dataObject instanceof Addresses) {
- Addresses addrs = (Addresses) dataObject;
- logger.info("createdData addresses:" + addrs);
- macToIp.put(addrs.getMac().getValue(), addrs.getIp().getIpv4Address().getValue());
- ipToMac.put(addrs.getIp().getIpv4Address().getValue(), addrs.getMac().getValue());
- }
+ private void onHostChanged(Collection<DataTreeModification<HostNode>> changes) {
+ exec.submit(() -> {
+ for (DataTreeModification<HostNode> change: changes) {
+ final DataObjectModification<HostNode> rootNode = change.getRootNode();
+ switch (rootNode.getModificationType()) {
+ case DELETE:
+ logger.info("deletedData");
+ HostNode deletedHostNode = rootNode.getDataBefore();
+ List<Addresses> addrList = deletedHostNode.getAddresses();
+ for (Addresses eachAddress : addrList) {
+ macToIp.remove(eachAddress.getMac().getValue());
+ ipToMac.remove(eachAddress.getIp().getIpv4Address().getValue());
+ }
+ break;
+ default:
+ break;
}
}
});
*/
package org.opendaylight.alto.spce.network.impl;
+import java.util.Collection;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
import org.opendaylight.alto.spce.network.api.NetworkPortStatisticsService;
import org.opendaylight.alto.spce.network.util.DataHelper;
import org.opendaylight.alto.spce.network.util.InstanceIdentifierUtils;
import org.opendaylight.alto.spce.network.util.NetworkServiceConstants;
import org.opendaylight.alto.spce.network.util.ReadDataFailedException;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter;
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.node.connector.statistics.Bytes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatisticsData;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-public class NetworkPortStatisticsServiceImpl implements NetworkPortStatisticsService, DataChangeListener, AutoCloseable{
+public class NetworkPortStatisticsServiceImpl implements NetworkPortStatisticsService,
+ DataTreeChangeListener<FlowCapableNodeConnectorStatisticsData>, AutoCloseable{
private static final Logger logger = LoggerFactory
.getLogger(NetworkPortStatisticsServiceImpl.class);
private static final int CPUS = Runtime.getRuntime().availableProcessors();
- private ExecutorService exec = Executors.newFixedThreadPool(CPUS);
+ private final ExecutorService exec = Executors.newFixedThreadPool(CPUS);
private DataBroker dataBroker = null;
private class nodeStatistic {
}
}
- private Map<String, nodeStatistic> nodeStatisticData = null;
- private ListenerRegistration<DataChangeListener> portListener = null;
+ private final Map<String, nodeStatistic> nodeStatisticData = new ConcurrentHashMap<>();
+ private ListenerRegistration<?> portListener = null;
public NetworkPortStatisticsServiceImpl(DataBroker dataBroker) {
- this.logger.info("NetworkPortStatisticsServiceImpl initial.");
+ logger.info("NetworkPortStatisticsServiceImpl initial.");
this.dataBroker = dataBroker;
- nodeStatisticData = new HashMap<>();
registerPortListener();
}
private void registerPortListener() {
- this.portListener = this.dataBroker.registerDataChangeListener(
- LogicalDatastoreType.OPERATIONAL, InstanceIdentifierUtils.STATISTICS,
- this, AsyncDataBroker.DataChangeScope.SUBTREE
- );
+ this.portListener = this.dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(
+ LogicalDatastoreType.OPERATIONAL, InstanceIdentifierUtils.STATISTICS), this);
}
@Override
FlowCapableNodeConnector nodeConnector = getFlowCapableNodeConnector(tpId);
Long capacity = getCapacity(nodeConnector, readMeter(tpId, meterId));
Long consumedBandwidth = getConsumedBandwidth(tpId, isHalfDuplex(nodeConnector));
- if (capacity == null || consumedBandwidth == null) return Long.valueOf(0);
+ if (capacity == null || consumedBandwidth == null) {
+ return Long.valueOf(0);
+ }
return capacity - consumedBandwidth;
}
}
private Long getCapacity(FlowCapableNodeConnector nodeConnector, Meter meter) {
- if (nodeConnector == null) return null;
+ if (nodeConnector == null) {
+ return null;
+ }
Long currentSpeed = nodeConnector.getCurrentSpeed();
- if (meter == null) return currentSpeed;
+ if (meter == null) {
+ return currentSpeed;
+ }
long bandRate = -1;
for (MeterBandHeader band : meter.getMeterBandHeaders().getMeterBandHeader()) {
if (bandRate > band.getBandRate() && bandRate < currentSpeed) {
bandRate = band.getBandRate();
}
}
- return (bandRate == -1) ? currentSpeed : bandRate;
+ return bandRate == -1 ? currentSpeed : bandRate;
}
private Meter readMeter(String tpId, Long meterId) {
}
private boolean isHalfDuplex(FlowCapableNodeConnector nodeConnector) {
- if (nodeConnector == null) return false;
+ if (nodeConnector == null) {
+ return false;
+ }
boolean[] portFeatures = nodeConnector.getCurrentFeature().getValue();
return portFeatures[NetworkServiceConstants.PORT_FEATURES.get(NetworkServiceConstants.TEN_MB_HD)]
|| portFeatures[NetworkServiceConstants.PORT_FEATURES.get(NetworkServiceConstants.HUNDRED_MD_HD)]
}
@Override
- public void onDataChanged(
- final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
- exec.submit(new Runnable() {
- @Override
- public void run() {
- onDataUpdated(change);
- onDataDeleted(change);
- }
-
- private void onDataUpdated(final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
- Map<InstanceIdentifier<?>, DataObject> updated = change.getUpdatedData();
-
- for (Map.Entry<InstanceIdentifier<?>, DataObject> eachEntry : updated.entrySet()) {
- final DataObject dataObject = eachEntry.getValue();
- if (dataObject instanceof FlowCapableNodeConnectorStatisticsData) {
- final FlowCapableNodeConnectorStatisticsData statistic =
- (FlowCapableNodeConnectorStatisticsData) dataObject;
- Bytes bytes = statistic.getFlowCapableNodeConnectorStatistics().getBytes();
- if (bytes != null) {
- String id = eachEntry.getKey()
- .firstKeyOf(NodeConnector.class, NodeConnectorKey.class)
- .getId().getValue();
- nodeStatistic ns = null;
- if (nodeStatisticData.containsKey(id)) {
- ns = nodeStatisticData.get(id);
- } else {
- ns = new nodeStatistic();
- nodeStatisticData.put(id, ns);
- }
- ns.rxSpeed = (bytes.getReceived().longValue() - ns.rxHistory) /
- (statistic.getFlowCapableNodeConnectorStatistics()
- .getDuration().getSecond().getValue() - ns.timestamp);
- ns.txSpeed = (bytes.getTransmitted().longValue() - ns.txHistory) /
- (statistic.getFlowCapableNodeConnectorStatistics()
- .getDuration().getSecond().getValue() - ns.timestamp);
- ns.rxHistory = bytes.getReceived().longValue();
- ns.txHistory = bytes.getTransmitted().longValue();
- ns.timestamp =
- statistic.getFlowCapableNodeConnectorStatistics()
- .getDuration().getSecond().getValue();
- }
- }
+ public void onDataTreeChanged(Collection<DataTreeModification<FlowCapableNodeConnectorStatisticsData>> changes) {
+ exec.submit(() -> {
+ for (DataTreeModification<FlowCapableNodeConnectorStatisticsData> change: changes) {
+ final DataObjectModification<FlowCapableNodeConnectorStatisticsData> rootNode = change.getRootNode();
+ final InstanceIdentifier<FlowCapableNodeConnectorStatisticsData> identifier =
+ change.getRootPath().getRootIdentifier();
+ switch (rootNode.getModificationType()) {
+ case WRITE:
+ case SUBTREE_MODIFIED:
+ onFlowCapableNodeConnectorStatisticsDataUpdated(identifier, rootNode.getDataAfter());
+ break;
+ case DELETE:
+ onFlowCapableNodeConnectorStatisticsDataDeleted(identifier);
+ break;
+ default:
+ break;
}
}
+ });
+ }
- private void onDataDeleted(final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
- Set<InstanceIdentifier<?>> removed = change.getRemovedPaths();
- for (InstanceIdentifier<?> eachPath : removed) {
- if (eachPath.getTargetType() == FlowCapableNodeConnectorStatisticsData.class) {
- String name =
- eachPath.firstKeyOf(NodeConnector.class, NodeConnectorKey.class).getId().getValue();
- nodeStatisticData.remove(name);
- }
- }
+ private void onFlowCapableNodeConnectorStatisticsDataDeleted(
+ InstanceIdentifier<FlowCapableNodeConnectorStatisticsData> identifier) {
+ String name = identifier.firstKeyOf(NodeConnector.class, NodeConnectorKey.class).getId().getValue();
+ nodeStatisticData.remove(name);
+ }
+
+ private void onFlowCapableNodeConnectorStatisticsDataUpdated(
+ InstanceIdentifier<FlowCapableNodeConnectorStatisticsData> identifier,
+ FlowCapableNodeConnectorStatisticsData statistic) {
+ Bytes bytes = statistic.getFlowCapableNodeConnectorStatistics().getBytes();
+ if (bytes != null) {
+ String id = identifier
+ .firstKeyOf(NodeConnector.class, NodeConnectorKey.class)
+ .getId().getValue();
+ final nodeStatistic ns;
+ if (nodeStatisticData.containsKey(id)) {
+ ns = nodeStatisticData.get(id);
+ } else {
+ ns = new nodeStatistic();
+ nodeStatisticData.put(id, ns);
}
- });
+ ns.rxSpeed = (bytes.getReceived().longValue() - ns.rxHistory) /
+ (statistic.getFlowCapableNodeConnectorStatistics()
+ .getDuration().getSecond().getValue() - ns.timestamp);
+ ns.txSpeed = (bytes.getTransmitted().longValue() - ns.txHistory) /
+ (statistic.getFlowCapableNodeConnectorStatistics()
+ .getDuration().getSecond().getValue() - ns.timestamp);
+ ns.rxHistory = bytes.getReceived().longValue();
+ ns.txHistory = bytes.getTransmitted().longValue();
+ ns.timestamp =
+ statistic.getFlowCapableNodeConnectorStatistics()
+ .getDuration().getSecond().getValue();
+ }
}
@Override
@Override
public Long getCurrentTxSpeed(String tpId, Metric metric) {
if (nodeStatisticData.containsKey(tpId)) {
- if (metric == Metric.BITSPERSECOND)
+ if (metric == Metric.BITSPERSECOND) {
return nodeStatisticData.get(tpId).txSpeed * 8;
- else if (metric == Metric.BYTESPERSECOND)
+ } else if (metric == Metric.BYTESPERSECOND) {
return nodeStatisticData.get(tpId).txSpeed;
+ }
}
return null;
}
@Override
public Long getCurrentRxSpeed(String tpId, Metric metric) {
if (nodeStatisticData.containsKey(tpId)) {
- if (metric == Metric.BITSPERSECOND)
+ if (metric == Metric.BITSPERSECOND) {
return nodeStatisticData.get(tpId).rxSpeed * 8;
- else if (metric == Metric.BYTESPERSECOND)
+ } else if (metric == Metric.BYTESPERSECOND) {
return nodeStatisticData.get(tpId).rxSpeed;
+ }
}
return null;
}