@Path("/{containerName}/hoststats/{srcNetworkAddr}/{dstNetworkAddr}")
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
- @TypeHint(HostStatistics.class)
+ @TypeHint(Statistics.class)
@StatusCodes({
- @ResponseCode(code = 200, condition = "Operation successful"),
- @ResponseCode(code = 404, condition = "The containerName is not found"),
- @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
- public HostStatistics getHostStatistics(
- @PathParam("containerName") String containerName,
- @PathParam("srcNetworkAddr") String srcNetworkAddr,
- @PathParam("dstNetworkAddr") String dstNetworkAddr) {
+ @ResponseCode(code = 200, condition = "Operation successful"),
+ @ResponseCode(code = 404, condition = "The containerName is not found"),
+ @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
+ public Statistics getHostStatistics(
+ @PathParam("containerName") String containerName,
+ @PathParam("srcNetworkAddr") String srcNetworkAddr,
+ @PathParam("dstNetworkAddr") String dstNetworkAddr) {
if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.READ, this))
throw new UnauthorizedException("User is not authorized to perform this operation on container " + containerName);
handleDefaultDisabled(containerName);
long byteCount = analyticsManager.getByteCount(srcHost, dstHost);
double bitRate = analyticsManager.getBitRate(srcHost, dstHost);
- return new HostStatistics(srcHost, dstHost, byteCount, bitRate);
+ return new Statistics(byteCount, bitRate);
}
/**
@Path("/{containerName}/hoststats/{srcIP}/{dstIP}/{protocol}")
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
- @TypeHint(HostStatistics.class)
+ @TypeHint(Statistics.class)
@StatusCodes({
@ResponseCode(code = 200, condition = "Operation successful"),
@ResponseCode(code = 404, condition = "The containerName is not found"),
@ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
- public HostStatistics getHostStatistics(
+ public Statistics getHostStatistics(
@PathParam("containerName") String containerName,
@PathParam("srcIP") String srcIP,
@PathParam("dstIP") String dstIP,
long byteCount = analyticsManager.getByteCount(srcHost, dstHost, IPProtocols.getProtocolNumberByte(protocol));
double bitRate = analyticsManager.getBitRate(srcHost, dstHost, IPProtocols.getProtocolNumberByte(protocol));
- return new HostStatistics(srcHost, dstHost, byteCount, bitRate);
+ return new Statistics(byteCount, bitRate);
}
/**
@Path("/{containerName}/hoststats/{srcIP}/{dstIP}/all")
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
- @TypeHint(AllHostStatistics.class)
+ @TypeHint(AllStatistics.class)
@StatusCodes({
@ResponseCode(code = 200, condition = "Operation successful"),
@ResponseCode(code = 404, condition = "The containerName is not found"),
@ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
- public AllHostStatistics getAllHostStatistics(
+ public AllStatistics getAllHostStatistics(
@PathParam("containerName") String containerName,
@PathParam("srcIP") String srcIP,
@PathParam("dstIP") String dstIP) {
Host dstHost = handleHostAvailability(containerName, dstIP);
Map<Byte, Long> byteCounts = analyticsManager.getAllByteCounts(srcHost, dstHost);
Map<Byte, Double> bitRates = analyticsManager.getAllBitRates(srcHost, dstHost);
- AllHostStatistics allStats = new AllHostStatistics();
+ AllStatistics allStats = new AllStatistics();
for (Byte protocol : byteCounts.keySet())
- allStats.addHostStat(protocol, new HostStatistics(srcHost, dstHost, byteCounts.get(protocol), bitRates.get(protocol)));
- System.out.println(">>> " + allStats);
+ allStats.addHostStat(protocol, new Statistics(byteCounts.get(protocol), bitRates.get(protocol)));
return allStats;
}
@Path("/{containerName}/affinitylinkstats/{linkName}")
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
- @TypeHint(HostStatistics.class)
+ @TypeHint(Statistics.class)
@StatusCodes({
@ResponseCode(code = 200, condition = "Operation successful"),
@ResponseCode(code = 404, condition = "The containerName is not found"),
@ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
- public AffinityLinkStatistics getAffinityLinkStatistics(
+ public Statistics getAffinityLinkStatistics(
@PathParam("containerName") String containerName,
@PathParam("linkName") String affinityLinkName) {
if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.READ, this))
long byteCount = analyticsManager.getByteCount(al);
double bitRate = analyticsManager.getBitRate(al);
- return new AffinityLinkStatistics(al, byteCount, bitRate);
+ return new Statistics(byteCount, bitRate);
+ }
+
+ /**
+ * Returns the affinity link statistics for a given link.
+ *
+ * @param containerName: Name of the Container
+ * @param linkName: AffinityLink name
+ * @param protocol: IP Protocol
+ * @return List of Affinity Link Statistics for a given link.
+ */
+ @Path("/{containerName}/affinitylinkstats/{linkName}/{protocol}")
+ @GET
+ @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+ @TypeHint(Statistics.class)
+ @StatusCodes({
+ @ResponseCode(code = 200, condition = "Operation successful"),
+ @ResponseCode(code = 404, condition = "The containerName is not found"),
+ @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
+ public Statistics getAffinityLinkStatistics(
+ @PathParam("containerName") String containerName,
+ @PathParam("linkName") String affinityLinkName,
+ @PathParam("protocol") String protocol) {
+ if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.READ, this))
+ throw new UnauthorizedException("User is not authorized to perform this operation on container " + containerName);
+ handleDefaultDisabled(containerName);
+
+ IAnalyticsManager analyticsManager = getAnalyticsService(containerName);
+ if (analyticsManager == null)
+ throw new ServiceUnavailableException("Analytics " + RestMessages.SERVICEUNAVAILABLE.toString());
+
+ AffinityLink al = handleAffinityLinkAvailability(containerName, affinityLinkName);
+ long byteCount = analyticsManager.getByteCount(al, IPProtocols.getProtocolNumberByte(protocol));
+ double bitRate = analyticsManager.getBitRate(al, IPProtocols.getProtocolNumberByte(protocol));
+
+ return new Statistics(byteCount, bitRate);
+ }
+
+ /**
+ * Returns all affinity link statistics for a given link.
+ *
+ * @param containerName: Name of the Container
+ * @param linkName: AffinityLink name
+ * @return List of Affinity Link Statistics for a given link.
+ */
+ @Path("/{containerName}/affinitylinkstats/{linkName}/all")
+ @GET
+ @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+ @TypeHint(AllStatistics.class)
+ @StatusCodes({
+ @ResponseCode(code = 200, condition = "Operation successful"),
+ @ResponseCode(code = 404, condition = "The containerName is not found"),
+ @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
+ public AllStatistics getAllAffinityLinkStatistics(
+ @PathParam("containerName") String containerName,
+ @PathParam("linkName") String affinityLinkName) {
+ if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.READ, this))
+ throw new UnauthorizedException("User is not authorized to perform this operation on container " + containerName);
+ handleDefaultDisabled(containerName);
+
+ IAnalyticsManager analyticsManager = getAnalyticsService(containerName);
+ if (analyticsManager == null)
+ throw new ServiceUnavailableException("Analytics " + RestMessages.SERVICEUNAVAILABLE.toString());
+
+ AffinityLink al = handleAffinityLinkAvailability(containerName, affinityLinkName);
+ Map<Byte, Long> byteCounts = analyticsManager.getAllByteCounts(al);
+ Map<Byte, Double> bitRates = analyticsManager.getAllBitRates(al);
+ AllStatistics allStats = new AllStatistics();
+ for (Byte protocol : byteCounts.keySet())
+ allStats.addHostStat(protocol, new Statistics(byteCounts.get(protocol), bitRates.get(protocol)));
+ return allStats;
}
/**
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@TypeHint(SubnetStatistics.class)
@StatusCodes({
- @ResponseCode(code = 200, condition = "Operation successful"),
- @ResponseCode(code = 404, condition = "The containerName is not found"),
- @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
- public SubnetStatistics getSubnetStatistics(
- @PathParam("containerName") String containerName,
- @PathParam("srcIP") String srcIP,
- @PathParam("srcMask") String srcMask,
- @PathParam("dstIP") String dstIP,
- @PathParam("dstMask") String dstMask) {
+ @ResponseCode(code = 200, condition = "Operation successful"),
+ @ResponseCode(code = 404, condition = "The containerName is not found"),
+ @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
+ public SubnetStatistics getSubnetStatistics(
+ @PathParam("containerName") String containerName,
+ @PathParam("srcIP") String srcIP,
+ @PathParam("srcMask") String srcMask,
+ @PathParam("dstIP") String dstIP,
+ @PathParam("dstMask") String dstMask) {
if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.READ, this))
throw new UnauthorizedException("User is not authorized to perform this operation on container " + containerName);
handleDefaultDisabled(containerName);
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@TypeHint(AllHosts.class)
@StatusCodes({
- @ResponseCode(code = 200, condition = "Operation successful"),
- @ResponseCode(code = 404, condition = "The containerName is not found"),
- @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
- public AllHosts getIncomingHostByteCounts(
- @PathParam("containerName") String containerName,
- @PathParam("ip") String ip,
- @PathParam("mask") String mask) {
+ @ResponseCode(code = 200, condition = "Operation successful"),
+ @ResponseCode(code = 404, condition = "The containerName is not found"),
+ @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
+ public AllHosts getIncomingHostByteCounts(
+ @PathParam("containerName") String containerName,
+ @PathParam("ip") String ip,
+ @PathParam("mask") String mask) {
// TODO: Change AllHosts class name to something better
if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.READ, this))
throw new UnauthorizedException("User is not authorized to perform this operation on container " + containerName);
### Affinity link statistics
+def bytes_on_link(al):
+ url = "http://localhost:8080/affinity/nb/v2/analytics/default/affinitylinkstats/%s" % al
+ data = rest_method(url, "GET")
+ print("%s bytes on link %s" % (data['byteCount'], al))
+
+def bytes_on_link_protocol(al, protocol):
+ url = "http://localhost:8080/affinity/nb/v2/analytics/default/affinitylinkstats/%s/%s" % (al, protocol)
+ data = rest_method(url, "GET")
+ print("%s bytes on link %s for protocol %s" % (data['byteCount'], al, protocol))
+
+def rate_on_link(al):
+ url = "http://localhost:8080/affinity/nb/v2/analytics/default/affinitylinkstats/%s" % al
+ data = rest_method(url, "GET")
+ print("%s bit/s on link %s" % (data['bitRate'], al))
+
+def rate_on_link_protocol(al, protocol):
+ url = "http://localhost:8080/affinity/nb/v2/analytics/default/affinitylinkstats/%s/%s" % (al, protocol)
+ data = rest_method(url, "GET")
+ print("%s bit/s on link %s for protocol %s" % (data['bitRate'], al, protocol))
+
+def all_byte_counts_link(al):
+ url = "http://localhost:8080/affinity/nb/v2/analytics/default/affinitylinkstats/%s/all" % al
+ data = rest_method(url, "GET")['data']['entry']
+ for entry in data:
+ protocol = entry['key']
+ byte_count = entry['value']['byteCount']
+ print("%s bytes from protocol %s" % (byte_count, protocol))
+
+def all_bit_rates_link(al):
+ url = "http://localhost:8080/affinity/nb/v2/analytics/default/affinitylinkstats/%s/all" % al
+ data = rest_method(url, "GET")['data']['entry']
+ for entry in data:
+ protocol = entry['key']
+ bit_rate = entry['value']['bitRate']
+ print("%s bit/s from protocol %s" % (bit_rate, protocol))
+
def run_interactive_mode():
print "Usage: [host | link] [src dst | link-name] {protocol}"
# Demo mode
while True:
request = raw_input("> ")
- try:
- request = request.split()
- request_type = request[0]
-
- if (request_type == "quit" or request_type == "exit"):
- sys.exit()
-
- if (request_type == "host"):
- if (len(request) == 3):
- src, dst = request[1:3]
- bytes_between_hosts(src, dst)
- rate_between_hosts(src, dst)
- all_byte_counts_hosts(src, dst)
- all_bit_rates_hosts(src, dst)
- elif (len(request) == 4):
- src, dst, protocol = request[1:4]
- bytes_between_hosts_protocol(src, dst, int(protocol))
- rate_between_hosts_protocol(src, dst, int(protocol))
-
- elif (request_type == "link"):
+ request = request.split()
+ request_type = request[0]
+
+ if (request_type == "quit" or request_type == "exit"):
+ sys.exit()
+
+ if (request_type == "host"):
+ if (len(request) == 3):
+ src, dst = request[1:3]
+ bytes_between_hosts(src, dst)
+ rate_between_hosts(src, dst)
+ all_byte_counts_hosts(src, dst)
+ all_bit_rates_hosts(src, dst)
+ elif (len(request) == 4):
+ src, dst, protocol = request[1:4]
+ bytes_between_hosts_protocol(src, dst, int(protocol))
+ rate_between_hosts_protocol(src, dst, int(protocol))
+
+ elif (request_type == "link"):
+ if (len(request) == 2):
link = request[1]
-
- elif (request_type == "subnet"):
- subnet = request[1]
+ bytes_on_link(link)
+ rate_on_link(link)
+ all_byte_counts_link(link)
+ all_bit_rates_link(link)
+ elif (len(request) == 3):
+ link, protocol = request[1:3]
+ bytes_on_link_protocol(link, protocol)
+ rate_on_link_protocol(link, protocol)
+
+ elif (request_type == "subnet"):
+ subnet = request[1]
def main():
subnet_control.add_subnet("defaultSubnet", "10.0.0.254/8")
# Set up an affinity link
-# affinity_control = AffinityControl()
-# affinity_control.add_affinity_group("testAG1", ips=["10.0.0.1", "10.0.0.2"])
-# affinity_control.add_affinity_group("testAG2", ips=["10.0.0.3", "10.0.0.4"])
-# affinity_control.add_affinity_link("testAL", "testAG1", "testAG2")
+ affinity_control = AffinityControl()
+ affinity_control.add_affinity_group("testAG1", ips=["10.0.0.1", "10.0.0.2"])
+ affinity_control.add_affinity_group("testAG2", ips=["10.0.0.3", "10.0.0.4"])
+ affinity_control.add_affinity_link("testAL", "testAG1", "testAG2")
# raw_input("[Press enter to continue]" )
run_interactive_mode()