Search in sources :

Example 11 with RemoveFlow

use of org.openkilda.messaging.command.flow.RemoveFlow 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 12 with RemoveFlow

use of org.openkilda.messaging.command.flow.RemoveFlow in project open-kilda by telstra.

the class RecordHandler method doReinstallDefaultFlowForSwitchManager.

/**
 * Reinstall default flow.
 *
 * @param message command message for flow deletion
 */
private void doReinstallDefaultFlowForSwitchManager(CommandMessage message) {
    ReinstallDefaultFlowForSwitchManagerRequest request = (ReinstallDefaultFlowForSwitchManagerRequest) message.getData();
    IKafkaProducerService producerService = getKafkaProducer();
    String replyToTopic = context.getKafkaSwitchManagerTopic();
    long cookie = request.getCookie();
    if (!Cookie.isDefaultRule(cookie)) {
        logger.warn("Failed to reinstall default switch rule for switch: '{}'. Rule {} is not default.", request.getSwitchId(), Long.toHexString(cookie));
        anError(ErrorType.DATA_INVALID).withMessage(format("Failed to reinstall default switch rule for switch %s. Rule %s is not default", request.getSwitchId(), Long.toHexString(cookie))).withDescription(request.getSwitchId().toString()).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
    }
    SwitchId switchId = request.getSwitchId();
    DatapathId dpid = DatapathId.of(switchId.toLong());
    try {
        RemoveFlow command = RemoveFlow.builder().flowId("REMOVE_DEFAULT_FLOW").cookie(cookie).switchId(switchId).build();
        Set<Long> removedFlows = new HashSet<>(processDeleteFlow(command, dpid));
        for (Long removedFlow : removedFlows) {
            Long installedFlow;
            if (request instanceof ReinstallServer42FlowForSwitchManagerRequest) {
                installedFlow = processInstallServer42Rule((ReinstallServer42FlowForSwitchManagerRequest) request);
            } else {
                installedFlow = processInstallDefaultFlowByCookie(switchId, removedFlow);
            }
            InfoMessage response = new InfoMessage(new FlowReinstallResponse(removedFlow, installedFlow), System.currentTimeMillis(), message.getCorrelationId());
            producerService.sendMessageAndTrack(replyToTopic, message.getCorrelationId(), response);
        }
    } catch (SwitchOperationException e) {
        logger.error("Failed to reinstall switch rule for switch: '{}'", request.getSwitchId(), e);
        anError(ErrorType.INTERNAL_ERROR).withMessage(e.getMessage()).withDescription(request.getSwitchId().toString()).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
    }
}
Also used : SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) ReinstallDefaultFlowForSwitchManagerRequest(org.openkilda.messaging.command.flow.ReinstallDefaultFlowForSwitchManagerRequest) FlowReinstallResponse(org.openkilda.messaging.info.flow.FlowReinstallResponse) SwitchId(org.openkilda.model.SwitchId) DatapathId(org.projectfloodlight.openflow.types.DatapathId) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) IKafkaProducerService(org.openkilda.floodlight.service.kafka.IKafkaProducerService) InfoMessage(org.openkilda.messaging.info.InfoMessage) ReinstallServer42FlowForSwitchManagerRequest(org.openkilda.messaging.command.flow.ReinstallServer42FlowForSwitchManagerRequest) HashSet(java.util.HashSet)

Aggregations

RemoveFlow (org.openkilda.messaging.command.flow.RemoveFlow)12 Test (org.junit.Test)6 CommandMessage (org.openkilda.messaging.command.CommandMessage)4 DeleteRulesCriteria (org.openkilda.messaging.command.switches.DeleteRulesCriteria)4 InfoMessage (org.openkilda.messaging.info.InfoMessage)4 FlowEntry (org.openkilda.messaging.info.rule.FlowEntry)4 FlowSegmentCookie (org.openkilda.model.cookie.FlowSegmentCookie)4 CommandData (org.openkilda.messaging.command.CommandData)3 IOException (java.io.IOException)2 Values (org.apache.storm.tuple.Values)2 Message (org.openkilda.messaging.Message)2 BaseInstallFlow (org.openkilda.messaging.command.flow.BaseInstallFlow)2 InstallFlowForSwitchManagerRequest (org.openkilda.messaging.command.flow.InstallFlowForSwitchManagerRequest)2 ReinstallDefaultFlowForSwitchManagerRequest (org.openkilda.messaging.command.flow.ReinstallDefaultFlowForSwitchManagerRequest)2 RemoveFlowForSwitchManagerRequest (org.openkilda.messaging.command.flow.RemoveFlowForSwitchManagerRequest)2 ErrorMessage (org.openkilda.messaging.error.ErrorMessage)2 DatapathId (org.projectfloodlight.openflow.types.DatapathId)2 HashSet (java.util.HashSet)1 SwitchOperationException (org.openkilda.floodlight.error.SwitchOperationException)1 UnsupportedSwitchOperationException (org.openkilda.floodlight.error.UnsupportedSwitchOperationException)1