Search in sources :

Example 6 with Top

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top in project controller by opendaylight.

the class WriteTransactionTest method testMergeCreateParentsSuccess.

@Test
public void testMergeCreateParentsSuccess() throws TransactionCommitFailedException, InterruptedException, ExecutionException {
    WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
    writeTx.merge(LogicalDatastoreType.OPERATIONAL, NODE_PATH, NODE, true);
    writeTx.submit().checkedGet();
    ReadOnlyTransaction readTx = getDataBroker().newReadOnlyTransaction();
    Optional<Top> topNode = readTx.read(LogicalDatastoreType.OPERATIONAL, TOP_PATH).get();
    assertTrue("Top node must exists after commit", topNode.isPresent());
    Optional<TopLevelList> listNode = readTx.read(LogicalDatastoreType.OPERATIONAL, NODE_PATH).get();
    assertTrue("List node must exists after commit", listNode.isPresent());
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) Top(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top) TopLevelList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) AbstractConcurrentDataBrokerTest(org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest) Test(org.junit.Test)

Example 7 with Top

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top in project controller by opendaylight.

the class BrokerIntegrationTest method simpleModifyOperation.

@Test
public void simpleModifyOperation() throws Exception {
    DataBroker dataBroker = testContext.getDataBroker();
    Optional<TopLevelList> tllFoo = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.CONFIGURATION, FOO_PATH).checkedGet(5, TimeUnit.SECONDS);
    assertFalse(tllFoo.isPresent());
    TopLevelList tllFooData = createTll(TLL_FOO_KEY);
    final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
    transaction.put(LogicalDatastoreType.CONFIGURATION, FOO_PATH, tllFooData);
    transaction.submit().get(5, TimeUnit.SECONDS);
    Optional<TopLevelList> readedData = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.CONFIGURATION, FOO_PATH).checkedGet(5, TimeUnit.SECONDS);
    assertTrue(readedData.isPresent());
    assertEquals(tllFooData.getKey(), readedData.get().getKey());
    TopLevelList nodeBarData = createTll(TLL_BAR_KEY);
    TopLevelList nodeBazData = createTll(TLL_BAZ_KEY);
    final WriteTransaction insertMoreTr = dataBroker.newWriteOnlyTransaction();
    insertMoreTr.put(LogicalDatastoreType.CONFIGURATION, BAR_PATH, nodeBarData);
    insertMoreTr.put(LogicalDatastoreType.CONFIGURATION, BAZ_PATH, nodeBazData);
    insertMoreTr.submit().get(5, TimeUnit.SECONDS);
    Optional<Top> top = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.CONFIGURATION, TOP_PATH).checkedGet(5, TimeUnit.SECONDS);
    assertTrue(top.isPresent());
    assertEquals(3, top.get().getTopLevelList().size());
    // We create transaction no 2
    final WriteTransaction removalTransaction = dataBroker.newWriteOnlyTransaction();
    // We remove node 1
    removalTransaction.delete(LogicalDatastoreType.CONFIGURATION, BAR_PATH);
    // We commit transaction
    removalTransaction.submit().get(5, TimeUnit.SECONDS);
    Optional<TopLevelList> readedData2 = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.CONFIGURATION, BAR_PATH).checkedGet(5, TimeUnit.SECONDS);
    assertFalse(readedData2.isPresent());
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) Top(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top) TopLevelList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) AbstractDataServiceTest(org.opendaylight.controller.sal.binding.test.AbstractDataServiceTest) Test(org.junit.Test)

Example 8 with Top

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top in project bgpcep by opendaylight.

the class Samcra method computeP2pPath.

/* Samcra Algo:
     *
     * To limit the modification outside the Samcra method the same set of parameters as
     * the CSPF method is used (related to pseudo code, the path length is computed inside
     * the method based on the individual constraint parameters).
     *
     * On contrast to a simple CSPF algo, with Samcra a connected vertex might be associated to several
     * metric vectors from which different path lengths are computed. However a connected vertex is only
     * present once in the priority queue, associated to the minimal path weight, which is used as key
     * to address the priority queue.
     *
     * For a given metric the path weight is an integer value computed as the entire part of
     * the quantity:
     *      100 * (vector_path_metric/target_metric)
     * The path weight correspond to the maximum length computed from either the delay or TE metric.
     *
     * To maintain the priority queue behavior unchanged, a "SamcraPath" classes is created to manage
     * the set of possible paths associated to a given vertex (see above).
     *
     */
