Search in sources :

Example 46 with FlowSegmentCookie

use of org.openkilda.model.cookie.FlowSegmentCookie in project open-kilda by telstra.

the class MultiTableServer42IngressRuleGenerator method buildServer42IngressCommand.

private FlowSpeakerData buildServer42IngressCommand(Switch sw, FlowEndpoint ingressEndpoint, Set<FieldMatch> match, int priority) {
    FlowSegmentCookie cookie = new FlowSegmentCookie(flowPath.getCookie().getValue()).toBuilder().type(CookieType.SERVER_42_FLOW_RTT_INGRESS).build();
    FlowSpeakerDataBuilder<?, ?> builder = FlowSpeakerData.builder().switchId(ingressEndpoint.getSwitchId()).ofVersion(OfVersion.of(sw.getOfVersion())).cookie(cookie).table(OfTable.INGRESS).priority(priority).match(match).instructions(buildIngressInstructions(sw, ingressEndpoint.getInnerVlanId()));
    if (sw.getFeatures().contains(SwitchFeature.RESET_COUNTS_FLAG)) {
        builder.flags(Sets.newHashSet(OfFlowFlag.RESET_COUNTERS));
    }
    return builder.build();
}
Also used : FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie)

Example 47 with FlowSegmentCookie

use of org.openkilda.model.cookie.FlowSegmentCookie in project open-kilda by telstra.

the class RerouteServiceTest method setup.

