Added northbound methods for AffinityLink statistics 39/1439/1
authorKatrina LaCurts <katrina.lacurts@plexxi.com>
Wed, 25 Sep 2013 17:27:59 +0000 (13:27 -0400)
committerKatrina LaCurts <katrina.lacurts@plexxi.com>
Wed, 25 Sep 2013 17:27:59 +0000 (13:27 -0400)
Signed-off-by: Katrina LaCurts <katrina.lacurts@plexxi.com>
analytics/api/pom.xml
analytics/api/src/main/java/org/opendaylight/affinity/analytics/IAnalyticsManager.java
analytics/northbound/pom.xml
analytics/northbound/src/main/java/org/opendaylight/affinity/analytics/northbound/AffinityLinkStatistics.java [new file with mode: 0644]
analytics/northbound/src/main/java/org/opendaylight/affinity/analytics/northbound/AnalyticsNorthbound.java
analytics/northbound/src/main/java/org/opendaylight/affinity/analytics/northbound/HostStatistics.java
scripts/analytics.py

index ae6976f53c45e34bec1570bf3ef82ba7fd3e3c64..1f144a0b85646bd2a04a7710ea017c7cfa8a73b4 100644 (file)
@@ -32,6 +32,7 @@
         <configuration>
           <instructions>
             <Import-Package>
+              org.opendaylight.affinity.affinity,
               org.opendaylight.controller.sal.core,
             </Import-Package>
             <Export-Package>
     </plugins>
   </build>
   <dependencies>
+    <dependency>
+      <groupId>org.opendaylight.affinity</groupId>
+      <artifactId>affinity</artifactId>
+      <version>0.4.0-SNAPSHOT</version>
+    </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>sal</artifactId>
       <version>0.5.0-SNAPSHOT</version>
     </dependency>
-
     <dependency>
       <groupId>org.opendaylight.yangtools.model</groupId>
       <artifactId>ietf-topology</artifactId>
index 99b2753369abb3131b436b6842cb5fb3bd977802..de7b6b16249b8e145adaf8c8260b19f0d5d8f0ae 100644 (file)
@@ -8,6 +8,7 @@
 
 package org.opendaylight.affinity.analytics;
 
+import org.opendaylight.affinity.affinity.AffinityLink;
 import org.opendaylight.controller.sal.core.Host;
 
 public interface IAnalyticsManager {
@@ -15,4 +16,8 @@ public interface IAnalyticsManager {
     long getByteCountBetweenHosts(Host src, Host dst);
 
     double getBitRateBetweenHosts(Host src, Host dst);
+
+    long getByteCountOnAffinityLink(AffinityLink al);
+
+    double getBitRateOnAffinityLink(AffinityLink al);
 }
index 80897810bef7fe6252ee59b29a63c67da9eb6eb6..ff1266f7c2142e8a14618f025feadf26cdfe8792 100644 (file)
@@ -42,6 +42,7 @@
                 javax.ws.rs,
                 javax.ws.rs.core,
                 javax.xml.bind.annotation,
+                org.opendaylight.affinity.affinity,
                 org.opendaylight.affinity.analytics,
                 org.opendaylight.controller.containermanager,
                 org.opendaylight.controller.hosttracker,
     </plugins>
   </build>
   <dependencies>
+    <dependency>
+      <groupId>org.opendaylight.affinity</groupId>
+      <artifactId>affinity</artifactId>
+      <version>0.4.0-SNAPSHOT</version>
+    </dependency>
     <dependency>
       <groupId>org.opendaylight.affinity</groupId>
       <artifactId>analytics</artifactId>
diff --git a/analytics/northbound/src/main/java/org/opendaylight/affinity/analytics/northbound/AffinityLinkStatistics.java b/analytics/northbound/src/main/java/org/opendaylight/affinity/analytics/northbound/AffinityLinkStatistics.java
new file mode 100644 (file)
index 0000000..19f9850
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * 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;
+    }
+}
index 519552d95e69233938f83acfe1070d476d847436..8ca29779d44cb074891d29e292ed2b0bd192f086 100644 (file)
@@ -25,6 +25,8 @@ import org.codehaus.enunciate.jaxrs.ResponseCode;
 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;
@@ -95,7 +97,7 @@ public class AnalyticsNorthbound {
     }
 
     /**
-     * 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
@@ -104,7 +106,7 @@ public class AnalyticsNorthbound {
      *            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
@@ -114,7 +116,6 @@ public class AnalyticsNorthbound {
         @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,
@@ -129,18 +130,50 @@ public class AnalyticsNorthbound {
             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) {
@@ -154,6 +187,22 @@ public class AnalyticsNorthbound {
         }
     }
 
+    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);
index ab5636506a9331b403d71d6813c8b200f8c69d38..ae34fefd89e6a43628ab9a7c811b67fac27e7bde 100644 (file)
@@ -21,9 +21,9 @@ public class HostStatistics {
     private Host srcHost;
     @XmlElement
     private Host dstHost;
-    @XmlElement(name="byteCount")
+    @XmlElement
     private long byteCount;
-    @XmlElement(name="bitRate")
+    @XmlElement
     private double bitRate;
 
     // To satisfy JAXB
index 41384bc38b61048aec31c081d5c387c3e1afa859..958f532bdb86d9bc0dd40bc4b561c76f5b620de4 100644 (file)
@@ -69,9 +69,7 @@ class SubnetControl:
             sys.exit(-1)
         data = json.loads(content)
 
-        # TODO:
         for key in data["subnetConfig"]:
-            print key["subnet"]
             if (key["subnet"] == subnet):
                 return True
         return False
@@ -97,14 +95,20 @@ def main():
     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()