Search in sources :

Example 61 with FlowSpeakerData

use of org.openkilda.rulemanager.FlowSpeakerData in project open-kilda by telstra.

the class MultiTableIngressRuleGeneratorTest method buildCommandsVlanEncapsulationDoubleVlanPortOverlappingTest.

@Test
public void buildCommandsVlanEncapsulationDoubleVlanPortOverlappingTest() {
    Flow oneSwitchFlow = buildFlow(ONE_SWITCH_PATH, OUTER_VLAN_ID_2, 0);
    Set<FlowSideAdapter> overlapping = Sets.newHashSet(FlowSideAdapter.makeIngressAdapter(oneSwitchFlow, ONE_SWITCH_PATH));
    Flow flow = buildFlow(PATH, OUTER_VLAN_ID_1, INNER_VLAN_ID_1);
    MultiTableIngressRuleGenerator generator = buildGenerator(PATH, flow, VLAN_ENCAPSULATION, overlapping);
    List<SpeakerData> commands = generator.generateCommands(SWITCH_1);
    assertEquals(3, commands.size());
    FlowSpeakerData ingressCommand = (FlowSpeakerData) commands.get(0);
    FlowSpeakerData preIngressCommand = (FlowSpeakerData) commands.get(1);
    MeterSpeakerData meterCommand = (MeterSpeakerData) commands.get(2);
    assertEquals(newArrayList(meterCommand.getUuid()), new ArrayList<>(ingressCommand.getDependsOn()));
    RoutingMetadata ingressMetadata = RoutingMetadata.builder().outerVlanId(OUTER_VLAN_ID_1).build(SWITCH_1.getFeatures());
    Set<FieldMatch> expectedIngressMatch = Sets.newHashSet(FieldMatch.builder().field(Field.IN_PORT).value(PORT_NUMBER_1).build(), FieldMatch.builder().field(Field.VLAN_VID).value(INNER_VLAN_ID_1).build(), FieldMatch.builder().field(Field.METADATA).value(ingressMetadata.getValue()).mask(ingressMetadata.getMask()).build());
    List<Action> expectedIngressActions = newArrayList(SetFieldAction.builder().field(Field.VLAN_VID).value(TRANSIT_VLAN_ID).build(), new PortOutAction(new PortNumber(PORT_NUMBER_2)));
    Set<FieldMatch> expectedPreIngressMatch = Sets.newHashSet(FieldMatch.builder().field(Field.IN_PORT).value(PORT_NUMBER_1).build(), FieldMatch.builder().field(Field.VLAN_VID).value(OUTER_VLAN_ID_1).build());
    FlowSharedSegmentCookie preIngressCookie = FlowSharedSegmentCookie.builder(SharedSegmentType.QINQ_OUTER_VLAN).portNumber(PORT_NUMBER_1).vlanId(OUTER_VLAN_ID_1).build();
    RoutingMetadata preIngressMetadata = RoutingMetadata.builder().outerVlanId(OUTER_VLAN_ID_1).build(SWITCH_1.getFeatures());
    assertPreIngressCommand(preIngressCommand, preIngressCookie, Priority.FLOW_PRIORITY, expectedPreIngressMatch, newArrayList(new PopVlanAction()), mapMetadata(preIngressMetadata));
    assertIngressCommand(ingressCommand, Priority.DOUBLE_VLAN_FLOW_PRIORITY, expectedIngressMatch, expectedIngressActions, METER_ID, null);
    assertMeterCommand(meterCommand);
}
Also used : SetFieldAction(org.openkilda.rulemanager.action.SetFieldAction) Action(org.openkilda.rulemanager.action.Action) PushVxlanAction(org.openkilda.rulemanager.action.PushVxlanAction) PushVlanAction(org.openkilda.rulemanager.action.PushVlanAction) PopVlanAction(org.openkilda.rulemanager.action.PopVlanAction) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) FieldMatch(org.openkilda.rulemanager.match.FieldMatch) FlowSharedSegmentCookie(org.openkilda.model.cookie.FlowSharedSegmentCookie) RoutingMetadata(org.openkilda.rulemanager.utils.RoutingMetadata) Flow(org.openkilda.model.Flow) PopVlanAction(org.openkilda.rulemanager.action.PopVlanAction) MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) FlowSideAdapter(org.openkilda.adapter.FlowSideAdapter) PortNumber(org.openkilda.rulemanager.ProtoConstants.PortNumber) SpeakerData(org.openkilda.rulemanager.SpeakerData) MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) Test(org.junit.Test)

Example 62 with FlowSpeakerData

use of org.openkilda.rulemanager.FlowSpeakerData in project open-kilda by telstra.

the class RuleManagerHelperTest method sortCommandsByDependencies3Test.

