Search in sources :

Example 11 with FlowSegmentCookie

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

the class CommandBuilderImplTest method shouldBuildRemoveFlowWithoutMeterFromFlowEntryWithVxlanEncapsulationTransitAndEgress.

@Test
public void shouldBuildRemoveFlowWithoutMeterFromFlowEntryWithVxlanEncapsulationTransitAndEgress() {
    Long cookie = new FlowSegmentCookie(FlowPathDirection.FORWARD, 1).getValue();
    String inPort = "1";
    String outPort = "2";
    String tunnelId = "10";
    FlowEntry flowEntry = buildFlowEntry(cookie, inPort, null, outPort, tunnelId, 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(tunnelId), 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)

Example 12 with FlowSegmentCookie

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

the class SwitchSyncServiceImplTest method setUp.

@Before
public void setUp() {
    RepositoryFactory repositoryFactory = Mockito.mock(RepositoryFactory.class);
    FlowRepository flowRepository = Mockito.mock(FlowRepository.class);
    FlowPathRepository flowPathRepository = Mockito.mock(FlowPathRepository.class);
    TransitVlanRepository transitVlanRepository = Mockito.mock(TransitVlanRepository.class);
    when(repositoryFactory.createFlowPathRepository()).thenReturn(flowPathRepository);
    when(repositoryFactory.createFlowRepository()).thenReturn(flowRepository);
    when(repositoryFactory.createTransitVlanRepository()).thenReturn(transitVlanRepository);
    when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
    Properties configProps = new Properties();
    configProps.setProperty("flow.meter-id.max", "40");
    configProps.setProperty("flow.vlan.max", "50");
    PropertiesBasedConfigurationProvider configurationProvider = new PropertiesBasedConfigurationProvider(configProps);
    FlowResourcesConfig flowResourcesConfig = configurationProvider.getConfiguration(FlowResourcesConfig.class);
    service = new SwitchSyncServiceImpl(carrier, persistenceManager, flowResourcesConfig);
    service.commandBuilder = commandBuilder;
    request = SwitchValidateRequest.builder().switchId(SWITCH_ID).performSync(true).build();
    flowEntry = new FlowEntry(new FlowSegmentCookie(FlowPathDirection.FORWARD, 7).getValue(), 0, 0, 0, 0, "", 0, 0, 0, 0, null, null, null);
    InstallIngressFlow installingRule = new InstallIngressFlow(UUID.randomUUID(), FLOW_ID, flowEntry.getCookie(), SWITCH_ID, 1, 2, 50, 0, 60, FlowEncapsulationType.TRANSIT_VLAN, OutputVlanType.POP, 10L, 100L, EGRESS_SWITCH_ID, false, false, false, null);
    when(commandBuilder.buildCommandsToSyncMissingRules(eq(SWITCH_ID), any())).thenReturn(singletonList(installingRule));
    missingRules = singletonList(flowEntry.getCookie());
    excessRules = emptyList();
    misconfiguredRules = emptyList();
    excessMeters = emptyList();
}
Also used : InstallIngressFlow(org.openkilda.messaging.command.flow.InstallIngressFlow) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) FlowResourcesConfig(org.openkilda.wfm.share.flow.resources.FlowResourcesConfig) FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) TransitVlanRepository(org.openkilda.persistence.repositories.TransitVlanRepository) PropertiesBasedConfigurationProvider(org.openkilda.config.provider.PropertiesBasedConfigurationProvider) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) Properties(java.util.Properties) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry) Before(org.junit.Before)

Example 13 with FlowSegmentCookie

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

the class CommandBuilderImpl method buildCommandsToSyncMissingRules.

