Search in sources :

Example 1 with OFInstructionMeter

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

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

the class SwitchManager method installOneSwitchFlow.

/**
 * {@inheritDoc}
 */
@Override
public long installOneSwitchFlow(final DatapathId dpid, final String flowId, final Long cookie, final int inputPort, final int outputPort, final int inputVlanId, final int outputVlanId, final OutputVlanType outputVlanType, final long meterId) throws SwitchOperationException {
    // TODO: As per other locations, how different is this to IngressFlow? Why separate code path?
    // As with any set of tests, the more we test the same code path, the better.
    // Based on brief glance, this looks 90% the same as IngressFlow.
    List<OFAction> actionList = new ArrayList<>();
    IOFSwitch sw = lookupSwitch(dpid);
    // build match by input port and transit vlan id
    Match match = matchFlow(sw, inputPort, inputVlanId);
    // build meter instruction
    OFInstructionMeter meter = null;
    if (meterId != 0L && !OVS_MANUFACTURER.equals(sw.getSwitchDescription().getManufacturerDescription())) {
        if (sw.getOFFactory().getVersion().compareTo(OF_12) <= 0) {
            actionList.add(legacyMeterAction(sw, meterId));
        } else if (sw.getOFFactory().getVersion().compareTo(OF_15) == 0) {
            actionList.add(sw.getOFFactory().actions().buildMeter().setMeterId(meterId).build());
        } else /* OF_13, OF_14 */
        {
            meter = sw.getOFFactory().instructions().buildMeter().setMeterId(meterId).build();
        }
    }
    // output action based on encap scheme
    actionList.addAll(pushSchemeOutputVlanTypeToOFActionList(sw, outputVlanId, outputVlanType));
    // transmit packet from outgoing port
    actionList.add(actionSetOutputPort(sw, outputPort));
    // build instruction with action list
    OFInstructionApplyActions actions = buildInstructionApplyActions(sw, actionList);
    // build FLOW_MOD command with meter
    OFFlowMod flowMod = buildFlowMod(sw, match, meter, actions, cookie & FLOW_COOKIE_MASK, FlowModUtils.PRIORITY_VERY_HIGH);
    pushFlow(sw, flowId, flowMod);
    return flowMod.getXid();
}
Also used : OFInstructionApplyActions(org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions) OFInstructionMeter(org.projectfloodlight.openflow.protocol.instruction.OFInstructionMeter) OFAction(org.projectfloodlight.openflow.protocol.action.OFAction) ArrayList(java.util.ArrayList) OFFlowMod(org.projectfloodlight.openflow.protocol.OFFlowMod) Match(org.projectfloodlight.openflow.protocol.match.Match) OFVlanVidMatch(org.projectfloodlight.openflow.types.OFVlanVidMatch)

Example 3 with OFInstructionMeter

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

the class SwitchManager method installIngressFlow.

/**
 * {@inheritDoc}
 */
@Override
public long installIngressFlow(final DatapathId dpid, final String flowId, final Long cookie, final int inputPort, final int outputPort, final int inputVlanId, final int transitVlanId, final OutputVlanType outputVlanType, final long meterId) throws SwitchOperationException {
    List<OFAction> actionList = new ArrayList<>();
    IOFSwitch sw = lookupSwitch(dpid);
    // build match by input port and input vlan id
    Match match = matchFlow(sw, inputPort, inputVlanId);
    // build meter instruction
    OFInstructionMeter meter = null;
    if (meterId != 0L && !OVS_MANUFACTURER.equals(sw.getSwitchDescription().getManufacturerDescription())) {
        if (sw.getOFFactory().getVersion().compareTo(OF_12) <= 0) {
            actionList.add(legacyMeterAction(sw, meterId));
        } else if (sw.getOFFactory().getVersion().compareTo(OF_15) == 0) {
            actionList.add(sw.getOFFactory().actions().buildMeter().setMeterId(meterId).build());
        } else /* OF_13, OF_14 */
        {
            meter = sw.getOFFactory().instructions().buildMeter().setMeterId(meterId).build();
        }
    }
    // output action based on encap scheme
    actionList.addAll(inputVlanTypeToOFActionList(sw, transitVlanId, outputVlanType));
    // transmit packet from outgoing port
    actionList.add(actionSetOutputPort(sw, outputPort));
    // build instruction with action list
    OFInstructionApplyActions actions = buildInstructionApplyActions(sw, actionList);
    // build FLOW_MOD command with meter
    OFFlowMod flowMod = buildFlowMod(sw, match, meter, actions, cookie & FLOW_COOKIE_MASK, FlowModUtils.PRIORITY_VERY_HIGH);
    return pushFlow(sw, "--InstallIngressFlow--", flowMod);
}
Also used : OFInstructionApplyActions(org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions) OFInstructionMeter(org.projectfloodlight.openflow.protocol.instruction.OFInstructionMeter) OFAction(org.projectfloodlight.openflow.protocol.action.OFAction) ArrayList(java.util.ArrayList) OFFlowMod(org.projectfloodlight.openflow.protocol.OFFlowMod) Match(org.projectfloodlight.openflow.protocol.match.Match) OFVlanVidMatch(org.projectfloodlight.openflow.types.OFVlanVidMatch)

Example 4 with OFInstructionMeter

use of org.projectfloodlight.openflow.protocol.instruction.OFInstructionMeter 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)4 OFInstructionApplyActions (org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions)4 OFInstructionMeter (org.projectfloodlight.openflow.protocol.instruction.OFInstructionMeter)4 Match (org.projectfloodlight.openflow.protocol.match.Match)3 ArrayList (java.util.ArrayList)2 OFActionType (org.projectfloodlight.openflow.protocol.OFActionType)2 OFFlowMod (org.projectfloodlight.openflow.protocol.OFFlowMod)2 OFInstructionType (org.projectfloodlight.openflow.protocol.OFInstructionType)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 OFVlanVidMatch (org.projectfloodlight.openflow.types.OFVlanVidMatch)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