Search in sources :

Example 6 with Action

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

the class RuleManagerHelperTest method buildFullFlowSpeakerCommandData.

private FlowSpeakerData buildFullFlowSpeakerCommandData(MeterId goToMeterId, UUID dependsOnUuid) {
    Set<FieldMatch> match = Arrays.stream(Field.values()).map(f -> FieldMatch.builder().field(f).value(f.ordinal()).mask(f.ordinal() + 1L).build()).collect(Collectors.toSet());
    Set<OfFlowFlag> flags = Sets.newHashSet(OfFlowFlag.values());
    List<Action> applyActions = new ArrayList<>(buildAllActions());
    applyActions.addAll(buildAllActions());
    Instructions instructions = Instructions.builder().goToMeter(goToMeterId).goToTable(OfTable.INPUT).writeMetadata(new OfMetadata(15, 0xff)).writeActions(new HashSet<>(buildAllActions())).applyActions(applyActions).build();
    return FlowSpeakerData.builder().uuid(UUID.randomUUID()).cookie(new Cookie(123)).priority(PRIORITY).table(OfTable.INPUT).match(match).instructions(instructions).flags(flags).switchId(SWITCH_ID).ofVersion(OfVersion.OF_13).dependsOn(dependsOnUuid == null ? newArrayList() : newArrayList(dependsOnUuid)).build();
}
Also used : MeterAction(org.openkilda.rulemanager.action.MeterAction) Arrays(java.util.Arrays) MeterFlag(org.openkilda.rulemanager.MeterFlag) GroupType(org.openkilda.rulemanager.group.GroupType) OfMetadata(org.openkilda.rulemanager.OfMetadata) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) RuleManagerHelper.sortCommandsByDependencies(org.openkilda.rulemanager.utils.RuleManagerHelper.sortCommandsByDependencies) WatchGroup(org.openkilda.rulemanager.group.WatchGroup) Instructions(org.openkilda.rulemanager.Instructions) Set(java.util.Set) SpeakerData(org.openkilda.rulemanager.SpeakerData) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) MacAddress(org.openkilda.model.MacAddress) OfFlowFlag(org.openkilda.rulemanager.OfFlowFlag) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) GroupAction(org.openkilda.rulemanager.action.GroupAction) CopyFieldAction(org.openkilda.rulemanager.action.noviflow.CopyFieldAction) RuleManagerHelper.checkCircularDependencies(org.openkilda.rulemanager.utils.RuleManagerHelper.checkCircularDependencies) SetFieldAction(org.openkilda.rulemanager.action.SetFieldAction) IPv4Address(org.openkilda.model.IPv4Address) FieldMatch(org.openkilda.rulemanager.match.FieldMatch) Action(org.openkilda.rulemanager.action.Action) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) PushVxlanAction(org.openkilda.rulemanager.action.PushVxlanAction) RuleManagerHelper.removeDuplicateCommands(org.openkilda.rulemanager.utils.RuleManagerHelper.removeDuplicateCommands) PopVxlanAction(org.openkilda.rulemanager.action.PopVxlanAction) Cookie(org.openkilda.model.cookie.Cookie) PushVlanAction(org.openkilda.rulemanager.action.PushVlanAction) PopVlanAction(org.openkilda.rulemanager.action.PopVlanAction) PortNumber(org.openkilda.rulemanager.ProtoConstants.PortNumber) ActionType(org.openkilda.rulemanager.action.ActionType) OpenFlowOxms(org.openkilda.rulemanager.action.noviflow.OpenFlowOxms) MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) OfVersion(org.openkilda.rulemanager.OfVersion) WatchPort(org.openkilda.rulemanager.group.WatchPort) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) MeterId(org.openkilda.model.MeterId) Bucket(org.openkilda.rulemanager.group.Bucket) SwitchId(org.openkilda.model.SwitchId) GroupSpeakerData(org.openkilda.rulemanager.GroupSpeakerData) OfTable(org.openkilda.rulemanager.OfTable) GroupId(org.openkilda.model.GroupId) Assert.assertEquals(org.junit.Assert.assertEquals) Field(org.openkilda.rulemanager.Field) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) OfMetadata(org.openkilda.rulemanager.OfMetadata) Cookie(org.openkilda.model.cookie.Cookie) 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) FieldMatch(org.openkilda.rulemanager.match.FieldMatch) OfFlowFlag(org.openkilda.rulemanager.OfFlowFlag) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) Instructions(org.openkilda.rulemanager.Instructions)

Example 7 with Action

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

the class BfdCatchRuleGeneratorTest method shouldBuildCorrectRuleForOf13.

