Search in sources :

Example 6 with DhcpRelayCounters

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)));
}
Also used : DhcpRelayCounters(org.onosproject.dhcprelay.store.DhcpRelayCounters) DhcpRecord(org.onosproject.dhcprelay.store.DhcpRecord) DhcpServerInfo(org.onosproject.dhcprelay.api.DhcpServerInfo)

Aggregations

DhcpRelayCounters (org.onosproject.dhcprelay.store.DhcpRelayCounters)6 DhcpRecord (org.onosproject.dhcprelay.store.DhcpRecord)3 DhcpRelayCountersStore (org.onosproject.dhcprelay.store.DhcpRelayCountersStore)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 DhcpRelayService (org.onosproject.dhcprelay.api.DhcpRelayService)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 DhcpServerInfo (org.onosproject.dhcprelay.api.DhcpServerInfo)1