Search in sources :

Example 6 with AddFlowOutput

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

the class SalFlowsBatchServiceImplTest method testAddFlowsBatch_failed.

@Test
public void testAddFlowsBatch_failed() throws Exception {
    Mockito.when(salFlowService.addFlow(Matchers.<AddFlowInput>any())).thenReturn(RpcResultBuilder.<AddFlowOutput>failed().withError(RpcError.ErrorType.APPLICATION, "ut-groupAddError").buildFuture());
    final AddFlowsBatchInput input = new AddFlowsBatchInputBuilder().setNode(NODE_REF).setBarrierAfter(true).setBatchAddFlows(Lists.newArrayList(createEmptyBatchAddFlow(FLOW_ID_VALUE_1, 42), createEmptyBatchAddFlow(FLOW_ID_VALUE_2, 43))).build();
    final Future<RpcResult<AddFlowsBatchOutput>> resultFuture = salFlowsBatchService.addFlowsBatch(input);
    Assert.assertTrue(resultFuture.isDone());
    Assert.assertFalse(resultFuture.get().isSuccessful());
    Assert.assertEquals(2, resultFuture.get().getResult().getBatchFailedFlowsOutput().size());
    Assert.assertEquals(FLOW_ID_VALUE_1, resultFuture.get().getResult().getBatchFailedFlowsOutput().get(0).getFlowId().getValue());
    Assert.assertEquals(FLOW_ID_VALUE_2, resultFuture.get().getResult().getBatchFailedFlowsOutput().get(1).getFlowId().getValue());
    Assert.assertEquals(2, resultFuture.get().getErrors().size());
    final InOrder inOrder = Mockito.inOrder(salFlowService, transactionService);
    inOrder.verify(salFlowService, Mockito.times(2)).addFlow(addFlowInputCpt.capture());
    final List<AddFlowInput> allValues = addFlowInputCpt.getAllValues();
    Assert.assertEquals(2, allValues.size());
    Assert.assertEquals(42, allValues.get(0).getPriority().longValue());
    Assert.assertEquals(43, allValues.get(1).getPriority().longValue());
    inOrder.verify(transactionService).sendBarrier(Matchers.<SendBarrierInput>any());
}
Also used : AddFlowsBatchInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.AddFlowsBatchInputBuilder) InOrder(org.mockito.InOrder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) AddFlowInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput) AddFlowsBatchInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.AddFlowsBatchInput) Test(org.junit.Test)

Example 7 with AddFlowOutput

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

