use of org.openkilda.rulemanager.MeterSpeakerData in project open-kilda by telstra.
the class SwitchValidateFsm method validateEnter.
protected void validateEnter(SwitchValidateState from, SwitchValidateState to, SwitchValidateEvent event, SwitchValidateContext context) {
SwitchId switchId = getSwitchId();
Set<PathId> flowPathIds = flowPathRepository.findBySegmentSwitch(switchId).stream().map(FlowPath::getPathId).collect(Collectors.toSet());
flowPathIds.addAll(flowPathRepository.findByEndpointSwitch(switchId).stream().map(FlowPath::getPathId).collect(Collectors.toSet()));
PersistenceDataAdapter dataAdapter = PersistenceDataAdapter.builder().persistenceManager(persistenceManager).switchIds(Collections.singleton(switchId)).pathIds(flowPathIds).keepMultitableForFlow(true).build();
List<SpeakerData> expectedEntities = ruleManager.buildRulesForSwitch(switchId, dataAdapter);
List<FlowSpeakerData> expectedRules = filterSpeakerData(expectedEntities, FlowSpeakerData.class);
List<MeterSpeakerData> expectedMeters = filterSpeakerData(expectedEntities, MeterSpeakerData.class);
List<GroupSpeakerData> expectedGroups = filterSpeakerData(expectedEntities, GroupSpeakerData.class);
validateRules(expectedRules);
validateMeters(expectedMeters);
validateGroups(expectedGroups);
validateLogicalPorts();
}
use of org.openkilda.rulemanager.MeterSpeakerData in project open-kilda by telstra.
the class BroadCastDiscoveryRuleGeneratorTest method shouldBuildCorrectRuleWithMeterAndGroupForOf13.
@Test
public void shouldBuildCorrectRuleWithMeterAndGroupForOf13() {
sw = buildSwitch("OF_13", Sets.newHashSet(METERS, GROUP_PACKET_OUT_CONTROLLER, MATCH_UDP_PORT, PKTPS_FLAG));
List<SpeakerData> commands = generator.generateCommands(sw);
assertEquals(3, commands.size());
commands.forEach(c -> assertEquals(sw.getSwitchId(), c.getSwitchId()));
commands.forEach(c -> assertEquals(sw.getOfVersion(), c.getOfVersion().toString()));
FlowSpeakerData flowCommandData = getCommand(FlowSpeakerData.class, commands);
MeterSpeakerData meterCommandData = getCommand(MeterSpeakerData.class, commands);
GroupSpeakerData groupCommandData = getCommand(GroupSpeakerData.class, commands);
assertEquals(2, flowCommandData.getDependsOn().size());
assertTrue(flowCommandData.getDependsOn().contains(meterCommandData.getUuid()));
assertTrue(flowCommandData.getDependsOn().contains(groupCommandData.getUuid()));
// Check flow command
checkFlowCommandBaseProperties(flowCommandData);
Set<FieldMatch> match = flowCommandData.getMatch();
assertEquals(4, match.size());
checkEthDstMatch(match);
checkUpdDstMatch(match);
checkGroupInstructions(flowCommandData.getInstructions(), meterCommandData.getMeterId(), groupCommandData.getGroupId());
// Check meter command
checkMeterCommand(meterCommandData);
// Check group command
checkGroupCommand(groupCommandData);
}
use of org.openkilda.rulemanager.MeterSpeakerData in project open-kilda by telstra.
the class BroadCastDiscoveryRuleGeneratorTest method shouldBuildCorrectRuleWithMeterAndGroupForOf15.
@Test
public void shouldBuildCorrectRuleWithMeterAndGroupForOf15() {
sw = buildSwitch("OF_15", Sets.newHashSet(METERS, GROUP_PACKET_OUT_CONTROLLER, MATCH_UDP_PORT, PKTPS_FLAG));
List<SpeakerData> commands = generator.generateCommands(sw);
assertEquals(3, commands.size());
commands.forEach(c -> assertEquals(sw.getSwitchId(), c.getSwitchId()));
commands.forEach(c -> assertEquals(sw.getOfVersion(), c.getOfVersion().toString()));
FlowSpeakerData flowCommandData = getCommand(FlowSpeakerData.class, commands);
MeterSpeakerData meterCommandData = getCommand(MeterSpeakerData.class, commands);
GroupSpeakerData groupCommandData = getCommand(GroupSpeakerData.class, commands);
assertEquals(2, flowCommandData.getDependsOn().size());
assertTrue(flowCommandData.getDependsOn().contains(meterCommandData.getUuid()));
assertTrue(flowCommandData.getDependsOn().contains(groupCommandData.getUuid()));
// Check flow command
checkFlowCommandBaseProperties(flowCommandData);
Set<FieldMatch> match = flowCommandData.getMatch();
assertEquals(4, match.size());
checkEthDstMatch(match);
checkUpdDstMatch(match);
// Check flow command has correct instructions for OF 1.5
Instructions instructions = flowCommandData.getInstructions();
assertEquals(2, instructions.getApplyActions().size());
Action first = instructions.getApplyActions().get(0);
assertTrue(first instanceof MeterAction);
MeterAction meterAction = (MeterAction) first;
assertEquals(meterCommandData.getMeterId(), meterAction.getMeterId());
checkGroupAction(instructions.getApplyActions().get(1), groupCommandData.getGroupId());
assertNull(instructions.getWriteActions());
assertNull(instructions.getGoToMeter());
assertNull(instructions.getGoToTable());
// Check meter command
checkMeterCommand(meterCommandData);
// Check group command
checkGroupCommand(groupCommandData);
}
use of org.openkilda.rulemanager.MeterSpeakerData in project open-kilda by telstra.
the class SingleTableIngressYRuleGeneratorTest method buildCommandsVlanEncapsulationSingleVlanTest.
@Test
public void buildCommandsVlanEncapsulationSingleVlanTest() {
Flow flow = buildFlow(PATH, OUTER_VLAN_ID_1, 0);
SingleTableIngressYRuleGenerator generator = buildGenerator(PATH, flow, VLAN_ENCAPSULATION);
List<SpeakerData> commands = generator.generateCommands(SWITCH_1);
assertEquals(2, commands.size());
FlowSpeakerData ingressCommand = (FlowSpeakerData) commands.get(0);
MeterSpeakerData meterCommand = (MeterSpeakerData) commands.get(1);
assertEquals(newArrayList(meterCommand.getUuid()), new ArrayList<>(ingressCommand.getDependsOn()));
Set<FieldMatch> expectedIngressMatch = Sets.newHashSet(FieldMatch.builder().field(Field.IN_PORT).value(PORT_NUMBER_1).build(), FieldMatch.builder().field(Field.VLAN_VID).value(OUTER_VLAN_ID_1).build());
List<Action> expectedIngressActions = newArrayList(SetFieldAction.builder().field(Field.VLAN_VID).value(TRANSIT_VLAN_ID).build(), new PortOutAction(new PortNumber(PORT_NUMBER_2)));
assertIngressCommand(ingressCommand, Priority.Y_FLOW_PRIORITY, expectedIngressMatch, expectedIngressActions, SHARED_METER_ID);
assertMeterCommand(meterCommand);
}
use of org.openkilda.rulemanager.MeterSpeakerData in project open-kilda by telstra.
the class ConnectedDevicesRuleGeneratorTest method shouldBuildCorrectRuleWithMeterForOf15.
@Test
public void shouldBuildCorrectRuleWithMeterForOf15() {
sw = buildSwitch("OF_15", expectedFeatures);
List<SpeakerData> commands = generator.generateCommands(sw);
assertEquals(2, commands.size());
commands.forEach(c -> assertEquals(sw.getSwitchId(), c.getSwitchId()));
commands.forEach(c -> assertEquals(sw.getOfVersion(), c.getOfVersion().toString()));
FlowSpeakerData flowCommandData = getCommand(FlowSpeakerData.class, commands);
MeterSpeakerData meterCommandData = getCommand(MeterSpeakerData.class, commands);
assertEquals(1, flowCommandData.getDependsOn().size());
assertTrue(flowCommandData.getDependsOn().contains(meterCommandData.getUuid()));
assertTrue(meterCommandData.getDependsOn().isEmpty());
// Check flow command
checkFlowCommandBaseProperties(flowCommandData);
checkMatch(flowCommandData.getMatch());
// Check correct meter instructions for OF 1.5
checkInstructionsOf15(flowCommandData.getInstructions(), meterCommandData.getMeterId());
// Check meter command
checkMeterCommand(meterCommandData);
}
Aggregations