use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder 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.AddFlowInputBuilder 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.AddFlowInputBuilder in project openflowplugin by opendaylight.
the class BundleAddMessageConverter method convertBundleFlowCase.
private BundleFlowModCase convertBundleFlowCase(final BundleInnerMessage messageCase, final VersionDatapathIdConvertorData data) throws ConversionException {
Optional<List<FlowModInputBuilder>> flowModInputs = Optional.empty();
final Class clazz = messageCase.getImplementedInterface();
if (clazz.equals(BundleAddFlowCase.class)) {
flowModInputs = CONVERTER_EXECUTOR.convert(new AddFlowInputBuilder(((BundleAddFlowCase) messageCase).getAddFlowCaseData()).build(), data);
} else if (clazz.equals(BundleUpdateFlowCase.class)) {
flowModInputs = CONVERTER_EXECUTOR.convert(new UpdatedFlowBuilder(((BundleUpdateFlowCase) messageCase).getUpdateFlowCaseData()).build(), data);
} else if (clazz.equals(BundleRemoveFlowCase.class)) {
flowModInputs = CONVERTER_EXECUTOR.convert(new RemoveFlowInputBuilder(((BundleRemoveFlowCase) messageCase).getRemoveFlowCaseData()).build(), data);
}
if (flowModInputs.isPresent()) {
if (flowModInputs.get().size() == 1) {
return new BundleFlowModCaseBuilder().setFlowModCaseData(new FlowModCaseDataBuilder(flowModInputs.get().get(0).setXid(xid).build()).build()).build();
} else {
throw new ConversionException("BundleFlowCase conversion unsuccessful - not able to convert to multiple flows.");
}
} else {
throw new ConversionException("BundleFlowCase conversion unsuccessful.");
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder 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.AddFlowInputBuilder in project openflowplugin by opendaylight.
the class FlowConvertorTest method testInstructionsTranslation.
/**
* Tests {@link FlowConvertor#convert(Flow, VersionDatapathIdConvertorData)} }.
*/
@Test
public void testInstructionsTranslation() {
InstructionBuilder instructionBuilder = new InstructionBuilder();
GoToTableCaseBuilder goToCaseBuilder = new GoToTableCaseBuilder();
GoToTableBuilder goToBuilder = new GoToTableBuilder();
goToBuilder.setTableId((short) 1);
goToCaseBuilder.setGoToTable(goToBuilder.build());
instructionBuilder.setInstruction(goToCaseBuilder.build());
instructionBuilder.setOrder(0);
List<Instruction> instructions = new ArrayList<>();
instructions.add(instructionBuilder.build());
instructionBuilder = new InstructionBuilder();
WriteMetadataCaseBuilder metaCaseBuilder = new WriteMetadataCaseBuilder();
WriteMetadataBuilder metaBuilder = new WriteMetadataBuilder();
metaBuilder.setMetadata(new BigInteger("2"));
metaBuilder.setMetadataMask(new BigInteger("3"));
metaCaseBuilder.setWriteMetadata(metaBuilder.build());
instructionBuilder.setInstruction(metaCaseBuilder.build());
instructionBuilder.setOrder(1);
instructions.add(instructionBuilder.build());
instructionBuilder = new InstructionBuilder();
WriteActionsCaseBuilder writeCaseBuilder = new WriteActionsCaseBuilder();
WriteActionsBuilder writeBuilder = new WriteActionsBuilder();
List<Action> actions = new ArrayList<>();
writeBuilder.setAction(actions);
writeCaseBuilder.setWriteActions(writeBuilder.build());
instructionBuilder.setInstruction(writeCaseBuilder.build());
instructionBuilder.setOrder(2);
instructions.add(instructionBuilder.build());
instructionBuilder = new InstructionBuilder();
ApplyActionsCaseBuilder applyCaseBuilder = new ApplyActionsCaseBuilder();
ApplyActionsBuilder applyBuilder = new ApplyActionsBuilder();
actions = new ArrayList<>();
applyBuilder.setAction(actions);
applyCaseBuilder.setApplyActions(applyBuilder.build());
instructionBuilder.setInstruction(applyCaseBuilder.build());
instructionBuilder.setOrder(3);
instructions.add(instructionBuilder.build());
instructionBuilder = new InstructionBuilder();
ClearActionsCaseBuilder clearCaseBuilder = new ClearActionsCaseBuilder();
ClearActionsBuilder clearBuilder = new ClearActionsBuilder();
actions = new ArrayList<>();
clearBuilder.setAction(actions);
clearCaseBuilder.setClearActions(clearBuilder.build());
instructionBuilder.setInstruction(clearCaseBuilder.build());
instructionBuilder.setOrder(4);
instructions.add(instructionBuilder.build());
instructionBuilder = new InstructionBuilder();
MeterCaseBuilder meterCaseBuilder = new MeterCaseBuilder();
MeterBuilder meterBuilder = new MeterBuilder();
meterBuilder.setMeterId(new MeterId(5L));
meterCaseBuilder.setMeter(meterBuilder.build());
instructionBuilder.setInstruction(meterCaseBuilder.build());
instructionBuilder.setOrder(5);
instructions.add(instructionBuilder.build());
InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
instructionsBuilder.setInstruction(instructions);
AddFlowInputBuilder flowBuilder = new AddFlowInputBuilder();
flowBuilder.setInstructions(instructionsBuilder.build());
AddFlowInput flow = flowBuilder.build();
VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_0);
data.setDatapathId(new BigInteger("42"));
List<FlowModInputBuilder> flowMod = convert(flow, data);
Assert.assertEquals("Wrong version", 1, flowMod.get(0).getVersion().intValue());
Assert.assertEquals("Wrong command", FlowModCommand.OFPFCADD, flowMod.get(0).getCommand());
Assert.assertEquals("Wrong instructions size", 6, flowMod.get(0).getInstruction().size());
org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction instruction = flowMod.get(0).getInstruction().get(0);
Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common" + ".instruction.rev130731.instruction.grouping.instruction.choice.GotoTableCase", instruction.getInstructionChoice().getImplementedInterface().getName());
GotoTableCase gotoTableCase = (GotoTableCase) instruction.getInstructionChoice();
Assert.assertEquals("Wrong table id", 1, gotoTableCase.getGotoTable().getTableId().intValue());
instruction = flowMod.get(0).getInstruction().get(1);
Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common" + ".instruction.rev130731.instruction.grouping.instruction.choice.WriteMetadataCase", instruction.getInstructionChoice().getImplementedInterface().getName());
WriteMetadataCase writeMetadataCase = (WriteMetadataCase) instruction.getInstructionChoice();
Assert.assertArrayEquals("Wrong metadata", new byte[] { 0, 0, 0, 0, 0, 0, 0, 2 }, writeMetadataCase.getWriteMetadata().getMetadata());
Assert.assertArrayEquals("Wrong metadata mask", new byte[] { 0, 0, 0, 0, 0, 0, 0, 3 }, writeMetadataCase.getWriteMetadata().getMetadataMask());
instruction = flowMod.get(0).getInstruction().get(2);
Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common" + ".instruction.rev130731.instruction.grouping.instruction.choice.WriteActionsCase", instruction.getInstructionChoice().getImplementedInterface().getName());
WriteActionsCase writeActionsCase = (WriteActionsCase) instruction.getInstructionChoice();
Assert.assertEquals("Wrong actions size", 0, writeActionsCase.getWriteActions().getAction().size());
instruction = flowMod.get(0).getInstruction().get(3);
Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common" + ".instruction.rev130731.instruction.grouping.instruction.choice.ApplyActionsCase", instruction.getInstructionChoice().getImplementedInterface().getName());
ApplyActionsCase applyActionsCase = (ApplyActionsCase) instruction.getInstructionChoice();
Assert.assertEquals("Wrong actions size", 0, applyActionsCase.getApplyActions().getAction().size());
instruction = flowMod.get(0).getInstruction().get(4);
Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common" + ".instruction.rev130731.instruction.grouping.instruction.choice.ClearActionsCase", instruction.getInstructionChoice().getImplementedInterface().getName());
instruction = flowMod.get(0).getInstruction().get(5);
Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common" + ".instruction.rev130731.instruction.grouping.instruction.choice.MeterCase", instruction.getInstructionChoice().getImplementedInterface().getName());
MeterCase meterCase = (MeterCase) instruction.getInstructionChoice();
Assert.assertEquals("Wrong meter id", 5, meterCase.getMeter().getMeterId().intValue());
}
Aggregations