use of org.openkilda.wfm.topology.switchmanager.model.GroupInstallContext in project open-kilda by telstra.
the class CommandBuilderImpl method buildGroupInstallContexts.
@Override
public List<GroupInstallContext> buildGroupInstallContexts(SwitchId switchId, List<Integer> groupIds) {
List<GroupInstallContext> groupInstallContexts = new ArrayList<>();
Map<PathId, MirrorGroup> mirrorGroups = new HashMap<>();
groupIds.stream().map(GroupId::new).map(mirrorGroupRepository::findByGroupId).flatMap(o -> o.map(Stream::of).orElseGet(Stream::empty)).forEach(mirrorGroup -> mirrorGroups.put(mirrorGroup.getPathId(), mirrorGroup));
flowPathRepository.findBySegmentDestSwitch(switchId).forEach(flowPath -> {
if (mirrorGroups.containsKey(flowPath.getPathId())) {
PathSegment segment = flowPath.getSegments().stream().filter(pathSegment -> pathSegment.getDestSwitchId().equals(switchId)).findAny().orElseThrow(() -> new IllegalStateException(format("PathSegment not found, path %s, switch %s", flowPath, switchId)));
Flow flow = flowPath.getFlow();
if (segment.getDestSwitchId().equals(flowPath.getDestSwitchId())) {
MirrorConfig mirrorConfig = makeMirrorConfig(flowPath, flow.getDestSwitchId(), flow.getDestPort());
groupInstallContexts.add(GroupInstallContext.builder().mirrorConfig(mirrorConfig).build());
log.info("Group {} is to be (re)installed on switch {}", mirrorConfig.getGroupId(), switchId);
}
}
});
flowPathRepository.findByEndpointSwitch(switchId).forEach(flowPath -> {
if (mirrorGroups.containsKey(flowPath.getPathId())) {
Flow flow = getFlow(flowPath);
if (flowPath.isOneSwitchFlow()) {
SwitchId swId = flowPath.isForward() ? flow.getDestSwitchId() : flow.getSrcSwitchId();
int port = flowPath.isForward() ? flow.getDestPort() : flow.getSrcPort();
MirrorConfig mirrorConfig = makeMirrorConfig(flowPath, swId, port);
groupInstallContexts.add(GroupInstallContext.builder().mirrorConfig(mirrorConfig).build());
log.info("Group {} is to be (re)installed on switch {}", mirrorConfig.getGroupId(), switchId);
} else if (flowPath.getSrcSwitchId().equals(switchId)) {
if (flowPath.getSegments().isEmpty()) {
log.warn("Output port was not found for mirror config");
} else {
PathSegment foundIngressSegment = flowPath.getSegments().get(0);
MirrorConfig mirrorConfig = makeMirrorConfig(flowPath, foundIngressSegment.getSrcSwitchId(), foundIngressSegment.getSrcPort());
EncapsulationResources encapsulation = getEncapsulationResources(flowPath, flow);
groupInstallContexts.add(GroupInstallContext.builder().mirrorConfig(mirrorConfig).encapsulation(new FlowTransitEncapsulation(encapsulation.getTransitEncapsulationId(), encapsulation.getEncapsulationType())).egressSwitchId(flowPath.getDestSwitchId()).build());
log.info("Group {} is to be (re)installed on switch {}", mirrorConfig.getGroupId(), switchId);
}
}
}
});
return groupInstallContexts;
}
use of org.openkilda.wfm.topology.switchmanager.model.GroupInstallContext in project open-kilda by telstra.
the class SwitchSyncFsm method sendGroupsCommands.
protected void sendGroupsCommands(SwitchSyncState from, SwitchSyncState to, SwitchSyncEvent event, Object context) {
if (missingGroups.isEmpty() && misconfiguredGroups.isEmpty() && excessGroups.isEmpty()) {
log.info("Nothing to do with groups (switch={}, key={})", switchId, key);
fire(NEXT);
return;
}
if (!missingGroups.isEmpty()) {
log.info("Request to install switch groups has been sent (switch={}, key={})", switchId, key);
missingGroupsPendingResponsesCount = missingGroups.size();
for (GroupInstallContext groupContext : missingGroups) {
carrier.sendCommandToSpeaker(key, new InstallGroupRequest(switchId, groupContext.getMirrorConfig(), groupContext.getEncapsulation(), groupContext.getEgressSwitchId()));
}
}
if (!misconfiguredGroups.isEmpty()) {
log.info("Request to modify switch groups has been sent (switch={}, key={})", switchId, key);
misconfiguredGroupsPendingResponsesCount = misconfiguredGroups.size();
for (GroupInstallContext groupContext : misconfiguredGroups) {
carrier.sendCommandToSpeaker(key, new ModifyGroupRequest(switchId, groupContext.getMirrorConfig(), groupContext.getEncapsulation(), groupContext.getEgressSwitchId()));
}
}
if (!excessGroups.isEmpty()) {
log.info("Request to remove switch groups has been sent (switch={}, key={})", switchId, key);
excessGroupsPendingResponsesCount = excessGroups.size();
for (Integer groupId : excessGroups) {
carrier.sendCommandToSpeaker(key, new DeleteGroupRequest(switchId, new GroupId(groupId)));
}
}
continueIfGroupsSynchronized();
}
Aggregations