Search in sources :

Example 6 with Switch

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);
}
Also used : FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) Switch(org.openkilda.testing.model.topology.TopologyDefinition.Switch) FlowSet(org.openkilda.atdd.staging.helpers.FlowSet) And(cucumber.api.java.en.And)

Example 7 with Switch

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();
}
Also used : NetworkEndpoint(org.openkilda.messaging.model.NetworkEndpoint) HashMap(java.util.HashMap) FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) YFlowSharedEndpoint(org.openkilda.northbound.dto.v2.yflows.YFlowSharedEndpoint) Switch(org.openkilda.testing.model.topology.TopologyDefinition.Switch) ArrayList(java.util.ArrayList) FlowEndpointV2(org.openkilda.northbound.dto.v2.flows.FlowEndpointV2) SubFlow(org.openkilda.northbound.dto.v2.yflows.SubFlow) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) Exam(org.openkilda.testing.service.traffexam.model.Exam) YFlow(org.openkilda.northbound.dto.v2.yflows.YFlow) TopologyDefinition(org.openkilda.testing.model.topology.TopologyDefinition) YFlowBidirectionalExam(org.openkilda.testing.service.traffexam.model.YFlowBidirectionalExam) FlowEndpointPayload(org.openkilda.messaging.payload.flow.FlowEndpointPayload) FlowBidirectionalExam(org.openkilda.testing.service.traffexam.model.FlowBidirectionalExam) Vlan(org.openkilda.testing.service.traffexam.model.Vlan) String.format(java.lang.String.format) TraffExamService(org.openkilda.testing.service.traffexam.TraffExamService) Host(org.openkilda.testing.service.traffexam.model.Host) List(java.util.List) TraffGen(org.openkilda.testing.model.topology.TopologyDefinition.TraffGen) TimeLimit(org.openkilda.testing.service.traffexam.model.TimeLimit) Optional(java.util.Optional) Bandwidth(org.openkilda.testing.service.traffexam.model.Bandwidth) FlowNotApplicableException(org.openkilda.testing.service.traffexam.FlowNotApplicableException) TraffGen(org.openkilda.testing.model.topology.TopologyDefinition.TraffGen) Bandwidth(org.openkilda.testing.service.traffexam.model.Bandwidth) ArrayList(java.util.ArrayList) Host(org.openkilda.testing.service.traffexam.model.Host) Vlan(org.openkilda.testing.service.traffexam.model.Vlan) TimeLimit(org.openkilda.testing.service.traffexam.model.TimeLimit)

Example 8 with Switch

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));
}
Also used : Switch(org.openkilda.testing.model.topology.TopologyDefinition.Switch) HttpEntity(org.springframework.http.HttpEntity) TrafficControlRequest(org.openkilda.testing.service.lockkeeper.model.TrafficControlRequest) FloodlightResourceAddress(org.openkilda.testing.service.lockkeeper.model.FloodlightResourceAddress)

Example 9 with Switch

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);
}
Also used : Arrays(java.util.Arrays) LinkDelayModify(org.openkilda.testing.service.lockkeeper.model.LinkDelayModify) Autowired(org.springframework.beans.factory.annotation.Autowired) TrafficControlData(org.openkilda.testing.service.lockkeeper.model.TrafficControlData) SCOPE_PROTOTYPE(org.springframework.beans.factory.config.ConfigurableBeanFactory.SCOPE_PROTOTYPE) FloodlightsHelper(org.openkilda.testing.service.floodlight.FloodlightsHelper) StringUtils(org.apache.commons.lang3.StringUtils) Scope(org.springframework.context.annotation.Scope) Switch(org.openkilda.testing.model.topology.TopologyDefinition.Switch) ContainerName(org.openkilda.testing.service.lockkeeper.model.ContainerName) FloodlightConnectMode(org.openkilda.testing.service.floodlight.model.FloodlightConnectMode) ChangeSwIpRequest(org.openkilda.testing.service.lockkeeper.model.ChangeSwIpRequest) FloodlightResourceAddress(org.openkilda.testing.service.lockkeeper.model.FloodlightResourceAddress) Value(org.springframework.beans.factory.annotation.Value) Pair(org.apache.commons.lang3.tuple.Pair) Service(org.springframework.stereotype.Service) TrafficControlRequest(org.openkilda.testing.service.lockkeeper.model.TrafficControlRequest) Qualifier(org.springframework.beans.factory.annotation.Qualifier) TopologyDefinition(org.openkilda.testing.model.topology.TopologyDefinition) RestTemplate(org.springframework.web.client.RestTemplate) MeterModify(org.openkilda.testing.service.lockkeeper.model.MeterModify) HttpHeaders(org.springframework.http.HttpHeaders) MediaType(org.springframework.http.MediaType) Floodlight(org.openkilda.testing.service.floodlight.model.Floodlight) HttpMethod(org.springframework.http.HttpMethod) SwitchModify(org.openkilda.testing.service.lockkeeper.model.SwitchModify) Profile(org.springframework.context.annotation.Profile) String.format(java.lang.String.format) ASwitchFlow(org.openkilda.testing.service.lockkeeper.model.ASwitchFlow) Collectors.toList(java.util.stream.Collectors.toList) Slf4j(lombok.extern.slf4j.Slf4j) HttpEntity(org.springframework.http.HttpEntity) List(java.util.List) Switch(org.openkilda.testing.model.topology.TopologyDefinition.Switch) Floodlight(org.openkilda.testing.service.floodlight.model.Floodlight) TrafficControlRequest(org.openkilda.testing.service.lockkeeper.model.TrafficControlRequest) FloodlightResourceAddress(org.openkilda.testing.service.lockkeeper.model.FloodlightResourceAddress)

Example 10 with Switch

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)));
}
Also used : Switch(org.openkilda.testing.model.topology.TopologyDefinition.Switch)

Aggregations

Switch (org.openkilda.testing.model.topology.TopologyDefinition.Switch)12 TopologyDefinition (org.openkilda.testing.model.topology.TopologyDefinition)6 List (java.util.List)5 FlowSet (org.openkilda.atdd.staging.helpers.FlowSet)5 FlowPayload (org.openkilda.messaging.payload.flow.FlowPayload)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 String.format (java.lang.String.format)3 Date (java.util.Date)3 Map (java.util.Map)3 Arrays (java.util.Arrays)2 Random (java.util.Random)2 Collectors.toList (java.util.stream.Collectors.toList)2 FlowBuilder (org.openkilda.atdd.staging.helpers.FlowSet.FlowBuilder)2 PathInfoData (org.openkilda.messaging.info.event.PathInfoData)2 PathNodePayload (org.openkilda.messaging.payload.flow.PathNodePayload)2 ASwitchFlow (org.openkilda.testing.service.lockkeeper.model.ASwitchFlow)2 FloodlightResourceAddress (org.openkilda.testing.service.lockkeeper.model.FloodlightResourceAddress)2 TrafficControlRequest (org.openkilda.testing.service.lockkeeper.model.TrafficControlRequest)2 HttpEntity (org.springframework.http.HttpEntity)2