Search in sources :

Example 6 with OFInstruction

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

the class IngressInstallFlowModFactory method makeForwardMessageInstructions.

protected List<OFInstruction> makeForwardMessageInstructions(EffectiveIds effectiveIds, List<Integer> vlanStack) {
    List<OFAction> applyActions = new ArrayList<>();
    List<OFInstruction> instructions = new ArrayList<>();
    MeterId effectiveMeterId = effectiveIds.getMeterId();
    if (effectiveMeterId != null) {
        OfAdapter.INSTANCE.makeMeterCall(of, effectiveMeterId, applyActions, instructions);
    }
    GroupId effectiveGroupId = effectiveIds.getGroupId();
    boolean groupIsPresent = effectiveGroupId != null;
    applyActions.addAll(makeTransformActions(vlanStack, groupIsPresent));
    if (groupIsPresent) {
        applyActions.add(makeGroupAction(effectiveGroupId));
    } else {
        applyActions.add(makeOutputAction());
    }
    instructions.add(of.instructions().applyActions(applyActions));
    if (command.getMetadata().isMultiTable() && effectiveGroupId == null) {
        instructions.add(of.instructions().gotoTable(TableId.of(SwitchManager.POST_INGRESS_TABLE_ID)));
        instructions.addAll(makeMetadataInstructions());
    }
    return instructions;
}
Also used : OFInstruction(org.projectfloodlight.openflow.protocol.instruction.OFInstruction) OFAction(org.projectfloodlight.openflow.protocol.action.OFAction) ArrayList(java.util.ArrayList) MeterId(org.openkilda.model.MeterId) GroupId(org.openkilda.model.GroupId)

Example 7 with OFInstruction

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

the class Server42FlowRttInputFlowGenerator method generateFlowMod.

/**
 * Generated OFFlowMod for Server 42 Flow RTT input rule.
 */
public static Optional<OFFlowMod> generateFlowMod(OFFactory ofFactory, Set<SwitchFeature> features, int udpOffset, int customerPort, int server42Port, MacAddress server42macAddress) {
    Match match = buildMatch(ofFactory, server42Port, customerPort + udpOffset, server42macAddress);
    List<OFAction> actions = Lists.newArrayList(actionSetUdpSrcAction(ofFactory, TransportPort.of(SERVER_42_FLOW_RTT_FORWARD_UDP_PORT)), actionSetUdpDstAction(ofFactory, TransportPort.of(SERVER_42_FLOW_RTT_FORWARD_UDP_PORT)));
    if (features.contains(NOVIFLOW_COPY_FIELD)) {
        actions.add(buildServer42CopyFirstTimestamp(ofFactory));
    }
    List<OFInstruction> instructions = ImmutableList.of(buildInstructionApplyActions(ofFactory, actions), instructionWriteMetadata(ofFactory, customerPort, features), instructionGoToTable(ofFactory, TableId.of(PRE_INGRESS_TABLE_ID)));
    return Optional.of(prepareFlowModBuilder(ofFactory, encodeServer42FlowRttInput(customerPort), SERVER_42_FLOW_RTT_INPUT_PRIORITY, INPUT_TABLE_ID).setMatch(match).setInstructions(instructions).build());
}
Also used : OFInstruction(org.projectfloodlight.openflow.protocol.instruction.OFInstruction) OFAction(org.projectfloodlight.openflow.protocol.action.OFAction) Match(org.projectfloodlight.openflow.protocol.match.Match)

Example 8 with OFInstruction

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

the class SwitchManager method installServer42OuterVlanMatchSharedFlow.

@Override
public void installServer42OuterVlanMatchSharedFlow(DatapathId dpid, FlowSharedSegmentCookie cookie) throws SwitchOperationException {
    IOFSwitch sw = lookupSwitch(dpid);
    OFFactory of = sw.getOFFactory();
    RoutingMetadata metadata = RoutingMetadata.builder().outerVlanId(cookie.getVlanId()).build(featureDetectorService.detectSwitch(sw));
    ImmutableList<OFInstruction> instructions = ImmutableList.of(of.instructions().applyActions(ImmutableList.of(of.actions().popVlan())), of.instructions().writeMetadata(metadata.getValue(), metadata.getMask()), of.instructions().gotoTable(TableId.of(SwitchManager.INGRESS_TABLE_ID)));
    OFFlowMod flow = prepareFlowModBuilder(of, cookie.getValue(), FLOW_PRIORITY, PRE_INGRESS_TABLE_ID).setCookie(U64.of(cookie.getValue())).setMatch(of.buildMatch().setExact(MatchField.IN_PORT, OFPort.of(cookie.getPortNumber())).setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(cookie.getVlanId())).build()).setInstructions(instructions).build();
    pushFlow(sw, "--server 42 shared rule--", flow);
}
Also used : IOFSwitch(net.floodlightcontroller.core.IOFSwitch) OFInstruction(org.projectfloodlight.openflow.protocol.instruction.OFInstruction) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) RoutingMetadata(org.openkilda.floodlight.utils.metadata.RoutingMetadata) OFFlowMod(org.projectfloodlight.openflow.protocol.OFFlowMod)

