Search in sources :

Example 6 with MeterAction

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

the class BroadCastDiscoveryRuleGeneratorTest method shouldBuildCorrectRuleWithMeterAndGroupForOf15.

@Test
public void shouldBuildCorrectRuleWithMeterAndGroupForOf15() {
    sw = buildSwitch("OF_15", Sets.newHashSet(METERS, GROUP_PACKET_OUT_CONTROLLER, MATCH_UDP_PORT, PKTPS_FLAG));
    List<SpeakerData> commands = generator.generateCommands(sw);
    assertEquals(3, 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);
    GroupSpeakerData groupCommandData = getCommand(GroupSpeakerData.class, commands);
    assertEquals(2, flowCommandData.getDependsOn().size());
    assertTrue(flowCommandData.getDependsOn().contains(meterCommandData.getUuid()));
    assertTrue(flowCommandData.getDependsOn().contains(groupCommandData.getUuid()));
    // Check flow command
    checkFlowCommandBaseProperties(flowCommandData);
    Set<FieldMatch> match = flowCommandData.getMatch();
    assertEquals(4, match.size());
    checkEthDstMatch(match);
    checkUpdDstMatch(match);
    // Check flow command has correct instructions for OF 1.5
    Instructions instructions = flowCommandData.getInstructions();
    assertEquals(2, instructions.getApplyActions().size());
    Action first = instructions.getApplyActions().get(0);
    assertTrue(first instanceof MeterAction);
    MeterAction meterAction = (MeterAction) first;
    assertEquals(meterCommandData.getMeterId(), meterAction.getMeterId());
    checkGroupAction(instructions.getApplyActions().get(1), groupCommandData.getGroupId());
    assertNull(instructions.getWriteActions());
    assertNull(instructions.getGoToMeter());
    assertNull(instructions.getGoToTable());
    // Check meter command
    checkMeterCommand(meterCommandData);
    // Check group command
    checkGroupCommand(groupCommandData);
}
Also used : MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) MeterAction(org.openkilda.rulemanager.action.MeterAction) GroupAction(org.openkilda.rulemanager.action.GroupAction) SetFieldAction(org.openkilda.rulemanager.action.SetFieldAction) Action(org.openkilda.rulemanager.action.Action) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) FieldMatch(org.openkilda.rulemanager.match.FieldMatch) GroupSpeakerData(org.openkilda.rulemanager.GroupSpeakerData) MeterAction(org.openkilda.rulemanager.action.MeterAction) Instructions(org.openkilda.rulemanager.Instructions) SpeakerData(org.openkilda.rulemanager.SpeakerData) MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) GroupSpeakerData(org.openkilda.rulemanager.GroupSpeakerData) Test(org.junit.Test)

Example 7 with MeterAction

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

the class LldpPostIngressVxlanRuleGeneratorTest 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 8 with MeterAction

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

the class RuleManagerHelperTest method buildAllActions.

private List<Action> buildAllActions() {
    List<Action> actions = new ArrayList<>();
    actions.add(new GroupAction(GROUP_ID_1));
    actions.add(new MeterAction(METER_ID_1));
    actions.add(new PopVlanAction());
    actions.add(new PopVxlanAction(ActionType.POP_VXLAN_OVS));
    actions.add(new PortOutAction(PORT_NUMBER));
    actions.add(new PushVlanAction());
    actions.add(SetFieldAction.builder().field(Field.VLAN_VID).value(VLAN_ID).build());
    actions.add(CopyFieldAction.builder().srcOffset(0).dstOffset(0).numberOfBits(NUMBER_OF_BITS).oxmSrcHeader(OpenFlowOxms.NOVIFLOW_TX_TIMESTAMP).oxmDstHeader(OpenFlowOxms.NOVIFLOW_PACKET_OFFSET).build());
    actions.add(PushVxlanAction.builder().type(ActionType.PUSH_VXLAN_NOVIFLOW).vni(VNI).srcMacAddress(SRC_MAC_ADDRESS).dstMacAddress(DST_MAC_ADDRESS).srcIpv4Address(SRC_IPV4_ADDRESS).dstIpv4Address(DST_IPV4_ADDRESS).udpSrc(UDP_SRC).build());
    return actions;
}
Also used : GroupAction(org.openkilda.rulemanager.action.GroupAction) MeterAction(org.openkilda.rulemanager.action.MeterAction) 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) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) PopVxlanAction(org.openkilda.rulemanager.action.PopVxlanAction) PushVlanAction(org.openkilda.rulemanager.action.PushVlanAction) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) MeterAction(org.openkilda.rulemanager.action.MeterAction) PopVlanAction(org.openkilda.rulemanager.action.PopVlanAction)