@Before
public void setup() throws Throwable {
    doAnswer(invocation -> {
        TransactionCallbackWithoutResult<?> arg = invocation.getArgument(0);
        arg.doInTransaction();
        return null;
    }).when(transactionManager).doInTransaction(Mockito.<TransactionCallbackWithoutResult<?>>any());
    doAnswer(invocation -> {
        TransactionCallback<?, ?> arg = invocation.getArgument(0);
        return arg.doInTransaction();
    }).when(transactionManager).doInTransaction(Mockito.<TransactionCallback<?, ?>>any());
    pinnedFlow = Flow.builder().flowId(FLOW_ID).srcSwitch(SWITCH_A).destSwitch(SWITCH_C).pinned(true).build();
    FlowPath pinnedFlowForwardPath = FlowPath.builder().pathId(new PathId("1")).srcSwitch(SWITCH_A).destSwitch(SWITCH_C).cookie(new FlowSegmentCookie(FlowPathDirection.FORWARD, 1)).build();
    List<PathSegment> pinnedFlowForwardSegments = new ArrayList<>();
    pinnedFlowForwardSegments.add(PathSegment.builder().pathId(pinnedFlowForwardPath.getPathId()).srcSwitch(SWITCH_A).srcPort(1).destSwitch(SWITCH_B).destPort(1).build());
    pinnedFlowForwardSegments.add(PathSegment.builder().pathId(pinnedFlowForwardPath.getPathId()).srcSwitch(SWITCH_B).srcPort(2).destSwitch(SWITCH_C).destPort(1).build());
    pinnedFlowForwardPath.setSegments(pinnedFlowForwardSegments);
    FlowPath pinnedFlowReversePath = FlowPath.builder().pathId(new PathId("2")).srcSwitch(SWITCH_C).destSwitch(SWITCH_A).cookie(new FlowSegmentCookie(FlowPathDirection.REVERSE, 2)).build();
    List<PathSegment> pinnedFlowReverseSegments = new ArrayList<>();
    pinnedFlowReverseSegments.add(PathSegment.builder().pathId(pinnedFlowReversePath.getPathId()).srcSwitch(SWITCH_C).srcPort(1).destSwitch(SWITCH_B).destPort(2).build());
    pinnedFlowReverseSegments.add(PathSegment.builder().pathId(pinnedFlowReversePath.getPathId()).srcSwitch(SWITCH_B).srcPort(1).destSwitch(SWITCH_A).destPort(1).build());
    pinnedFlowReversePath.setSegments(pinnedFlowReverseSegments);
    pinnedFlow.setForwardPath(pinnedFlowForwardPath);
    pinnedFlow.setReversePath(pinnedFlowReversePath);
    regularFlow = Flow.builder().flowId(FLOW_ID).srcSwitch(SWITCH_A).destSwitch(SWITCH_C).pinned(false).priority(2).build();
    FlowPath regularFlowForwardPath = FlowPath.builder().pathId(new PathId("3")).srcSwitch(SWITCH_A).destSwitch(SWITCH_C).cookie(new FlowSegmentCookie(FlowPathDirection.FORWARD, 3)).status(FlowPathStatus.ACTIVE).build();
    List<PathSegment> unpinnedFlowForwardSegments = new ArrayList<>();
    unpinnedFlowForwardSegments.add(PathSegment.builder().pathId(regularFlowForwardPath.getPathId()).srcSwitch(SWITCH_A).srcPort(1).destSwitch(SWITCH_B).destPort(1).build());
    unpinnedFlowForwardSegments.add(PathSegment.builder().pathId(regularFlowForwardPath.getPathId()).srcSwitch(SWITCH_B).srcPort(2).destSwitch(SWITCH_C).destPort(1).build());
    regularFlowForwardPath.setSegments(unpinnedFlowForwardSegments);
    FlowPath regularFlowReversePath = FlowPath.builder().pathId(new PathId("4")).srcSwitch(SWITCH_C).destSwitch(SWITCH_A).cookie(new FlowSegmentCookie(FlowPathDirection.REVERSE, 3)).status(FlowPathStatus.ACTIVE).build();
    List<PathSegment> unpinnedFlowReverseSegments = new ArrayList<>();
    unpinnedFlowReverseSegments.add(PathSegment.builder().pathId(regularFlowReversePath.getPathId()).srcSwitch(SWITCH_C).srcPort(1).destSwitch(SWITCH_B).destPort(2).build());
    unpinnedFlowReverseSegments.add(PathSegment.builder().pathId(regularFlowReversePath.getPathId()).srcSwitch(SWITCH_B).srcPort(1).destSwitch(SWITCH_A).destPort(1).build());
    regularFlowReversePath.setSegments(unpinnedFlowReverseSegments);
    regularFlow.setForwardPath(regularFlowForwardPath);
    regularFlow.setReversePath(regularFlowReversePath);
    oneSwitchFlow = Flow.builder().flowId(FLOW_ID).srcSwitch(SWITCH_A).destSwitch(SWITCH_A).build();
    FlowPath oneSwitchFlowForwardPath = FlowPath.builder().pathId(new PathId("5")).srcSwitch(SWITCH_A).destSwitch(SWITCH_A).cookie(new FlowSegmentCookie(FlowPathDirection.FORWARD, 4)).status(FlowPathStatus.ACTIVE).build();
    FlowPath oneSwitchFlowReversePath = FlowPath.builder().pathId(new PathId("6")).srcSwitch(SWITCH_A).destSwitch(SWITCH_A).cookie(new FlowSegmentCookie(FlowPathDirection.REVERSE, 4)).status(FlowPathStatus.ACTIVE).build();
    oneSwitchFlow.setForwardPath(oneSwitchFlowForwardPath);
    oneSwitchFlow.setReversePath(oneSwitchFlowReversePath);
    regularYFlow = YFlow.builder().yFlowId(YFLOW_ID).priority(2).sharedEndpoint(new SharedEndpoint(SWITCH_A.getSwitchId(), 10)).build();
    FlowPath regularYFlowForwardPath = FlowPath.builder().pathId(new PathId("3")).srcSwitch(SWITCH_A).destSwitch(SWITCH_C).cookie(new FlowSegmentCookie(FlowPathDirection.FORWARD, 3)).status(FlowPathStatus.ACTIVE).build();
    regularYFlowForwardPath.setSegments(unpinnedFlowForwardSegments);
    FlowPath regularYFlowReversePath = FlowPath.builder().pathId(new PathId("4")).srcSwitch(SWITCH_C).destSwitch(SWITCH_A).cookie(new FlowSegmentCookie(FlowPathDirection.REVERSE, 3)).status(FlowPathStatus.ACTIVE).build();
    regularYFlowReversePath.setSegments(unpinnedFlowReverseSegments);
    subFlow = Flow.builder().flowId(SUB_YFLOW_ID).srcSwitch(SWITCH_A).destSwitch(SWITCH_C).pinned(false).priority(2).yFlowId(YFLOW_ID).yFlow(regularYFlow).build();
    subFlow.setForwardPath(regularYFlowForwardPath);
    subFlow.setReversePath(regularYFlowReversePath);
    Set<YSubFlow> subFlows = Collections.singleton(YSubFlow.builder().yFlow(regularYFlow).flow(subFlow).build());
    regularYFlow.setSubFlows(subFlows);
}
Also used : PathId(org.openkilda.model.PathId) FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) ArrayList(java.util.ArrayList) SharedEndpoint(org.openkilda.model.YFlow.SharedEndpoint) PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath) YSubFlow(org.openkilda.model.YSubFlow) Before(org.junit.Before)

