Search in sources :

Example 36 with Action

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

the class SingleTableIngressYRuleGeneratorTest method buildCommandsWithoutMeter.

@Test
public void buildCommandsWithoutMeter() {
    Flow flow = buildFlow(PATH, OUTER_VLAN_ID_1, 0);
    SingleTableIngressYRuleGenerator generator = buildGenerator(PATH, flow, VLAN_ENCAPSULATION, false);
    List<SpeakerData> commands = generator.generateCommands(SWITCH_1);
    assertEquals(1, commands.size());
    FlowSpeakerData ingressCommand = (FlowSpeakerData) commands.get(0);
    assertEquals(newArrayList(SHARED_METER_UUID), new ArrayList<>(ingressCommand.getDependsOn()));
    Set<FieldMatch> expectedIngressMatch = Sets.newHashSet(FieldMatch.builder().field(Field.IN_PORT).value(PORT_NUMBER_1).build(), FieldMatch.builder().field(Field.VLAN_VID).value(OUTER_VLAN_ID_1).build());
    List<Action> expectedIngressActions = newArrayList(SetFieldAction.builder().field(Field.VLAN_VID).value(TRANSIT_VLAN_ID).build(), new PortOutAction(new PortNumber(PORT_NUMBER_2)));
    assertIngressCommand(ingressCommand, Priority.Y_FLOW_PRIORITY, expectedIngressMatch, expectedIngressActions, SHARED_METER_ID);
}
Also used : SetFieldAction(org.openkilda.rulemanager.action.SetFieldAction) Action(org.openkilda.rulemanager.action.Action) PushVxlanAction(org.openkilda.rulemanager.action.PushVxlanAction) PushVlanAction(org.openkilda.rulemanager.action.PushVlanAction) PopVlanAction(org.openkilda.rulemanager.action.PopVlanAction) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) FieldMatch(org.openkilda.rulemanager.match.FieldMatch) PortNumber(org.openkilda.rulemanager.ProtoConstants.PortNumber) SpeakerData(org.openkilda.rulemanager.SpeakerData) MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Example 37 with Action

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

the class Utils method makeVlanReplaceActions.

/**
 * Create series of actions required to reTAG one set of vlan tags to another.
 */
public static List<Action> makeVlanReplaceActions(List<Integer> currentVlanStack, List<Integer> targetVlanStack) {
    Iterator<Integer> currentIter = currentVlanStack.iterator();
    Iterator<Integer> targetIter = targetVlanStack.iterator();
    final List<Action> actions = new ArrayList<>();
    while (currentIter.hasNext() && targetIter.hasNext()) {
        Integer current = currentIter.next();
        Integer target = targetIter.next();
        if (current == null || target == null) {
            throw new IllegalArgumentException("Null elements are not allowed inside currentVlanStack and targetVlanStack arguments");
        }
        if (!current.equals(target)) {
            // remove all extra VLANs
            while (currentIter.hasNext()) {
                currentIter.next();
                actions.add(new PopVlanAction());
            }
            // rewrite existing VLAN stack "head"
            actions.add(SetFieldAction.builder().field(Field.VLAN_VID).value(target).build());
            break;
        }
    }
    // remove all extra VLANs (if previous loops ends with lack of target VLANs)
    while (currentIter.hasNext()) {
        currentIter.next();
        actions.add(new PopVlanAction());
    }
    while (targetIter.hasNext()) {
        actions.add(new PushVlanAction());
        actions.add(SetFieldAction.builder().field(Field.VLAN_VID).value(targetIter.next()).build());
    }
    return actions;
}
Also used : Action(org.openkilda.rulemanager.action.Action) PushVxlanAction(org.openkilda.rulemanager.action.PushVxlanAction) PushVlanAction(org.openkilda.rulemanager.action.PushVlanAction) PopVlanAction(org.openkilda.rulemanager.action.PopVlanAction) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) SetFieldAction(org.openkilda.rulemanager.action.SetFieldAction) PushVlanAction(org.openkilda.rulemanager.action.PushVlanAction) ArrayList(java.util.ArrayList) PopVlanAction(org.openkilda.rulemanager.action.PopVlanAction)

Example 38 with Action

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

the class Utils method buildMirrorBuckets.

/**
 * Builds group buckets for flow mirror points (only for sink endpoints. Flow bucket must be build separately).
 */
