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));
}
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();
}
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();
}
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();
}
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());
}
Aggregations