Search in sources :

Example 1 with SubFlowPingPayload

use of org.openkilda.messaging.info.flow.SubFlowPingPayload in project open-kilda by telstra.

the class YFlowMapperTest method pingResultTest.

@Test
public void pingResultTest() {
    YFlowPingResponse response = new YFlowPingResponse(Y_FLOW_ID, false, ERROR_MESSAGE, Lists.newArrayList(new SubFlowPingPayload(SUB_FLOW_1, new UniSubFlowPingPayload(true, null, 1), new UniSubFlowPingPayload(false, Errors.TIMEOUT, 2)), new SubFlowPingPayload(SUB_FLOW_2, new UniSubFlowPingPayload(false, Errors.DEST_NOT_AVAILABLE, 3), new UniSubFlowPingPayload(true, null, 4))));
    YFlowPingResult result = mapper.toPingResult(response);
    assertEquals(response.getYFlowId(), result.getYFlowId());
    assertEquals(response.isPingSuccess(), result.isPingSuccess());
    assertEquals(response.getError(), result.getError());
    assertEquals(response.getSubFlows().size(), result.getSubFlows().size());
    assertSubFlowPingPayload(response.getSubFlows().get(0), result.getSubFlows().get(0));
}
Also used : YFlowPingResult(org.openkilda.northbound.dto.v2.yflows.YFlowPingResult) UniSubFlowPingPayload(org.openkilda.messaging.info.flow.UniSubFlowPingPayload) YFlowPingResponse(org.openkilda.messaging.info.flow.YFlowPingResponse) UniSubFlowPingPayload(org.openkilda.messaging.info.flow.UniSubFlowPingPayload) SubFlowPingPayload(org.openkilda.messaging.info.flow.SubFlowPingPayload) Test(org.junit.Test)

Example 2 with SubFlowPingPayload

use of org.openkilda.messaging.info.flow.SubFlowPingPayload 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)

Aggregations

SubFlowPingPayload (org.openkilda.messaging.info.flow.SubFlowPingPayload)2 UniSubFlowPingPayload (org.openkilda.messaging.info.flow.UniSubFlowPingPayload)2 YFlowPingResponse (org.openkilda.messaging.info.flow.YFlowPingResponse)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1 YFlowPingResult (org.openkilda.northbound.dto.v2.yflows.YFlowPingResult)1 PingContext (org.openkilda.wfm.topology.ping.model.PingContext)1