-
Notifications
You must be signed in to change notification settings - Fork 4
/
simmeshv13.py
1128 lines (979 loc) · 39.1 KB
/
simmeshv13.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
import pygtk
pygtk.require('2.0')
import gtk
import gobject
import math
import pickle
import os
import netsnmp
import time
import vboxapi
import ipdb
dir_trabajo = ''
wire_prop = {'lo': 0, 'de': 0, 'du': 0, 'bw': 0, 'sp': 0,
'ca': 0, 'da': 0, 'ch': '24GHz'}
password = ''
v_name_base = 'openwrtv12'
trace_l2 = False
node_tr = []
node_head = ''
o = []
n = []
class LinkList(list):
def __init__(self):
self.ll = []
self.current_wire = None
def stop(self):
os.system('killall -q wirefilter')
for x in self:
x.stop()
def __del__(self):
self.stop()
def start(self):
for x in self:
x.start()
def set_current_wire(self, sdds):
for x in self:
if x.sd in sdds:
self.current_wire = sdds
class NodoList(list):
def __init__(self):
self.nl = []
self.current = None
self.run = False
def set_current(self, no):
self.current = no
def set_cur_pos(self, pos):
for x in self:
if x.pos == pos:
self.current = x
def stop(self):
for x in self:
x.stop()
self.run = False
def start(self):
for x in self:
x.start()
self.run = True
link_color24 = LinkList()
link_color50 = LinkList()
nodolist = NodoList()
class Interface(object):
def __init__(self, indice, name, nodonum, oamip):
self.ind = indice
self.name = name
self.oamip = oamip
self.ifpresent = False
self.rx = '0'
self.tx = '0'
self.ip = {'tapwrt': '192.168.' + nodonum + '.1',
'oam': '192.168.100.' + nodonum,
'lo': None,
'eth0': '192.168.100.' + nodonum,
'eth1': None,
'eth2': None,
'bat0': '192.168.7.' + nodonum, }[name]
self.mac = {'tapwrt': None,
'oam': None,
'lo': None,
'eth0': '80:01:00:00:07:' + nodonum,
'eth1': '80:02:00:00:07:' + nodonum,
'eth2': '80:05:00:00:07:' + nodonum,
'bat0': '90:' + nodonum + ':' + nodonum + ':' + nodonum +
':' + nodonum + ':' + nodonum}[name]
def __str__(self):
return str(self.name)
class NodoClass(object):
def __init__(self, p):
self.pos = p
self.num = int(p[0] * 10 + p[1])
self.name = 'wrt' + str(self.num)
self.octet_str = str(self.num)
self.smp_ip = '192.168.100.' + str(self)
self.oam = Interface(None, 'oam', str(self), self.smp_ip)
self.tapwrt = Interface(None, 'tapwrt', str(self), self.smp_ip)
self.lo = Interface(1, 'lo', str(self), self.smp_ip)
self.eth0 = Interface(2, 'eth0', str(self), self.smp_ip)
self.eth1 = Interface(3, 'eth1', str(self), self.smp_ip)
self.eth2 = Interface(4, 'eth2', str(self), self.smp_ip)
self.bat0 = Interface(5, 'bat0', str(self), self.smp_ip)
self.interfases = [self.tapwrt, self.oam, self.lo, self.eth0,
self.eth1, self.eth2, self.bat0]
self.originator_nexthop = ['None'], ['None']
self.vm = v_name_base
self.load_average = '0.00'
self.count = 0
self.running = False
def __str__(self):
return str(self.num)
def __del__(self):
self.stop()
def stop(self):
if self.running:
os.system('echo ' + password + ' | sudo -S rm -rf /tmp/24GHz' +
self.octet_str)
os.system('echo ' + password + ' | sudo -S rm -rf /tmp/50GHz' +
self.octet_str)
os.system('echo ' + password + ' | sudo -S ip addr del ' +
self.tapwrt.ip + '/24 dev tap24GHz' + self.octet_str)
os.system('echo ' + password + ' | sudo -S ip link delete tap24GHz'
+ self.octet_str)
os.system('echo ' + password + ' | sudo -S ip addr del '
+ self.tapwrt.ip + '/24 dev tap50GHz' + self.octet_str)
os.system('echo ' + password + ' | sudo -S ip link delete tap50GHz'
+ self.octet_str)
os.system('VBoxManage controlvm num' + self.octet_str + ' poweroff')
os.system('VBoxManage unregistervm --delete num' + self.octet_str)
os.system('killall -q vde_switch')
self.running = False
def get_originators_nexthop(self):
host = self.smp_ip
mibr = netsnmp.Varbind('iso.3.6.1.4.1.32.1.2')
orig = netsnmp.snmpget(mibr, Version=2, DestHost=host,
Community='public', Timeout=50000, Retries=3)
on = str(orig[0]).split()
return on[::2], on[1::2]
def start(self):
if not self.running:
os.system('echo ' + password + ' | sudo -S ip tuntap add tap24GHz'
+ self.octet_str + ' mode tap')
os.system('echo ' + password + ' | sudo -S ifconfig tap24GHz'
+ self.octet_str + ' ' + self.tapwrt.ip + ' up')
os.system('echo ' + password + ' | sudo -S ip tuntap add tap50GHz'
+ self.octet_str + ' mode tap')
os.system('echo ' + password + ' | sudo -S ifconfig tap50GHz'
+ self.octet_str + ' ' + self.tapwrt.ip + ' up')
os.system('vde_switch -d --hub -s /tmp/24GHz' + self.octet_str
+ ' -tap tap24GHz' + self.octet_str + ' -m 666 -f ' + dir_trabajo
+ '/colourful.rc')
os.system('vde_switch -d --hub -s /tmp/50GHz' + self.octet_str
+ ' -tap tap50GHz' + self.octet_str + ' -m 666 -f ' + dir_trabajo
+ '/colourful.rc')
os.system('VBoxManage clonevm ' + self.vm + ' --name num'
+ self.octet_str + ' --register')
os.system('VBoxManage modifyvm num' + self.octet_str +
' --nic1 hostonly --hostonlyadapter1 vboxnet0 --macaddress1 '
+ str(self.eth0.mac).translate(None, ':'))
os.system('VBoxManage modifyvm num' + self.octet_str
+ ' --nic2 generic --nicgenericdrv2 VDE --nicproperty2 network=/tmp/24GHz' + self.octet_str + '[2] --macaddress2 ' + str(self.eth1.mac).translate(None, ':'))
os.system('VBoxManage modifyvm num' + self.octet_str
+ ' --nic3 generic --nicgenericdrv3 VDE --nicproperty3 network=/tmp/50GHz' + self.octet_str + '[3] --macaddress3 ' + str(self.eth2.mac).translate(None, ':'))
os.system('VBoxManage startvm num' + self.octet_str + node_head)
self.running = True
class WireClass(object):
def __init__(self, src, dst, quality):
self.s = src
self.d = dst
self.sd = src, dst
self.ds = dst, src
self.quality = quality
self.s_str = str(point2num(self.s))
self.d_str = str(point2num(self.d))
self.name = "wire" + self.s_str + '-' + self.d_str
self.canal = self.quality['ch']
self.running = False
self.prop = {'lo': self.quality['lo'],
'de': self.quality['de'],
'du': self.quality['du'],
'bw': self.quality['bw'],
'sp': self.quality['sp'],
'ca': self.quality['ca'],
'da': self.quality['da'],
'ch': self.quality['ch']}
def __del__(self):
if nodolist.run:
link_color24.stop()
link_color50.stop()
link_color24.start()
link_color50.start()
def start(self):
if not self.running:
od = 'wirefilter' + ' --daemon -v /tmp/' + self.canal + self.s_str + ':/tmp/' + self.canal + self.d_str
if self.prop['lo'] != 0:
od = od + ' -l ' + str(self.prop['lo'])
if self.prop['de'] != 0:
od = od + ' -d ' + str(self.prop['de']) + '+' + str(self.prop['de'] / 2) + 'N'
if self.prop['du'] != 0:
od = od + ' -D ' + str(self.prop['du'])
if self.prop['bw'] != 0:
od = od + ' -b ' + str(self.prop['bw'])
if self.prop['sp'] != 0:
od = od + ' -s ' + str(self.prop['sp'])
if self.prop['ca'] != 0:
od = od + ' -c ' + str(self.prop['ca'])
if self.prop['da'] != 0:
od = od + ' -n ' + str(self.prop['da'])
os.system(od)
self.running = True
def stop(self):
self.running = False
def traceon(signal):
global trace_l2, node_tr
node_tr = []
if signal.active:
trace_l2 = True
else:
trace_l2 = False
def headon(signal):
global node_head
if signal.active:
node_head = ' --type headless'
else:
node_head = ''
def point2num(point):
return int(point[0] * 10 + point[1])
# set point close to grid node
def near(punto, eh, ev):
x, y = punto
xi, xd = divmod(x, eh)
yi, yd = divmod(y, ev)
if xd > eh / 2:
if xi < 10:
xi = xi + 1
if yd > ev / 2:
yi = yi + 1
return xi, yi
def open_mesh(widget):
global link_color24, link_color50, nodolist
if not nodolist.run:
dialog = gtk.FileChooserDialog(
"Select a mesh file",
None,
gtk.FILE_CHOOSER_ACTION_OPEN,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN, gtk.RESPONSE_OK))
response = dialog.run()
if response == gtk.RESPONSE_OK:
file_path = dialog.get_filename()
with open(file_path, 'rb') as f:
nodolist, link_color24, link_color50 = pickle.load(f)
archivo_corriente = file_path
elif response == gtk.RESPONSE_CANCEL:
dialog.destroy()
dialog.destroy()
else:
message_stop()
def message_stop():
md = gtk.MessageDialog(None,
gtk.DIALOG_DESTROY_WITH_PARENT,
gtk.MESSAGE_INFO,
gtk.BUTTONS_CLOSE,
"Firs stop emulation")
md.run()
md.destroy()
def save_mesh(signal):
if not nodolist.run:
datos = nodolist, link_color24, link_color50
with open(dir_trabajo + '/data.ms', 'wb') as f:
pickle.dump(datos, f)
else:
message_stop()
def save_as_mesh(signal):
if not nodolist.run:
dialog = gtk.FileChooserDialog("Select or create a mesh file",
None,
gtk.FILE_CHOOSER_ACTION_SAVE,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN, gtk.RESPONSE_OK))
response = dialog.run()
if response == gtk.RESPONSE_OK:
file_path = dialog.get_filename()
datos = nodolist, link_color24, link_color50
with open(file_path, 'wb') as f:
pickle.dump(datos, f)
archivo_corriente = file_path
elif response == gtk.RESPONSE_CANCEL:
dialog.destroy()
dialog.destroy()
else:
message_stop()
def select_folder(signal):
global dir_trabajo
if not nodolist.run:
dialog = gtk.FileChooserDialog("Select work directory",
None,
gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN, gtk.RESPONSE_OK))
response = dialog.run()
if response == gtk.RESPONSE_OK:
dir_trabajo = dialog.get_filename()
elif response == gtk.RESPONSE_CANCEL:
dialog.destroy()
dialog.destroy()
else:
message_stop()
def response_to_dialog(entry, dialog, response):
dialog.response(response)
def get_password():
dialog = gtk.MessageDialog(
None,
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
gtk.MESSAGE_QUESTION,
gtk.BUTTONS_OK,
None)
dialog.set_markup('Please enter your <b>password</b>:')
entry = gtk.Entry()
entry.connect("activate", response_to_dialog, dialog, gtk.RESPONSE_OK)
entry.set_visibility(False)
hbox = gtk.HBox()
hbox.pack_start(gtk.Label("Password:"), False, 5, 5)
hbox.pack_end(entry)
dialog.format_secondary_markup("This will be used for create interfaces in your local machine")
dialog.vbox.pack_end(hbox, True, True, 0)
dialog.set_position(gtk.WIN_POS_CENTER)
dialog.show_all()
dialog.run()
text = entry.get_text()
dialog.destroy()
return text
def run_mesh(signal):
if not nodolist.run:
nodolist.start()
link_color24.start()
link_color50.start()
os.system('echo ' + password +
' | sudo -S ifconfig vboxnet0 inet 192.168.100.1 up')
# nodolist.run = True
def stop_mesh(signal):
global node_tr
if nodolist.run:
link_color24.stop()
link_color50.stop()
os.system('killall -q vde_switch')
nodolist.stop()
os.system('echo ' + password + ' | sudo -S ip addr del 192.168.100.1/24 dev vboxnet0')
os.system('echo ' + password + ' | sudo -S ip link set vboxnet0 down')
# nodolist.run = False
node_tr = []
def delete_mesh(signal):
if not nodolist.run:
for x in link_color24[:]:
link_color24.remove(x)
for x in link_color50[:]:
link_color50.remove(x)
for x in nodolist[:]:
nodolist.remove(x)
else:
message_stop()
def remover_nodos(signal):
link = [(j.sd) for j in link_color24]
o = [(j[0]) for j in link]
d = [(j[1]) for j in link]
link = [(j.sd) for j in link_color50]
o5 = [(j[0]) for j in link]
d5 = [(j[1]) for j in link]
for i in nodolist[:]:
if (i.pos not in o and i.pos not in d) and (i.pos not in o5 and i.pos not in d5):
nodolist.remove(i)
def remover_enlaces(signal):
n = [(j.pos) for j in nodolist]
for i in link_color24[:]:
linea = i.sd
((x1, y1), (x2, y2)) = linea
if (x1, y1) not in n or (x2, y2) not in n:
link_color24.remove(i)
for i in link_color50[:]:
linea = i.sd
((x1, y1), (x2, y2)) = linea
if (x1, y1) not in n or (x2, y2) not in n:
link_color50.remove(i)
if nodolist.run:
link_color24.start()
link_color50.start()
# Create a new backing pixmap of the appropriate size
def configure_event(widget, event):
return True
def dibujar(widget):
global cr, node_tr
cr = widget.window.cairo_create()
w = widget.allocation.width
h = widget.allocation.height
cr.set_source_rgb(0.0, 0.0, 0.0)
cr.rectangle(0, 0, w, h)
cr.fill()
# import ipdb; ipdb.set_trace()
# Draw background grid
cr.set_line_width(1)
cr.set_source_rgba(0.2, 0.2, 0.2, 1.0)
eh = int((w - 260) / 9)
ev = int((h - 99) / 9)
# Draw vertical line
for i in range(10):
cr.move_to(i * eh, ev)
cr.line_to(i * eh, ev * 9)
# Draw horizontal line
for i in range(9):
cr.move_to(0, (i + 1) * ev)
cr.line_to(eh * 9, (i + 1) * ev)
cr.stroke()
# Draw wire
cr.select_font_face('Sans')
cr.set_font_size(12)
for l in link_color24:
if l.sd in link_color24.current_wire:
# Draw wire property for current wire
cr.set_source_rgba(0.6, 0.4, 1.0, 1.0) # blue
i = 0
for p in l.prop:
cr.move_to(i * 70, h - 70)
cr.show_text(p + ': ' + str(l.prop[p]))
i += 1
cr.set_source_rgba(0.6, 0.4, 1.0, 1.0) # blue
cr.set_line_width(6.0)
else:
cr.set_source_rgba(0.6, 0.4, 1.0, 1.0) # blue
cr.set_line_width(2.0)
if trace_l2 and (str(point2num(l.sd[0])) in node_tr and
str(point2num(l.sd[1]))) in node_tr:
cr.set_source_rgba(1.0, 1.0, 1.0, 0.5)
(xi, yi), (xf, yf) = l.sd
cr.move_to(xi * eh, yi * ev)
cr.line_to(xf * eh, yf * ev)
cr.stroke()
for l in link_color50:
if l.sd in link_color50.current_wire:
# Draw wire property for current wire
cr.set_source_rgba(0.6, 1.0, 0.0, 1.0) # green
i = 0
for p in l.prop:
cr.move_to(i * 70, h - 57)
cr.show_text(p + ': ' + str(l.prop[p]))
i += 1
cr.set_source_rgba(0.6, 1.0, 0.0, 0.5) # green
cr.set_line_width(6.0)
else:
cr.set_source_rgba(0.6, 1.0, 0.0, 0.5) # green
cr.set_line_width(2.0)
if trace_l2 and (str(point2num(l.sd[0])) in node_tr and
str(point2num(l.sd[1]))) in node_tr:
cr.set_source_rgba(1.0, 1.0, 1.0, 0.5)
(xi, yi), (xf, yf) = l.sd
cr.move_to(xi * eh, yi * ev)
cr.line_to(xf * eh, yf * ev)
cr.stroke()
# Draw nodo
for po in nodolist:
p = po.pos
cr.arc(p[0] * eh, p[1] * ev, 12, 0, 2 * math.pi)
cr.set_source_rgba(0.1, 0.6, 0.1, 1.0)
if nodolist.run:
if po.count == 0:
mibr = netsnmp.Varbind('iso.3.6.1.4.1.2021.10.1.3.1')
po.load_average = netsnmp.snmpget(mibr, Version=2,
DestHost=po.smp_ip,
Community='public',
Timeout=5000, Retries=1)[0]
if po.load_average is None:
cr.set_source_rgba(0.6, 0.0, 0.0, 1.0)
elif float(po.load_average) > 1:
po.count = 10
else:
cr.set_source_rgba(0.1, 0.6, 0.1, 1.0)
mibr = netsnmp.Varbind('iso.3.6.1.2.1.2.2.1.11')
rx = netsnmp.snmpwalk(mibr, Version=2, DestHost=po.smp_ip,
Community='public',
Timeout=5000, Retries=1)
mibr = netsnmp.Varbind('iso.3.6.1.2.1.2.2.1.17')
tx = netsnmp.snmpwalk(mibr, Version=2, DestHost=po.smp_ip,
Community='public',
Timeout=5000, Retries=1)
for i in po.interfases:
if i.ind:
if i.ind < len(rx):
i.rx = rx[i.ind - 1]
else:
i.rx = '0'
if i.ind < len(tx):
i.tx = tx[i.ind - 1]
else:
i.tx = '0'
else:
po.count = po.count - 1
cr.set_source_rgba(1.0, 0.0, 0.3, 1.0)
if po.pos == nodolist.current.pos:
cr.set_source_rgba(1.0, 1.0, 0.0, 1.0) # yellow
cr.move_to(400, 30)
cr.show_text('vm: ' + po.vm)
# Draw originators for curren nodo
if nodolist.run:
cr.set_source_rgba(1.0, 1.0, 1.0, 1.0)
cr.move_to(w - 251, 15)
cr.show_text("Originators")
cr.set_source_rgba(1.0, 1.0, 1.0, 1.0)
cr.move_to(w - 251 + 125, 15)
cr.show_text("Next Hop")
# o,n = po.get_originators_nexthop()
rg = len(o)
if rg > len(n):
rg = len(n)
for i in range(rg):
cr.set_source_rgba(0.0, 0.7, 0.7, 1.0)
if i & 0x01:
cr.set_source_rgba(0.0, 1.0, 1.0, 1.0)
cr.move_to(w - 251, 40 + i * 15)
cr.show_text(str(o[i]))
cr.move_to(w - 251 + 125, 40 + i * 15)
cr.show_text(str(n[i]))
# Drow Interface packets for curren nodo
for i in po.interfases:
if i.ind:
if i.ind < 4:
cr.move_to(200 * (i.ind - 1), 15)
cr.show_text(i.name + ' rx: ' + i.rx + ' tx: ' + i.tx)
if i.ind > 3:
cr.move_to(200 * (i.ind - 4), 30)
cr.show_text(i.name + ' rx: ' + i.rx + ' tx: ' + i.tx)
cr.set_source_rgba(0.3, 1.0, 0.3, 1.0)
# else:
# cr.set_source_rgba(0.1,0.6, 0.1,1.0)
if trace_l2 and str(po) in node_tr:
cr.set_source_rgba(1.0, 1.0, 1.0, 0.5)
cr.fill()
cr.stroke()
# Draw bat0 packets for each nodo
cr.set_source_rgb(0.0, 0.0, 0.1)
cr.move_to(p[0] * eh - 7, p[1] * ev + 5)
cr.show_text(str(po))
if nodolist.run:
cr.move_to(p[0] * eh - 30, p[1] * ev + 18)
cr.set_source_rgb(0.0, 1.0, 0.1)
cr.show_text('Rx:' + str(po.bat0.rx))
cr.move_to(p[0] * eh - 30, p[1] * ev - 13)
cr.show_text('Tx:' + str(po.bat0.tx))
cr.stroke()
if trace_l2:
x = -60
y = h - 36
cr.set_line_width(1.0)
for i in node_tr:
if len(i) == 2:
x = x + 80
if x > w - 301:
x = 20
y = y + 24
cr.set_source_rgba(0.0, 1.0, 0.0, 1.0)
cr.move_to(x + 12, y)
cr.arc(x, y, 12, 0, 2 * math.pi)
cr.move_to(x - 7, y + 5)
cr.show_text(i)
elif '.' in i:
cr.set_source_rgba(1.0, 1.0, 0.0, 1.0)
cr.move_to(x + 14, y + 5)
cr.show_text(i)
else:
cr.set_source_rgba(1.0, 0.0, 0.0, 1.0)
cr.move_to(x + 14, y + 5)
cr.show_text('too delay')
cr.stroke()
# Redraw the screen from the backing pixmap
def expose_event(widget, event):
ti = time.time()
dibujar(widget)
tf = time.time()
# print tf-ti
return False
def button_press_event(widget, event):
global inicio
w = widget.allocation.width
h = widget.allocation.height
eh = int((w - 260) / 9)
ev = int((h - 99) / 9)
if cr is not None:
inicio = near((event.x, event.y), eh, ev)
return True
def button_release_event(widget, event):
global wire_prop, trace_l2, node_tr, o, n
w = widget.allocation.width
h = widget.allocation.height
eh = int((w - 260) / 9)
ev = int((h - 99) / 9)
fin = near((event.x, event.y), eh, ev)
if fin[0] < 10 and fin[0] > 1 / 2 and fin[1] < 10 and fin[1] > 1 / 2:
if event.button == 1 and cr is not None:
if inicio == fin:
if not nodolist.run and not any(x.pos == inicio for x in nodolist):
nodolist.append(NodoClass(inicio))
nodolist.set_cur_pos(inicio)
elif any(x.pos == inicio for x in nodolist) and any(x.pos == fin for x in nodolist):
if nodolist.run and trace_l2:
for x in nodolist:
if x.pos == fin:
trace_fin_mac = str(x.bat0.mac)
if x.pos == inicio:
trace_nicio_ip = str(x.eth0.ip)
pos_ini = str(x)
l = []
mibr = netsnmp.Varbind('iso', '3.6.1.4.1.32.1.4', trace_fin_mac, 'OCTETSTR')
orig = netsnmp.snmpset(mibr, Version=2, DestHost=trace_nicio_ip, Community='private', Timeout=10000000, Retries=1)
mibr = netsnmp.Varbind('iso.3.6.1.4.1.32.1.4')
orig = netsnmp.snmpget(mibr, Version=2, DestHost=trace_nicio_ip, Community='private', Timeout=1000000, Retries=1)
for i in str(orig[0]).split():
l.append(i.split(':')[-1:])
node_tr = reduce(lambda x, y: x + y, l)
node_tr.insert(0, pos_ini)
else:
link_color24.current_wire = [(inicio, fin), (fin, inicio)]
link_color50.current_wire = [(inicio, fin), (fin, inicio)]
if wire_prop['ch'] == '24GHz':
if (not any(x.sd in link_color24.current_wire for x in link_color24)):
link_color24.append(WireClass(inicio, fin, wire_prop))
if nodolist.run:
link_color24.start()
link_color50.start()
if wire_prop['ch'] == '50GHz':
if (not any(x.sd in link_color50.current_wire for x in link_color50)):
link_color50.append(WireClass(inicio, fin, wire_prop))
if nodolist.run:
link_color24.start()
link_color50.start()
if event.button == 2 and cr is not None:
if inicio == fin:
if any(x.pos == inicio for x in nodolist):
nodolist.set_cur_pos(inicio)
if nodolist.run:
for x in nodolist:
if x.pos == fin:
o, n = x.get_originators_nexthop()
else:
link_color24.current_wire = [(inicio, fin), (fin, inicio)]
if wire_prop['ch'] == '24GHz':
if any(x.pos in [inicio, fin] for x in nodolist):
if any(x.sd in link_color24.current_wire for x in link_color24):
for x in link_color24:
if x.ds in link_color24.current_wire:
wire_prop = x.prop
link_color50.current_wire = [(inicio, fin), (fin, inicio)]
if wire_prop['ch'] == '50GHz':
if any(x.pos in [inicio, fin] for x in nodolist):
if any(x.sd in link_color50.current_wire for x in link_color50):
for x in link_color50:
if x.ds in link_color50.current_wire:
wire_prop = x.prop
elif event.button == 3 and cr is not None:
if inicio == fin:
if not nodolist.run:
if any(x.pos == inicio for x in nodolist):
for x in nodolist:
if x.pos == inicio:
nid = nodolist.index(x)
i = nodolist.pop(nid)
elif any(x.pos == inicio for x in nodolist) and any(x.pos == fin for x in nodolist):
if wire_prop['ch'] == '24GHz':
for x in link_color24:
if x.sd in [(inicio, fin), (fin, inicio)]:
lid = link_color24.index(x)
i = link_color24.pop(lid)
if wire_prop['ch'] == '50GHz':
for x in link_color50:
if x.sd in [(inicio, fin), (fin, inicio)]:
lid = link_color50.index(x)
i = link_color50.pop(lid)
dibujar(widget)
return True
def select_vm(signal):
window = gtk.Window()
window.connect('destroy', lambda w: select_vm)
window.set_title("SELECT VIRTUAL MACHINE")
combobox = gtk.combo_box_new_text()
window.add(combobox)
virtual_box_manager = vboxapi.VirtualBoxManager(None, None)
vbox = virtual_box_manager.vbox
vbox_vm_list = virtual_box_manager.getArray(vbox, 'machines')
vbox_name_list = [mach.name for mach in vbox_vm_list]
for i in vbox_name_list:
combobox.append_text(str(i))
combobox.connect('changed', changed_cb)
combobox.set_active(0)
window.set_position(gtk.WIN_POS_CENTER)
window.show_all()
return
def changed_cb(combobox):
global v_name_base
model = combobox.get_model()
index = combobox.get_active()
if index:
v_name_base = model[index][0]
return
def wire_show(signal):
Wire()
def menuitem_response():
return
def scale_set_default_values(scale):
scale.set_update_policy(gtk.UPDATE_CONTINUOUS)
scale.set_digits(1)
scale.set_value_pos(gtk.POS_TOP)
scale.set_draw_value(True)
def on_changed(widget):
global wire_prop
val = widget.get_value()
name = widget.get_name()
wire_prop[name] = int(val)
def callback(self, button):
global wire_prop
wire_prop['ch'] = button
class Wire(gtk.Window):
def __init__(self):
super(Wire, self).__init__()
self.set_size_request(400, 700)
self.set_border_width(10)
self.set_title("WIREFILTER SETUP")
self.connect("delete_event", lambda w, e: self.destroy())
vbox_app = gtk.VBox(False, 0)
self.add(vbox_app)
vbox_app.show()
vbox1 = gtk.VBox(False, 0)
label1 = gtk.Label("Percentage of loss: ")
vbox1.pack_start(label1, True, True, 0)
label1.show()
adj1 = gtk.Adjustment(wire_prop['lo'], 0.0, 101.0, 1.0, 1.0, 1.0)
vscale1 = gtk.HScale(adj1)
scale_set_default_values(vscale1)
vscale1.set_name('lo')
vbox1.pack_start(vscale1, True, True, 0)
vscale1.connect("value-changed", on_changed)
vscale1.show()
label1 = gtk.Label("Extra delay in milliseconds: ")
vbox1.pack_start(label1, True, True, 0)
label1.show()
adj2 = gtk.Adjustment(wire_prop['de'], 0.0, 1001.0, 1.0, 1.0, 1.0)
vscale2 = gtk.HScale(adj2)
scale_set_default_values(vscale2)
vscale2.set_name('de')
vbox1.pack_start(vscale2, True, True, 0)
vscale2.connect("value-changed", on_changed)
vscale2.show()
label1 = gtk.Label("dup percentage of dup packet: ")
vbox1.pack_start(label1, True, True, 0)
label1.show()
adj3 = gtk.Adjustment(wire_prop['du'], 0.0, 101.0, 1.0, 1.0, 1.0)
vscale3 = gtk.HScale(adj3)
scale_set_default_values(vscale3)
vscale3.set_name('du')
vbox1.pack_start(vscale3, True, True, 0)
vscale3.connect("value-changed", on_changed)
vscale3.show()
label1 = gtk.Label("Channel bandwidth in Bytes/sec: ")
vbox1.pack_start(label1, True, True, 0)
label1.show()
adj4 = gtk.Adjustment(wire_prop['bw'], 0.0, 1001.0, 1.0, 1.0, 1.0)
vscale4 = gtk.HScale(adj4)
scale_set_default_values(vscale4)
vscale4.set_name('bw')
vbox1.pack_start(vscale4, True, True, 0)
vscale4.connect("value-changed", on_changed)
vscale4.show()
label1 = gtk.Label("Interface speed in Bytes/sec: ")
vbox1.pack_start(label1, True, True, 0)
label1.show()
adj5 = gtk.Adjustment(wire_prop['sp'], 0.0, 1001.0, 1.0, 1.0, 1.0)
vscale5 = gtk.HScale(adj5)
scale_set_default_values(vscale5)
vscale5.set_name('sp')
vbox1.pack_start(vscale5, True, True, 0)
vscale5.connect("value-changed", on_changed)
vscale5.show()
label1 = gtk.Label("Channel capacity in Bytes: ")
vbox1.pack_start(label1, True, True, 0)
label1.show()
adj6 = gtk.Adjustment(wire_prop['ca'], 0.0, 1001.0, 1.0, 1.0, 1.0)
vscale6 = gtk.HScale(adj6)
scale_set_default_values(vscale6)
vscale6.set_name('ca')
vbox1.pack_start(vscale6, True, True, 0)
vscale6.connect("value-changed", on_changed)
vscale6.show()
label1 = gtk.Label("Number bits damaged/Megabyte: ")
vbox1.pack_start(label1, True, True, 0)
label1.show()
adj7 = gtk.Adjustment(wire_prop['da'], 0.0, 101.0, 1.0, 1.0, 1.0)
vscale7 = gtk.HScale(adj7)
scale_set_default_values(vscale7)
vscale7.set_name('da')
vbox1.pack_start(vscale7, True, True, 0)
vscale7.connect("value-changed", on_changed)
vscale7.show()
hbox1 = gtk.HBox(gtk.FALSE, 0)
hbox1.set_border_width(10)
vbox1.pack_start(hbox1, gtk.TRUE, gtk.TRUE, 0)
hbox1.show()
button = gtk.RadioButton(None, "2.4 GHz")
button.connect("toggled", callback, "24GHz")
if wire_prop['ch'] == "24GHz":
button.set_active(gtk.TRUE)
hbox1.pack_start(button, gtk.TRUE, gtk.TRUE, 0)
button.show()
button = gtk.RadioButton(button, "5.0 GHz")
button.connect("toggled", callback, "50GHz")
if wire_prop['ch'] == "50GHz":
button.set_active(gtk.TRUE)
hbox1.pack_start(button, gtk.TRUE, gtk.TRUE, 0)
button.show()
button_set = gtk.Button(stock=gtk.STOCK_OK)
button_set.connect("clicked", lambda w: self.destroy())
button_set.set_flags(gtk.CAN_DEFAULT)
hbox1.pack_start(button_set, True, True, 0)
button_set.show()
button_close = gtk.Button(stock=gtk.STOCK_CLOSE)
button_close.connect("clicked", lambda w: self.destroy())
button_close.set_flags(gtk.CAN_DEFAULT)
hbox1.pack_start(button_close, True, True, 0)
button_close.show()
vbox1.show()
vbox_app.add(vbox1)
button_close.grab_default()
self.set_position(gtk.WIN_POS_CENTER)
self.show()
def get_mesh(dir_trabajo):
global nodolist, link_color24, link_color50
dm = dir_trabajo + '/data.ms'
if os.path.isfile('data.ms'):
with open(dm, 'rb') as f:
nodolist, link_color24, link_color50 = pickle.load(f)
def create_colorfull(dir_trabajo):
f = open(dir_trabajo + '/colourful.rc', 'w')
f.write('port/setcolourful 1\n')
f.write('port/create 1\n')
f.write('port/create 2\n')
f.write('port/create 3\n')
f.write('port/create 4\n')
f.write('port/create 5\n')
f.write('port/setcolour 1 1\n')
f.write('port/setcolour 2 2\n')
f.write('port/setcolour 3 2\n')
f.close()
class MenuApp(gtk.Window):
def __init__(self):
super(MenuApp, self).__init__()
screen = self.get_screen()
self.set_title("Mesh network emulator")
self.set_size_request(min(screen.get_width(), 800),
min(screen.get_height(), 600))
# self.maximize()
self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(6400, 6400, 6440))
self.set_position(gtk.WIN_POS_CENTER)
# top level menu bar
menubar = gtk.MenuBar()
# top items on the menu bar
filem = gtk.MenuItem("File")
editm = gtk.MenuItem("Edit")
runm = gtk.MenuItem("Run/Stop")
toolsm = gtk.MenuItem("Tools")
aboutm = gtk.MenuItem("About")
# now, create for FILE item the menu
filemenu = gtk.Menu()
filem.set_submenu(filemenu)
# create the items for File menu
new = gtk.MenuItem("New")
filemenu.append(new)
new.connect("activate", select_folder)
open = gtk.MenuItem("Open")
filemenu.append(open)
open.connect("activate", open_mesh)
save = gtk.MenuItem("Save")
filemenu.append(save)
save.connect("activate", save_mesh)
saveas = gtk.MenuItem("Save as")
filemenu.append(saveas)
saveas.connect("activate", save_as_mesh)