the class NaptEventHandler method handleEvent.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void handleEvent(final NAPTEntryEvent naptEntryEvent) {
    /*
            Flow programming logic of the OUTBOUND NAPT TABLE :
            1) Get the internal IP address, port number, router ID from the event.
            2) Use the NAPT service getExternalAddressMapping() to get the External IP and the port.
            3) Build the flow for replacing the Internal IP and port with the External IP and port.
              a) Write the matching criteria.
              b) Match the router ID in the metadata.
              d) Write the VPN ID to the metadata.
              e) Write the other data.
              f) Set the apply actions instruction with the action setfield.
            4) Write the flow to the OUTBOUND NAPT Table and forward to FIB table for routing the traffic.

            Flow programming logic of the INBOUND NAPT TABLE :
            Same as Outbound table logic except that :
            1) Build the flow for replacing the External IP and port with the Internal IP and port.
            2) Match the VPN ID in the metadata.
            3) Write the router ID to the metadata.
            5) Write the flow to the INBOUND NAPT Table and forward to FIB table for routing the traffic.
    */
    try {
        Long routerId = naptEntryEvent.getRouterId();
        LOG.trace("handleEvent : Time Elapsed before procesing snat ({}:{}) packet is {} ms," + "routerId: {},isPktProcessed:{}", naptEntryEvent.getIpAddress(), naptEntryEvent.getPortNumber(), System.currentTimeMillis() - naptEntryEvent.getObjectCreationTime(), routerId, naptEntryEvent.isPktProcessed());
        // Get the DPN ID
        BigInteger dpnId = NatUtil.getPrimaryNaptfromRouterId(dataBroker, routerId);
        long bgpVpnId = NatConstants.INVALID_ID;
        if (dpnId == null) {
            LOG.warn("handleEvent : dpnId is null. Assuming the router ID {} as the BGP VPN ID and proceeding....", routerId);
            bgpVpnId = routerId;
            LOG.debug("handleEvent : BGP VPN ID {}", bgpVpnId);
            String vpnName = NatUtil.getRouterName(dataBroker, bgpVpnId);
            String routerName = NatUtil.getRouterIdfromVpnInstance(dataBroker, vpnName);
            if (routerName == null) {
                LOG.error("handleEvent : Unable to find router for VpnName {}", vpnName);
                return;
            }
            routerId = NatUtil.getVpnId(dataBroker, routerName);
            LOG.debug("handleEvent : Router ID {}", routerId);
            dpnId = NatUtil.getPrimaryNaptfromRouterId(dataBroker, routerId);
            if (dpnId == null) {
                LOG.error("handleEvent : dpnId is null for the router {}", routerId);
                return;
            }
        }
        if (naptEntryEvent.getOperation() == NAPTEntryEvent.Operation.ADD) {
            LOG.debug("handleEvent : Inside Add operation of NaptEventHandler");
            // Build and install the NAPT translation flows in the Outbound and Inbound NAPT tables
            if (!naptEntryEvent.isPktProcessed()) {
                // Get the External Gateway MAC Address
                String extGwMacAddress = NatUtil.getExtGwMacAddFromRouterId(dataBroker, routerId);
                if (extGwMacAddress != null) {
                    LOG.debug("handleEvent : External Gateway MAC address {} found for External Router ID {}", extGwMacAddress, routerId);
                } else {
                    LOG.error("handleEvent : No External Gateway MAC address found for External Router ID {}", routerId);
                    return;
                }
                // Get the external network ID from the ExternalRouter model
                Uuid networkId = NatUtil.getNetworkIdFromRouterId(dataBroker, routerId);
                if (networkId == null) {
                    LOG.error("handleEvent : networkId is null");
                    return;
                }
                // Get the VPN ID from the ExternalNetworks model
                Uuid vpnUuid = NatUtil.getVpnIdfromNetworkId(dataBroker, networkId);
                if (vpnUuid == null) {
                    LOG.error("handleEvent : vpnUuid is null");
                    return;
                }
                Long vpnId = NatUtil.getVpnId(dataBroker, vpnUuid.getValue());
                // Get the internal IpAddress, internal port number from the event
                String internalIpAddress = naptEntryEvent.getIpAddress();
                int internalPort = naptEntryEvent.getPortNumber();
                SessionAddress internalAddress = new SessionAddress(internalIpAddress, internalPort);
                NAPTEntryEvent.Protocol protocol = naptEntryEvent.getProtocol();
                // Get the external IP address for the corresponding internal IP address
                SessionAddress externalAddress = naptManager.getExternalAddressMapping(routerId, internalAddress, naptEntryEvent.getProtocol());
                if (externalAddress == null) {
                    LOG.error("handleEvent : externalAddress is null");
                    return;
                }
                Long vpnIdFromExternalSubnet = getVpnIdFromExternalSubnet(routerId, externalAddress.getIpAddress());
                if (vpnIdFromExternalSubnet != NatConstants.INVALID_ID) {
                    vpnId = vpnIdFromExternalSubnet;
                }
                // Added External Gateway MAC Address
                Future<RpcResult<AddFlowOutput>> addFlowResult = buildAndInstallNatFlowsOptionalRpc(dpnId, NwConstants.INBOUND_NAPT_TABLE, vpnId, routerId, bgpVpnId, externalAddress, internalAddress, protocol, extGwMacAddress, true);
                final BigInteger finalDpnId = dpnId;
                final Long finalVpnId = vpnId;
                final Long finalRouterId = routerId;
                final long finalBgpVpnId = bgpVpnId;
                Futures.addCallback(JdkFutureAdapters.listenInPoolThread(addFlowResult), new FutureCallback<RpcResult<AddFlowOutput>>() {

                    @Override
                    public void onSuccess(@Nullable RpcResult<AddFlowOutput> result) {
                        LOG.debug("handleEvent : Configured inbound rule for {} to {}", internalAddress, externalAddress);
                        Future<RpcResult<AddFlowOutput>> addFlowResult = buildAndInstallNatFlowsOptionalRpc(finalDpnId, NwConstants.OUTBOUND_NAPT_TABLE, finalVpnId, finalRouterId, finalBgpVpnId, internalAddress, externalAddress, protocol, extGwMacAddress, true);
                        Futures.addCallback(JdkFutureAdapters.listenInPoolThread(addFlowResult), new FutureCallback<RpcResult<AddFlowOutput>>() {

                            @Override
                            public void onSuccess(@Nullable RpcResult<AddFlowOutput> result) {
                                LOG.debug("handleEvent : Configured outbound rule, sending packet out" + "from {} to {}", internalAddress, externalAddress);
                                prepareAndSendPacketOut(naptEntryEvent, finalRouterId);
                            }

                            @Override
                            public void onFailure(@Nonnull Throwable throwable) {
                                LOG.error("handleEvent : Error configuring outbound " + "SNAT flows using RPC for SNAT connection from {} to {}", internalAddress, externalAddress);
                            }
                        }, MoreExecutors.directExecutor());
                    }

                    @Override
                    public void onFailure(@Nonnull Throwable throwable) {
                        LOG.error("handleEvent : Error configuring inbound SNAT flows " + "using RPC for SNAT connection from {} to {}", internalAddress, externalAddress);
                    }
                }, MoreExecutors.directExecutor());
                NatPacketProcessingState state = naptEntryEvent.getState();
                if (state != null) {
                    state.setFlowInstalledTime(System.currentTimeMillis());
                }
            } else {
                prepareAndSendPacketOut(naptEntryEvent, routerId);
            }
            LOG.trace("handleEvent : Time elapsed after Processsing snat ({}:{}) packet: {}ms,isPktProcessed:{} ", naptEntryEvent.getIpAddress(), naptEntryEvent.getPortNumber(), System.currentTimeMillis() - naptEntryEvent.getObjectCreationTime(), naptEntryEvent.isPktProcessed());
        } else {
            LOG.debug("handleEvent : Inside delete Operation of NaptEventHandler");
            removeNatFlows(dpnId, NwConstants.INBOUND_NAPT_TABLE, routerId, naptEntryEvent.getIpAddress(), naptEntryEvent.getPortNumber());
            LOG.info("handleEvent : exited for removeEvent for IP {}, port {}, routerID : {}", naptEntryEvent.getIpAddress(), naptEntryEvent.getPortNumber(), routerId);
        }
    } catch (Exception e) {
        LOG.error("handleEvent :Exception in NaptEventHandler.handleEvent() payload {}", naptEntryEvent, e);
    }
}
Also used : AddFlowOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput) Nonnull(javax.annotation.Nonnull) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) NatPacketProcessingState(org.opendaylight.netvirt.natservice.internal.NaptPacketInHandler.NatPacketProcessingState) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) PacketException(org.opendaylight.openflowplugin.libraries.liblldp.PacketException) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) BigInteger(java.math.BigInteger) Future(java.util.concurrent.Future) FutureCallback(com.google.common.util.concurrent.FutureCallback) Nullable(javax.annotation.Nullable)

