this.hostsToStats.get(src).get(dst) != null) {
if (protocol == null) {
byteCount += this.hostsToStats.get(src).get(dst).getByteCount();
- // log.info("Source and destination: {} and {}.", src, dst);
} else
byteCount += this.hostsToStats.get(src).get(dst).getByteCount(protocol);
}
+ if (src != null && dst != null) {
+ log.info("Source and destination: {} and {}, byteCount = {}.", src.getNetworkAddress(), dst.getNetworkAddress(), byteCount);
+ }
}
}
return byteCount;
# put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/group/webservers/addsubnet/ipprefix/10.0.0.1/mask/31'
# rest_method(put_url, "PUT")
- print "add subnet to webservers"
+ print "add endpoint to webservers"
put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/group/webservers/add/ip/10.0.0.1'
rest_method(put_url, "PUT")
- print "add ip to external"
+ print "add ip to clients"
put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/group/clients/add/ip/10.0.0.3'
rest_method(put_url, "PUT")
print "get_all_affinity_links..."
get_all_affinity_links()
- test_tap_2()
+# test_tap_2()
list_all_hosts()
return
#init_urllib()
h = httplib2.Http(".cache")
h.add_credentials('admin', 'admin')
-#if __name__ == "__main__":
-# main()
+if __name__ == "__main__":
+ main()
global prefix
link_name = "inflows"
-rate_low = (100 * 10**3) # 100 kbps
-rate_high = (1 * 10**6) # 1 Mbps
+rate_high = (100 * 10**6) # 100 mbps
+rate_low = (10 * 10**6) # 10 mbps
prefix = "10.0.0.254/8"
# If True, SIG_INT has been captured
def set_high_threshold(self, s):
self.stat.set_high_threshold(s)
- print "Set high threshold for flow rate to %d bps" % s
+ print "Set high threshold for flow rate to %3.3f Mbps" % (int(s) * (1.0/1000000))
print("-------------------------")
def set_low_threshold(self, s):
self.stat.set_low_threshold(s)
- print "Set low threshold for flow rate to %d bps" % s
+ print "Set low threshold for flow rate to %3.3f Mbps" % (int(s) * (1.0/1000000))
print("-------------------------")
def run(self):
high_rate_set = False
while not sigint:
is_high, is_low = self.stat.refresh()
- print "Rate is: %f" % (self.stat.get_ewma_rate())
if is_high and not high_rate_set:
- print "Fast flow detected (%3.3f bit/s)" % (self.stat.get_ewma_rate())
ac = AffinityControl()
-# ac.add_waypoint(link_name, self.waypoint_address)
-## ac.add_isolate(link_name)
-## ac.enable_affinity()
high_rate_set = True
-# time.sleep(3)
+# ac.add_waypoint(link_name, self.waypoint_address)
+ ac.add_isolate(link_name)
+ ac.enable_affinity()
+ print "Adding isolate affinity to link: %s" % (link_name)
+# time.sleep(3)
elif is_low and high_rate_set:
- print "Flow rate below threshold (%3.3f bit/s)" % (self.stat.get_ewma_rate())
-## ac.remove_isolate(link_name)
-## ac.disable_affinity()
high_rate_set = False
- time.sleep(1)
+ ac.remove_isolate(link_name)
+ ac.enable_affinity()
+ print "Adding isolate affinity to link: %s" % (link_name)
+ time.sleep(10)
def main():
print "# flows = %d" % len(flows)
for f in flows:
print f["flow"]["match"], "priority = ", f["flow"]["priority"]
+ print "seconds = ", f["durationSeconds"], "packets = ", f["packetCount"], "bytes = ", f["byteCount"]
print "\t Actions:"
for a in f["flow"]["actions"]:
print "\t \t", a
self.large_flow_threshold = 5 * 10**6 # in bytes
self.rate_threshold = 1 * 10**6 # bits/sec
- print "Created stats"
def __str__(self):
if (self.stat_type == Stats.TYPE_HOST):
if (self.prev_t == None or self.prev_bytes == None):
new_bitrate = 0
else:
- new_bitrate = (self.get_bytes() - self.prev_bytes)/(self.get_duration() - self.prev_t)
- print "Rate is now %f" % (new_bitrate)
+ new_bitrate = 8.0 * (self.get_bytes() - self.prev_bytes)/(self.get_duration() - self.prev_t)
+# print "Rate is now %f" % (new_bitrate)
# Calculate ewma rate from instantaneous rate and check if it crosses threshold.
if (self.rate_ewma == None):
self.rate_ewma = alpha * new_bitrate + (1 - alpha) * self.rate_ewma
if (self.rate_ewma > self.rate_high_threshold):
- print "Rate exceeded %f" % (self.rate_ewma)
+ print "High rate: %3.3f Mbps" % (self.rate_ewma/1000000.0)
is_high = True
- if (self.rate_ewma < self.rate_high_threshold):
- print "Rate dropped %f" % (self.rate_ewma)
+ if (self.rate_ewma < self.rate_low_threshold):
+ print "Low rate: %3.3f Mbps" % (self.rate_ewma/1000000.0)
is_low = True
# Update the time and bytes snapshots
self.prev_t = self.get_duration()
self.prev_bytes = self.get_bytes()
-# print "calc_ewma_rate: [high=%s:low=%s] rate=%f" % (is_high, is_low, self.rate_ewma)
- print "calc_ewma_rate: rate=%f" % (self.rate_ewma)
return [is_high, is_low]