Search in sources :

Example 31 with TableKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey in project netvirt by opendaylight.

the class BaseVrfEntryHandler method makeConnectedRoute.

protected void makeConnectedRoute(BigInteger dpId, long vpnId, VrfEntry vrfEntry, String rd, List<InstructionInfo> instructions, int addOrRemove, WriteTransaction tx, List<SubTransaction> subTxns) {
    Boolean wrTxPresent = true;
    if (tx == null) {
        wrTxPresent = false;
        tx = dataBroker.newWriteOnlyTransaction();
    }
    LOG.trace("makeConnectedRoute: vrfEntry {}", vrfEntry);
    String[] values = vrfEntry.getDestPrefix().split("/");
    String ipAddress = values[0];
    int prefixLength = values.length == 1 ? 0 : Integer.parseInt(values[1]);
    if (addOrRemove == NwConstants.ADD_FLOW) {
        LOG.debug("Adding route to DPN {} for rd {} prefix {} ", dpId, rd, vrfEntry.getDestPrefix());
    } else {
        LOG.debug("Removing route from DPN {} for rd {} prefix {}", dpId, rd, vrfEntry.getDestPrefix());
    }
    InetAddress destPrefix;
    try {
        destPrefix = InetAddress.getByName(ipAddress);
    } catch (UnknownHostException e) {
        LOG.error("Failed to get destPrefix for prefix {} rd {} VpnId {} DPN {}", vrfEntry.getDestPrefix(), rd, vpnId, dpId, e);
        return;
    }
    List<MatchInfo> matches = new ArrayList<>();
    matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
    if (destPrefix instanceof Inet4Address) {
        matches.add(MatchEthernetType.IPV4);
        if (prefixLength != 0) {
            matches.add(new MatchIpv4Destination(destPrefix.getHostAddress(), Integer.toString(prefixLength)));
        }
    } else {
        matches.add(MatchEthernetType.IPV6);
        if (prefixLength != 0) {
            matches.add(new MatchIpv6Destination(destPrefix.getHostAddress() + "/" + prefixLength));
        }
    }
    int priority = DEFAULT_FIB_FLOW_PRIORITY + prefixLength;
    String flowRef = FibUtil.getFlowRef(dpId, NwConstants.L3_FIB_TABLE, rd, priority, destPrefix);
    FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.L3_FIB_TABLE, flowRef, priority, flowRef, 0, 0, COOKIE_VM_FIB_TABLE, matches, instructions);
    Flow flow = flowEntity.getFlowBuilder().build();
    String flowId = flowEntity.getFlowId();
    FlowKey flowKey = new FlowKey(new FlowId(flowId));
    Node nodeDpn = FibUtil.buildDpnNode(dpId);
    InstanceIdentifier<Flow> flowInstanceId = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class).child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flowKey).build();
    if (RouteOrigin.value(vrfEntry.getOrigin()) == RouteOrigin.BGP) {
        SubTransaction subTransaction = new SubTransactionImpl();
        if (addOrRemove == NwConstants.ADD_FLOW) {
            subTransaction.setInstanceIdentifier(flowInstanceId);
            subTransaction.setInstance(flow);
            subTransaction.setAction(SubTransaction.CREATE);
        } else {
            subTransaction.setInstanceIdentifier(flowInstanceId);
            subTransaction.setAction(SubTransaction.DELETE);
        }
        subTxns.add(subTransaction);
    }
    if (addOrRemove == NwConstants.ADD_FLOW) {
        tx.put(LogicalDatastoreType.CONFIGURATION, flowInstanceId, flow, true);
    } else {
        tx.delete(LogicalDatastoreType.CONFIGURATION, flowInstanceId);
    }
    if (!wrTxPresent) {
        tx.submit();
    }
}
Also used : MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) Inet4Address(java.net.Inet4Address) FlowKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey) UnknownHostException(java.net.UnknownHostException) SubTransactionImpl(org.opendaylight.genius.utils.batching.SubTransactionImpl) 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) ArrayList(java.util.ArrayList) SubTransaction(org.opendaylight.genius.utils.batching.SubTransaction) MatchIpv4Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination) TableKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow) FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) MatchIpv6Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv6Destination) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) InetAddress(java.net.InetAddress)

Example 32 with TableKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey in project openflowplugin by opendaylight.

the class OpenflowpluginTestCommandProvider method writeFlow.

private void writeFlow(final CommandInterpreter ci, final FlowBuilder flow, final NodeBuilder nodeBuilder) {
    final ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
    final InstanceIdentifier<Flow> path1 = InstanceIdentifier.create(Nodes.class).child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class).child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flow.getKey());
    modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
    modification.merge(LogicalDatastoreType.CONFIGURATION, path1, flow.build(), true);
    final CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
    Futures.addCallback(commitFuture, new FutureCallback<Void>() {

        @Override
        public void onSuccess(final Void notUsed) {
            ci.println("Status of Group Data Loaded Transaction: success.");
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error(throwable.getMessage(), throwable);
            ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable));
        }
    }, MoreExecutors.directExecutor());
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) Table(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) TableKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)