@Override
public ConstrainedPath computeP2pPath(final VertexKey src, final VertexKey dst, final PathConstraints cts) {
    ConstrainedPathBuilder cpathBuilder;
    List<ConnectedEdge> edges;
    CspfPath currentPath;
    LOG.info("Start SAMCRA Path Computation from {} to {} with constraints {}", src, dst, cts);
    /* Initialize SAMCRA variables */
    this.constraints = cts;
    cpathBuilder = initializePathComputation(src, dst);
    if (cpathBuilder.getStatus() == ComputationStatus.Failed) {
        return cpathBuilder.build();
    }
    cpathBuilder.setBandwidth(cts.getBandwidth()).setClassType(cts.getClassType());
    samcraPaths.clear();
    samcraPaths.put(pathSource.getVertexKey(), new SamcraPath(pathSource.getVertex()));
    samcraPaths.put(pathDestination.getVertexKey(), new SamcraPath(pathDestination.getVertex()));
    /* Exploration of the priority queue:
         * Each connected vertex is represented only once in the priority queue associated to the path
         * with the minimal length (other path are stored in the SamcraPath object).
         * The top of the queue, i.e. the element with the minimal key( path weight), is processed at each loop
         */
    while (priorityQueue.size() != 0) {
        currentPath = priorityQueue.poll();
        LOG.debug(" - Process path up to Vertex {} from Priority Queue", currentPath.getVertex());
        /* Prepare Samcra Path from current CSP Path except for the source */
        if (!currentPath.equals(pathSource)) {
            SamcraPath currentSamcraPath = samcraPaths.get(currentPath.getVertexKey());
            CspfPath currentCspfPath = currentSamcraPath.getCurrentPath();
            float queuePathLength = currentCspfPath.getPathLength();
            LOG.trace(" - Priority Queue output SamcraPaths {} CurrentPath {} with PathLength {}", currentSamcraPath.currentPath, currentCspfPath, queuePathLength);
        }
        edges = currentPath.getVertex().getOutputConnectedEdges();
        float currentPathLength = 1.0F;
        for (ConnectedEdge edge : edges) {
            /* Connected Vertex's edges processing:
                 * Prune the connected edges that do not satisfy the constraints (Bandwidth, TE Metric, Delay, Loss)
                 * For each remaining edge process the path to the remote vertex using the "relaxSamcra" procedure
                 *
                 * If the return path length is positive, the destination is reached and the
                 * obtained route satisfies the requested constraints.
                 * The path length is checked to record only the optimal route (i.e. the route with
                 * the minimal path length) info obtained from the destination vertex
                 */
            if (pruneEdge(edge, currentPath)) {
                LOG.trace(" - Prune Edge {}", edge);
                continue;
            }
            float pathLength = relaxSamcra(edge, currentPath, pathSource);
            /* Check if we found a valid and better path */
            if (pathLength > 0F && pathLength <= currentPathLength) {
                final SamcraPath finalPath = samcraPaths.get(pathDestination.getVertexKey());
                cpathBuilder.setPathDescription(getPathDescription(finalPath.getCurrentPath().getPath())).setMetric(Uint32.valueOf(finalPath.getCurrentPath().getCost())).setDelay(new Delay(Uint32.valueOf(finalPath.getCurrentPath().getDelay()))).setStatus(ComputationStatus.Active);
                LOG.debug(" - Path to destination found and registered {}", cpathBuilder.getPathDescription());
                currentPathLength = pathLength;
            }
        }
        /* The connected vertex that has been removed from the priority queue may have to be re-inserted with
             * the minimal length non-dominated path associated to the connected vertex if it exists (to be done
             * except for the source). Otherwise, the current path associated to the connected vertex is reset to
             * null to allow the connected vertex addition to the priority queue later on with a new path
             * (refer to "relaxSamcra" for addition of a connected vertex to the priority queue).
             */
        float previousLength = 1.0F;
        CspfPath selectedPath = null;
        if (!currentPath.equals(pathSource)) {
            LOG.debug(" - Processing current path {} up to {} from Priority Queue", currentPath, currentPath.getVertex());
            SamcraPath currentSamcraPath = samcraPaths.get(currentPath.getVertexKey());
            currentSamcraPath.decrementPathCount();
            /*
                 * The list of paths associated to the connected vertex is retrieved
                 * The path used to represent the connected vertex in the Priority Queue is marked from "selected"
                 * to "processed". The list of paths is analyzed to check if other "active" path(s) exist(s).
                 * If it is the case the shortest length is used to re-inject the connected vertex in the Priority Queue
                 */
            for (CspfPath testedPath : currentSamcraPath.getPathList()) {
                LOG.debug(" - Testing path {} with status {} ", testedPath, testedPath.getPathStatus());
                if (testedPath.getPathStatus() == CspfPath.SELECTED) {
                    testedPath.setPathStatus(CspfPath.PROCESSED);
                } else if (testedPath.getPathStatus() == CspfPath.ACTIVE && testedPath.getPathLength() < previousLength) {
                    selectedPath = testedPath;
                    previousLength = testedPath.getPathLength();
                }
            }
            /* If a path is found it is marked as "selected", used as "current path" for the connected vertex
                 * and added to the priority queue
                 */
            if (selectedPath != null) {
                selectedPath.setPathStatus(CspfPath.SELECTED);
                currentSamcraPath.setCurrentPath(selectedPath);
                priorityQueue.add(selectedPath);
                LOG.debug(" - Add path {} to Priority Queue. New path count {} ", selectedPath, currentSamcraPath.getPathCount());
            } else {
                currentSamcraPath.setCurrentPath(null);
            }
        }
    }
    /* The priority queue is empty => all the possible (vertex, path) elements have been explored
         * The "ConstrainedPathBuilder" object contains the optimal path if it exists
         * Otherwise an empty path with status failed is returned
         */
    if (cpathBuilder.getStatus() == ComputationStatus.InProgress || cpathBuilder.getPathDescription().size() == 0) {
        cpathBuilder.setStatus(ComputationStatus.Failed);
    } else {
        cpathBuilder.setStatus(ComputationStatus.Completed);
    }
    return cpathBuilder.build();
}
Also used : ConstrainedPathBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev200120.ConstrainedPathBuilder) ConnectedEdge(org.opendaylight.graph.ConnectedEdge) Delay(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.Delay)

