Search in sources :

Example 1 with SubTransactionImpl

use of org.opendaylight.genius.utils.batching.SubTransactionImpl in project genius by opendaylight.

the class InterfaceBatchHandler method buildSubTransactions.

private void buildSubTransactions(List<SubTransaction> transactionObjects, InstanceIdentifier identifier, Object data, short subTransactionType) {
    // enable retries
    SubTransaction subTransaction = new SubTransactionImpl();
    subTransaction.setInstanceIdentifier(identifier);
    subTransaction.setInstance(data);
    subTransaction.setAction(subTransactionType);
    transactionObjects.add(subTransaction);
}
Also used : SubTransactionImpl(org.opendaylight.genius.utils.batching.SubTransactionImpl) SubTransaction(org.opendaylight.genius.utils.batching.SubTransaction)

Example 2 with SubTransactionImpl

use of org.opendaylight.genius.utils.batching.SubTransactionImpl 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 3 with SubTransactionImpl

use of org.opendaylight.genius.utils.batching.SubTransactionImpl in project genius by opendaylight.

the class MdSalUtilBatchHandler method buildSubTransactions.

private void buildSubTransactions(List<SubTransaction> transactionObjects, InstanceIdentifier identifier, Object data, short subTransactionType) {
    // enable retries
    SubTransaction subTransaction = new SubTransactionImpl();
    subTransaction.setInstanceIdentifier(identifier);
    subTransaction.setInstance(data);
    subTransaction.setAction(subTransactionType);
    transactionObjects.add(subTransaction);
}
Also used : SubTransactionImpl(org.opendaylight.genius.utils.batching.SubTransactionImpl) SubTransaction(org.opendaylight.genius.utils.batching.SubTransaction)

Aggregations

SubTransaction (org.opendaylight.genius.utils.batching.SubTransaction)3 SubTransactionImpl (org.opendaylight.genius.utils.batching.SubTransactionImpl)3 Inet4Address (java.net.Inet4Address)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)1 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)1 MatchIpv4Destination (org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination)1 MatchIpv6Destination (org.opendaylight.genius.mdsalutil.matches.MatchIpv6Destination)1 MatchMetadata (org.opendaylight.genius.mdsalutil.matches.MatchMetadata)1 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)1 FlowId (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId)1 TableKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey)1 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)1 FlowKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey)1 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)1 Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)1