Search in sources :

Example 1 with FlowNotApplicableException

use of org.openkilda.testing.service.traffexam.FlowNotApplicableException 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)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 String.format (java.lang.String.format)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 NetworkEndpoint (org.openkilda.messaging.model.NetworkEndpoint)1 FlowEndpointPayload (org.openkilda.messaging.payload.flow.FlowEndpointPayload)1 FlowPayload (org.openkilda.messaging.payload.flow.FlowPayload)1 FlowEndpointV2 (org.openkilda.northbound.dto.v2.flows.FlowEndpointV2)1 SubFlow (org.openkilda.northbound.dto.v2.yflows.SubFlow)1 YFlow (org.openkilda.northbound.dto.v2.yflows.YFlow)1 YFlowSharedEndpoint (org.openkilda.northbound.dto.v2.yflows.YFlowSharedEndpoint)1 TopologyDefinition (org.openkilda.testing.model.topology.TopologyDefinition)1 Switch (org.openkilda.testing.model.topology.TopologyDefinition.Switch)1 TraffGen (org.openkilda.testing.model.topology.TopologyDefinition.TraffGen)1 FlowNotApplicableException (org.openkilda.testing.service.traffexam.FlowNotApplicableException)1 TraffExamService (org.openkilda.testing.service.traffexam.TraffExamService)1 Bandwidth (org.openkilda.testing.service.traffexam.model.Bandwidth)1