Example 33 with TableKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey in project openflowplugin by opendaylight.

the class OpenflowpluginTestCommandProvider method _removeMDFlow.

public void _removeMDFlow(final CommandInterpreter ci) {
    final ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
    final NodeBuilder tn = createTestNode(ci.nextArgument());
    final String flowtype = ci.nextArgument();
    FlowBuilder tf;
    if (flowtype.equals("fTM")) {
        tf = createtablemiss();
    } else {
        tf = createTestFlow(tn, flowtype, ci.nextArgument());
    }
    final InstanceIdentifier<Flow> path1 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.getKey()).augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf.getTableId())).child(Flow.class, tf.getKey());
    modification.delete(LogicalDatastoreType.CONFIGURATION, path1);
    final CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
    Futures.addCallback(commitFuture, new FutureCallback<Void>() {

        @Override
        public void onSuccess(final Void notUsed) {
            ci.println("Status of Group Data Loaded Transaction: success.");
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error(throwable.getMessage(), throwable);
            ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable));
        }
    }, MoreExecutors.directExecutor());
}
Also used : Table(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) TableKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey) NodeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) FlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)

Example 34 with TableKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey in project openflowplugin by opendaylight.

the class FlowForwarder method update.

@Override
public Future<RpcResult<UpdateFlowOutput>> update(final InstanceIdentifier<Flow> identifier, final Flow original, final Flow update, final InstanceIdentifier<FlowCapableNode> nodeIdent) {
    LOG.trace("Forwarding Flow UPDATE request [Tbl id, node Id {} {} {}", identifier, nodeIdent, update);
    final Future<RpcResult<UpdateFlowOutput>> output;
    final TableKey tableKey = identifier.firstKeyOf(Table.class, TableKey.class);
    if (tableIdValidationPrecondition(tableKey, update)) {
        final UpdateFlowInputBuilder builder = new UpdateFlowInputBuilder();
        builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class)));
        builder.setFlowRef(new FlowRef(identifier));
        // always needs to set strict flag into update-flow input so that
        // only a flow entry associated with a given flow object is updated.
        builder.setUpdatedFlow(new UpdatedFlowBuilder(update).setStrict(Boolean.TRUE).build());
        builder.setOriginalFlow(new OriginalFlowBuilder(original).setStrict(Boolean.TRUE).build());
        output = salFlowService.updateFlow(builder.build());
    } else {
        output = RpcResultBuilder.<UpdateFlowOutput>failed().withError(RpcError.ErrorType.APPLICATION, TABLE_ID_MISMATCH).buildFuture();
    }
    return output;
}
Also used : UpdateFlowInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInputBuilder) NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) FlowRef(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) TableKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey) OriginalFlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlowBuilder) UpdatedFlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlowBuilder)

Example 35 with TableKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey in project openflowplugin by opendaylight.

the class FlowForwarder method remove.

@Override
public Future<RpcResult<RemoveFlowOutput>> remove(final InstanceIdentifier<Flow> identifier, final Flow removeDataObj, final InstanceIdentifier<FlowCapableNode> nodeIdent) {
    LOG.trace("Forwarding Flow REMOVE request Tbl id, node Id {} {}", identifier, nodeIdent);
    final TableKey tableKey = identifier.firstKeyOf(Table.class, TableKey.class);
    if (tableIdValidationPrecondition(tableKey, removeDataObj)) {
        final RemoveFlowInputBuilder builder = new RemoveFlowInputBuilder(removeDataObj);
        builder.setFlowRef(new FlowRef(identifier));
        builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class)));
        builder.setFlowTable(new FlowTableRef(nodeIdent.child(Table.class, tableKey)));
        // always needs to set strict flag into remove-flow input so that
        // only a flow entry associated with a given flow object will be removed.
        builder.setStrict(Boolean.TRUE);
        return salFlowService.removeFlow(builder.build());
    } else {
        return RpcResultBuilder.<RemoveFlowOutput>failed().withError(RpcError.ErrorType.APPLICATION, TABLE_ID_MISMATCH).buildFuture();
    }
}
Also used : NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) FlowTableRef(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowTableRef) RemoveFlowOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutput) FlowRef(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef) RemoveFlowInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInputBuilder) TableKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey)

Aggregations

TableKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey)50 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)41 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)37 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)28 Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)28 FlowKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey)27 FlowId (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId)23 Table (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table)22 Test (org.junit.Test)13 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)12 ArrayList (java.util.ArrayList)10 FlowBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder)10 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)8 ItemSyncBox (org.opendaylight.openflowplugin.applications.frsync.util.ItemSyncBox)8 FlowRef (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef)8 NodeRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef)8 NodeKey (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey)8 TableBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableBuilder)7 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)6 StaleFlow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.StaleFlow)6