Search in sources :

Example 1 with OFActionSetField

use of org.projectfloodlight.openflow.protocol.action.OFActionSetField in project open-kilda by telstra.

the class OfInstructionsConverter method convertToRuleManagerAction.

/**
 * Converts action.
 */
public Action convertToRuleManagerAction(OFAction action) {
    switch(action.getType()) {
        case PUSH_VLAN:
            return new PushVlanAction();
        case POP_VLAN:
            return new PopVlanAction();
        case METER:
            OFActionMeter meterAction = (OFActionMeter) action;
            MeterId meterId = new MeterId(meterAction.getMeterId());
            return new MeterAction(meterId);
        case GROUP:
            OFActionGroup groupAction = (OFActionGroup) action;
            GroupId groupId = new GroupId(groupAction.getGroup().getGroupNumber());
            return new GroupAction(groupId);
        case OUTPUT:
            OFActionOutput outputAction = (OFActionOutput) action;
            PortNumber portNumber = convertPort(outputAction.getPort());
            return new PortOutAction(portNumber);
        case EXPERIMENTER:
            if (action instanceof OFActionNoviflowPushVxlanTunnel) {
                OFActionNoviflowPushVxlanTunnel pushNoviVxlan = (OFActionNoviflowPushVxlanTunnel) action;
                return PushVxlanAction.builder().type(ActionType.PUSH_VXLAN_NOVIFLOW).vni((int) pushNoviVxlan.getVni()).srcMacAddress(convertMac(pushNoviVxlan.getEthSrc())).dstMacAddress(convertMac(pushNoviVxlan.getEthDst())).srcIpv4Address(convertIPv4Address(pushNoviVxlan.getIpv4Src())).dstIpv4Address(convertIPv4Address(pushNoviVxlan.getIpv4Dst())).udpSrc(pushNoviVxlan.getUdpSrc()).build();
            } else if (action instanceof OFActionKildaPushVxlanField) {
                OFActionKildaPushVxlanField pushKildaVxlan = (OFActionKildaPushVxlanField) action;
                return PushVxlanAction.builder().type(ActionType.PUSH_VXLAN_OVS).vni((int) pushKildaVxlan.getVni()).srcMacAddress(convertMac(pushKildaVxlan.getEthSrc())).dstMacAddress(convertMac(pushKildaVxlan.getEthDst())).srcIpv4Address(convertIPv4Address(pushKildaVxlan.getIpv4Src())).dstIpv4Address(convertIPv4Address(pushKildaVxlan.getIpv4Dst())).udpSrc(pushKildaVxlan.getUdpSrc()).build();
            } else if (action instanceof OFActionNoviflowCopyField) {
                OFActionNoviflowCopyField copyField = (OFActionNoviflowCopyField) action;
                return CopyFieldAction.builder().numberOfBits(copyField.getNBits()).srcOffset(copyField.getSrcOffset()).dstOffset(copyField.getDstOffset()).oxmSrcHeader(convertOxmHeader(copyField.getOxmSrcHeader())).oxmDstHeader(convertOxmHeader(copyField.getOxmDstHeader())).build();
            } else if (action instanceof OFActionNoviflowSwapField) {
                OFActionNoviflowSwapField swapField = (OFActionNoviflowSwapField) action;
                return SwapFieldAction.builder().type(ActionType.NOVI_SWAP_FIELD).numberOfBits(swapField.getNBits()).srcOffset(swapField.getSrcOffset()).dstOffset(swapField.getDstOffset()).oxmSrcHeader(convertOxmHeader(swapField.getOxmSrcHeader())).oxmDstHeader(convertOxmHeader(swapField.getOxmDstHeader())).build();
            } else if (action instanceof OFActionKildaSwapField) {
                OFActionKildaSwapField swapField = (OFActionKildaSwapField) action;
                return SwapFieldAction.builder().type(ActionType.KILDA_SWAP_FIELD).numberOfBits(swapField.getNBits()).srcOffset(swapField.getSrcOffset()).dstOffset(swapField.getDstOffset()).oxmSrcHeader(convertOxmHeader(swapField.getOxmSrcHeader())).oxmDstHeader(convertOxmHeader(swapField.getOxmDstHeader())).build();
            } else if (action instanceof OFActionNoviflowPopVxlanTunnel) {
                return new PopVxlanAction(ActionType.POP_VXLAN_NOVIFLOW);
            } else if (action instanceof OFActionKildaPopVxlanField) {
                return new PopVxlanAction(ActionType.POP_VXLAN_OVS);
            } else {
                throw new IllegalStateException(format("Unknown experimenter action %s", action.getType()));
            }
        case SET_FIELD:
            OFActionSetField setFieldAction = (OFActionSetField) action;
            return convertOxm(setFieldAction.getField());
        case SET_VLAN_VID:
            OFActionSetVlanVid setVlanVid = (OFActionSetVlanVid) action;
            return SetFieldAction.builder().field(Field.VLAN_VID).value(setVlanVid.getVlanVid().getVlan()).build();
        default:
            throw new IllegalStateException(format("Unknown action type %s", action.getType()));
    }
}
Also used : OFActionOutput(org.projectfloodlight.openflow.protocol.action.OFActionOutput) OFActionNoviflowPushVxlanTunnel(org.projectfloodlight.openflow.protocol.action.OFActionNoviflowPushVxlanTunnel) OFActionNoviflowPopVxlanTunnel(org.projectfloodlight.openflow.protocol.action.OFActionNoviflowPopVxlanTunnel) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) MeterAction(org.openkilda.rulemanager.action.MeterAction) OFActionNoviflowCopyField(org.projectfloodlight.openflow.protocol.action.OFActionNoviflowCopyField) OFActionGroup(org.projectfloodlight.openflow.protocol.action.OFActionGroup) OFActionNoviflowSwapField(org.projectfloodlight.openflow.protocol.action.OFActionNoviflowSwapField) PopVlanAction(org.openkilda.rulemanager.action.PopVlanAction) MeterId(org.openkilda.model.MeterId) GroupId(org.openkilda.model.GroupId) GroupAction(org.openkilda.rulemanager.action.GroupAction) OFActionMeter(org.projectfloodlight.openflow.protocol.action.OFActionMeter) OFActionSetVlanVid(org.projectfloodlight.openflow.protocol.action.OFActionSetVlanVid) OFActionKildaPushVxlanField(org.projectfloodlight.openflow.protocol.action.OFActionKildaPushVxlanField) OFActionKildaPopVxlanField(org.projectfloodlight.openflow.protocol.action.OFActionKildaPopVxlanField) PushVlanAction(org.openkilda.rulemanager.action.PushVlanAction) PopVxlanAction(org.openkilda.rulemanager.action.PopVxlanAction) OFActionSetField(org.projectfloodlight.openflow.protocol.action.OFActionSetField) PortNumber(org.openkilda.rulemanager.ProtoConstants.PortNumber) OFActionKildaSwapField(org.projectfloodlight.openflow.protocol.action.OFActionKildaSwapField)

