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());
}
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);
}
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);
}
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);
}
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());
}
Aggregations