Search in sources :

Example 1 with ReinstallServer42FlowForSwitchManagerRequest

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

the class CommandBuilderImplTest method reinstallServer42RuleTest.

@Test
public void reinstallServer42RuleTest() {
    List<ReinstallDefaultFlowForSwitchManagerRequest> commands = commandBuilder.buildCommandsToReinstallRules(SWITCH_ID_A, Lists.newArrayList(Cookie.SERVER_42_FLOW_RTT_OUTPUT_VLAN_COOKIE));
    assertEquals(1, commands.size());
    assertEquals(ReinstallServer42FlowForSwitchManagerRequest.class, commands.get(0).getClass());
    ReinstallServer42FlowForSwitchManagerRequest server42Command = (ReinstallServer42FlowForSwitchManagerRequest) commands.get(0);
    assertEquals(SERVER42_MAC_ADDRESS, server42Command.getServer42MacAddress());
    assertEquals(SERVER42_PORT, server42Command.getServer42Port());
    assertEquals(SERVER42_VLAN, server42Command.getServer42Vlan());
}
Also used : ReinstallDefaultFlowForSwitchManagerRequest(org.openkilda.messaging.command.flow.ReinstallDefaultFlowForSwitchManagerRequest) ReinstallServer42FlowForSwitchManagerRequest(org.openkilda.messaging.command.flow.ReinstallServer42FlowForSwitchManagerRequest) Test(org.junit.Test)

Example 2 with ReinstallServer42FlowForSwitchManagerRequest

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

the class RecordHandlerTest method reinstallServer42FlowRttOutputVlanTest.

@Test
public void reinstallServer42FlowRttOutputVlanTest() throws SwitchOperationException {
    long cookie = SERVER_42_FLOW_RTT_OUTPUT_VLAN_COOKIE;
    expect(switchManager.installServer42FlowRttOutputVlanFlow(DATAPATH_ID, SERVER42_PORT, SERVER42_VLAN, SERVER42_MAC_ADDRESS)).andReturn(cookie).once();
    expect(switchManager.deleteRulesByCriteria(DATAPATH_ID, false, null, DeleteRulesCriteria.builder().cookie(cookie).build())).andReturn(Lists.newArrayList(cookie)).once();
    replay(switchManager);
    ReinstallServer42FlowForSwitchManagerRequest request = new ReinstallServer42FlowForSwitchManagerRequest(SWITCH_ID, cookie, SERVER42_MAC_ADDRESS, SERVER42_VLAN, SERVER42_PORT);
    recordHandler.handleCommand(new CommandMessage(request, 0, null));
    verify(switchManager);
}
Also used : ReinstallServer42FlowForSwitchManagerRequest(org.openkilda.messaging.command.flow.ReinstallServer42FlowForSwitchManagerRequest) CommandMessage(org.openkilda.messaging.command.CommandMessage) Test(org.junit.Test)

Example 3 with ReinstallServer42FlowForSwitchManagerRequest

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

the class RecordHandlerTest method shouldReinstallServer42IslRttOutputRule.

@Test
public void shouldReinstallServer42IslRttOutputRule() throws SwitchOperationException {
    long cookie = SERVER_42_ISL_RTT_OUTPUT_COOKIE;
    expect(switchManager.installServer42IslRttOutputFlow(DATAPATH_ID, SERVER42_PORT, SERVER42_VLAN, SERVER42_MAC_ADDRESS)).andReturn(cookie).once();
    expect(switchManager.deleteRulesByCriteria(DATAPATH_ID, false, null, DeleteRulesCriteria.builder().cookie(cookie).build())).andReturn(Lists.newArrayList(cookie)).once();
    replay(switchManager);
    ReinstallServer42FlowForSwitchManagerRequest request = new ReinstallServer42FlowForSwitchManagerRequest(SWITCH_ID, cookie, SERVER42_MAC_ADDRESS, SERVER42_VLAN, SERVER42_PORT);
    recordHandler.handleCommand(new CommandMessage(request, 0, null));
    verify(switchManager);
}
Also used : ReinstallServer42FlowForSwitchManagerRequest(org.openkilda.messaging.command.flow.ReinstallServer42FlowForSwitchManagerRequest) CommandMessage(org.openkilda.messaging.command.CommandMessage) Test(org.junit.Test)

Example 4 with ReinstallServer42FlowForSwitchManagerRequest

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

the class RecordHandlerTest method shouldReinstallServer42IslRttInputRule.

@Test
public void shouldReinstallServer42IslRttInputRule() throws SwitchOperationException {
    int islPort = 123;
    PortColourCookie cookie = PortColourCookie.builder().portNumber(islPort).type(SERVER_42_ISL_RTT_INPUT).build();
    expect(switchManager.installServer42IslRttInputFlow(DATAPATH_ID, SERVER42_PORT, islPort)).andReturn(cookie.getValue()).once();
    expect(switchManager.deleteRulesByCriteria(DATAPATH_ID, false, null, DeleteRulesCriteria.builder().cookie(cookie.getValue()).build())).andReturn(Lists.newArrayList(cookie.getValue())).once();
    replay(switchManager);
    ReinstallServer42FlowForSwitchManagerRequest request = new ReinstallServer42FlowForSwitchManagerRequest(SWITCH_ID, cookie.getValue(), SERVER42_MAC_ADDRESS, SERVER42_VLAN, SERVER42_PORT);
    recordHandler.handleCommand(new CommandMessage(request, 0, null));
    verify(switchManager);
}
Also used : ReinstallServer42FlowForSwitchManagerRequest(org.openkilda.messaging.command.flow.ReinstallServer42FlowForSwitchManagerRequest) PortColourCookie(org.openkilda.model.cookie.PortColourCookie) CommandMessage(org.openkilda.messaging.command.CommandMessage) Test(org.junit.Test)

Example 5 with ReinstallServer42FlowForSwitchManagerRequest

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

ReinstallServer42FlowForSwitchManagerRequest (org.openkilda.messaging.command.flow.ReinstallServer42FlowForSwitchManagerRequest)8 Test (org.junit.Test)6 CommandMessage (org.openkilda.messaging.command.CommandMessage)5 ReinstallDefaultFlowForSwitchManagerRequest (org.openkilda.messaging.command.flow.ReinstallDefaultFlowForSwitchManagerRequest)3 PortColourCookie (org.openkilda.model.cookie.PortColourCookie)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 SwitchOperationException (org.openkilda.floodlight.error.SwitchOperationException)1 UnsupportedSwitchOperationException (org.openkilda.floodlight.error.UnsupportedSwitchOperationException)1 IKafkaProducerService (org.openkilda.floodlight.service.kafka.IKafkaProducerService)1 RemoveFlow (org.openkilda.messaging.command.flow.RemoveFlow)1 InfoMessage (org.openkilda.messaging.info.InfoMessage)1 FlowReinstallResponse (org.openkilda.messaging.info.flow.FlowReinstallResponse)1 SwitchId (org.openkilda.model.SwitchId)1 SwitchProperties (org.openkilda.model.SwitchProperties)1 DatapathId (org.projectfloodlight.openflow.types.DatapathId)1