@Override
public List<BaseFlow> buildCommandsToSyncMissingRules(SwitchId switchId, List<Long> switchRules) {
    List<BaseFlow> commands = new ArrayList<>(buildInstallDefaultRuleCommands(switchId, switchRules));
    commands.addAll(buildInstallFlowSharedRuleCommands(switchId, switchRules));
    flowPathRepository.findBySegmentDestSwitch(switchId).forEach(flowPath -> {
        FlowSegmentCookie mirrorCookie = flowPath.getCookie().toBuilder().mirror(true).build();
        boolean switchRulesContainsFlowPathCookie = switchRules.contains(flowPath.getCookie().getValue());
        boolean switchRulesContainsMirrorCookie = switchRules.contains(mirrorCookie.getValue());
        if (switchRulesContainsFlowPathCookie || switchRulesContainsMirrorCookie) {
            PathSegment segment = flowPath.getSegments().stream().filter(pathSegment -> pathSegment.getDestSwitchId().equals(switchId)).findAny().orElseThrow(() -> new IllegalStateException(format("PathSegment not found, path %s, switch %s", flowPath, switchId)));
            log.info("Rule {} is to be (re)installed on switch {}", flowPath.getCookie(), switchId);
            commands.addAll(buildInstallCommandFromSegment(flowPath, segment, switchRulesContainsFlowPathCookie, switchRulesContainsMirrorCookie));
        }
    });
    SwitchProperties switchProperties = getSwitchProperties(switchId);
    flowPathRepository.findByEndpointSwitch(switchId).forEach(flowPath -> {
        FlowSegmentCookie mirrorCookie = flowPath.getCookie().toBuilder().mirror(true).build();
        boolean switchRulesContainsFlowPathCookie = switchRules.contains(flowPath.getCookie().getValue());
        boolean switchRulesContainsMirrorCookie = switchRules.contains(mirrorCookie.getValue());
        if (switchRulesContainsFlowPathCookie || switchRulesContainsMirrorCookie) {
            Flow flow = getFlow(flowPath);
            if (flowPath.isOneSwitchFlow()) {
                log.info("One-switch flow {} is to be (re)installed on switch {}", flowPath.getCookie(), switchId);
                SwitchId swId = flowPath.isForward() ? flow.getDestSwitchId() : flow.getSrcSwitchId();
                int port = flowPath.isForward() ? flow.getDestPort() : flow.getSrcPort();
                if (switchRulesContainsMirrorCookie) {
                    MirrorConfig mirrorConfig = makeMirrorConfig(flowPath, swId, port);
                    commands.add(flowCommandFactory.makeOneSwitchMirrorRule(flow, flowPath, mirrorConfig));
                }
                if (switchRulesContainsFlowPathCookie) {
                    commands.add(flowCommandFactory.makeOneSwitchRule(flow, flowPath));
                }
            } else if (flowPath.getSrcSwitchId().equals(switchId)) {
                log.info("Ingress flow {} is to be (re)installed on switch {}", flowPath.getCookie(), switchId);
                if (flowPath.getSegments().isEmpty()) {
                    log.warn("Output port was not found for ingress flow rule");
                } else {
                    PathSegment foundIngressSegment = flowPath.getSegments().get(0);
                    EncapsulationResources encapsulationResources = getEncapsulationResources(flowPath, flow);
                    if (switchRulesContainsMirrorCookie) {
                        MirrorConfig mirrorConfig = makeMirrorConfig(flowPath, foundIngressSegment.getSrcSwitchId(), foundIngressSegment.getSrcPort());
                        commands.add(flowCommandFactory.buildInstallIngressMirrorFlow(flow, flowPath, foundIngressSegment.getSrcPort(), encapsulationResources, foundIngressSegment.isSrcWithMultiTable(), mirrorConfig));
                    }
                    if (switchRulesContainsFlowPathCookie) {
                        commands.add(flowCommandFactory.buildInstallIngressFlow(flow, flowPath, foundIngressSegment.getSrcPort(), encapsulationResources, foundIngressSegment.isSrcWithMultiTable()));
                    }
                }
            }
        }
        long server42Cookie = flowPath.getCookie().toBuilder().type(CookieType.SERVER_42_FLOW_RTT_INGRESS).build().getValue();
        if (switchRules.contains(server42Cookie) && !flowPath.isOneSwitchFlow() && flowPath.getSrcSwitchId().equals(switchId)) {
            log.info("Ingress server 42 flow {} is to be (re)installed on switch {}", server42Cookie, switchId);
            if (flowPath.getSegments().isEmpty()) {
                log.warn("Output port was not found for server 42 ingress flow rule {}", server42Cookie);
            } else {
                Flow flow = getFlow(flowPath);
                PathSegment foundIngressSegment = flowPath.getSegments().get(0);
                EncapsulationResources encapsulationResources = getEncapsulationResources(flowPath, flow);
                commands.add(flowCommandFactory.buildInstallServer42IngressFlow(flow, flowPath, foundIngressSegment.getSrcPort(), switchProperties.getServer42Port(), switchProperties.getServer42MacAddress(), encapsulationResources, foundIngressSegment.isSrcWithMultiTable()));
            }
        }
        long loopCookie = flowPath.getCookie().toBuilder().looped(true).build().getValue();
        if (switchRules.contains(loopCookie)) {
            log.info("Loop rule with cookie {} is to be reinstalled on switch {}", loopCookie, switchId);
            Flow flow = getFlow(flowPath);
            EncapsulationResources encapsulationResources = getEncapsulationResources(flowPath, flow);
            if (flowPath.getSrcSwitch().getSwitchId().equals(switchId)) {
                boolean srcWithMultiTable = flowPath.getSegments().get(0).isSrcWithMultiTable();
                commands.add(flowCommandFactory.buildInstallIngressLoopFlow(flow, flowPath, encapsulationResources, srcWithMultiTable));
            } else {
                PathSegment lastSegment = flowPath.getSegments().get(flowPath.getSegments().size() - 1);
                boolean destWithMultiTable = lastSegment.isDestWithMultiTable();
                commands.add(flowCommandFactory.buildInstallTransitLoopFlow(flow, flowPath, lastSegment.getDestPort(), encapsulationResources, destWithMultiTable));
            }
        }
    });
    return commands;
}
Also used : FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) BaseFlow(org.openkilda.messaging.command.flow.BaseFlow) ArrayList(java.util.ArrayList) SwitchId(org.openkilda.model.SwitchId) PathSegment(org.openkilda.model.PathSegment) InstallServer42Flow(org.openkilda.messaging.command.flow.InstallServer42Flow) BaseFlow(org.openkilda.messaging.command.flow.BaseFlow) Flow(org.openkilda.model.Flow) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) BaseInstallFlow(org.openkilda.messaging.command.flow.BaseInstallFlow) InstallSharedFlow(org.openkilda.messaging.command.flow.InstallSharedFlow) EncapsulationResources(org.openkilda.wfm.share.flow.resources.EncapsulationResources) MirrorConfig(org.openkilda.model.MirrorConfig) SwitchProperties(org.openkilda.model.SwitchProperties)