public static List<Bucket> buildMirrorBuckets(FlowMirrorPoints flowMirrorPoints) {
    List<Bucket> buckets = new ArrayList<>();
    Set<MirrorConfigData> mirrorConfigDataSet = flowMirrorPoints.getMirrorPaths().stream().map(mirrorPath -> new MirrorConfigData(mirrorPath.getEgressPort(), mirrorPath.getEgressOuterVlan())).collect(Collectors.toSet());
    for (MirrorConfigData mirrorConfig : mirrorConfigDataSet) {
        Set<Action> actions = new HashSet<>(makeVlanReplaceActions(new ArrayList<>(), makeVlanStack(mirrorConfig.getMirrorVlan())));
        actions.add(new PortOutAction(new PortNumber(mirrorConfig.getMirrorPort())));
        buckets.add(Bucket.builder().writeActions(actions).watchGroup(WatchGroup.ANY).watchPort(WatchPort.ANY).build());
    }
    return buckets;
}
Also used : VXLAN_SRC_IPV4_ADDRESS(org.openkilda.rulemanager.Constants.VXLAN_SRC_IPV4_ADDRESS) FlowPath(org.openkilda.model.FlowPath) SwitchFeature(org.openkilda.model.SwitchFeature) FieldMatch(org.openkilda.rulemanager.match.FieldMatch) Action(org.openkilda.rulemanager.action.Action) SpecialPortType(org.openkilda.rulemanager.ProtoConstants.PortNumber.SpecialPortType) KILDA_OVS_PUSH_POP_MATCH_VXLAN(org.openkilda.model.SwitchFeature.KILDA_OVS_PUSH_POP_MATCH_VXLAN) OfMetadata(org.openkilda.rulemanager.OfMetadata) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) PushVxlanAction(org.openkilda.rulemanager.action.PushVxlanAction) VXLAN_DST_IPV4_ADDRESS(org.openkilda.rulemanager.Constants.VXLAN_DST_IPV4_ADDRESS) Flow(org.openkilda.model.Flow) FlowEndpoint.makeVlanStack(org.openkilda.model.FlowEndpoint.makeVlanStack) PushVlanAction(org.openkilda.rulemanager.action.PushVlanAction) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) PopVlanAction(org.openkilda.rulemanager.action.PopVlanAction) PortNumber(org.openkilda.rulemanager.ProtoConstants.PortNumber) ActionType(org.openkilda.rulemanager.action.ActionType) FlowSideAdapter(org.openkilda.adapter.FlowSideAdapter) WatchGroup(org.openkilda.rulemanager.group.WatchGroup) FlowEndpoint(org.openkilda.model.FlowEndpoint) Iterator(java.util.Iterator) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) WatchPort(org.openkilda.rulemanager.group.WatchPort) Set(java.util.Set) SpeakerData(org.openkilda.rulemanager.SpeakerData) NOVIFLOW_PUSH_POP_VXLAN(org.openkilda.model.SwitchFeature.NOVIFLOW_PUSH_POP_VXLAN) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Bucket(org.openkilda.rulemanager.group.Bucket) MacAddress(org.openkilda.model.MacAddress) List(java.util.List) FlowEndpoint.isVlanIdSet(org.openkilda.model.FlowEndpoint.isVlanIdSet) SwitchId(org.openkilda.model.SwitchId) MirrorConfigData(org.openkilda.model.MirrorConfig.MirrorConfigData) Optional(java.util.Optional) Field(org.openkilda.rulemanager.Field) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) SetFieldAction(org.openkilda.rulemanager.action.SetFieldAction) Action(org.openkilda.rulemanager.action.Action) PushVxlanAction(org.openkilda.rulemanager.action.PushVxlanAction) PushVlanAction(org.openkilda.rulemanager.action.PushVlanAction) PopVlanAction(org.openkilda.rulemanager.action.PopVlanAction) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) SetFieldAction(org.openkilda.rulemanager.action.SetFieldAction) Bucket(org.openkilda.rulemanager.group.Bucket) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) ArrayList(java.util.ArrayList) MirrorConfigData(org.openkilda.model.MirrorConfig.MirrorConfigData) PortNumber(org.openkilda.rulemanager.ProtoConstants.PortNumber) HashSet(java.util.HashSet) Sets.newHashSet(com.google.common.collect.Sets.newHashSet)

Example 39 with Action

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

the class SingleTableIngressRuleGeneratorTest method buildTransformActionsVxlanEncapsulationFullPortTest.