Example 8 with AddFlowOutput

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

the class LLDPPacketPuntEnforcer method onDataTreeChanged.

@Override
public void onDataTreeChanged(@Nonnull final Collection<DataTreeModification<FlowCapableNode>> modifications) {
    for (DataTreeModification<FlowCapableNode> modification : modifications) {
        if (modification.getRootNode().getModificationType() == ModificationType.WRITE) {
            AddFlowInputBuilder addFlowInput = new AddFlowInputBuilder(createFlow());
            addFlowInput.setNode(new NodeRef(modification.getRootPath().getRootIdentifier().firstIdentifierOf(Node.class)));
            final Future<RpcResult<AddFlowOutput>> resultFuture = this.flowService.addFlow(addFlowInput.build());
            JdkFutures.addErrorLogging(resultFuture, LOG, "addFlow");
        }
    }
}
Also used : NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) AddFlowInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder)

Example 9 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) {
    LOG.trace("Forwarding the Flow ADD request [Tbl id, node Id {} {} {}", identifier, nodeIdent, addDataObj);
    final Future<RpcResult<AddFlowOutput>> output;
    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)));
        output = salFlowService.addFlow(builder.build());
    } else {
        output = RpcResultBuilder.<AddFlowOutput>failed().withError(RpcError.ErrorType.APPLICATION, TABLE_ID_MISMATCH).buildFuture();
    }
    return output;
}
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) 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)

