Search in sources :

Example 1 with FlowApplyActions

use of org.openkilda.messaging.info.rule.FlowApplyActions in project open-kilda by telstra.

the class OFFlowStatsConverter method buildFlowInstructions.

private static FlowInstructions buildFlowInstructions(final List<OFInstruction> instructions) {
    Map<OFInstructionType, OFInstruction> instructionMap = instructions.stream().collect(Collectors.toMap(OFInstruction::getType, instruction -> instruction));
    FlowApplyActions applyActions = Optional.ofNullable(instructionMap.get(OFInstructionType.APPLY_ACTIONS)).map(OFFlowStatsConverter::buildApplyActions).orElse(null);
    Long meter = Optional.ofNullable(instructionMap.get(OFInstructionType.METER)).map(instruction -> ((OFInstructionMeter) instruction).getMeterId()).orElse(null);
    return FlowInstructions.builder().applyActions(applyActions).goToMeter(meter).build();
}
Also used : OFFlowModFlags(org.projectfloodlight.openflow.protocol.OFFlowModFlags) OFFlowStatsEntry(org.projectfloodlight.openflow.protocol.OFFlowStatsEntry) OFActionType(org.projectfloodlight.openflow.protocol.OFActionType) Map(java.util.Map) Match(org.projectfloodlight.openflow.protocol.match.Match) OFActionMeter(org.projectfloodlight.openflow.protocol.action.OFActionMeter) OFInstruction(org.projectfloodlight.openflow.protocol.instruction.OFInstruction) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry) OFActionOutput(org.projectfloodlight.openflow.protocol.action.OFActionOutput) OFOxm(org.projectfloodlight.openflow.protocol.oxm.OFOxm) OFInstructionApplyActions(org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions) Collectors(java.util.stream.Collectors) OFAction(org.projectfloodlight.openflow.protocol.action.OFAction) FlowApplyActions(org.openkilda.messaging.info.rule.FlowApplyActions) Objects(java.util.Objects) List(java.util.List) OFActionPushVlan(org.projectfloodlight.openflow.protocol.action.OFActionPushVlan) FlowSetFieldAction(org.openkilda.messaging.info.rule.FlowSetFieldAction) FlowInstructions(org.openkilda.messaging.info.rule.FlowInstructions) MatchField(org.projectfloodlight.openflow.protocol.match.MatchField) Optional(java.util.Optional) OFInstructionMeter(org.projectfloodlight.openflow.protocol.instruction.OFInstructionMeter) FlowMatchField(org.openkilda.messaging.info.rule.FlowMatchField) OFInstructionType(org.projectfloodlight.openflow.protocol.OFInstructionType) OFActionSetField(org.projectfloodlight.openflow.protocol.action.OFActionSetField) OFInstructionMeter(org.projectfloodlight.openflow.protocol.instruction.OFInstructionMeter) OFInstruction(org.projectfloodlight.openflow.protocol.instruction.OFInstruction) FlowApplyActions(org.openkilda.messaging.info.rule.FlowApplyActions) OFInstructionType(org.projectfloodlight.openflow.protocol.OFInstructionType)

Example 2 with FlowApplyActions

use of org.openkilda.messaging.info.rule.FlowApplyActions in project open-kilda by telstra.

the class CommandBuilderImpl method buildRemoveFlowWithoutMeterFromFlowEntry.