@Test
public void buildTransformActionsVxlanEncapsulationFullPortTest() {
    Flow flow = buildFlow(PATH, 0, 0);
    SingleTableIngressRuleGenerator generator = buildGenerator(PATH, flow, VXLAN_ENCAPSULATION);
    List<Action> transformActions = generator.buildTransformActions(0, FEATURES);
    List<Action> expectedActions = newArrayList(buildPushVxlan());
    assertEquals(expectedActions, transformActions);
}
Also used : SetFieldAction(org.openkilda.rulemanager.action.SetFieldAction) Action(org.openkilda.rulemanager.action.Action) PushVxlanAction(org.openkilda.rulemanager.action.PushVxlanAction) PushVlanAction(org.openkilda.rulemanager.action.PushVlanAction) PopVlanAction(org.openkilda.rulemanager.action.PopVlanAction) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Example 40 with Action

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

the class SingleTableIngressRuleGeneratorTest method buildCommandsVlanEncapsulationSingleVlanTest.

@Test
public void buildCommandsVlanEncapsulationSingleVlanTest() {
    Flow flow = buildFlow(PATH, OUTER_VLAN_ID_1, 0);
    SingleTableIngressRuleGenerator generator = buildGenerator(PATH, flow, VLAN_ENCAPSULATION);
    List<SpeakerData> commands = generator.generateCommands(SWITCH_1);
    assertEquals(2, commands.size());
    FlowSpeakerData ingressCommand = (FlowSpeakerData) commands.get(0);
    MeterSpeakerData meterCommand = (MeterSpeakerData) commands.get(1);
    assertEquals(newArrayList(meterCommand.getUuid()), new ArrayList<>(ingressCommand.getDependsOn()));
    Set<FieldMatch> expectedIngressMatch = Sets.newHashSet(FieldMatch.builder().field(Field.IN_PORT).value(PORT_NUMBER_1).build(), FieldMatch.builder().field(Field.VLAN_VID).value(OUTER_VLAN_ID_1).build());
    List<Action> expectedIngressActions = newArrayList(SetFieldAction.builder().field(Field.VLAN_VID).value(TRANSIT_VLAN_ID).build(), new PortOutAction(new PortNumber(PORT_NUMBER_2)));
    assertIngressCommand(ingressCommand, Priority.FLOW_PRIORITY, expectedIngressMatch, expectedIngressActions, METER_ID);
    assertMeterCommand(meterCommand);
}
Also used : SetFieldAction(org.openkilda.rulemanager.action.SetFieldAction) Action(org.openkilda.rulemanager.action.Action) PushVxlanAction(org.openkilda.rulemanager.action.PushVxlanAction) PushVlanAction(org.openkilda.rulemanager.action.PushVlanAction) PopVlanAction(org.openkilda.rulemanager.action.PopVlanAction) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) FieldMatch(org.openkilda.rulemanager.match.FieldMatch) Flow(org.openkilda.model.Flow) MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) PortNumber(org.openkilda.rulemanager.ProtoConstants.PortNumber) SpeakerData(org.openkilda.rulemanager.SpeakerData) MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) Test(org.junit.Test)

Aggregations

Action (org.openkilda.rulemanager.action.Action)196 PortOutAction (org.openkilda.rulemanager.action.PortOutAction)195 SetFieldAction (org.openkilda.rulemanager.action.SetFieldAction)168 Test (org.junit.Test)151 PushVlanAction (org.openkilda.rulemanager.action.PushVlanAction)149 PopVlanAction (org.openkilda.rulemanager.action.PopVlanAction)146 Flow (org.openkilda.model.Flow)136 PushVxlanAction (org.openkilda.rulemanager.action.PushVxlanAction)117 FlowSpeakerData (org.openkilda.rulemanager.FlowSpeakerData)67 SpeakerData (org.openkilda.rulemanager.SpeakerData)67 PortNumber (org.openkilda.rulemanager.ProtoConstants.PortNumber)59 GroupAction (org.openkilda.rulemanager.action.GroupAction)55 FieldMatch (org.openkilda.rulemanager.match.FieldMatch)47 PopVxlanAction (org.openkilda.rulemanager.action.PopVxlanAction)46 Instructions (org.openkilda.rulemanager.Instructions)34 ArrayList (java.util.ArrayList)29 FlowPath (org.openkilda.model.FlowPath)27 GroupSpeakerData (org.openkilda.rulemanager.GroupSpeakerData)23 MeterSpeakerData (org.openkilda.rulemanager.MeterSpeakerData)21 CopyFieldAction (org.openkilda.rulemanager.action.noviflow.CopyFieldAction)20