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;
}
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();
}
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;
}
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;
}
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();
});
}
Aggregations