Search in sources :

Example 1 with Builder

use of org.projectfloodlight.openflow.protocol.match.Match.Builder in project open-kilda by telstra.

the class SwitchManager method matchVerification.

/**
 * Create a match object for the verification packets
 *
 * @param sw          siwtch object
 * @param isBroadcast if broadcast then set a generic match; else specific to switch Id
 * @return {@link Match}
 */
private Match matchVerification(final IOFSwitch sw, final boolean isBroadcast) {
    MacAddress dstMac = isBroadcast ? MacAddress.of(VERIFICATION_BCAST_PACKET_DST) : dpidToMac(sw);
    Builder builder = sw.getOFFactory().buildMatch();
    builder.setMasked(MatchField.ETH_DST, dstMac, MacAddress.NO_MASK);
    return builder.build();
}
Also used : Builder(org.projectfloodlight.openflow.protocol.match.Match.Builder) MacAddress(org.projectfloodlight.openflow.types.MacAddress)

Example 2 with Builder

use of org.projectfloodlight.openflow.protocol.match.Match.Builder in project open-kilda by telstra.

the class OfMatchConverter method convertMatch.

/**
 * Convert match.
 */
public Match convertMatch(Set<FieldMatch> match, OFFactory ofFactory) {
    Builder builder = ofFactory.buildMatch();
    match.forEach(fieldMatch -> processFieldMatch(builder, fieldMatch));
    return builder.build();
}
Also used : FieldMatchBuilder(org.openkilda.rulemanager.match.FieldMatch.FieldMatchBuilder) Builder(org.projectfloodlight.openflow.protocol.match.Match.Builder)

Example 3 with Builder

use of org.projectfloodlight.openflow.protocol.match.Match.Builder in project open-kilda by telstra.

the class SwitchManager method simpleDstMatch.

/**
 * A simple Match rule based on destination mac address and mask.
 * TODO: Could be generalized
 *
 * @param dstMac
 * @param dstMask
 * @return
 */
private Match simpleDstMatch(IOFSwitch sw, String dstMac, String dstMask) throws SwitchOperationException {
    Match match = null;
    if (dstMac != null && dstMask != null && dstMac.length() > 0 && dstMask.length() > 0) {
        Builder builder = sw.getOFFactory().buildMatch();
        builder.setMasked(MatchField.ETH_DST, MacAddress.of(dstMac), MacAddress.NO_MASK);
        match = builder.build();
    }
    return match;
}
Also used : Builder(org.projectfloodlight.openflow.protocol.match.Match.Builder) Match(org.projectfloodlight.openflow.protocol.match.Match) OFVlanVidMatch(org.projectfloodlight.openflow.types.OFVlanVidMatch)

Example 4 with Builder

use of org.projectfloodlight.openflow.protocol.match.Match.Builder in project open-kilda by telstra.

the class SwitchManager method buildFlowDeleteByCriteria.

private OFFlowDelete buildFlowDeleteByCriteria(OFFactory ofFactory, DeleteRulesCriteria criteria, boolean multiTable, RuleType ruleType) {
    OFFlowDelete.Builder builder = ofFactory.buildFlowDelete();
    if (criteria.getCookie() != null) {
        builder.setCookie(U64.of(criteria.getCookie()));
        builder.setCookieMask(U64.NO_MASK);
    }
    Match.Builder matchBuilder = ofFactory.buildMatch();
    if (criteria.getMetadataValue() != null && criteria.getMetadataMask() != null) {
        matchBuilder.setMasked(MatchField.METADATA, OFMetadata.of(U64.of(criteria.getMetadataValue())), OFMetadata.of(U64.of(criteria.getMetadataMask())));
    }
    if (criteria.getInPort() != null) {
        // Match either In Port or both Port & Vlan criteria.
        addMatchFlowToBuilder(matchBuilder, ofFactory, criteria.getInPort(), Optional.ofNullable(criteria.getEncapsulationId()).orElse(0), criteria.getEncapsulationType());
    } else if (criteria.getEncapsulationId() != null) {
        // Match In Vlan criterion if In Port is not specified
        switch(criteria.getEncapsulationType()) {
            case TRANSIT_VLAN:
                matchVlan(ofFactory, matchBuilder, criteria.getEncapsulationId());
                break;
            case VXLAN:
                matchVxlan(ofFactory, matchBuilder, criteria.getEncapsulationId());
                break;
            default:
                throw new UnsupportedOperationException(String.format("Unknown encapsulation type: %s", criteria.getEncapsulationType()));
        }
    }
    Match match = matchBuilder.build();
    if (!match.equals(ofFactory.buildMatch().build())) {
        // we should not set empty match
        builder.setMatch(matchBuilder.build());
    }
    if (criteria.getPriority() != null) {
        // Match Priority criterion.
        builder.setPriority(criteria.getPriority());
    }
    if (criteria.getOutPort() != null) {
        // Match only Out Vlan criterion.
        builder.setOutPort(OFPort.of(criteria.getOutPort()));
    }
    if (multiTable) {
        switch(ruleType) {
            case TRANSIT:
                builder.setTableId(TableId.of(TRANSIT_TABLE_ID));
                break;
            case EGRESS:
                builder.setTableId(TableId.of(EGRESS_TABLE_ID));
                break;
            case INGRESS:
                builder.setTableId(TableId.of(INGRESS_TABLE_ID));
                break;
            default:
                builder.setTableId(TableId.of(INPUT_TABLE_ID));
                break;
        }
    } else {
        if (POST_INGRESS.equals(ruleType)) {
            builder.setTableId(TableId.of(TABLE_1));
        } else {
            builder.setTableId(TableId.ALL);
        }
    }
    return builder.setTableId(TableId.ALL).build();
}
Also used : OFFlowDelete(org.projectfloodlight.openflow.protocol.OFFlowDelete) Builder(org.projectfloodlight.openflow.protocol.match.Match.Builder) Match(org.projectfloodlight.openflow.protocol.match.Match) OFVlanVidMatch(org.projectfloodlight.openflow.types.OFVlanVidMatch)

Aggregations

Builder (org.projectfloodlight.openflow.protocol.match.Match.Builder)4 Match (org.projectfloodlight.openflow.protocol.match.Match)2 OFVlanVidMatch (org.projectfloodlight.openflow.types.OFVlanVidMatch)2 FieldMatchBuilder (org.openkilda.rulemanager.match.FieldMatch.FieldMatchBuilder)1 OFFlowDelete (org.projectfloodlight.openflow.protocol.OFFlowDelete)1 MacAddress (org.projectfloodlight.openflow.types.MacAddress)1