@Test
public void sortCommandsByDependencies3Test() {
    FlowSpeakerData command1 = buildFullFlowSpeakerCommandData(METER_ID_1, null);
    FlowSpeakerData command2 = buildFullFlowSpeakerCommandData(METER_ID_1, command1.getUuid());
    FlowSpeakerData command3 = buildFullFlowSpeakerCommandData(METER_ID_2, command2.getUuid());
    List<SpeakerData> result = sortCommandsByDependencies(newArrayList(command3, command2, command1));
    assertEquals(3, result.size());
    assertEquals(command1.getUuid(), result.get(0).getUuid());
    assertEquals(command2.getUuid(), result.get(1).getUuid());
    assertEquals(command3.getUuid(), result.get(2).getUuid());
}
Also used : FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) SpeakerData(org.openkilda.rulemanager.SpeakerData) MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) GroupSpeakerData(org.openkilda.rulemanager.GroupSpeakerData) Test(org.junit.Test)

Example 63 with FlowSpeakerData

use of org.openkilda.rulemanager.FlowSpeakerData in project open-kilda by telstra.

the class RuleManagerHelperTest method checkCircularDependenciesUnknownDependsOnTest.

@Test(expected = IllegalStateException.class)
public void checkCircularDependenciesUnknownDependsOnTest() {
    FlowSpeakerData command = buildFullFlowSpeakerCommandData(METER_ID_1, UUID.randomUUID());
    checkCircularDependencies(newArrayList(command));
}
Also used : FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) Test(org.junit.Test)

Example 64 with FlowSpeakerData

use of org.openkilda.rulemanager.FlowSpeakerData in project open-kilda by telstra.

the class Server42IslRttTurningRuleGeneratorTest method server42IslRttTurningRuleGeneratorTest.

@Test
public void server42IslRttTurningRuleGeneratorTest() {
    Switch sw = buildSwitch("OF_13", Sets.newHashSet(NOVIFLOW_COPY_FIELD));
    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 Cookie(SERVER_42_ISL_RTT_TURNING_COOKIE), flowCommandData.getCookie());
    assertEquals(OfTable.INPUT, flowCommandData.getTable());
    assertEquals(SERVER_42_ISL_RTT_TURNING_PRIORITY, flowCommandData.getPriority());
    Set<FieldMatch> expectedMatch = Sets.newHashSet(FieldMatch.builder().field(Field.ETH_DST).value(MAC_ADDRESS.toLong()).build(), FieldMatch.builder().field(Field.ETH_TYPE).value(EthType.IPv4).build(), FieldMatch.builder().field(Field.IP_PROTO).value(IpProto.UDP).build(), FieldMatch.builder().field(Field.UDP_SRC).value(SERVER_42_ISL_RTT_FORWARD_UDP_PORT).build());
    assertEquals(expectedMatch, flowCommandData.getMatch());
    List<Action> expectedApplyActions = Lists.newArrayList(SetFieldAction.builder().field(Field.UDP_SRC).value(SERVER_42_ISL_RTT_REVERSE_UDP_PORT).build(), new PortOutAction(new PortNumber(SpecialPortType.IN_PORT)));
    Instructions expectedInstructions = Instructions.builder().applyActions(expectedApplyActions).build();
    assertEquals(expectedInstructions, flowCommandData.getInstructions());
}
Also used : Cookie(org.openkilda.model.cookie.Cookie) Action(org.openkilda.rulemanager.action.Action) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) SetFieldAction(org.openkilda.rulemanager.action.SetFieldAction) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) Utils.buildSwitch(org.openkilda.rulemanager.Utils.buildSwitch) Switch(org.openkilda.model.Switch) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) FieldMatch(org.openkilda.rulemanager.match.FieldMatch) Instructions(org.openkilda.rulemanager.Instructions) PortNumber(org.openkilda.rulemanager.ProtoConstants.PortNumber) SpeakerData(org.openkilda.rulemanager.SpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) Test(org.junit.Test)

Example 65 with FlowSpeakerData

use of org.openkilda.rulemanager.FlowSpeakerData in project open-kilda by telstra.

the class OfBatchExecutor method verifyFlows.

