Search in sources :

Example 1 with OFFlowMod

use of org.projectfloodlight.openflow.protocol.OFFlowMod 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 2 with OFFlowMod

use of org.projectfloodlight.openflow.protocol.OFFlowMod 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 3 with OFFlowMod

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

the class SwitchManager method installDropFlow.

/**
 * {@inheritDoc}
 */
@Override
public void installDropFlow(final DatapathId dpid) throws SwitchOperationException {
    // TODO: leverage installDropFlowCustom
    IOFSwitch sw = lookupSwitch(dpid);
    OFFlowMod flowMod = buildFlowMod(sw, null, null, null, DROP_RULE_COOKIE, 1);
    String flowName = "--DropRule--" + dpid.toString();
    pushFlow(sw, flowName, flowMod);
}
Also used : OFFlowMod(org.projectfloodlight.openflow.protocol.OFFlowMod)

Example 4 with OFFlowMod

use of org.projectfloodlight.openflow.protocol.OFFlowMod 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 OFFlowMod

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

the class SwitchManagerOF12Test method installTransitFlow.

@Test
public void installTransitFlow() throws Exception {
    Capture<OFFlowMod> capture = prepareForInstallFlowOperation();
    String flowId = "test-transit-flow-rule";
    int inputPort = 2;
    int outputPort = 4;
    int transitVlanId = 512;
    switchManager.installTransitFlow(switchDpId, flowId, commonFlowCookie, inputPort, outputPort, transitVlanId);
    OFFactory referenceOfFactory = new OFFactoryVer12Mock();
    OFFlowMod expected = referenceOfFactory.buildFlowAdd().setCookie(U64.of(commonFlowCookie).applyMask(U64.of(SwitchManager.FLOW_COOKIE_MASK))).setPriority(FlowModUtils.PRIORITY_VERY_HIGH).setMatch(referenceOfFactory.buildMatch().setExact(MatchField.IN_PORT, OFPort.of(inputPort)).setMasked(MatchField.VLAN_VID, OFVlanVidMatch.ofVlan(transitVlanId), OFVlanVidMatch.ofRawVid((short) 0x0FFF)).build()).setInstructions(singletonList(referenceOfFactory.instructions().applyActions(singletonList(referenceOfFactory.actions().buildOutput().setMaxLen(0xFFFFFFFF).setPort(OFPort.of(outputPort)).build())).createBuilder().build())).build();
    assertEquals(expected, capture.getValue());
}
Also used : OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) OFFactoryVer12Mock(org.openkilda.floodlight.OFFactoryVer12Mock) OFFlowMod(org.projectfloodlight.openflow.protocol.OFFlowMod) Test(org.junit.Test)

Aggregations

OFFlowMod (org.projectfloodlight.openflow.protocol.OFFlowMod)10 Match (org.projectfloodlight.openflow.protocol.match.Match)6 OFVlanVidMatch (org.projectfloodlight.openflow.types.OFVlanVidMatch)6 ArrayList (java.util.ArrayList)5 OFAction (org.projectfloodlight.openflow.protocol.action.OFAction)5 OFInstructionApplyActions (org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions)5 Test (org.junit.Test)3 OFInstructionMeter (org.projectfloodlight.openflow.protocol.instruction.OFInstructionMeter)2 OFFactoryVer12Mock (org.openkilda.floodlight.OFFactoryVer12Mock)1 OFFactory (org.projectfloodlight.openflow.protocol.OFFactory)1 OFFlowStatsEntry (org.projectfloodlight.openflow.protocol.OFFlowStatsEntry)1 OFFlowStatsReply (org.projectfloodlight.openflow.protocol.OFFlowStatsReply)1 OFFlowStatsRequest (org.projectfloodlight.openflow.protocol.OFFlowStatsRequest)1