Search in sources :

Example 1 with MeterAction

use of org.openkilda.rulemanager.action.MeterAction in project open-kilda by telstra.

the class ConnectedDevicesRuleGeneratorTest method checkInstructionsOf15.

protected void checkInstructionsOf15(Instructions instructions, MeterId meterId) {
    assertEquals(2, instructions.getApplyActions().size());
    Action first = instructions.getApplyActions().get(0);
    assertTrue(first instanceof PortOutAction);
    PortOutAction portOutAction = (PortOutAction) first;
    assertEquals(SpecialPortType.CONTROLLER, portOutAction.getPortNumber().getPortType());
    Action second = instructions.getApplyActions().get(1);
    assertTrue(second instanceof MeterAction);
    MeterAction meterAction = (MeterAction) second;
    assertEquals(meterId, meterAction.getMeterId());
    assertNull(instructions.getWriteActions());
    assertNull(instructions.getGoToMeter());
    assertNull(instructions.getGoToTable());
}
Also used : MeterAction(org.openkilda.rulemanager.action.MeterAction) Action(org.openkilda.rulemanager.action.Action) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) MeterAction(org.openkilda.rulemanager.action.MeterAction)

Example 2 with MeterAction

use of org.openkilda.rulemanager.action.MeterAction in project open-kilda by telstra.

the class UniCastDiscoveryRuleGeneratorTest method shouldBuildCorrectRuleWithMeterForOf15.

@Test
public void shouldBuildCorrectRuleWithMeterForOf15() {
    sw = buildSwitch("OF_15", Sets.newHashSet(METERS, PKTPS_FLAG));
    List<SpeakerData> commands = generator.generateCommands(sw);
    assertEquals(2, commands.size());
    commands.forEach(c -> assertEquals(sw.getSwitchId(), c.getSwitchId()));
    commands.forEach(c -> assertEquals(sw.getOfVersion(), c.getOfVersion().toString()));
    FlowSpeakerData flowCommandData = getCommand(FlowSpeakerData.class, commands);
    MeterSpeakerData meterCommandData = getCommand(MeterSpeakerData.class, commands);
    assertEquals(1, flowCommandData.getDependsOn().size());
    assertTrue(flowCommandData.getDependsOn().contains(meterCommandData.getUuid()));
    // Check flow command
    checkFlowCommandBaseProperties(flowCommandData);
    Set<FieldMatch> match = flowCommandData.getMatch();
    assertEquals(2, match.size());
    checkMatch(match);
    // Check flow command has correct instructions for OF 1.5
    Instructions instructions = flowCommandData.getInstructions();
    assertEquals(3, instructions.getApplyActions().size());
    Action first = instructions.getApplyActions().get(0);
    assertTrue(first instanceof MeterAction);
    MeterAction meterAction = (MeterAction) first;
    assertEquals(meterCommandData.getMeterId(), meterAction.getMeterId());
    checkPortOutAction(instructions.getApplyActions().get(1));
    checkSetFieldAction(instructions.getApplyActions().get(2));
    assertNull(instructions.getWriteActions());
    assertNull(instructions.getGoToMeter());
    assertNull(instructions.getGoToTable());
    // Check meter command
    checkMeterCommand(meterCommandData);
}
Also used : MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) MeterAction(org.openkilda.rulemanager.action.MeterAction) Action(org.openkilda.rulemanager.action.Action) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) SetFieldAction(org.openkilda.rulemanager.action.SetFieldAction) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) FieldMatch(org.openkilda.rulemanager.match.FieldMatch) MeterAction(org.openkilda.rulemanager.action.MeterAction) Instructions(org.openkilda.rulemanager.Instructions) MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) SpeakerData(org.openkilda.rulemanager.SpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) Test(org.junit.Test)

Example 3 with MeterAction

use of org.openkilda.rulemanager.action.MeterAction in project open-kilda by telstra.

the class ArpPostIngressVxlanRuleGeneratorTest method checkInstructionsOf15.

@Override
protected void checkInstructionsOf15(Instructions instructions, MeterId meterId) {
    assertEquals(3, instructions.getApplyActions().size());
    Action first = instructions.getApplyActions().get(0);
    assertTrue(first instanceof PopVxlanAction);
    PopVxlanAction popVxlanAction = (PopVxlanAction) first;
    assertEquals(ActionType.POP_VXLAN_NOVIFLOW, popVxlanAction.getType());
    Action second = instructions.getApplyActions().get(1);
    assertTrue(second instanceof PortOutAction);
    PortOutAction portOutAction = (PortOutAction) second;
    assertEquals(SpecialPortType.CONTROLLER, portOutAction.getPortNumber().getPortType());
    Action third = instructions.getApplyActions().get(2);
    assertTrue(third instanceof MeterAction);
    MeterAction meterAction = (MeterAction) third;
    assertEquals(meterId, meterAction.getMeterId());
    assertNull(instructions.getWriteActions());
    assertNull(instructions.getGoToMeter());
    assertNull(instructions.getGoToTable());
}
Also used : MeterAction(org.openkilda.rulemanager.action.MeterAction) Action(org.openkilda.rulemanager.action.Action) PopVxlanAction(org.openkilda.rulemanager.action.PopVxlanAction) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) PopVxlanAction(org.openkilda.rulemanager.action.PopVxlanAction) MeterAction(org.openkilda.rulemanager.action.MeterAction)