private void verifyFlows() {
    log.debug("Verify flows with key: {} (hasFlows={})", kafkaKey, hasFlows);
    if (!hasFlows) {
        return;
    }
    try {
        List<OFFlowStatsReply> replies = flowStats.get();
        List<FlowSpeakerData> switchFlows = new ArrayList<>();
        replies.forEach(reply -> switchFlows.addAll(OfFlowConverter.INSTANCE.convertToFlowSpeakerData(reply, new SwitchId(iofSwitch.getId().getLong()))));
        Map<Long, Long> cookieCounts = switchFlows.stream().map(v -> v.getCookie().getValue()).collect(groupingBy(identity(), counting()));
        for (FlowSpeakerData switchFlow : switchFlows) {
            FlowSpeakerData expectedFlow = holder.getByCookie(switchFlow.getCookie());
            if (expectedFlow != null) {
                if (switchFlow.equals(expectedFlow)) {
                    holder.recordSuccessUuid(expectedFlow.getUuid());
                } else {
                    long cookie = switchFlow.getCookie().getValue();
                    // Go through all duplicate cookies, and fail on the last one.
                    if (cookieCounts.get(cookie) > 1) {
                        log.debug("Detected duplicate cookies {} on switch {}, skipping...", switchFlow.getCookie(), switchFlow.getSwitchId());
                        cookieCounts.compute(cookie, (k, v) -> v - 1);
                    } else {
                        holder.recordFailedUuid(expectedFlow.getUuid(), format("Failed to validate flow on a switch. Expected: %s, actual: %s", expectedFlow, switchFlow));
                    }
                }
            }
        }
    } catch (Exception e) {
        log.error("Failed to verify flows for message", e);
    }
}
Also used : OfMeterConverter(org.openkilda.floodlight.converter.rulemanager.OfMeterConverter) Session(org.openkilda.floodlight.service.session.Session) SwitchFeature(org.openkilda.model.SwitchFeature) Collectors.counting(java.util.stream.Collectors.counting) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) CompletableFuture(java.util.concurrent.CompletableFuture) IOFSwitch(net.floodlightcontroller.core.IOFSwitch) ArrayList(java.util.ArrayList) OFFlowStatsReply(org.projectfloodlight.openflow.protocol.OFFlowStatsReply) Map(java.util.Map) SessionService(org.openkilda.floodlight.service.session.SessionService) OFMessage(org.projectfloodlight.openflow.protocol.OFMessage) OFErrorMsg(org.projectfloodlight.openflow.protocol.OFErrorMsg) IKafkaProducerService(org.openkilda.floodlight.service.kafka.IKafkaProducerService) MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) OFMeterConfigStatsReply(org.projectfloodlight.openflow.protocol.OFMeterConfigStatsReply) MessageContext(org.openkilda.messaging.MessageContext) Set(java.util.Set) OfFlowConverter(org.openkilda.floodlight.converter.rulemanager.OfFlowConverter) UUID(java.util.UUID) OfGroupConverter(org.openkilda.floodlight.converter.rulemanager.OfGroupConverter) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) String.format(java.lang.String.format) OFGroupDescStatsReply(org.projectfloodlight.openflow.protocol.OFGroupDescStatsReply) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) KafkaUtilityService(org.openkilda.floodlight.service.kafka.KafkaUtilityService) KafkaChannel(org.openkilda.floodlight.KafkaChannel) SwitchId(org.openkilda.model.SwitchId) Builder(lombok.Builder) GroupSpeakerData(org.openkilda.rulemanager.GroupSpeakerData) Function.identity(java.util.function.Function.identity) Optional(java.util.Optional) Joiner(com.google.common.base.Joiner) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) ArrayList(java.util.ArrayList) SwitchId(org.openkilda.model.SwitchId) OFFlowStatsReply(org.projectfloodlight.openflow.protocol.OFFlowStatsReply)

Aggregations

FlowSpeakerData (org.openkilda.rulemanager.FlowSpeakerData)106 SpeakerData (org.openkilda.rulemanager.SpeakerData)88 Test (org.junit.Test)83 PortOutAction (org.openkilda.rulemanager.action.PortOutAction)58 FieldMatch (org.openkilda.rulemanager.match.FieldMatch)55 Action (org.openkilda.rulemanager.action.Action)54 SetFieldAction (org.openkilda.rulemanager.action.SetFieldAction)49 MeterSpeakerData (org.openkilda.rulemanager.MeterSpeakerData)42 PushVlanAction (org.openkilda.rulemanager.action.PushVlanAction)38 Flow (org.openkilda.model.Flow)35 Instructions (org.openkilda.rulemanager.Instructions)35 PortNumber (org.openkilda.rulemanager.ProtoConstants.PortNumber)35 PopVlanAction (org.openkilda.rulemanager.action.PopVlanAction)35 GroupSpeakerData (org.openkilda.rulemanager.GroupSpeakerData)33 GroupAction (org.openkilda.rulemanager.action.GroupAction)23 PushVxlanAction (org.openkilda.rulemanager.action.PushVxlanAction)22 PopVxlanAction (org.openkilda.rulemanager.action.PopVxlanAction)18 Cookie (org.openkilda.model.cookie.Cookie)15 FlowPath (org.openkilda.model.FlowPath)14 Switch (org.openkilda.model.Switch)14