use of org.openkilda.messaging.info.switches.MeterInfoEntry in project open-kilda by telstra.
the class ValidationServiceImpl method convertMeter.
private MeterInfoEntry convertMeter(SwitchId switchId, MeterSpeakerData meterSpeakerData) {
MeterInfoEntry meterInfoEntry = MeterEntryConverter.INSTANCE.toMeterEntry(meterSpeakerData);
Optional<FlowMeter> flowMeter = flowMeterRepository.findById(switchId, meterSpeakerData.getMeterId());
if (flowMeter.isPresent()) {
meterInfoEntry.setFlowId(flowMeter.get().getFlowId());
Optional<FlowPath> flowPath = flowPathRepository.findById(flowMeter.get().getPathId());
if (flowPath.isPresent()) {
meterInfoEntry.setCookie(flowPath.get().getCookie().getValue());
}
}
return meterInfoEntry;
}
use of org.openkilda.messaging.info.switches.MeterInfoEntry in project open-kilda by telstra.
the class SwitchSyncServiceImplTest method handleSyncExcess.
@Test
public void handleSyncExcess() {
request = SwitchValidateRequest.builder().switchId(SWITCH_ID).performSync(true).removeExcess(true).build();
excessRules = singletonList(EXCESS_COOKIE);
excessMeters = singletonList(new MeterInfoEntry(EXCESS_COOKIE, EXCESS_COOKIE, FLOW_ID, 0L, 0L, new String[] {}, null, null));
RemoveFlow removeFlow = RemoveFlow.builder().transactionId(UUID.randomUUID()).flowId(FLOW_ID).cookie(EXCESS_COOKIE).switchId(SWITCH_ID).meterId(EXCESS_COOKIE).build();
when(commandBuilder.buildCommandsToRemoveExcessRules(eq(SWITCH_ID), any(), any())).thenReturn(singletonList(removeFlow));
service.handleSwitchSync(KEY, request, makeValidationResult());
verify(commandBuilder).buildCommandsToSyncMissingRules(eq(SWITCH_ID), eq(missingRules));
verify(commandBuilder).buildCommandsToRemoveExcessRules(eq(SWITCH_ID), eq(singletonList(flowEntry)), eq(excessRules));
verify(carrier).sendCommandToSpeaker(eq(KEY), any(DeleterMeterForSwitchManagerRequest.class));
service.handleRemoveMetersResponse(KEY);
verify(carrier).sendCommandToSpeaker(eq(KEY), any(InstallFlowForSwitchManagerRequest.class));
verify(carrier).sendCommandToSpeaker(eq(KEY), any(RemoveFlowForSwitchManagerRequest.class));
service.handleInstallRulesResponse(KEY);
service.handleRemoveRulesResponse(KEY);
verify(carrier, times(3)).sendCommandToSpeaker(eq(KEY), any(CommandData.class));
verify(carrier).cancelTimeoutCallback(eq(KEY));
verify(carrier).response(eq(KEY), any(InfoMessage.class));
verifyNoMoreInteractions(commandBuilder);
verifyNoMoreInteractions(carrier);
}
use of org.openkilda.messaging.info.switches.MeterInfoEntry in project open-kilda by telstra.
the class SwitchSyncFsmTest method getModifyDefaultMetersWithFlowMeters.
@Test
public void getModifyDefaultMetersWithFlowMeters() {
ArrayList<MeterInfoEntry> misconfiguredMeters = newArrayList(MeterInfoEntry.builder().cookie(COOKIE_1).meterId((long) MeterId.MIN_FLOW_METER_ID).build());
ValidateMetersResult validateMetersResult = new ValidateMetersResult(newArrayList(), misconfiguredMeters, newArrayList(), newArrayList());
ValidationResult validationResult = new ValidationResult(new ArrayList<>(), true, EMPTY_VALIDATE_RULES_RESULT, validateMetersResult, EMPTY_VALIDATE_GROUPS_RESULT, EMPTY_LOGICAL_PORTS_RESULT);
SwitchSyncFsm fsm = new SwitchSyncFsm(null, null, null, new SwitchValidateRequest(SWITCH_ID, true, true, true), validationResult);
assertTrue(fsm.getModifyDefaultMeters().isEmpty());
}
use of org.openkilda.messaging.info.switches.MeterInfoEntry in project open-kilda by telstra.
the class SwitchSyncFsmTest method getModifyDefaultMetersWithMissingRulesTest.
@Test
public void getModifyDefaultMetersWithMissingRulesTest() {
ValidateRulesResult validateRulesResult = new ValidateRulesResult(newHashSet(COOKIE_1), newHashSet(), newHashSet(), newHashSet(COOKIE_2));
ArrayList<MeterInfoEntry> misconfiguredMeters = newArrayList(MeterInfoEntry.builder().cookie(COOKIE_1).meterId(METER_ID_1).build(), MeterInfoEntry.builder().cookie(COOKIE_2).meterId(METER_ID_2).build(), MeterInfoEntry.builder().cookie(COOKIE_3).meterId(METER_ID_3).build());
ValidateMetersResult validateMetersResult = new ValidateMetersResult(newArrayList(), misconfiguredMeters, newArrayList(), newArrayList());
ValidationResult validationResult = new ValidationResult(new ArrayList<>(), true, validateRulesResult, validateMetersResult, EMPTY_VALIDATE_GROUPS_RESULT, EMPTY_LOGICAL_PORTS_RESULT);
SwitchSyncFsm fsm = new SwitchSyncFsm(null, null, null, new SwitchValidateRequest(SWITCH_ID, true, true, true), validationResult);
List<Long> modifyMeters = fsm.getModifyDefaultMeters();
assertEquals(1, modifyMeters.size());
assertEquals(METER_ID_3, modifyMeters.get(0).longValue());
}
Aggregations