Example 48 with FlowSegmentCookie

use of org.openkilda.model.cookie.FlowSegmentCookie in project open-kilda by telstra.

the class TestFlowBuilder method build.

/**
 * Build a Flow with set properties.
 */
public Flow build() {
    Switch srcSwitch = source.sw;
    Switch destSwitch = destination.sw;
    if (srcSwitch.getSwitchId().equals(destSwitch.getSwitchId())) {
        checkArgument(transit.isEmpty(), "Transit endpoints were provided for a one-switch flow");
        checkArgument(protectedTransit.isEmpty(), "ProtectedTransit endpoints were provided for a one-switch flow");
    } else {
        checkArgument(transit.isEmpty() || transit.size() % 2 == 0, "The number of transit endpoints is wrong");
    }
    checkArgument(protectedTransit.isEmpty() || protectedUnmaskedCookie != unmaskedCookie, "Same unmasked cookies provided with enabled ProtectedTransit");
    Flow flow = Flow.builder().flowId(flowId).yFlowId(yFlowId).srcSwitch(srcSwitch).srcPort(source.port).srcVlan(srcVlan).destSwitch(destSwitch).destPort(destination.port).destVlan(destVlan).bandwidth(bandwidth).ignoreBandwidth(ignoreBandwidth).encapsulationType(encapsulationType).maxLatency(maxLatency).priority(priority).detectConnectedDevices(detectConnectedDevices).pathComputationStrategy(pathComputationStrategy).description(description).build();
    flow.setStatus(status);
    FlowPath forwardPath = buildFlowPath(flow, srcSwitch, destSwitch, transit, new FlowSegmentCookie(FlowPathDirection.FORWARD, unmaskedCookie), new MeterId(forwardMeterId));
    flow.setForwardPath(forwardPath);
    FlowPath reversePath = buildFlowPath(flow, destSwitch, srcSwitch, Lists.reverse(transit), new FlowSegmentCookie(FlowPathDirection.REVERSE, unmaskedCookie), new MeterId(reverseMeterId));
    flow.setReversePath(reversePath);
    if (!protectedTransit.isEmpty()) {
        FlowPath protectedForwardPath = buildFlowPath(flow, srcSwitch, destSwitch, protectedTransit, new FlowSegmentCookie(FlowPathDirection.FORWARD, protectedUnmaskedCookie), new MeterId(protectedForwardMeterId));
        flow.setProtectedForwardPath(protectedForwardPath);
        FlowPath protectedReversePath = buildFlowPath(flow, destSwitch, srcSwitch, Lists.reverse(protectedTransit), new FlowSegmentCookie(FlowPathDirection.REVERSE, protectedUnmaskedCookie), new MeterId(protectedReverseMeterId));
        flow.setProtectedReversePath(protectedReversePath);
    }
    return flow;
}
Also used : FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) Switch(org.openkilda.model.Switch) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow) MeterId(org.openkilda.model.MeterId)

