use of org.projectfloodlight.openflow.protocol.OFFlowStatsReply in project open-kilda by telstra.
the class RecordHandler method doDumpRulesRequest.
private void doDumpRulesRequest(final CommandMessage message) {
DumpRulesRequest request = (DumpRulesRequest) message.getData();
final String switchId = request.getSwitchId();
logger.debug("Loading installed rules for switch {}", switchId);
OFFlowStatsReply reply = context.getSwitchManager().dumpFlowTable(DatapathId.of(switchId));
List<FlowEntry> flows = reply.getEntries().stream().map(OFFlowStatsConverter::toFlowEntry).collect(Collectors.toList());
SwitchFlowEntries response = SwitchFlowEntries.builder().switchId(switchId).flowEntries(flows).build();
InfoMessage infoMessage = new InfoMessage(response, message.getTimestamp(), message.getCorrelationId());
context.getKafkaProducer().postMessage(TOPO_ENG_TOPIC, infoMessage);
}
use of org.projectfloodlight.openflow.protocol.OFFlowStatsReply 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.OFFlowStatsReply in project open-kilda by telstra.
the class SwitchManager method dumpFlowTable.
/**
* {@inheritDoc}
*/
@Override
public OFFlowStatsReply dumpFlowTable(final DatapathId dpid) {
OFFlowStatsReply values = null;
IOFSwitch sw = ofSwitchService.getSwitch(dpid);
if (sw == null) {
throw new IllegalArgumentException(String.format("Switch %s was not found", dpid.toString()));
}
OFFactory ofFactory = sw.getOFFactory();
OFFlowStatsRequest flowRequest = ofFactory.buildFlowStatsRequest().setOutGroup(OFGroup.ANY).setCookieMask(U64.ZERO).build();
try {
ListenableFuture<OFFlowStatsReply> future = sw.writeRequest(flowRequest);
values = future.get(10, TimeUnit.SECONDS);
} catch (ExecutionException | InterruptedException | TimeoutException e) {
logger.error("Could not get flow stats: {}", e.getMessage());
}
return values;
}
use of org.projectfloodlight.openflow.protocol.OFFlowStatsReply 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.OFFlowStatsReply 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