Search in sources :

Example 26 with FlowEndpoint

use of org.openkilda.model.FlowEndpoint 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 27 with FlowEndpoint

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

the class IngressMirrorRuleGenerator method generateCommands.

@Override
public List<SpeakerData> generateCommands(Switch sw) {
    List<SpeakerData> result = new ArrayList<>();
    FlowMirrorPoints mirrorPoints = flowPath.getFlowMirrorPointsSet().stream().filter(points -> sw.getSwitchId().equals(points.getMirrorSwitchId())).findFirst().orElse(null);
    if (mirrorPoints == null) {
        return result;
    }
    FlowEndpoint ingressEndpoint = checkAndBuildIngressEndpoint(flow, flowPath, sw.getSwitchId());
    FlowSpeakerData ingressCommand = buildFlowIngressCommand(sw, ingressEndpoint, mirrorPoints.getMirrorGroupId());
    result.add(ingressCommand);
    SpeakerData groupCommand = buildGroup(sw, mirrorPoints);
    result.add(groupCommand);
    ingressCommand.getDependsOn().add(groupCommand.getUuid());
    if (sharedMeterCommandUuid != null) {
        ingressCommand.getDependsOn().add(sharedMeterCommandUuid);
    }
    return result;
}
Also used : FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) FlowEndpoint(org.openkilda.model.FlowEndpoint) ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) SpeakerData(org.openkilda.rulemanager.SpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) GroupSpeakerData(org.openkilda.rulemanager.GroupSpeakerData)

Example 28 with FlowEndpoint

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

the class InputArpRuleGeneratorTest method buildCorrectRuleForOf13Test.

@Test
public void buildCorrectRuleForOf13Test() {
    FlowEndpoint endpoint = new FlowEndpoint(SW.getSwitchId(), PORT_NUMBER_1, 0, 0, false, true);
    FlowSideAdapter overlapAdapter = new FlowSourceAdapter(Flow.builder().flowId("some").srcSwitch(SW).destSwitch(buildSwitch("OF_13", Collections.emptySet())).detectConnectedDevices(DetectConnectedDevices.builder().srcArp(false).srcSwitchArp(false).build()).build());
    InputArpRuleGenerator generator = InputArpRuleGenerator.builder().ingressEndpoint(endpoint).multiTable(true).overlappingIngressAdapters(Sets.newHashSet(overlapAdapter)).build();
    List<SpeakerData> commands = generator.generateCommands(SW);
    assertEquals(1, commands.size());
    FlowSpeakerData flowCommandData = getCommand(FlowSpeakerData.class, commands);
    assertEquals(SW.getSwitchId(), flowCommandData.getSwitchId());
    assertEquals(SW.getOfVersion(), flowCommandData.getOfVersion().toString());
    assertTrue(flowCommandData.getDependsOn().isEmpty());
    assertEquals(new PortColourCookie(CookieType.ARP_INPUT_CUSTOMER_TYPE, PORT_NUMBER_1), flowCommandData.getCookie());
    assertEquals(OfTable.INPUT, flowCommandData.getTable());
    assertEquals(Priority.ARP_INPUT_CUSTOMER_PRIORITY, flowCommandData.getPriority());
    Set<FieldMatch> expectedMatch = Sets.newHashSet(FieldMatch.builder().field(Field.IN_PORT).value(PORT_NUMBER_1).build(), FieldMatch.builder().field(Field.ETH_TYPE).value(EthType.ARP).build());
    assertEqualsMatch(expectedMatch, flowCommandData.getMatch());
    RoutingMetadata metadata = RoutingMetadata.builder().arpFlag(true).build(SW.getFeatures());
    Instructions expectedInstructions = Instructions.builder().writeMetadata(new OfMetadata(metadata.getValue(), metadata.getMask())).goToTable(OfTable.PRE_INGRESS).build();
    assertEquals(expectedInstructions, flowCommandData.getInstructions());
    assertTrue(flowCommandData.getFlags().isEmpty());
}
Also used : FlowSourceAdapter(org.openkilda.adapter.FlowSourceAdapter) FieldMatch(org.openkilda.rulemanager.match.FieldMatch) RoutingMetadata(org.openkilda.rulemanager.utils.RoutingMetadata) Instructions(org.openkilda.rulemanager.Instructions) PortColourCookie(org.openkilda.model.cookie.PortColourCookie) OfMetadata(org.openkilda.rulemanager.OfMetadata) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) FlowEndpoint(org.openkilda.model.FlowEndpoint) FlowSideAdapter(org.openkilda.adapter.FlowSideAdapter) SpeakerData(org.openkilda.rulemanager.SpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) Test(org.junit.Test)

Example 29 with FlowEndpoint

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

the class InputArpRuleGeneratorTest method buildArpRuleForSingleTableTest.

@Test
public void buildArpRuleForSingleTableTest() {
    FlowEndpoint endpoint = new FlowEndpoint(SW.getSwitchId(), PORT_NUMBER_1, 0, 0, true, false);
    InputArpRuleGenerator generator = InputArpRuleGenerator.builder().ingressEndpoint(endpoint).multiTable(false).overlappingIngressAdapters(new HashSet<>()).build();
    assertEquals(0, generator.generateCommands(SW).size());
}
Also used : FlowEndpoint(org.openkilda.model.FlowEndpoint) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 30 with FlowEndpoint

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

the class InputArpRuleGeneratorTest method buildArpRuleWithoutArpTest.

@Test
public void buildArpRuleWithoutArpTest() {
    FlowEndpoint endpoint = new FlowEndpoint(SW.getSwitchId(), PORT_NUMBER_1, 0, 0, false, false);
    InputArpRuleGenerator generator = InputArpRuleGenerator.builder().ingressEndpoint(endpoint).multiTable(true).overlappingIngressAdapters(new HashSet<>()).build();
    assertEquals(0, generator.generateCommands(SW).size());
}
Also used : FlowEndpoint(org.openkilda.model.FlowEndpoint) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

FlowEndpoint (org.openkilda.model.FlowEndpoint)105 Test (org.junit.Test)26 Flow (org.openkilda.model.Flow)22 ArrayList (java.util.ArrayList)15 RoutingMetadata (org.openkilda.floodlight.utils.metadata.RoutingMetadata)12 YFlow (org.openkilda.model.YFlow)11 FlowPath (org.openkilda.model.FlowPath)10 FlowSpeakerData (org.openkilda.rulemanager.FlowSpeakerData)9 SpeakerData (org.openkilda.rulemanager.SpeakerData)9 SwitchId (org.openkilda.model.SwitchId)8 YSubFlow (org.openkilda.model.YSubFlow)8 HashSet (java.util.HashSet)7 FlowSideAdapter (org.openkilda.adapter.FlowSideAdapter)7 FlowSourceAdapter (org.openkilda.adapter.FlowSourceAdapter)7 IngressFlowSegmentInstallCommand (org.openkilda.floodlight.command.flow.ingress.IngressFlowSegmentInstallCommand)7 EffectiveIds (org.openkilda.floodlight.model.EffectiveIds)7 FlowSegmentWrapperCommand (org.openkilda.floodlight.command.flow.FlowSegmentWrapperCommand)6 FlowProcessingException (org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException)6 OFFlowAdd (org.projectfloodlight.openflow.protocol.OFFlowAdd)6 MessageContext (org.openkilda.messaging.MessageContext)5