From 95dc8d1d0c2a2fadb58111e810f39dd9344b3b88 Mon Sep 17 00:00:00 2001 From: Christopher Kenna Date: Tue, 7 Dec 2010 02:36:57 -0500 Subject: hc plotting for ASes --- netsec.py | 86 ++++++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 66 insertions(+), 20 deletions(-) diff --git a/netsec.py b/netsec.py index b1f4f30..ad88b90 100755 --- a/netsec.py +++ b/netsec.py @@ -115,6 +115,68 @@ class NetsecPlotter(defapp.App): else: p.gnuplot_exec() + def plot_hc(self, datafile, name, conf): + current_host_num = 0 + host_mapping = {} + + name += "_counts" + + data = self.load(datafile) + for row in data: + if row[0] not in host_mapping: + current_host_num += 1 + host_mapping[row[0]] = current_host_num + row[0] = host_mapping[row[0]] + + del host_mapping + + fname = self.write(data, name, ext='data') + + p = self.make_plot(name) + + p.labels = [label(0.5, 0.9, get_stats_label(data[:,1]), + coord=['graph', 'screen'], align='center')] + + # plot raw samples + p.title = "hop counts by hosts" + p.title += self.get_as_title(conf) + p.ylabel = "hop count" + p.xlabel = "host id" + p.xrange = (0, current_host_num) + #p.xticks = (0, 100) + #p.yticks = (0, 1) + p.yrange = (1, amax(data[:,1]) + 1) + if amax(data[:,1]) > 100: + p.ylog = True + + p.curves = [curve(fname=fname, xcol=1, ycol=2, title="hop count")] + + #### Styling. + + if not self.setup_png(p): + p.rounded_caps = True + p.font = 'Helvetica' + + p.font_size = '10' + p.size = ('20cm', '10cm') + p.monochrome = False + p.dashed_lines = False + p.key = 'off' + p.default_style = 'points lw 1' + + if self.options.smooth: + p.default_style += " smooth bezier" + + self.render(p) + + def get_as_title(self, conf): + if 'as-num' in conf: + return " AS=%s, IP/mask=%s/%s MB=%s Unique Hosts=%s" % \ + (conf['as-num'], conf['as-str'], conf['as-mask'], \ + conf['megabytes'], conf['num-hosts']) + return "" + + def plot_hchisto(self, datafile, name, conf): data = self.load(datafile) @@ -139,10 +201,7 @@ class NetsecPlotter(defapp.App): if 'per-host' in conf: p.title += " HC per-host: %s" % conf['per-host'] - if 'as-num' in conf: - p.title += " AS=%s, IP/mask=%s/%s MB=%s Unique Hosts=%s" % \ - (conf['as-num'], conf['as-str'], conf['as-mask'], \ - conf['megabytes'], conf['num-hosts']) + p.title += self.get_as_title(conf) # p.xrange = (0, ceil(max_cost)) p.xticks = (0, 10) @@ -157,22 +216,6 @@ class NetsecPlotter(defapp.App): if ymax > 10000: p.ylog = True - #print "not implemented yet..." - #return - ## plot raw samples - #p.title = "raw decoding cost; input=%s; host=%s" \ - # % (conf['file'], conf['host']) - - #p.ylabel = "decoding cost (ms)" - #p.xlabel = "frame number" - #p.xrange = (0, len(data)) - ##p.xticks = (0, 100) - #p.yticks = (0, 1) - #p.yrange = (1, ceil(max_cost) + 2) - - #p.curves = [curve(fname=fname, xcol=2, ycol=1, title="decoding cost")] - - #### Styling. if not self.setup_png(p): @@ -197,6 +240,9 @@ class NetsecPlotter(defapp.App): name, ext = splitext(bname) conf = decode(name) + self.plot_hc(datafile, name, conf) + return + if 'per-host' in conf or 'as-num' in conf: self.plot_hchisto(datafile, name, conf) -- cgit v1.2.2