Example 49 with FlowSegmentCookie

use of org.openkilda.model.cookie.FlowSegmentCookie in project open-kilda by telstra.

the class FlowMapper method buildPath.

private FlowPath buildPath(FlowDto flowDto) {
    Switch srcSwitch = Switch.builder().switchId(flowDto.getSourceSwitch()).build();
    Switch destSwitch = Switch.builder().switchId(flowDto.getDestinationSwitch()).build();
    return FlowPath.builder().srcSwitch(srcSwitch).destSwitch(destSwitch).cookie(new FlowSegmentCookie(flowDto.getCookie())).bandwidth(flowDto.getBandwidth()).ignoreBandwidth(flowDto.isIgnoreBandwidth()).pathId(new PathId(UUID.randomUUID().toString())).meterId(flowDto.getMeterId() != null ? new MeterId(flowDto.getMeterId()) : null).build();
}
Also used : PathId(org.openkilda.model.PathId) FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) Switch(org.openkilda.model.Switch) MeterId(org.openkilda.model.MeterId)

Example 50 with FlowSegmentCookie

use of org.openkilda.model.cookie.FlowSegmentCookie in project open-kilda by telstra.

the class CommandBuilderImplTest method shouldBuildRemoveFlowWithoutMeterFromFlowEntryWithTransitVlanEncapsulation.

@Test
public void shouldBuildRemoveFlowWithoutMeterFromFlowEntryWithTransitVlanEncapsulation() {
    Long cookie = new FlowSegmentCookie(FlowPathDirection.FORWARD, 1).getValue();
    String inPort = "1";
    String inVlan = "10";
    String outPort = "2";
    FlowEntry flowEntry = buildFlowEntry(cookie, inPort, inVlan, outPort, null, false, null, null);
    RemoveFlow removeFlow = commandBuilder.buildRemoveFlowWithoutMeterFromFlowEntry(SWITCH_ID_A, flowEntry);
    assertEquals(cookie, removeFlow.getCookie());
    DeleteRulesCriteria criteria = removeFlow.getCriteria();
    assertEquals(cookie, criteria.getCookie());
    assertEquals(Integer.valueOf(inPort), criteria.getInPort());
    assertEquals(Integer.valueOf(inVlan), criteria.getEncapsulationId());
    assertEquals(Integer.valueOf(outPort), criteria.getOutPort());
    assertNull(criteria.getMetadataValue());
    assertNull(criteria.getMetadataMask());
}
Also used : FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) DeleteRulesCriteria(org.openkilda.messaging.command.switches.DeleteRulesCriteria) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry) Test(org.junit.Test)

Aggregations

FlowSegmentCookie (org.openkilda.model.cookie.FlowSegmentCookie)59 Flow (org.openkilda.model.Flow)33 FlowPath (org.openkilda.model.FlowPath)31 PathId (org.openkilda.model.PathId)23 MeterId (org.openkilda.model.MeterId)19 Test (org.junit.Test)15 PathSegment (org.openkilda.model.PathSegment)15 Switch (org.openkilda.model.Switch)15 ArrayList (java.util.ArrayList)8 SwitchId (org.openkilda.model.SwitchId)8 FlowEntry (org.openkilda.messaging.info.rule.FlowEntry)6 UUID (java.util.UUID)5 FlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory)5 IngressFlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.IngressFlowSegmentRequestFactory)5 RemoveFlow (org.openkilda.messaging.command.flow.RemoveFlow)5 DeleteRulesCriteria (org.openkilda.messaging.command.switches.DeleteRulesCriteria)4 MirrorConfig (org.openkilda.model.MirrorConfig)4 YFlow (org.openkilda.model.YFlow)4 Before (org.junit.Before)3 EgressFlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.EgressFlowSegmentRequestFactory)3