Search in sources :

Example 26 with Instructions

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

the class LldpTransitRuleGenerator method generateCommands.

@Override
public List<SpeakerData> generateCommands(Switch sw) {
    Set<FieldMatch> match = Sets.newHashSet(FieldMatch.builder().field(Field.ETH_TYPE).value(EthType.LLDP).build());
    Instructions instructions = buildSendToControllerInstructions();
    Cookie cookie = new Cookie(LLDP_TRANSIT_COOKIE);
    return buildCommands(sw, cookie, OfTable.TRANSIT, Priority.LLDP_TRANSIT_ISL_PRIORITY, match, instructions);
}
Also used : Cookie(org.openkilda.model.cookie.Cookie) FieldMatch(org.openkilda.rulemanager.match.FieldMatch) Instructions(org.openkilda.rulemanager.Instructions)

Example 27 with Instructions

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

the class Server42IslRttInputRuleGenerator method generateCommands.

@Override
public List<SpeakerData> generateCommands(Switch sw) {
    int udpOffset = config.getServer42IslRttUdpPortOffset();
    Set<FieldMatch> match = buildMatch(server42Port, udpOffset + islPort, sw.getSwitchId());
    long ethDst = new SwitchId(config.getServer42IslRttMagicMacAddress()).toLong();
    List<Action> actions = Lists.newArrayList(SetFieldAction.builder().field(Field.UDP_SRC).value(SERVER_42_ISL_RTT_FORWARD_UDP_PORT).build(), SetFieldAction.builder().field(Field.ETH_DST).value(ethDst).build(), new PortOutAction(new PortNumber(islPort)));
    Instructions instructions = Instructions.builder().applyActions(actions).build();
    return Collections.singletonList(FlowSpeakerData.builder().switchId(sw.getSwitchId()).ofVersion(OfVersion.of(sw.getOfVersion())).cookie(new Cookie(encodeServer42IslRttInput(islPort))).table(OfTable.INPUT).priority(SERVER_42_ISL_RTT_INPUT_PRIORITY).match(match).instructions(instructions).build());
}
Also used : Cookie(org.openkilda.model.cookie.Cookie) Action(org.openkilda.rulemanager.action.Action) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) SetFieldAction(org.openkilda.rulemanager.action.SetFieldAction) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) FieldMatch(org.openkilda.rulemanager.match.FieldMatch) SwitchId(org.openkilda.model.SwitchId) Instructions(org.openkilda.rulemanager.Instructions) PortNumber(org.openkilda.rulemanager.ProtoConstants.PortNumber)

Example 28 with Instructions

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

the class MultiTableIngressYRuleGeneratorTest method assertIngressCommand.

private void assertIngressCommand(FlowSpeakerData command, int expectedPriority, Set<FieldMatch> expectedMatch, List<Action> expectedApplyActions, MeterId expectedMeter, OfMetadata expectedMetadata) {
    assertEquals(SWITCH_1.getSwitchId(), command.getSwitchId());
    assertEquals(SWITCH_1.getOfVersion(), command.getOfVersion().toString());
    assertEquals(COOKIE, command.getCookie());
    assertEquals(OfTable.INGRESS, command.getTable());
    assertEquals(expectedPriority, command.getPriority());
    assertEqualsMatch(expectedMatch, command.getMatch());
    Instructions expectedInstructions = Instructions.builder().applyActions(expectedApplyActions).goToTable(OfTable.POST_INGRESS).goToMeter(expectedMeter).writeMetadata(expectedMetadata).build();
    assertEquals(expectedInstructions, command.getInstructions());
    assertEquals(Sets.newHashSet(OfFlowFlag.RESET_COUNTERS), command.getFlags());
}
Also used : Instructions(org.openkilda.rulemanager.Instructions)

Example 29 with Instructions

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

the class InputLldpRuleGeneratorTest method buildCorrectRuleForOf13Test.

