Search in sources :

Example 51 with CommandMessage

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

the class Flow method getInstallationCommands.

/**
 * Returns set of installation commands.
 *
 * @param path          sorted path
 * @param correlationId correlation id
 * @return set of {@link CommandMessage} instances
 */
public Set<CommandMessage> getInstallationCommands(final List<Isl> path, final String correlationId) {
    Set<CommandMessage> commands = new HashSet<>();
    Isl firstIsl = path.get(0);
    Isl lastIsl = path.get(path.size() - 1);
    if ((cookie & DIRECT_FLOW_COOKIE) == DIRECT_FLOW_COOKIE) {
        commands.add(new CommandMessage(new InstallIngressFlow(0L, flowId, cookie, sourceSwitch, sourcePort, firstIsl.getSourcePort(), sourceVlan, transitVlan, flowType, bandwidth, 0L), now(), correlationId, Destination.WFM));
        commands.add(new CommandMessage(new InstallEgressFlow(0L, flowId, cookie, destinationSwitch, lastIsl.getDestinationPort(), destinationPort, transitVlan, destinationVlan, flowType), now(), correlationId, Destination.WFM));
    } else {
        commands.add(new CommandMessage(new InstallIngressFlow(0L, flowId, cookie, destinationSwitch, sourcePort, lastIsl.getDestinationPort(), destinationVlan, transitVlan, getReverseFlowType(flowType), bandwidth, 0L), now(), correlationId, Destination.WFM));
        commands.add(new CommandMessage(new InstallEgressFlow(0L, flowId, cookie, sourceSwitch, firstIsl.getSourcePort(), sourcePort, transitVlan, sourceVlan, getReverseFlowType(flowType)), now(), correlationId, Destination.WFM));
    }
    for (int i = 0; i < path.size() - 1; i++) {
        Isl currentIsl = path.get(i);
        Isl nextIsl = path.get(i + 1);
        if ((cookie & DIRECT_FLOW_COOKIE) == DIRECT_FLOW_COOKIE) {
            commands.add(new CommandMessage(new InstallTransitFlow(0L, flowId, cookie, currentIsl.getDestinationSwitch(), currentIsl.getDestinationPort(), nextIsl.getSourcePort(), transitVlan), now(), correlationId, Destination.WFM));
        } else {
            commands.add(new CommandMessage(new InstallTransitFlow(0L, flowId, cookie, currentIsl.getDestinationSwitch(), nextIsl.getSourcePort(), currentIsl.getDestinationPort(), transitVlan), now(), correlationId, Destination.WFM));
        }
    }
    return commands;
}
Also used : InstallIngressFlow(org.openkilda.messaging.command.flow.InstallIngressFlow) InstallTransitFlow(org.openkilda.messaging.command.flow.InstallTransitFlow) InstallEgressFlow(org.openkilda.messaging.command.flow.InstallEgressFlow) CommandMessage(org.openkilda.messaging.command.CommandMessage) HashSet(java.util.HashSet)

Example 52 with CommandMessage

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

the class FlowServiceImpl method createFlow.

/**
 * {@inheritDoc}
 */
@Override
public Set<CommandMessage> createFlow(final FlowPayload payload, final String correlationId) {
    Switch source = switchRepository.findByName(payload.getSource().getSwitchId());
    Switch destination = switchRepository.findByName(payload.getDestination().getSwitchId());
    if (source == null || destination == null) {
        logger.error("Switches not found: source={}, destination={}", payload.getSource().getSwitchId(), payload.getDestination().getSwitchId());
        throw new MessageException(ErrorType.NOT_FOUND, System.currentTimeMillis());
    }
    List<Isl> path = islRepository.getPath(source.getName(), destination.getName());
    if (path == null || path.isEmpty()) {
        logger.error("Path not found: source={}, destination={}", payload.getSource().getSwitchId(), payload.getDestination().getSwitchId());
        throw new MessageException(ErrorType.NOT_FOUND, System.currentTimeMillis());
    }
    List<Isl> sortedPath = sortPath(source.getName(), path);
    logger.debug("Path found: {}", sortedPath);
    int directVlanId = transitVlanIdPool.allocate();
    int reverseVlanId = transitVlanIdPool.allocate();
    long cookie = getCookie();
    Flow direct = buildFlow(path, source, destination, payload, directVlanId, cookie | DIRECT_FLOW_COOKIE);
    Flow reverse = buildFlow(path, destination, source, payload, reverseVlanId, cookie | REVERSE_FLOW_COOKIE);
    flowRepository.save(direct);
    logger.debug("Flow stored: flow={}", direct);
    flowRepository.save(reverse);
    logger.debug("Flow stored: flow={}", reverse);
    Set<CommandMessage> response = new HashSet<>();
    response.addAll(direct.getInstallationCommands(sortedPath, correlationId));
    response.addAll(reverse.getInstallationCommands(sortedPath, correlationId));
    logger.debug("Flows create command message list: {}", response);
    return response;
}
Also used : Isl(org.openkilda.topology.domain.Isl) Switch(org.openkilda.topology.domain.Switch) MessageException(org.openkilda.messaging.error.MessageException) Flow(org.openkilda.topology.domain.Flow) CommandMessage(org.openkilda.messaging.command.CommandMessage) HashSet(java.util.HashSet)

Example 53 with CommandMessage

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

the class FlowServiceImpl method deleteFlow.

/**
 * Removes given flows from database and forms removal commands.
 *
 * @param flows         collection of {@link Flow} instances
 * @param correlationId request correlation id
 * @return set of removal commands
 */
private Set<CommandMessage> deleteFlow(final Set<Flow> flows, final String correlationId) {
    Set<CommandMessage> response = new HashSet<>();
    for (Flow flow : flows) {
        response.addAll(flow.getDeletionCommands(correlationId));
        flowRepository.delete(flow);
        cookiePool.deallocate((int) (flow.getCookie()));
        transitVlanIdPool.deallocate(flow.getTransitVlan());
        logger.debug("Flow deleted: {}", flows);
    }
    logger.debug("Flows delete command message list: {}", response);
    return response;
}
Also used : CommandMessage(org.openkilda.messaging.command.CommandMessage) HashSet(java.util.HashSet) Flow(org.openkilda.topology.domain.Flow)

Example 54 with CommandMessage

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

the class AbstractSerializerTest method flowGetRequestTest.

@Test
public void flowGetRequestTest() throws IOException, ClassNotFoundException {
    FlowGetRequest data = new FlowGetRequest(flowIdStatusRequest);
    System.out.println(data);
    CommandMessage command = new CommandMessage(data, System.currentTimeMillis(), CORRELATION_ID, DESTINATION);
    serialize(command);
    Message message = (Message) deserialize();
    assertTrue(message instanceof CommandMessage);
    CommandMessage resultCommand = (CommandMessage) message;
    assertTrue(resultCommand.getData() instanceof FlowGetRequest);
    FlowGetRequest resultData = (FlowGetRequest) resultCommand.getData();
    System.out.println(resultData);
    assertEquals(data, resultData);
    assertEquals(data.hashCode(), resultData.hashCode());
    assertEquals(flowIdStatusRequest.hashCode(), resultData.getPayload().hashCode());
}
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) CommandMessage(org.openkilda.messaging.command.CommandMessage) Test(org.junit.Test)

Example 55 with CommandMessage

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

the class AbstractSerializerTest method flowPathRequestTest.

@Test
public void flowPathRequestTest() throws IOException, ClassNotFoundException {
    FlowPathRequest data = new FlowPathRequest(flowIdStatusRequest);
    System.out.println(data);
    CommandMessage command = new CommandMessage(data, System.currentTimeMillis(), CORRELATION_ID, DESTINATION);
    serialize(command);
    Message message = (Message) deserialize();
    assertTrue(message instanceof CommandMessage);
    CommandMessage resultCommand = (CommandMessage) message;
    assertTrue(resultCommand.getData() instanceof FlowPathRequest);
    FlowPathRequest resultData = (FlowPathRequest) resultCommand.getData();
    System.out.println(resultData);
    assertEquals(data, resultData);
    assertEquals(data.hashCode(), resultData.hashCode());
    assertEquals(flowIdStatusRequest.hashCode(), resultData.getPayload().hashCode());
}
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) CommandMessage(org.openkilda.messaging.command.CommandMessage) Test(org.junit.Test)

Aggregations

CommandMessage (org.openkilda.messaging.command.CommandMessage)70 Message (org.openkilda.messaging.Message)36 InfoMessage (org.openkilda.messaging.info.InfoMessage)32 Test (org.junit.Test)19 ErrorMessage (org.openkilda.messaging.error.ErrorMessage)18 Values (org.apache.storm.tuple.Values)11 FlowIdStatusPayload (org.openkilda.messaging.payload.flow.FlowIdStatusPayload)11 RemoveFlow (org.openkilda.messaging.command.flow.RemoveFlow)8 Flow (org.openkilda.messaging.model.Flow)8 IOException (java.io.IOException)7 CommandData (org.openkilda.messaging.command.CommandData)7 AbstractStormTest (org.openkilda.wfm.AbstractStormTest)7 HashSet (java.util.HashSet)6 SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)6 CommandWithReplyToMessage (org.openkilda.messaging.command.CommandWithReplyToMessage)5 NetworkCommandData (org.openkilda.messaging.command.discovery.NetworkCommandData)5 InstallOneSwitchFlow (org.openkilda.messaging.command.flow.InstallOneSwitchFlow)5 FlowDeleteRequest (org.openkilda.messaging.command.flow.FlowDeleteRequest)4 FlowPathRequest (org.openkilda.messaging.command.flow.FlowPathRequest)4 FlowRerouteRequest (org.openkilda.messaging.command.flow.FlowRerouteRequest)4