Search in sources :

Example 11 with OFInstruction

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

the class SwitchManager method installOuterVlanMatchSharedFlow.

@Override
public void installOuterVlanMatchSharedFlow(SwitchId switchId, String flowId, FlowSharedSegmentCookie cookie) throws SwitchOperationException {
    IOFSwitch sw = lookupSwitch(DatapathId.of(switchId.toLong()));
    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).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, flowId, 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 12 with OFInstruction

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

the class UnicastVerificationVxlanRuleGenerator method buildUnicastVerificationRuleVxlan.

private OFFlowMod buildUnicastVerificationRuleVxlan(IOFSwitch sw, Set<SwitchFeature> features, long cookie, OFInstructionMeter meter, ArrayList<OFAction> actionList) {
    OFFactory ofFactory = sw.getOFFactory();
    if (features.contains(NOVIFLOW_PUSH_POP_VXLAN)) {
        actionList.add(ofFactory.actions().noviflowPopVxlanTunnel());
    } else {
        actionList.add(ofFactory.actions().kildaPopVxlanField());
    }
    actionList.add(actionSendToController(sw.getOFFactory()));
    MacAddress macAddress = convertDpIdToMac(sw.getId());
    actionList.add(actionSetDstMac(sw.getOFFactory(), macAddress));
    List<OFInstruction> instructions = new ArrayList<>(2);
    if (meter != null) {
        instructions.add(meter);
    }
    instructions.add(ofFactory.instructions().applyActions(actionList));
    MacAddress srcMac = MacAddress.of(kildaCore.getConfig().getFlowPingMagicSrcMacAddress());
    Match.Builder builder = sw.getOFFactory().buildMatch();
    builder.setMasked(MatchField.ETH_SRC, srcMac, MacAddress.NO_MASK);
    builder.setMasked(MatchField.ETH_DST, macAddress, MacAddress.NO_MASK);
    builder.setExact(MatchField.ETH_TYPE, EthType.IPv4);
    builder.setExact(MatchField.IP_PROTO, IpProtocol.UDP);
    builder.setExact(MatchField.UDP_SRC, TransportPort.of(STUB_VXLAN_UDP_SRC));
    return prepareFlowModBuilder(ofFactory, cookie, VERIFICATION_RULE_VXLAN_PRIORITY, INPUT_TABLE_ID).setInstructions(instructions).setMatch(builder.build()).build();
}
Also used : OFInstruction(org.projectfloodlight.openflow.protocol.instruction.OFInstruction) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) ArrayList(java.util.ArrayList) MacAddress(org.projectfloodlight.openflow.types.MacAddress) Match(org.projectfloodlight.openflow.protocol.match.Match)

Example 13 with OFInstruction

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

the class OfInstructionsConverterTest method convertInstructionsTest.

@Test
public void convertInstructionsTest() {
    OFFactory factory = new OFFactoryVer13();
    Instructions instructions = Instructions.builder().goToTable(OfTable.PRE_INGRESS).goToMeter(new MeterId(2)).writeMetadata(new OfMetadata(123, 234)).applyActions(buildActions()).build();
    List<OFInstruction> actual = OfInstructionsConverter.INSTANCE.convertInstructions(instructions, factory);
    assertEquals(4, actual.size());
    assertTrue(actual.contains(factory.instructions().gotoTable(TableId.of(1))));
    assertTrue(actual.contains(factory.instructions().buildMeter().setMeterId(2).build()));
    assertTrue(actual.contains(factory.instructions().buildWriteMetadata().setMetadata(U64.of(123)).setMetadataMask(U64.of(234)).build()));
    OFInstructionApplyActions applyActionsInstruction = (OFInstructionApplyActions) actual.get(3);
    assertEquals(12, applyActionsInstruction.getActions().size());
    List<OFAction> expectedActions = buildActions(factory);
    assertTrue(applyActionsInstruction.getActions().containsAll(expectedActions));
}
Also used : OfMetadata(org.openkilda.rulemanager.OfMetadata) OFInstructionApplyActions(org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions) OFInstruction(org.projectfloodlight.openflow.protocol.instruction.OFInstruction) OFFactoryVer13(org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) OFAction(org.projectfloodlight.openflow.protocol.action.OFAction) Instructions(org.openkilda.rulemanager.Instructions) MeterId(org.openkilda.model.MeterId) Test(org.junit.Test)

Example 14 with OFInstruction

use of org.projectfloodlight.openflow.protocol.instruction.OFInstruction 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> instructionData = 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:
                            instructionData.put(actionType.toString(), ((OFActionMeter) action).getMeterId());
                            break;
                        case OUTPUT:
                            Optional.ofNullable(((OFActionOutput) action).getPort()).ifPresent(port -> instructionData.put(actionType.toString(), port.toString()));
                            break;
                        case POP_VLAN:
                            instructionData.put(actionType.toString(), null);
                            break;
                        case PUSH_VLAN:
                            Optional.ofNullable(((OFActionPushVlan) action).getEthertype()).ifPresent(ethType -> instructionData.put(actionType.toString(), ethType.toString()));
                            break;
                        case SET_FIELD:
                            OFOxm<?> setFieldAction = ((OFActionSetField) action).getField();
                            instructionData.put(actionType.toString(), String.format("%s->%s", setFieldAction.getValue(), setFieldAction.getMatchField().getName()));
                            break;
                        default:
                            instructionData.put(actionType.toString(), "could not parse");
                            break;
                    }
                }
                break;
            case METER:
                OFInstructionMeter action = ((OFInstructionMeter) instruction);
                instructionData.put(instructionType.toString(), action.getMeterId());
                break;
            default:
                instructionData.put(instructionType.toString(), "could not parse");
                break;
        }
        data.put(instruction.getType().name(), instructionData);
    }
    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

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