Example 9 with Top

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top in project bgpcep by opendaylight.

the class ConnectedGraphServer method initOperationalGraphModel.

/**
 * Initialize GraphModel tree at Data Store top-level.
 */
private synchronized void initOperationalGraphModel() {
    requireNonNull(this.chain, "A valid transaction chain must be provided.");
    final WriteTransaction trans = this.chain.newWriteOnlyTransaction();
    LOG.info("Create Graph Model at top level in Operational DataStore: {}", GRAPH_TOPOLOGY_IDENTIFIER);
    trans.put(LogicalDatastoreType.OPERATIONAL, GRAPH_TOPOLOGY_IDENTIFIER, new GraphTopologyBuilder().build());
    trans.commit().addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.trace("Transaction {} committed successfully", trans.getIdentifier());
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error("Failed to initialize GraphModel {} (transaction {}) by listener {}", GRAPH_TOPOLOGY_IDENTIFIER, trans.getIdentifier(), ConnectedGraphServer.this, throwable);
        }
    }, MoreExecutors.directExecutor());
}
Also used : ReadWriteTransaction(org.opendaylight.mdsal.binding.api.ReadWriteTransaction) WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) GraphTopologyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.GraphTopologyBuilder) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo)

Example 10 with Top

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top in project mdsal by opendaylight.

the class WriteTransactionTest method testMergeCreateParentsSuccess.

@Test
public void testMergeCreateParentsSuccess() throws InterruptedException, ExecutionException {
    final WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
    writeTx.mergeParentStructureMerge(LogicalDatastoreType.OPERATIONAL, NODE_PATH, NODE);
    writeTx.commit().get();
    final ReadTransaction readTx = getDataBroker().newReadOnlyTransaction();
    final Optional<Top> topNode = readTx.read(LogicalDatastoreType.OPERATIONAL, TOP_PATH).get();
    assertTrue("Top node must exists after commit", topNode.isPresent());
    final Optional<TopLevelList> listNode = readTx.read(LogicalDatastoreType.OPERATIONAL, NODE_PATH).get();
    assertTrue("List node must exists after commit", listNode.isPresent());
}
Also used : WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) Top(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top) ReadTransaction(org.opendaylight.mdsal.binding.api.ReadTransaction) TopLevelList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelList) Test(org.junit.Test) AbstractDataBrokerTest(org.opendaylight.mdsal.binding.dom.adapter.test.AbstractDataBrokerTest)

Aggregations

Test (org.junit.Test)41 Top (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top)27 AbstractDataTreeChangeListenerTest (org.opendaylight.mdsal.binding.dom.adapter.test.AbstractDataTreeChangeListenerTest)11 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)11 DataObject (org.opendaylight.yangtools.yang.binding.DataObject)10 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)9 WriteTransaction (org.opendaylight.mdsal.binding.api.WriteTransaction)9 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)9 TopLevelList (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelList)8 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)8 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)8 ReadWriteTransaction (org.opendaylight.mdsal.binding.api.ReadWriteTransaction)7 TopBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.TopBuilder)7 Top (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top)6 TopLevelListKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelListKey)6 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)6 AbstractDataChangeListenerTest (org.opendaylight.controller.md.sal.binding.test.AbstractDataChangeListenerTest)5 TopLevelListKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey)5 TopLevelList (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList)4 AbstractConcurrentDataBrokerTest (org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest)3