16 package org.openkilda.northbound.service.impl;
18 import static java.lang.String.format;
19 import static java.util.Collections.emptyList;
60 import org.slf4j.Logger;
61 import org.slf4j.LoggerFactory;
62 import org.springframework.beans.factory.annotation.Autowired;
63 import org.springframework.beans.factory.annotation.Value;
64 import org.springframework.stereotype.Service;
65 import org.springframework.util.CollectionUtils;
67 import java.util.ArrayList;
68 import java.util.List;
69 import java.util.stream.Collectors;
74 private static final Logger LOGGER = LoggerFactory.getLogger(
SwitchServiceImpl.class);
76 @Value(
"#{kafkaTopicsConfig.getTopoEngTopic()}")
77 private String topoEngTopic;
91 @Value(
"#{kafkaTopicsConfig.getSpeakerTopic()}")
92 private String floodlightTopic;
94 @Value(
"#{kafkaTopicsConfig.getNorthboundTopic()}")
95 private String northboundTopic;
97 @Value(
"#{kafkaTopicsConfig.getTopoNbTopic()}")
98 private String nbworkerTopic;
106 LOGGER.debug(
"Get switch request received");
109 messageProducer.send(nbworkerTopic, request);
111 List<SwitchInfoData> switches = switchesCollector.getResult(correlationId);
112 return switches.stream()
113 .map(switchMapper::toSwitchDto)
114 .collect(Collectors.toList());
125 messageProducer.send(floodlightTopic, commandMessage);
126 Message message = messageConsumer.poll(correlationId);
130 List<FlowEntry> matchedFlows =
new ArrayList<>();
131 for (
FlowEntry entry : response.getFlowEntries()) {
132 if (cookie.equals(entry.getCookie())) {
133 matchedFlows.add(entry);
149 LOGGER.debug(
"Delete switch rules request received: deleteAction={}", deleteAction);
154 messageProducer.send(floodlightTopic, request);
156 Message message = messageConsumer.poll(correlationId);
164 LOGGER.debug(
"Delete switch rules request received: criteria={}", criteria);
169 messageProducer.send(floodlightTopic, request);
171 Message message = messageConsumer.poll(correlationId);
183 LOGGER.debug(
"Install switch rules request received");
188 messageProducer.send(floodlightTopic, request);
190 Message message = messageConsumer.poll(correlationId);
202 LOGGER.debug(
"Set/Get switch connect mode request received: mode = {}", mode);
207 messageProducer.send(floodlightTopic, request);
209 Message message = messageConsumer.poll(correlationId);
221 messageProducer.send(topoEngTopic, validateCommandMessage);
223 Message validateResponseMessage = messageConsumer.poll(correlationId);
225 validateResponseMessage, correlationId);
227 return switchMapper.toRulesValidationResult(validateResponse);
233 List<Long> missingRules = validationResult.getMissingRules();
235 if (CollectionUtils.isEmpty(missingRules)) {
236 return switchMapper.toRulesSyncResult(validationResult, emptyList());
239 LOGGER.debug(
"The validation result for switch {}: missing rules = {}", switchId, missingRules);
246 messageProducer.send(topoEngTopic, syncCommandMessage);
248 Message syncResponseMessage = messageConsumer.poll(syncCorrelationId);
250 syncResponseMessage, syncCorrelationId);
252 return switchMapper.toRulesSyncResult(validationResult, syncResponse.getInstalledRules());
261 messageProducer.send(floodlightTopic, deleteCommand);
263 Message response = messageConsumer.poll(requestId);
278 request, System.currentTimeMillis(), correlationId,
280 messageProducer.send(floodlightTopic, updateStatusCommand);
282 Message response = messageConsumer.poll(correlationId);
284 updateStatusCommand, response, correlationId);
286 return new PortDto(switchPortResponse.getSwitchId().
toString(), switchPortResponse.getPortNo());
294 boolean adminDownState;
297 adminDownState =
false;
300 adminDownState =
true;
303 throw new IllegalArgumentException(String.format(
306 return adminDownState;
List< SwitchDto > getSwitches()
ConnectModeRequest.Mode getMode()
PortDto configurePort(SwitchId switchId, int port, PortConfigurationPayload config)
SwitchFlowEntries getRules(SwitchId switchId, Long cookie)
List< Long > getRuleIds()
SwitchFlowEntries getRules(SwitchId switchId, Long cookie, String correlationId)
DeleteMeterResult deleteMeter(SwitchId switchId, long meterId)
RulesValidationResult validateRules(SwitchId switchId)
List< Long > deleteRules(SwitchId switchId, DeleteRulesAction deleteAction)
default InfoData validateInfoMessage(final Message requestMessage, final Message responseMessage, final String correlationId)
ConnectModeRequest.Mode connectMode(ConnectModeRequest.Mode mode)
RulesSyncResult syncRules(SwitchId switchId)
List< Long > deleteRules(SwitchId switchId, DeleteRulesCriteria criteria)
List< Long > installRules(SwitchId switchId, InstallRulesAction installAction)