use of org.projectfloodlight.openflow.protocol.OFFactory in project open-kilda by telstra.
the class StatisticsService method startUp.
@Override
public void startUp(FloodlightModuleContext context) throws FloodlightModuleException {
if (interval > 0) {
threadPoolService.getScheduledExecutor().scheduleAtFixedRate(() -> switchService.getAllSwitchMap().values().forEach(iofSwitch -> {
OFFactory factory = iofSwitch.getOFFactory();
final String switchId = iofSwitch.getId().toString();
OFPortStatsRequest portStatsRequest = factory.buildPortStatsRequest().setPortNo(OFPort.ANY).build();
OFFlowStatsRequest flowStatsRequest = factory.buildFlowStatsRequest().setOutGroup(OFGroup.ANY).setCookieMask(SYSTEM_MASK).build();
logger.info("Getting port stats for switch={}", iofSwitch.getId());
Futures.addCallback(iofSwitch.writeStatsRequest(portStatsRequest), new RequestCallback<>(data -> {
List<PortStatsReply> replies = data.stream().map(reply -> {
List<PortStatsEntry> entries = reply.getEntries().stream().map(entry -> {
if (entry.getVersion().compareTo(OFVersion.OF_13) > 0) {
long rxFrameErr, rxOverErr, rxCrcErr, collisions;
rxFrameErr = rxOverErr = rxCrcErr = collisions = 0;
for (OFPortStatsProp property : entry.getProperties()) {
if (property.getType() == 0x0) {
OFPortStatsPropEthernet etherProps = (OFPortStatsPropEthernet) property;
rxFrameErr = etherProps.getRxFrameErr().getValue();
rxOverErr = etherProps.getRxOverErr().getValue();
rxCrcErr = etherProps.getRxCrcErr().getValue();
collisions = etherProps.getCollisions().getLength();
}
}
return new PortStatsEntry(entry.getPortNo().getPortNumber(), entry.getRxPackets().getValue(), entry.getTxPackets().getValue(), entry.getRxBytes().getValue(), entry.getTxBytes().getValue(), entry.getRxDropped().getValue(), entry.getTxDropped().getValue(), entry.getRxErrors().getValue(), entry.getTxErrors().getValue(), rxFrameErr, rxOverErr, rxCrcErr, collisions);
} else {
return new PortStatsEntry(entry.getPortNo().getPortNumber(), entry.getRxPackets().getValue(), entry.getTxPackets().getValue(), entry.getRxBytes().getValue(), entry.getTxBytes().getValue(), entry.getRxDropped().getValue(), entry.getTxDropped().getValue(), entry.getRxErrors().getValue(), entry.getTxErrors().getValue(), entry.getRxFrameErr().getValue(), entry.getRxOverErr().getValue(), entry.getRxCrcErr().getValue(), entry.getCollisions().getValue());
}
}).collect(toList());
return new PortStatsReply(reply.getXid(), entries);
}).collect(toList());
return new PortStatsData(switchId, replies);
}, "port"));
if (factory.getVersion().compareTo(OFVersion.OF_15) != 0) {
// skip flow stats for OF 1.5 protocol version
logger.info("Getting flow stats for switch={}", iofSwitch.getId());
Futures.addCallback(iofSwitch.writeStatsRequest(flowStatsRequest), new RequestCallback<>(data -> {
List<FlowStatsReply> replies = data.stream().map(reply -> {
List<FlowStatsEntry> entries = reply.getEntries().stream().map(entry -> new FlowStatsEntry(entry.getTableId().getValue(), entry.getCookie().getValue(), entry.getPacketCount().getValue(), entry.getByteCount().getValue())).collect(toList());
return new FlowStatsReply(reply.getXid(), entries);
}).collect(toList());
return new FlowStatsData(switchId, replies);
}, "flow"));
}
}), interval, interval, TimeUnit.SECONDS);
}
}
use of org.projectfloodlight.openflow.protocol.OFFactory 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.OFFactory 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.OFFactory in project open-kilda by telstra.
the class SwitchManager method deleteFlow.
// Utility Methods
/**
* {@inheritDoc}
*/
@Override
public long deleteFlow(final DatapathId dpid, final String flowId, final Long cookie) throws SwitchOperationException {
logger.info("deleting flows {} from switch {}", flowId, dpid.toString());
IOFSwitch sw = lookupSwitch(dpid);
OFFactory ofFactory = sw.getOFFactory();
OFFlowDelete flowDelete = ofFactory.buildFlowDelete().setCookie(U64.of(cookie)).setCookieMask(NON_SYSTEM_MASK).build();
return pushFlow(sw, "--DeleteFlow--", flowDelete);
}
use of org.projectfloodlight.openflow.protocol.OFFactory in project open-kilda by telstra.
the class SwitchManager method deleteLegacyMeter.
public long deleteLegacyMeter(final IOFSwitch sw, final DatapathId dpid, final long meterId) throws OFInstallException {
logger.debug("deleting legacy meter {} from switch {}", meterId, dpid);
OFFactory ofFactory = sw.getOFFactory();
OFLegacyMeterMod meterDelete = ofFactory.buildLegacyMeterMod().setMeterId(meterId).setMeters(emptyList()).setCommand(OFLegacyMeterModCommand.DELETE).build();
return pushFlow(sw, "--DeleteMeter--", meterDelete);
}
Aggregations