Search in sources :

Example 1 with DhcpRelayService

use of org.onosproject.dhcprelay.api.DhcpRelayService 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;
}
Also used : DhcpRelayCounters(org.onosproject.dhcprelay.store.DhcpRelayCounters) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DhcpRelayService(org.onosproject.dhcprelay.api.DhcpRelayService) DhcpRecord(org.onosproject.dhcprelay.store.DhcpRecord) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 2 with DhcpRelayService

use of org.onosproject.dhcprelay.api.DhcpRelayService in project onos by opennetworkinglab.

the class DhcpRelayWebResource method dhcpFpmDelete.

/**
 * Deletes the fpm route from fpm record.
 * Corresponding route from the route store
 *
 * @param prefix IpPrefix
 * @return 204 NO CONTENT, 404; 401
 */
@DELETE
@Path("fpm/{prefix}")
public Response dhcpFpmDelete(@PathParam("prefix") String prefix) {
    DhcpRelayService dhcpRelayService = get(DhcpRelayService.class);
    RouteStore routeStore = get(RouteStore.class);
    try {
        // removes fpm route from fpm record
        Optional<FpmRecord> fpmRecord = dhcpRelayService.removeFpmRecord(IpPrefix.valueOf(prefix));
        if (fpmRecord.isPresent()) {
            IpAddress nextHop = fpmRecord.get().nextHop();
            Route route = new Route(Route.Source.DHCP, IpPrefix.valueOf(prefix), nextHop);
            // removes DHCP route from route store
            routeStore.removeRoute(route);
        } else {
            LOG.warn("fpmRecord is not present");
        }
    } catch (IllegalArgumentException ex) {
        throw new IllegalArgumentException(ex);
    }
    return Response.noContent().build();
}
Also used : RouteStore(org.onosproject.routeservice.RouteStore) FpmRecord(org.onosproject.routing.fpm.api.FpmRecord) DhcpRelayService(org.onosproject.dhcprelay.api.DhcpRelayService) IpAddress(org.onlab.packet.IpAddress) Route(org.onosproject.routeservice.Route) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 3 with DhcpRelayService

use of org.onosproject.dhcprelay.api.DhcpRelayService in project onos by opennetworkinglab.

the class DhcpRelayWebResource method getDefaultDhcpServers.

/**
 * To get the list of default dhcp servers.
 *
 * @return node type ObjectNode.
 */
private ArrayNode getDefaultDhcpServers() {
    ObjectNode node = mapper().createObjectNode();
    DhcpRelayService dhcpDelayService = get(DhcpRelayService.class);
    List<DhcpServerInfo> defaultDhcpServerInfoList = dhcpDelayService.getDefaultDhcpServerInfoList();
    ArrayNode defaultDhcpServers = listServers(defaultDhcpServerInfoList);
    return defaultDhcpServers;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DhcpRelayService(org.onosproject.dhcprelay.api.DhcpRelayService) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) DhcpServerInfo(org.onosproject.dhcprelay.api.DhcpServerInfo)

Example 4 with DhcpRelayService

use of org.onosproject.dhcprelay.api.DhcpRelayService 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)

Example 5 with DhcpRelayService

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

Aggregations

DhcpRelayService (org.onosproject.dhcprelay.api.DhcpRelayService)6 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 DhcpRecord (org.onosproject.dhcprelay.store.DhcpRecord)3 DhcpServerInfo (org.onosproject.dhcprelay.api.DhcpServerInfo)2 DhcpRelayCounters (org.onosproject.dhcprelay.store.DhcpRelayCounters)2 DELETE (javax.ws.rs.DELETE)1 Path (javax.ws.rs.Path)1 IpAddress (org.onlab.packet.IpAddress)1 DhcpRelayCommand (org.onosproject.dhcprelay.cli.DhcpRelayCommand)1 Route (org.onosproject.routeservice.Route)1 RouteStore (org.onosproject.routeservice.RouteStore)1 FpmRecord (org.onosproject.routing.fpm.api.FpmRecord)1