use of org.onosproject.dhcprelay.store.DhcpRelayCounters in project onos by opennetworkinglab.
the class DhcpRelayCommand method doExecute.
@Override
protected void doExecute() {
List<DhcpServerInfo> defaultDhcpServerInfoList = DHCP_RELAY_SERVICE.getDefaultDhcpServerInfoList();
List<DhcpServerInfo> indirectDhcpServerInfoList = DHCP_RELAY_SERVICE.getIndirectDhcpServerInfoList();
if (defaultDhcpServerInfoList.isEmpty() && indirectDhcpServerInfoList.isEmpty()) {
print(MISSING_SERVER_CFG);
return;
}
if (!defaultDhcpServerInfoList.isEmpty()) {
print(DEFAULT_SERVERS);
listServers(defaultDhcpServerInfoList);
}
if (!indirectDhcpServerInfoList.isEmpty()) {
print(INDIRECT_SERVERS);
listServers(indirectDhcpServerInfoList);
}
// DHCP records
Collection<DhcpRecord> records = DHCP_RELAY_SERVICE.getDhcpRecords();
if (records.isEmpty()) {
print(NO_RECORDS);
return;
}
// Handle display of counters
boolean toResetFlag;
if (counter != null) {
if (counter.equals("counter") || counter.equals("[counter]")) {
print(CONUTER_HEADER);
} else {
print("first parameter is [counter]");
return;
}
if (reset != null) {
if (reset.equals("reset") || reset.equals("[reset]")) {
toResetFlag = true;
} else {
print("Last parameter is [reset]");
return;
}
} else {
toResetFlag = false;
}
records.forEach(record -> {
print(COUNTER_HOST, record.macAddress(), record.vlanId(), record.locations(), record.directlyConnected() ? DIRECTLY : EMPTY);
DhcpRelayCounters v6Counters = record.getV6Counters();
Map<String, Integer> countersMap = v6Counters.getCounters();
countersMap.forEach((name, value) -> {
print("%-30s ............................ %-4d packets", name, value);
});
if (toResetFlag) {
v6Counters.resetCounters();
record.updateLastSeen();
DHCP_RELAY_SERVICE.updateDhcpRecord(HostId.hostId(record.macAddress(), record.vlanId()), record);
}
});
return;
}
// Handle display of records
print(HEADER);
records.forEach(record -> print(HOST, record.macAddress(), record.vlanId(), record.locations(), record.directlyConnected() ? DIRECTLY : EMPTY, Tools.timeAgo(record.lastSeen()), ip4State(record), ip6State(record)));
}
Aggregations