use of org.openkilda.model.PathId in project open-kilda by telstra.
the class AvailableNetworkFactory method getAvailableNetwork.
/**
* Gets a {@link AvailableNetwork}.
*
* @param flow the flow, for which {@link AvailableNetwork} is constructing.
* @param reusePathsResources reuse resources already allocated by {@param reusePathsResources} paths.
* @return {@link AvailableNetwork} instance.
*/
public AvailableNetwork getAvailableNetwork(Flow flow, Collection<PathId> reusePathsResources) throws RecoverableException {
BuildStrategy buildStrategy = BuildStrategy.from(config.getNetworkStrategy());
AvailableNetwork network = new AvailableNetwork();
try {
// Reads all active links from the database and creates representation of the network.
getAvailableIsls(buildStrategy, flow).forEach(link -> addIslAsEdge(link, network));
if (!reusePathsResources.isEmpty() && !flow.isIgnoreBandwidth()) {
reusePathsResources.stream().filter(pathId -> flowPathRepository.findById(pathId).map(path -> !path.isIgnoreBandwidth()).orElse(false)).forEach(pathId -> {
// ISLs occupied by the flow (take the bandwidth already occupied by the flow into account).
islRepository.findActiveByPathAndBandwidthAndEncapsulationType(pathId, flow.getBandwidth(), flow.getEncapsulationType()).forEach(link -> addIslAsEdge(link, network));
});
}
} catch (PersistenceException e) {
throw new RecoverableException("An error from the database", e);
}
if (flow.getDiverseGroupId() != null) {
log.info("Filling AvailableNetwork diverse weights for group with id {}", flow.getDiverseGroupId());
Collection<PathId> flowPaths = flowPathRepository.findPathIdsByFlowDiverseGroupId(flow.getDiverseGroupId());
if (!reusePathsResources.isEmpty()) {
flowPaths = flowPaths.stream().filter(s -> !reusePathsResources.contains(s)).collect(Collectors.toList());
}
Collection<PathId> affinityPathIds = flowPathRepository.findPathIdsByFlowAffinityGroupId(flow.getAffinityGroupId());
flowPaths.forEach(pathId -> flowPathRepository.findById(pathId).filter(flowPath -> !affinityPathIds.contains(flowPath.getPathId()) || flowPath.getFlowId().equals(flow.getFlowId())).ifPresent(flowPath -> {
network.processDiversitySegments(flowPath.getSegments(), flow);
network.processDiversitySegmentsWithPop(flowPath.getSegments());
}));
}
// The main flow should not take into account the rest of the flows in this affinity group.
if (flow.getAffinityGroupId() != null && !flow.getAffinityGroupId().equals(flow.getFlowId())) {
log.info("Filling AvailableNetwork affinity weights for group with id {}", flow.getAffinityGroupId());
flowPathRepository.findByFlowId(flow.getAffinityGroupId()).stream().filter(flowPath -> !flowPath.isProtected()).filter(FlowPath::isForward).map(FlowPath::getSegments).forEach(network::processAffinitySegments);
}
return network;
}
use of org.openkilda.model.PathId in project open-kilda by telstra.
the class LinkOperationsServiceTest method createFlow.
private Flow createFlow(String flowId, SwitchId srcSwitchId, int srcPort, SwitchId dstSwitchId, int dstPort) {
Switch srcSwitch = createSwitchIfNotExist(srcSwitchId);
Switch dstSwitch = createSwitchIfNotExist(dstSwitchId);
Flow flow = Flow.builder().flowId(flowId).srcSwitch(srcSwitch).srcPort(srcPort).destSwitch(dstSwitch).destPort(dstPort).status(FlowStatus.UP).build();
FlowPath forwardPath = FlowPath.builder().pathId(new PathId("forward_path_id")).srcSwitch(srcSwitch).destSwitch(dstSwitch).cookie(new FlowSegmentCookie(1L)).build();
FlowPath reversePath = FlowPath.builder().pathId(new PathId("reverse_path_id")).srcSwitch(dstSwitch).destSwitch(srcSwitch).cookie(new FlowSegmentCookie(1L)).build();
forwardPath.setSegments(newArrayList(createPathSegment(forwardPath.getPathId(), srcSwitch, srcPort, dstSwitch, dstPort)));
reversePath.setSegments(newArrayList(createPathSegment(reversePath.getPathId(), dstSwitch, dstPort, srcSwitch, srcPort)));
flow.setForwardPath(forwardPath);
flow.setReversePath(reversePath);
flowRepository.add(flow);
return flow;
}
use of org.openkilda.model.PathId in project open-kilda by telstra.
the class SwitchOperationsServiceTest method shouldValidateFlowMirrorPathWhenUpdatingServer42PortSwitchProperties.
@Test(expected = IllegalSwitchPropertiesException.class)
public void shouldValidateFlowMirrorPathWhenUpdatingServer42PortSwitchProperties() {
Switch firstSwitch = Switch.builder().switchId(TEST_SWITCH_ID).status(SwitchStatus.ACTIVE).build();
Switch secondSwitch = Switch.builder().switchId(TEST_SWITCH_ID_2).status(SwitchStatus.ACTIVE).build();
switchRepository.add(firstSwitch);
switchRepository.add(secondSwitch);
FlowMirrorPath flowMirrorPath = FlowMirrorPath.builder().pathId(new PathId("test_path_id")).mirrorSwitch(secondSwitch).egressSwitch(firstSwitch).egressPort(TEST_FLOW_SRC_PORT).build();
flowMirrorPathRepository.add(flowMirrorPath);
createSwitchProperties(firstSwitch, Collections.singleton(FlowEncapsulationType.TRANSIT_VLAN), true, false, false);
SwitchPropertiesDto update = new SwitchPropertiesDto();
update.setSupportedTransitEncapsulation(Collections.singleton(org.openkilda.messaging.payload.flow.FlowEncapsulationType.TRANSIT_VLAN));
update.setServer42Port(TEST_FLOW_SRC_PORT);
switchOperationsService.updateSwitchProperties(TEST_SWITCH_ID, update);
}
use of org.openkilda.model.PathId in project open-kilda by telstra.
the class SwitchOperationsServiceTest method shouldValidateFlowMirrorPointsWhenUpdatingSwitchArpProperties.
@Test(expected = IllegalSwitchPropertiesException.class)
public void shouldValidateFlowMirrorPointsWhenUpdatingSwitchArpProperties() {
Switch mirrorSwitch = Switch.builder().switchId(TEST_SWITCH_ID).status(SwitchStatus.ACTIVE).build();
switchRepository.add(mirrorSwitch);
MirrorGroup mirrorGroup = MirrorGroup.builder().switchId(TEST_SWITCH_ID).groupId(new GroupId(12L)).pathId(new PathId("test_path_id")).flowId(TEST_FLOW_ID_1).mirrorGroupType(MirrorGroupType.TRAFFIC_INTEGRITY).mirrorDirection(MirrorDirection.INGRESS).build();
mirrorGroupRepository.add(mirrorGroup);
FlowMirrorPoints flowMirrorPoints = FlowMirrorPoints.builder().mirrorGroup(mirrorGroup).mirrorSwitch(mirrorSwitch).build();
flowMirrorPointsRepository.add(flowMirrorPoints);
createSwitchProperties(mirrorSwitch, Collections.singleton(FlowEncapsulationType.TRANSIT_VLAN), true, false, false);
SwitchPropertiesDto update = new SwitchPropertiesDto();
update.setSupportedTransitEncapsulation(Collections.singleton(org.openkilda.messaging.payload.flow.FlowEncapsulationType.TRANSIT_VLAN));
update.setMultiTable(true);
update.setSwitchArp(true);
switchOperationsService.updateSwitchProperties(TEST_SWITCH_ID, update);
}
use of org.openkilda.model.PathId in project open-kilda by telstra.
the class RerouteServiceTest method setup.
@Before
public void setup() throws Throwable {
doAnswer(invocation -> {
TransactionCallbackWithoutResult<?> arg = invocation.getArgument(0);
arg.doInTransaction();
return null;
}).when(transactionManager).doInTransaction(Mockito.<TransactionCallbackWithoutResult<?>>any());
doAnswer(invocation -> {
TransactionCallback<?, ?> arg = invocation.getArgument(0);
return arg.doInTransaction();
}).when(transactionManager).doInTransaction(Mockito.<TransactionCallback<?, ?>>any());
pinnedFlow = Flow.builder().flowId(FLOW_ID).srcSwitch(SWITCH_A).destSwitch(SWITCH_C).pinned(true).build();
FlowPath pinnedFlowForwardPath = FlowPath.builder().pathId(new PathId("1")).srcSwitch(SWITCH_A).destSwitch(SWITCH_C).cookie(new FlowSegmentCookie(FlowPathDirection.FORWARD, 1)).build();
List<PathSegment> pinnedFlowForwardSegments = new ArrayList<>();
pinnedFlowForwardSegments.add(PathSegment.builder().pathId(pinnedFlowForwardPath.getPathId()).srcSwitch(SWITCH_A).srcPort(1).destSwitch(SWITCH_B).destPort(1).build());
pinnedFlowForwardSegments.add(PathSegment.builder().pathId(pinnedFlowForwardPath.getPathId()).srcSwitch(SWITCH_B).srcPort(2).destSwitch(SWITCH_C).destPort(1).build());
pinnedFlowForwardPath.setSegments(pinnedFlowForwardSegments);
FlowPath pinnedFlowReversePath = FlowPath.builder().pathId(new PathId("2")).srcSwitch(SWITCH_C).destSwitch(SWITCH_A).cookie(new FlowSegmentCookie(FlowPathDirection.REVERSE, 2)).build();
List<PathSegment> pinnedFlowReverseSegments = new ArrayList<>();
pinnedFlowReverseSegments.add(PathSegment.builder().pathId(pinnedFlowReversePath.getPathId()).srcSwitch(SWITCH_C).srcPort(1).destSwitch(SWITCH_B).destPort(2).build());
pinnedFlowReverseSegments.add(PathSegment.builder().pathId(pinnedFlowReversePath.getPathId()).srcSwitch(SWITCH_B).srcPort(1).destSwitch(SWITCH_A).destPort(1).build());
pinnedFlowReversePath.setSegments(pinnedFlowReverseSegments);
pinnedFlow.setForwardPath(pinnedFlowForwardPath);
pinnedFlow.setReversePath(pinnedFlowReversePath);
regularFlow = Flow.builder().flowId(FLOW_ID).srcSwitch(SWITCH_A).destSwitch(SWITCH_C).pinned(false).priority(2).build();
FlowPath regularFlowForwardPath = FlowPath.builder().pathId(new PathId("3")).srcSwitch(SWITCH_A).destSwitch(SWITCH_C).cookie(new FlowSegmentCookie(FlowPathDirection.FORWARD, 3)).status(FlowPathStatus.ACTIVE).build();
List<PathSegment> unpinnedFlowForwardSegments = new ArrayList<>();
unpinnedFlowForwardSegments.add(PathSegment.builder().pathId(regularFlowForwardPath.getPathId()).srcSwitch(SWITCH_A).srcPort(1).destSwitch(SWITCH_B).destPort(1).build());
unpinnedFlowForwardSegments.add(PathSegment.builder().pathId(regularFlowForwardPath.getPathId()).srcSwitch(SWITCH_B).srcPort(2).destSwitch(SWITCH_C).destPort(1).build());
regularFlowForwardPath.setSegments(unpinnedFlowForwardSegments);
FlowPath regularFlowReversePath = FlowPath.builder().pathId(new PathId("4")).srcSwitch(SWITCH_C).destSwitch(SWITCH_A).cookie(new FlowSegmentCookie(FlowPathDirection.REVERSE, 3)).status(FlowPathStatus.ACTIVE).build();
List<PathSegment> unpinnedFlowReverseSegments = new ArrayList<>();
unpinnedFlowReverseSegments.add(PathSegment.builder().pathId(regularFlowReversePath.getPathId()).srcSwitch(SWITCH_C).srcPort(1).destSwitch(SWITCH_B).destPort(2).build());
unpinnedFlowReverseSegments.add(PathSegment.builder().pathId(regularFlowReversePath.getPathId()).srcSwitch(SWITCH_B).srcPort(1).destSwitch(SWITCH_A).destPort(1).build());
regularFlowReversePath.setSegments(unpinnedFlowReverseSegments);
regularFlow.setForwardPath(regularFlowForwardPath);
regularFlow.setReversePath(regularFlowReversePath);
oneSwitchFlow = Flow.builder().flowId(FLOW_ID).srcSwitch(SWITCH_A).destSwitch(SWITCH_A).build();
FlowPath oneSwitchFlowForwardPath = FlowPath.builder().pathId(new PathId("5")).srcSwitch(SWITCH_A).destSwitch(SWITCH_A).cookie(new FlowSegmentCookie(FlowPathDirection.FORWARD, 4)).status(FlowPathStatus.ACTIVE).build();
FlowPath oneSwitchFlowReversePath = FlowPath.builder().pathId(new PathId("6")).srcSwitch(SWITCH_A).destSwitch(SWITCH_A).cookie(new FlowSegmentCookie(FlowPathDirection.REVERSE, 4)).status(FlowPathStatus.ACTIVE).build();
oneSwitchFlow.setForwardPath(oneSwitchFlowForwardPath);
oneSwitchFlow.setReversePath(oneSwitchFlowReversePath);
regularYFlow = YFlow.builder().yFlowId(YFLOW_ID).priority(2).sharedEndpoint(new SharedEndpoint(SWITCH_A.getSwitchId(), 10)).build();
FlowPath regularYFlowForwardPath = FlowPath.builder().pathId(new PathId("3")).srcSwitch(SWITCH_A).destSwitch(SWITCH_C).cookie(new FlowSegmentCookie(FlowPathDirection.FORWARD, 3)).status(FlowPathStatus.ACTIVE).build();
regularYFlowForwardPath.setSegments(unpinnedFlowForwardSegments);
FlowPath regularYFlowReversePath = FlowPath.builder().pathId(new PathId("4")).srcSwitch(SWITCH_C).destSwitch(SWITCH_A).cookie(new FlowSegmentCookie(FlowPathDirection.REVERSE, 3)).status(FlowPathStatus.ACTIVE).build();
regularYFlowReversePath.setSegments(unpinnedFlowReverseSegments);
subFlow = Flow.builder().flowId(SUB_YFLOW_ID).srcSwitch(SWITCH_A).destSwitch(SWITCH_C).pinned(false).priority(2).yFlowId(YFLOW_ID).yFlow(regularYFlow).build();
subFlow.setForwardPath(regularYFlowForwardPath);
subFlow.setReversePath(regularYFlowReversePath);
Set<YSubFlow> subFlows = Collections.singleton(YSubFlow.builder().yFlow(regularYFlow).flow(subFlow).build());
regularYFlow.setSubFlows(subFlows);
}
Aggregations