Search in sources :

Example 1 with DhcpRelayCommand

use of org.onosproject.dhcprelay.cli.DhcpRelayCommand in project onos by opennetworkinglab.

the class DhcpRelayWebResource method dhcpRelayRecords.

/**
 * To get the list of dhcp relay records.
 *
 * @return dhcpRelayRecords type ArrayNode.
 */
private ArrayNode dhcpRelayRecords() {
    DhcpRelayCommand dhcpRelayCommand = new DhcpRelayCommand();
    DhcpRelayService dhcpDelayService = get(DhcpRelayService.class);
    Collection<DhcpRecord> records = dhcpDelayService.getDhcpRecords();
    ObjectNode node = mapper().createObjectNode();
    ArrayNode dhcpRelayRecords = mapper().createArrayNode();
    records.forEach(record -> {
        ObjectNode dhcpRecord = mapper().createObjectNode();
        dhcpRecord.put("id", record.macAddress() + "/" + record.vlanId());
        dhcpRecord.put("locations", record.locations().toString().concat(record.directlyConnected() ? DIRECTLY : EMPTY));
        dhcpRecord.put("last-seen", Tools.timeAgo(record.lastSeen()));
        dhcpRecord.put("IPv4", dhcpRelayCommand.ip4State(record));
        dhcpRecord.put("IPv6", dhcpRelayCommand.ip6State(record));
        dhcpRelayRecords.add(dhcpRecord);
    });
    return dhcpRelayRecords;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DhcpRelayCommand(org.onosproject.dhcprelay.cli.DhcpRelayCommand) DhcpRelayService(org.onosproject.dhcprelay.api.DhcpRelayService) DhcpRecord(org.onosproject.dhcprelay.store.DhcpRecord) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Aggregations

ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 DhcpRelayService (org.onosproject.dhcprelay.api.DhcpRelayService)1 DhcpRelayCommand (org.onosproject.dhcprelay.cli.DhcpRelayCommand)1 DhcpRecord (org.onosproject.dhcprelay.store.DhcpRecord)1