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