@VisibleForTesting
RemoveFlow buildRemoveFlowWithoutMeterFromFlowEntry(SwitchId switchId, FlowEntry entry) {
    Optional<FlowMatchField> entryMatch = Optional.ofNullable(entry.getMatch());
    Integer inPort = entryMatch.map(FlowMatchField::getInPort).map(Integer::valueOf).orElse(null);
    FlowEncapsulationType encapsulationType = FlowEncapsulationType.TRANSIT_VLAN;
    Integer encapsulationId = null;
    Integer vlan = entryMatch.map(FlowMatchField::getVlanVid).map(Integer::valueOf).orElse(null);
    if (vlan != null) {
        encapsulationId = vlan;
    } else {
        Integer tunnelId = entryMatch.map(FlowMatchField::getTunnelId).map(Integer::decode).orElse(null);
        if (tunnelId != null) {
            encapsulationId = tunnelId;
            encapsulationType = FlowEncapsulationType.VXLAN;
        }
    }
    Optional<FlowApplyActions> actions = Optional.ofNullable(entry.getInstructions()).map(FlowInstructions::getApplyActions);
    Integer outPort = actions.map(FlowApplyActions::getFlowOutput).filter(NumberUtils::isNumber).map(Integer::valueOf).orElse(null);
    SwitchId ingressSwitchId = entryMatch.map(FlowMatchField::getEthSrc).map(SwitchId::new).orElse(null);
    Long metadataValue = entryMatch.map(FlowMatchField::getMetadataValue).map(Long::decode).orElse(null);
    Long metadataMask = entryMatch.map(FlowMatchField::getMetadataMask).map(Long::decode).orElse(null);
    DeleteRulesCriteria criteria = new DeleteRulesCriteria(entry.getCookie(), inPort, encapsulationId, 0, outPort, encapsulationType, ingressSwitchId, metadataValue, metadataMask);
    return RemoveFlow.builder().transactionId(transactionIdGenerator.generate()).flowId("SWMANAGER_BATCH_REMOVE").cookie(entry.getCookie()).switchId(switchId).criteria(criteria).build();
}
Also used : FlowInstructions(org.openkilda.messaging.info.rule.FlowInstructions) FlowMatchField(org.openkilda.messaging.info.rule.FlowMatchField) DeleteRulesCriteria(org.openkilda.messaging.command.switches.DeleteRulesCriteria) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) SwitchId(org.openkilda.model.SwitchId) FlowApplyActions(org.openkilda.messaging.info.rule.FlowApplyActions) NumberUtils(org.apache.commons.lang.math.NumberUtils) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with FlowApplyActions

use of org.openkilda.messaging.info.rule.FlowApplyActions in project open-kilda by telstra.

the class SimpleSwitchRuleConverter method buildSimpleSwitchRule.

private SimpleSwitchRule buildSimpleSwitchRule(SwitchId switchId, FlowEntry flowEntry, SwitchMeterEntries meters, SwitchGroupEntries groups) {
    SimpleSwitchRule rule = SimpleSwitchRule.builder().switchId(switchId).cookie(flowEntry.getCookie()).pktCount(flowEntry.getPacketCount()).byteCount(flowEntry.getByteCount()).version(flowEntry.getVersion()).build();
    if (flowEntry.getMatch() != null) {
        rule.setInPort(NumberUtils.toInt(flowEntry.getMatch().getInPort()));
        rule.setInVlan(NumberUtils.toInt(flowEntry.getMatch().getVlanVid()));
        rule.setTunnelId(Optional.ofNullable(flowEntry.getMatch().getTunnelId()).map(Integer::decode).orElse(NumberUtils.INTEGER_ZERO));
    }
    if (flowEntry.getInstructions() != null) {
        if (flowEntry.getInstructions().getApplyActions() != null) {
            FlowApplyActions applyActions = flowEntry.getInstructions().getApplyActions();
            List<FlowSetFieldAction> setFields = Optional.ofNullable(applyActions.getSetFieldActions()).orElse(new ArrayList<>());
            rule.setOutVlan(setFields.stream().filter(Objects::nonNull).filter(action -> VLAN_VID.equals(action.getFieldName())).map(FlowSetFieldAction::getFieldValue).map(NumberUtils::toInt).collect(Collectors.toList()));
            String outPort = applyActions.getFlowOutput();
            if (IN_PORT.equals(outPort) && flowEntry.getMatch() != null) {
                outPort = flowEntry.getMatch().getInPort();
            }
            rule.setOutPort(NumberUtils.toInt(outPort));
            if (rule.getTunnelId() == NumberUtils.INTEGER_ZERO) {
                rule.setTunnelId(Optional.ofNullable(applyActions.getPushVxlan()).map(Integer::parseInt).orElse(NumberUtils.INTEGER_ZERO));
            }
            if (NumberUtils.isParsable(applyActions.getGroup()) && groups != null && groups.getGroupEntries() != null) {
                int groupId = NumberUtils.toInt(applyActions.getGroup());
                List<SimpleGroupBucket> buckets = groups.getGroupEntries().stream().filter(config -> config.getGroupId() == groupId).map(GroupEntry::getBuckets).map(this::mapGroupBuckets).findFirst().orElse(Collections.emptyList());
                rule.setGroupId(groupId);
                rule.setGroupBuckets(buckets);
            }
        }
        Optional.ofNullable(flowEntry.getInstructions().getGoToMeter()).ifPresent(meterId -> {
            rule.setMeterId(meterId);
            if (meters != null && meters.getMeterEntries() != null) {
                meters.getMeterEntries().stream().filter(entry -> meterId.equals(entry.getMeterId())).findFirst().ifPresent(entry -> {
                    rule.setMeterRate(entry.getRate());
                    rule.setMeterBurstSize(entry.getBurstSize());
                    rule.setMeterFlags(entry.getFlags());
                });
            }
        });
    }
    return rule;
}
Also used : FlowSetFieldAction(org.openkilda.messaging.info.rule.FlowSetFieldAction) FlowApplyActions(org.openkilda.messaging.info.rule.FlowApplyActions) FlowEndpoint(org.openkilda.model.FlowEndpoint) SimpleGroupBucket(org.openkilda.wfm.share.utils.rule.validation.SimpleSwitchRule.SimpleGroupBucket) NumberUtils(org.apache.commons.lang3.math.NumberUtils)