Example 10 with AddFlowOutput

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

the class SyncPlanPushStrategyIncrementalImpl method addMissingFlows.

ListenableFuture<RpcResult<Void>> addMissingFlows(final NodeId nodeId, final InstanceIdentifier<FlowCapableNode> nodeIdent, final Map<TableKey, ItemSyncBox<Flow>> flowsInTablesSyncBox, final SyncCrudCounters counters) {
    if (flowsInTablesSyncBox.isEmpty()) {
        LOG.trace("no tables in config for node: {} -> SKIPPING", nodeId.getValue());
        return RpcResultBuilder.<Void>success().buildFuture();
    }
    final List<ListenableFuture<RpcResult<AddFlowOutput>>> allResults = new ArrayList<>();
    final List<ListenableFuture<RpcResult<UpdateFlowOutput>>> allUpdateResults = new ArrayList<>();
    final CrudCounts flowCrudCounts = counters.getFlowCrudCounts();
    for (Map.Entry<TableKey, ItemSyncBox<Flow>> flowsInTableBoxEntry : flowsInTablesSyncBox.entrySet()) {
        final TableKey tableKey = flowsInTableBoxEntry.getKey();
        final ItemSyncBox<Flow> flowSyncBox = flowsInTableBoxEntry.getValue();
        final KeyedInstanceIdentifier<Table, TableKey> tableIdent = nodeIdent.child(Table.class, tableKey);
        for (final Flow flow : flowSyncBox.getItemsToPush()) {
            final KeyedInstanceIdentifier<Flow, FlowKey> flowIdent = tableIdent.child(Flow.class, flow.getKey());
            LOG.trace("adding flow {} in table {} - absent on device {} match{}", flow.getId(), tableKey, nodeId, flow.getMatch());
            allResults.add(JdkFutureAdapters.listenInPoolThread(flowForwarder.add(flowIdent, flow, nodeIdent)));
            flowCrudCounts.incAdded();
        }
        for (final ItemSyncBox.ItemUpdateTuple<Flow> flowUpdate : flowSyncBox.getItemsToUpdate()) {
            final Flow existingFlow = flowUpdate.getOriginal();
            final Flow updatedFlow = flowUpdate.getUpdated();
            final KeyedInstanceIdentifier<Flow, FlowKey> flowIdent = tableIdent.child(Flow.class, updatedFlow.getKey());
            LOG.trace("flow {} in table {} - needs update on device {} match{}", updatedFlow.getId(), tableKey, nodeId, updatedFlow.getMatch());
            allUpdateResults.add(JdkFutureAdapters.listenInPoolThread(flowForwarder.update(flowIdent, existingFlow, updatedFlow, nodeIdent)));
            flowCrudCounts.incUpdated();
        }
    }
    final ListenableFuture<RpcResult<Void>> singleVoidAddResult = Futures.transform(Futures.allAsList(allResults), ReconcileUtil.<AddFlowOutput>createRpcResultCondenser("flow adding"), MoreExecutors.directExecutor());
    final ListenableFuture<RpcResult<Void>> singleVoidUpdateResult = Futures.transform(Futures.allAsList(allUpdateResults), ReconcileUtil.<UpdateFlowOutput>createRpcResultCondenser("flow updating"), MoreExecutors.directExecutor());
    return Futures.transform(Futures.allAsList(singleVoidAddResult, singleVoidUpdateResult), ReconcileUtil.<Void>createRpcResultCondenser("flow add/update"), MoreExecutors.directExecutor());
}
Also used : AddFlowOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput) FlowKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey) Table(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table) ItemSyncBox(org.opendaylight.openflowplugin.applications.frsync.util.ItemSyncBox) ArrayList(java.util.ArrayList) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) 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) CrudCounts(org.opendaylight.openflowplugin.applications.frsync.util.CrudCounts) UpdateFlowOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Map(java.util.Map)

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