Example 9 with MeterAction

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

the class FlowEntryConverter method addAction.

private void addAction(FlowApplyActionsBuilder builder, Action action) {
    switch(action.getType()) {
        case GROUP:
            GroupAction groupAction = (GroupAction) action;
            builder.group(String.valueOf(groupAction.getGroupId().getValue()));
            return;
        case PORT_OUT:
            PortOutAction portOutAction = (PortOutAction) action;
            builder.flowOutput(portOutAction.getPortNumber().toString());
            return;
        case POP_VLAN:
            builder.popVlan("");
            return;
        case PUSH_VLAN:
            builder.pushVlan("");
            return;
        case POP_VXLAN_NOVIFLOW:
        case POP_VXLAN_OVS:
            // todo handle pop vxlan
            return;
        case PUSH_VXLAN_NOVIFLOW:
        case PUSH_VXLAN_OVS:
            PushVxlanAction pushVxlanAction = (PushVxlanAction) action;
            builder.pushVxlan(String.valueOf(pushVxlanAction.getVni()));
            return;
        case METER:
            MeterAction meterAction = (MeterAction) action;
            builder.meter(String.valueOf(meterAction.getMeterId().getValue()));
            return;
        case NOVI_COPY_FIELD:
            CopyFieldAction copyFieldAction = (CopyFieldAction) action;
            builder.copyFieldAction(FlowCopyFieldAction.builder().bits(String.valueOf(copyFieldAction.getNumberOfBits())).srcOffset(String.valueOf(copyFieldAction.getSrcOffset())).dstOffset(String.valueOf(copyFieldAction.getDstOffset())).srcOxm(copyFieldAction.getOxmSrcHeader().toString()).dstOxm(copyFieldAction.getOxmDstHeader().toString()).build());
            return;
        case NOVI_SWAP_FIELD:
        case KILDA_SWAP_FIELD:
            SwapFieldAction swapFieldAction = (SwapFieldAction) action;
            builder.swapFieldAction(FlowSwapFieldAction.builder().bits(String.valueOf(swapFieldAction.getNumberOfBits())).srcOffset(String.valueOf(swapFieldAction.getSrcOffset())).dstOffset(String.valueOf(swapFieldAction.getDstOffset())).srcOxm(swapFieldAction.getOxmSrcHeader().toString()).dstOxm(swapFieldAction.getOxmDstHeader().toString()).build());
            return;
        case SET_FIELD:
            SetFieldAction setFieldAction = (SetFieldAction) action;
            builder.setFieldAction(FlowSetFieldAction.builder().fieldName(setFieldAction.getField().toString()).fieldValue(String.valueOf(setFieldAction.getValue())).build());
            return;
        default:
            throw new IllegalStateException(format("Unknown action type %s", action.getType()));
    }
}
Also used : GroupAction(org.openkilda.rulemanager.action.GroupAction) FlowCopyFieldAction(org.openkilda.messaging.info.rule.FlowCopyFieldAction) CopyFieldAction(org.openkilda.rulemanager.action.noviflow.CopyFieldAction) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) MeterAction(org.openkilda.rulemanager.action.MeterAction) SwapFieldAction(org.openkilda.rulemanager.action.SwapFieldAction) FlowSwapFieldAction(org.openkilda.messaging.info.rule.FlowSwapFieldAction) PushVxlanAction(org.openkilda.rulemanager.action.PushVxlanAction) FlowSetFieldAction(org.openkilda.messaging.info.rule.FlowSetFieldAction) SetFieldAction(org.openkilda.rulemanager.action.SetFieldAction)

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