use of org.openkilda.model.PathId in project open-kilda by telstra.
the class RuleManagerImpl method buildFlowRulesForSwitch.
/**
* Builds command data only for switches present in the map. Silently skips all others.
*/
private List<SpeakerData> buildFlowRulesForSwitch(SwitchId switchId, FlowPath flowPath, DataAdapter adapter) {
List<SpeakerData> result = new ArrayList<>();
Flow flow = adapter.getFlow(flowPath.getPathId());
Switch sw = adapter.getSwitch(switchId);
PathId oppositePathId = flow.getOppositePathId(flowPath.getPathId()).orElse(null);
FlowTransitEncapsulation encapsulation = adapter.getTransitEncapsulation(flowPath.getPathId(), oppositePathId);
if (switchId.equals(flowPath.getSrcSwitchId()) && !flow.isProtectedPath(flowPath.getPathId())) {
// TODO filter out equal shared rules from the result list
result.addAll(buildIngressCommands(sw, flowPath, flow, encapsulation, new HashSet<>(), adapter.getSwitchProperties(switchId), adapter.getFeatureToggles()));
}
if (!flowPath.isOneSwitchFlow()) {
if (switchId.equals(flowPath.getDestSwitchId())) {
result.addAll(buildEgressCommands(sw, flowPath, flow, encapsulation));
}
for (int i = 1; i < flowPath.getSegments().size(); i++) {
PathSegment firstSegment = flowPath.getSegments().get(i - 1);
PathSegment secondSegment = flowPath.getSegments().get(i);
if (switchId.equals(firstSegment.getDestSwitchId()) && switchId.equals(secondSegment.getSrcSwitchId())) {
result.addAll(buildTransitCommands(sw, flowPath, encapsulation, firstSegment, secondSegment));
break;
}
}
if (flow.isLooped() && sw.getSwitchId().equals(flow.getLoopSwitchId()) && !flow.isProtectedPath(flowPath.getPathId())) {
result.addAll(buildTransitLoopCommands(sw, flowPath, flow, encapsulation));
}
}
return result;
}
use of org.openkilda.model.PathId in project open-kilda by telstra.
the class TransitVlanPoolTest method gotSameVlanForOppositePath.
@Test
public void gotSameVlanForOppositePath() {
Flow flow = Flow.builder().flowId("flow_1").srcSwitch(SWITCH_A).destSwitch(SWITCH_B).build();
final PathId forwardPathId = new PathId("forward");
final PathId reversePathId = new PathId("reverse");
transactionManager.doInTransaction(() -> {
TransitVlan forward = transitVlanPool.allocate(flow, forwardPathId, reversePathId).getTransitVlan();
TransitVlan reverse = transitVlanPool.allocate(flow, reversePathId, forwardPathId).getTransitVlan();
Assert.assertEquals(forward, reverse);
});
}
use of org.openkilda.model.PathId in project open-kilda by telstra.
the class FlowMapper method buildPath.
private FlowPath buildPath(FlowDto flowDto) {
Switch srcSwitch = Switch.builder().switchId(flowDto.getSourceSwitch()).build();
Switch destSwitch = Switch.builder().switchId(flowDto.getDestinationSwitch()).build();
return FlowPath.builder().srcSwitch(srcSwitch).destSwitch(destSwitch).cookie(new FlowSegmentCookie(flowDto.getCookie())).bandwidth(flowDto.getBandwidth()).ignoreBandwidth(flowDto.isIgnoreBandwidth()).pathId(new PathId(UUID.randomUUID().toString())).meterId(flowDto.getMeterId() != null ? new MeterId(flowDto.getMeterId()) : null).build();
}
use of org.openkilda.model.PathId in project open-kilda by telstra.
the class SwitchValidateFsm method validateEnter.
protected void validateEnter(SwitchValidateState from, SwitchValidateState to, SwitchValidateEvent event, SwitchValidateContext context) {
SwitchId switchId = getSwitchId();
Set<PathId> flowPathIds = flowPathRepository.findBySegmentSwitch(switchId).stream().map(FlowPath::getPathId).collect(Collectors.toSet());
flowPathIds.addAll(flowPathRepository.findByEndpointSwitch(switchId).stream().map(FlowPath::getPathId).collect(Collectors.toSet()));
PersistenceDataAdapter dataAdapter = PersistenceDataAdapter.builder().persistenceManager(persistenceManager).switchIds(Collections.singleton(switchId)).pathIds(flowPathIds).keepMultitableForFlow(true).build();
List<SpeakerData> expectedEntities = ruleManager.buildRulesForSwitch(switchId, dataAdapter);
List<FlowSpeakerData> expectedRules = filterSpeakerData(expectedEntities, FlowSpeakerData.class);
List<MeterSpeakerData> expectedMeters = filterSpeakerData(expectedEntities, MeterSpeakerData.class);
List<GroupSpeakerData> expectedGroups = filterSpeakerData(expectedEntities, GroupSpeakerData.class);
validateRules(expectedRules);
validateMeters(expectedMeters);
validateGroups(expectedGroups);
validateLogicalPorts();
}
use of org.openkilda.model.PathId in project open-kilda by telstra.
the class AllocateProtectedResourcesAction method allocate.
@TimedExecution("fsm.resource_allocation_protected")
@Override
protected void allocate(FlowRerouteFsm stateMachine) throws RecoverableException, UnroutableFlowException, ResourceAllocationException {
String flowId = stateMachine.getFlowId();
Flow tmpFlowCopy = getFlow(flowId);
// Detach the entity to avoid propagation to the database.
flowRepository.detach(tmpFlowCopy);
if (stateMachine.getNewEncapsulationType() != null) {
// This is for PCE to use proper (updated) encapsulation type.
tmpFlowCopy.setEncapsulationType(stateMachine.getNewEncapsulationType());
}
FlowPathPair oldPaths = new FlowPathPair(tmpFlowCopy.getProtectedForwardPath(), tmpFlowCopy.getProtectedReversePath());
FlowPath primaryForward = tmpFlowCopy.getPath(stateMachine.getNewPrimaryForwardPath()).orElse(tmpFlowCopy.getForwardPath());
FlowPath primaryReverse = tmpFlowCopy.getPath(stateMachine.getNewPrimaryReversePath()).orElse(tmpFlowCopy.getReversePath());
Predicate<GetPathsResult> testNonOverlappingPath = path -> (primaryForward == null || !flowPathBuilder.arePathsOverlapped(path.getForward(), primaryForward)) && (primaryReverse == null || !flowPathBuilder.arePathsOverlapped(path.getReverse(), primaryReverse));
PathId newForwardPathId = resourcesManager.generatePathId(flowId);
PathId newReversePathId = resourcesManager.generatePathId(flowId);
List<PathId> pathsToReuse = Lists.newArrayList(tmpFlowCopy.getProtectedForwardPathId(), tmpFlowCopy.getProtectedReversePathId());
pathsToReuse.addAll(stateMachine.getRejectedPaths());
log.debug("Finding a new protected path for flow {}", flowId);
GetPathsResult allocatedPaths = allocatePathPair(tmpFlowCopy, newForwardPathId, newReversePathId, stateMachine.isIgnoreBandwidth(), pathsToReuse, oldPaths, stateMachine.isRecreateIfSamePath(), stateMachine.getSharedBandwidthGroupId(), testNonOverlappingPath);
if (allocatedPaths != null) {
stateMachine.setBackUpProtectedPathComputationWayUsed(allocatedPaths.isBackUpPathComputationWayUsed());
if (!testNonOverlappingPath.test(allocatedPaths)) {
stateMachine.saveActionToHistory("Couldn't find non overlapping protected path. Skipped creating it");
stateMachine.fireNoPathFound("Couldn't find non overlapping protected path");
} else {
log.debug("New protected paths have been allocated: {}", allocatedPaths);
stateMachine.setNewProtectedForwardPath(newForwardPathId);
stateMachine.setNewProtectedReversePath(newReversePathId);
log.debug("Allocating resources for a new protected path of flow {}", flowId);
FlowResources flowResources = allocateFlowResources(tmpFlowCopy, newForwardPathId, newReversePathId);
stateMachine.setNewProtectedResources(flowResources);
FlowPathPair createdPaths = createFlowPathPair(flowId, flowResources, allocatedPaths, stateMachine.isIgnoreBandwidth(), stateMachine.getSharedBandwidthGroupId());
log.debug("New protected paths have been created: {}", createdPaths);
saveAllocationActionWithDumpsToHistory(stateMachine, tmpFlowCopy, "protected", createdPaths);
}
} else {
stateMachine.saveActionToHistory("Found the same protected path. Skipped creating of it");
}
}
Aggregations