Example 14 with FlowSegmentCookie

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

the class StatsTopologyTest method flowAttendantRulesStatsTest.

@Test
public void flowAttendantRulesStatsTest() {
    Flow flow = createFlow();
    FlowSegmentCookie server42IngressCookie = MAIN_FORWARD_COOKIE.toBuilder().type(CookieType.SERVER_42_FLOW_RTT_INGRESS).build();
    FlowEndpoint ingress = new FlowEndpoint(SWITCH_ID_1, PORT_1);
    FlowStatsEntry measure0 = new FlowStatsEntry(0, server42IngressCookie.getValue(), 0, 0, ingress.getPortNumber(), ingress.getPortNumber() + 1);
    FlowStatsEntry measure1 = new FlowStatsEntry(0, server42IngressCookie.getValue(), 1, 200, ingress.getPortNumber(), ingress.getPortNumber() + 1);
    FlowStatsEntry measure2 = new FlowStatsEntry(0, server42IngressCookie.getValue(), 2, 300, ingress.getPortNumber(), ingress.getPortNumber() + 1);
    sendStatsMessage(new FlowStatsData(ingress.getSwitchId(), Collections.singletonList(measure0)));
    sendUpdateFlowPathInfo(flow.getForwardPath());
    sendStatsMessage(new FlowStatsData(ingress.getSwitchId(), Collections.singletonList(measure1)));
    sendRemoveFlowPathInfo(flow.getForwardPath());
    sendStatsMessage(new FlowStatsData(ingress.getSwitchId(), Collections.singletonList(measure2)));
    List<Datapoint> datapoints = pollDatapoints(9);
    List<Datapoint> rawPacketsMetric = datapoints.stream().filter(entry -> (METRIC_PREFIX + "flow.raw.packets").equals(entry.getMetric())).collect(Collectors.toList());
    Assert.assertEquals(3, rawPacketsMetric.size());
    for (Datapoint entry : rawPacketsMetric) {
        Map<String, String> tags = entry.getTags();
        Assert.assertEquals(CookieType.SERVER_42_FLOW_RTT_INGRESS.name().toLowerCase(), tags.get("type"));
        if (Objects.equals(0, entry.getValue())) {
            Assert.assertEquals("unknown", tags.get("flowid"));
        } else if (Objects.equals(1, entry.getValue())) {
            Assert.assertEquals(flowId, tags.get("flowid"));
        } else if (Objects.equals(2, entry.getValue())) {
            Assert.assertEquals("unknown", tags.get("flowid"));
        } else {
            Assert.fail(format("Unexpected metric value: %s", entry));
        }
    }
}
Also used : Datapoint(org.openkilda.messaging.info.Datapoint) CoreMatchers.is(org.hamcrest.CoreMatchers.is) InfoMessage(org.openkilda.messaging.info.InfoMessage) Arrays(java.util.Arrays) FlowPath(org.openkilda.model.FlowPath) GetPacketInOutStatsResponse(org.openkilda.messaging.info.grpc.GetPacketInOutStatsResponse) CoreMatchers.startsWith(org.hamcrest.CoreMatchers.startsWith) Utils.sleep(org.apache.storm.utils.Utils.sleep) Flow(org.openkilda.model.Flow) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) FlowRttStatsData(org.openkilda.messaging.info.stats.FlowRttStatsData) FlowStatsEntry(org.openkilda.messaging.info.stats.FlowStatsEntry) PortStatsData(org.openkilda.messaging.info.stats.PortStatsData) AfterClass(org.junit.AfterClass) LaunchEnvironment(org.openkilda.wfm.LaunchEnvironment) FORWARD(org.openkilda.model.FlowPathDirection.FORWARD) AbstractStormTest(org.openkilda.wfm.AbstractStormTest) InfoData(org.openkilda.messaging.info.InfoData) CookieType(org.openkilda.model.cookie.CookieBase.CookieType) MeterConfigStatsData(org.openkilda.messaging.info.stats.MeterConfigStatsData) UUID(java.util.UUID) Datapoint(org.openkilda.messaging.info.Datapoint) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) UpdateFlowPathInfo(org.openkilda.messaging.info.stats.UpdateFlowPathInfo) Objects(java.util.Objects) List(java.util.List) MeterStatsEntry(org.openkilda.messaging.info.stats.MeterStatsEntry) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) Config(org.apache.storm.Config) REVERSE(org.openkilda.model.FlowPathDirection.REVERSE) FlowStatsData(org.openkilda.messaging.info.stats.FlowStatsData) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) IntStream(java.util.stream.IntStream) BeforeClass(org.junit.BeforeClass) STATS_TOPOLOGY_TEST_ZOOKEEPER_PORT(org.openkilda.wfm.config.ZookeeperConfig.STATS_TOPOLOGY_TEST_ZOOKEEPER_PORT) HashMap(java.util.HashMap) FlowPathMapper(org.openkilda.wfm.share.mappers.FlowPathMapper) Function(java.util.function.Function) ArrayList(java.util.ArrayList) RemoveFlowPathInfo(org.openkilda.messaging.info.stats.RemoveFlowPathInfo) SwitchTableStatsData(org.openkilda.messaging.info.stats.SwitchTableStatsData) ImmutableList(com.google.common.collect.ImmutableList) StormTopology(org.apache.storm.generated.StormTopology) TableStatsEntry(org.openkilda.messaging.info.stats.TableStatsEntry) Cookie(org.openkilda.model.cookie.Cookie) MeterConfigReply(org.openkilda.messaging.info.stats.MeterConfigReply) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) TestFlowBuilder(org.openkilda.wfm.share.flow.TestFlowBuilder) Before(org.junit.Before) InMemoryGraphPersistenceManager(org.openkilda.persistence.inmemory.InMemoryGraphPersistenceManager) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) FlowEndpoint(org.openkilda.model.FlowEndpoint) STATS_TOPOLOGY_TEST_KAFKA_PORT(org.openkilda.wfm.config.KafkaConfig.STATS_TOPOLOGY_TEST_KAFKA_PORT) Switch(org.openkilda.model.Switch) Properties(java.util.Properties) PortStatsEntry(org.openkilda.messaging.info.stats.PortStatsEntry) MeterStatsData(org.openkilda.messaging.info.stats.MeterStatsData) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) IOException(java.io.IOException) MeterId(org.openkilda.model.MeterId) TimeUnit(java.util.concurrent.TimeUnit) Collectors.toList(java.util.stream.Collectors.toList) SwitchId(org.openkilda.model.SwitchId) Ignore(org.junit.Ignore) PacketInOutStatsDto(org.openkilda.messaging.model.grpc.PacketInOutStatsDto) Destination(org.openkilda.messaging.Destination) TestKafkaConsumer(org.openkilda.wfm.topology.TestKafkaConsumer) VERIFICATION_BROADCAST_RULE_COOKIE(org.openkilda.model.cookie.Cookie.VERIFICATION_BROADCAST_RULE_COOKIE) Assert(org.junit.Assert) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) FlowEndpoint(org.openkilda.model.FlowEndpoint) FlowStatsEntry(org.openkilda.messaging.info.stats.FlowStatsEntry) FlowStatsData(org.openkilda.messaging.info.stats.FlowStatsData) Flow(org.openkilda.model.Flow) AbstractStormTest(org.openkilda.wfm.AbstractStormTest) Test(org.junit.Test)

Example 15 with FlowSegmentCookie

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

the class BaseCacheChangeHandler method handleStatsEntry.

@Override
public void handleStatsEntry(YFlowSubDescriptor descriptor) {
    FlowSegmentCookie cookie = descriptor.getCookie();
    handleFlowStatsEntry(descriptor.getSwitchId(), cookie, descriptor.getMeterId(), descriptor);
    FlowSegmentCookie satelliteCookie = cookie.toBuilder().yFlow(true).build();
    cacheAction(new CookieCacheKey(descriptor.getSwitchId(), satelliteCookie.getValue()), descriptor);
}
Also used : FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) CookieCacheKey(org.openkilda.wfm.topology.stats.model.CookieCacheKey)

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