use of org.projectfloodlight.openflow.protocol.instruction.OFInstruction in project open-kilda by telstra.
the class OFFlowStatsConverter method buildFlowInstructions.
private static FlowInstructions buildFlowInstructions(final List<OFInstruction> instructions) {
Map<OFInstructionType, OFInstruction> instructionMap = instructions.stream().collect(Collectors.toMap(OFInstruction::getType, instruction -> instruction));
FlowApplyActions applyActions = Optional.ofNullable(instructionMap.get(OFInstructionType.APPLY_ACTIONS)).map(OFFlowStatsConverter::buildApplyActions).orElse(null);
Long meter = Optional.ofNullable(instructionMap.get(OFInstructionType.METER)).map(instruction -> ((OFInstructionMeter) instruction).getMeterId()).orElse(null);
return FlowInstructions.builder().applyActions(applyActions).goToMeter(meter).build();
}
use of org.projectfloodlight.openflow.protocol.instruction.OFInstruction in project open-kilda by telstra.
the class OneSwitchFlowInstallFlowModFactoryTest method makeForwardingMessage.
// --- service methods
private OFFlowAdd makeForwardingMessage(OneSwitchFlowInstallCommand command, int priorityOffset, Match match, TableId tableId, List<Integer> vlanStack) {
List<OFAction> applyActions = new ArrayList<>();
List<OFInstruction> instructions = new ArrayList<>();
if (command.getMeterConfig() != null) {
OfAdapter.INSTANCE.makeMeterCall(of, command.getMeterConfig().getId(), applyActions, instructions);
}
applyActions.addAll(OfAdapter.INSTANCE.makeVlanReplaceActions(of, vlanStack, command.getEgressEndpoint().getVlanStack()));
FlowEndpoint ingress = command.getEndpoint();
FlowEndpoint egress = command.getEgressEndpoint();
OFPort outPort = ingress.getPortNumber() == egress.getPortNumber() ? OFPort.IN_PORT : OFPort.of(egress.getPortNumber());
applyActions.add(of.actions().buildOutput().setPort(outPort).build());
instructions.add(of.instructions().applyActions(applyActions));
getGoToTableInstruction().ifPresent(instructions::add);
getWriteMetadataInstruction().ifPresent(instructions::add);
return of.buildFlowAdd().setTableId(tableId).setPriority(OneSwitchFlowInstallCommand.FLOW_PRIORITY + priorityOffset).setCookie(U64.of(command.getCookie().getValue())).setMatch(match).setInstructions(instructions).build();
}
use of org.projectfloodlight.openflow.protocol.instruction.OFInstruction in project open-kilda by telstra.
the class OfFlowPresenceVerifier method isInstructionsEquals.
private boolean isInstructionsEquals(List<OFInstruction> expectedSeq, List<OFInstruction> actualSeq) {
if (expectedSeq.size() != actualSeq.size()) {
return false;
}
Map<Class<?>, OFInstruction> expectedMap = sequenceToMapByTypes(expectedSeq);
Map<Class<?>, OFInstruction> actualMap = sequenceToMapByTypes(actualSeq);
boolean result = true;
for (Map.Entry<Class<?>, OFInstruction> entry : expectedMap.entrySet()) {
OFInstruction expected = entry.getValue();
OFInstruction actual = actualMap.get(entry.getKey());
if (actual == null) {
result = false;
} else if (expected instanceof OFInstructionApplyActions) {
result = isApplyActionsInstructionEquals((OFInstructionApplyActions) expected, (OFInstructionApplyActions) actual);
} else if (expected instanceof OFInstructionWriteActions) {
result = isWriteActionsInstructionEquals((OFInstructionWriteActions) expected, (OFInstructionWriteActions) actual);
} else if (!Objects.equals(expected, actual)) {
result = false;
}
if (!result) {
break;
}
}
return result;
}
use of org.projectfloodlight.openflow.protocol.instruction.OFInstruction in project open-kilda by telstra.
the class IngressFlowModFactoryTest method verifyGoToTableInstruction.
// --- verify methods
protected void verifyGoToTableInstruction(OFFlowMod message) {
OFInstructionGotoTable match = null;
for (OFInstruction instruction : message.getInstructions()) {
if (instruction instanceof OFInstructionGotoTable) {
match = (OFInstructionGotoTable) instruction;
break;
}
}
if (expectPostIngressTableRedirect()) {
Assert.assertNotNull(match);
Assert.assertEquals(TableId.of(SwitchManager.POST_INGRESS_TABLE_ID), match.getTableId());
} else {
Assert.assertNull(match);
}
}
use of org.projectfloodlight.openflow.protocol.instruction.OFInstruction in project open-kilda by telstra.
the class OfInstructionsConverterTest method convertToRuleManagerInstructionsTest.
@Test
public void convertToRuleManagerInstructionsTest() {
OFFactory factory = new OFFactoryVer13();
List<OFInstruction> instructions = new ArrayList<>();
instructions.add(factory.instructions().gotoTable(TableId.of(1)));
instructions.add(factory.instructions().meter(2));
instructions.add(factory.instructions().writeMetadata(U64.of(123), U64.of(234)));
List<OFAction> actions = buildActions(factory);
instructions.add(factory.instructions().applyActions(actions));
Instructions actual = OfInstructionsConverter.INSTANCE.convertToRuleManagerInstructions(instructions);
assertEquals(OfTable.PRE_INGRESS, actual.getGoToTable());
assertEquals(new MeterId(2), actual.getGoToMeter());
assertEquals(new OfMetadata(123, 234), actual.getWriteMetadata());
assertEquals(12, actual.getApplyActions().size());
List<Action> expectedActions = buildActions();
assertTrue(actual.getApplyActions().containsAll(expectedActions));
}
Aggregations