use of org.openkilda.model.YFlow in project open-kilda by telstra.
the class YFlowSwitchFlowEntriesBuilder method getFlowEntries.
/**
* Construct a set of {@link FlowEntry} that corresponds to the builder's y-flow.
*/
public Map<SwitchId, Collection<FlowEntry>> getFlowEntries() {
MultiValuedMap<SwitchId, FlowEntry> flowEntries = new ArrayListValuedHashMap<>();
yFlow.getSubFlows().forEach(subFlow -> {
Flow flow = subFlow.getFlow();
SwitchFlowEntriesBuilder builder = new SwitchFlowEntriesBuilder(flow);
int forwardTransitEncId = getEncapsulationId(flow.getEncapsulationType(), flow.getForwardPathId()).orElseThrow(IllegalStateException::new);
int reverseTransitEncId = getEncapsulationId(flow.getEncapsulationType(), flow.getReversePathId()).orElseThrow(IllegalStateException::new);
Integer protectedForwardTransitEncId = getEncapsulationId(flow.getEncapsulationType(), flow.getProtectedForwardPathId()).orElse(null);
Integer protectedReverseTransitEncId = getEncapsulationId(flow.getEncapsulationType(), flow.getProtectedReversePathId()).orElse(null);
builder.getSwitchFlowEntries(forwardTransitEncId, reverseTransitEncId, protectedForwardTransitEncId, protectedReverseTransitEncId).forEach(entries -> flowEntries.putAll(entries.getSwitchId(), entries.getFlowEntries()));
FlowPath forwardPath = flow.getForwardPath();
PathSegment firstSegment = forwardPath.getSegments().get(0);
FlowSegmentCookie forwardCookie = forwardPath.getCookie().toBuilder().yFlow(true).build();
boolean isVxlan = flow.getEncapsulationType() == VXLAN;
flowEntries.put(forwardPath.getSrcSwitchId(), builder.getFlowEntry(forwardCookie.getValue(), flow.getSrcPort(), flow.getSrcVlan(), null, firstSegment.getSrcPort(), isVxlan ? null : forwardTransitEncId, isVxlan ? forwardTransitEncId : null, yFlow.getSharedEndpointMeterId().getValue()));
if (!yFlow.getYPoint().equals(flow.getSrcSwitchId())) {
FlowPath reversePath = flow.getReversePath();
FlowSegmentCookie reverseCookie = reversePath.getCookie().toBuilder().yFlow(true).build();
List<PathSegment> reverseSegments = reversePath.getSegments();
for (int i = 0; i < reverseSegments.size() - 1; i++) {
PathSegment nsegment = reverseSegments.get(i);
PathSegment n1segment = reverseSegments.get(i + 1);
if (nsegment.getDestSwitchId().equals(yFlow.getYPoint())) {
flowEntries.put(yFlow.getYPoint(), builder.getFlowEntry(reverseCookie.getValue(), n1segment.getSrcPort(), isVxlan ? null : reverseTransitEncId, isVxlan ? reverseTransitEncId : null, nsegment.getDestPort(), null, null, yFlow.getMeterId().getValue()));
}
}
}
if (yFlow.isAllocateProtectedPath() && yFlow.getProtectedPathYPoint() != null && !yFlow.getProtectedPathYPoint().equals(flow.getSrcSwitchId())) {
FlowPath reversePath = flow.getProtectedReversePath();
FlowSegmentCookie reverseCookie = reversePath.getCookie().toBuilder().yFlow(true).build();
List<PathSegment> reverseSegments = reversePath.getSegments();
for (int i = 0; i < reverseSegments.size() - 1; i++) {
PathSegment nsegment = reverseSegments.get(i);
PathSegment n1segment = reverseSegments.get(i + 1);
if (nsegment.getDestSwitchId().equals(yFlow.getProtectedPathYPoint())) {
flowEntries.put(yFlow.getProtectedPathYPoint(), builder.getFlowEntry(reverseCookie.getValue(), n1segment.getSrcPort(), isVxlan ? null : reverseTransitEncId, isVxlan ? reverseTransitEncId : null, nsegment.getDestPort(), null, null, yFlow.getProtectedPathMeterId().getValue()));
}
}
}
});
return flowEntries.asMap();
}
use of org.openkilda.model.YFlow in project open-kilda by telstra.
the class AbstractYFlowTest method verifyAffinity.
protected void verifyAffinity(String yFlowId) {
YFlow flow = getYFlow(yFlowId);
Set<String> affinityGroups = flow.getSubFlows().stream().map(YSubFlow::getFlow).map(Flow::getAffinityGroupId).collect(Collectors.toSet());
assertEquals(1, affinityGroups.size());
String affinityGroupId = affinityGroups.iterator().next();
Set<String> subFlowIds = flow.getSubFlows().stream().map(YSubFlow::getSubFlowId).collect(Collectors.toSet());
assertTrue(subFlowIds.contains(affinityGroupId));
}
use of org.openkilda.model.YFlow in project open-kilda by telstra.
the class AbstractYFlowTest method verifyYFlowAndSubFlowStatus.
protected void verifyYFlowAndSubFlowStatus(String yFlowId, FlowStatus expectedStatus) {
YFlow flow = getYFlow(yFlowId);
assertEquals(expectedStatus, flow.getStatus());
flow.getSubFlows().forEach(subFlow -> {
assertEquals(expectedStatus, subFlow.getFlow().getStatus());
});
}
use of org.openkilda.model.YFlow in project open-kilda by telstra.
the class AbstractYFlowTest method verifyYFlowStatus.
protected void verifyYFlowStatus(String yFlowId, FlowStatus expectedStatus) {
YFlow flow = getYFlow(yFlowId);
assertEquals(expectedStatus, flow.getStatus());
}
use of org.openkilda.model.YFlow in project open-kilda by telstra.
the class PersistenceDataAdapterTest method shouldProvideCorrectYFlows.
@Test
public void shouldProvideCorrectYFlows() {
PathId pathId = new PathId("path1");
Set<PathId> pathIds = Sets.newHashSet(pathId);
YFlow yFlow = YFlow.builder().yFlowId("flow").sharedEndpoint(new SharedEndpoint(SWITCH_ID_1, 1)).build();
Map<PathId, YFlow> yFlows = new HashMap<>();
yFlows.put(pathId, yFlow);
when(flowPathRepository.findYFlowsByPathIds(pathIds)).thenReturn(yFlows);
adapter = PersistenceDataAdapter.builder().pathIds(pathIds).persistenceManager(persistenceManager).build();
YFlow actual = adapter.getYFlow(pathId);
assertEquals(yFlow, actual);
adapter.getYFlow(new PathId("test"));
verify(flowPathRepository).findYFlowsByPathIds(pathIds);
verifyNoMoreInteractions(flowPathRepository);
}
Aggregations