diff options
| -rwxr-xr-x | netsec.py | 86 |
1 files changed, 66 insertions, 20 deletions
| @@ -115,6 +115,68 @@ class NetsecPlotter(defapp.App): | |||
| 115 | else: | 115 | else: |
| 116 | p.gnuplot_exec() | 116 | p.gnuplot_exec() |
| 117 | 117 | ||
| 118 | def plot_hc(self, datafile, name, conf): | ||
| 119 | current_host_num = 0 | ||
| 120 | host_mapping = {} | ||
| 121 | |||
| 122 | name += "_counts" | ||
| 123 | |||
| 124 | data = self.load(datafile) | ||
| 125 | for row in data: | ||
| 126 | if row[0] not in host_mapping: | ||
| 127 | current_host_num += 1 | ||
| 128 | host_mapping[row[0]] = current_host_num | ||
| 129 | row[0] = host_mapping[row[0]] | ||
| 130 | |||
| 131 | del host_mapping | ||
| 132 | |||
| 133 | fname = self.write(data, name, ext='data') | ||
| 134 | |||
| 135 | p = self.make_plot(name) | ||
| 136 | |||
| 137 | p.labels = [label(0.5, 0.9, get_stats_label(data[:,1]), | ||
| 138 | coord=['graph', 'screen'], align='center')] | ||
| 139 | |||
| 140 | # plot raw samples | ||
| 141 | p.title = "hop counts by hosts" | ||
| 142 | p.title += self.get_as_title(conf) | ||
| 143 | p.ylabel = "hop count" | ||
| 144 | p.xlabel = "host id" | ||
| 145 | p.xrange = (0, current_host_num) | ||
| 146 | #p.xticks = (0, 100) | ||
| 147 | #p.yticks = (0, 1) | ||
| 148 | p.yrange = (1, amax(data[:,1]) + 1) | ||
| 149 | if amax(data[:,1]) > 100: | ||
| 150 | p.ylog = True | ||
| 151 | |||
| 152 | p.curves = [curve(fname=fname, xcol=1, ycol=2, title="hop count")] | ||
| 153 | |||
| 154 | #### Styling. | ||
| 155 | |||
| 156 | if not self.setup_png(p): | ||
| 157 | p.rounded_caps = True | ||
| 158 | p.font = 'Helvetica' | ||
| 159 | |||
| 160 | p.font_size = '10' | ||
| 161 | p.size = ('20cm', '10cm') | ||
| 162 | p.monochrome = False | ||
| 163 | p.dashed_lines = False | ||
| 164 | p.key = 'off' | ||
| 165 | p.default_style = 'points lw 1' | ||
| 166 | |||
| 167 | if self.options.smooth: | ||
| 168 | p.default_style += " smooth bezier" | ||
| 169 | |||
| 170 | self.render(p) | ||
| 171 | |||
| 172 | def get_as_title(self, conf): | ||
| 173 | if 'as-num' in conf: | ||
| 174 | return " AS=%s, IP/mask=%s/%s MB=%s Unique Hosts=%s" % \ | ||
| 175 | (conf['as-num'], conf['as-str'], conf['as-mask'], \ | ||
| 176 | conf['megabytes'], conf['num-hosts']) | ||
| 177 | return "" | ||
| 178 | |||
| 179 | |||
| 118 | def plot_hchisto(self, datafile, name, conf): | 180 | def plot_hchisto(self, datafile, name, conf): |
| 119 | data = self.load(datafile) | 181 | data = self.load(datafile) |
| 120 | 182 | ||
| @@ -139,10 +201,7 @@ class NetsecPlotter(defapp.App): | |||
| 139 | if 'per-host' in conf: | 201 | if 'per-host' in conf: |
| 140 | p.title += " HC per-host: %s" % conf['per-host'] | 202 | p.title += " HC per-host: %s" % conf['per-host'] |
| 141 | 203 | ||
| 142 | if 'as-num' in conf: | 204 | p.title += self.get_as_title(conf) |
| 143 | p.title += " AS=%s, IP/mask=%s/%s MB=%s Unique Hosts=%s" % \ | ||
| 144 | (conf['as-num'], conf['as-str'], conf['as-mask'], \ | ||
| 145 | conf['megabytes'], conf['num-hosts']) | ||
| 146 | 205 | ||
| 147 | # p.xrange = (0, ceil(max_cost)) | 206 | # p.xrange = (0, ceil(max_cost)) |
| 148 | p.xticks = (0, 10) | 207 | p.xticks = (0, 10) |
| @@ -157,22 +216,6 @@ class NetsecPlotter(defapp.App): | |||
| 157 | if ymax > 10000: | 216 | if ymax > 10000: |
| 158 | p.ylog = True | 217 | p.ylog = True |
| 159 | 218 | ||
| 160 | #print "not implemented yet..." | ||
| 161 | #return | ||
| 162 | ## plot raw samples | ||
| 163 | #p.title = "raw decoding cost; input=%s; host=%s" \ | ||
| 164 | # % (conf['file'], conf['host']) | ||
| 165 | |||
| 166 | #p.ylabel = "decoding cost (ms)" | ||
| 167 | #p.xlabel = "frame number" | ||
| 168 | #p.xrange = (0, len(data)) | ||
| 169 | ##p.xticks = (0, 100) | ||
| 170 | #p.yticks = (0, 1) | ||
| 171 | #p.yrange = (1, ceil(max_cost) + 2) | ||
| 172 | |||
| 173 | #p.curves = [curve(fname=fname, xcol=2, ycol=1, title="decoding cost")] | ||
| 174 | |||
| 175 | |||
| 176 | #### Styling. | 219 | #### Styling. |
| 177 | 220 | ||
| 178 | if not self.setup_png(p): | 221 | if not self.setup_png(p): |
| @@ -197,6 +240,9 @@ class NetsecPlotter(defapp.App): | |||
| 197 | name, ext = splitext(bname) | 240 | name, ext = splitext(bname) |
| 198 | conf = decode(name) | 241 | conf = decode(name) |
| 199 | 242 | ||
| 243 | self.plot_hc(datafile, name, conf) | ||
| 244 | return | ||
| 245 | |||
| 200 | if 'per-host' in conf or 'as-num' in conf: | 246 | if 'per-host' in conf or 'as-num' in conf: |
| 201 | self.plot_hchisto(datafile, name, conf) | 247 | self.plot_hchisto(datafile, name, conf) |
| 202 | 248 | ||
