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()));
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations