Search in sources :

Example 6 with Flow

use of org.openkilda.topology.domain.Flow in project open-kilda by telstra.

the class FlowServiceImplTest method createFlow.

@Test
public void createFlow() throws Exception {
    FlowEndpointPayload firstEndpoint = new FlowEndpointPayload(srcSwitchId, DIRECT_INCOMING_PORT, INPUT_VLAN_ID);
    FlowEndpointPayload secondEndpoint = new FlowEndpointPayload(dstSwitchId, DIRECT_OUTGOING_PORT, OUTPUT_VLAN_ID);
    FlowPayload flowPayload = new FlowPayload(flowId, 0L, firstEndpoint, secondEndpoint, 10000L, "", "", OutputVlanType.NONE);
    flowService.createFlow(flowPayload, DEFAULT_CORRELATION_ID);
    Set<Flow> flows = flowRepository.findByFlowId(flowId);
    assertNotNull(flows);
    assertFalse(flows.isEmpty());
    assertEquals(2, flows.size());
}
Also used : FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) FlowEndpointPayload(org.openkilda.messaging.payload.flow.FlowEndpointPayload) Flow(org.openkilda.topology.domain.Flow) Test(org.junit.Test)

Example 7 with Flow

use of org.openkilda.topology.domain.Flow 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 8 with Flow

use of org.openkilda.topology.domain.Flow 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 9 with Flow

use of org.openkilda.topology.domain.Flow in project open-kilda by telstra.

the class FlowServiceImpl method getFlows.

/**
 * {@inheritDoc}
 */
@Override
public InfoMessage getFlows(final FlowIdStatusPayload payload, final String correlationId) {
    Set<Flow> flows = flowRepository.findAll();
    List<FlowPayload> flowsPayload = new ArrayList<>(flows.size() / 2);
    for (Flow flow : flows) {
        if ((flow.getCookie() & DIRECT_FLOW_COOKIE) == DIRECT_FLOW_COOKIE) {
            flowsPayload.add(getFlowPayloadByFlow(flow));
        }
    }
    logger.debug("Flows get: {}", flowsPayload);
    return new InfoMessage(new FlowsResponse(new FlowsPayload(flowsPayload)), System.currentTimeMillis(), correlationId, Destination.WFM);
}
Also used : FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) InfoMessage(org.openkilda.messaging.info.InfoMessage) FlowsResponse(org.openkilda.messaging.info.flow.FlowsResponse) ArrayList(java.util.ArrayList) FlowsPayload(org.openkilda.messaging.payload.flow.FlowsPayload) Flow(org.openkilda.topology.domain.Flow)

Aggregations

Flow (org.openkilda.topology.domain.Flow)9 FlowPayload (org.openkilda.messaging.payload.flow.FlowPayload)4 Test (org.junit.Test)3 InfoMessage (org.openkilda.messaging.info.InfoMessage)3 FlowEndpointPayload (org.openkilda.messaging.payload.flow.FlowEndpointPayload)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 CommandMessage (org.openkilda.messaging.command.CommandMessage)2 MessageException (org.openkilda.messaging.error.MessageException)2 Isl (org.openkilda.topology.domain.Isl)2 FlowPathResponse (org.openkilda.messaging.info.flow.FlowPathResponse)1 FlowResponse (org.openkilda.messaging.info.flow.FlowResponse)1 FlowsResponse (org.openkilda.messaging.info.flow.FlowsResponse)1 FlowIdStatusPayload (org.openkilda.messaging.payload.flow.FlowIdStatusPayload)1 FlowPathPayload (org.openkilda.messaging.payload.flow.FlowPathPayload)1 FlowsPayload (org.openkilda.messaging.payload.flow.FlowsPayload)1 Switch (org.openkilda.topology.domain.Switch)1