use of org.openkilda.rulemanager.OfMetadata in project open-kilda by telstra.
the class MultiTableIngressRuleGenerator method buildFlowPreIngressCommand.
private FlowSpeakerData buildFlowPreIngressCommand(Switch sw, FlowEndpoint endpoint) {
FlowSharedSegmentCookie cookie = FlowSharedSegmentCookie.builder(SharedSegmentType.QINQ_OUTER_VLAN).portNumber(endpoint.getPortNumber()).vlanId(endpoint.getOuterVlanId()).build();
RoutingMetadata metadata = RoutingMetadata.builder().outerVlanId(endpoint.getOuterVlanId()).build(sw.getFeatures());
Instructions instructions = Instructions.builder().applyActions(Lists.newArrayList(new PopVlanAction())).writeMetadata(new OfMetadata(metadata.getValue(), metadata.getMask())).goToTable(OfTable.INGRESS).build();
FlowSpeakerDataBuilder<?, ?> builder = FlowSpeakerData.builder().switchId(endpoint.getSwitchId()).ofVersion(OfVersion.of(sw.getOfVersion())).cookie(cookie).table(OfTable.PRE_INGRESS).priority(Constants.Priority.FLOW_PRIORITY).match(buildPreIngressMatch(endpoint)).instructions(instructions);
// todo add RESET_COUNTERS flag
return builder.build();
}
use of org.openkilda.rulemanager.OfMetadata in project open-kilda by telstra.
the class InputArpRuleGeneratorTest method buildCorrectRuleForOf13Test.
@Test
public void buildCorrectRuleForOf13Test() {
FlowEndpoint endpoint = new FlowEndpoint(SW.getSwitchId(), PORT_NUMBER_1, 0, 0, false, true);
FlowSideAdapter overlapAdapter = new FlowSourceAdapter(Flow.builder().flowId("some").srcSwitch(SW).destSwitch(buildSwitch("OF_13", Collections.emptySet())).detectConnectedDevices(DetectConnectedDevices.builder().srcArp(false).srcSwitchArp(false).build()).build());
InputArpRuleGenerator generator = InputArpRuleGenerator.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.ARP_INPUT_CUSTOMER_TYPE, PORT_NUMBER_1), flowCommandData.getCookie());
assertEquals(OfTable.INPUT, flowCommandData.getTable());
assertEquals(Priority.ARP_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.ARP).build());
assertEqualsMatch(expectedMatch, flowCommandData.getMatch());
RoutingMetadata metadata = RoutingMetadata.builder().arpFlag(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());
}
use of org.openkilda.rulemanager.OfMetadata in project open-kilda by telstra.
the class OfInstructionsConverter method convertToRuleManagerInstructions.
/**
* Convert instructions.
*/
public Instructions convertToRuleManagerInstructions(List<OFInstruction> ofInstructions) {
InstructionsBuilder builder = Instructions.builder();
for (OFInstruction ofInstruction : ofInstructions) {
if (ofInstruction instanceof OFInstructionApplyActions) {
List<OFAction> ofActions = ((OFInstructionApplyActions) ofInstruction).getActions();
List<Action> actions = ofActions.stream().map(this::convertToRuleManagerAction).collect(Collectors.toList());
builder.applyActions(actions);
} else if (ofInstruction instanceof OFInstructionWriteActions) {
List<OFAction> ofActions = ((OFInstructionWriteActions) ofInstruction).getActions();
Set<Action> actions = ofActions.stream().map(this::convertToRuleManagerAction).collect(Collectors.toSet());
builder.writeActions(actions);
} else if (ofInstruction instanceof OFInstructionMeter) {
final long meterId = ((OFInstructionMeter) ofInstruction).getMeterId();
builder.goToMeter(new MeterId(meterId));
} else if (ofInstruction instanceof OFInstructionGotoTable) {
final short tableId = ((OFInstructionGotoTable) ofInstruction).getTableId().getValue();
builder.goToTable(OfTable.fromInt(tableId));
} else if (ofInstruction instanceof OFInstructionWriteMetadata) {
final long metadata = ((OFInstructionWriteMetadata) ofInstruction).getMetadata().getValue();
final long metadataMask = ((OFInstructionWriteMetadata) ofInstruction).getMetadataMask().getValue();
builder.writeMetadata(new OfMetadata(metadata, metadataMask));
}
}
return builder.build();
}
use of org.openkilda.rulemanager.OfMetadata in project open-kilda by telstra.
the class OfInstructionsConverterTest method convertInstructionsTest.
@Test
public void convertInstructionsTest() {
OFFactory factory = new OFFactoryVer13();
Instructions instructions = Instructions.builder().goToTable(OfTable.PRE_INGRESS).goToMeter(new MeterId(2)).writeMetadata(new OfMetadata(123, 234)).applyActions(buildActions()).build();
List<OFInstruction> actual = OfInstructionsConverter.INSTANCE.convertInstructions(instructions, factory);
assertEquals(4, actual.size());
assertTrue(actual.contains(factory.instructions().gotoTable(TableId.of(1))));
assertTrue(actual.contains(factory.instructions().buildMeter().setMeterId(2).build()));
assertTrue(actual.contains(factory.instructions().buildWriteMetadata().setMetadata(U64.of(123)).setMetadataMask(U64.of(234)).build()));
OFInstructionApplyActions applyActionsInstruction = (OFInstructionApplyActions) actual.get(3);
assertEquals(12, applyActionsInstruction.getActions().size());
List<OFAction> expectedActions = buildActions(factory);
assertTrue(applyActionsInstruction.getActions().containsAll(expectedActions));
}
use of org.openkilda.rulemanager.OfMetadata in project open-kilda by telstra.
the class MultiTableServer42IngressRuleGenerator method buildServer42PreIngressCommand.
private FlowSpeakerData buildServer42PreIngressCommand(Switch sw, FlowEndpoint endpoint) {
FlowSharedSegmentCookie cookie = FlowSharedSegmentCookie.builder(SharedSegmentType.SERVER42_QINQ_OUTER_VLAN).portNumber(switchProperties.getServer42Port()).vlanId(endpoint.getOuterVlanId()).build();
RoutingMetadata metadata = RoutingMetadata.builder().outerVlanId(endpoint.getOuterVlanId()).build(sw.getFeatures());
Instructions instructions = Instructions.builder().applyActions(Lists.newArrayList(new PopVlanAction())).writeMetadata(new OfMetadata(metadata.getValue(), metadata.getMask())).goToTable(OfTable.INGRESS).build();
FlowSpeakerDataBuilder<?, ?> builder = FlowSpeakerData.builder().switchId(endpoint.getSwitchId()).ofVersion(OfVersion.of(sw.getOfVersion())).cookie(cookie).table(OfTable.PRE_INGRESS).priority(SERVER_42_PRE_INGRESS_FLOW_PRIORITY).match(Sets.newHashSet(FieldMatch.builder().field(Field.IN_PORT).value(switchProperties.getServer42Port()).build(), FieldMatch.builder().field(Field.VLAN_VID).value(endpoint.getOuterVlanId()).build())).instructions(instructions);
return builder.build();
}
Aggregations