Search in sources :

Example 6 with FlowTransitEncapsulation

use of org.openkilda.model.FlowTransitEncapsulation in project open-kilda by telstra.

the class FlowFetcher method handleOnDemandRequest.

private void handleOnDemandRequest(Tuple input) throws PipelineException {
    log.debug("Handle on demand ping request");
    FlowPingRequest request = pullOnDemandRequest(input);
    Optional<Flow> optionalFlow = flowRepository.findById(request.getFlowId());
    if (optionalFlow.isPresent()) {
        Flow flow = optionalFlow.get();
        flowRepository.detach(flow);
        if (!flow.isOneSwitchFlow()) {
            Optional<FlowTransitEncapsulation> transitEncapsulation = getTransitEncapsulation(flow);
            if (transitEncapsulation.isPresent()) {
                PingContext pingContext = PingContext.builder().group(new GroupId(DIRECTION_COUNT_PER_FLOW)).kind(Kinds.ON_DEMAND).flow(flow).transitEncapsulation(transitEncapsulation.get()).timeout(request.getTimeout()).build();
                emit(input, pingContext, pullContext(input));
            } else {
                emitOnDemandResponse(input, request, format("Encapsulation resource not found for flow %s", request.getFlowId()));
            }
        } else {
            emitOnDemandResponse(input, request, format("Flow %s should not be one switch flow", request.getFlowId()));
        }
    } else {
        emitOnDemandResponse(input, request, format("Flow %s does not exist", request.getFlowId()));
    }
}
Also used : FlowTransitEncapsulation(org.openkilda.model.FlowTransitEncapsulation) PingContext(org.openkilda.wfm.topology.ping.model.PingContext) FlowPingRequest(org.openkilda.messaging.command.flow.FlowPingRequest) YFlowPingRequest(org.openkilda.messaging.command.flow.YFlowPingRequest) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow) GroupId(org.openkilda.wfm.topology.ping.model.GroupId)

Example 7 with FlowTransitEncapsulation

use of org.openkilda.model.FlowTransitEncapsulation in project open-kilda by telstra.

the class RuleManagerImpl method buildRulesForFlowPath.

@Override
public List<SpeakerData> buildRulesForFlowPath(FlowPath flowPath, boolean filterOutUsedSharedRules, DataAdapter adapter) {
    List<SpeakerData> result = new ArrayList<>();
    Flow flow = adapter.getFlow(flowPath.getPathId());
    PathId oppositePathId = flow.getOppositePathId(flowPath.getPathId()).orElse(null);
    FlowTransitEncapsulation encapsulation = adapter.getTransitEncapsulation(flowPath.getPathId(), oppositePathId);
    if (!flow.isProtectedPath(flowPath.getPathId())) {
        Set<FlowSideAdapter> overlappingAdapters = new HashSet<>();
        if (filterOutUsedSharedRules) {
            overlappingAdapters = getOverlappingMultiTableIngressAdapters(flowPath, adapter);
        }
        buildIngressCommands(adapter.getSwitch(flowPath.getSrcSwitchId()), flowPath, flow, encapsulation, overlappingAdapters, adapter.getSwitchProperties(flowPath.getSrcSwitchId()), adapter.getFeatureToggles());
    }
    if (flowPath.isOneSwitchFlow()) {
        return result;
    }
    result.addAll(buildEgressCommands(adapter.getSwitch(flowPath.getDestSwitchId()), flowPath, flow, encapsulation));
    for (int i = 1; i < flowPath.getSegments().size(); i++) {
        PathSegment firstSegment = flowPath.getSegments().get(i - 1);
        PathSegment secondSegment = flowPath.getSegments().get(i);
        result.addAll(buildTransitCommands(adapter.getSwitch(firstSegment.getDestSwitchId()), flowPath, encapsulation, firstSegment, secondSegment));
    }
    if (flow.isLooped()) {
        Switch loopedSwitch = adapter.getSwitch(flow.getLoopSwitchId());
        result.addAll(buildTransitLoopCommands(loopedSwitch, flowPath, flow, encapsulation));
    }
    return postProcessCommands(result);
}
Also used : PathId(org.openkilda.model.PathId) Switch(org.openkilda.model.Switch) ArrayList(java.util.ArrayList) FlowTransitEncapsulation(org.openkilda.model.FlowTransitEncapsulation) FlowSideAdapter(org.openkilda.adapter.FlowSideAdapter) PathSegment(org.openkilda.model.PathSegment) FlowEndpoint(org.openkilda.model.FlowEndpoint) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) HashSet(java.util.HashSet)

