Search in sources :

Example 6 with MeterInfoEntry

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;
}
Also used : MeterInfoEntry(org.openkilda.messaging.info.switches.MeterInfoEntry) FlowPath(org.openkilda.model.FlowPath) FlowMeter(org.openkilda.model.FlowMeter)

Example 7 with 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);
}
Also used : RemoveFlowForSwitchManagerRequest(org.openkilda.messaging.command.flow.RemoveFlowForSwitchManagerRequest) MeterInfoEntry(org.openkilda.messaging.info.switches.MeterInfoEntry) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) DeleterMeterForSwitchManagerRequest(org.openkilda.messaging.command.switches.DeleterMeterForSwitchManagerRequest) InfoMessage(org.openkilda.messaging.info.InfoMessage) InstallFlowForSwitchManagerRequest(org.openkilda.messaging.command.flow.InstallFlowForSwitchManagerRequest) CommandData(org.openkilda.messaging.command.CommandData) Test(org.junit.Test)

Example 8 with MeterInfoEntry

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());
}
Also used : MeterInfoEntry(org.openkilda.messaging.info.switches.MeterInfoEntry) ValidateMetersResult(org.openkilda.wfm.topology.switchmanager.model.ValidateMetersResult) SwitchValidateRequest(org.openkilda.messaging.command.switches.SwitchValidateRequest) ValidationResult(org.openkilda.wfm.topology.switchmanager.model.ValidationResult) Test(org.junit.Test)

Example 9 with MeterInfoEntry

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());
}
Also used : ValidateRulesResult(org.openkilda.wfm.topology.switchmanager.model.ValidateRulesResult) MeterInfoEntry(org.openkilda.messaging.info.switches.MeterInfoEntry) ValidateMetersResult(org.openkilda.wfm.topology.switchmanager.model.ValidateMetersResult) SwitchValidateRequest(org.openkilda.messaging.command.switches.SwitchValidateRequest) ValidationResult(org.openkilda.wfm.topology.switchmanager.model.ValidationResult) Test(org.junit.Test)

Aggregations

MeterInfoEntry (org.openkilda.messaging.info.switches.MeterInfoEntry)9 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 ValidateMetersResult (org.openkilda.wfm.topology.switchmanager.model.ValidateMetersResult)4 FlowPath (org.openkilda.model.FlowPath)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 String.format (java.lang.String.format)2 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Slf4j (lombok.extern.slf4j.Slf4j)2 CommandData (org.openkilda.messaging.command.CommandData)2 RemoveFlow (org.openkilda.messaging.command.flow.RemoveFlow)2 SwitchValidateRequest (org.openkilda.messaging.command.switches.SwitchValidateRequest)2 ValidationResult (org.openkilda.wfm.topology.switchmanager.model.ValidationResult)2 Generators (com.fasterxml.uuid.Generators)1 NoArgGenerator (com.fasterxml.uuid.NoArgGenerator)1