--- /dev/null
+/*
+ * Copyright (c) 2013 Plexxi, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.affinity.analytics.northbound;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.opendaylight.affinity.affinity.AffinityLink;
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.NONE)
+public class AffinityLinkStatistics {
+
+ private AffinityLink link;
+ @XmlElement
+ private long byteCount;
+ @XmlElement
+ private double bitRate;
+
+ // To satisfy JAXB
+ @SuppressWarnings("unused")
+ private AffinityLinkStatistics() {
+ }
+
+ public AffinityLinkStatistics(AffinityLink link, long byteCount, double bitRate) {
+ super();
+ this.link = link;
+ this.byteCount = byteCount;
+ this.bitRate = bitRate;
+ }
+
+ public AffinityLink getLink() {
+ return this.link;
+ }
+
+ public void setLink(AffinityLink link) {
+ this.link = link;
+ }
+
+ public long getByteCount() {
+ return this.byteCount;
+ }
+
+ public void setByteCount(long byteCount) {
+ this.byteCount = byteCount;
+ }
+
+ public double getBitRate() {
+ return this.bitRate;
+ }
+
+ public void setBitRate(double bitRate) {
+ this.bitRate = bitRate;
+ }
+}
import org.codehaus.enunciate.jaxrs.StatusCodes;
import org.codehaus.enunciate.jaxrs.TypeHint;
+import org.opendaylight.affinity.affinity.AffinityLink;
+import org.opendaylight.affinity.affinity.IAffinityManager;
import org.opendaylight.affinity.analytics.IAnalyticsManager;
import org.opendaylight.controller.containermanager.IContainerManager;
import org.opendaylight.controller.hosttracker.IfIptoHost;
}
/**
- * Returns a list of Host Statistics for a given Node.
+ * Returns Host Statistics for a (src, dst) pair
*
* @param containerName
* Name of the Container. The Container name for the base
* DataLayerAddress for the host
* @param networkAddr
* NetworkAddress for the host
- * @return List of Flow Statistics for a given Node. // TODO:
+ * @return Host Statistics for a given Node.
*/
@Path("/{containerName}/hoststats/{srcNetworkAddr}/{dstNetworkAddr}")
@GET
@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") })
- // TODO: This will need other parameters
public HostStatistics getHostStatistics(
@PathParam("containerName") String containerName,
@PathParam("srcNetworkAddr") String srcNetworkAddr,
throw new ServiceUnavailableException("Analytics " + RestMessages.SERVICEUNAVAILABLE.toString());
}
- ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class, containerName, this);
- if (switchManager == null) {
- throw new ServiceUnavailableException("Switch manager " + RestMessages.SERVICEUNAVAILABLE.toString());
- }
-
Host srcHost = handleHostAvailability(containerName, srcNetworkAddr);
Host dstHost = handleHostAvailability(containerName, dstNetworkAddr);
long byteCount = analyticsManager.getByteCountBetweenHosts(srcHost, dstHost);
double bitRate = analyticsManager.getBitRateBetweenHosts(srcHost, dstHost);
return new HostStatistics(srcHost, dstHost, byteCount, bitRate);
+ }
+
+ /**
+ * Returns the affinity link statistics for a given link.
+ *
+ * @param containerName
+ * Name of the Container. The Container name for the base
+ * controller is "default".
+ * @param linkName
+ * AffinityLink name.
+ * @return List of Affinity Link Statistics for a given link.
+ */
+ @Path("/{containerName}/affinitylinkstats/{linkName}")
+ @GET
+ @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+ @TypeHint(HostStatistics.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(
+ @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);
+ long byteCount = analyticsManager.getByteCountOnAffinityLink(al);
+ double bitRate = analyticsManager.getBitRateOnAffinityLink(al);
+
+ return new AffinityLinkStatistics(al, byteCount, bitRate);
}
private void handleDefaultDisabled(String containerName) {
}
}
+ private AffinityLink handleAffinityLinkAvailability(String containerName, String linkName) {
+
+ IAffinityManager affinityManager = (IAffinityManager) ServiceHelper.getInstance(IAffinityManager.class, containerName, this);
+ if (affinityManager == null) {
+ throw new ServiceUnavailableException("Affinity manager " + RestMessages.SERVICEUNAVAILABLE.toString());
+ }
+
+ AffinityLink al = affinityManager.getAffinityLink(linkName);
+ if (al == null) {
+ throw new ResourceNotFoundException(linkName + " : AffinityLink does not exist");
+ }
+
+ return al;
+ }
+
+
private Host handleHostAvailability(String containerName, String networkAddr) {
IfIptoHost hostTracker = (IfIptoHost) ServiceHelper.getInstance(IfIptoHost.class, containerName, this);
sys.exit(-1)
data = json.loads(content)
- # TODO:
for key in data["subnetConfig"]:
- print key["subnet"]
if (key["subnet"] == subnet):
return True
return False
subnet_control = SubnetControl()
subnet_control.add_subnet("defaultSubnet", "10.0.0.254/8")
- src = "10.0.0.1"
- dst = "10.0.0.2"
- host_stat = HostStats(src, dst)
+ test_mode = True
- # These counts should be nonzero
- print("%d bytes between %s and %s" % (host_stat.get_bytes(), src, dst))
- print("%f mbit/s between %s and %s" % (host_stat.get_bit_rate(), src, dst))
+ if (test_mode):
+ src = "10.0.0.1"
+ dst = "10.0.0.2"
+ host_stat = HostStats(src, dst)
+
+ # These counts should be nonzero
+ print("%d bytes between %s and %s" % (host_stat.get_bytes(), src, dst))
+ print("%f mbit/s between %s and %s" % (host_stat.get_bit_rate(), src, dst))
+ sys.exit()
+
+ # Demo mode
if __name__ == "__main__":
main()