Search in sources :

Example 1 with OfMetadata

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

the class OfInstructionsConverterTest method convertToRuleManagerInstructionsTest.

@Test
public void convertToRuleManagerInstructionsTest() {
    OFFactory factory = new OFFactoryVer13();
    List<OFInstruction> instructions = new ArrayList<>();
    instructions.add(factory.instructions().gotoTable(TableId.of(1)));
    instructions.add(factory.instructions().meter(2));
    instructions.add(factory.instructions().writeMetadata(U64.of(123), U64.of(234)));
    List<OFAction> actions = buildActions(factory);
    instructions.add(factory.instructions().applyActions(actions));
    Instructions actual = OfInstructionsConverter.INSTANCE.convertToRuleManagerInstructions(instructions);
    assertEquals(OfTable.PRE_INGRESS, actual.getGoToTable());
    assertEquals(new MeterId(2), actual.getGoToMeter());
    assertEquals(new OfMetadata(123, 234), actual.getWriteMetadata());
    assertEquals(12, actual.getApplyActions().size());
    List<Action> expectedActions = buildActions();
    assertTrue(actual.getApplyActions().containsAll(expectedActions));
}
Also used : OfMetadata(org.openkilda.rulemanager.OfMetadata) 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) SwapFieldAction(org.openkilda.rulemanager.action.SwapFieldAction) OFAction(org.projectfloodlight.openflow.protocol.action.OFAction) GroupAction(org.openkilda.rulemanager.action.GroupAction) CopyFieldAction(org.openkilda.rulemanager.action.noviflow.CopyFieldAction) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) SetFieldAction(org.openkilda.rulemanager.action.SetFieldAction) OFInstruction(org.projectfloodlight.openflow.protocol.instruction.OFInstruction) OFFactoryVer13(org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) ArrayList(java.util.ArrayList) OFAction(org.projectfloodlight.openflow.protocol.action.OFAction) Instructions(org.openkilda.rulemanager.Instructions) MeterId(org.openkilda.model.MeterId) Test(org.junit.Test)

Example 2 with OfMetadata

use of org.openkilda.rulemanager.OfMetadata 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 3 with OfMetadata

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

the class InputLldpRuleGenerator method buildLldpInputCustomerFlowCommand.

private SpeakerData buildLldpInputCustomerFlowCommand(Switch sw, FlowEndpoint endpoint) {
    RoutingMetadata metadata = RoutingMetadata.builder().lldpFlag(true).build(sw.getFeatures());
    FlowSpeakerDataBuilder<?, ?> builder = FlowSpeakerData.builder().switchId(endpoint.getSwitchId()).ofVersion(OfVersion.of(sw.getOfVersion())).cookie(new PortColourCookie(CookieType.LLDP_INPUT_CUSTOMER_TYPE, endpoint.getPortNumber())).table(OfTable.INPUT).priority(Constants.Priority.LLDP_INPUT_CUSTOMER_PRIORITY).match(Sets.newHashSet(FieldMatch.builder().field(Field.IN_PORT).value(endpoint.getPortNumber()).build(), FieldMatch.builder().field(Field.ETH_TYPE).value(EthType.LLDP).build())).instructions(Instructions.builder().goToTable(OfTable.PRE_INGRESS).writeMetadata(new OfMetadata(metadata.getValue(), metadata.getMask())).build());
    // todo add RESET_COUNTERS flag
    return builder.build();
}
Also used : OfMetadata(org.openkilda.rulemanager.OfMetadata) RoutingMetadata(org.openkilda.rulemanager.utils.RoutingMetadata) PortColourCookie(org.openkilda.model.cookie.PortColourCookie)

Example 4 with OfMetadata

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

the class InputArpRuleGenerator method buildArpInputCustomerFlowCommand.

private SpeakerData buildArpInputCustomerFlowCommand(Switch sw, FlowEndpoint endpoint) {
    RoutingMetadata metadata = RoutingMetadata.builder().arpFlag(true).build(sw.getFeatures());
    FlowSpeakerDataBuilder<?, ?> builder = FlowSpeakerData.builder().switchId(endpoint.getSwitchId()).ofVersion(OfVersion.of(sw.getOfVersion())).cookie(new PortColourCookie(CookieType.ARP_INPUT_CUSTOMER_TYPE, endpoint.getPortNumber())).table(OfTable.INPUT).priority(Priority.ARP_INPUT_CUSTOMER_PRIORITY).match(Sets.newHashSet(FieldMatch.builder().field(Field.IN_PORT).value(endpoint.getPortNumber()).build(), FieldMatch.builder().field(Field.ETH_TYPE).value(EthType.ARP).build())).instructions(Instructions.builder().goToTable(OfTable.PRE_INGRESS).writeMetadata(new OfMetadata(metadata.getValue(), metadata.getMask())).build());
    // todo add RESET_COUNTERS flag
    return builder.build();
}
Also used : OfMetadata(org.openkilda.rulemanager.OfMetadata) RoutingMetadata(org.openkilda.rulemanager.utils.RoutingMetadata) PortColourCookie(org.openkilda.model.cookie.PortColourCookie)

Example 5 with OfMetadata

use of org.openkilda.rulemanager.OfMetadata 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)

Aggregations

OfMetadata (org.openkilda.rulemanager.OfMetadata)11 Instructions (org.openkilda.rulemanager.Instructions)8 RoutingMetadata (org.openkilda.rulemanager.utils.RoutingMetadata)7 Test (org.junit.Test)5 PopVlanAction (org.openkilda.rulemanager.action.PopVlanAction)5 MeterId (org.openkilda.model.MeterId)4 PortColourCookie (org.openkilda.model.cookie.PortColourCookie)4 ArrayList (java.util.ArrayList)3 FlowSpeakerData (org.openkilda.rulemanager.FlowSpeakerData)3 SpeakerData (org.openkilda.rulemanager.SpeakerData)3 Action (org.openkilda.rulemanager.action.Action)3 GroupAction (org.openkilda.rulemanager.action.GroupAction)3 PopVxlanAction (org.openkilda.rulemanager.action.PopVxlanAction)3 PortOutAction (org.openkilda.rulemanager.action.PortOutAction)3 PushVlanAction (org.openkilda.rulemanager.action.PushVlanAction)3 PushVxlanAction (org.openkilda.rulemanager.action.PushVxlanAction)3 SetFieldAction (org.openkilda.rulemanager.action.SetFieldAction)3 CopyFieldAction (org.openkilda.rulemanager.action.noviflow.CopyFieldAction)3 FieldMatch (org.openkilda.rulemanager.match.FieldMatch)3 List (java.util.List)2