Added AffinityGroups and Links via northbound API 24/1724/1
authorKatrina LaCurts <katrina.lacurts@plexxi.com>
Mon, 7 Oct 2013 15:07:18 +0000 (11:07 -0400)
committerKatrina LaCurts <katrina.lacurts@plexxi.com>
Mon, 7 Oct 2013 15:07:18 +0000 (11:07 -0400)
Signed-off-by: Katrina LaCurts <katrina.lacurts@plexxi.com>
analytics/implementation/src/main/java/org/opendaylight/affinity/analytics/internal/AnalyticsManager.java
scripts/affinity-topo.py
scripts/analytics.py

index 4da5136ddef5bc1c832eada629b37147ce0ee911..79d73c388210c4582b72da04e2fb54d8766d07f6 100644 (file)
@@ -79,21 +79,6 @@ public class AnalyticsManager implements IReadServiceListener, IAnalyticsManager
 
     void setAffinityManager(IAffinityManager a) {
         this.affinityManager = a;
 
     void setAffinityManager(IAffinityManager a) {
         this.affinityManager = a;
-
-        // TODO: Testing
-        AffinityGroup ag1 = new AffinityGroup("testAG1");
-        ag1.add("10.0.0.1");
-        //        ag1.add("10.0.0.2");
-        AffinityGroup ag2 = new AffinityGroup("testAG2");
-        ag2.add("10.0.0.3");
-        //        ag2.add("10.0.0.4");
-        this.affinityManager.addAffinityGroup(ag1);
-        this.affinityManager.addAffinityGroup(ag2);
-        AffinityLink al = new AffinityLink("testAL", ag1, ag2);
-        this.affinityManager.addAffinityLink(al);
-        al.setAttribute("redirect");
-        al.setWaypoint("10.0.0.4");
-        // TODO: End testing
     }
 
     void unsetAffinityManager(IAffinityManager a) {
     }
 
     void unsetAffinityManager(IAffinityManager a) {
index 8d0559b644d7749866e7d60c2627b9d3c5d6414f..a99c9cc59ce9bf6e13bc8e682d1bde0e95344533 100644 (file)
@@ -8,7 +8,7 @@ from mininet.link import TCLink
 #   > sudo mn --custom affinity-topo.py --topo affinity --link tc
 # Using spaces rather than '=' is very important, as is having the --link flag
 
 #   > sudo mn --custom affinity-topo.py --topo affinity --link tc
 # Using spaces rather than '=' is very important, as is having the --link flag
 
-class CustomTopo(Topo):
+class AffinityTopo(Topo):
 
     def __init__(self, **opts):
         Topo.__init__(self, **opts)
 
     def __init__(self, **opts):
         Topo.__init__(self, **opts)
@@ -27,11 +27,6 @@ class CustomTopo(Topo):
         h2 = self.addHost('h2')
         h3 = self.addHost('h3')
         h4 = self.addHost('h4')
         h2 = self.addHost('h2')
         h3 = self.addHost('h3')
         h4 = self.addHost('h4')
-        h1.setIP('10.0.0.10')
-        h1.setIP('10.0.0.20')
-        h1.setIP('10.0.0.30')
-        h1.setIP('10.0.0.40')
-
 
         # Connect hosts to switches
         self.addLink(h1, s2, bw=10) # These two links get limited
 
         # Connect hosts to switches
         self.addLink(h1, s2, bw=10) # These two links get limited
@@ -39,4 +34,4 @@ class CustomTopo(Topo):
         self.addLink(h3, s3)
         self.addLink(h4, s3)
 
         self.addLink(h3, s3)
         self.addLink(h4, s3)
 
-topos = { 'affinity' : (lambda: CustomTopo()) }
+topos = { 'affinity' : (lambda: AffinityTopo()) }
index 7f31baecfe97555b938ab11e971613ed8a28b3e8..ad135c7a90d7b654b08af5993ffe81e45a048f35 100644 (file)
@@ -65,10 +65,10 @@ class Stats:
             new_rate_ewma = alpha * new_bitrate + (1 - alpha) * self.rate_ewma
             if (self.rate_ewma > 0 and new_rate_ewma > anomaly_threshold * self.rate_ewma):
                 if (self.stat_type == "host"):
             new_rate_ewma = alpha * new_bitrate + (1 - alpha) * self.rate_ewma
             if (self.rate_ewma > 0 and new_rate_ewma > anomaly_threshold * self.rate_ewma):
                 if (self.stat_type == "host"):
-                    print "Anomaly detected between %s and %s" % (self.src, self.dst)
+                    print "!! Anomaly detected between %s and %s" % (self.src, self.dst)
                 elif (self.stat_type == "affinityLink"):
                 elif (self.stat_type == "affinityLink"):
-                    print "Anomaly detected on AffinityLink %s" % (self.al)
-                print "Rate rose from %1.1f mbit/s to %1.1f mbit/s" % ((self.rate_ewma/10**6), (new_rate_ewma/10**6))
+                    print "!! Anomaly detected on AffinityLink %s" % (self.al)
+                print "!! Rate rose from %1.1f mbit/s to %1.1f mbit/s" % ((self.rate_ewma/10**6), (new_rate_ewma/10**6))
             self.rate_ewma = new_rate_ewma
 
     # Bytes
             self.rate_ewma = new_rate_ewma
 
     # Bytes
@@ -88,6 +88,38 @@ class Stats:
         return bitrate
 
 
         return bitrate
 
 
+class AffinityControl:
+
+    def __init__(self):
+        self.http = httplib2.Http(".cache")
+        self.http.add_credentials("admin", "admin")
+        self.url_prefix = "http://localhost:8080/affinity/nb/v2/affinity/default/"
+        self.groups = []
+        self.links = []        
+
+    def add_affinity_group(self, group_name, ips):
+        resp, content = self.http.request(self.url_prefix + "create/group/%s" % group_name, "PUT")
+        if (resp.status != 201):
+            print "AffinityGroup %s could not be created" % group_name
+            return
+        for ip in ips:
+            resp, content = self.http.request(self.url_prefix + "group/%s/add/ip/%s" % (group_name, ip), "PUT")
+            if (resp.status != 201):
+                print "IP %s could not be added to AffinityGroup %s" % (ip, group_name)
+                return
+        self.groups.append(group_name)
+        print "AffinityGroup %s added successfully. IPs are %s" % (group_name, ips)
+
+
+    def add_affinity_link(self, link_name, src_group, dst_group):
+        resp, content = self.http.request(self.url_prefix + "create/link/%s/from/%s/to/%s" % (link_name, src_group, dst_group), "PUT")
+        if (resp.status != 201):
+            print "AffinityLink %s could not be added between %s and %s" % (link_name, src_group, dst_group)
+            return
+        self.links.append(link_name)
+        print "AffinityLink %s added between %s and %s" % (link_name, src_group, dst_group)
+
+
 '''
 Class for controlling subnets.  Right now, just adds subnets and
 checks whether they exist, because that's all we need.
 '''
 Class for controlling subnets.  Right now, just adds subnets and
 checks whether they exist, because that's all we need.
@@ -192,35 +224,38 @@ def get_all_hosts():
     return active_hosts
 
 
     return active_hosts
 
 
-def run_passive_mode():
-
+def run_passive_mode(affinity_links):
+    # TODO: Get affinity_links automatically
     affinity_link_stats = {}
     affinity_link_stats = {}
-    affinity_links = set(["testAL"]) # TODO: Get these automatically
 
 
+    # Go through all affinity link stats
     while True:
     while True:
-        # Go through all affinity link stats
         for al in affinity_links:
             if al not in affinity_link_stats:
                 affinity_link_stats[al] = Stats("affinityLink", al=al)
             stat = affinity_link_stats[al]
             stat.refresh()
             print "%d bytes (%1.1f mbit/s) on %s" % (stat.get_bytes(), (stat.get_bit_rate() / (10**6)), al)
         for al in affinity_links:
             if al not in affinity_link_stats:
                 affinity_link_stats[al] = Stats("affinityLink", al=al)
             stat = affinity_link_stats[al]
             stat.refresh()
             print "%d bytes (%1.1f mbit/s) on %s" % (stat.get_bytes(), (stat.get_bit_rate() / (10**6)), al)
-
         time.sleep(2)
 
 def main():
 
         time.sleep(2)
 
 def main():
 
-    # Default subnet is required for the host tracker to work.  Run
-    # this script once *before* you start mininet.
+    # Default subnet is required for the host tracker to work.
     subnet_control = SubnetControl()
     subnet_control.add_subnet("defaultSubnet", "10.0.0.254/8")
 
     subnet_control = SubnetControl()
     subnet_control.add_subnet("defaultSubnet", "10.0.0.254/8")
 
+    # Set up an affinity link
+    affinity_control = AffinityControl()
+    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")
+
     interactive_mode = False
 
     if interactive_mode:
         run_interactive_mode()
     else:
     interactive_mode = False
 
     if interactive_mode:
         run_interactive_mode()
     else:
-        run_passive_mode()
+        run_passive_mode(["testAL"])
 
 if __name__ == "__main__":
     main()
 
 if __name__ == "__main__":
     main()