use of org.projectfloodlight.openflow.protocol.OFFlowStatsEntry in project open-kilda by telstra.
the class SwitchManager method deleteAllNonDefaultRules.
@Override
public List<Long> deleteAllNonDefaultRules(final DatapathId dpid) throws SwitchOperationException {
OFFlowStatsReply flowStats = dumpFlowTable(dpid);
IOFSwitch sw = lookupSwitch(dpid);
OFFactory ofFactory = sw.getOFFactory();
List<Long> removedRules = new ArrayList<>();
for (OFFlowStatsEntry flowStatsEntry : flowStats.getEntries()) {
long flowCookie = flowStatsEntry.getCookie().getValue();
if (flowCookie != DROP_RULE_COOKIE && flowCookie != VERIFICATION_BROADCAST_RULE_COOKIE && flowCookie != VERIFICATION_UNICAST_RULE_COOKIE) {
OFFlowDelete flowDelete = ofFactory.buildFlowDelete().setCookie(U64.of(flowCookie)).setCookieMask(NON_SYSTEM_MASK).build();
pushFlow(sw, "--DeleteFlow--", flowDelete);
removedRules.add(flowCookie);
}
}
return removedRules;
}
use of org.projectfloodlight.openflow.protocol.OFFlowStatsEntry in project open-kilda by telstra.
the class FlowsResource method getFlows.
@Get("json")
@SuppressWarnings("unchecked")
public Map<String, Object> getFlows() {
Map<String, Object> response = new HashMap<>();
String switchId = (String) this.getRequestAttributes().get("switch_id");
LOGGER.debug("Get flows for switch: {}", switchId);
ISwitchManager switchManager = (ISwitchManager) getContext().getAttributes().get(ISwitchManager.class.getCanonicalName());
try {
OFFlowStatsReply replay = switchManager.dumpFlowTable(DatapathId.of(switchId));
LOGGER.debug("OF_STATS: {}", replay);
if (replay != null) {
for (OFFlowStatsEntry entry : replay.getEntries()) {
String key = String.format("flow-0x%s", Long.toHexString(entry.getCookie().getValue()).toUpperCase());
response.put(key, buildFlowStat(entry));
}
}
} catch (IllegalArgumentException exception) {
String messageString = "No such switch";
LOGGER.error("{}: {}", messageString, switchId, exception);
MessageError responseMessage = new MessageError(DEFAULT_CORRELATION_ID, System.currentTimeMillis(), ErrorType.PARAMETERS_INVALID.toString(), messageString, exception.getMessage());
response.putAll(MAPPER.convertValue(responseMessage, Map.class));
}
return response;
}
use of org.projectfloodlight.openflow.protocol.OFFlowStatsEntry 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