Search in sources :

Example 1 with AddFlowOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput in project netvirt by opendaylight.

the class NaptEventHandler method buildAndInstallNatFlowsOptionalRpc.

private Future<RpcResult<AddFlowOutput>> buildAndInstallNatFlowsOptionalRpc(BigInteger dpnId, short tableId, long vpnId, long routerId, long bgpVpnId, SessionAddress actualSourceAddress, SessionAddress translatedSourceAddress, NAPTEntryEvent.Protocol protocol, String extGwMacAddress, boolean sendRpc) {
    LOG.debug("buildAndInstallNatFlowsOptionalRpc : Build and install table={} flow on dpnId {} and routerId {}", tableId, dpnId, routerId);
    // Build the flow for replacing the actual IP and port with the translated IP and port.
    int idleTimeout = 0;
    if (tableId == NwConstants.OUTBOUND_NAPT_TABLE) {
        idleTimeout = NatConstants.DEFAULT_NAPT_IDLE_TIMEOUT;
    }
    long intranetVpnId;
    if (bgpVpnId != NatConstants.INVALID_ID) {
        intranetVpnId = bgpVpnId;
    } else {
        intranetVpnId = routerId;
    }
    LOG.debug("buildAndInstallNatFlowsOptionalRpc : Intranet VPN ID {} Router ID {}", intranetVpnId, routerId);
    String translatedIp = translatedSourceAddress.getIpAddress();
    int translatedPort = translatedSourceAddress.getPortNumber();
    String actualIp = actualSourceAddress.getIpAddress();
    int actualPort = actualSourceAddress.getPortNumber();
    String switchFlowRef = NatUtil.getNaptFlowRef(dpnId, tableId, String.valueOf(routerId), actualIp, actualPort);
    FlowEntity snatFlowEntity = new FlowEntityBuilder().setDpnId(dpnId).setTableId(tableId).setFlowId(switchFlowRef).setPriority(NatConstants.DEFAULT_NAPT_FLOW_PRIORITY).setFlowName(NatConstants.NAPT_FLOW_NAME).setIdleTimeOut(idleTimeout).setHardTimeOut(0).setCookie(NatUtil.getCookieNaptFlow(routerId)).setMatchInfoList(buildAndGetMatchInfo(actualIp, actualPort, tableId, protocol, intranetVpnId)).setInstructionInfoList(buildAndGetSetActionInstructionInfo(translatedIp, translatedPort, intranetVpnId, vpnId, tableId, protocol, extGwMacAddress)).setSendFlowRemFlag(true).build();
    // Install flows using RPC to prevent race with future packet-out that depends on this flow
    Future<RpcResult<AddFlowOutput>> addFlowResult = null;
    if (sendRpc) {
        Flow flow = snatFlowEntity.getFlowBuilder().build();
        NodeRef nodeRef = getNodeRef(dpnId);
        FlowRef flowRef = getFlowRef(dpnId, flow);
        AddFlowInput addFlowInput = new AddFlowInputBuilder(flow).setFlowRef(flowRef).setNode(nodeRef).build();
        long startTime = System.currentTimeMillis();
        addFlowResult = salFlowServiceRpc.addFlow(addFlowInput);
        LOG.debug("buildAndInstallNatFlowsOptionalRpc : Time elapsed for salFlowServiceRpc table {}: {}ms ", tableId, System.currentTimeMillis() - startTime);
        // Keep flow installation through MDSAL as well to be able to handle switch failures
        startTime = System.currentTimeMillis();
        mdsalManager.installFlow(snatFlowEntity);
        LOG.trace("buildAndInstallNatFlowsOptionalRpc : Time Elapsed while installing table-{} " + "flow on DPN:{} for snat packet({},{}): {}ms", tableId, dpnId, actualSourceAddress.getIpAddress(), actualSourceAddress.getPortNumber(), System.currentTimeMillis() - startTime);
    } else {
        long startTime = System.currentTimeMillis();
        mdsalManager.syncInstallFlow(snatFlowEntity);
        LOG.trace("buildAndInstallNatFlowsOptionalRpc : Time Elapsed while installing table-{} " + "flow on DPN:{} for snat packet({},{}): {}ms", tableId, dpnId, actualSourceAddress.getIpAddress(), actualSourceAddress.getPortNumber(), System.currentTimeMillis() - startTime);
    }
    LOG.trace("buildAndInstallNatFlowsOptionalRpc : Exited");
    return addFlowResult;
}
Also used : FlowEntityBuilder(org.opendaylight.genius.mdsalutil.FlowEntityBuilder) 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) AddFlowInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput) AddFlowInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)

Example 2 with AddFlowOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput in project openflowplugin by opendaylight.

the class DropTestRpcSender method processPacket.