Example 8 with FlowTransitEncapsulation

use of org.openkilda.model.FlowTransitEncapsulation in project open-kilda by telstra.

the class RuleManagerImpl method buildIngressYFlowCommands.

private List<SpeakerData> buildIngressYFlowCommands(FlowPath flowPath, FlowPath altFlowPath, DataAdapter adapter) {
    Flow flow = adapter.getFlow(flowPath.getPathId());
    Flow altFlow = adapter.getFlow(altFlowPath.getPathId());
    if (flow.isProtectedPath(flowPath.getPathId()) || altFlow.isProtectedPath(altFlowPath.getPathId())) {
        return Collections.emptyList();
    }
    YFlow yFlow = adapter.getYFlow(flowPath.getPathId());
    if (yFlow == null) {
        return Collections.emptyList();
    }
    SwitchId sharedSwitchId = yFlow.getSharedEndpoint().getSwitchId();
    Switch sharedSwitch = adapter.getSwitch(sharedSwitchId);
    if (sharedSwitch == null || !sharedSwitchId.equals(flowPath.getSrcSwitchId()) || !sharedSwitchId.equals(altFlowPath.getSrcSwitchId())) {
        return Collections.emptyList();
    }
    FlowTransitEncapsulation encapsulation = getFlowTransitEncapsulation(flowPath.getPathId(), flow, adapter);
    FlowTransitEncapsulation altEncapsulation = getFlowTransitEncapsulation(altFlowPath.getPathId(), altFlow, adapter);
    MeterId sharedMeterId = yFlow.getSharedEndpointMeterId();
    RuleGenerator generator = flowRulesFactory.getIngressYRuleGenerator(flowPath, flow, encapsulation, new HashSet<>(), altFlowPath, altFlow, altEncapsulation, new HashSet<>(), sharedMeterId);
    return generator.generateCommands(sharedSwitch);
}
Also used : YFlow(org.openkilda.model.YFlow) Switch(org.openkilda.model.Switch) FlowTransitEncapsulation(org.openkilda.model.FlowTransitEncapsulation) SwitchId(org.openkilda.model.SwitchId) RuleGenerator(org.openkilda.rulemanager.factory.RuleGenerator) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) MeterId(org.openkilda.model.MeterId)

Example 9 with FlowTransitEncapsulation

use of org.openkilda.model.FlowTransitEncapsulation in project open-kilda by telstra.

the class RuleManagerImpl method buildTransitYFlowCommands.

private List<SpeakerData> buildTransitYFlowCommands(FlowPath flowPath, FlowPath altFlowPath, DataAdapter adapter) {
    Flow flow = adapter.getFlow(flowPath.getPathId());
    Flow altFlow = adapter.getFlow(altFlowPath.getPathId());
    YFlow yFlow = adapter.getYFlow(flowPath.getPathId());
    if (yFlow == null) {
        return Collections.emptyList();
    }
    SwitchId sharedSwitchId = yFlow.getSharedEndpoint().getSwitchId();
    if (sharedSwitchId.equals(flowPath.getSrcSwitchId()) || sharedSwitchId.equals(altFlowPath.getSrcSwitchId())) {
        return Collections.emptyList();
    }
    SwitchId yPointSwitchId = yFlow.getYPoint();
    MeterId yPointMeterId = yFlow.getMeterId();
    if (flow.isProtectedPath(flowPath.getPathId()) && altFlow.isProtectedPath(altFlowPath.getPathId())) {
        yPointSwitchId = yFlow.getProtectedPathYPoint();
        yPointMeterId = yFlow.getProtectedPathMeterId();
    }
    Switch yPointSwitch = adapter.getSwitch(yPointSwitchId);
    if (yPointSwitch == null) {
        return Collections.emptyList();
    }
    FlowTransitEncapsulation encapsulation = getFlowTransitEncapsulation(flowPath.getPathId(), flow, adapter);
    FlowTransitEncapsulation altEncapsulation = getFlowTransitEncapsulation(altFlowPath.getPathId(), altFlow, adapter);
    SwitchPathSegments switchPathSegments = findPathSegmentsForSwitch(yPointSwitchId, flowPath.getSegments());
    SwitchPathSegments altSwitchPathSegments = findPathSegmentsForSwitch(yPointSwitchId, altFlowPath.getSegments());
    if (switchPathSegments == null || altSwitchPathSegments == null) {
        return Collections.emptyList();
    }
    RuleGenerator generator = flowRulesFactory.getTransitYRuleGenerator(flowPath, encapsulation, switchPathSegments.getFirstPathSegment(), switchPathSegments.getSecondPathSegment(), altFlowPath, altEncapsulation, altSwitchPathSegments.getFirstPathSegment(), altSwitchPathSegments.getSecondPathSegment(), yPointMeterId);
    return generator.generateCommands(yPointSwitch);
}
Also used : YFlow(org.openkilda.model.YFlow) Switch(org.openkilda.model.Switch) FlowTransitEncapsulation(org.openkilda.model.FlowTransitEncapsulation) SwitchId(org.openkilda.model.SwitchId) RuleGenerator(org.openkilda.rulemanager.factory.RuleGenerator) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) MeterId(org.openkilda.model.MeterId)

