Search in sources :

Example 1 with PingContext

use of org.openkilda.wfm.topology.ping.model.PingContext in project open-kilda by telstra.

the class FlowFetcher method handlePeriodicRequest.

private void handlePeriodicRequest(Tuple input) throws PipelineException {
    log.debug("Handle periodic ping request");
    if (lastPeriodicPingCacheRefresh + periodicPingCacheExpiryInterval < System.currentTimeMillis()) {
        refreshHeap(input, true);
    }
    final CommandContext commandContext = pullContext(input);
    for (FlowWithTransitEncapsulation flow : flowsSet) {
        PingContext pingContext = PingContext.builder().group(new GroupId(DIRECTION_COUNT_PER_FLOW)).kind(Kinds.PERIODIC).flow(flow.getFlow()).yFlowId(flow.yFlowId).transitEncapsulation(flow.getTransitEncapsulation()).build();
        emit(input, pingContext, commandContext);
    }
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) PingContext(org.openkilda.wfm.topology.ping.model.PingContext) GroupId(org.openkilda.wfm.topology.ping.model.GroupId)

Example 2 with PingContext

use of org.openkilda.wfm.topology.ping.model.PingContext in project open-kilda by telstra.

the class GroupCollector method saveCurrentRecord.

private CollectorDescriptor saveCurrentRecord(Tuple input) throws Exception {
    final PingContext pingContext = pullPingContext(input);
    // expiring is only a memory leakage protection in this place
    // waiting ping command timeout + storm internal processing delay milliseconds
    long expireAt = System.currentTimeMillis() + pingContext.getTimeout() + expireDelay;
    CollectorDescriptor descriptor = new CollectorDescriptor(expireAt, pingContext.getGroup());
    descriptor = cache.addIfAbsent(descriptor);
    try {
        int size = descriptor.add(pingContext);
        GroupId group = descriptor.getGroupId();
        log.debug("Group {} add {} of {} response {}", group.getId(), size, group.getSize(), pingContext);
    } catch (IllegalArgumentException e) {
        throw new WorkflowException(this, input, e.toString());
    }
    return descriptor;
}
Also used : WorkflowException(org.openkilda.wfm.error.WorkflowException) CollectorDescriptor(org.openkilda.wfm.topology.ping.model.CollectorDescriptor) PingContext(org.openkilda.wfm.topology.ping.model.PingContext) GroupId(org.openkilda.wfm.topology.ping.model.GroupId)

Example 3 with PingContext

use of org.openkilda.wfm.topology.ping.model.PingContext in project open-kilda by telstra.

the class OnDemandResultManager method buildYFlowPingResponse.

private YFlowPingResponse buildYFlowPingResponse(Group group) {
    Map<String, SubFlowPingPayload> subFlowMap = new HashMap<>();
    Set<String> yFlowIdSet = new HashSet<>();
    for (PingContext record : group.getRecords()) {
        if (record.getYFlowId() == null) {
            throw new IllegalArgumentException(format("Ping report %s has no yFlowId", record));
        }
        yFlowIdSet.add(record.getYFlowId());
        SubFlowPingPayload subFlow = subFlowMap.computeIfAbsent(record.getFlowId(), mappingFunction -> new SubFlowPingPayload(record.getFlowId(), null, null));
        switch(record.getDirection()) {
            case FORWARD:
                validateSubFlow(subFlow.getForward(), FORWARD, group, record, subFlow.getFlowId());
                subFlow.setForward(makeSubFlowPayload(record));
                break;
            case REVERSE:
                validateSubFlow(subFlow.getReverse(), REVERSE, group, record, subFlow.getFlowId());
                subFlow.setReverse(makeSubFlowPayload(record));
                break;
            default:
                throw new IllegalArgumentException(format("Unsupported %s.%s value", record.getDirection().getClass().getName(), record.getDirection()));
        }
    }
    if (subFlowMap.size() * 2 != group.getRecords().size()) {
        throw new IllegalArgumentException(format("Expect %d unique Flow IDs in ping group responses, but got responses about %d Flows: %s", group.getRecords().size() / 2, subFlowMap.size(), subFlowMap.keySet()));
    }
    if (yFlowIdSet.size() != 1) {
        throw new IllegalArgumentException(format("Expect exact one Y Flow id in pings group response, got - %s", yFlowIdSet));
    }
    return new YFlowPingResponse(yFlowIdSet.iterator().next(), null, new ArrayList<>(subFlowMap.values()));
}
Also used : HashMap(java.util.HashMap) YFlowPingResponse(org.openkilda.messaging.info.flow.YFlowPingResponse) PingContext(org.openkilda.wfm.topology.ping.model.PingContext) UniSubFlowPingPayload(org.openkilda.messaging.info.flow.UniSubFlowPingPayload) SubFlowPingPayload(org.openkilda.messaging.info.flow.SubFlowPingPayload) HashSet(java.util.HashSet)

