use of org.onosproject.dhcprelay.store.DhcpRelayCounters in project onos by opennetworkinglab.
the class DhcpRelayAggCountersCommand method doExecute.
@Override
protected void doExecute() {
boolean toResetFlag;
if (reset != null) {
if (reset.equals("reset") || reset.equals("[reset]")) {
toResetFlag = true;
} else {
print("Last parameter is [reset]");
return;
}
} else {
toResetFlag = false;
}
print(HEADER);
DhcpRelayCountersStore counterStore = AbstractShellCommand.get(DhcpRelayCountersStore.class);
Optional<DhcpRelayCounters> perClassCounters = counterStore.getCounters(GCOUNT);
if (perClassCounters.isPresent()) {
Map<String, Integer> counters = perClassCounters.get().getCounters();
if (counters.size() > 0) {
counters.forEach((name, value) -> {
print("%-30s ............................ %-4d packets", name, value);
});
} else {
print("No counter for {}", GCOUNT);
}
if (toResetFlag) {
counterStore.resetCounters(GCOUNT);
}
}
}
use of org.onosproject.dhcprelay.store.DhcpRelayCounters in project onos by opennetworkinglab.
the class DhcpRelayWebResource method getDhcpRelayCountersJsonOutput.
/**
* To get the details of dhcp relay counters.
*
* @return counterArray type ArrayNode.
*/
private ObjectNode getDhcpRelayCountersJsonOutput() {
ObjectNode node = mapper().createObjectNode();
ObjectNode counters = mapper().createObjectNode();
DhcpRelayService dhcpDelayService = get(DhcpRelayService.class);
Collection<DhcpRecord> records = dhcpDelayService.getDhcpRecords();
ArrayNode counterArray = mapper().createArrayNode();
records.forEach(record -> {
DhcpRelayCounters v6Counters = record.getV6Counters();
Map<String, Integer> countersMap = v6Counters.getCounters();
ObjectNode counterPackets = mapper().createObjectNode();
countersMap.forEach((name, value) -> {
counterPackets.put(name, value);
});
counters.put(record.macAddress() + "/" + record.vlanId().toString(), counterPackets);
});
counterArray.add(counters);
node.put("v6-DHCP-Relay-Counter", counterArray);
return node;
}
use of org.onosproject.dhcprelay.store.DhcpRelayCounters in project onos by opennetworkinglab.
the class DhcpRelayWebResource method resetDhcpRelayAggCountersInternal.
/**
* To reset aggregate counters.
*
* @return counterPackets type ObjectNode.
*/
private void resetDhcpRelayAggCountersInternal() {
DhcpRelayCountersStore counterStore = get(DhcpRelayCountersStore.class);
Optional<DhcpRelayCounters> perClassCounters = counterStore.getCounters(GCOUNT_KEY);
if (perClassCounters.isPresent()) {
counterStore.resetCounters(GCOUNT_KEY);
}
}
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)));
}
use of org.onosproject.dhcprelay.store.DhcpRelayCounters in project onos by opennetworkinglab.
the class DhcpRelayWebResource method resetDhcpRelayCountersInternal.
/**
* To reset dhcp relay counters.
*
* @return counterArray type ArrayNode.
*/
private void resetDhcpRelayCountersInternal() {
DhcpRelayService dhcpDelayService = get(DhcpRelayService.class);
Collection<DhcpRecord> records = dhcpDelayService.getDhcpRecords();
records.forEach(record -> {
DhcpRelayCounters v6Counters = record.getV6Counters();
v6Counters.resetCounters();
});
}
Aggregations