Search in sources :

Example 1 with FlowMatchField

use of org.openkilda.messaging.info.rule.FlowMatchField 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)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 NumberUtils (org.apache.commons.lang.math.NumberUtils)1 DeleteRulesCriteria (org.openkilda.messaging.command.switches.DeleteRulesCriteria)1 FlowApplyActions (org.openkilda.messaging.info.rule.FlowApplyActions)1 FlowInstructions (org.openkilda.messaging.info.rule.FlowInstructions)1 FlowMatchField (org.openkilda.messaging.info.rule.FlowMatchField)1 FlowEncapsulationType (org.openkilda.model.FlowEncapsulationType)1 SwitchId (org.openkilda.model.SwitchId)1