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());
}
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;
}
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;
}
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);
}
Aggregations