use of org.openkilda.messaging.payload.flow.PathNodePayload in project open-kilda by telstra.
the class ActionServiceTest method shouldUpdateFlowInfo.
@Test
public void shouldUpdateFlowInfo() {
service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.FORWARD, NANOSECOND);
service.processFlowLatencyMeasurement(flow.getFlowId(), FlowDirection.REVERSE, NANOSECOND);
FlowPathDto path = FlowPathDto.builder().forwardPath(Arrays.asList(new PathNodePayload(SRC_SWITCH, 1, 2), new PathNodePayload(DST_SWITCH, 3, 4))).reversePath(Arrays.asList(new PathNodePayload(DST_SWITCH, 4, 3), new PathNodePayload(SRC_SWITCH, 2, 1))).build();
long maxLatency = flow.getMaxLatency() / 2;
long maxLatencyTier2 = flow.getMaxLatencyTier2() / 2;
UpdateFlowCommand info = new UpdateFlowCommand(flow.getFlowId(), path, maxLatency, maxLatencyTier2);
service.updateFlowInfo(info);
assertEquals(2, service.fsms.values().size());
FlowLatencyMonitoringFsm fsm = service.fsms.values().stream().findAny().orElseThrow(() -> new IllegalStateException("Fsm not found"));
assertEquals(maxLatency, fsm.getMaxLatency());
assertEquals(maxLatencyTier2, fsm.getMaxLatencyTier2());
verifyNoMoreInteractions(carrier);
}
use of org.openkilda.messaging.payload.flow.PathNodePayload in project open-kilda by telstra.
the class FlowManagerImpl method createFlowsWithASwitch.
/**
* Creates a number of flows with given number of alternate paths and at least 1 a-switch ISL. a-switch ISL
* will later allow to bring such link down and verify the further flow behavior. <br>
* Note that unlike some other methods here, the flow(s) will already be created in the system.
*
* @param flowsAmount amount of flows to create. Will throw assumption error if unable to find enough flows
* @param alternatePaths amount of alternate paths that should be available for the created flows
* @param bandwidth bandwidth for created flows
* @return map. Key: created flow. Value: list of a-switch isls for flow.
*/
@Override
public Map<FlowPayload, List<TopologyDefinition.Isl>> createFlowsWithASwitch(int flowsAmount, int alternatePaths, int bandwidth) {
final List<TopologyDefinition.TraffGen> traffGens = topologyDefinition.getActiveTraffGens();
FlowSet flowSet = new FlowSet();
boolean foundEnoughFlows = false;
Map<FlowPayload, List<TopologyDefinition.Isl>> result = new HashMap<>();
for (TopologyDefinition.TraffGen srcTraffGen : traffGens) {
for (TopologyDefinition.TraffGen dstTraffGen : traffGens) {
TopologyDefinition.Switch srcSwitch = srcTraffGen.getSwitchConnected();
TopologyDefinition.Switch dstSwitch = dstTraffGen.getSwitchConnected();
if (srcSwitch.getDpId().compareTo(dstSwitch.getDpId()) >= 0) {
continue;
}
// test only bi-directional flow
List<PathInfoData> forwardPaths = db.getPaths(srcSwitch.getDpId(), dstSwitch.getDpId());
List<PathInfoData> reversePaths = db.getPaths(dstSwitch.getDpId(), srcSwitch.getDpId());
boolean hasAlternatePath = forwardPaths.size() > alternatePaths && reversePaths.size() > alternatePaths;
if (hasAlternatePath) {
// try creating flow to see the actual path being used
String flowId = format("%s_%s_%s", srcSwitch.getName(), dstSwitch.getName(), sdf.format(new Date()));
FlowBuilder builder = flowSet.getFlowBuilder(flowId, srcSwitch, dstSwitch);
FlowPayload flow = builder.buildInUniqueVlan(srcTraffGen.getSwitchPort(), dstTraffGen.getSwitchPort());
flow.setMaximumBandwidth(bandwidth);
northboundService.addFlow(flow);
List<PathNodePayload> flowPath = northboundService.getFlowPath(flowId).getForwardPath();
List<TopologyDefinition.Isl> isls = new ArrayList<>();
for (int i = 1; i < flowPath.size(); i++) {
PathNodePayload from = flowPath.get(i - 1);
PathNodePayload to = flowPath.get(i);
isls.addAll(topologyDefinition.getIslsForActiveSwitches().stream().filter(isl -> ((isl.getSrcSwitch().getDpId().equals(from.getSwitchId()) && isl.getDstSwitch().getDpId().equals(to.getSwitchId())) || (isl.getSrcSwitch().getDpId().equals(to.getSwitchId()) && isl.getDstSwitch().getDpId().equals(from.getSwitchId()))) && isl.getAswitch() != null).collect(Collectors.toList()));
}
if (isls.isEmpty()) {
// created flow has no aswitch links, doesn't work for us
northboundService.deleteFlow(flowId);
} else {
result.put(flow, isls);
}
foundEnoughFlows = result.size() == flowsAmount;
}
if (foundEnoughFlows) {
break;
}
}
if (foundEnoughFlows) {
break;
}
}
if (!foundEnoughFlows) {
result.keySet().forEach(f -> northboundService.deleteFlow(f.getId()));
}
Assume.assumeTrue("Didn't find enough of requested flows. This test cannot be run on given topology. " + "Do you have enough a-switch links in the topology?", foundEnoughFlows);
return result;
}
use of org.openkilda.messaging.payload.flow.PathNodePayload in project open-kilda by telstra.
the class FlowPathMapper method mapToPathNodes.
/**
* Convert {@link FlowPath} to {@link PathNodePayload}.
*/
public List<PathNodePayload> mapToPathNodes(FlowPath flowPath, int inPort, int outPort) {
List<PathNodePayload> resultList = new ArrayList<>();
if (flowPath.getSegments().isEmpty()) {
resultList.add(new PathNodePayload(flowPath.getSrcSwitchId(), inPort, outPort));
} else {
List<PathSegment> pathSegments = flowPath.getSegments();
resultList.add(new PathNodePayload(flowPath.getSrcSwitchId(), inPort, pathSegments.get(0).getSrcPort()));
for (int i = 1; i < pathSegments.size(); i++) {
PathSegment inputNode = pathSegments.get(i - 1);
PathSegment outputNode = pathSegments.get(i);
resultList.add(new PathNodePayload(inputNode.getDestSwitchId(), inputNode.getDestPort(), outputNode.getSrcPort()));
}
resultList.add(new PathNodePayload(flowPath.getDestSwitchId(), pathSegments.get(pathSegments.size() - 1).getDestPort(), outPort));
}
return resultList;
}
use of org.openkilda.messaging.payload.flow.PathNodePayload in project open-kilda by telstra.
the class PathMapper method map.
/**
* Convert {@link org.openkilda.pce.Path} to {@link org.openkilda.messaging.info.network.Path}.
*/
public org.openkilda.messaging.info.network.Path map(org.openkilda.pce.Path path) {
if (path == null || path.getSegments().isEmpty()) {
return new org.openkilda.messaging.info.network.Path(0L, Duration.ZERO, new ArrayList<>());
}
List<PathNodePayload> nodes = new ArrayList<>();
List<Path.Segment> pathSegments = path.getSegments();
if (!pathSegments.isEmpty()) {
Segment firstSegment = pathSegments.get(0);
nodes.add(new PathNodePayload(firstSegment.getSrcSwitchId(), null, firstSegment.getSrcPort()));
for (int i = 1; i < pathSegments.size(); i++) {
Path.Segment inputNode = pathSegments.get(i - 1);
Path.Segment outputNode = pathSegments.get(i);
nodes.add(new PathNodePayload(inputNode.getDestSwitchId(), inputNode.getDestPort(), outputNode.getSrcPort()));
}
Segment lastSegment = pathSegments.get(pathSegments.size() - 1);
nodes.add(new PathNodePayload(lastSegment.getDestSwitchId(), lastSegment.getDestPort(), null));
}
return new org.openkilda.messaging.info.network.Path(path.getMinAvailableBandwidth(), Duration.ofNanos(path.getLatency()), nodes);
}
use of org.openkilda.messaging.payload.flow.PathNodePayload in project open-kilda by telstra.
the class FlowPathMapper method mapToPathNodes.
/**
* Convert {@link FlowPath} to {@link PathNodePayload}.
*/
public List<PathNodePayload> mapToPathNodes(FlowPath flowPath) {
List<PathNodePayload> resultList = new ArrayList<>();
Flow flow = flowPath.getFlow();
FlowEndpoint ingress = FlowSideAdapter.makeIngressAdapter(flow, flowPath).getEndpoint();
FlowEndpoint egress = FlowSideAdapter.makeEgressAdapter(flow, flowPath).getEndpoint();
List<PathSegment> pathSegments = flowPath.getSegments();
Iterator<PathSegment> leftIter = pathSegments.iterator();
Iterator<PathSegment> rightIter = pathSegments.iterator();
if (!rightIter.hasNext()) {
resultList.add(new PathNodePayload(flowPath.getSrcSwitchId(), ingress.getPortNumber(), egress.getPortNumber()));
} else {
PathSegment left;
PathSegment right = rightIter.next();
resultList.add(new PathNodePayload(ingress.getSwitchId(), ingress.getPortNumber(), right.getSrcPort()));
while (rightIter.hasNext()) {
left = leftIter.next();
right = rightIter.next();
resultList.add(new PathNodePayload(left.getDestSwitchId(), left.getDestPort(), right.getSrcPort()));
}
resultList.add(new PathNodePayload(egress.getSwitchId(), right.getDestPort(), egress.getPortNumber()));
}
return resultList;
}
Aggregations