long getByteCountOnAffinityLink(AffinityLink al);
double getBitRateOnAffinityLink(AffinityLink al);
+
+ long getByteCountIntoPrefix(String ipAndMask);
}
return totalBytes;
}
- public long getByteCountIntoPrefix(String prefixAndMask, Set <HostNodeConnector> allHosts) {
+ public long getByteCountIntoPrefix(String prefixAndMask) {
long totalBytes = 0;
InetAddress ip;
Short mask;
// Match on prefixes
InetAddress targetPrefix = getPrefix(ip, mask);
+ Set<HostNodeConnector> allHosts = this.hostTracker.getAllHosts();
for (HostNodeConnector host : allHosts) {
InetAddress hostPrefix = getPrefix(host.getNetworkAddress(), mask);
if (hostPrefix.equals(targetPrefix)) {
package org.opendaylight.affinity.analytics.northbound;
+import java.lang.Long;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;
return new AffinityLinkStatistics(al, byteCount, bitRate);
}
+ /**
+ * Returns TODO:
+ *
+ * @param containerName
+ * Name of the Container. The Container name for the base
+ * controller is "default".
+ * @param TODO:
+ * @return TODO:
+ */
+ @Path("/{containerName}/prefixstats/{ip}/{mask}/")
+ @GET
+ @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+ // @TypeHint(Long.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 PrefixStatistics getPrefixMaskStatistics(
+ @PathParam("containerName") String containerName,
+ @PathParam("ip") String ip,
+ @PathParam("mask") String mask) {
+ 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());
+ }
+
+ long byteCount = analyticsManager.getByteCountIntoPrefix(ip + "/" + mask);
+ return new PrefixStatistics(byteCount);
+ }
+
private void handleDefaultDisabled(String containerName) {
IContainerManager containerManager = (IContainerManager) ServiceHelper.getGlobalInstance(IContainerManager.class, this);
if (containerManager == null) {
--- /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.controller.sal.core.Host;
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.NONE)
+public class PrefixStatistics {
+ @XmlElement
+ private long byteCount;
+
+ // To satisfy JAXB
+ @SuppressWarnings("unused")
+ private PrefixStatistics() {
+ }
+
+ public PrefixStatistics(long byteCount) {
+ super();
+ this.byteCount = byteCount;
+ }
+
+ public long getByteCount() {
+ return this.byteCount;
+ }
+
+ public void setByteCount(long byteCount) {
+ this.byteCount = byteCount;
+ }
+}
if (request_type == "quit"):
sys.exit()
- action = request[1]
-
if (request_type == "host"):
+ action = request[1]
src, dst = request[2:4]
+ host_stat = Stats("host", src=src, dst=dst)
if (action == "bytes"):
- host_stat = Stats("host", src=src, dst=dst)
print("%d bytes between %s and %s" % (host_stat.get_bytes(), src, dst))
elif (action == "rate"):
- host_stat = Stats("host", src=src, dst=dst)
print("%f bit/s between %s and %s" % (host_stat.get_bit_rate(), src, dst))
else:
+ print "wrong action"
raise Exception
- # TODO: Change this to use AffinityLinkStats
elif (request_type == "link"):
+ action = request[1]
link = request[2]
- h = httplib2.Http(".cache")
- h.add_credentials("admin", "admin")
- resp, content = h.request("http://localhost:8080/affinity/nb/v2/analytics/default/affinitylinkstats/" + link, "GET")
- al_stats = json.loads(content)
-
+ link_stat = Stats("affinityLink", al=link)
if (action == "bytes"):
- print("%d bytes on %s" % (long(al_stats["byteCount"]), link))
+ print("%d bytes on %s" % (link_stat.get_bytes(), link))
elif (action == "rate"):
- print("%f bit/s on %s" % (float(al_stats["bitRate"]), link))
+ print("%f bit/s on %s" % (link_stat.get_bit_rate(), link))
else:
+ print "wrong action 2"
raise Exception
+ elif (request_type == "prefix"):
+ prefix = request[1]
+ h = httplib2.Http(".cache")
+ h.add_credentials("admin", "admin")
+ url_prefix = "http://localhost:8080/affinity/nb/v2/analytics/default/prefixstats/"
+ resp, content = h.request(url_prefix + prefix, "GET")
+ if (resp.status == 200):
+ data = json.loads(content)
+ print data['byteCount'], "bytes"
+
else:
+ print "something else"
raise Exception
except Exception as e:
print "Error"
+ print e
def get_all_hosts():
affinity_control.add_affinity_group("testAG1", ["10.0.0.1", "10.0.0.2"])
affinity_control.add_affinity_group("testAG2", ["10.0.0.3", "10.0.0.4"])
affinity_control.add_affinity_link("testAL", "testAG1", "testAG2")
- raw_input("[Press enter to continue] ")
+ raw_input("[Press enter to continue]" )
- interactive_mode = False
+ interactive_mode = True
if interactive_mode:
run_interactive_mode()