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();
}
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();
}
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);
}
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;
}
Aggregations