Example 2 with OFActionSetField

use of org.projectfloodlight.openflow.protocol.action.OFActionSetField in project open-kilda by telstra.

the class SwitchManagerTest method mockGetGroupsRequest.

private void mockGetGroupsRequest(List<Integer> groupIds) throws Exception {
    List<OFGroupDescStatsEntry> meterConfigs = new ArrayList<>(groupIds.size());
    for (Integer groupId : groupIds) {
        OFBucket firstBucket = mock(OFBucket.class);
        OFBucket secondBucket = mock(OFBucket.class);
        OFActionSetField setDestMacAction = ofFactory.actions().buildSetField().setField(ofFactory.oxms().buildEthDst().setValue(convertDpIdToMac(dpid)).build()).build();
        OFActionOutput sendToControllerAction = ofFactory.actions().output(OFPort.CONTROLLER, 0xFFFFFFFF);
        TransportPort udpPort = TransportPort.of(LATENCY_PACKET_UDP_PORT);
        OFActionSetField setUdpDstAction = ofFactory.actions().setField(ofFactory.oxms().udpDst(udpPort));
        OFActionOutput sendInPortAction = ofFactory.actions().output(OFPort.IN_PORT, 0xFFFFFFFF);
        expect(firstBucket.getActions()).andStubReturn(Lists.newArrayList(setDestMacAction, sendToControllerAction));
        expect(secondBucket.getActions()).andStubReturn(Lists.newArrayList(setUdpDstAction, sendInPortAction));
        OFGroupDescStatsEntry groupEntry = mock(OFGroupDescStatsEntry.class);
        expect(groupEntry.getGroup()).andStubReturn(OFGroup.of(groupId));
        expect(groupEntry.getBuckets()).andStubReturn(Lists.newArrayList(firstBucket, secondBucket));
        replay(firstBucket, secondBucket, groupEntry);
        meterConfigs.add(groupEntry);
    }
    OFGroupDescStatsReply statsReply = mock(OFGroupDescStatsReply.class);
    expect(statsReply.getEntries()).andStubReturn(meterConfigs);
    ListenableFuture<List<OFGroupDescStatsReply>> ofStatsFuture = mock(ListenableFuture.class);
    expect(ofStatsFuture.get(anyLong(), anyObject())).andStubReturn(Collections.singletonList(statsReply));
    expect(iofSwitch.writeStatsRequest(isA(OFGroupDescStatsRequest.class))).andStubReturn(ofStatsFuture);
    replay(statsReply, ofStatsFuture);
}
Also used : OFBucket(org.projectfloodlight.openflow.protocol.OFBucket) OFActionOutput(org.projectfloodlight.openflow.protocol.action.OFActionOutput) OFGroupDescStatsEntry(org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry) ArrayList(java.util.ArrayList) OFGroupDescStatsReply(org.projectfloodlight.openflow.protocol.OFGroupDescStatsReply) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) OFActionSetField(org.projectfloodlight.openflow.protocol.action.OFActionSetField) TransportPort(org.projectfloodlight.openflow.types.TransportPort) OFGroupDescStatsRequest(org.projectfloodlight.openflow.protocol.OFGroupDescStatsRequest)

