Search in sources :

Example 1 with OFInstructionType

use of org.projectfloodlight.openflow.protocol.OFInstructionType 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 OFInstructionType

use of org.projectfloodlight.openflow.protocol.OFInstructionType in project open-kilda by telstra.

the class FlowsResource method buildFlowInstructions.

private Map<String, Object> buildFlowInstructions(final List<OFInstruction> instructions) {
    Map<String, Object> data = new HashMap<>();
    for (OFInstruction instruction : instructions) {
        Map<String, Object> iData = new HashMap<>();
        OFInstructionType instructionType = instruction.getType();
        switch(instructionType) {
            case APPLY_ACTIONS:
                for (OFAction action : ((OFInstructionApplyActions) instruction).getActions()) {
                    OFActionType actionType = action.getType();
                    switch(actionType) {
                        case // ver1.5
                        METER:
                            iData.put(actionType.toString(), ((OFActionMeter) action).getMeterId());
                            break;
                        case OUTPUT:
                            Optional.ofNullable(((OFActionOutput) action).getPort()).ifPresent(port -> iData.put(actionType.toString(), port.toString()));
                            break;
                        case POP_VLAN:
                            iData.put(actionType.toString(), null);
                            break;
                        case PUSH_VLAN:
                            Optional.ofNullable(((OFActionPushVlan) action).getEthertype()).ifPresent(ethType -> iData.put(actionType.toString(), ethType.toString()));
                            break;
                        case SET_FIELD:
                            OFOxm<?> setFieldAction = ((OFActionSetField) action).getField();
                            iData.put(actionType.toString(), String.format("%s->%s", setFieldAction.getValue(), setFieldAction.getMatchField().getName()));
                            break;
                        default:
                            iData.put(actionType.toString(), "could not parse");
                            break;
                    }
                }
                break;
            case METER:
                OFInstructionMeter action = ((OFInstructionMeter) instruction);
                iData.put(instructionType.toString(), action.getMeterId());
                break;
            default:
                iData.put(instructionType.toString(), "could not parse");
                break;
        }
        data.put(instruction.getType().name(), iData);
    }
    return data;
}
Also used : OFActionOutput(org.projectfloodlight.openflow.protocol.action.OFActionOutput) OFInstructionMeter(org.projectfloodlight.openflow.protocol.instruction.OFInstructionMeter) HashMap(java.util.HashMap) OFAction(org.projectfloodlight.openflow.protocol.action.OFAction) OFActionType(org.projectfloodlight.openflow.protocol.OFActionType) OFActionPushVlan(org.projectfloodlight.openflow.protocol.action.OFActionPushVlan) OFInstructionType(org.projectfloodlight.openflow.protocol.OFInstructionType) OFInstructionApplyActions(org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions) OFInstruction(org.projectfloodlight.openflow.protocol.instruction.OFInstruction) OFActionSetField(org.projectfloodlight.openflow.protocol.action.OFActionSetField)

Aggregations

OFActionType (org.projectfloodlight.openflow.protocol.OFActionType)2 OFInstructionType (org.projectfloodlight.openflow.protocol.OFInstructionType)2 OFAction (org.projectfloodlight.openflow.protocol.action.OFAction)2 OFActionOutput (org.projectfloodlight.openflow.protocol.action.OFActionOutput)2 OFActionPushVlan (org.projectfloodlight.openflow.protocol.action.OFActionPushVlan)2 OFActionSetField (org.projectfloodlight.openflow.protocol.action.OFActionSetField)2 OFInstruction (org.projectfloodlight.openflow.protocol.instruction.OFInstruction)2 OFInstructionApplyActions (org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions)2 OFInstructionMeter (org.projectfloodlight.openflow.protocol.instruction.OFInstructionMeter)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 FlowApplyActions (org.openkilda.messaging.info.rule.FlowApplyActions)1 FlowEntry (org.openkilda.messaging.info.rule.FlowEntry)1 FlowInstructions (org.openkilda.messaging.info.rule.FlowInstructions)1 FlowMatchField (org.openkilda.messaging.info.rule.FlowMatchField)1 FlowSetFieldAction (org.openkilda.messaging.info.rule.FlowSetFieldAction)1