Search in sources :

Example 1 with RemoveFlow

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

the class SpeakerBolt method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute(Tuple tuple) {
    String request = tuple.getString(0);
    Values values = null;
    try {
        Message message = MAPPER.readValue(request, Message.class);
        if (!Destination.WFM_TRANSACTION.equals(message.getDestination())) {
            return;
        }
        logger.debug("Request tuple={}", tuple);
        if (message instanceof CommandMessage) {
            CommandData data = ((CommandMessage) message).getData();
            if (data instanceof BaseInstallFlow) {
                Long transactionId = ((BaseInstallFlow) data).getTransactionId();
                String switchId = ((BaseInstallFlow) data).getSwitchId();
                String flowId = ((BaseInstallFlow) data).getId();
                logger.debug("Flow install message: {}={}, switch-id={}, {}={}, {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), switchId, Utils.FLOW_ID, flowId, Utils.TRANSACTION_ID, transactionId, request);
                message.setDestination(Destination.TOPOLOGY_ENGINE);
                values = new Values(MAPPER.writeValueAsString(message), switchId, flowId, transactionId);
                // FIXME(surabujin): looks like TE ignore this messages
                outputCollector.emit(StreamType.CREATE.toString(), tuple, values);
            } else if (data instanceof RemoveFlow) {
                Long transactionId = ((RemoveFlow) data).getTransactionId();
                String switchId = ((RemoveFlow) data).getSwitchId();
                String flowId = ((RemoveFlow) data).getId();
                logger.debug("Flow remove message: {}={}, switch-id={}, {}={}, {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), switchId, Utils.FLOW_ID, flowId, Utils.TRANSACTION_ID, transactionId, request);
                message.setDestination(Destination.TOPOLOGY_ENGINE);
                values = new Values(MAPPER.writeValueAsString(message), switchId, flowId, transactionId);
                outputCollector.emit(StreamType.DELETE.toString(), tuple, values);
            } else {
                logger.debug("Skip undefined command message: {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), request);
            }
        } else if (message instanceof ErrorMessage) {
            String flowId = ((ErrorMessage) message).getData().getErrorDescription();
            FlowState status = FlowState.DOWN;
            // TODO: Should add debug message if receiving ErrorMessage.
            if (flowId != null) {
                logger.error("Flow error message: {}={}, {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), Utils.FLOW_ID, flowId, request);
                values = new Values(flowId, status);
                outputCollector.emit(StreamType.STATUS.toString(), tuple, values);
            } else {
                logger.debug("Skip error message without flow-id: {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), request);
            }
        } else {
            // TODO: should this be a warn or error? Probably, after refactored / specific
            // topics
            logger.debug("Skip undefined message: {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), request);
        }
    } catch (IOException exception) {
        logger.error("\n\nCould not deserialize message={}", request, exception);
    } finally {
        logger.debug("Speaker message ack: component={}, stream={}, tuple={}, values={}", tuple.getSourceComponent(), tuple.getSourceStreamId(), tuple, values);
        outputCollector.ack(tuple);
    }
}
Also used : FlowState(org.openkilda.messaging.payload.flow.FlowState) Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) Values(org.apache.storm.tuple.Values) BaseInstallFlow(org.openkilda.messaging.command.flow.BaseInstallFlow) IOException(java.io.IOException) CommandData(org.openkilda.messaging.command.CommandData) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 2 with RemoveFlow

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

the class TopologyEngineBolt method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute(Tuple tuple) {
    String request = tuple.getString(0);
    Values values = null;
    try {
        Message message = MAPPER.readValue(request, Message.class);
        if (!Destination.WFM.equals(message.getDestination())) {
            return;
        }
        logger.debug("Request tuple={}", tuple);
        if (message instanceof CommandMessage) {
            CommandData data = ((CommandMessage) message).getData();
            if (data instanceof BaseInstallFlow) {
                BaseInstallFlow installData = (BaseInstallFlow) data;
                Long transactionId = UUID.randomUUID().getLeastSignificantBits();
                installData.setTransactionId(transactionId);
                String switchId = installData.getSwitchId();
                String flowId = installData.getId();
                logger.debug("Flow install message: {}={}, switch-id={}, {}={}, {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), switchId, Utils.FLOW_ID, flowId, Utils.TRANSACTION_ID, transactionId, request);
                // FIXME(surabujin): send here and in TE
                message.setDestination(Destination.CONTROLLER);
                values = new Values(MAPPER.writeValueAsString(message), switchId, flowId, transactionId);
                outputCollector.emit(StreamType.CREATE.toString(), tuple, values);
            } else if (data instanceof RemoveFlow) {
                RemoveFlow removeData = (RemoveFlow) data;
                Long transactionId = UUID.randomUUID().getLeastSignificantBits();
                removeData.setTransactionId(transactionId);
                String switchId = removeData.getSwitchId();
                String flowId = removeData.getId();
                logger.debug("Flow remove message: {}={}, switch-id={}, {}={}, {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), switchId, Utils.FLOW_ID, flowId, Utils.TRANSACTION_ID, transactionId, request);
                message.setDestination(Destination.CONTROLLER);
                values = new Values(MAPPER.writeValueAsString(message), switchId, flowId, transactionId);
                outputCollector.emit(StreamType.DELETE.toString(), tuple, values);
            } else {
                logger.debug("Skip undefined command message: {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), request);
            }
        } else if (message instanceof InfoMessage) {
            values = new Values(message);
            logger.debug("Flow response message: {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), request);
            outputCollector.emit(StreamType.RESPONSE.toString(), tuple, values);
        } else if (message instanceof ErrorMessage) {
            String flowId = ((ErrorMessage) message).getData().getErrorDescription();
            logger.error("Flow error message: {}={}, {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), Utils.FLOW_ID, flowId, request);
            values = new Values(message, flowId);
            outputCollector.emit(StreamType.STATUS.toString(), tuple, values);
        } else {
            logger.debug("Skip undefined message: {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), request);
        }
    } catch (IOException exception) {
        logger.error("Could not deserialize message={}", request, exception);
    } finally {
        logger.debug("Topology-Engine message ack: component={}, stream={}, tuple={}, values={}", tuple.getSourceComponent(), tuple.getSourceStreamId(), tuple, values);
        outputCollector.ack(tuple);
    }
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) InfoMessage(org.openkilda.messaging.info.InfoMessage) Values(org.apache.storm.tuple.Values) BaseInstallFlow(org.openkilda.messaging.command.flow.BaseInstallFlow) IOException(java.io.IOException) CommandData(org.openkilda.messaging.command.CommandData) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 3 with RemoveFlow

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

the class FlowTopologyTest method removeFlowTopologyEngineSpeakerBoltTest.

@Test
public void removeFlowTopologyEngineSpeakerBoltTest() throws Exception {
    String flowId = UUID.randomUUID().toString();
    ConsumerRecord<String, String> ofsRecord;
    ConsumerRecord<String, String> record;
    createFlow(flowId);
    record = cacheConsumer.pollMessage();
    assertNotNull(record);
    assertNotNull(record.value());
    record = nbConsumer.pollMessage();
    assertNotNull(record);
    assertNotNull(record.value());
    statusFlow(flowId);
    record = nbConsumer.pollMessage();
    assertNotNull(record);
    assertNotNull(record.value());
    InfoMessage infoMessage = objectMapper.readValue(record.value(), InfoMessage.class);
    assertNotNull(infoMessage);
    FlowStatusResponse infoData = (FlowStatusResponse) infoMessage.getData();
    assertNotNull(infoData);
    FlowIdStatusPayload flowNbPayload = infoData.getPayload();
    assertNotNull(flowNbPayload);
    assertEquals(flowId, flowNbPayload.getId());
    assertEquals(FlowState.ALLOCATED, flowNbPayload.getStatus());
    RemoveFlow data = removeFlowCommand(flowId);
    ofsRecord = ofsConsumer.pollMessage();
    assertNotNull(ofsRecord);
    assertNotNull(ofsRecord.value());
    CommandMessage response = objectMapper.readValue(ofsRecord.value(), CommandMessage.class);
    assertNotNull(response);
    RemoveFlow responseData = (RemoveFlow) response.getData();
    Long transactionId = responseData.getTransactionId();
    responseData.setTransactionId(0L);
    assertEquals(data, responseData);
    responseData.setTransactionId(transactionId);
    statusFlow(flowId);
    record = nbConsumer.pollMessage();
    assertNotNull(record);
    assertNotNull(record.value());
    infoMessage = objectMapper.readValue(record.value(), InfoMessage.class);
    assertNotNull(infoMessage);
    infoData = (FlowStatusResponse) infoMessage.getData();
    assertNotNull(infoData);
    flowNbPayload = infoData.getPayload();
    assertNotNull(flowNbPayload);
    assertEquals(flowId, flowNbPayload.getId());
    assertEquals(FlowState.IN_PROGRESS, flowNbPayload.getStatus());
    response.setDestination(Destination.WFM_TRANSACTION);
    removeRuleCommand(response);
    statusFlow(flowId);
    record = nbConsumer.pollMessage();
    assertNotNull(record);
    assertNotNull(record.value());
    infoMessage = objectMapper.readValue(record.value(), InfoMessage.class);
    assertNotNull(infoMessage);
    infoData = (FlowStatusResponse) infoMessage.getData();
    assertNotNull(infoData);
    flowNbPayload = infoData.getPayload();
    assertNotNull(flowNbPayload);
    assertEquals(flowId, flowNbPayload.getId());
    assertEquals(FlowState.UP, flowNbPayload.getStatus());
}
Also used : FlowStatusResponse(org.openkilda.messaging.info.flow.FlowStatusResponse) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) FlowIdStatusPayload(org.openkilda.messaging.payload.flow.FlowIdStatusPayload) InfoMessage(org.openkilda.messaging.info.InfoMessage) CommandMessage(org.openkilda.messaging.command.CommandMessage) AbstractStormTest(org.openkilda.wfm.AbstractStormTest) Test(org.junit.Test)

Example 4 with RemoveFlow

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

the class CommandBuilderImplTest method shouldBuildRemoveFlowWithoutMeterFromFlowEntryWithStringOutPort.

@Test
public void shouldBuildRemoveFlowWithoutMeterFromFlowEntryWithStringOutPort() {
    Long cookie = new FlowSegmentCookie(FlowPathDirection.FORWARD, 1).getValue();
    String inPort = "1";
    String inVlan = "10";
    String outPort = "in_port";
    FlowEntry flowEntry = buildFlowEntry(cookie, inPort, inVlan, outPort, null, false, null, null);
    RemoveFlow removeFlow = commandBuilder.buildRemoveFlowWithoutMeterFromFlowEntry(SWITCH_ID_A, flowEntry);
    assertEquals(cookie, removeFlow.getCookie());
    DeleteRulesCriteria criteria = removeFlow.getCriteria();
    assertEquals(cookie, criteria.getCookie());
    assertEquals(Integer.valueOf(inPort), criteria.getInPort());
    assertEquals(Integer.valueOf(inVlan), criteria.getEncapsulationId());
    assertNull(criteria.getOutPort());
    assertNull(criteria.getMetadataValue());
    assertNull(criteria.getMetadataMask());
}
Also used : FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) DeleteRulesCriteria(org.openkilda.messaging.command.switches.DeleteRulesCriteria) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry) Test(org.junit.Test)

Example 5 with RemoveFlow

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

the class CommandBuilderImplTest method shouldBuildRemoveFlowWithoutMeterFromFlowEntryWithVxlanEncapsulationIngress.

@Test
public void shouldBuildRemoveFlowWithoutMeterFromFlowEntryWithVxlanEncapsulationIngress() {
    Long cookie = new FlowSegmentCookie(FlowPathDirection.FORWARD, 1).getValue();
    String inPort = "1";
    String outPort = "2";
    String tunnelId = "10";
    String metadataValue = "0x15";
    String metadataMask = "0xFF";
    FlowEntry flowEntry = buildFlowEntry(cookie, inPort, null, outPort, tunnelId, true, metadataValue, metadataMask);
    RemoveFlow removeFlow = commandBuilder.buildRemoveFlowWithoutMeterFromFlowEntry(SWITCH_ID_A, flowEntry);
    assertEquals(cookie, removeFlow.getCookie());
    DeleteRulesCriteria criteria = removeFlow.getCriteria();
    assertEquals(cookie, criteria.getCookie());
    assertEquals(Integer.valueOf(inPort), criteria.getInPort());
    assertNull(criteria.getEncapsulationId());
    assertEquals(Integer.valueOf(outPort), criteria.getOutPort());
    assertEquals(Long.decode(metadataValue), criteria.getMetadataValue());
    assertEquals(Long.decode(metadataMask), criteria.getMetadataMask());
}
Also used : FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) DeleteRulesCriteria(org.openkilda.messaging.command.switches.DeleteRulesCriteria) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry) Test(org.junit.Test)

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