Search in sources :

Example 1 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 sw        switch object
 * @param inputPort input port for the match
 * @param vlanId    vlanID to match on; 0 means match on port
 * @return {@link Match}
 */
private Match matchFlow(final IOFSwitch sw, final int inputPort, final int vlanId) {
    Match.Builder mb = sw.getOFFactory().buildMatch();
    // 
    // Extra emphasis: vlan of 0 means match on port on not VLAN.
    // 
    mb.setExact(MatchField.IN_PORT, OFPort.of(inputPort));
    if (vlanId > 0) {
        if (0 <= OF_12.compareTo(sw.getOFFactory().getVersion())) {
            mb.setMasked(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(vlanId), OFVlanVidMatch.ofRawVid(OF10_VLAN_MASK));
        } else {
            mb.setExact(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(vlanId));
        }
    }
    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 2 with Match

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

the class SwitchManager method installTransitFlow.

/**
 * {@inheritDoc}
 */
@Override
public long installTransitFlow(final DatapathId dpid, final String flowId, final Long cookie, final int inputPort, final int outputPort, final int transitVlanId) throws SwitchOperationException {
    List<OFAction> actionList = new ArrayList<>();
    IOFSwitch sw = lookupSwitch(dpid);
    // build match by input port and transit vlan id
    Match match = matchFlow(sw, inputPort, transitVlanId);
    // transmit packet from outgoing port
    actionList.add(actionSetOutputPort(sw, outputPort));
    // build instruction with action list
    OFInstructionApplyActions actions = buildInstructionApplyActions(sw, actionList);
    // build FLOW_MOD command, no meter
    OFFlowMod flowMod = buildFlowMod(sw, match, null, actions, cookie & FLOW_COOKIE_MASK, FlowModUtils.PRIORITY_VERY_HIGH);
    return pushFlow(sw, flowId, flowMod);
}
Also used : OFInstructionApplyActions(org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions) OFAction(org.projectfloodlight.openflow.protocol.action.OFAction) ArrayList(java.util.ArrayList) OFFlowMod(org.projectfloodlight.openflow.protocol.OFFlowMod) Match(org.projectfloodlight.openflow.protocol.match.Match) OFVlanVidMatch(org.projectfloodlight.openflow.types.OFVlanVidMatch)

Example 3 with Match

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

the class SwitchManager method installOneSwitchFlow.

/**
 * {@inheritDoc}
 */
@Override
public long installOneSwitchFlow(final DatapathId dpid, final String flowId, final Long cookie, final int inputPort, final int outputPort, final int inputVlanId, final int outputVlanId, final OutputVlanType outputVlanType, final long meterId) throws SwitchOperationException {
    // TODO: As per other locations, how different is this to IngressFlow? Why separate code path?
    // As with any set of tests, the more we test the same code path, the better.
    // Based on brief glance, this looks 90% the same as IngressFlow.
    List<OFAction> actionList = new ArrayList<>();
    IOFSwitch sw = lookupSwitch(dpid);
    // build match by input port and transit vlan id
    Match match = matchFlow(sw, inputPort, inputVlanId);
    // build meter instruction
    OFInstructionMeter meter = null;
    if (meterId != 0L && !OVS_MANUFACTURER.equals(sw.getSwitchDescription().getManufacturerDescription())) {
        if (sw.getOFFactory().getVersion().compareTo(OF_12) <= 0) {
            actionList.add(legacyMeterAction(sw, meterId));
        } else if (sw.getOFFactory().getVersion().compareTo(OF_15) == 0) {
            actionList.add(sw.getOFFactory().actions().buildMeter().setMeterId(meterId).build());
        } else /* OF_13, OF_14 */
        {
            meter = sw.getOFFactory().instructions().buildMeter().setMeterId(meterId).build();
        }
    }
    // output action based on encap scheme
    actionList.addAll(pushSchemeOutputVlanTypeToOFActionList(sw, outputVlanId, outputVlanType));
    // transmit packet from outgoing port
    actionList.add(actionSetOutputPort(sw, outputPort));
    // build instruction with action list
    OFInstructionApplyActions actions = buildInstructionApplyActions(sw, actionList);
    // build FLOW_MOD command with meter
    OFFlowMod flowMod = buildFlowMod(sw, match, meter, actions, cookie & FLOW_COOKIE_MASK, FlowModUtils.PRIORITY_VERY_HIGH);
    pushFlow(sw, flowId, flowMod);
    return flowMod.getXid();
}
Also used : OFInstructionApplyActions(org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions) OFInstructionMeter(org.projectfloodlight.openflow.protocol.instruction.OFInstructionMeter) OFAction(org.projectfloodlight.openflow.protocol.action.OFAction) ArrayList(java.util.ArrayList) OFFlowMod(org.projectfloodlight.openflow.protocol.OFFlowMod) Match(org.projectfloodlight.openflow.protocol.match.Match) OFVlanVidMatch(org.projectfloodlight.openflow.types.OFVlanVidMatch)

Example 4 with Match

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

the class SwitchManager method installVerificationRule.

/**
 * {@inheritDoc}
 */
@Override
public void installVerificationRule(final DatapathId dpid, final boolean isBroadcast) throws SwitchOperationException {
    IOFSwitch sw = lookupSwitch(dpid);
    // Don't install the unicast for OpenFlow 1.2 doesn't work properly
    if (!isBroadcast) {
        if (sw.getOFFactory().getVersion().compareTo(OF_12) > 0) {
            logger.debug("installing unicast verification match for {}", dpid.toString());
        } else {
            logger.debug("not installing unicast verification match for {}", dpid.toString());
            return;
        }
    }
    logger.debug("installing verification rule for {}", dpid.toString());
    Match match = matchVerification(sw, isBroadcast);
    ArrayList<OFAction> actionList = new ArrayList<>(2);
    actionList.add(actionSendToController(sw));
    actionList.add(actionSetDstMac(sw, dpidToMac(sw)));
    OFInstructionApplyActions instructionApplyActions = sw.getOFFactory().instructions().applyActions(actionList).createBuilder().build();
    final long cookie = isBroadcast ? VERIFICATION_BROADCAST_RULE_COOKIE : VERIFICATION_UNICAST_RULE_COOKIE;
    OFFlowMod flowMod = buildFlowMod(sw, match, null, instructionApplyActions, cookie, FlowModUtils.PRIORITY_VERY_HIGH);
    String flowname = (isBroadcast) ? "Broadcast" : "Unicast";
    flowname += "--VerificationFlow--" + dpid.toString();
    pushFlow(sw, flowname, flowMod);
}
Also used : OFInstructionApplyActions(org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions) OFAction(org.projectfloodlight.openflow.protocol.action.OFAction) ArrayList(java.util.ArrayList) OFFlowMod(org.projectfloodlight.openflow.protocol.OFFlowMod) Match(org.projectfloodlight.openflow.protocol.match.Match) OFVlanVidMatch(org.projectfloodlight.openflow.types.OFVlanVidMatch)

Example 5 with Match

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

the class OutputCommands method installRoundTripLatencyRule.

/**
 * Expected result for install default round trip latency rule.
 *
 * @param dpid datapath of the switch.
 * @return expected OFFlowAdd instance.
 */
default OFFlowAdd installRoundTripLatencyRule(DatapathId dpid) {
    Match match = ofFactory.buildMatch().setExact(MatchField.ETH_TYPE, EthType.IPv4).setExact(MatchField.ETH_SRC, MacAddress.of(dpid)).setExact(MatchField.ETH_DST, MacAddress.of(VERIFICATION_BCAST_PACKET_DST)).setExact(MatchField.IP_PROTO, IpProtocol.UDP).setExact(MatchField.UDP_DST, TransportPort.of(LATENCY_PACKET_UDP_PORT)).build();
    OFOxms oxms = ofFactory.oxms();
    return ofFactory.buildFlowAdd().setCookie(U64.of(Cookie.ROUND_TRIP_LATENCY_RULE_COOKIE)).setMatch(match).setPriority(ROUND_TRIP_LATENCY_RULE_PRIORITY).setActions(ImmutableList.of(ofFactory.actions().buildNoviflowCopyField().setNBits(ROUND_TRIP_LATENCY_TIMESTAMP_SIZE).setSrcOffset(0).setDstOffset(ROUND_TRIP_LATENCY_T1_OFFSET).setOxmSrcHeader(oxms.buildNoviflowRxtimestamp().getTypeLen()).setOxmDstHeader(oxms.buildNoviflowPacketOffset().getTypeLen()).build(), ofFactory.actions().buildOutput().setPort(OFPort.CONTROLLER).setMaxLen(0xFFFFFFFF).build())).build();
}
Also used : OFOxms(org.projectfloodlight.openflow.protocol.oxm.OFOxms) 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