Example 4 with PingContext

use of org.openkilda.wfm.topology.ping.model.PingContext in project open-kilda by telstra.

the class OnDemandResultManager method produceFlowErrors.

private List<FlowPingResponse> produceFlowErrors(Group group, String errorMessage) {
    HashSet<String> seen = new HashSet<>();
    ArrayList<FlowPingResponse> results = new ArrayList<>();
    for (PingContext pingContext : group.getRecords()) {
        if (!seen.add(pingContext.getFlowId())) {
            continue;
        }
        log.info("Produce error response (group={}, flow={}): {}", group.getId(), pingContext.getFlowId(), errorMessage);
        results.add(new FlowPingResponse(pingContext.getFlowId(), errorMessage));
    }
    return results;
}
Also used : ArrayList(java.util.ArrayList) PingContext(org.openkilda.wfm.topology.ping.model.PingContext) YFlowPingResponse(org.openkilda.messaging.info.flow.YFlowPingResponse) UniFlowPingResponse(org.openkilda.messaging.info.flow.UniFlowPingResponse) FlowPingResponse(org.openkilda.messaging.info.flow.FlowPingResponse) HashSet(java.util.HashSet)

Example 5 with PingContext

use of org.openkilda.wfm.topology.ping.model.PingContext in project open-kilda by telstra.

the class PeriodicPingShaping method handlePing.

private void handlePing(Tuple input) throws PipelineException {
    Values output = extract(input);
    if (burstCalculator == null) {
        // ping-shaping disabled, silently proxying
        emit(input, output);
        return;
    }
    PingContext ping = pullPingContext(input);
    if (ping.getKind() != Kinds.PERIODIC) {
        emit(input, output);
        return;
    }
    burstCalculator.increment();
    proxy(input, output, ping);
    logStats();
}
Also used : Values(org.apache.storm.tuple.Values) PingContext(org.openkilda.wfm.topology.ping.model.PingContext)

Aggregations

PingContext (org.openkilda.wfm.topology.ping.model.PingContext)19 Values (org.apache.storm.tuple.Values)5 GroupId (org.openkilda.wfm.topology.ping.model.GroupId)4 HashSet (java.util.HashSet)3 YFlowPingResponse (org.openkilda.messaging.info.flow.YFlowPingResponse)3 CommandContext (org.openkilda.wfm.CommandContext)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 YFlowPingRequest (org.openkilda.messaging.command.flow.YFlowPingRequest)2 Flow (org.openkilda.model.Flow)2 FlowTransitEncapsulation (org.openkilda.model.FlowTransitEncapsulation)2 YFlow (org.openkilda.model.YFlow)2 YSubFlow (org.openkilda.model.YSubFlow)2 FlowPingRequest (org.openkilda.messaging.command.flow.FlowPingRequest)1 FlowPingResponse (org.openkilda.messaging.info.flow.FlowPingResponse)1 FlowPingResponseBuilder (org.openkilda.messaging.info.flow.FlowPingResponse.FlowPingResponseBuilder)1 SubFlowPingPayload (org.openkilda.messaging.info.flow.SubFlowPingPayload)1 UniFlowPingResponse (org.openkilda.messaging.info.flow.UniFlowPingResponse)1 UniSubFlowPingPayload (org.openkilda.messaging.info.flow.UniSubFlowPingPayload)1 WorkflowException (org.openkilda.wfm.error.WorkflowException)1