use of org.openkilda.model.MeterId in project open-kilda by telstra.
the class ValidationServiceImplTest method validateMetersProperMeters.
@Test
public void validateMetersProperMeters() {
ValidationService validationService = new ValidationServiceImpl(persistenceManager().build());
MeterSpeakerData meter = MeterSpeakerData.builder().meterId(new MeterId(32)).rate(10000).burst(10500).ofVersion(OfVersion.OF_13).flags(Sets.newHashSet(MeterFlag.KBPS, MeterFlag.BURST, MeterFlag.STATS)).build();
ValidateMetersResult response = validationService.validateMeters(SWITCH_ID_B, singletonList(meter), singletonList(meter));
assertTrue(response.getMissingMeters().isEmpty());
assertTrue(response.getMisconfiguredMeters().isEmpty());
assertFalse(response.getProperMeters().isEmpty());
assertEquals(meter.getMeterId().getValue(), response.getProperMeters().get(0).getMeterId().longValue());
assertMeter(response.getProperMeters().get(0), 32, 10000, 10500, new String[] { "KBPS", "BURST", "STATS" });
assertTrue(response.getExcessMeters().isEmpty());
}
use of org.openkilda.model.MeterId in project open-kilda by telstra.
the class UniCastDiscoveryRuleGenerator method generateCommands.
@Override
public List<SpeakerData> generateCommands(Switch sw) {
List<SpeakerData> commands = new ArrayList<>();
Instructions instructions = Instructions.builder().applyActions(new ArrayList<>()).build();
FlowSpeakerData flowCommand = buildRule(sw, instructions);
if (flowCommand == null) {
return Collections.emptyList();
} else {
commands.add(flowCommand);
}
MeterId meterId = createMeterIdForDefaultRule(VERIFICATION_UNICAST_RULE_COOKIE);
SpeakerData meterCommand = generateMeterCommandForServiceRule(sw, meterId, config.getUnicastRateLimit(), config.getSystemMeterBurstSizeInPackets(), config.getDiscoPacketSize());
if (meterCommand != null) {
commands.add(meterCommand);
addMeterToInstructions(meterId, sw, instructions);
}
instructions.getApplyActions().add(new PortOutAction(new PortNumber(SpecialPortType.CONTROLLER)));
// todo remove useless set field action
instructions.getApplyActions().add(SetFieldAction.builder().field(Field.ETH_DST).value(sw.getSwitchId().toLong()).build());
if (meterCommand != null) {
flowCommand.getDependsOn().add(meterCommand.getUuid());
}
return commands;
}
use of org.openkilda.model.MeterId in project open-kilda by telstra.
the class SwitchValidateServiceImplTest method setUp.
@Before
public void setUp() {
RepositoryFactory repositoryFactory = Mockito.mock(RepositoryFactory.class);
FlowPathRepository flowPathRepository = Mockito.mock(FlowPathRepository.class);
SwitchRepository switchRepository = Mockito.mock(SwitchRepository.class);
when(switchRepository.findById(eq(SWITCH_ID))).thenReturn(Optional.of(SWITCH_1));
when(switchRepository.findById(eq(SWITCH_ID_MISSING))).thenReturn(Optional.empty());
LagLogicalPortRepository lagLogicalPortRepository = Mockito.mock(LagLogicalPortRepository.class);
when(repositoryFactory.createFlowPathRepository()).thenReturn(flowPathRepository);
when(repositoryFactory.createSwitchRepository()).thenReturn(switchRepository);
when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
service = new SwitchValidateServiceImpl(carrier, persistenceManager, validationService, ruleManager);
request = SwitchValidateRequest.builder().switchId(SWITCH_ID).processMeters(true).build();
flowSpeakerData = FlowSpeakerData.builder().ofVersion(OfVersion.OF_13).cookie(new Cookie(1L)).table(OfTable.INPUT).priority(10).match(emptySet()).instructions(Instructions.builder().build()).flags(emptySet()).build();
meterSpeakerData = MeterSpeakerData.builder().meterId(new MeterId(32)).rate(10000).burst(10500).ofVersion(OfVersion.OF_13).flags(Sets.newHashSet(MeterFlag.KBPS, MeterFlag.BURST, MeterFlag.STATS)).build();
when(validationService.validateRules(any(), any(), any())).thenReturn(new ValidateRulesResult(newHashSet(flowSpeakerData.getCookie().getValue()), emptySet(), emptySet(), emptySet()));
when(validationService.validateMeters(any(), any(), any())).thenReturn(new ValidateMetersResult(emptyList(), emptyList(), emptyList(), emptyList()));
}
use of org.openkilda.model.MeterId in project open-kilda by telstra.
the class DatabaseSupportImpl method updateFlowMeterId.
@Override
public void updateFlowMeterId(String flowId, long newMeterId) {
// TODO(andriidovhan) rewrite it, FlowPair flowPair -> Flow
// FlowPair flowPair = flowPairRepository.findById(flowId)
// .orElseThrow(() -> new RuntimeException(format("Unable to find Flow for %s", flowId)));
// flowPair.getForward().setMeterId(newMeterId.getValue());
// flowPair.getReverse().setMeterId(newMeterId.getValue());
// flowRepository.createOrUpdate(flowPair);
// flow path
transactionManager.doInTransaction(() -> {
Collection<FlowPath> flowPaths = flowPathRepository.findByFlowId(flowId);
long meterId = newMeterId;
for (FlowPath flowPath : flowPaths) {
flowPath.setMeterId(new MeterId(meterId));
Optional<FlowMeter> meter = flowMeterRepository.findByPathId(flowPath.getPathId());
if (meter.isPresent()) {
meter.get().setMeterId(new MeterId(meterId++));
}
}
});
}
use of org.openkilda.model.MeterId in project open-kilda by telstra.
the class RuleManagerImpl method buildIngressYFlowCommands.
private List<SpeakerData> buildIngressYFlowCommands(FlowPath flowPath, FlowPath altFlowPath, DataAdapter adapter) {
Flow flow = adapter.getFlow(flowPath.getPathId());
Flow altFlow = adapter.getFlow(altFlowPath.getPathId());
if (flow.isProtectedPath(flowPath.getPathId()) || altFlow.isProtectedPath(altFlowPath.getPathId())) {
return Collections.emptyList();
}
YFlow yFlow = adapter.getYFlow(flowPath.getPathId());
if (yFlow == null) {
return Collections.emptyList();
}
SwitchId sharedSwitchId = yFlow.getSharedEndpoint().getSwitchId();
Switch sharedSwitch = adapter.getSwitch(sharedSwitchId);
if (sharedSwitch == null || !sharedSwitchId.equals(flowPath.getSrcSwitchId()) || !sharedSwitchId.equals(altFlowPath.getSrcSwitchId())) {
return Collections.emptyList();
}
FlowTransitEncapsulation encapsulation = getFlowTransitEncapsulation(flowPath.getPathId(), flow, adapter);
FlowTransitEncapsulation altEncapsulation = getFlowTransitEncapsulation(altFlowPath.getPathId(), altFlow, adapter);
MeterId sharedMeterId = yFlow.getSharedEndpointMeterId();
RuleGenerator generator = flowRulesFactory.getIngressYRuleGenerator(flowPath, flow, encapsulation, new HashSet<>(), altFlowPath, altFlow, altEncapsulation, new HashSet<>(), sharedMeterId);
return generator.generateCommands(sharedSwitch);
}
Aggregations