Search in sources :

Example 41 with Match

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

the class LldpPostIngressOneSwitchFlowGenerator method getLldpFlowMod.

@Override
OFFlowMod getLldpFlowMod(IOFSwitch sw, OFInstructionMeter meter, List<OFAction> actionList) {
    OFFactory ofFactory = sw.getOFFactory();
    RoutingMetadata metadata = makeMetadataMatch(sw);
    Match match = ofFactory.buildMatch().setMasked(MatchField.METADATA, OFMetadata.of(metadata.getValue()), OFMetadata.of(metadata.getMask())).build();
    actionList.add(actionSendToController(sw.getOFFactory()));
    OFInstructionApplyActions actions = ofFactory.instructions().applyActions(actionList).createBuilder().build();
    return prepareFlowModBuilder(ofFactory, LLDP_POST_INGRESS_ONE_SWITCH_COOKIE, LLDP_POST_INGRESS_ONE_SWITCH_PRIORITY, POST_INGRESS_TABLE_ID).setMatch(match).setInstructions(meter != null ? ImmutableList.of(meter, actions) : ImmutableList.of(actions)).build();
}
Also used : OFInstructionApplyActions(org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) RoutingMetadata(org.openkilda.floodlight.utils.metadata.RoutingMetadata) Match(org.projectfloodlight.openflow.protocol.match.Match)

Example 42 with Match

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

the class LldpTransitFlowGenerator method getLldpFlowMod.

@Override
OFFlowMod getLldpFlowMod(IOFSwitch sw, OFInstructionMeter meter, List<OFAction> actionList) {
    OFFactory ofFactory = sw.getOFFactory();
    Match match = ofFactory.buildMatch().setExact(MatchField.ETH_TYPE, EthType.LLDP).build();
    actionList.add(actionSendToController(sw.getOFFactory()));
    OFInstructionApplyActions actions = ofFactory.instructions().applyActions(actionList).createBuilder().build();
    return prepareFlowModBuilder(ofFactory, Cookie.LLDP_TRANSIT_COOKIE, LLDP_TRANSIT_ISL_PRIORITY, TRANSIT_TABLE_ID).setMatch(match).setInstructions(meter != null ? ImmutableList.of(meter, actions) : ImmutableList.of(actions)).build();
}
Also used : OFInstructionApplyActions(org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) Match(org.projectfloodlight.openflow.protocol.match.Match)

Example 43 with Match

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

the class SwitchManager method matchFlow.

/**
 * Creates a Match based on an inputPort and VlanID.
 * NB1: that this match only matches on the outer most tag which must be of ether-type 0x8100.
 * NB2: vlanId of 0 means match on port, not vlan
 *
 * @param ofFactory OF factory for the switch
 * @param inputPort input port for the match
 * @param tunnelId tunnel id to match on; 0 means match on port
 * @return {@link Match}
 */
private Match matchFlow(OFFactory ofFactory, int inputPort, int tunnelId, FlowEncapsulationType encapsulationType) {
    Match.Builder mb = ofFactory.buildMatch();
    addMatchFlowToBuilder(mb, ofFactory, inputPort, tunnelId, encapsulationType);
    return mb.build();
}
Also used : Builder(org.projectfloodlight.openflow.protocol.match.Match.Builder) Match(org.projectfloodlight.openflow.protocol.match.Match) OFVlanVidMatch(org.projectfloodlight.openflow.types.OFVlanVidMatch)

Example 44 with Match

use of org.projectfloodlight.openflow.protocol.match.Match 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)

Example 45 with Match

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

the class SwitchManager method removeEgressIslVlanRule.

@Override
public long removeEgressIslVlanRule(DatapathId dpid, int port) throws SwitchOperationException {
    IOFSwitch sw = lookupSwitch(dpid);
    OFFactory ofFactory = sw.getOFFactory();
    OFFlowDelete.Builder builder = ofFactory.buildFlowDelete();
    long cookie = Cookie.encodeIslVlanEgress(port);
    builder.setCookie(U64.of(cookie));
    builder.setCookieMask(U64.NO_MASK);
    Match match = buildInPortMatch(port, ofFactory);
    builder.setMatch(match);
    builder.setPriority(ISL_EGRESS_VLAN_RULE_PRIORITY_MULTITABLE);
    removeFlowByOfFlowDelete(dpid, EGRESS_TABLE_ID, builder.build());
    return cookie;
}
Also used : IOFSwitch(net.floodlightcontroller.core.IOFSwitch) OFFlowDelete(org.projectfloodlight.openflow.protocol.OFFlowDelete) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) Match(org.projectfloodlight.openflow.protocol.match.Match) OFVlanVidMatch(org.projectfloodlight.openflow.types.OFVlanVidMatch)

Aggregations

Match (org.projectfloodlight.openflow.protocol.match.Match)51 OFFactory (org.projectfloodlight.openflow.protocol.OFFactory)28 OFVlanVidMatch (org.projectfloodlight.openflow.types.OFVlanVidMatch)28 OFInstructionApplyActions (org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions)18 OFFlowMod (org.projectfloodlight.openflow.protocol.OFFlowMod)14 OFAction (org.projectfloodlight.openflow.protocol.action.OFAction)11 RoutingMetadata (org.openkilda.floodlight.utils.metadata.RoutingMetadata)10 IOFSwitch (net.floodlightcontroller.core.IOFSwitch)8 OFInstructionGotoTable (org.projectfloodlight.openflow.protocol.instruction.OFInstructionGotoTable)7 ArrayList (java.util.ArrayList)5 SwitchFeature (org.openkilda.model.SwitchFeature)5 OFFlowDelete (org.projectfloodlight.openflow.protocol.OFFlowDelete)5 OFFactoryVer13 (org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13)5 HashSet (java.util.HashSet)4 Test (org.junit.Test)4 FieldMatch (org.openkilda.rulemanager.match.FieldMatch)4 Builder (org.projectfloodlight.openflow.protocol.match.Match.Builder)4 MacAddress (org.projectfloodlight.openflow.types.MacAddress)3 U64 (org.projectfloodlight.openflow.types.U64)3 Builder (org.projectfloodlight.openflow.protocol.OFFlowMod.Builder)2