Example 3 with OFActionSetField

use of org.projectfloodlight.openflow.protocol.action.OFActionSetField in project open-kilda by telstra.

the class IngressServer42FlowInstallCommandTest method assertSetField.

private void assertSetField(OFAction action, Class<? extends OFOxm> type, Object value) {
    assertEquals(OFActionType.SET_FIELD, action.getType());
    OFActionSetField setFiledAction = (OFActionSetField) action;
    assertTrue(type.isInstance(setFiledAction.getField()));
    assertEquals(value, setFiledAction.getField().getValue());
}
Also used : OFActionSetField(org.projectfloodlight.openflow.protocol.action.OFActionSetField)

Example 4 with OFActionSetField

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

Example 5 with OFActionSetField

use of org.projectfloodlight.openflow.protocol.action.OFActionSetField in project open-kilda by telstra.

the class IngressFlowLoopSegmentInstallCommandTest method assertSetField.

private void assertSetField(OFAction action, Class<? extends OFOxm> type, Object value) {
    assertEquals(OFActionType.SET_FIELD, action.getType());
    OFActionSetField setFiledAction = (OFActionSetField) action;
    assertTrue(type.isInstance(setFiledAction.getField()));
    assertEquals(value, setFiledAction.getField().getValue());
}
Also used : OFActionSetField(org.projectfloodlight.openflow.protocol.action.OFActionSetField)

Aggregations

OFActionSetField (org.projectfloodlight.openflow.protocol.action.OFActionSetField)5 OFActionOutput (org.projectfloodlight.openflow.protocol.action.OFActionOutput)3 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 Collections.singletonList (java.util.Collections.singletonList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Collectors.toList (java.util.stream.Collectors.toList)1 GroupId (org.openkilda.model.GroupId)1 MeterId (org.openkilda.model.MeterId)1 PortNumber (org.openkilda.rulemanager.ProtoConstants.PortNumber)1 GroupAction (org.openkilda.rulemanager.action.GroupAction)1 MeterAction (org.openkilda.rulemanager.action.MeterAction)1 PopVlanAction (org.openkilda.rulemanager.action.PopVlanAction)1 PopVxlanAction (org.openkilda.rulemanager.action.PopVxlanAction)1 PortOutAction (org.openkilda.rulemanager.action.PortOutAction)1 PushVlanAction (org.openkilda.rulemanager.action.PushVlanAction)1 OFActionType (org.projectfloodlight.openflow.protocol.OFActionType)1 OFBucket (org.projectfloodlight.openflow.protocol.OFBucket)1 OFGroupDescStatsEntry (org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry)1