Search in sources :

Example 21 with DataBroker

use of org.opendaylight.controller.md.sal.binding.api.DataBroker in project controller by opendaylight.

the class WildcardedDataChangeListenerTest method testNoChangeOnReplaceWithSameValue.

@Test
public void testNoChangeOnReplaceWithSameValue() throws InterruptedException, TimeoutException, ExecutionException {
    DataBroker dataBroker = testContext.getDataBroker();
    // We wrote initial state NODE_0_FLOW
    final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
    transaction.put(LogicalDatastoreType.OPERATIONAL, NODE_0_LVU_PATH, LVU, true);
    transaction.submit().get(5, TimeUnit.SECONDS);
    // We registered DataChangeListener
    final SettableFuture<AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject>> eventFuture = SettableFuture.create();
    dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, DEEP_WILDCARDED_PATH, dataChangeEvent -> eventFuture.set(dataChangeEvent), DataChangeScope.SUBTREE);
    assertFalse(eventFuture.isDone());
    final WriteTransaction secondTx = dataBroker.newWriteOnlyTransaction();
    secondTx.put(LogicalDatastoreType.OPERATIONAL, NODE_0_LVU_PATH, LVU, true);
    secondTx.put(LogicalDatastoreType.OPERATIONAL, NODE_1_LVU_PATH, LVU, true);
    secondTx.submit().get(5, TimeUnit.SECONDS);
    AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = eventFuture.get(1000, TimeUnit.MILLISECONDS);
    assertNotNull(event);
    // Data change should contains NODE_1 Flow - which was added
    assertTrue(event.getCreatedData().containsKey(NODE_1_LVU_PATH));
    // Data change must not containe NODE_0 Flow which was replaced with same value.
    assertFalse(event.getUpdatedData().containsKey(NODE_0_LVU_PATH));
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) AsyncDataChangeEvent(org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent) AbstractDataServiceTest(org.opendaylight.controller.sal.binding.test.AbstractDataServiceTest) Test(org.junit.Test)

Example 22 with DataBroker

use of org.opendaylight.controller.md.sal.binding.api.DataBroker in project openflowplugin by opendaylight.

the class SimplifiedOperationalListenerTest method setUp.

@Before
public void setUp() throws Exception {
    final DataBroker db = Mockito.mock(DataBroker.class);
    final FlowCapableNodeSnapshotDao configSnapshot = new FlowCapableNodeSnapshotDao();
    final FlowCapableNodeSnapshotDao operationalSnapshot = new FlowCapableNodeSnapshotDao();
    final FlowCapableNodeDao configDao = new FlowCapableNodeCachedDao(configSnapshot, new FlowCapableNodeOdlDao(db, LogicalDatastoreType.CONFIGURATION));
    nodeListenerOperational = new SimplifiedOperationalListener(reactor, operationalSnapshot, configDao, reconciliationRegistry, deviceMastershipManager);
    InstanceIdentifier<Node> nodePath = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(NODE_ID));
    fcNodePath = nodePath.augmentation(FlowCapableNode.class);
    final DataTreeIdentifier<Node> dataTreeIdentifier = new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, nodePath);
    Mockito.when(db.newReadOnlyTransaction()).thenReturn(roTx);
    Mockito.when(operationalNode.getId()).thenReturn(NODE_ID);
    Mockito.when(dataTreeModification.getRootPath()).thenReturn(dataTreeIdentifier);
    Mockito.when(dataTreeModification.getRootNode()).thenReturn(operationalModification);
    Mockito.when(operationalNode.getAugmentation(FlowCapableNode.class)).thenReturn(fcOperationalNode);
}
Also used : FlowCapableNodeSnapshotDao(org.opendaylight.openflowplugin.applications.frsync.dao.FlowCapableNodeSnapshotDao) FlowCapableNodeOdlDao(org.opendaylight.openflowplugin.applications.frsync.dao.FlowCapableNodeOdlDao) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) DataTreeIdentifier(org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier) FlowCapableNodeDao(org.opendaylight.openflowplugin.applications.frsync.dao.FlowCapableNodeDao) NodeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey) FlowCapableNodeCachedDao(org.opendaylight.openflowplugin.applications.frsync.dao.FlowCapableNodeCachedDao) Before(org.junit.Before)

Example 23 with DataBroker

use of org.opendaylight.controller.md.sal.binding.api.DataBroker in project lispflowmapping by opendaylight.

the class ListenerTest method toStringTest.

/**
 * Tests {@link NetworkListener#toString}, {@link PortListener#toString}, {@link SubnetListener#toString} method.
 */
@Test
public void toStringTest() {
    final DataProcessor<Network> networkDataProcessor = Mockito.mock(DataProcessor.class);
    final DataBroker dataBroker = Mockito.mock(DataBroker.class);
    final NetworkListener networkListener = new NetworkListener(networkDataProcessor, dataBroker);
    final DataProcessor<Port> portDataProcessor = Mockito.mock(DataProcessor.class);
    final PortListener portListener = new PortListener(portDataProcessor, dataBroker);
    final DataProcessor<Subnet> subnetDataProcessor = Mockito.mock(DataProcessor.class);
    final SubnetListener subnetListener = new SubnetListener(subnetDataProcessor, dataBroker);
    assertEquals("NetworkListener", networkListener.toString());
    assertEquals("PortListener", portListener.toString());
    assertEquals("SubnetListener", subnetListener.toString());
}
Also used : Network(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network) Port(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) Subnet(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet) Test(org.junit.Test)

