use of org.openkilda.model.cookie.FlowSegmentCookie 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.cookie.FlowSegmentCookie in project open-kilda by telstra.
the class FermaFlowMirrorPathRepositoryTest method createFlowPath.
private FlowMirrorPath createFlowPath(PathId pathId, long cookie, Switch srcSwitch, Switch dstSwitch, int dstPort, int dstOuterVlan, int dstInnerVlan) {
FlowMirrorPath flowMirrorPath = FlowMirrorPath.builder().pathId(pathId).cookie(new FlowSegmentCookie(cookie).toBuilder().mirror(true).build()).mirrorSwitch(srcSwitch).egressSwitch(dstSwitch).egressPort(dstPort).egressOuterVlan(dstOuterVlan).egressInnerVlan(dstInnerVlan).status(FlowPathStatus.ACTIVE).build();
flowMirrorPathRepository.add(flowMirrorPath);
return flowMirrorPath;
}
use of org.openkilda.model.cookie.FlowSegmentCookie in project open-kilda by telstra.
the class FermaFlowPathRepositoryTest method createFlowPath.
private FlowPath createFlowPath(Flow flow, String suffixName, long cookie, long meterId, Switch srcSwitch, Switch dstSwitch) {
FlowPath flowPath = FlowPath.builder().pathId(new PathId(flow.getFlowId() + suffixName)).cookie(new FlowSegmentCookie(cookie)).meterId(new MeterId(meterId)).srcSwitch(srcSwitch).destSwitch(dstSwitch).status(FlowPathStatus.ACTIVE).build();
flowPathRepository.add(flowPath);
return flowPath;
}
use of org.openkilda.model.cookie.FlowSegmentCookie in project open-kilda by telstra.
the class FlowSegmentCookieConverterTest method shouldConvertIdToLong.
@Test
public void shouldConvertIdToLong() {
// given
FlowSegmentCookie cookie = new FlowSegmentCookie((long) 0x123);
// when
Long graphObject = FlowSegmentCookieConverter.INSTANCE.toGraphProperty(cookie);
// then
assertEquals(cookie.getValue(), (long) graphObject);
}
use of org.openkilda.model.cookie.FlowSegmentCookie in project open-kilda by telstra.
the class NetworkSwitchServiceTest method newSwitchWithWrongSynchronizationResponse.
@Test
public void newSwitchWithWrongSynchronizationResponse() {
List<SpeakerSwitchPortView> ports = getSpeakerSwitchPortViews();
SpeakerSwitchView speakerSwitchView = getSpeakerSwitchView().toBuilder().ports(ports).build();
SwitchInfoData switchAddEvent = new SwitchInfoData(alphaDatapath, SwitchChangeType.ACTIVATED, alphaInetAddress.toString(), alphaDescription, speakerInetAddress.toString(), false, speakerSwitchView);
NetworkSwitchService service = new NetworkSwitchService(carrier, persistenceManager, options);
service.switchEvent(switchAddEvent);
RulesSyncEntry rulesSyncEntry = new RulesSyncEntry(singletonList(new FlowSegmentCookie(FlowPathDirection.FORWARD, 1).getValue()), emptyList(), emptyList(), emptyList(), emptyList(), emptyList());
MetersSyncEntry metersSyncEntry = new MetersSyncEntry(emptyList(), emptyList(), emptyList(), emptyList(), emptyList(), emptyList());
GroupSyncEntry groupSyncEntry = new GroupSyncEntry(emptyList(), emptyList(), emptyList(), emptyList(), emptyList(), emptyList(), emptyList());
SwitchSyncResponse response = new SwitchSyncResponse(alphaDatapath, rulesSyncEntry, metersSyncEntry, groupSyncEntry, LogicalPortsSyncEntry.builder().build());
// for a randomly generated key in SwitchFsm
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
verify(carrier).sendSwitchSynchronizeRequest(captor.capture(), eq(alphaDatapath));
service.switchManagerResponse(response, captor.getValue());
verify(carrier, times(SYNC_ATTEMPTS)).sendSwitchSynchronizeRequest(captor.capture(), eq(alphaDatapath));
service.switchManagerResponse(response, captor.getValue());
verifyNewSwitchAfterSwitchSync(ports);
verify(carrier).sendSwitchStateChanged(alphaDatapath, SwitchStatus.ACTIVE);
verifyNoMoreInteractions(carrier);
}
Aggregations