@Test
public void shouldBuildCorrectRuleForOf13() {
    Switch sw = buildSwitch("OF_13", Sets.newHashSet(BFD));
    BfdCatchRuleGenerator generator = new BfdCatchRuleGenerator();
    List<SpeakerData> commands = generator.generateCommands(sw);
    assertEquals(1, commands.size());
    FlowSpeakerData flowCommandData = getCommand(FlowSpeakerData.class, commands);
    assertEquals(sw.getSwitchId(), flowCommandData.getSwitchId());
    assertEquals(sw.getOfVersion(), flowCommandData.getOfVersion().toString());
    assertTrue(flowCommandData.getDependsOn().isEmpty());
    assertEquals(new Cookie(CATCH_BFD_RULE_COOKIE), flowCommandData.getCookie());
    assertEquals(OfTable.INPUT, flowCommandData.getTable());
    assertEquals(CATCH_BFD_RULE_PRIORITY, flowCommandData.getPriority());
    FieldMatch ethDstMatch = getMatchByField(Field.ETH_DST, flowCommandData.getMatch());
    assertEquals(sw.getSwitchId().toLong(), ethDstMatch.getValue());
    assertFalse(ethDstMatch.isMasked());
    FieldMatch ethTypeMatch = getMatchByField(Field.ETH_TYPE, flowCommandData.getMatch());
    assertEquals(EthType.IPv4, ethTypeMatch.getValue());
    assertFalse(ethTypeMatch.isMasked());
    FieldMatch ipProtoMatch = getMatchByField(Field.IP_PROTO, flowCommandData.getMatch());
    assertEquals(IpProto.UDP, ipProtoMatch.getValue());
    assertFalse(ipProtoMatch.isMasked());
    FieldMatch udpDstMatch = getMatchByField(Field.UDP_DST, flowCommandData.getMatch());
    assertEquals(Constants.BDF_DEFAULT_PORT, udpDstMatch.getValue());
    assertFalse(udpDstMatch.isMasked());
    Instructions instructions = flowCommandData.getInstructions();
    assertEquals(1, instructions.getApplyActions().size());
    Action action = instructions.getApplyActions().get(0);
    assertTrue(action instanceof PortOutAction);
    PortOutAction portOutAction = (PortOutAction) action;
    assertEquals(SpecialPortType.LOCAL, portOutAction.getPortNumber().getPortType());
}
Also used : Cookie(org.openkilda.model.cookie.Cookie) Action(org.openkilda.rulemanager.action.Action) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) Utils.buildSwitch(org.openkilda.rulemanager.Utils.buildSwitch) Switch(org.openkilda.model.Switch) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) FieldMatch(org.openkilda.rulemanager.match.FieldMatch) Instructions(org.openkilda.rulemanager.Instructions) SpeakerData(org.openkilda.rulemanager.SpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) Test(org.junit.Test)

Example 8 with Action

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

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

the class RoundTripLatencyRuleGeneratorTest method shouldBuildCorrectRuleForOf13.

