16 package org.openkilda.floodlight.command.flow;
25 import net.floodlightcontroller.core.IOFSwitch;
26 import net.floodlightcontroller.core.internal.IOFSwitchService;
27 import net.floodlightcontroller.core.module.FloodlightModuleContext;
28 import org.projectfloodlight.openflow.types.DatapathId;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 import java.util.ArrayList;
33 import java.util.List;
34 import java.util.Optional;
39 private final IOFSwitchService switchService;
42 super(context, verificationRequest);
45 switchService = moduleContext.getServiceImpl(IOFSwitchService.class);
50 launchSubCommands(produceSubCommands());
53 List<Optional<Command>> produceSubCommands() {
54 List<Optional<Command>> plan =
new ArrayList<>();
58 plan.add(makeListenCommand());
59 plan.add(makeSendCommand());
60 }
catch (InsufficientCapabilitiesException e) {
62 "Unable to perform flow VERIFICATION due to {} (packetID: {})",
63 e.toString(), getVerificationRequest().getPacketId());
64 sendErrorResponse(FlowVerificationErrorCode.NOT_CAPABLE);
71 private void launchSubCommands(List<Optional<Command>> subCommands) {
72 for (Optional<Command>
command : subCommands) {
73 command.ifPresent(this::startSubCommand);
77 private Optional<Command> makeSendCommand() {
78 UniFlowVerificationRequest verificationRequest = getVerificationRequest();
79 if (!isOwnSwitch(verificationRequest.getSourceSwitchId())) {
80 log.debug(
"Switch {} is not under our control, do not produce flow verification send request");
81 return Optional.empty();
84 log.debug(
"Initiate verification send command (request: {})", verificationRequest.getPacketId());
85 return Optional.of(
new VerificationSendCommand(
getContext(), verificationRequest));
88 private Optional<Command> makeListenCommand() throws InsufficientCapabilitiesException {
89 UniFlowVerificationRequest verificationRequest = getVerificationRequest();
90 if (!isOwnSwitch(verificationRequest.getDestSwitchId())) {
91 log.debug(
"Switch {} is not under our control, do not produce flow verification receive handler");
92 return Optional.empty();
95 log.debug(
"Initiate verification listen command (request: {})", verificationRequest.getPacketId());
96 return Optional.of(
new VerificationListenCommand(
getContext(), verificationRequest));
99 private boolean isOwnSwitch(SwitchId switchId) {
100 DatapathId dpId = DatapathId.of(switchId.toLong());
101 IOFSwitch sw = switchService.getActiveSwitch(dpId);
CommandContext getContext()
def command(payload, fields)
VerificationDispatchCommand(CommandContext context, UniFlowVerificationRequest verificationRequest)
FloodlightModuleContext getModuleContext()