@Override
protected void processPacket(final InstanceIdentifier<Node> node, final Match match, final Instructions instructions) {
    final AddFlowInputBuilder fb = BUILDER.get();
    // Finally build our flow
    fb.setMatch(match);
    fb.setInstructions(instructions);
    // Construct the flow instance id
    fb.setNode(new NodeRef(node));
    // Add flow
    final AddFlowInput flow = fb.build();
    if (LOG.isDebugEnabled()) {
        LOG.debug("onPacketReceived - About to write flow (via SalFlowService) {}", flow);
    }
    ListenableFuture<RpcResult<AddFlowOutput>> result = JdkFutureAdapters.listenInPoolThread(flowService.addFlow(flow));
    Futures.addCallback(result, new FutureCallback<RpcResult<AddFlowOutput>>() {

        @Override
        public void onSuccess(final RpcResult<AddFlowOutput> result) {
            countFutureSuccess();
        }

        @Override
        public void onFailure(final Throwable throwable) {
            countFutureError();
        }
    }, MoreExecutors.directExecutor());
}
Also used : AddFlowOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput) NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) AddFlowInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) AddFlowInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder)

Example 3 with AddFlowOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput in project openflowplugin by opendaylight.

the class SalFlowServiceImplTest method addFlowFailCallback.

private void addFlowFailCallback(short version) throws InterruptedException, ExecutionException {
    AddFlowInput mockedAddFlowInput = new AddFlowInputBuilder().setMatch(match).setTableId((short) 1).build();
    Mockito.doReturn(Futures.<RequestContext<Object>>immediateFailedFuture(new Exception("ut-failed-response"))).when(requestContext).getFuture();
    mockingFlowRegistryLookup();
    final Future<RpcResult<AddFlowOutput>> rpcResultFuture = mockSalFlowService(version).addFlow(mockedAddFlowInput);
    assertNotNull(rpcResultFuture);
    final RpcResult<?> addFlowOutputRpcResult = rpcResultFuture.get();
    assertNotNull(addFlowOutputRpcResult);
    assertFalse(addFlowOutputRpcResult.isSuccessful());
}
Also used : AddFlowInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) AddFlowInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with AddFlowOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput in project openflowplugin by opendaylight.

the class FlowForwarder method add.

@Override
public Future<RpcResult<AddFlowOutput>> add(final InstanceIdentifier<Flow> identifier, final Flow addDataObj, final InstanceIdentifier<FlowCapableNode> nodeIdent) {
    Future<RpcResult<AddFlowOutput>> future;
    final TableKey tableKey = identifier.firstKeyOf(Table.class, TableKey.class);
    if (tableIdValidationPrecondition(tableKey, addDataObj)) {
        final AddFlowInputBuilder builder = new AddFlowInputBuilder(addDataObj);
        builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class)));
        builder.setFlowRef(new FlowRef(identifier));
        builder.setFlowTable(new FlowTableRef(nodeIdent.child(Table.class, tableKey)));
        builder.setTransactionUri(new Uri(provider.getNewTransactionId()));
        future = provider.getSalFlowService().addFlow(builder.build());
    } else {
        future = Futures.<RpcResult<AddFlowOutput>>immediateFuture(null);
    }
    return future;
}
Also used : AddFlowOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput) NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) FlowTableRef(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowTableRef) FlowRef(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) AddFlowInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder) TableKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey) Uri(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri)

Example 5 with AddFlowOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput in project openflowplugin by opendaylight.

the class SalBulkFlowServiceImpl method addFlowsRpc.

@Override
public Future<RpcResult<Void>> addFlowsRpc(AddFlowsRpcInput input) {
    List<ListenableFuture<RpcResult<AddFlowOutput>>> bulkResults = new ArrayList<>();
    for (BulkFlowBaseContentGrouping bulkFlow : input.getBulkFlowItem()) {
        AddFlowInputBuilder flowInputBuilder = new AddFlowInputBuilder((org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow) bulkFlow);
        final NodeRef nodeRef = bulkFlow.getNode();
        flowInputBuilder.setNode(nodeRef);
        flowInputBuilder.setTableId(bulkFlow.getTableId());
        Future<RpcResult<AddFlowOutput>> rpcAddFlowResult = flowService.addFlow(flowInputBuilder.build());
        bulkResults.add(JdkFutureAdapters.listenInPoolThread(rpcAddFlowResult));
    }
    return handleResultFuture(Futures.allAsList(bulkResults));
}
Also used : AddFlowOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput) BulkFlowBaseContentGrouping(org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608.BulkFlowBaseContentGrouping) ArrayList(java.util.ArrayList) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) AddFlowInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder)

Aggregations

RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)12 AddFlowInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder)8 AddFlowOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput)7 AddFlowInput (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput)6 NodeRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef)6 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)3 ArrayList (java.util.ArrayList)3 TableKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey)3 FlowRef (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef)3 ExecutionException (java.util.concurrent.ExecutionException)2 Test (org.junit.Test)2 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)2 FlowTableRef (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowTableRef)2 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 BigInteger (java.math.BigInteger)1 UnknownHostException (java.net.UnknownHostException)1 Map (java.util.Map)1 Future (java.util.concurrent.Future)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1