@Test
public void shouldBuildCorrectRuleForOf13() {
    Switch sw = buildSwitch("OF_13", Sets.newHashSet(NOVIFLOW_COPY_FIELD));
    RoundTripLatencyRuleGenerator generator = RoundTripLatencyRuleGenerator.builder().config(config).build();
    List<SpeakerData> commands = generator.generateCommands(sw);
    assertEquals(1, commands.size());
    FlowSpeakerData flowCommandData = getCommand(FlowSpeakerData.class, commands);
    assertEquals(sw.getSwitchId(), flowCommandData.getSwitchId());
    assertEquals(sw.getOfVersion(), flowCommandData.getOfVersion().toString());
    assertTrue(flowCommandData.getDependsOn().isEmpty());
    assertEquals(new Cookie(ROUND_TRIP_LATENCY_RULE_COOKIE), flowCommandData.getCookie());
    assertEquals(OfTable.INPUT, flowCommandData.getTable());
    assertEquals(ROUND_TRIP_LATENCY_RULE_PRIORITY, flowCommandData.getPriority());
    FieldMatch ethSrcMatch = getMatchByField(Field.ETH_SRC, flowCommandData.getMatch());
    assertEquals(sw.getSwitchId().toLong(), ethSrcMatch.getValue());
    assertFalse(ethSrcMatch.isMasked());
    FieldMatch ethDstMatch = getMatchByField(Field.ETH_DST, flowCommandData.getMatch());
    assertEquals(new SwitchId(config.getDiscoveryBcastPacketDst()).toLong(), ethDstMatch.getValue());
    assertFalse(ethDstMatch.isMasked());
    FieldMatch ethTypeMatch = getMatchByField(Field.ETH_TYPE, flowCommandData.getMatch());
    assertEquals(EthType.IPv4, ethTypeMatch.getValue());
    assertFalse(ethTypeMatch.isMasked());
    FieldMatch ipProtoMatch = getMatchByField(Field.IP_PROTO, flowCommandData.getMatch());
    assertEquals(IpProto.UDP, ipProtoMatch.getValue());
    assertFalse(ipProtoMatch.isMasked());
    FieldMatch udpDstMatch = getMatchByField(Field.UDP_DST, flowCommandData.getMatch());
    assertEquals(Constants.LATENCY_PACKET_UDP_PORT, udpDstMatch.getValue());
    assertFalse(udpDstMatch.isMasked());
    Instructions instructions = flowCommandData.getInstructions();
    assertEquals(2, instructions.getApplyActions().size());
    Action first = instructions.getApplyActions().get(0);
    assertTrue(first instanceof CopyFieldAction);
    CopyFieldAction copyFieldAction = (CopyFieldAction) first;
    assertEquals(ROUND_TRIP_LATENCY_TIMESTAMP_SIZE, copyFieldAction.getNumberOfBits());
    assertEquals(0, copyFieldAction.getSrcOffset());
    assertEquals(ROUND_TRIP_LATENCY_T1_OFFSET, copyFieldAction.getDstOffset());
    assertEquals(NOVIFLOW_RX_TIMESTAMP, copyFieldAction.getOxmSrcHeader());
    assertEquals(NOVIFLOW_PACKET_OFFSET, copyFieldAction.getOxmDstHeader());
    Action second = instructions.getApplyActions().get(1);
    assertTrue(second instanceof PortOutAction);
    PortOutAction portOutAction = (PortOutAction) second;
    assertEquals(SpecialPortType.CONTROLLER, portOutAction.getPortNumber().getPortType());
}
Also used : Cookie(org.openkilda.model.cookie.Cookie) CopyFieldAction(org.openkilda.rulemanager.action.noviflow.CopyFieldAction) Action(org.openkilda.rulemanager.action.Action) CopyFieldAction(org.openkilda.rulemanager.action.noviflow.CopyFieldAction) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) Utils.buildSwitch(org.openkilda.rulemanager.Utils.buildSwitch) Switch(org.openkilda.model.Switch) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) FieldMatch(org.openkilda.rulemanager.match.FieldMatch) SwitchId(org.openkilda.model.SwitchId) Instructions(org.openkilda.rulemanager.Instructions) SpeakerData(org.openkilda.rulemanager.SpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) RoundTripLatencyRuleGenerator(org.openkilda.rulemanager.factory.generator.service.noviflow.RoundTripLatencyRuleGenerator) Test(org.junit.Test)

Example 10 with Action

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

the class SingleTableServer42IngressRuleGeneratorTest method buildCommandsVxlanEncapsulationSingleVlanTest.

@Test
public void buildCommandsVxlanEncapsulationSingleVlanTest() {
    Flow flow = buildFlow(PATH, OUTER_VLAN_ID_1);
    SingleTableServer42IngressRuleGenerator generator = buildGenerator(PATH, flow, VXLAN_ENCAPSULATION);
    List<SpeakerData> commands = generator.generateCommands(SWITCH_1);
    assertEquals(1, commands.size());
    FlowSpeakerData ingressCommand = (FlowSpeakerData) commands.get(0);
    Set<FieldMatch> expectedIngressMatch = Sets.newHashSet(FieldMatch.builder().field(Field.IN_PORT).value(SERVER_42_PORT_NUMBER).build(), FieldMatch.builder().field(Field.ETH_SRC).value(SERVER_42_MAC_ADDRESS.toLong()).build(), FieldMatch.builder().field(Field.ETH_TYPE).value(EthType.IPv4).build(), FieldMatch.builder().field(Field.IP_PROTO).value(IpProto.UDP).build(), FieldMatch.builder().field(Field.UDP_SRC).value(PORT_OFFSET + PORT_NUMBER_1).build(), FieldMatch.builder().field(Field.VLAN_VID).value(OUTER_VLAN_ID_1).build());
    List<Action> expectedIngressActions = newArrayList(new PopVlanAction(), COPY_FIELD_ACTION, buildPushVxlan(), new PortOutAction(new PortNumber(PORT_NUMBER_2)));
    assertIngressCommand(ingressCommand, Priority.SERVER_42_INGRESS_SINGLE_VLAN_FLOW_PRIORITY, expectedIngressMatch, expectedIngressActions);
}
Also used : 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) 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) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) Flow(org.openkilda.model.Flow) PopVlanAction(org.openkilda.rulemanager.action.PopVlanAction) 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