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;
}
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());
}
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());
}
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;
}
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));
}
Aggregations