Search in sources :

Example 6 with OFFlowMod

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

the class SwitchManagerTest method deleteFlow.

@Test
public void deleteFlow() throws Exception {
    Capture<OFFlowMod> capture = prepareForInstallTest();
    switchManager.deleteFlow(dpid, cookieHex, cookie);
    final OFFlowMod actual = capture.getValue();
    assertEquals(OFFlowModCommand.DELETE, actual.getCommand());
    assertEquals(Long.valueOf(cookieHex, 16).longValue(), actual.getCookie().getValue());
    assertEquals(SwitchManager.NON_SYSTEM_MASK, actual.getCookieMask());
}
Also used : OFFlowMod(org.projectfloodlight.openflow.protocol.OFFlowMod) Test(org.junit.Test)

Example 7 with OFFlowMod

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

the class SwitchManager method installEgressFlow.

/**
 * {@inheritDoc}
 */
@Override
public long installEgressFlow(final DatapathId dpid, String flowId, final Long cookie, final int inputPort, final int outputPort, final int transitVlanId, final int outputVlanId, final OutputVlanType outputVlanType) 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);
    // output action based on encap scheme
    actionList.addAll(outputVlanTypeToOFActionList(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, no meter
    OFFlowMod flowMod = buildFlowMod(sw, match, null, actions, cookie & FLOW_COOKIE_MASK, FlowModUtils.PRIORITY_VERY_HIGH);
    return pushFlow(sw, "--InstallEgressFlow--", 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 8 with OFFlowMod

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

the class SwitchManager method installIngressFlow.

/**
 * {@inheritDoc}
 */
@Override
public long installIngressFlow(final DatapathId dpid, final String flowId, final Long cookie, final int inputPort, final int outputPort, final int inputVlanId, final int transitVlanId, final OutputVlanType outputVlanType, final long meterId) throws SwitchOperationException {
    List<OFAction> actionList = new ArrayList<>();
    IOFSwitch sw = lookupSwitch(dpid);
    // build match by input port and input 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(inputVlanTypeToOFActionList(sw, transitVlanId, 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);
    return pushFlow(sw, "--InstallIngressFlow--", flowMod);
}
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 9 with OFFlowMod

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

the class SwitchManager method installDropFlowCustom.

/**
 * Installs custom drop rule .. ie cookie, priority, match
 *
 * @param dpid datapathId of switch
 * @param dstMac Destination Mac address to match on
 * @param dstMask Destination Mask to match on
 * @param cookie Cookie to use for this rule
 * @param priority Priority of the rule
 * @throws SwitchOperationException
 */
@Override
public void installDropFlowCustom(final DatapathId dpid, String dstMac, String dstMask, final long cookie, final int priority) throws SwitchOperationException {
    IOFSwitch sw = lookupSwitch(dpid);
    Match match = simpleDstMatch(sw, dstMac, dstMask);
    OFFlowMod flowMod = buildFlowMod(sw, match, null, null, cookie, priority);
    String flowName = "--CustomDropRule--" + dpid.toString();
    pushFlow(sw, flowName, flowMod);
}
Also used : OFFlowMod(org.projectfloodlight.openflow.protocol.OFFlowMod) Match(org.projectfloodlight.openflow.protocol.match.Match) OFVlanVidMatch(org.projectfloodlight.openflow.types.OFVlanVidMatch)

Example 10 with OFFlowMod

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

the class SwitchManagerTest method shouldDeleteAllNonDefaultRules.

@Test
public void shouldDeleteAllNonDefaultRules() throws Exception {
    // given
    expect(ofSwitchService.getSwitch(dpid)).andStubReturn(iofSwitch);
    expect(iofSwitch.getOFFactory()).andStubReturn(ofFactory);
    OFFlowStatsEntry ofFlowStatsEntry = mock(OFFlowStatsEntry.class);
    expect(ofFlowStatsEntry.getCookie()).andReturn(U64.of(cookie));
    OFFlowStatsReply ofFlowStatsReply = mock(OFFlowStatsReply.class);
    expect(ofFlowStatsReply.getEntries()).andReturn(singletonList(ofFlowStatsEntry));
    ListenableFuture<OFFlowStatsReply> ofStatsFuture = mock(ListenableFuture.class);
    expect(ofStatsFuture.get(anyLong(), anyObject())).andReturn(ofFlowStatsReply);
    expect(iofSwitch.writeRequest(anyObject(OFFlowStatsRequest.class))).andReturn(ofStatsFuture);
    Capture<OFFlowMod> capture = EasyMock.newCapture();
    expect(iofSwitch.write(capture(capture))).andReturn(true);
    expectLastCall();
    replay(ofSwitchService, iofSwitch, ofFlowStatsEntry, ofFlowStatsReply, ofStatsFuture);
    // when
    switchManager.deleteAllNonDefaultRules(dpid);
    // then
    final OFFlowMod actual = capture.getValue();
    assertEquals(OFFlowModCommand.DELETE, actual.getCommand());
    assertEquals(cookie, actual.getCookie().getValue());
    assertEquals(SwitchManager.NON_SYSTEM_MASK, actual.getCookieMask());
}
Also used : OFFlowStatsEntry(org.projectfloodlight.openflow.protocol.OFFlowStatsEntry) OFFlowStatsReply(org.projectfloodlight.openflow.protocol.OFFlowStatsReply) OFFlowStatsRequest(org.projectfloodlight.openflow.protocol.OFFlowStatsRequest) 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