Search in sources :

Example 1 with SimpleGroupBucket

use of org.openkilda.wfm.share.utils.rule.validation.SimpleSwitchRule.SimpleGroupBucket in project open-kilda by telstra.

the class SimpleSwitchRuleConverter method mapGroupBuckets.

private List<SimpleGroupBucket> mapGroupBuckets(Collection<FlowMirrorPath> flowMirrorPaths, int mainMirrorPort, int mainMirrorVlan, int mainMirrorVni) {
    List<SimpleGroupBucket> buckets = Lists.newArrayList(new SimpleGroupBucket(mainMirrorPort, mainMirrorVlan, mainMirrorVni));
    flowMirrorPaths.forEach(flowMirrorPath -> buckets.add(new SimpleGroupBucket(flowMirrorPath.getEgressPort(), flowMirrorPath.getEgressOuterVlan(), 0)));
    buckets.sort(this::compareSimpleGroupBucket);
    return buckets;
}
Also used : SimpleGroupBucket(org.openkilda.wfm.share.utils.rule.validation.SimpleSwitchRule.SimpleGroupBucket)

Example 2 with SimpleGroupBucket

use of org.openkilda.wfm.share.utils.rule.validation.SimpleSwitchRule.SimpleGroupBucket 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 3 with SimpleGroupBucket

use of org.openkilda.wfm.share.utils.rule.validation.SimpleSwitchRule.SimpleGroupBucket 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)

Aggregations

SimpleGroupBucket (org.openkilda.wfm.share.utils.rule.validation.SimpleSwitchRule.SimpleGroupBucket)3 FlowApplyActions (org.openkilda.messaging.info.rule.FlowApplyActions)2 FlowSetFieldAction (org.openkilda.messaging.info.rule.FlowSetFieldAction)2 FlowEndpoint (org.openkilda.model.FlowEndpoint)2 ArrayList (java.util.ArrayList)1 NumberUtils (org.apache.commons.lang3.math.NumberUtils)1 GroupBucket (org.openkilda.messaging.info.rule.GroupBucket)1