use of org.openkilda.testing.model.topology.TopologyDefinition.Switch in project open-kilda by telstra.
the class FlowSteps method createFlowBetween.
@And("^create flow between '(.*)' and '(.*)' and alias it as '(.*)'$")
public void createFlowBetween(String srcAlias, String dstAlias, String flowAlias) {
Switch srcSwitch = topologyUnderTest.getAliasedObject(srcAlias);
Switch dstSwitch = topologyUnderTest.getAliasedObject(dstAlias);
FlowPayload flow = new FlowSet().buildWithAnyPortsInUniqueVlan("auto" + getTimestamp(), srcSwitch, dstSwitch, 1000);
northboundService.addFlow(flow);
topologyUnderTest.addAlias(flowAlias, flow);
}
use of org.openkilda.testing.model.topology.TopologyDefinition.Switch in project open-kilda by telstra.
the class FlowTrafficExamBuilder method buildExam.
/**
* Build Exam in one direction.
*/
public Exam buildExam(FlowPayload flow, int bandwidth, Long duration) throws FlowNotApplicableException {
Optional<TraffGen> source = Optional.ofNullable(endpointToTraffGen.get(makeComparableEndpoint(flow.getSource())));
Optional<TraffGen> dest = Optional.ofNullable(endpointToTraffGen.get(makeComparableEndpoint(flow.getDestination())));
// do not allow traffic exam on OF version <1.3. We are not installing meters on OF 1.2 intentionally
String srcOfVersion = topology.getSwitches().stream().filter(sw -> sw.getDpId().equals(flow.getSource().getDatapath())).findFirst().map(Switch::getOfVersion).orElseThrow(() -> new IllegalStateException(format("Switch %s not found", flow.getSource().getDatapath())));
String dstOfVersion = topology.getSwitches().stream().filter(sw -> sw.getDpId().equals(flow.getDestination().getDatapath())).findFirst().map(Switch::getOfVersion).orElseThrow(() -> new IllegalStateException(format("Switch %s not found", flow.getDestination().getDatapath())));
checkIsFlowApplicable(flow.getId(), source.isPresent() && !"OF_12".equals(srcOfVersion), dest.isPresent() && !"OF_12".equals(dstOfVersion));
List<Vlan> srcVlanIds = new ArrayList<Vlan>();
srcVlanIds.add(new Vlan(flow.getSource().getVlanId()));
srcVlanIds.add(new Vlan(flow.getSource().getInnerVlanId()));
List<Vlan> dstVlanIds = new ArrayList<Vlan>();
dstVlanIds.add(new Vlan(flow.getDestination().getVlanId()));
dstVlanIds.add(new Vlan(flow.getDestination().getInnerVlanId()));
// noinspection ConstantConditions
Host sourceHost = traffExam.hostByName(source.get().getName());
// noinspection ConstantConditions
Host destHost = traffExam.hostByName(dest.get().getName());
// 1024 * 1024 / 8 / 1500 = 87.3...
return Exam.builder().flow(flow).source(sourceHost).sourceVlans(srcVlanIds).dest(destHost).destVlans(dstVlanIds).bandwidthLimit(new Bandwidth(bandwidth)).burstPkt(100).timeLimitSeconds(duration != null ? new TimeLimit(duration) : null).build();
}
use of org.openkilda.testing.model.topology.TopologyDefinition.Switch in project open-kilda by telstra.
the class LockKeeperServiceImpl method shapeSwitchesTraffic.
@Override
public void shapeSwitchesTraffic(List<Switch> switches, TrafficControlData tcData) {
log.debug("Add traffic control rules for switches {}", switches.stream().map(Switch::getDpId).collect(toList()));
switches.stream().flatMap(sw -> toFlResources(sw, sw.getRegions()).stream()).collect(Collectors.groupingBy(FloodlightResourceAddress::getRegion)).entrySet().parallelStream().forEach(resourcesPerRegion -> lockKeepersByRegion.get(resourcesPerRegion.getKey()).exchange("/floodlight/tc", HttpMethod.POST, new HttpEntity<>(new TrafficControlRequest(tcData, resourcesPerRegion.getValue()), buildJsonHeaders()), String.class));
}
use of org.openkilda.testing.model.topology.TopologyDefinition.Switch in project open-kilda by telstra.
the class LockKeeperVirtualImpl method shapeSwitchesTraffic.
@Override
public void shapeSwitchesTraffic(List<Switch> switches, TrafficControlData tcData) {
log.debug("Add traffic control rules for switches {}", switches.stream().map(Switch::getDpId).collect(toList()));
List<FloodlightResourceAddress> swResources = switches.stream().flatMap(sw -> sw.getRegions().stream().map(region -> {
Floodlight fl = flHelper.getFlByRegion(region);
String swAddress = fl.getFloodlightService().getSwitches().stream().filter(s -> sw.getDpId().equals(s.getSwitchId())).findFirst().get().getAddress();
Pair<String, Integer> inetAddress = LockKeeperService.parseAddressPort(swAddress);
return new FloodlightResourceAddress(region, fl.getContainer(), inetAddress.getLeft(), inetAddress.getRight());
})).collect(toList());
restTemplate.exchange(getCurrentLabUrl() + "/lock-keeper/floodlight/tc", HttpMethod.POST, new HttpEntity<>(new TrafficControlRequest(tcData, swResources), buildJsonHeaders()), String.class);
}
use of org.openkilda.testing.model.topology.TopologyDefinition.Switch in project open-kilda by telstra.
the class FlowSteps method getAllowedVlan.
private int getAllowedVlan(Set<FlowPayload> flows, SwitchId switchDpId) {
RangeSet<Integer> allocatedVlans = TreeRangeSet.create();
flows.forEach(f -> {
allocatedVlans.add(Range.singleton(f.getSource().getVlanId()));
allocatedVlans.add(Range.singleton(f.getDestination().getVlanId()));
});
RangeSet<Integer> availableVlansRange = TreeRangeSet.create();
Switch theSwitch = topologyDefinition.getSwitches().stream().filter(sw -> sw.getDpId().equals(switchDpId)).findFirst().orElseThrow(() -> new IllegalStateException(format("Switch %s not found.", switchDpId)));
theSwitch.getOutPorts().forEach(port -> availableVlansRange.addAll(port.getVlanRange()));
availableVlansRange.removeAll(allocatedVlans);
return availableVlansRange.asRanges().stream().flatMap(range -> ContiguousSet.create(range, DiscreteDomain.integers()).stream()).findFirst().orElseThrow(() -> new IllegalStateException(format("Couldn't found available Vlan for switch %s.", switchDpId)));
}
Aggregations