Example 4 with FlowApplyActions

use of org.openkilda.messaging.info.rule.FlowApplyActions in project open-kilda by telstra.

the class SimpleSwitchRuleConverter method mapGroupBuckets.

private List<SimpleGroupBucket> mapGroupBuckets(List<GroupBucket> buckets) {
    List<SimpleGroupBucket> simpleGroupBuckets = new ArrayList<>();
    for (GroupBucket bucket : buckets) {
        FlowApplyActions actions = bucket.getApplyActions();
        if (actions == null || !NumberUtils.isParsable(actions.getFlowOutput())) {
            continue;
        }
        int bucketPort = NumberUtils.toInt(actions.getFlowOutput());
        int bucketVlan = 0;
        if (actions.getSetFieldActions() != null && actions.getSetFieldActions().size() == 1) {
            FlowSetFieldAction setFieldAction = actions.getSetFieldActions().get(0);
            if (VLAN_VID.equals(setFieldAction.getFieldName())) {
                bucketVlan = NumberUtils.toInt(setFieldAction.getFieldValue());
            }
        }
        int bucketVni = 0;
        if (actions.getPushVxlan() != null) {
            bucketVni = NumberUtils.toInt(actions.getPushVxlan());
        }
        simpleGroupBuckets.add(new SimpleGroupBucket(bucketPort, bucketVlan, bucketVni));
    }
    simpleGroupBuckets.sort(this::compareSimpleGroupBucket);
    return simpleGroupBuckets;
}
Also used : FlowSetFieldAction(org.openkilda.messaging.info.rule.FlowSetFieldAction) ArrayList(java.util.ArrayList) SimpleGroupBucket(org.openkilda.wfm.share.utils.rule.validation.SimpleSwitchRule.SimpleGroupBucket) GroupBucket(org.openkilda.messaging.info.rule.GroupBucket) FlowApplyActions(org.openkilda.messaging.info.rule.FlowApplyActions) SimpleGroupBucket(org.openkilda.wfm.share.utils.rule.validation.SimpleSwitchRule.SimpleGroupBucket) FlowEndpoint(org.openkilda.model.FlowEndpoint)

Example 5 with FlowApplyActions

use of org.openkilda.messaging.info.rule.FlowApplyActions in project open-kilda by telstra.

the class OfFlowStatsMapperTest method testFlowEntry.

