Search in sources :

Example 1 with Host

use of org.openkilda.testing.service.traffexam.model.Host in project open-kilda by telstra.

the class StubServiceFactory method getTraffExamStub.

/**
 * Get a stub for {@link TraffExamService}. The instance is tied to the factory state.
 */
public TraffExamService getTraffExamStub() {
    TraffExamService serviceMock = mock(TraffExamService.class);
    when(serviceMock.hostByName(any())).thenAnswer(invocation -> {
        String hostName = (String) invocation.getArguments()[0];
        Host host = mock(Host.class);
        when(host.getName()).thenReturn(hostName);
        return host;
    });
    when(serviceMock.waitExam(any())).thenAnswer(invocation -> {
        Exam exam = (Exam) invocation.getArguments()[0];
        ExamReport report = mock(ExamReport.class);
        when(report.hasError()).thenReturn(false);
        when(report.hasTraffic()).thenReturn(flows.containsKey(exam.getFlow().getId()));
        when(report.getBandwidth()).thenReturn(new Bandwidth(exam.getFlow().getMaximumBandwidth()));
        return report;
    });
    return serviceMock;
}
Also used : TraffExamService(org.openkilda.testing.service.traffexam.TraffExamService) Bandwidth(org.openkilda.testing.service.traffexam.model.Bandwidth) ExamReport(org.openkilda.testing.service.traffexam.model.ExamReport) Host(org.openkilda.testing.service.traffexam.model.Host) Exam(org.openkilda.testing.service.traffexam.model.Exam)

Example 2 with Host

use of org.openkilda.testing.service.traffexam.model.Host 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 3 with Host

use of org.openkilda.testing.service.traffexam.model.Host in project open-kilda by telstra.

the class FlowTrafficExamBuilder method buildYFlowExam.

/**
 * Build traff exam object for both 'y-flow' subflows in both directions.
 */