Example 4 with MeterAction

use of org.openkilda.rulemanager.action.MeterAction 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 5 with MeterAction

use of org.openkilda.rulemanager.action.MeterAction in project open-kilda by telstra.

the class UnicastVerificationVxlanRuleGeneratorTest method shouldBuildCorrectRuleWithMeterForOf15.

@Test
public void shouldBuildCorrectRuleWithMeterForOf15() {
    sw = buildSwitch("OF_15", Sets.newHashSet(NOVIFLOW_PUSH_POP_VXLAN, METERS, PKTPS_FLAG));
    List<SpeakerData> commands = generator.generateCommands(sw);
    assertEquals(2, commands.size());
    commands.forEach(c -> assertEquals(sw.getSwitchId(), c.getSwitchId()));
    commands.forEach(c -> assertEquals(sw.getOfVersion(), c.getOfVersion().toString()));
    FlowSpeakerData flowCommandData = getCommand(FlowSpeakerData.class, commands);
    MeterSpeakerData meterCommandData = getCommand(MeterSpeakerData.class, commands);
    assertEquals(1, flowCommandData.getDependsOn().size());
    assertTrue(flowCommandData.getDependsOn().contains(meterCommandData.getUuid()));
    // Check flow command
    checkFlowCommandBaseProperties(flowCommandData);
    checkMatch(flowCommandData.getMatch());
    // Check flow command has correct instructions for OF 1.5
    Instructions instructions = flowCommandData.getInstructions();
    assertEquals(4, instructions.getApplyActions().size());
    Action first = instructions.getApplyActions().get(0);
    assertTrue(first instanceof PopVxlanAction);
    PopVxlanAction popVxlanAction = (PopVxlanAction) first;
    assertEquals(ActionType.POP_VXLAN_NOVIFLOW, popVxlanAction.getType());
    Action second = instructions.getApplyActions().get(1);
    assertTrue(second instanceof PortOutAction);
    PortOutAction sendToControllerAction = (PortOutAction) second;
    assertEquals(SpecialPortType.CONTROLLER, sendToControllerAction.getPortNumber().getPortType());
    Action third = instructions.getApplyActions().get(3);
    assertTrue(third instanceof MeterAction);
    MeterAction meterAction = (MeterAction) third;
    assertEquals(meterCommandData.getMeterId(), meterAction.getMeterId());
    assertNull(instructions.getWriteActions());
    assertNull(instructions.getGoToMeter());
    assertNull(instructions.getGoToTable());
    // Check meter command
    checkMeterCommand(meterCommandData);
}
Also used : MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) MeterAction(org.openkilda.rulemanager.action.MeterAction) Action(org.openkilda.rulemanager.action.Action) PopVxlanAction(org.openkilda.rulemanager.action.PopVxlanAction) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) PopVxlanAction(org.openkilda.rulemanager.action.PopVxlanAction) MeterAction(org.openkilda.rulemanager.action.MeterAction) Instructions(org.openkilda.rulemanager.Instructions) MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) SpeakerData(org.openkilda.rulemanager.SpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) Test(org.junit.Test)

Aggregations

MeterAction (org.openkilda.rulemanager.action.MeterAction)9 PortOutAction (org.openkilda.rulemanager.action.PortOutAction)9 Action (org.openkilda.rulemanager.action.Action)7 PopVxlanAction (org.openkilda.rulemanager.action.PopVxlanAction)5 GroupAction (org.openkilda.rulemanager.action.GroupAction)4 SetFieldAction (org.openkilda.rulemanager.action.SetFieldAction)4 Test (org.junit.Test)3 FlowSpeakerData (org.openkilda.rulemanager.FlowSpeakerData)3 Instructions (org.openkilda.rulemanager.Instructions)3 MeterSpeakerData (org.openkilda.rulemanager.MeterSpeakerData)3 SpeakerData (org.openkilda.rulemanager.SpeakerData)3 PopVlanAction (org.openkilda.rulemanager.action.PopVlanAction)2 PushVlanAction (org.openkilda.rulemanager.action.PushVlanAction)2 PushVxlanAction (org.openkilda.rulemanager.action.PushVxlanAction)2 CopyFieldAction (org.openkilda.rulemanager.action.noviflow.CopyFieldAction)2 FieldMatch (org.openkilda.rulemanager.match.FieldMatch)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 ArrayList (java.util.ArrayList)1 FlowCopyFieldAction (org.openkilda.messaging.info.rule.FlowCopyFieldAction)1 FlowSetFieldAction (org.openkilda.messaging.info.rule.FlowSetFieldAction)1