Example 24 with DataBroker

use of org.opendaylight.controller.md.sal.binding.api.DataBroker in project lispflowmapping by opendaylight.

the class VppNodeReader method readFirstAvailableIpOfVppNode.

private ListenableFuture<Optional<Ipv4Address>> readFirstAvailableIpOfVppNode(final KeyedInstanceIdentifier<Node, NodeKey> instanceIdentifierToVppNode) {
    final SettableFuture<Optional<Ipv4Address>> resultFuture = SettableFuture.create();
    final DataBroker vppDataBroker = LispNeutronUtil.resolveDataBrokerForMountPoint(instanceIdentifierToVppNode, mountService);
    if (vppDataBroker != null) {
        final Optional<InterfacesState> interfacesOnVppNodeOptional = VppNetconfTrasaction.read(vppDataBroker, LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(InterfacesState.class));
        if (interfacesOnVppNodeOptional.isPresent()) {
            for (Interface intf : interfacesOnVppNodeOptional.get().getInterface()) {
                if (intf.getType().equals(Loopback.class)) {
                    continue;
                }
                final Optional<Ipv4Address> ipv4AddressOptional = readIpAddressFromInterface(intf, instanceIdentifierToVppNode);
                if (ipv4AddressOptional.isPresent()) {
                    resultFuture.set(ipv4AddressOptional);
                    break;
                }
            }
        }
        resultFuture.set(Optional.absent());
    } else {
        LOG.debug("Data broker for vpp {} is missing.", instanceIdentifierToVppNode);
    }
    return resultFuture;
}
Also used : Optional(com.google.common.base.Optional) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) InterfacesState(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState) Interface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)

Example 25 with DataBroker

use of org.opendaylight.controller.md.sal.binding.api.DataBroker in project lispflowmapping by opendaylight.

the class AuthenticationKeyDataListenerTest method init.

@Before
@SuppressWarnings("unchecked")
public void init() {
    DataBroker dataBrokerMock = Mockito.mock(DataBroker.class);
    iMappingSystemMock = Mockito.mock(IMappingSystem.class);
    authenticationKeyDataListener = new AuthenticationKeyDataListener(dataBrokerMock, iMappingSystemMock);
    final InstanceIdentifier<AuthenticationKey> instanceIdentifierMock = Mockito.mock(InstanceIdentifier.class);
    final DataTreeIdentifier<AuthenticationKey> dataTreeIdentifier = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, instanceIdentifierMock);
    change_del = Mockito.mock(DataTreeModification.class);
    change_subtreeModified = Mockito.mock(DataTreeModification.class);
    change_write = Mockito.mock(DataTreeModification.class);
    mod_del = Mockito.mock(DataObjectModification.class);
    mod_subtreeModified = Mockito.mock(DataObjectModification.class);
    mod_write = Mockito.mock(DataObjectModification.class);
    Mockito.when(change_del.getRootPath()).thenReturn(dataTreeIdentifier);
    Mockito.when(change_del.getRootNode()).thenReturn(mod_del);
    Mockito.when(change_subtreeModified.getRootPath()).thenReturn(dataTreeIdentifier);
    Mockito.when(change_subtreeModified.getRootNode()).thenReturn(mod_subtreeModified);
    Mockito.when(change_write.getRootPath()).thenReturn(dataTreeIdentifier);
    Mockito.when(change_write.getRootNode()).thenReturn(mod_write);
    Mockito.when(mod_del.getModificationType()).thenReturn(ModificationType.DELETE);
    Mockito.when(mod_subtreeModified.getModificationType()).thenReturn(ModificationType.SUBTREE_MODIFIED);
    Mockito.when(mod_write.getModificationType()).thenReturn(ModificationType.WRITE);
}
Also used : DataTreeModification(org.opendaylight.controller.md.sal.binding.api.DataTreeModification) DataTreeIdentifier(org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier) AuthenticationKey(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.AuthenticationKey) DataObjectModification(org.opendaylight.controller.md.sal.binding.api.DataObjectModification) IMappingSystem(org.opendaylight.lispflowmapping.interfaces.mapcache.IMappingSystem) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) Before(org.junit.Before)

Aggregations

DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)67 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)38 Optional (com.google.common.base.Optional)37 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)37 Logger (org.slf4j.Logger)37 LoggerFactory (org.slf4j.LoggerFactory)36 ArrayList (java.util.ArrayList)34 List (java.util.List)33 BigInteger (java.math.BigInteger)31 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)30 Collections (java.util.Collections)29 Inject (javax.inject.Inject)29 Singleton (javax.inject.Singleton)29 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)25 NwConstants (org.opendaylight.genius.mdsalutil.NwConstants)24 MDSALUtil (org.opendaylight.genius.mdsalutil.MDSALUtil)23 ManagedNewTransactionRunner (org.opendaylight.genius.infra.ManagedNewTransactionRunner)22 IMdsalApiManager (org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager)22 FutureCallback (com.google.common.util.concurrent.FutureCallback)21 PostConstruct (javax.annotation.PostConstruct)21