Search in sources :

Example 6 with OFAction

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

OFAction (org.projectfloodlight.openflow.protocol.action.OFAction)6 OFInstructionApplyActions (org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions)6 ArrayList (java.util.ArrayList)5 OFFlowMod (org.projectfloodlight.openflow.protocol.OFFlowMod)5 Match (org.projectfloodlight.openflow.protocol.match.Match)5 OFVlanVidMatch (org.projectfloodlight.openflow.types.OFVlanVidMatch)5 OFInstructionMeter (org.projectfloodlight.openflow.protocol.instruction.OFInstructionMeter)3 HashMap (java.util.HashMap)1 OFActionType (org.projectfloodlight.openflow.protocol.OFActionType)1 OFInstructionType (org.projectfloodlight.openflow.protocol.OFInstructionType)1 OFActionOutput (org.projectfloodlight.openflow.protocol.action.OFActionOutput)1 OFActionPushVlan (org.projectfloodlight.openflow.protocol.action.OFActionPushVlan)1 OFActionSetField (org.projectfloodlight.openflow.protocol.action.OFActionSetField)1 OFInstruction (org.projectfloodlight.openflow.protocol.instruction.OFInstruction)1