Example 9 with OFInstruction

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

the class OfFlowStatsMapper method toFlowInstructions.

/**
 * Convert list of {@link OFInstruction} to {@link FlowInstructions}.
 * @param instructions list of instructions to be converted.
 * @return result of transformation {@link FlowInstructions}.
 */
public FlowInstructions toFlowInstructions(final List<OFInstruction> instructions) {
    FlowInstructions.FlowInstructionsBuilder flowInstructions = FlowInstructions.builder();
    for (OFInstruction entry : instructions) {
        if (entry instanceof OFInstructionApplyActions) {
            List<OFAction> actions = ((OFInstructionApplyActions) entry).getActions();
            flowInstructions.applyActions(toFlowApplyActions(actions));
        } else if (entry instanceof OFInstructionMeter) {
            flowInstructions.goToMeter(((OFInstructionMeter) entry).getMeterId());
        } else if (entry instanceof OFInstructionGotoTable) {
            flowInstructions.goToTable(((OFInstructionGotoTable) entry).getTableId().getValue());
        }
    // add handling for other instructions here
    }
    return flowInstructions.build();
}
Also used : OFInstructionApplyActions(org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions) OFInstructionMeter(org.projectfloodlight.openflow.protocol.instruction.OFInstructionMeter) OFInstruction(org.projectfloodlight.openflow.protocol.instruction.OFInstruction) OFInstructionGotoTable(org.projectfloodlight.openflow.protocol.instruction.OFInstructionGotoTable) FlowInstructions(org.openkilda.messaging.info.rule.FlowInstructions) OFAction(org.projectfloodlight.openflow.protocol.action.OFAction)

Example 10 with OFInstruction

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

the class OfInstructionsConverter method convertToRuleManagerInstructions.

/**
 * Convert instructions.
 */
public Instructions convertToRuleManagerInstructions(List<OFInstruction> ofInstructions) {
    InstructionsBuilder builder = Instructions.builder();
    for (OFInstruction ofInstruction : ofInstructions) {
        if (ofInstruction instanceof OFInstructionApplyActions) {
            List<OFAction> ofActions = ((OFInstructionApplyActions) ofInstruction).getActions();
            List<Action> actions = ofActions.stream().map(this::convertToRuleManagerAction).collect(Collectors.toList());
            builder.applyActions(actions);
        } else if (ofInstruction instanceof OFInstructionWriteActions) {
            List<OFAction> ofActions = ((OFInstructionWriteActions) ofInstruction).getActions();
            Set<Action> actions = ofActions.stream().map(this::convertToRuleManagerAction).collect(Collectors.toSet());
            builder.writeActions(actions);
        } else if (ofInstruction instanceof OFInstructionMeter) {
            final long meterId = ((OFInstructionMeter) ofInstruction).getMeterId();
            builder.goToMeter(new MeterId(meterId));
        } else if (ofInstruction instanceof OFInstructionGotoTable) {
            final short tableId = ((OFInstructionGotoTable) ofInstruction).getTableId().getValue();
            builder.goToTable(OfTable.fromInt(tableId));
        } else if (ofInstruction instanceof OFInstructionWriteMetadata) {
            final long metadata = ((OFInstructionWriteMetadata) ofInstruction).getMetadata().getValue();
            final long metadataMask = ((OFInstructionWriteMetadata) ofInstruction).getMetadataMask().getValue();
            builder.writeMetadata(new OfMetadata(metadata, metadataMask));
        }
    }
    return builder.build();
}
Also used : OFInstructionMeter(org.projectfloodlight.openflow.protocol.instruction.OFInstructionMeter) MeterAction(org.openkilda.rulemanager.action.MeterAction) 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) SetFieldAction(org.openkilda.rulemanager.action.SetFieldAction) 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) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) Set(java.util.Set) OFInstructionGotoTable(org.projectfloodlight.openflow.protocol.instruction.OFInstructionGotoTable) OFAction(org.projectfloodlight.openflow.protocol.action.OFAction) OFInstructionWriteMetadata(org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteMetadata) InstructionsBuilder(org.openkilda.rulemanager.Instructions.InstructionsBuilder) MeterId(org.openkilda.model.MeterId) OFInstructionApplyActions(org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions) OfMetadata(org.openkilda.rulemanager.OfMetadata) OFInstruction(org.projectfloodlight.openflow.protocol.instruction.OFInstruction) List(java.util.List) ArrayList(java.util.ArrayList) OFInstructionWriteActions(org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteActions)

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