Example 10 with FlowTransitEncapsulation

use of org.openkilda.model.FlowTransitEncapsulation in project open-kilda by telstra.

the class FlowPingResponseTest method serializeLoop.

@Test
public void serializeLoop() throws Exception {
    NetworkEndpoint endpointAlpha = new NetworkEndpoint(new SwitchId("ff:fe:00:00:00:00:00:01"), 8);
    NetworkEndpoint endpointBeta = new NetworkEndpoint(new SwitchId("ff:fe:00:00:00:00:00:02"), 10);
    UniFlowPingResponse forward = new UniFlowPingResponse(new Ping(endpointAlpha, endpointBeta, new FlowTransitEncapsulation(4, FlowEncapsulationType.TRANSIT_VLAN), 5), new PingMeters(1L, 2L, 3L), null);
    UniFlowPingResponse reverse = new UniFlowPingResponse(new Ping(endpointBeta, endpointAlpha, new FlowTransitEncapsulation(4, FlowEncapsulationType.TRANSIT_VLAN), 5), new PingMeters(3L, 2L, 1L), null);
    FlowPingResponse origin = new FlowPingResponse("flowId-" + getClass().getSimpleName(), forward, reverse, null);
    InfoMessage wrapper = new InfoMessage(origin, System.currentTimeMillis(), getClass().getSimpleName());
    serializer.serialize(wrapper);
    InfoMessage decodedWrapper = (InfoMessage) serializer.deserialize();
    InfoData decoded = decodedWrapper.getData();
    Assert.assertEquals(String.format("%s object have been mangled in serialisation/deserialization loop", origin.getClass().getName()), origin, decoded);
}
Also used : NetworkEndpoint(org.openkilda.messaging.model.NetworkEndpoint) InfoMessage(org.openkilda.messaging.info.InfoMessage) InfoData(org.openkilda.messaging.info.InfoData) Ping(org.openkilda.messaging.model.Ping) FlowTransitEncapsulation(org.openkilda.model.FlowTransitEncapsulation) SwitchId(org.openkilda.model.SwitchId) PingMeters(org.openkilda.messaging.model.PingMeters) Test(org.junit.Test)

Aggregations

FlowTransitEncapsulation (org.openkilda.model.FlowTransitEncapsulation)21 SwitchId (org.openkilda.model.SwitchId)12 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)7 Flow (org.openkilda.model.Flow)7 YFlow (org.openkilda.model.YFlow)6 InfoMessage (org.openkilda.messaging.info.InfoMessage)5 NetworkEndpoint (org.openkilda.messaging.model.NetworkEndpoint)5 Ping (org.openkilda.messaging.model.Ping)5 PathId (org.openkilda.model.PathId)5 Switch (org.openkilda.model.Switch)5 Ethernet (net.floodlightcontroller.packet.Ethernet)3 IPacket (net.floodlightcontroller.packet.IPacket)3 FlowEndpoint (org.openkilda.model.FlowEndpoint)3 PathSegment (org.openkilda.model.PathSegment)3 HashSet (java.util.HashSet)2 EgressFlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.EgressFlowSegmentRequestFactory)2 FlowTransitData (org.openkilda.floodlight.model.FlowTransitData)2 InputService (org.openkilda.floodlight.service.of.InputService)2 MessageContext (org.openkilda.messaging.MessageContext)2