public YFlowBidirectionalExam buildYFlowExam(YFlow flow, long bandwidth, Long duration) throws FlowNotApplicableException {
    SubFlow subFlow1 = flow.getSubFlows().get(0);
    SubFlow subFlow2 = flow.getSubFlows().get(1);
    Optional<TraffGen> source = Optional.ofNullable(endpointToTraffGen.get(makeComparableEndpoint(flow.getSharedEndpoint())));
    Optional<TraffGen> dest1 = Optional.ofNullable(endpointToTraffGen.get(makeComparableEndpoint(subFlow1.getEndpoint())));
    Optional<TraffGen> dest2 = Optional.ofNullable(endpointToTraffGen.get(makeComparableEndpoint(subFlow2.getEndpoint())));
    checkIsFlowApplicable(flow.getYFlowId(), source.isPresent(), dest1.isPresent() && dest2.isPresent());
    List<Vlan> srcVlanIds1 = ImmutableList.of(new Vlan(subFlow1.getSharedEndpoint().getVlanId()), new Vlan(subFlow1.getSharedEndpoint().getInnerVlanId()));
    List<Vlan> srcVlanIds2 = ImmutableList.of(new Vlan(subFlow2.getSharedEndpoint().getVlanId()), new Vlan(subFlow2.getSharedEndpoint().getInnerVlanId()));
    List<Vlan> dstVlanIds1 = ImmutableList.of(new Vlan(subFlow1.getEndpoint().getVlanId()), new Vlan(subFlow1.getEndpoint().getInnerVlanId()));
    List<Vlan> dstVlanIds2 = ImmutableList.of(new Vlan(subFlow2.getEndpoint().getVlanId()), new Vlan(subFlow2.getEndpoint().getInnerVlanId()));
    // noinspection ConstantConditions
    Host sourceHost = traffExam.hostByName(source.get().getName());
    // noinspection ConstantConditions
    Host destHost1 = traffExam.hostByName(dest1.get().getName());
    Host destHost2 = traffExam.hostByName(dest2.get().getName());
    Exam forward1 = Exam.builder().flow(null).source(sourceHost).sourceVlans(srcVlanIds1).dest(destHost1).destVlans(dstVlanIds1).bandwidthLimit(new Bandwidth(bandwidth)).burstPkt(200).timeLimitSeconds(duration != null ? new TimeLimit(duration) : null).build();
    Exam forward2 = Exam.builder().flow(null).source(sourceHost).sourceVlans(srcVlanIds2).dest(destHost2).destVlans(dstVlanIds2).bandwidthLimit(new Bandwidth(bandwidth)).burstPkt(200).timeLimitSeconds(duration != null ? new TimeLimit(duration) : null).build();
    Exam reverse1 = Exam.builder().flow(null).source(destHost1).sourceVlans(dstVlanIds1).dest(sourceHost).destVlans(srcVlanIds1).bandwidthLimit(new Bandwidth(bandwidth)).burstPkt(200).timeLimitSeconds(duration != null ? new TimeLimit(duration) : null).build();
    Exam reverse2 = Exam.builder().flow(null).source(destHost2).sourceVlans(dstVlanIds2).dest(sourceHost).destVlans(srcVlanIds2).bandwidthLimit(new Bandwidth(bandwidth)).burstPkt(200).timeLimitSeconds(duration != null ? new TimeLimit(duration) : null).build();
    return new YFlowBidirectionalExam(forward1, reverse1, forward2, reverse2);
}
Also used : TraffGen(org.openkilda.testing.model.topology.TopologyDefinition.TraffGen) Bandwidth(org.openkilda.testing.service.traffexam.model.Bandwidth) Host(org.openkilda.testing.service.traffexam.model.Host) Vlan(org.openkilda.testing.service.traffexam.model.Vlan) SubFlow(org.openkilda.northbound.dto.v2.yflows.SubFlow) YFlowBidirectionalExam(org.openkilda.testing.service.traffexam.model.YFlowBidirectionalExam) Exam(org.openkilda.testing.service.traffexam.model.Exam) YFlowBidirectionalExam(org.openkilda.testing.service.traffexam.model.YFlowBidirectionalExam) FlowBidirectionalExam(org.openkilda.testing.service.traffexam.model.FlowBidirectionalExam) TimeLimit(org.openkilda.testing.service.traffexam.model.TimeLimit)

Example 4 with Host

use of org.openkilda.testing.service.traffexam.model.Host in project open-kilda by telstra.

the class FlowTrafficExamBuilder method buildBidirectionalExam.

/**
 * Builds bidirectional exam.
 */
public FlowBidirectionalExam buildBidirectionalExam(FlowPayload flow, long 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())));
    checkIsFlowApplicable(flow.getId(), source.isPresent(), dest.isPresent());
    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());
    Exam forward = Exam.builder().flow(flow).source(sourceHost).sourceVlans(srcVlanIds).dest(destHost).destVlans(dstVlanIds).bandwidthLimit(new Bandwidth(bandwidth)).burstPkt(0).timeLimitSeconds(duration != null ? new TimeLimit(duration) : null).build();
    Exam reverse = Exam.builder().flow(flow).source(destHost).sourceVlans(dstVlanIds).dest(sourceHost).destVlans(srcVlanIds).bandwidthLimit(new Bandwidth(bandwidth)).burstPkt(0).timeLimitSeconds(duration != null ? new TimeLimit(duration) : null).build();
    return new FlowBidirectionalExam(forward, reverse);
}
Also used : 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) YFlowBidirectionalExam(org.openkilda.testing.service.traffexam.model.YFlowBidirectionalExam) FlowBidirectionalExam(org.openkilda.testing.service.traffexam.model.FlowBidirectionalExam) Exam(org.openkilda.testing.service.traffexam.model.Exam) YFlowBidirectionalExam(org.openkilda.testing.service.traffexam.model.YFlowBidirectionalExam) FlowBidirectionalExam(org.openkilda.testing.service.traffexam.model.FlowBidirectionalExam) TimeLimit(org.openkilda.testing.service.traffexam.model.TimeLimit)

Example 5 with Host

use of org.openkilda.testing.service.traffexam.model.Host in project open-kilda by telstra.