@Test
public void testFlowEntry() {
    OFFlowStatsEntry ofEntry = buildFlowStatsEntry();
    FlowEntry entry = OfFlowStatsMapper.INSTANCE.toFlowEntry(ofEntry);
    assertEquals(tableId, entry.getTableId());
    assertEquals(cookie, entry.getCookie());
    assertEquals(packetCount, entry.getPacketCount());
    assertEquals(byteCount, entry.getByteCount());
    assertEquals(durationSec, entry.getDurationSeconds());
    assertEquals(durationNsec, entry.getDurationNanoSeconds());
    assertEquals(hardTimeout, entry.getHardTimeout());
    assertEquals(idleTimeout, entry.getIdleTimeout());
    assertEquals(priority, entry.getPriority());
    assertEquals(String.valueOf(vlanVid.getVlan()), entry.getMatch().getVlanVid());
    assertEquals(ethType.toString(), entry.getMatch().getEthType());
    assertEquals(ethDst.toString(), entry.getMatch().getEthDst());
    assertEquals(port.toString(), entry.getMatch().getInPort());
    assertEquals(ipProto.toString(), entry.getMatch().getIpProto());
    assertEquals(udpSrc.toString(), entry.getMatch().getUdpSrc());
    assertEquals(udpDst.toString(), entry.getMatch().getUdpDst());
    FlowSetFieldAction flowSetEthSrcAction = new FlowSetFieldAction("eth_src", MAC_ADDRESS_1);
    FlowSetFieldAction flowSetEthDstAction = new FlowSetFieldAction("eth_dst", MAC_ADDRESS_2);
    FlowCopyFieldAction flowCopyFieldAction = FlowCopyFieldAction.builder().bits(String.valueOf(bits)).srcOffset(String.valueOf(srcOffset)).dstOffset(String.valueOf(dstOffset)).srcOxm(String.valueOf(oxmSrcHeader)).dstOxm(String.valueOf(oxmDstHeader)).build();
    FlowSwapFieldAction flowSwapFieldAction = FlowSwapFieldAction.builder().bits(String.valueOf(bits)).srcOffset(String.valueOf(srcOffset)).dstOffset(String.valueOf(dstOffset)).srcOxm(String.valueOf(oxmSrcHeader)).dstOxm(String.valueOf(oxmDstHeader)).build();
    FlowApplyActions applyActions = new FlowApplyActions(port.toString(), Lists.newArrayList(flowSetEthSrcAction, flowSetEthDstAction), ethType.toString(), null, null, null, group.toString(), flowCopyFieldAction, flowSwapFieldAction);
    FlowInstructions instructions = new FlowInstructions(applyActions, null, meterId, goToTable.getValue());
    assertEquals(instructions, entry.getInstructions());
}
Also used : OFFlowStatsEntry(org.projectfloodlight.openflow.protocol.OFFlowStatsEntry) FlowSetFieldAction(org.openkilda.messaging.info.rule.FlowSetFieldAction) FlowSwapFieldAction(org.openkilda.messaging.info.rule.FlowSwapFieldAction) FlowInstructions(org.openkilda.messaging.info.rule.FlowInstructions) FlowApplyActions(org.openkilda.messaging.info.rule.FlowApplyActions) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry) FlowCopyFieldAction(org.openkilda.messaging.info.rule.FlowCopyFieldAction) Test(org.junit.Test)

Aggregations

FlowApplyActions (org.openkilda.messaging.info.rule.FlowApplyActions)5 FlowSetFieldAction (org.openkilda.messaging.info.rule.FlowSetFieldAction)4 FlowInstructions (org.openkilda.messaging.info.rule.FlowInstructions)3 FlowEntry (org.openkilda.messaging.info.rule.FlowEntry)2 FlowMatchField (org.openkilda.messaging.info.rule.FlowMatchField)2 FlowEndpoint (org.openkilda.model.FlowEndpoint)2 SimpleGroupBucket (org.openkilda.wfm.share.utils.rule.validation.SimpleSwitchRule.SimpleGroupBucket)2 OFFlowStatsEntry (org.projectfloodlight.openflow.protocol.OFFlowStatsEntry)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 NumberUtils (org.apache.commons.lang.math.NumberUtils)1 NumberUtils (org.apache.commons.lang3.math.NumberUtils)1 Test (org.junit.Test)1 DeleteRulesCriteria (org.openkilda.messaging.command.switches.DeleteRulesCriteria)1 FlowCopyFieldAction (org.openkilda.messaging.info.rule.FlowCopyFieldAction)1