@Test
public void buildCorrectRuleForOf13Test() {
    FlowEndpoint endpoint = new FlowEndpoint(SW.getSwitchId(), PORT_NUMBER_1, 0, 0, true, false);
    FlowSideAdapter overlapAdapter = new FlowSourceAdapter(Flow.builder().flowId("some").srcSwitch(SW).destSwitch(buildSwitch("OF_13", Collections.emptySet())).detectConnectedDevices(DetectConnectedDevices.builder().srcLldp(false).srcSwitchLldp(false).build()).build());
    InputLldpRuleGenerator generator = InputLldpRuleGenerator.builder().ingressEndpoint(endpoint).multiTable(true).overlappingIngressAdapters(Sets.newHashSet(overlapAdapter)).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 PortColourCookie(CookieType.LLDP_INPUT_CUSTOMER_TYPE, PORT_NUMBER_1), flowCommandData.getCookie());
    assertEquals(OfTable.INPUT, flowCommandData.getTable());
    assertEquals(Priority.LLDP_INPUT_CUSTOMER_PRIORITY, flowCommandData.getPriority());
    Set<FieldMatch> expectedMatch = Sets.newHashSet(FieldMatch.builder().field(Field.IN_PORT).value(PORT_NUMBER_1).build(), FieldMatch.builder().field(Field.ETH_TYPE).value(EthType.LLDP).build());
    assertEqualsMatch(expectedMatch, flowCommandData.getMatch());
    RoutingMetadata metadata = RoutingMetadata.builder().lldpFlag(true).build(SW.getFeatures());
    Instructions expectedInstructions = Instructions.builder().writeMetadata(new OfMetadata(metadata.getValue(), metadata.getMask())).goToTable(OfTable.PRE_INGRESS).build();
    assertEquals(expectedInstructions, flowCommandData.getInstructions());
    assertTrue(flowCommandData.getFlags().isEmpty());
}
Also used : FlowSourceAdapter(org.openkilda.adapter.FlowSourceAdapter) FieldMatch(org.openkilda.rulemanager.match.FieldMatch) RoutingMetadata(org.openkilda.rulemanager.utils.RoutingMetadata) Instructions(org.openkilda.rulemanager.Instructions) PortColourCookie(org.openkilda.model.cookie.PortColourCookie) OfMetadata(org.openkilda.rulemanager.OfMetadata) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) FlowEndpoint(org.openkilda.model.FlowEndpoint) FlowSideAdapter(org.openkilda.adapter.FlowSideAdapter) SpeakerData(org.openkilda.rulemanager.SpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) Test(org.junit.Test)

Example 30 with Instructions

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

the class TransitYRuleGeneratorTest method assertTransitCommands.

private void assertTransitCommands(List<SpeakerData> commands, OfTable table, FlowTransitEncapsulation encapsulation) {
    assertEquals(2, commands.size());
    MeterSpeakerData meterCommandData = getCommand(MeterSpeakerData.class, commands);
    FlowSpeakerData flowCommandData = getCommand(FlowSpeakerData.class, commands);
    assertEquals(SWITCH_1.getSwitchId(), flowCommandData.getSwitchId());
    assertEquals(SWITCH_1.getOfVersion(), flowCommandData.getOfVersion().toString());
    assertTrue(flowCommandData.getDependsOn().contains(meterCommandData.getUuid()));
    assertEquals(COOKIE, flowCommandData.getCookie());
    assertEquals(table, flowCommandData.getTable());
    assertEquals(Priority.Y_FLOW_PRIORITY, flowCommandData.getPriority());
    Set<FieldMatch> expectedMatch;
    if (encapsulation.getType().equals(FlowEncapsulationType.TRANSIT_VLAN)) {
        expectedMatch = buildExpectedVlanMatch(PORT_NUMBER_1, encapsulation.getId());
    } else {
        expectedMatch = buildExpectedVxlanMatch(PORT_NUMBER_1, encapsulation.getId());
    }
    assertEqualsMatch(expectedMatch, flowCommandData.getMatch());
    Instructions expectedInstructions = Instructions.builder().applyActions(Lists.newArrayList(new PortOutAction(new PortNumber(PORT_NUMBER_2)))).goToMeter(SHARED_METER_ID).build();
    assertEquals(expectedInstructions, flowCommandData.getInstructions());
    assertEquals(Sets.newHashSet(OfFlowFlag.RESET_COUNTERS), flowCommandData.getFlags());
}
Also used : MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) FieldMatch(org.openkilda.rulemanager.match.FieldMatch) Instructions(org.openkilda.rulemanager.Instructions) PortNumber(org.openkilda.rulemanager.ProtoConstants.PortNumber)

Aggregations

Instructions (org.openkilda.rulemanager.Instructions)84 FieldMatch (org.openkilda.rulemanager.match.FieldMatch)55 PortOutAction (org.openkilda.rulemanager.action.PortOutAction)40 FlowSpeakerData (org.openkilda.rulemanager.FlowSpeakerData)35 Action (org.openkilda.rulemanager.action.Action)34 Cookie (org.openkilda.model.cookie.Cookie)31 SpeakerData (org.openkilda.rulemanager.SpeakerData)29 Test (org.junit.Test)26 PortNumber (org.openkilda.rulemanager.ProtoConstants.PortNumber)25 SetFieldAction (org.openkilda.rulemanager.action.SetFieldAction)24 ArrayList (java.util.ArrayList)14 PortColourCookie (org.openkilda.model.cookie.PortColourCookie)14 RoutingMetadata (org.openkilda.rulemanager.utils.RoutingMetadata)13 Switch (org.openkilda.model.Switch)12 Utils.buildSwitch (org.openkilda.rulemanager.Utils.buildSwitch)12 MeterSpeakerData (org.openkilda.rulemanager.MeterSpeakerData)11 PopVxlanAction (org.openkilda.rulemanager.action.PopVxlanAction)10 MeterAction (org.openkilda.rulemanager.action.MeterAction)9 PushVlanAction (org.openkilda.rulemanager.action.PushVlanAction)9 OfMetadata (org.openkilda.rulemanager.OfMetadata)8