Search in sources :

Example 1 with OFInstruction

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();
}
Also used : OFFlowModFlags(org.projectfloodlight.openflow.protocol.OFFlowModFlags) OFFlowStatsEntry(org.projectfloodlight.openflow.protocol.OFFlowStatsEntry) OFActionType(org.projectfloodlight.openflow.protocol.OFActionType) Map(java.util.Map) Match(org.projectfloodlight.openflow.protocol.match.Match) OFActionMeter(org.projectfloodlight.openflow.protocol.action.OFActionMeter) OFInstruction(org.projectfloodlight.openflow.protocol.instruction.OFInstruction) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry) OFActionOutput(org.projectfloodlight.openflow.protocol.action.OFActionOutput) OFOxm(org.projectfloodlight.openflow.protocol.oxm.OFOxm) OFInstructionApplyActions(org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions) Collectors(java.util.stream.Collectors) OFAction(org.projectfloodlight.openflow.protocol.action.OFAction) FlowApplyActions(org.openkilda.messaging.info.rule.FlowApplyActions) Objects(java.util.Objects) List(java.util.List) OFActionPushVlan(org.projectfloodlight.openflow.protocol.action.OFActionPushVlan) FlowSetFieldAction(org.openkilda.messaging.info.rule.FlowSetFieldAction) FlowInstructions(org.openkilda.messaging.info.rule.FlowInstructions) MatchField(org.projectfloodlight.openflow.protocol.match.MatchField) Optional(java.util.Optional) OFInstructionMeter(org.projectfloodlight.openflow.protocol.instruction.OFInstructionMeter) FlowMatchField(org.openkilda.messaging.info.rule.FlowMatchField) OFInstructionType(org.projectfloodlight.openflow.protocol.OFInstructionType) OFActionSetField(org.projectfloodlight.openflow.protocol.action.OFActionSetField) OFInstructionMeter(org.projectfloodlight.openflow.protocol.instruction.OFInstructionMeter) OFInstruction(org.projectfloodlight.openflow.protocol.instruction.OFInstruction) FlowApplyActions(org.openkilda.messaging.info.rule.FlowApplyActions) OFInstructionType(org.projectfloodlight.openflow.protocol.OFInstructionType)

Example 2 with OFInstruction

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();
}
Also used : OFInstruction(org.projectfloodlight.openflow.protocol.instruction.OFInstruction) FlowEndpoint(org.openkilda.model.FlowEndpoint) OFPort(org.projectfloodlight.openflow.types.OFPort) OFAction(org.projectfloodlight.openflow.protocol.action.OFAction) ArrayList(java.util.ArrayList)

Example 3 with OFInstruction

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;
}
Also used : OFInstructionApplyActions(org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions) OFInstruction(org.projectfloodlight.openflow.protocol.instruction.OFInstruction) OFInstructionWriteActions(org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteActions) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with OFInstruction

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);
    }
}
Also used : OFInstruction(org.projectfloodlight.openflow.protocol.instruction.OFInstruction) OFInstructionGotoTable(org.projectfloodlight.openflow.protocol.instruction.OFInstructionGotoTable)

Example 5 with OFInstruction

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));
}
Also used : OfMetadata(org.openkilda.rulemanager.OfMetadata) Action(org.openkilda.rulemanager.action.Action) PushVxlanAction(org.openkilda.rulemanager.action.PushVxlanAction) PopVxlanAction(org.openkilda.rulemanager.action.PopVxlanAction) PushVlanAction(org.openkilda.rulemanager.action.PushVlanAction) PopVlanAction(org.openkilda.rulemanager.action.PopVlanAction) SwapFieldAction(org.openkilda.rulemanager.action.SwapFieldAction) OFAction(org.projectfloodlight.openflow.protocol.action.OFAction) GroupAction(org.openkilda.rulemanager.action.GroupAction) CopyFieldAction(org.openkilda.rulemanager.action.noviflow.CopyFieldAction) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) SetFieldAction(org.openkilda.rulemanager.action.SetFieldAction) OFInstruction(org.projectfloodlight.openflow.protocol.instruction.OFInstruction) OFFactoryVer13(org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) ArrayList(java.util.ArrayList) OFAction(org.projectfloodlight.openflow.protocol.action.OFAction) Instructions(org.openkilda.rulemanager.Instructions) MeterId(org.openkilda.model.MeterId) Test(org.junit.Test)

Aggregations

OFInstruction (org.projectfloodlight.openflow.protocol.instruction.OFInstruction)14 OFAction (org.projectfloodlight.openflow.protocol.action.OFAction)9 OFInstructionApplyActions (org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions)6 ArrayList (java.util.ArrayList)5 OFFactory (org.projectfloodlight.openflow.protocol.OFFactory)5 MeterId (org.openkilda.model.MeterId)4 OfMetadata (org.openkilda.rulemanager.OfMetadata)3 OFInstructionMeter (org.projectfloodlight.openflow.protocol.instruction.OFInstructionMeter)3 Match (org.projectfloodlight.openflow.protocol.match.Match)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 IOFSwitch (net.floodlightcontroller.core.IOFSwitch)2 Test (org.junit.Test)2 RoutingMetadata (org.openkilda.floodlight.utils.metadata.RoutingMetadata)2 FlowInstructions (org.openkilda.messaging.info.rule.FlowInstructions)2 Instructions (org.openkilda.rulemanager.Instructions)2 Action (org.openkilda.rulemanager.action.Action)2 GroupAction (org.openkilda.rulemanager.action.GroupAction)2 PopVlanAction (org.openkilda.rulemanager.action.PopVlanAction)2