the class TraffExamServiceImpl method initializePools.

@PostConstruct
void initializePools() {
    baseUrl = labEndpoint + "/api/" + topology.getLabId() + "/traffgen/";
    hostsPool = new ConcurrentHashMap<>();
    for (TraffGen traffGen : topology.getActiveTraffGens()) {
        URI controlEndpoint;
        try {
            controlEndpoint = new URI(traffGen.getControlEndpoint());
        } catch (URISyntaxException e) {
            throw new IllegalArgumentException(String.format("Invalid traffGen(%s) REST endpoint address \"%s\": %s", traffGen.getName(), traffGen.getControlEndpoint(), e.getMessage()), e);
        }
        UUID id = UUID.randomUUID();
        Host host = new Host(id, traffGen.getIfaceName(), controlEndpoint, traffGen.getName());
        try {
            restTemplate.headForHeaders(makeHostUri(host).path("endpoint").build());
        } catch (RestClientException ex) {
            throw new IllegalArgumentException(String.format("The traffGen(%s) REST endpoint address \"%s\" can't be reached: %s", traffGen.getName(), traffGen.getControlEndpoint(), ex.getMessage()), ex);
        }
        hostsPool.put(id, host);
    }
    TraffGenConfig config = topology.getTraffGenConfig();
    Inet4Network network;
    try {
        network = new Inet4Network((Inet4Address) Inet4Address.getByName(config.getAddressPoolBase()), config.getAddressPoolPrefixLen());
    } catch (Inet4ValueException | UnknownHostException e) {
        throw new InputMismatchException(String.format("Invalid traffGen address pool \"%s:%s\": %s", config.getAddressPoolBase(), config.getAddressPoolPrefixLen(), e));
    }
    addressPool = new Inet4NetworkPool(network, 30);
}
Also used : Inet4Address(java.net.Inet4Address) UnknownHostException(java.net.UnknownHostException) Host(org.openkilda.testing.service.traffexam.model.Host) URISyntaxException(java.net.URISyntaxException) InputMismatchException(java.util.InputMismatchException) URI(java.net.URI) TraffGen(org.openkilda.testing.model.topology.TopologyDefinition.TraffGen) Inet4Network(org.openkilda.testing.service.traffexam.networkpool.Inet4Network) Inet4ValueException(org.openkilda.testing.service.traffexam.networkpool.Inet4ValueException) RestClientException(org.springframework.web.client.RestClientException) TraffGenConfig(org.openkilda.testing.model.topology.TopologyDefinition.TraffGenConfig) Inet4NetworkPool(org.openkilda.testing.service.traffexam.networkpool.Inet4NetworkPool) UUID(java.util.UUID) PostConstruct(javax.annotation.PostConstruct)

Aggregations

Host (org.openkilda.testing.service.traffexam.model.Host)5 TraffGen (org.openkilda.testing.model.topology.TopologyDefinition.TraffGen)4 Bandwidth (org.openkilda.testing.service.traffexam.model.Bandwidth)4 Exam (org.openkilda.testing.service.traffexam.model.Exam)4 FlowBidirectionalExam (org.openkilda.testing.service.traffexam.model.FlowBidirectionalExam)3 TimeLimit (org.openkilda.testing.service.traffexam.model.TimeLimit)3 Vlan (org.openkilda.testing.service.traffexam.model.Vlan)3 YFlowBidirectionalExam (org.openkilda.testing.service.traffexam.model.YFlowBidirectionalExam)3 ArrayList (java.util.ArrayList)2 SubFlow (org.openkilda.northbound.dto.v2.yflows.SubFlow)2 TraffExamService (org.openkilda.testing.service.traffexam.TraffExamService)2 ImmutableList (com.google.common.collect.ImmutableList)1 String.format (java.lang.String.format)1 Inet4Address (java.net.Inet4Address)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 UnknownHostException (java.net.UnknownHostException)1 HashMap (java.util.HashMap)1 InputMismatchException (java.util.InputMismatchException)1 List (java.util.List)1