├── .gitignore
├── README.md
├── figures
├── Untitled.png
├── edit.png
├── example.png
├── menuedit.png
├── menufile.png
├── mesh.png
├── pass.png
├── ping.png
├── run.png
├── vde2c.png
├── vm.png
├── wire.png
└── wireshark.png
├── install.sh
├── openwrt
├── config.sh
├── rc.local
├── snmp.tar
└── snmp
│ ├── batctl_n.sh
│ ├── batctl_o.sh
│ ├── batctl_tg.sh
│ └── batctl_tr.sh
├── openwrtv12.ova
├── openwrtv14.ova
├── simmeshv12.py
├── simmeshv13.py
└── vde2-2.3.2-patch.tar
/.gitignore:
--------------------------------------------------------------------------------
1 | *.ms
2 | *~
3 | *.swp
4 | colourful.rc
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Network Mesh emulator
2 | =====================
3 |
4 | This is a network Mesh emulator with batman-adv. Is written in python and work with Virtualbox and vde-switch.
5 |
6 | ####Key features:
7 |
8 | - Its possible to build topologies to 81 nodes.
9 | - Each node can be a different virtual machine.
10 | - Compatibility with Wireshark.
11 | - Its possible change the links properties while the emulation is running.
12 | - Easy access to each virtual machine.
13 |
14 | ####Prerequisites
15 |
16 | - Linux (developed on Ubuntu 14.08)
17 | - Python 2.7
18 | - VirtualBox.
19 | - OpenWrt.
20 | - vde-switch.
21 | - vde_switch colour patch.
22 | - python library pygtk, gobject, cairo,math, pickle os, netsnmp, time and vboxapi.
23 |
24 | ####Installation
25 |
26 | 1. Install all of the necessary Python modules listed above. Many of them are available via pip and/or apt-get.
27 | 2. Install Virtualbox.
28 | 3. Add a Host-only Network (vboxnet0) in Virtualbox -> Preferences -> Network
29 | 4. Install vde_switch with the patch.
30 | 5. Import the provided OpenWrt virtual machine (openwrt.ova).
31 | 6. Run the program $>python simmeshv11.py
32 |
33 | ####Basic usage
34 |
35 | Read the wiki Emulator Manual.
36 |
37 | ####Example.
38 |
39 | In this example one can view five networks of nine nodes each one with links in 2.4 GHz band and connected the five network with links of 5.0 GHz Band.
40 |
41 | 
42 |
43 | In the right of the screen there are the originators and next hope list for the node number 66.
44 |
45 | In the next figure is shown the node 66 making a ping to node number 11, the times are good.
46 |
47 | 
48 |
49 | In the last figure is shown the cpu and memory usage for 36 nodes running together.
50 |
51 | 
52 |
--------------------------------------------------------------------------------
/figures/Untitled.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dbritos/Network-mesh-emulator/c2eb1d1c279d61b66fa9bc280f942fc2d15d1462/figures/Untitled.png
--------------------------------------------------------------------------------
/figures/edit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dbritos/Network-mesh-emulator/c2eb1d1c279d61b66fa9bc280f942fc2d15d1462/figures/edit.png
--------------------------------------------------------------------------------
/figures/example.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dbritos/Network-mesh-emulator/c2eb1d1c279d61b66fa9bc280f942fc2d15d1462/figures/example.png
--------------------------------------------------------------------------------
/figures/menuedit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dbritos/Network-mesh-emulator/c2eb1d1c279d61b66fa9bc280f942fc2d15d1462/figures/menuedit.png
--------------------------------------------------------------------------------
/figures/menufile.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dbritos/Network-mesh-emulator/c2eb1d1c279d61b66fa9bc280f942fc2d15d1462/figures/menufile.png
--------------------------------------------------------------------------------
/figures/mesh.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dbritos/Network-mesh-emulator/c2eb1d1c279d61b66fa9bc280f942fc2d15d1462/figures/mesh.png
--------------------------------------------------------------------------------
/figures/pass.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dbritos/Network-mesh-emulator/c2eb1d1c279d61b66fa9bc280f942fc2d15d1462/figures/pass.png
--------------------------------------------------------------------------------
/figures/ping.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dbritos/Network-mesh-emulator/c2eb1d1c279d61b66fa9bc280f942fc2d15d1462/figures/ping.png
--------------------------------------------------------------------------------
/figures/run.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dbritos/Network-mesh-emulator/c2eb1d1c279d61b66fa9bc280f942fc2d15d1462/figures/run.png
--------------------------------------------------------------------------------
/figures/vde2c.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dbritos/Network-mesh-emulator/c2eb1d1c279d61b66fa9bc280f942fc2d15d1462/figures/vde2c.png
--------------------------------------------------------------------------------
/figures/vm.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dbritos/Network-mesh-emulator/c2eb1d1c279d61b66fa9bc280f942fc2d15d1462/figures/vm.png
--------------------------------------------------------------------------------
/figures/wire.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dbritos/Network-mesh-emulator/c2eb1d1c279d61b66fa9bc280f942fc2d15d1462/figures/wire.png
--------------------------------------------------------------------------------
/figures/wireshark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dbritos/Network-mesh-emulator/c2eb1d1c279d61b66fa9bc280f942fc2d15d1462/figures/wireshark.png
--------------------------------------------------------------------------------
/install.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | file="virtualbox-5.0_5.0.0-101573~Ubuntu~trusty_amd64.deb"
3 | if [ -e ${PWD}/$file ];
4 | then echo "existe" ${PWD}/$file
5 | else wget -c http://download.virtualbox.org/virtualbox/5.0.0/virtualbox-5.0_5.0.0-101573~Ubuntu~trusty_amd64.deb
6 | fi
7 | apt-get -y install libsdl1.2debian
8 | dpkg --install virtualbox-5.0_5.0.0-101573~Ubuntu~trusty_amd64.deb
9 | apt-get -y install snmp
10 | tar -xf vde2-2.3.2-patch.tar
11 | cd vde2-2.3.2-patch
12 | ./configure
13 | make
14 | make install
15 | cd ..
16 | apt-get -y install libvdeplug2
17 | apt-get -y install python2.7
18 | apt-get -y install python-gtk2-dev
19 | apt-get -y install python-gobject
20 | apt-get -y install python-cairo
21 | apt-get -y install python-netsnmp
22 | apt-get -y remove libvdeplug2
23 | apt-get -y install libvdeplug2
24 | VBoxManage import openwrtv12.ova
25 |
26 |
27 |
--------------------------------------------------------------------------------
/openwrt/config.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | route add default gw $1
3 | echo "nameserver" $1>/etc/resolv.conf
4 | #install packages
5 | opkg update
6 | opkg install kernel
7 | opkg install snmpd
8 | opkg install ip
9 | opkg install kmod-batman-adv
10 | opkg install batctl
11 | cp ./rc.local /etc/rc.local
12 | #Enable SNMP daemon
13 | /etc/init.d/snmpd restart
14 | echo 'Configuring and starting snmpd'
15 |
16 | uci delete snmpd.private
17 | uci delete snmpd.public
18 | uci commit snmpd
19 |
20 | uci set snmpd.@agent[0].agentaddress='UDP:161,UDP6:161'
21 | uci add snmpd public
22 | uci set snmpd.public=com2sec
23 | uci set snmpd.public.secname=rw
24 | uci set snmpd.public.source=192.168.0.0/16
25 | uci set snmpd.public.community=public
26 | uci commit snmpd
27 | uci add snmpd private
28 | uci set snmpd.private=com2sec
29 | uci set snmpd.private.secname=rw
30 | uci set snmpd.private.source=192.168.0.0/16
31 | uci set snmpd.private.community=private
32 | uci commit snmpd
33 | uci add snmpd com2sec6
34 | uci set snmpd.@com2sec6[-1].secname=rw
35 | uci set snmpd.@com2sec6[-1].source=default
36 | uci set snmpd.@com2sec6[-1].community=public
37 | uci commit snmpd
38 | uci add snmpd com2sec6
39 | uci set snmpd.@com2sec6[-1].secname=rw
40 | uci set snmpd.@com2sec6[-1].source=default
41 | uci set snmpd.@com2sec6[-1].community=private
42 | uci commit snmpd
43 |
44 | uci add snmpd pass
45 | uci set snmpd.@pass[-1].miboid=.1.3.6.1.4.1.32.1.1
46 | uci set snmpd.@pass[-1].prog=/root/snmp/batctl_o.sh
47 | uci commit snmpd
48 | uci add snmpd pass
49 | uci set snmpd.@pass[-1].miboid=.1.3.6.1.4.1.32.1.2
50 | uci set snmpd.@pass[-1].prog=/root/snmp/batctl_n.sh
51 | uci commit snmpd
52 | uci add snmpd pass
53 | uci set snmpd.@pass[-1].miboid=.1.3.6.1.4.1.32.1.3
54 | uci set snmpd.@pass[-1].prog=/root/snmp/batctl_tg.sh
55 | uci commit snmpd
56 | uci add snmpd pass
57 | uci set snmpd.@pass[-1].miboid=.1.3.6.1.4.1.32.1.4
58 | uci set snmpd.@pass[-1].prog=/root/snmp/batctl_tr.sh
59 | uci commit snmpd
60 | /etc/init.d/snmpd restart
61 | /etc/init.d/snmpd enable
62 | /etc/init.d/snmpd restart
63 |
64 |
--------------------------------------------------------------------------------
/openwrt/rc.local:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # kill default openwrt network config
3 | RED=$(ifconfig eth1 | sed '1,1!d' | sed 's/.*HWaddr //'| sed 's/.\{11\}://'| sed 's/.\{5\}$//')
4 | NUM=$(ifconfig eth1 | sed '1,1!d' | sed 's/.*HWaddr //'| sed 's/.*://'| sed 's/[\n\ ].*//')
5 | ifconfig br-lan down
6 | brctl delbr br-lan
7 | ip link delete eth0
8 | ip addr add 192.168.100.$NUM/24 dev eth0
9 | ip link set dev eth1 mtu 1500 up
10 | ip link set dev eth2 mtu 1500 up
11 | batctl -m bat0 interface add eth1
12 | batctl -m bat0 interface add eth2
13 | ip addr add 192.168.$RED.$NUM/24 dev bat0
14 | ip link set dev bat0 address 90:$NUM:$NUM:$NUM:$NUM:$NUM
15 | ip link set dev bat0 up
16 | batctl -m bat0 originators
17 | /etc/init.d/snmpd enable
18 | /etc/init.d/snmpd restart
19 |
--------------------------------------------------------------------------------
/openwrt/snmp.tar:
--------------------------------------------------------------------------------
1 | config.sh 0000775 0001750 0001750 00000003400 12556471571 012574 0 ustar dbritos dbritos #!/bin/sh
2 | route add default gw $1
3 | echo "nameserver" $1>/etc/resolv.conf
4 | #install packages
5 | opkg update
6 | opkg install kernel
7 | opkg install snmpd
8 | opkg install ip
9 | opkg install kmod-batman-adv
10 | opkg install batctl
11 | cp ./rc.local /etc/rc.local
12 | #Enable SNMP daemon
13 | /etc/init.d/snmpd restart
14 | echo 'Configuring and starting snmpd'
15 |
16 | uci delete snmpd.private
17 | uci delete snmpd.public
18 | uci commit snmpd
19 |
20 | uci set snmpd.@agent[0].agentaddress='UDP:161,UDP6:161'
21 | uci add snmpd public
22 | uci set snmpd.public=com2sec
23 | uci set snmpd.public.secname=rw
24 | uci set snmpd.public.source=192.168.0.0/16
25 | uci set snmpd.public.community=public
26 | uci commit snmpd
27 | uci add snmpd private
28 | uci set snmpd.private=com2sec
29 | uci set snmpd.private.secname=rw
30 | uci set snmpd.private.source=192.168.0.0/16
31 | uci set snmpd.private.community=private
32 | uci commit snmpd
33 | uci add snmpd com2sec6
34 | uci set snmpd.@com2sec6[-1].secname=rw
35 | uci set snmpd.@com2sec6[-1].source=default
36 | uci set snmpd.@com2sec6[-1].community=public
37 | uci commit snmpd
38 | uci add snmpd com2sec6
39 | uci set snmpd.@com2sec6[-1].secname=rw
40 | uci set snmpd.@com2sec6[-1].source=default
41 | uci set snmpd.@com2sec6[-1].community=private
42 | uci commit snmpd
43 |
44 | uci add snmpd pass
45 | uci set snmpd.@pass[-1].miboid=.1.3.6.1.4.1.32.1.1
46 | uci set snmpd.@pass[-1].prog=/root/snmp/batctl_o.sh
47 | uci commit snmpd
48 | uci add snmpd pass
49 | uci set snmpd.@pass[-1].miboid=.1.3.6.1.4.1.32.1.2
50 | uci set snmpd.@pass[-1].prog=/root/snmp/batctl_n.sh
51 | uci commit snmpd
52 | uci add snmpd pass
53 | uci set snmpd.@pass[-1].miboid=.1.3.6.1.4.1.32.1.3
54 | uci set snmpd.@pass[-1].prog=/root/snmp/batctl_tg.sh
55 | uci commit snmpd
56 | uci add snmpd pass
57 | uci set snmpd.@pass[-1].miboid=.1.3.6.1.4.1.32.1.4
58 | uci set snmpd.@pass[-1].prog=/root/snmp/batctl_tr.sh
59 | uci commit snmpd
60 | /etc/init.d/snmpd restart
61 | /etc/init.d/snmpd enable
62 | /etc/init.d/snmpd restart
63 |
64 | rc.local 0000775 0001750 0001750 00000001246 12556546575 012430 0 ustar dbritos dbritos #!/bin/sh
65 | # kill default openwrt network config
66 | RED=$(ifconfig eth1 | sed '1,1!d' | sed 's/.*HWaddr //'| sed 's/.\{11\}://'| sed 's/.\{5\}$//')
67 | NUM=$(ifconfig eth1 | sed '1,1!d' | sed 's/.*HWaddr //'| sed 's/.*://'| sed 's/[\n\ ].*//')
68 | ifconfig br-lan down
69 | brctl delbr br-lan
70 | ip link delete eth0
71 | ip addr add 192.168.100.$NUM/24 dev eth0
72 | ip link set dev eth1 mtu 1500 up
73 | ip link set dev eth2 mtu 1500 up
74 | batctl -m bat0 interface add eth1
75 | batctl -m bat0 interface add eth2
76 | ip addr add 192.168.$RED.$NUM/24 dev bat0
77 | ip link set dev bat0 address 90:$NUM:$NUM:$NUM:$NUM:$NUM
78 | ip link set dev bat0 up
79 | batctl -m bat0 originators
80 | /etc/init.d/snmpd enable
81 | /etc/init.d/snmpd restart
82 | snmp/ 0000775 0001750 0001750 00000000000 12556015660 011741 5 ustar dbritos dbritos snmp/batctl_tr.sh 0000775 0001750 0001750 00000000567 12554335053 014265 0 ustar dbritos dbritos #!/bin/sh
83 | if test "$1" = '-s' ;
84 | then
85 |
86 | BAT=$(batctl tr $4 | sed -n 's/.*\(..:..:..:..:..:..\)[ ,\*]\+\([0-9][0-9]*\.[0-9][0-9]*\).*/\2 \1/p')
87 | echo $BAT > trace
88 | exit
89 | elif test "$1" = '-g' ;
90 | then
91 | BAT=$(cat trace)
92 | echo $2
93 | echo "string"
94 | echo $BAT
95 | fi
96 |
97 |
98 | snmp/batctl_n.sh 0000755 0001750 0001750 00000000372 12552730040 014056 0 ustar dbritos dbritos #!/bin/sh
99 | if test "$1" = '-s' ;
100 | then
101 | exit
102 | elif test "$1" = '-g' ;
103 | then
104 | BAT=$(batctl o | sed -n 's/^\(..:..:..:..:..:..\).* \(..:..:..:..:..:..\).*/\1 \2/p')
105 | echo $2
106 | echo "string"
107 | echo $BAT
108 | fi
109 |
110 | snmp/batctl_o.sh 0000755 0001750 0001750 00000000337 12552265605 014072 0 ustar dbritos dbritos #!/bin/sh
111 | if test "$1" = '-s' ;
112 | then
113 | exit
114 | elif test "$1" = '-g' ;
115 | then
116 | BAT=$(batctl o | sed -n 's/^\(..:..:..:..:..:..\).*/\1/p')
117 | echo $2
118 | echo "string"
119 | echo $BAT
120 | fi
121 |
122 | snmp/batctl_tg.sh 0000755 0001750 0001750 00000000374 12552265574 014254 0 ustar dbritos dbritos #!/bin/sh
123 | if test "$1" = '-s' ;
124 | then
125 | exit
126 | elif test "$1" = '-g' ;
127 | then
128 | BAT=$(batctl tg | sed -n 's/.*\(..:..:..:..:..:..\).* \(..:..:..:..:..:..\).*/\1 \2/p')
129 | echo $2
130 | echo "string"
131 | echo $BAT
132 | fi
133 |
134 |
--------------------------------------------------------------------------------
/openwrt/snmp/batctl_n.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | if test "$1" = '-s' ;
3 | then
4 | exit
5 | elif test "$1" = '-g' ;
6 | then
7 | BAT=$(batctl o | sed -n 's/^\(..:..:..:..:..:..\).* \(..:..:..:..:..:..\).*/\1 \2/p')
8 | echo $2
9 | echo "string"
10 | echo $BAT
11 | fi
12 |
13 |
--------------------------------------------------------------------------------
/openwrt/snmp/batctl_o.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | if test "$1" = '-s' ;
3 | then
4 | exit
5 | elif test "$1" = '-g' ;
6 | then
7 | BAT=$(batctl o | sed -n 's/^\(..:..:..:..:..:..\).*/\1/p')
8 | echo $2
9 | echo "string"
10 | echo $BAT
11 | fi
12 |
13 |
--------------------------------------------------------------------------------
/openwrt/snmp/batctl_tg.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | if test "$1" = '-s' ;
3 | then
4 | exit
5 | elif test "$1" = '-g' ;
6 | then
7 | BAT=$(batctl tg | sed -n 's/.*\(..:..:..:..:..:..\).* \(..:..:..:..:..:..\).*/\1 \2/p')
8 | echo $2
9 | echo "string"
10 | echo $BAT
11 | fi
12 |
13 |
--------------------------------------------------------------------------------
/openwrt/snmp/batctl_tr.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | if test "$1" = '-s' ;
3 | then
4 |
5 | BAT=$(batctl tr $4 | sed -n 's/.*\(..:..:..:..:..:..\)[ ,\*]\+\([0-9][0-9]*\.[0-9][0-9]*\).*/\2 \1/p')
6 | echo $BAT > trace
7 | exit
8 | elif test "$1" = '-g' ;
9 | then
10 | BAT=$(cat trace)
11 | echo $2
12 | echo "string"
13 | echo $BAT
14 | fi
15 |
16 |
17 |
--------------------------------------------------------------------------------
/openwrtv12.ova:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dbritos/Network-mesh-emulator/c2eb1d1c279d61b66fa9bc280f942fc2d15d1462/openwrtv12.ova
--------------------------------------------------------------------------------
/openwrtv14.ova:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dbritos/Network-mesh-emulator/c2eb1d1c279d61b66fa9bc280f942fc2d15d1462/openwrtv14.ova
--------------------------------------------------------------------------------
/simmeshv12.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | import pygtk
4 | pygtk.require('2.0')
5 | import gtk
6 | import gobject
7 | import math
8 | import pickle
9 | import os
10 | import netsnmp
11 | import time
12 | import vboxapi
13 |
14 | dir_trabajo = ''
15 | wire_prop = {'lo': 0, 'de': 0, 'du': 0, 'bw': 0, 'sp': 0,
16 | 'ca': 0, 'da': 0, 'ch': '24GHz'}
17 | password = ''
18 | v_name_base = 'openwrtv12'
19 | trace_l2 = False
20 | node_tr = []
21 | node_head = ''
22 | o = []
23 | n = []
24 |
25 |
26 | class LinkList(list):
27 | def __init__(self):
28 | self.ll = []
29 | self.current_wire = None
30 |
31 | def stop(self):
32 | os.system('killall -q wirefilter')
33 | for x in self:
34 | x.stop()
35 |
36 | def start(self):
37 | for x in self:
38 | x.start()
39 |
40 | def set_current_wire(self, sdds):
41 | for x in self:
42 | if x.sd in sdds:
43 | self.current_wire = sdds
44 |
45 |
46 | class NodoList(list):
47 | def __init__(self):
48 | self.nl = []
49 | self.current = None
50 | self.run = False
51 |
52 | def set_current(self, no):
53 | self.current = no
54 |
55 | def set_cur_pos(self, pos):
56 | for x in self:
57 | if x.pos == pos:
58 | self.current = x
59 |
60 | def stop(self):
61 | for x in self:
62 | x.stop()
63 | self.run = False
64 |
65 | def start(self):
66 | for x in self:
67 | x.start()
68 | self.run = True
69 |
70 | link_color24 = LinkList()
71 | link_color50 = LinkList()
72 | nodolist = NodoList()
73 |
74 |
75 | class Interface(object):
76 | def __init__(self, indice, name, nodonum, oamip):
77 | self.ind = indice
78 | self.name = name
79 | self.oamip = oamip
80 | self.ifpresent = False
81 | self.rx = '0'
82 | self.tx = '0'
83 | self.ip = {'tapwrt': '192.168.' + nodonum + '.1',
84 | 'oam': '192.168.100.' + nodonum,
85 | 'lo': None,
86 | 'eth0': '192.168.100.' + nodonum,
87 | 'eth1': None,
88 | 'eth2': None,
89 | 'bat0': '192.168.7.' + nodonum, }[name]
90 | self.mac = {'tapwrt': None,
91 | 'oam': None,
92 | 'lo': None,
93 | 'eth0': '80:01:00:00:07:' + nodonum,
94 | 'eth1': '80:02:00:00:07:' + nodonum,
95 | 'eth2': '80:05:00:00:07:' + nodonum,
96 | 'bat0': '90:' + nodonum + ':' + nodonum + ':' + nodonum +
97 | ':' + nodonum + ':' + nodonum}[name]
98 |
99 | def __str__(self):
100 | return str(self.name)
101 |
102 |
103 | class NodoClass(object):
104 | def __init__(self, p):
105 | self.pos = p
106 | self.num = int((p[0] // 100) * 10 + p[1] // 100)
107 | self.name = 'wrt' + str(self.num)
108 | self.octet_str = str(self.num)
109 | self.smp_ip = '192.168.100.' + str(self)
110 | self.oam = Interface(None, 'oam', str(self), self.smp_ip)
111 | self.tapwrt = Interface(None, 'tapwrt', str(self), self.smp_ip)
112 | self.lo = Interface(1, 'lo', str(self), self.smp_ip)
113 | self.eth0 = Interface(2, 'eth0', str(self), self.smp_ip)
114 | self.eth1 = Interface(3, 'eth1', str(self), self.smp_ip)
115 | self.eth2 = Interface(4, 'eth2', str(self), self.smp_ip)
116 | self.bat0 = Interface(5, 'bat0', str(self), self.smp_ip)
117 | <<<<<<< HEAD
118 | self.interfases = [self.tapwrt, self.oam, self.lo, self.eth0,
119 | self.eth1, self.eth2, self.bat0]
120 | =======
121 | self.interfaces = [self.tapwrt, self.oam, self.lo, self.eth0, self.eth1, self.eth2, self.bat0]
122 | >>>>>>> f5e62b78799f1cf4662b5edfd3edaef3a6eb5d09
123 | self.originator_nexthop = ['None'], ['None']
124 | self.vm = v_name_base
125 | self.load_average = '0.00'
126 | self.count = 0
127 | self.running = False
128 |
129 | def __str__(self):
130 | return str(self.num)
131 |
132 | def __del__(self):
133 | self.stop()
134 |
135 | def stop(self):
136 | if self.running:
137 | os.system('echo ' + password + ' | sudo -S rm -rf /tmp/24GHz' +
138 | self.octet_str)
139 | os.system('echo ' + password + ' | sudo -S rm -rf /tmp/50GHz' +
140 | self.octet_str)
141 | os.system('echo ' + password + ' | sudo -S ip addr del ' +
142 | self.tapwrt.ip + '/24 dev tap24GHz' + self.octet_str)
143 | os.system('echo ' + password + ' | sudo -S ip link delete tap24GHz' + self.octet_str)
144 | os.system('echo ' + password + ' | sudo -S ip addr del ' + self.tapwrt.ip + '/24 dev tap50GHz' + self.octet_str)
145 | os.system('echo ' + password + ' | sudo -S ip link delete tap50GHz' + self.octet_str)
146 | os.system('VBoxManage controlvm num' + self.octet_str + ' poweroff')
147 | time.sleep(1)
148 | os.system('VBoxManage unregistervm --delete num' + self.octet_str)
149 | os.system('killall -q vde_switch')
150 | self.running = False
151 |
152 | def get_originators_nexthop(self):
153 | host = self.smp_ip
154 | mibr = netsnmp.Varbind('iso.3.6.1.4.1.32.1.2')
155 | orig = netsnmp.snmpget(mibr, Version=2, DestHost=host, Community='public', Timeout=50000, Retries=3)
156 | on = str(orig[0]).split()
157 | return on[::2], on[1::2]
158 |
159 | def start(self):
160 | if not self.running:
161 | os.system('echo ' + password + ' | sudo -S ip tuntap add tap24GHz' + self.octet_str + ' mode tap')
162 | os.system('echo ' + password + ' | sudo -S ifconfig tap24GHz' + self.octet_str + ' ' + self.tapwrt.ip + ' up')
163 | os.system('echo ' + password + ' | sudo -S ip tuntap add tap50GHz' + self.octet_str + ' mode tap')
164 | os.system('echo ' + password + ' | sudo -S ifconfig tap50GHz' + self.octet_str + ' ' + self.tapwrt.ip + ' up')
165 | os.system('vde_switch -d --hub -s /tmp/24GHz' + self.octet_str + ' -tap tap24GHz' + self.octet_str + ' -m 666 -f ' + dir_trabajo + '/colourful.rc')
166 | os.system('vde_switch -d --hub -s /tmp/50GHz' + self.octet_str + ' -tap tap50GHz' + self.octet_str + ' -m 666 -f ' + dir_trabajo + '/colourful.rc')
167 | os.system('VBoxManage clonevm ' + self.vm + ' --name num' + self.octet_str + ' --register')
168 | os.system('VBoxManage modifyvm num' + self.octet_str + ' --nic1 hostonly --hostonlyadapter1 vboxnet0 --macaddress1 ' + str(self.eth0.mac).translate(None, ':'))
169 | 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, ':'))
170 | 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, ':'))
171 | os.system('VBoxManage startvm num' + self.octet_str + node_head) # + '--type headless'
172 | self.running = True
173 |
174 |
175 | class WireClass(object):
176 | def __init__(self, src, dst, quality):
177 | self.s = src
178 | self.d = dst
179 | self.sd = src, dst
180 | self.ds = dst, src
181 | self.quality = quality
182 | self.s_str = str(point2num(self.s))
183 | self.d_str = str(point2num(self.d))
184 | self.name = "wire" + self.s_str + '-' + self.d_str
185 | self.canal = self.quality['ch']
186 | self.running = False
187 | self.prop = {'lo': self.quality['lo'],
188 | 'de': self.quality['de'],
189 | 'du': self.quality['du'],
190 | 'bw': self.quality['bw'],
191 | 'sp': self.quality['sp'],
192 | 'ca': self.quality['ca'],
193 | 'da': self.quality['da'],
194 | 'ch': self.quality['ch']}
195 |
196 | def __del__(self):
197 | if nodolist.run:
198 | link_color24.stop()
199 | link_color50.stop()
200 | link_color24.start()
201 | link_color50.start()
202 |
203 | def start(self):
204 | if not self.running:
205 | od = 'wirefilter' + ' --daemon -v /tmp/' + self.canal + self.s_str + ':/tmp/' + self.canal + self.d_str
206 | if self.prop['lo'] != 0:
207 | od = od + ' -l ' + str(self.prop['lo'])
208 | if self.prop['de'] != 0:
209 | od = od + ' -d ' + str(self.prop['de']) + '+' + str(self.prop['de'] / 2) + 'N'
210 | if self.prop['du'] != 0:
211 | od = od + ' -D ' + str(self.prop['du'])
212 | if self.prop['bw'] != 0:
213 | od = od + ' -b ' + str(self.prop['bw'])
214 | if self.prop['sp'] != 0:
215 | od = od + ' -s ' + str(self.prop['sp'])
216 | if self.prop['ca'] != 0:
217 | od = od + ' -c ' + str(self.prop['ca'])
218 | if self.prop['da'] != 0:
219 | od = od + ' -n ' + str(self.prop['da'])
220 | os.system(od)
221 | self.running = True
222 |
223 | def stop(self):
224 | self.running = False
225 |
226 |
227 | def traceon(signal):
228 | global trace_l2, node_tr
229 | node_tr = []
230 | if signal.active:
231 | trace_l2 = True
232 | else:
233 | trace_l2 = False
234 |
235 |
236 | def headon(signal):
237 | global node_head
238 | if signal.active:
239 | node_head = ' --type headless'
240 | else:
241 | node_head = ''
242 |
243 |
244 | def point2num(point):
245 | return int((point[0] // 100) * 10 + point[1] // 100)
246 |
247 |
248 | # set point close to grid node
249 | def near(punto):
250 | x, y = punto
251 | xi, xd = divmod(x, 100)
252 | yi, yd = divmod(y, 100)
253 | if xd > 50:
254 | if xi < 10:
255 | xi = xi + 1
256 | if yd > 50:
257 | yi = yi + 1
258 | return xi * 100, yi * 100
259 |
260 |
261 | def open_mesh(widget):
262 | global link_color24, link_color50, nodolist
263 | if not nodolist.run:
264 | dialog = gtk.FileChooserDialog(
265 | title="Select a mesh file",
266 | parent=None,
267 | action=gtk.FILE_CHOOSER_ACTION_OPEN,
268 | buttons=(gtk.STOCK_CANCEL,
269 | gtk.RESPONSE_CANCEL,
270 | gtk.STOCK_OPEN, gtk.RESPONSE_OK))
271 | response = dialog.run()
272 | if response == gtk.RESPONSE_OK:
273 | file_path = dialog.get_filename()
274 | with open(file_path, 'rb') as f:
275 | nodolist, link_color24, link_color50 = pickle.load(f)
276 | archivo_corriente = file_path
277 | elif response == gtk.RESPONSE_CANCEL:
278 | dialog.destroy()
279 | dialog.destroy()
280 | else:
281 | message_stop()
282 |
283 |
284 | def message_stop():
285 | md = gtk.MessageDialog(parent=None,
286 | flags=gtk.DIALOG_DESTROY_WITH_PARENT,
287 | type=gtk.MESSAGE_INFO,
288 | buttons=gtk.BUTTONS_CLOSE,
289 | message_format="First stop emulation.")
290 | md.run()
291 | md.destroy()
292 |
293 |
294 | def save_mesh(signal):
295 | if not nodolist.run:
296 | datos = nodolist, link_color24, link_color50
297 | with open(dir_trabajo + '/data.ms', 'wb') as f:
298 | pickle.dump(datos, f)
299 | else:
300 | message_stop()
301 |
302 |
303 | def save_as_mesh(signal):
304 | if not nodolist.run:
305 | dialog = gtk.FileChooserDialog(title="Select or create a mesh file",
306 | parent=None,
307 | flags=gtk.FILE_CHOOSER_ACTION_SAVE,
308 | buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
309 | gtk.STOCK_OPEN, gtk.RESPONSE_OK))
310 | response = dialog.run()
311 | if response == gtk.RESPONSE_OK:
312 | file_path = dialog.get_filename()
313 | datos = nodolist, link_color24, link_color50
314 | with open(file_path, 'wb') as f:
315 | pickle.dump(datos, f)
316 | archivo_corriente = file_path
317 | elif response == gtk.RESPONSE_CANCEL:
318 | dialog.destroy()
319 | dialog.destroy()
320 | else:
321 | message_stop()
322 |
323 |
324 | def select_folder(signal):
325 | global dir_trabajo
326 | if not nodolist.run:
327 | dialog = gtk.FileChooserDialog("Select work directory",
328 | None,
329 | gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
330 | (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
331 | gtk.STOCK_OPEN, gtk.RESPONSE_OK))
332 | response = dialog.run()
333 | if response == gtk.RESPONSE_OK:
334 | dir_trabajo = dialog.get_filename()
335 | elif response == gtk.RESPONSE_CANCEL:
336 | dialog.destroy()
337 | dialog.destroy()
338 | else:
339 | message_stop()
340 |
341 |
342 | def response_to_dialog(entry, dialog, response):
343 | dialog.response(response)
344 |
345 |
346 | def get_password():
347 | dialog = gtk.MessageDialog(
348 | parent=None,
349 | flags=gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
350 | type=gtk.MESSAGE_QUESTION,
351 | buttons=gtk.BUTTONS_OK,
352 | message_format=None)
353 | dialog.set_markup('Please enter your password:')
354 | entry = gtk.Entry()
355 | entry.connect("activate", response_to_dialog, dialog, gtk.RESPONSE_OK)
356 | entry.set_visibility(False) # Hide password chars
357 | hbox = gtk.HBox()
358 | hbox.pack_start(gtk.Label("Password:"), False, 5, 5)
359 | hbox.pack_end(entry)
360 | dialog.format_secondary_markup("This will be used for create interfaces in your local machine")
361 | dialog.vbox.pack_end(hbox, True, True, 0)
362 | dialog.set_position(gtk.WIN_POS_CENTER)
363 | dialog.show_all()
364 | dialog.run()
365 | text = entry.get_text()
366 | dialog.destroy()
367 | return text
368 |
369 |
370 | def run_mesh(signal):
371 | if not nodolist.run:
372 | nodolist.start()
373 | link_color24.start()
374 | link_color50.start()
375 | os.system('echo ' + password + ' | sudo -S ifconfig vboxnet0 inet 192.168.100.1 up')
376 | # nodolist.run = True
377 |
378 |
379 | def stop_mesh(signal):
380 | global node_tr
381 | if nodolist.run:
382 | link_color24.stop()
383 | link_color50.stop()
384 | os.system('killall -q vde_switch')
385 | nodolist.stop()
386 | os.system('echo ' + password + ' | sudo -S ip addr del 192.168.100.1/24 dev vboxnet0')
387 | os.system('echo ' + password + ' | sudo -S ip link set vboxnet0 down')
388 | # nodolist.run = False
389 | node_tr = []
390 |
391 |
392 | def delete_mesh(signal):
393 | if not nodolist.run:
394 | for x in link_color24[:]:
395 | link_color24.remove(x)
396 | for x in link_color50[:]:
397 | link_color50.remove(x)
398 | for x in nodolist[:]:
399 | nodolist.remove(x)
400 | else:
401 | message_stop()
402 |
403 |
404 | def remover_nodos(signal):
405 | link = [(j.sd) for j in link_color24]
406 | o = [(j[0]) for j in link]
407 | d = [(j[1]) for j in link]
408 | link = [(j.sd) for j in link_color50]
409 | o5 = [(j[0]) for j in link]
410 | d5 = [(j[1]) for j in link]
411 | for i in nodolist[:]:
412 | if (i.pos not in o and i.pos not in d) and (i.pos not in o5 and i.pos not in d5):
413 | nodolist.remove(i)
414 |
415 |
416 | def remover_enlaces(signal):
417 | n = [(j.pos) for j in nodolist]
418 | for i in link_color24[:]:
419 | linea = i.sd
420 | ((x1, y1), (x2, y2)) = linea
421 | if (x1, y1) not in n or (x2, y2) not in n:
422 | link_color24.remove(i)
423 | for i in link_color50[:]:
424 | linea = i.sd
425 | ((x1, y1), (x2, y2)) = linea
426 | if (x1, y1) not in n or (x2, y2) not in n:
427 | link_color50.remove(i)
428 | if nodolist.run:
429 | link_color24.start()
430 | link_color50.start()
431 |
432 |
433 | # Create a new backing pixmap of the appropriate size
434 | def configure_event(widget, event):
435 | return True
436 |
437 |
438 | def dibujar(widget):
439 | global cr, node_tr
440 | cr = widget.window.cairo_create()
441 | w = widget.allocation.width
442 | h = widget.allocation.height
443 | print w, h
444 | cr.set_source_rgb(0.0, 0.0, 0.0)
445 | cr.rectangle(0, 0, w, h)
446 | cr.fill()
447 | # import ipdb; ipdb.set_trace()
448 | # Draw background grid
449 | cr.set_line_width(1)
450 | cr.set_source_rgba(0.1, 0.1, 0.1, 1.0)
451 | nv = int((w - 201) / 100)
452 | nh = int((h - 99) / 100)
453 | for i in range(10): #vertical line
454 | cr.move_to(i * 100, 0)
455 | cr.line_to(i * 100, 100 * nh)
456 | for i in range(nh + 1): #horizontal line
457 | cr.move_to(0, i * 100)
458 | cr.line_to(100 * (9), i * 100)
459 | cr.stroke()
460 | # Draw wire
461 | cr.select_font_face('Sans')
462 | cr.set_font_size(12)
463 | for l in link_color24:
464 | if l.sd in link_color24.current_wire:
465 | # Draw wire property for current wire
466 | cr.set_source_rgba(0.3, 0.7, 1.0, 1.0) # blue
467 | i = 0
468 | for p in l.prop:
469 | cr.move_to(i * 70, 45)
470 | cr.show_text(p + ': ' + str(l.prop[p]))
471 | i += 1
472 | cr.set_source_rgba(0.3, 0.7, 1.0, 1.0) # blue
473 | cr.set_line_width(4.0)
474 | else:
475 | cr.set_source_rgba(0.3, 0.7, 1.0, 1.0) # blue
476 | cr.set_line_width(2.0)
477 | if trace_l2 and (str(point2num(l.sd[0])) in node_tr and
478 | str(point2num(l.sd[1]))) in node_tr:
479 | cr.set_source_rgba(1.0, 1.0, 1.0, 0.5)
480 | (xi, yi), (xf, yf) = l.sd
481 | cr.move_to(xi, yi)
482 | cr.line_to(xf, yf)
483 | cr.stroke()
484 | for l in link_color50:
485 | if l.sd in link_color50.current_wire:
486 | # Draw wire property for current wire
487 | cr.set_source_rgba(0.0, 1.0, 0.0, 1.0) # green
488 | i = 0
489 | for p in l.prop:
490 | cr.move_to(i * 70, 60)
491 | cr.show_text(p + ': ' + str(l.prop[p]))
492 | i += 1
493 | cr.set_source_rgba(0.0, 1.0, 0.0, 0.5) # green
494 | cr.set_line_width(4.0)
495 | else:
496 | cr.set_source_rgba(0.0, 1.0, 0.0, 0.5) # green
497 | cr.set_line_width(2.0)
498 | if trace_l2 and (str(point2num(l.sd[0])) in node_tr and str(point2num(l.sd[1]))) in node_tr:
499 | cr.set_source_rgba(1.0, 1.0, 1.0, 0.5)
500 | (xi, yi), (xf, yf) = l.sd
501 | cr.move_to(xi, yi)
502 | cr.line_to(xf, yf)
503 | cr.stroke()
504 | # Draw nodo
505 | for po in nodolist:
506 | p = po.pos
507 | cr.arc(p[0], p[1], 12, 0, 2 * math.pi)
508 | cr.set_source_rgba(0.1, 0.6, 0.1, 1.0)
509 | if nodolist.run:
510 | if po.count == 0:
511 | mibr = netsnmp.Varbind('iso.3.6.1.4.1.2021.10.1.3.1')
512 | po.load_average = netsnmp.snmpget(mibr, Version=2,
513 | DestHost=po.smp_ip, Community='public', Timeout=5000, Retries=1)[0]
514 | if po.load_average is None:
515 | cr.set_source_rgba(0.6, 0.0, 0.0, 1.0)
516 | elif float(po.load_average) > 1:
517 | po.count = 10
518 | else:
519 | cr.set_source_rgba(0.1, 0.6, 0.1, 1.0)
520 | mibr = netsnmp.Varbind('iso.3.6.1.2.1.2.2.1.11')
521 | rx = netsnmp.snmpwalk(mibr, Version=2, DestHost=po.smp_ip,
522 | Community='public', Timeout=5000, Retries=1)
523 | mibr = netsnmp.Varbind('iso.3.6.1.2.1.2.2.1.17')
524 | <<<<<<< HEAD
525 | tx = netsnmp.snmpwalk(mibr, Version=2, DestHost=po.smp_ip,
526 | Community='public', Timeout=5000, Retries=1)
527 | for i in po.interfases:
528 | =======
529 | tx = netsnmp.snmpwalk(mibr, Version=2, DestHost=po.smp_ip, Community='public', Timeout=5000, Retries=1)
530 | for i in po.interfaces:
531 | >>>>>>> f5e62b78799f1cf4662b5edfd3edaef3a6eb5d09
532 | if i.ind:
533 | if i.ind < len(rx):
534 | i.rx = rx[i.ind - 1]
535 | else:
536 | i.rx = '0'
537 | if i.ind < len(tx):
538 | i.tx = tx[i.ind - 1]
539 | else:
540 | i.tx = '0'
541 | else:
542 | po.count = po.count - 1
543 | cr.set_source_rgba(1.0, 0.0, 0.3, 1.0)
544 | if po.pos == nodolist.current.pos:
545 | cr.set_source_rgba(1.0, 1.0, 0.0, 1.0) # yellow
546 | cr.move_to(400, 30)
547 | cr.show_text('vm: ' + po.vm)
548 | # Draw originators for curren nodo
549 | if nodolist.run:
550 | cr.set_source_rgba(1.0, 1.0, 1.0, 1.0)
551 | cr.move_to(w-251, 15)
552 | cr.show_text("Originators")
553 | cr.set_source_rgba(1.0, 1.0, 1.0, 1.0)
554 | cr.move_to(w-251 + 125, 15)
555 | cr.show_text("Next Hop")
556 | # o,n = po.get_originators_nexthop()
557 | rg = len(o)
558 | if rg > len(n):
559 | rg = len(n)
560 | for i in range(rg):
561 | cr.set_source_rgba(0.0, 0.7, 0.7, 1.0)
562 | if i & 0x01:
563 | cr.set_source_rgba(0.0, 1.0, 1.0, 1.0)
564 | cr.move_to(w-251, 40 + i * 15)
565 | cr.show_text(str(o[i]))
566 | cr.move_to(w-251 + 125, 40 + i * 15)
567 | cr.show_text(str(n[i]))
568 | # Drow Interface packets for curren nodo
569 | for i in po.interfaces:
570 | if i.ind:
571 | if i.ind < 4:
572 | cr.move_to(200 * (i.ind - 1), 15)
573 | cr.show_text(i.name + ' rx: ' + i.rx + ' tx: ' + i.tx)
574 | if i.ind > 3:
575 | cr.move_to(200 * (i.ind - 4), 30)
576 | cr.show_text(i.name + ' rx: ' + i.rx + ' tx: ' + i.tx)
577 | cr.set_source_rgba(0.3, 1.0, 0.3, 1.0)
578 | # else:
579 | # cr.set_source_rgba(0.1,0.6, 0.1,1.0)
580 | if trace_l2 and str(po) in node_tr:
581 | cr.set_source_rgba(1.0, 1.0, 1.0, 0.5)
582 | cr.fill()
583 | cr.stroke()
584 | # Draw bat0 packets for each nodo
585 | cr.set_source_rgb(0.0, 0.0, 0.1)
586 | cr.move_to(p[0] - 7, p[1] + 5)
587 | cr.show_text(str(po))
588 | if nodolist.run:
589 | cr.move_to(p[0] - 30, p[1] - 30)
590 | cr.set_source_rgb(0.0, 1.0, 0.1)
591 | cr.show_text('Rx:' + str(po.bat0.rx))
592 | cr.move_to(p[0] - 30, p[1] - 15)
593 | cr.show_text('Tx:' + str(po.bat0.tx))
594 | cr.stroke()
595 | if trace_l2:
596 | x = -60
597 | <<<<<<< HEAD
598 | y = h-49
599 | =======
600 | y = h - 50
601 | >>>>>>> f5e62b78799f1cf4662b5edfd3edaef3a6eb5d09
602 | cr.set_line_width(1.0)
603 | for i in node_tr:
604 | if len(i) == 2:
605 | x = x + 80
606 | <<<<<<< HEAD
607 | if x > w-301:
608 | x = 20
609 | y = h-24
610 | =======
611 | if x > w -900:
612 | x = 20
613 | y = h - 25
614 | >>>>>>> f5e62b78799f1cf4662b5edfd3edaef3a6eb5d09
615 | cr.set_source_rgba(0.0, 1.0, 0.0, 1.0)
616 | cr.move_to(x + 12, y)
617 | cr.arc(x, y, 12, 0, 2 * math.pi)
618 | cr.move_to(x - 7, y + 5)
619 | cr.show_text(i)
620 | elif '.' in i:
621 | cr.set_source_rgba(1.0, 1.0, 0.0, 1.0)
622 | cr.move_to(x + 14, y + 5)
623 | cr.show_text(i)
624 | else:
625 | cr.set_source_rgba(1.0, 0.0, 0.0, 1.0)
626 | cr.move_to(x + 14, y + 5)
627 | cr.show_text('too delay')
628 | cr.stroke()
629 |
630 |
631 | # Redraw the screen from the backing pixmap
632 | def expose_event(widget, event):
633 | ti = time.time()
634 | dibujar(widget)
635 | tf = time.time()
636 | # print tf-ti
637 | return False
638 |
639 |
640 | def button_press_event(widget, event):
641 | global inicio
642 | if cr is not None:
643 | inicio = near((event.x, event.y))
644 | return True
645 |
646 |
647 | def button_release_event(widget, event):
648 | global wire_prop, trace_l2, node_tr, o, n
649 | fin = near((event.x, event.y))
650 | w = widget.allocation.width
651 | h = widget.allocation.height
652 | nv = int((w - 201) / 100)
653 | nh = int((h - 99) / 100)
654 | if fin[0] <100*10 and fin[0] > 50 and fin[1] < h-49 and fin[1] > 50:
655 | if event.button == 1 and cr is not None:
656 | if inicio == fin:
657 | if not nodolist.run and not any(x.pos == inicio for x in nodolist):
658 | nodolist.append(NodoClass(inicio))
659 | nodolist.set_cur_pos(inicio)
660 | elif any(x.pos == inicio for x in nodolist) and any(x.pos == fin for x in nodolist):
661 | if nodolist.run and trace_l2:
662 | for x in nodolist:
663 | if x.pos == fin:
664 | trace_fin_mac = str(x.bat0.mac)
665 | if x.pos == inicio:
666 | trace_nicio_ip = str(x.eth0.ip)
667 | pos_ini = str(x)
668 | l = []
669 | mibr = netsnmp.Varbind('iso', '3.6.1.4.1.32.1.4', trace_fin_mac, 'OCTETSTR')
670 | orig = netsnmp.snmpset(mibr, Version=2, DestHost=trace_nicio_ip, Community='private', Timeout=10000000, Retries=1)
671 | mibr = netsnmp.Varbind('iso.3.6.1.4.1.32.1.4')
672 | orig = netsnmp.snmpget(mibr, Version=2, DestHost=trace_nicio_ip, Community='private', Timeout=1000000, Retries=1)
673 | for i in str(orig[0]).split():
674 | l.append(i.split(':')[-1:])
675 | node_tr = reduce(lambda x, y: x + y, l)
676 | node_tr.insert(0, pos_ini)
677 | else:
678 | link_color24.current_wire = [(inicio, fin), (fin, inicio)]
679 | link_color50.current_wire = [(inicio, fin), (fin, inicio)]
680 | if wire_prop['ch'] == '24GHz':
681 | if (not any(x.sd in link_color24.current_wire for x in link_color24)):
682 | link_color24.append(WireClass(inicio, fin, wire_prop))
683 | if nodolist.run:
684 | link_color24.start()
685 | link_color50.start()
686 | if wire_prop['ch'] == '50GHz':
687 | if (not any(x.sd in link_color50.current_wire for x in link_color50)):
688 | link_color50.append(WireClass(inicio, fin, wire_prop))
689 | if nodolist.run:
690 | link_color24.start()
691 | link_color50.start()
692 | if event.button == 2 and cr is not None:
693 | if inicio == fin:
694 | if any(x.pos == inicio for x in nodolist):
695 | nodolist.set_cur_pos(inicio)
696 | if nodolist.run:
697 | for x in nodolist:
698 | if x.pos == fin:
699 | o, n = x.get_originators_nexthop()
700 | else:
701 | link_color24.current_wire = [(inicio, fin), (fin, inicio)]
702 | if wire_prop['ch'] == '24GHz':
703 | if any(x.pos in [inicio, fin] for x in nodolist):
704 | if any(x.sd in link_color24.current_wire for x in link_color24):
705 | for x in link_color24:
706 | if x.ds in link_color24.current_wire:
707 | wire_prop = x.prop
708 | link_color50.current_wire = [(inicio, fin), (fin, inicio)]
709 | if wire_prop['ch'] == '50GHz':
710 | if any(x.pos in [inicio, fin] for x in nodolist):
711 | if any(x.sd in link_color50.current_wire for x in link_color50):
712 | for x in link_color50:
713 | if x.ds in link_color50.current_wire:
714 | wire_prop = x.prop
715 |
716 | elif event.button == 3 and cr is not None:
717 | if inicio == fin:
718 | if not nodolist.run:
719 | if any(x.pos == inicio for x in nodolist):
720 | for x in nodolist:
721 | if x.pos == inicio:
722 | nid = nodolist.index(x)
723 | i = nodolist.pop(nid)
724 | elif any(x.pos == inicio for x in nodolist) and any(x.pos == fin for x in nodolist):
725 | if wire_prop['ch'] == '24GHz':
726 | for x in link_color24:
727 | if x.sd in [(inicio, fin), (fin, inicio)]:
728 | lid = link_color24.index(x)
729 | i = link_color24.pop(lid)
730 | if wire_prop['ch'] == '50GHz':
731 | for x in link_color50:
732 | if x.sd in [(inicio, fin), (fin, inicio)]:
733 | lid = link_color50.index(x)
734 | i = link_color50.pop(lid)
735 |
736 | dibujar(widget)
737 | return True
738 |
739 |
740 | def select_vm(signal):
741 | window = gtk.Window()
742 | window.connect('destroy', lambda w: select_vm)
743 | window.set_title("SELECT VIRTUAL MACHINE")
744 | combobox = gtk.combo_box_new_text()
745 | window.add(combobox)
746 | virtual_box_manager = vboxapi.VirtualBoxManager(None, None)
747 | vbox = virtual_box_manager.vbox
748 | vbox_vm_list = virtual_box_manager.getArray(vbox, 'machines')
749 | vbox_name_list = [mach.name for mach in vbox_vm_list]
750 | for i in vbox_name_list:
751 | combobox.append_text(str(i))
752 | combobox.connect('changed', changed_cb)
753 | combobox.set_active(0)
754 | window.show_all()
755 | return
756 |
757 |
758 | def changed_cb(combobox):
759 | global v_name_base
760 | model = combobox.get_model()
761 | index = combobox.get_active()
762 | if index:
763 | v_name_base = model[index][0]
764 | return
765 |
766 |
767 | def wire_show(signal):
768 | Wire()
769 |
770 |
771 | def menuitem_response():
772 | return
773 |
774 |
775 | def scale_set_default_values(scale):
776 | scale.set_update_policy(gtk.UPDATE_CONTINUOUS)
777 | scale.set_digits(1)
778 | scale.set_value_pos(gtk.POS_TOP)
779 | scale.set_draw_value(True)
780 |
781 |
782 | def on_changed(widget):
783 | global wire_prop
784 | val = widget.get_value()
785 | name = widget.get_name()
786 | wire_prop[name] = int(val)
787 |
788 |
789 | def callback(self, button):
790 | global wire_prop
791 | wire_prop['ch'] = button
792 |
793 |
794 | class Wire(gtk.Window):
795 | def __init__(self):
796 | super(Wire, self).__init__()
797 | self.set_size_request(400, 700)
798 | self.set_border_width(10)
799 | self.set_title("WIREFILTER SETUP")
800 | self.connect("delete_event", lambda w, e: self.destroy())
801 |
802 | vbox_app = gtk.VBox(False, 0)
803 | self.add(vbox_app)
804 | vbox_app.show()
805 | vbox1 = gtk.VBox(False, 0)
806 |
807 | label1 = gtk.Label("Percentage of loss: ")
808 | vbox1.pack_start(label1, True, True, 0)
809 | label1.show()
810 |
811 | adj1 = gtk.Adjustment(wire_prop['lo'], 0.0, 101.0, 1.0, 1.0, 1.0)
812 | vscale1 = gtk.HScale(adj1)
813 | scale_set_default_values(vscale1)
814 | vscale1.set_name('lo')
815 | vbox1.pack_start(vscale1, True, True, 0)
816 | vscale1.connect("value-changed", on_changed)
817 | vscale1.show()
818 |
819 | label1 = gtk.Label("Extra delay in milliseconds: ")
820 | vbox1.pack_start(label1, True, True, 0)
821 | label1.show()
822 |
823 | adj2 = gtk.Adjustment(wire_prop['de'], 0.0, 1001.0, 1.0, 1.0, 1.0)
824 | vscale2 = gtk.HScale(adj2)
825 | scale_set_default_values(vscale2)
826 | vscale2.set_name('de')
827 | vbox1.pack_start(vscale2, True, True, 0)
828 | vscale2.connect("value-changed", on_changed)
829 | vscale2.show()
830 |
831 | label1 = gtk.Label("dup percentage of dup packet: ")
832 | vbox1.pack_start(label1, True, True, 0)
833 | label1.show()
834 |
835 | adj3 = gtk.Adjustment(wire_prop['du'], 0.0, 101.0, 1.0, 1.0, 1.0)
836 | vscale3 = gtk.HScale(adj3)
837 | scale_set_default_values(vscale3)
838 | vscale3.set_name('du')
839 | vbox1.pack_start(vscale3, True, True, 0)
840 | vscale3.connect("value-changed", on_changed)
841 | vscale3.show()
842 |
843 | label1 = gtk.Label("Channel bandwidth in Bytes/sec: ")
844 | vbox1.pack_start(label1, True, True, 0)
845 | label1.show()
846 |
847 | adj4 = gtk.Adjustment(wire_prop['bw'], 0.0, 1001.0, 1.0, 1.0, 1.0)
848 | vscale4 = gtk.HScale(adj4)
849 | scale_set_default_values(vscale4)
850 | vscale4.set_name('bw')
851 | vbox1.pack_start(vscale4, True, True, 0)
852 | vscale4.connect("value-changed", on_changed)
853 | vscale4.show()
854 |
855 | label1 = gtk.Label("Interface speed in Bytes/sec: ")
856 | vbox1.pack_start(label1, True, True, 0)
857 | label1.show()
858 |
859 | adj5 = gtk.Adjustment(wire_prop['sp'], 0.0, 1001.0, 1.0, 1.0, 1.0)
860 | vscale5 = gtk.HScale(adj5)
861 | scale_set_default_values(vscale5)
862 | vscale5.set_name('sp')
863 | vbox1.pack_start(vscale5, True, True, 0)
864 | vscale5.connect("value-changed", on_changed)
865 | vscale5.show()
866 |
867 | label1 = gtk.Label("Channel capacity in Bytes: ")
868 | vbox1.pack_start(label1, True, True, 0)
869 | label1.show()
870 |
871 | adj6 = gtk.Adjustment(wire_prop['ca'], 0.0, 1001.0, 1.0, 1.0, 1.0)
872 | vscale6 = gtk.HScale(adj6)
873 | scale_set_default_values(vscale6)
874 | vscale6.set_name('ca')
875 | vbox1.pack_start(vscale6, True, True, 0)
876 | vscale6.connect("value-changed", on_changed)
877 | vscale6.show()
878 |
879 | label1 = gtk.Label("Number bits damaged/Megabyte: ")
880 | vbox1.pack_start(label1, True, True, 0)
881 | label1.show()
882 |
883 | adj7 = gtk.Adjustment(wire_prop['da'], 0.0, 101.0, 1.0, 1.0, 1.0)
884 | vscale7 = gtk.HScale(adj7)
885 | scale_set_default_values(vscale7)
886 | vscale7.set_name('da')
887 | vbox1.pack_start(vscale7, True, True, 0)
888 | vscale7.connect("value-changed", on_changed)
889 | vscale7.show()
890 |
891 | hbox1 = gtk.HBox(gtk.FALSE, 0)
892 | hbox1.set_border_width(10)
893 | vbox1.pack_start(hbox1, gtk.TRUE, gtk.TRUE, 0)
894 | hbox1.show()
895 |
896 | button = gtk.RadioButton(None, "2.4 GHz")
897 | button.connect("toggled", callback, "24GHz")
898 | if wire_prop['ch'] == "24GHz":
899 | button.set_active(gtk.TRUE)
900 | hbox1.pack_start(button, gtk.TRUE, gtk.TRUE, 0)
901 | button.show()
902 | button = gtk.RadioButton(button, "5.0 GHz")
903 | button.connect("toggled", callback, "50GHz")
904 | if wire_prop['ch'] == "50GHz":
905 | button.set_active(gtk.TRUE)
906 | hbox1.pack_start(button, gtk.TRUE, gtk.TRUE, 0)
907 | button.show()
908 |
909 | button_set = gtk.Button(stock=gtk.STOCK_OK)
910 | button_set.connect("clicked", lambda w: self.destroy())
911 | button_set.set_flags(gtk.CAN_DEFAULT)
912 | hbox1.pack_start(button_set, True, True, 0)
913 | button_set.show()
914 |
915 | button_close = gtk.Button(stock=gtk.STOCK_CLOSE)
916 | button_close.connect("clicked", lambda w: self.destroy())
917 | button_close.set_flags(gtk.CAN_DEFAULT)
918 | hbox1.pack_start(button_close, True, True, 0)
919 | button_close.show()
920 |
921 | vbox1.show()
922 | vbox_app.add(vbox1)
923 | button_close.grab_default()
924 | self.show()
925 |
926 |
927 | def get_mesh(dir_trabajo):
928 | global nodolist, link_color24, link_color50
929 | dm = dir_trabajo + '/data.ms'
930 | if os.path.isfile('data.ms'):
931 | with open(dm, 'rb') as f:
932 | nodolist, link_color24, link_color50 = pickle.load(f)
933 |
934 |
935 | def create_colorfull(dir_trabajo):
936 | f = open(dir_trabajo + '/colourful.rc', 'w')
937 | f.write('port/setcolourful 1\n')
938 | f.write('port/create 1\n')
939 | f.write('port/create 2\n')
940 | f.write('port/create 3\n')
941 | f.write('port/create 4\n')
942 | f.write('port/create 5\n')
943 | f.write('port/setcolour 1 1\n')
944 | f.write('port/setcolour 2 2\n')
945 | f.write('port/setcolour 3 2\n')
946 | f.close()
947 |
948 |
949 | class MenuApp(gtk.Window):
950 | def __init__(self):
951 | super(MenuApp, self).__init__()
952 | screen = self.get_screen()
953 | self.set_title("Mesh network emulator")
954 | self.set_size_request(min(screen.get_width(), 800),
955 | min(screen.get_height(), 600))
956 | <<<<<<< HEAD
957 | # self.maximize()
958 | =======
959 | self.maximize()
960 | >>>>>>> f5e62b78799f1cf4662b5edfd3edaef3a6eb5d09
961 | self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(6400, 6400, 6440))
962 | self.set_position(gtk.WIN_POS_CENTER)
963 | # top level menu bar
964 | menubar = gtk.MenuBar()
965 |
966 | # top items on the menu bar
967 | filem = gtk.MenuItem("File")
968 | editm = gtk.MenuItem("Edit")
969 | runm = gtk.MenuItem("Run/Stop")
970 | toolsm = gtk.MenuItem("Tools")
971 | aboutm = gtk.MenuItem("About")
972 |
973 | # now, create for FILE item the menu
974 | filemenu = gtk.Menu()
975 | filem.set_submenu(filemenu)
976 |
977 | # create the items for File menu
978 | new = gtk.MenuItem("New")
979 | filemenu.append(new)
980 | new.connect("activate", select_folder)
981 |
982 | open = gtk.MenuItem("Open")
983 | filemenu.append(open)
984 | open.connect("activate", open_mesh)
985 |
986 | save = gtk.MenuItem("Save")
987 | filemenu.append(save)
988 | save.connect("activate", save_mesh)
989 |
990 | saveas = gtk.MenuItem("Save as")
991 | filemenu.append(saveas)
992 | saveas.connect("activate", save_as_mesh)
993 | # separator
994 | separat = gtk.SeparatorMenuItem()
995 | filemenu.append(separat)
996 |
997 | # now, Quit item with accelerator and image
998 | # generic accelerator
999 | agr = gtk.AccelGroup()
1000 | self.add_accel_group(agr)
1001 |
1002 | quit_img = gtk.ImageMenuItem(gtk.STOCK_QUIT, agr)
1003 | key, mod = gtk.accelerator_parse("Q")
1004 | quit_img.add_accelerator("activate", agr, key, mod, gtk.ACCEL_VISIBLE)
1005 | filemenu.append(quit_img)
1006 |
1007 | # connect to Quit the activate event
1008 | quit_img.connect("activate", gtk.main_quit)
1009 |
1010 | # create the edit menu and attach it to the top item
1011 | editmenu = gtk.Menu()
1012 | editm.set_submenu(editmenu)
1013 |
1014 | # create the items for Edit menu
1015 | delmesh = gtk.MenuItem("Delete Mesh")
1016 | editmenu.append(delmesh)
1017 | delmesh.connect("activate", delete_mesh)
1018 |
1019 | delnodo = gtk.MenuItem("Delete Nodo")
1020 | editmenu.append(delnodo)
1021 | delnodo.connect("activate", remover_nodos)
1022 |
1023 | dellink = gtk.MenuItem("Delete Link")
1024 | editmenu.append(dellink)
1025 | dellink.connect("activate", remover_enlaces)
1026 |
1027 | editwire = gtk.MenuItem("Edit Wire")
1028 | editmenu.append(editwire)
1029 | editwire.connect("activate", wire_show)
1030 |
1031 | selectvm = gtk.MenuItem("Select VM")
1032 | editmenu.append(selectvm)
1033 | selectvm.connect("activate", select_vm)
1034 |
1035 | # create the run menu and attach it to the top item
1036 | runmenu = gtk.Menu()
1037 | runm.set_submenu(runmenu)
1038 |
1039 | # create the items for Run menu
1040 | run = gtk.MenuItem("Run")
1041 | runmenu.append(run)
1042 | run.connect("activate", run_mesh)
1043 |
1044 | stop = gtk.MenuItem("Stop")
1045 | runmenu.append(stop)
1046 | stop.connect("activate", stop_mesh)
1047 |
1048 | # create the tools menu and attach it to the top item
1049 | toolsmenu = gtk.Menu()
1050 | toolsm.set_submenu(toolsmenu)
1051 |
1052 | # create the items for Run menu
1053 | trace = gtk.CheckMenuItem("Trace route on")
1054 | trace.set_active(False)
1055 | toolsmenu.append(trace)
1056 | trace.connect("activate", traceon)
1057 |
1058 | head = gtk.CheckMenuItem("VM Headless on")
1059 | head.set_active(False)
1060 | toolsmenu.append(head)
1061 | head.connect("activate", headon)
1062 |
1063 | # append the top items
1064 | menubar.append(filem)
1065 | menubar.append(editm)
1066 | menubar.append(runm)
1067 | menubar.append(toolsm)
1068 | menubar.append(aboutm)
1069 |
1070 | # pack in a vbox
1071 | vbox = gtk.VBox(False, 2)
1072 | vbox.pack_start(menubar, False, False, 0)
1073 |
1074 | # Create the drawing area
1075 | drawing_area = gtk.DrawingArea()
1076 | # drawing_area.set_size_request(1000, 1000)
1077 | drawing_area.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(0, 0, 0))
1078 | vbox.pack_start(drawing_area, True, True, 0)
1079 | drawing_area.show()
1080 |
1081 | # Signals used to handle backing pixmap
1082 | drawing_area.connect("expose_event", expose_event)
1083 | drawing_area.connect("configure_event", configure_event)
1084 |
1085 | # Event signals
1086 |
1087 | drawing_area.connect("button_press_event", button_press_event)
1088 | drawing_area.connect("button_release_event", button_release_event)
1089 |
1090 | drawing_area.set_events(gtk.gdk.EXPOSURE_MASK |
1091 | gtk.gdk.LEAVE_NOTIFY_MASK |
1092 | gtk.gdk.BUTTON_PRESS_MASK |
1093 | gtk.gdk.BUTTON_RELEASE_MASK |
1094 | gtk.gdk.BUTTON3_MOTION_MASK |
1095 | gtk.gdk.POINTER_MOTION_MASK |
1096 | gtk.gdk.POINTER_MOTION_HINT_MASK)
1097 |
1098 | # add the vbox to the window
1099 | self.add(vbox)
1100 | self.connect("destroy", gtk.main_quit)
1101 |
1102 | self.show_all()
1103 | gobject.timeout_add(2000, self.tick)
1104 | # gobject.idle_add(self.tick )
1105 | global password
1106 | password = get_password()
1107 | global dir_trabajo
1108 | dir_trabajo = os.getcwd()
1109 | if not os.path.isfile('colourful.rc'):
1110 | create_colorfull(dir_trabajo)
1111 | get_mesh(dir_trabajo)
1112 |
1113 | def tick(self):
1114 | self.queue_draw()
1115 | return True
1116 |
1117 |
1118 | MenuApp()
1119 |
1120 | gtk.main()
1121 |
--------------------------------------------------------------------------------
/simmeshv13.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | import pygtk
4 | pygtk.require('2.0')
5 | import gtk
6 | import gobject
7 | import math
8 | import pickle
9 | import os
10 | import netsnmp
11 | import time
12 | import vboxapi
13 | import ipdb
14 | dir_trabajo = ''
15 | wire_prop = {'lo': 0, 'de': 0, 'du': 0, 'bw': 0, 'sp': 0,
16 | 'ca': 0, 'da': 0, 'ch': '24GHz'}
17 | password = ''
18 | v_name_base = 'openwrtv12'
19 | trace_l2 = False
20 | node_tr = []
21 | node_head = ''
22 | o = []
23 | n = []
24 |
25 |
26 | class LinkList(list):
27 | def __init__(self):
28 | self.ll = []
29 | self.current_wire = None
30 |
31 | def stop(self):
32 | os.system('killall -q wirefilter')
33 | for x in self:
34 | x.stop()
35 |
36 | def __del__(self):
37 | self.stop()
38 |
39 | def start(self):
40 | for x in self:
41 | x.start()
42 |
43 | def set_current_wire(self, sdds):
44 | for x in self:
45 | if x.sd in sdds:
46 | self.current_wire = sdds
47 |
48 |
49 | class NodoList(list):
50 | def __init__(self):
51 | self.nl = []
52 | self.current = None
53 | self.run = False
54 |
55 | def set_current(self, no):
56 | self.current = no
57 |
58 | def set_cur_pos(self, pos):
59 | for x in self:
60 | if x.pos == pos:
61 | self.current = x
62 |
63 | def stop(self):
64 | for x in self:
65 | x.stop()
66 | self.run = False
67 |
68 | def start(self):
69 | for x in self:
70 | x.start()
71 | self.run = True
72 |
73 | link_color24 = LinkList()
74 | link_color50 = LinkList()
75 | nodolist = NodoList()
76 |
77 |
78 | class Interface(object):
79 | def __init__(self, indice, name, nodonum, oamip):
80 | self.ind = indice
81 | self.name = name
82 | self.oamip = oamip
83 | self.ifpresent = False
84 | self.rx = '0'
85 | self.tx = '0'
86 | self.ip = {'tapwrt': '192.168.' + nodonum + '.1',
87 | 'oam': '192.168.100.' + nodonum,
88 | 'lo': None,
89 | 'eth0': '192.168.100.' + nodonum,
90 | 'eth1': None,
91 | 'eth2': None,
92 | 'bat0': '192.168.7.' + nodonum, }[name]
93 | self.mac = {'tapwrt': None,
94 | 'oam': None,
95 | 'lo': None,
96 | 'eth0': '80:01:00:00:07:' + nodonum,
97 | 'eth1': '80:02:00:00:07:' + nodonum,
98 | 'eth2': '80:05:00:00:07:' + nodonum,
99 | 'bat0': '90:' + nodonum + ':' + nodonum + ':' + nodonum +
100 | ':' + nodonum + ':' + nodonum}[name]
101 |
102 | def __str__(self):
103 | return str(self.name)
104 |
105 |
106 | class NodoClass(object):
107 | def __init__(self, p):
108 | self.pos = p
109 | self.num = int(p[0] * 10 + p[1])
110 | self.name = 'wrt' + str(self.num)
111 | self.octet_str = str(self.num)
112 | self.smp_ip = '192.168.100.' + str(self)
113 | self.oam = Interface(None, 'oam', str(self), self.smp_ip)
114 | self.tapwrt = Interface(None, 'tapwrt', str(self), self.smp_ip)
115 | self.lo = Interface(1, 'lo', str(self), self.smp_ip)
116 | self.eth0 = Interface(2, 'eth0', str(self), self.smp_ip)
117 | self.eth1 = Interface(3, 'eth1', str(self), self.smp_ip)
118 | self.eth2 = Interface(4, 'eth2', str(self), self.smp_ip)
119 | self.bat0 = Interface(5, 'bat0', str(self), self.smp_ip)
120 | self.interfases = [self.tapwrt, self.oam, self.lo, self.eth0,
121 | self.eth1, self.eth2, self.bat0]
122 | self.originator_nexthop = ['None'], ['None']
123 | self.vm = v_name_base
124 | self.load_average = '0.00'
125 | self.count = 0
126 | self.running = False
127 |
128 | def __str__(self):
129 | return str(self.num)
130 |
131 | def __del__(self):
132 | self.stop()
133 |
134 | def stop(self):
135 | if self.running:
136 | os.system('echo ' + password + ' | sudo -S rm -rf /tmp/24GHz' +
137 | self.octet_str)
138 | os.system('echo ' + password + ' | sudo -S rm -rf /tmp/50GHz' +
139 | self.octet_str)
140 | os.system('echo ' + password + ' | sudo -S ip addr del ' +
141 | self.tapwrt.ip + '/24 dev tap24GHz' + self.octet_str)
142 | os.system('echo ' + password + ' | sudo -S ip link delete tap24GHz'
143 | + self.octet_str)
144 | os.system('echo ' + password + ' | sudo -S ip addr del '
145 | + self.tapwrt.ip + '/24 dev tap50GHz' + self.octet_str)
146 | os.system('echo ' + password + ' | sudo -S ip link delete tap50GHz'
147 | + self.octet_str)
148 | os.system('VBoxManage controlvm num' + self.octet_str + ' poweroff')
149 | os.system('VBoxManage unregistervm --delete num' + self.octet_str)
150 | os.system('killall -q vde_switch')
151 | self.running = False
152 |
153 | def get_originators_nexthop(self):
154 | host = self.smp_ip
155 | mibr = netsnmp.Varbind('iso.3.6.1.4.1.32.1.2')
156 | orig = netsnmp.snmpget(mibr, Version=2, DestHost=host,
157 | Community='public', Timeout=50000, Retries=3)
158 | on = str(orig[0]).split()
159 | return on[::2], on[1::2]
160 |
161 | def start(self):
162 | if not self.running:
163 | os.system('echo ' + password + ' | sudo -S ip tuntap add tap24GHz'
164 | + self.octet_str + ' mode tap')
165 | os.system('echo ' + password + ' | sudo -S ifconfig tap24GHz'
166 | + self.octet_str + ' ' + self.tapwrt.ip + ' up')
167 | os.system('echo ' + password + ' | sudo -S ip tuntap add tap50GHz'
168 | + self.octet_str + ' mode tap')
169 | os.system('echo ' + password + ' | sudo -S ifconfig tap50GHz'
170 | + self.octet_str + ' ' + self.tapwrt.ip + ' up')
171 | os.system('vde_switch -d --hub -s /tmp/24GHz' + self.octet_str
172 | + ' -tap tap24GHz' + self.octet_str + ' -m 666 -f ' + dir_trabajo
173 | + '/colourful.rc')
174 | os.system('vde_switch -d --hub -s /tmp/50GHz' + self.octet_str
175 | + ' -tap tap50GHz' + self.octet_str + ' -m 666 -f ' + dir_trabajo
176 | + '/colourful.rc')
177 | os.system('VBoxManage clonevm ' + self.vm + ' --name num'
178 | + self.octet_str + ' --register')
179 | os.system('VBoxManage modifyvm num' + self.octet_str +
180 | ' --nic1 hostonly --hostonlyadapter1 vboxnet0 --macaddress1 '
181 | + str(self.eth0.mac).translate(None, ':'))
182 | os.system('VBoxManage modifyvm num' + self.octet_str
183 | + ' --nic2 generic --nicgenericdrv2 VDE --nicproperty2 network=/tmp/24GHz' + self.octet_str + '[2] --macaddress2 ' + str(self.eth1.mac).translate(None, ':'))
184 | os.system('VBoxManage modifyvm num' + self.octet_str
185 | + ' --nic3 generic --nicgenericdrv3 VDE --nicproperty3 network=/tmp/50GHz' + self.octet_str + '[3] --macaddress3 ' + str(self.eth2.mac).translate(None, ':'))
186 | os.system('VBoxManage startvm num' + self.octet_str + node_head)
187 | self.running = True
188 |
189 |
190 | class WireClass(object):
191 | def __init__(self, src, dst, quality):
192 | self.s = src
193 | self.d = dst
194 | self.sd = src, dst
195 | self.ds = dst, src
196 | self.quality = quality
197 | self.s_str = str(point2num(self.s))
198 | self.d_str = str(point2num(self.d))
199 | self.name = "wire" + self.s_str + '-' + self.d_str
200 | self.canal = self.quality['ch']
201 | self.running = False
202 | self.prop = {'lo': self.quality['lo'],
203 | 'de': self.quality['de'],
204 | 'du': self.quality['du'],
205 | 'bw': self.quality['bw'],
206 | 'sp': self.quality['sp'],
207 | 'ca': self.quality['ca'],
208 | 'da': self.quality['da'],
209 | 'ch': self.quality['ch']}
210 |
211 | def __del__(self):
212 | if nodolist.run:
213 | link_color24.stop()
214 | link_color50.stop()
215 | link_color24.start()
216 | link_color50.start()
217 |
218 | def start(self):
219 | if not self.running:
220 | od = 'wirefilter' + ' --daemon -v /tmp/' + self.canal + self.s_str + ':/tmp/' + self.canal + self.d_str
221 | if self.prop['lo'] != 0:
222 | od = od + ' -l ' + str(self.prop['lo'])
223 | if self.prop['de'] != 0:
224 | od = od + ' -d ' + str(self.prop['de']) + '+' + str(self.prop['de'] / 2) + 'N'
225 | if self.prop['du'] != 0:
226 | od = od + ' -D ' + str(self.prop['du'])
227 | if self.prop['bw'] != 0:
228 | od = od + ' -b ' + str(self.prop['bw'])
229 | if self.prop['sp'] != 0:
230 | od = od + ' -s ' + str(self.prop['sp'])
231 | if self.prop['ca'] != 0:
232 | od = od + ' -c ' + str(self.prop['ca'])
233 | if self.prop['da'] != 0:
234 | od = od + ' -n ' + str(self.prop['da'])
235 | os.system(od)
236 | self.running = True
237 |
238 | def stop(self):
239 | self.running = False
240 |
241 |
242 | def traceon(signal):
243 | global trace_l2, node_tr
244 | node_tr = []
245 | if signal.active:
246 | trace_l2 = True
247 | else:
248 | trace_l2 = False
249 |
250 |
251 | def headon(signal):
252 | global node_head
253 | if signal.active:
254 | node_head = ' --type headless'
255 | else:
256 | node_head = ''
257 |
258 |
259 | def point2num(point):
260 | return int(point[0] * 10 + point[1])
261 |
262 |
263 | # set point close to grid node
264 | def near(punto, eh, ev):
265 | x, y = punto
266 | xi, xd = divmod(x, eh)
267 | yi, yd = divmod(y, ev)
268 | if xd > eh / 2:
269 | if xi < 10:
270 | xi = xi + 1
271 | if yd > ev / 2:
272 | yi = yi + 1
273 | return xi, yi
274 |
275 |
276 | def open_mesh(widget):
277 | global link_color24, link_color50, nodolist
278 | if not nodolist.run:
279 | dialog = gtk.FileChooserDialog(
280 | "Select a mesh file",
281 | None,
282 | gtk.FILE_CHOOSER_ACTION_OPEN,
283 | (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
284 | gtk.STOCK_OPEN, gtk.RESPONSE_OK))
285 | response = dialog.run()
286 | if response == gtk.RESPONSE_OK:
287 | file_path = dialog.get_filename()
288 | with open(file_path, 'rb') as f:
289 | nodolist, link_color24, link_color50 = pickle.load(f)
290 | archivo_corriente = file_path
291 | elif response == gtk.RESPONSE_CANCEL:
292 | dialog.destroy()
293 | dialog.destroy()
294 | else:
295 | message_stop()
296 |
297 |
298 | def message_stop():
299 | md = gtk.MessageDialog(None,
300 | gtk.DIALOG_DESTROY_WITH_PARENT,
301 | gtk.MESSAGE_INFO,
302 | gtk.BUTTONS_CLOSE,
303 | "Firs stop emulation")
304 | md.run()
305 | md.destroy()
306 |
307 |
308 | def save_mesh(signal):
309 | if not nodolist.run:
310 | datos = nodolist, link_color24, link_color50
311 | with open(dir_trabajo + '/data.ms', 'wb') as f:
312 | pickle.dump(datos, f)
313 | else:
314 | message_stop()
315 |
316 |
317 | def save_as_mesh(signal):
318 | if not nodolist.run:
319 | dialog = gtk.FileChooserDialog("Select or create a mesh file",
320 | None,
321 | gtk.FILE_CHOOSER_ACTION_SAVE,
322 | (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
323 | gtk.STOCK_OPEN, gtk.RESPONSE_OK))
324 | response = dialog.run()
325 | if response == gtk.RESPONSE_OK:
326 | file_path = dialog.get_filename()
327 | datos = nodolist, link_color24, link_color50
328 | with open(file_path, 'wb') as f:
329 | pickle.dump(datos, f)
330 | archivo_corriente = file_path
331 | elif response == gtk.RESPONSE_CANCEL:
332 | dialog.destroy()
333 | dialog.destroy()
334 | else:
335 | message_stop()
336 |
337 |
338 | def select_folder(signal):
339 | global dir_trabajo
340 | if not nodolist.run:
341 | dialog = gtk.FileChooserDialog("Select work directory",
342 | None,
343 | gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
344 | (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
345 | gtk.STOCK_OPEN, gtk.RESPONSE_OK))
346 | response = dialog.run()
347 | if response == gtk.RESPONSE_OK:
348 | dir_trabajo = dialog.get_filename()
349 | elif response == gtk.RESPONSE_CANCEL:
350 | dialog.destroy()
351 | dialog.destroy()
352 | else:
353 | message_stop()
354 |
355 |
356 | def response_to_dialog(entry, dialog, response):
357 | dialog.response(response)
358 |
359 |
360 | def get_password():
361 | dialog = gtk.MessageDialog(
362 | None,
363 | gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
364 | gtk.MESSAGE_QUESTION,
365 | gtk.BUTTONS_OK,
366 | None)
367 | dialog.set_markup('Please enter your password:')
368 | entry = gtk.Entry()
369 | entry.connect("activate", response_to_dialog, dialog, gtk.RESPONSE_OK)
370 | entry.set_visibility(False)
371 | hbox = gtk.HBox()
372 | hbox.pack_start(gtk.Label("Password:"), False, 5, 5)
373 | hbox.pack_end(entry)
374 | dialog.format_secondary_markup("This will be used for create interfaces in your local machine")
375 | dialog.vbox.pack_end(hbox, True, True, 0)
376 | dialog.set_position(gtk.WIN_POS_CENTER)
377 | dialog.show_all()
378 | dialog.run()
379 | text = entry.get_text()
380 | dialog.destroy()
381 | return text
382 |
383 |
384 | def run_mesh(signal):
385 | if not nodolist.run:
386 | nodolist.start()
387 | link_color24.start()
388 | link_color50.start()
389 | os.system('echo ' + password +
390 | ' | sudo -S ifconfig vboxnet0 inet 192.168.100.1 up')
391 | # nodolist.run = True
392 |
393 |
394 | def stop_mesh(signal):
395 | global node_tr
396 | if nodolist.run:
397 | link_color24.stop()
398 | link_color50.stop()
399 | os.system('killall -q vde_switch')
400 | nodolist.stop()
401 | os.system('echo ' + password + ' | sudo -S ip addr del 192.168.100.1/24 dev vboxnet0')
402 | os.system('echo ' + password + ' | sudo -S ip link set vboxnet0 down')
403 | # nodolist.run = False
404 | node_tr = []
405 |
406 |
407 | def delete_mesh(signal):
408 | if not nodolist.run:
409 | for x in link_color24[:]:
410 | link_color24.remove(x)
411 | for x in link_color50[:]:
412 | link_color50.remove(x)
413 | for x in nodolist[:]:
414 | nodolist.remove(x)
415 | else:
416 | message_stop()
417 |
418 |
419 | def remover_nodos(signal):
420 | link = [(j.sd) for j in link_color24]
421 | o = [(j[0]) for j in link]
422 | d = [(j[1]) for j in link]
423 | link = [(j.sd) for j in link_color50]
424 | o5 = [(j[0]) for j in link]
425 | d5 = [(j[1]) for j in link]
426 | for i in nodolist[:]:
427 | if (i.pos not in o and i.pos not in d) and (i.pos not in o5 and i.pos not in d5):
428 | nodolist.remove(i)
429 |
430 |
431 | def remover_enlaces(signal):
432 | n = [(j.pos) for j in nodolist]
433 | for i in link_color24[:]:
434 | linea = i.sd
435 | ((x1, y1), (x2, y2)) = linea
436 | if (x1, y1) not in n or (x2, y2) not in n:
437 | link_color24.remove(i)
438 | for i in link_color50[:]:
439 | linea = i.sd
440 | ((x1, y1), (x2, y2)) = linea
441 | if (x1, y1) not in n or (x2, y2) not in n:
442 | link_color50.remove(i)
443 | if nodolist.run:
444 | link_color24.start()
445 | link_color50.start()
446 |
447 |
448 | # Create a new backing pixmap of the appropriate size
449 | def configure_event(widget, event):
450 | return True
451 |
452 |
453 | def dibujar(widget):
454 | global cr, node_tr
455 | cr = widget.window.cairo_create()
456 | w = widget.allocation.width
457 | h = widget.allocation.height
458 | cr.set_source_rgb(0.0, 0.0, 0.0)
459 | cr.rectangle(0, 0, w, h)
460 | cr.fill()
461 | # import ipdb; ipdb.set_trace()
462 | # Draw background grid
463 | cr.set_line_width(1)
464 | cr.set_source_rgba(0.2, 0.2, 0.2, 1.0)
465 | eh = int((w - 260) / 9)
466 | ev = int((h - 99) / 9)
467 | # Draw vertical line
468 | for i in range(10):
469 | cr.move_to(i * eh, ev)
470 | cr.line_to(i * eh, ev * 9)
471 | # Draw horizontal line
472 | for i in range(9):
473 | cr.move_to(0, (i + 1) * ev)
474 | cr.line_to(eh * 9, (i + 1) * ev)
475 | cr.stroke()
476 | # Draw wire
477 | cr.select_font_face('Sans')
478 | cr.set_font_size(12)
479 | for l in link_color24:
480 | if l.sd in link_color24.current_wire:
481 | # Draw wire property for current wire
482 | cr.set_source_rgba(0.6, 0.4, 1.0, 1.0) # blue
483 | i = 0
484 | for p in l.prop:
485 | cr.move_to(i * 70, h - 70)
486 | cr.show_text(p + ': ' + str(l.prop[p]))
487 | i += 1
488 | cr.set_source_rgba(0.6, 0.4, 1.0, 1.0) # blue
489 | cr.set_line_width(6.0)
490 | else:
491 | cr.set_source_rgba(0.6, 0.4, 1.0, 1.0) # blue
492 | cr.set_line_width(2.0)
493 | if trace_l2 and (str(point2num(l.sd[0])) in node_tr and
494 | str(point2num(l.sd[1]))) in node_tr:
495 | cr.set_source_rgba(1.0, 1.0, 1.0, 0.5)
496 | (xi, yi), (xf, yf) = l.sd
497 | cr.move_to(xi * eh, yi * ev)
498 | cr.line_to(xf * eh, yf * ev)
499 | cr.stroke()
500 | for l in link_color50:
501 | if l.sd in link_color50.current_wire:
502 | # Draw wire property for current wire
503 | cr.set_source_rgba(0.6, 1.0, 0.0, 1.0) # green
504 | i = 0
505 | for p in l.prop:
506 | cr.move_to(i * 70, h - 57)
507 | cr.show_text(p + ': ' + str(l.prop[p]))
508 | i += 1
509 | cr.set_source_rgba(0.6, 1.0, 0.0, 0.5) # green
510 | cr.set_line_width(6.0)
511 | else:
512 | cr.set_source_rgba(0.6, 1.0, 0.0, 0.5) # green
513 | cr.set_line_width(2.0)
514 | if trace_l2 and (str(point2num(l.sd[0])) in node_tr and
515 | str(point2num(l.sd[1]))) in node_tr:
516 | cr.set_source_rgba(1.0, 1.0, 1.0, 0.5)
517 | (xi, yi), (xf, yf) = l.sd
518 | cr.move_to(xi * eh, yi * ev)
519 | cr.line_to(xf * eh, yf * ev)
520 | cr.stroke()
521 | # Draw nodo
522 | for po in nodolist:
523 | p = po.pos
524 | cr.arc(p[0] * eh, p[1] * ev, 12, 0, 2 * math.pi)
525 | cr.set_source_rgba(0.1, 0.6, 0.1, 1.0)
526 | if nodolist.run:
527 | if po.count == 0:
528 | mibr = netsnmp.Varbind('iso.3.6.1.4.1.2021.10.1.3.1')
529 | po.load_average = netsnmp.snmpget(mibr, Version=2,
530 | DestHost=po.smp_ip,
531 | Community='public',
532 | Timeout=5000, Retries=1)[0]
533 | if po.load_average is None:
534 | cr.set_source_rgba(0.6, 0.0, 0.0, 1.0)
535 | elif float(po.load_average) > 1:
536 | po.count = 10
537 | else:
538 | cr.set_source_rgba(0.1, 0.6, 0.1, 1.0)
539 | mibr = netsnmp.Varbind('iso.3.6.1.2.1.2.2.1.11')
540 | rx = netsnmp.snmpwalk(mibr, Version=2, DestHost=po.smp_ip,
541 | Community='public',
542 | Timeout=5000, Retries=1)
543 | mibr = netsnmp.Varbind('iso.3.6.1.2.1.2.2.1.17')
544 | tx = netsnmp.snmpwalk(mibr, Version=2, DestHost=po.smp_ip,
545 | Community='public',
546 | Timeout=5000, Retries=1)
547 | for i in po.interfases:
548 | if i.ind:
549 | if i.ind < len(rx):
550 | i.rx = rx[i.ind - 1]
551 | else:
552 | i.rx = '0'
553 | if i.ind < len(tx):
554 | i.tx = tx[i.ind - 1]
555 | else:
556 | i.tx = '0'
557 | else:
558 | po.count = po.count - 1
559 | cr.set_source_rgba(1.0, 0.0, 0.3, 1.0)
560 | if po.pos == nodolist.current.pos:
561 | cr.set_source_rgba(1.0, 1.0, 0.0, 1.0) # yellow
562 | cr.move_to(400, 30)
563 | cr.show_text('vm: ' + po.vm)
564 | # Draw originators for curren nodo
565 | if nodolist.run:
566 | cr.set_source_rgba(1.0, 1.0, 1.0, 1.0)
567 | cr.move_to(w - 251, 15)
568 | cr.show_text("Originators")
569 | cr.set_source_rgba(1.0, 1.0, 1.0, 1.0)
570 | cr.move_to(w - 251 + 125, 15)
571 | cr.show_text("Next Hop")
572 | # o,n = po.get_originators_nexthop()
573 | rg = len(o)
574 | if rg > len(n):
575 | rg = len(n)
576 | for i in range(rg):
577 | cr.set_source_rgba(0.0, 0.7, 0.7, 1.0)
578 | if i & 0x01:
579 | cr.set_source_rgba(0.0, 1.0, 1.0, 1.0)
580 | cr.move_to(w - 251, 40 + i * 15)
581 | cr.show_text(str(o[i]))
582 | cr.move_to(w - 251 + 125, 40 + i * 15)
583 | cr.show_text(str(n[i]))
584 | # Drow Interface packets for curren nodo
585 | for i in po.interfases:
586 | if i.ind:
587 | if i.ind < 4:
588 | cr.move_to(200 * (i.ind - 1), 15)
589 | cr.show_text(i.name + ' rx: ' + i.rx + ' tx: ' + i.tx)
590 | if i.ind > 3:
591 | cr.move_to(200 * (i.ind - 4), 30)
592 | cr.show_text(i.name + ' rx: ' + i.rx + ' tx: ' + i.tx)
593 | cr.set_source_rgba(0.3, 1.0, 0.3, 1.0)
594 | # else:
595 | # cr.set_source_rgba(0.1,0.6, 0.1,1.0)
596 | if trace_l2 and str(po) in node_tr:
597 | cr.set_source_rgba(1.0, 1.0, 1.0, 0.5)
598 | cr.fill()
599 | cr.stroke()
600 | # Draw bat0 packets for each nodo
601 | cr.set_source_rgb(0.0, 0.0, 0.1)
602 | cr.move_to(p[0] * eh - 7, p[1] * ev + 5)
603 | cr.show_text(str(po))
604 | if nodolist.run:
605 | cr.move_to(p[0] * eh - 30, p[1] * ev + 18)
606 | cr.set_source_rgb(0.0, 1.0, 0.1)
607 | cr.show_text('Rx:' + str(po.bat0.rx))
608 | cr.move_to(p[0] * eh - 30, p[1] * ev - 13)
609 | cr.show_text('Tx:' + str(po.bat0.tx))
610 | cr.stroke()
611 | if trace_l2:
612 | x = -60
613 | y = h - 36
614 | cr.set_line_width(1.0)
615 | for i in node_tr:
616 | if len(i) == 2:
617 | x = x + 80
618 | if x > w - 301:
619 | x = 20
620 | y = y + 24
621 | cr.set_source_rgba(0.0, 1.0, 0.0, 1.0)
622 | cr.move_to(x + 12, y)
623 | cr.arc(x, y, 12, 0, 2 * math.pi)
624 | cr.move_to(x - 7, y + 5)
625 | cr.show_text(i)
626 | elif '.' in i:
627 | cr.set_source_rgba(1.0, 1.0, 0.0, 1.0)
628 | cr.move_to(x + 14, y + 5)
629 | cr.show_text(i)
630 | else:
631 | cr.set_source_rgba(1.0, 0.0, 0.0, 1.0)
632 | cr.move_to(x + 14, y + 5)
633 | cr.show_text('too delay')
634 | cr.stroke()
635 |
636 |
637 | # Redraw the screen from the backing pixmap
638 | def expose_event(widget, event):
639 | ti = time.time()
640 | dibujar(widget)
641 | tf = time.time()
642 | # print tf-ti
643 | return False
644 |
645 |
646 | def button_press_event(widget, event):
647 | global inicio
648 | w = widget.allocation.width
649 | h = widget.allocation.height
650 | eh = int((w - 260) / 9)
651 | ev = int((h - 99) / 9)
652 | if cr is not None:
653 | inicio = near((event.x, event.y), eh, ev)
654 | return True
655 |
656 |
657 | def button_release_event(widget, event):
658 | global wire_prop, trace_l2, node_tr, o, n
659 | w = widget.allocation.width
660 | h = widget.allocation.height
661 | eh = int((w - 260) / 9)
662 | ev = int((h - 99) / 9)
663 | fin = near((event.x, event.y), eh, ev)
664 | if fin[0] < 10 and fin[0] > 1 / 2 and fin[1] < 10 and fin[1] > 1 / 2:
665 | if event.button == 1 and cr is not None:
666 | if inicio == fin:
667 | if not nodolist.run and not any(x.pos == inicio for x in nodolist):
668 | nodolist.append(NodoClass(inicio))
669 | nodolist.set_cur_pos(inicio)
670 | elif any(x.pos == inicio for x in nodolist) and any(x.pos == fin for x in nodolist):
671 | if nodolist.run and trace_l2:
672 | for x in nodolist:
673 | if x.pos == fin:
674 | trace_fin_mac = str(x.bat0.mac)
675 | if x.pos == inicio:
676 | trace_nicio_ip = str(x.eth0.ip)
677 | pos_ini = str(x)
678 | l = []
679 | mibr = netsnmp.Varbind('iso', '3.6.1.4.1.32.1.4', trace_fin_mac, 'OCTETSTR')
680 | orig = netsnmp.snmpset(mibr, Version=2, DestHost=trace_nicio_ip, Community='private', Timeout=10000000, Retries=1)
681 | mibr = netsnmp.Varbind('iso.3.6.1.4.1.32.1.4')
682 | orig = netsnmp.snmpget(mibr, Version=2, DestHost=trace_nicio_ip, Community='private', Timeout=1000000, Retries=1)
683 | for i in str(orig[0]).split():
684 | l.append(i.split(':')[-1:])
685 | node_tr = reduce(lambda x, y: x + y, l)
686 | node_tr.insert(0, pos_ini)
687 | else:
688 | link_color24.current_wire = [(inicio, fin), (fin, inicio)]
689 | link_color50.current_wire = [(inicio, fin), (fin, inicio)]
690 | if wire_prop['ch'] == '24GHz':
691 | if (not any(x.sd in link_color24.current_wire for x in link_color24)):
692 | link_color24.append(WireClass(inicio, fin, wire_prop))
693 | if nodolist.run:
694 | link_color24.start()
695 | link_color50.start()
696 | if wire_prop['ch'] == '50GHz':
697 | if (not any(x.sd in link_color50.current_wire for x in link_color50)):
698 | link_color50.append(WireClass(inicio, fin, wire_prop))
699 | if nodolist.run:
700 | link_color24.start()
701 | link_color50.start()
702 | if event.button == 2 and cr is not None:
703 | if inicio == fin:
704 | if any(x.pos == inicio for x in nodolist):
705 | nodolist.set_cur_pos(inicio)
706 | if nodolist.run:
707 | for x in nodolist:
708 | if x.pos == fin:
709 | o, n = x.get_originators_nexthop()
710 | else:
711 | link_color24.current_wire = [(inicio, fin), (fin, inicio)]
712 | if wire_prop['ch'] == '24GHz':
713 | if any(x.pos in [inicio, fin] for x in nodolist):
714 | if any(x.sd in link_color24.current_wire for x in link_color24):
715 | for x in link_color24:
716 | if x.ds in link_color24.current_wire:
717 | wire_prop = x.prop
718 | link_color50.current_wire = [(inicio, fin), (fin, inicio)]
719 | if wire_prop['ch'] == '50GHz':
720 | if any(x.pos in [inicio, fin] for x in nodolist):
721 | if any(x.sd in link_color50.current_wire for x in link_color50):
722 | for x in link_color50:
723 | if x.ds in link_color50.current_wire:
724 | wire_prop = x.prop
725 |
726 | elif event.button == 3 and cr is not None:
727 | if inicio == fin:
728 | if not nodolist.run:
729 | if any(x.pos == inicio for x in nodolist):
730 | for x in nodolist:
731 | if x.pos == inicio:
732 | nid = nodolist.index(x)
733 | i = nodolist.pop(nid)
734 | elif any(x.pos == inicio for x in nodolist) and any(x.pos == fin for x in nodolist):
735 | if wire_prop['ch'] == '24GHz':
736 | for x in link_color24:
737 | if x.sd in [(inicio, fin), (fin, inicio)]:
738 | lid = link_color24.index(x)
739 | i = link_color24.pop(lid)
740 | if wire_prop['ch'] == '50GHz':
741 | for x in link_color50:
742 | if x.sd in [(inicio, fin), (fin, inicio)]:
743 | lid = link_color50.index(x)
744 | i = link_color50.pop(lid)
745 |
746 | dibujar(widget)
747 | return True
748 |
749 |
750 | def select_vm(signal):
751 | window = gtk.Window()
752 | window.connect('destroy', lambda w: select_vm)
753 | window.set_title("SELECT VIRTUAL MACHINE")
754 | combobox = gtk.combo_box_new_text()
755 | window.add(combobox)
756 | virtual_box_manager = vboxapi.VirtualBoxManager(None, None)
757 | vbox = virtual_box_manager.vbox
758 | vbox_vm_list = virtual_box_manager.getArray(vbox, 'machines')
759 | vbox_name_list = [mach.name for mach in vbox_vm_list]
760 | for i in vbox_name_list:
761 | combobox.append_text(str(i))
762 | combobox.connect('changed', changed_cb)
763 | combobox.set_active(0)
764 | window.set_position(gtk.WIN_POS_CENTER)
765 | window.show_all()
766 | return
767 |
768 |
769 | def changed_cb(combobox):
770 | global v_name_base
771 | model = combobox.get_model()
772 | index = combobox.get_active()
773 | if index:
774 | v_name_base = model[index][0]
775 | return
776 |
777 |
778 | def wire_show(signal):
779 | Wire()
780 |
781 |
782 | def menuitem_response():
783 | return
784 |
785 |
786 | def scale_set_default_values(scale):
787 | scale.set_update_policy(gtk.UPDATE_CONTINUOUS)
788 | scale.set_digits(1)
789 | scale.set_value_pos(gtk.POS_TOP)
790 | scale.set_draw_value(True)
791 |
792 |
793 | def on_changed(widget):
794 | global wire_prop
795 | val = widget.get_value()
796 | name = widget.get_name()
797 | wire_prop[name] = int(val)
798 |
799 |
800 | def callback(self, button):
801 | global wire_prop
802 | wire_prop['ch'] = button
803 |
804 |
805 | class Wire(gtk.Window):
806 | def __init__(self):
807 | super(Wire, self).__init__()
808 | self.set_size_request(400, 700)
809 | self.set_border_width(10)
810 | self.set_title("WIREFILTER SETUP")
811 | self.connect("delete_event", lambda w, e: self.destroy())
812 |
813 | vbox_app = gtk.VBox(False, 0)
814 | self.add(vbox_app)
815 | vbox_app.show()
816 | vbox1 = gtk.VBox(False, 0)
817 |
818 | label1 = gtk.Label("Percentage of loss: ")
819 | vbox1.pack_start(label1, True, True, 0)
820 | label1.show()
821 |
822 | adj1 = gtk.Adjustment(wire_prop['lo'], 0.0, 101.0, 1.0, 1.0, 1.0)
823 | vscale1 = gtk.HScale(adj1)
824 | scale_set_default_values(vscale1)
825 | vscale1.set_name('lo')
826 | vbox1.pack_start(vscale1, True, True, 0)
827 | vscale1.connect("value-changed", on_changed)
828 | vscale1.show()
829 |
830 | label1 = gtk.Label("Extra delay in milliseconds: ")
831 | vbox1.pack_start(label1, True, True, 0)
832 | label1.show()
833 |
834 | adj2 = gtk.Adjustment(wire_prop['de'], 0.0, 1001.0, 1.0, 1.0, 1.0)
835 | vscale2 = gtk.HScale(adj2)
836 | scale_set_default_values(vscale2)
837 | vscale2.set_name('de')
838 | vbox1.pack_start(vscale2, True, True, 0)
839 | vscale2.connect("value-changed", on_changed)
840 | vscale2.show()
841 |
842 | label1 = gtk.Label("dup percentage of dup packet: ")
843 | vbox1.pack_start(label1, True, True, 0)
844 | label1.show()
845 |
846 | adj3 = gtk.Adjustment(wire_prop['du'], 0.0, 101.0, 1.0, 1.0, 1.0)
847 | vscale3 = gtk.HScale(adj3)
848 | scale_set_default_values(vscale3)
849 | vscale3.set_name('du')
850 | vbox1.pack_start(vscale3, True, True, 0)
851 | vscale3.connect("value-changed", on_changed)
852 | vscale3.show()
853 |
854 | label1 = gtk.Label("Channel bandwidth in Bytes/sec: ")
855 | vbox1.pack_start(label1, True, True, 0)
856 | label1.show()
857 |
858 | adj4 = gtk.Adjustment(wire_prop['bw'], 0.0, 1001.0, 1.0, 1.0, 1.0)
859 | vscale4 = gtk.HScale(adj4)
860 | scale_set_default_values(vscale4)
861 | vscale4.set_name('bw')
862 | vbox1.pack_start(vscale4, True, True, 0)
863 | vscale4.connect("value-changed", on_changed)
864 | vscale4.show()
865 |
866 | label1 = gtk.Label("Interface speed in Bytes/sec: ")
867 | vbox1.pack_start(label1, True, True, 0)
868 | label1.show()
869 |
870 | adj5 = gtk.Adjustment(wire_prop['sp'], 0.0, 1001.0, 1.0, 1.0, 1.0)
871 | vscale5 = gtk.HScale(adj5)
872 | scale_set_default_values(vscale5)
873 | vscale5.set_name('sp')
874 | vbox1.pack_start(vscale5, True, True, 0)
875 | vscale5.connect("value-changed", on_changed)
876 | vscale5.show()
877 |
878 | label1 = gtk.Label("Channel capacity in Bytes: ")
879 | vbox1.pack_start(label1, True, True, 0)
880 | label1.show()
881 |
882 | adj6 = gtk.Adjustment(wire_prop['ca'], 0.0, 1001.0, 1.0, 1.0, 1.0)
883 | vscale6 = gtk.HScale(adj6)
884 | scale_set_default_values(vscale6)
885 | vscale6.set_name('ca')
886 | vbox1.pack_start(vscale6, True, True, 0)
887 | vscale6.connect("value-changed", on_changed)
888 | vscale6.show()
889 |
890 | label1 = gtk.Label("Number bits damaged/Megabyte: ")
891 | vbox1.pack_start(label1, True, True, 0)
892 | label1.show()
893 |
894 | adj7 = gtk.Adjustment(wire_prop['da'], 0.0, 101.0, 1.0, 1.0, 1.0)
895 | vscale7 = gtk.HScale(adj7)
896 | scale_set_default_values(vscale7)
897 | vscale7.set_name('da')
898 | vbox1.pack_start(vscale7, True, True, 0)
899 | vscale7.connect("value-changed", on_changed)
900 | vscale7.show()
901 |
902 | hbox1 = gtk.HBox(gtk.FALSE, 0)
903 | hbox1.set_border_width(10)
904 | vbox1.pack_start(hbox1, gtk.TRUE, gtk.TRUE, 0)
905 | hbox1.show()
906 |
907 | button = gtk.RadioButton(None, "2.4 GHz")
908 | button.connect("toggled", callback, "24GHz")
909 | if wire_prop['ch'] == "24GHz":
910 | button.set_active(gtk.TRUE)
911 | hbox1.pack_start(button, gtk.TRUE, gtk.TRUE, 0)
912 | button.show()
913 | button = gtk.RadioButton(button, "5.0 GHz")
914 | button.connect("toggled", callback, "50GHz")
915 | if wire_prop['ch'] == "50GHz":
916 | button.set_active(gtk.TRUE)
917 | hbox1.pack_start(button, gtk.TRUE, gtk.TRUE, 0)
918 | button.show()
919 |
920 | button_set = gtk.Button(stock=gtk.STOCK_OK)
921 | button_set.connect("clicked", lambda w: self.destroy())
922 | button_set.set_flags(gtk.CAN_DEFAULT)
923 | hbox1.pack_start(button_set, True, True, 0)
924 | button_set.show()
925 |
926 | button_close = gtk.Button(stock=gtk.STOCK_CLOSE)
927 | button_close.connect("clicked", lambda w: self.destroy())
928 | button_close.set_flags(gtk.CAN_DEFAULT)
929 | hbox1.pack_start(button_close, True, True, 0)
930 | button_close.show()
931 |
932 | vbox1.show()
933 | vbox_app.add(vbox1)
934 | button_close.grab_default()
935 | self.set_position(gtk.WIN_POS_CENTER)
936 | self.show()
937 |
938 |
939 | def get_mesh(dir_trabajo):
940 | global nodolist, link_color24, link_color50
941 | dm = dir_trabajo + '/data.ms'
942 | if os.path.isfile('data.ms'):
943 | with open(dm, 'rb') as f:
944 | nodolist, link_color24, link_color50 = pickle.load(f)
945 |
946 |
947 | def create_colorfull(dir_trabajo):
948 | f = open(dir_trabajo + '/colourful.rc', 'w')
949 | f.write('port/setcolourful 1\n')
950 | f.write('port/create 1\n')
951 | f.write('port/create 2\n')
952 | f.write('port/create 3\n')
953 | f.write('port/create 4\n')
954 | f.write('port/create 5\n')
955 | f.write('port/setcolour 1 1\n')
956 | f.write('port/setcolour 2 2\n')
957 | f.write('port/setcolour 3 2\n')
958 | f.close()
959 |
960 |
961 | class MenuApp(gtk.Window):
962 | def __init__(self):
963 | super(MenuApp, self).__init__()
964 | screen = self.get_screen()
965 | self.set_title("Mesh network emulator")
966 | self.set_size_request(min(screen.get_width(), 800),
967 | min(screen.get_height(), 600))
968 | # self.maximize()
969 | self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(6400, 6400, 6440))
970 | self.set_position(gtk.WIN_POS_CENTER)
971 | # top level menu bar
972 | menubar = gtk.MenuBar()
973 |
974 | # top items on the menu bar
975 | filem = gtk.MenuItem("File")
976 | editm = gtk.MenuItem("Edit")
977 | runm = gtk.MenuItem("Run/Stop")
978 | toolsm = gtk.MenuItem("Tools")
979 | aboutm = gtk.MenuItem("About")
980 |
981 | # now, create for FILE item the menu
982 | filemenu = gtk.Menu()
983 | filem.set_submenu(filemenu)
984 |
985 | # create the items for File menu
986 | new = gtk.MenuItem("New")
987 | filemenu.append(new)
988 | new.connect("activate", select_folder)
989 |
990 | open = gtk.MenuItem("Open")
991 | filemenu.append(open)
992 | open.connect("activate", open_mesh)
993 |
994 | save = gtk.MenuItem("Save")
995 | filemenu.append(save)
996 | save.connect("activate", save_mesh)
997 |
998 | saveas = gtk.MenuItem("Save as")
999 | filemenu.append(saveas)
1000 | saveas.connect("activate", save_as_mesh)
1001 | # separator
1002 | separat = gtk.SeparatorMenuItem()
1003 | filemenu.append(separat)
1004 |
1005 | # now, Quit item with accelerator and image
1006 | # generic accelerator
1007 | agr = gtk.AccelGroup()
1008 | self.add_accel_group(agr)
1009 |
1010 | quit_img = gtk.ImageMenuItem(gtk.STOCK_QUIT, agr)
1011 | key, mod = gtk.accelerator_parse("Q")
1012 | quit_img.add_accelerator("activate", agr, key, mod, gtk.ACCEL_VISIBLE)
1013 | filemenu.append(quit_img)
1014 |
1015 | # connect to Quit the activate event
1016 | quit_img.connect("activate", gtk.main_quit)
1017 |
1018 | # create the edit menu and attach it to the top item
1019 | editmenu = gtk.Menu()
1020 | editm.set_submenu(editmenu)
1021 |
1022 | # create the items for Edit menu
1023 | delmesh = gtk.MenuItem("Delete Mesh")
1024 | editmenu.append(delmesh)
1025 | delmesh.connect("activate", delete_mesh)
1026 |
1027 | delnodo = gtk.MenuItem("Delete Nodo")
1028 | editmenu.append(delnodo)
1029 | delnodo.connect("activate", remover_nodos)
1030 |
1031 | dellink = gtk.MenuItem("Delete Link")
1032 | editmenu.append(dellink)
1033 | dellink.connect("activate", remover_enlaces)
1034 |
1035 | editwire = gtk.MenuItem("Edit Wire")
1036 | editmenu.append(editwire)
1037 | editwire.connect("activate", wire_show)
1038 |
1039 | selectvm = gtk.MenuItem("Select VM")
1040 | editmenu.append(selectvm)
1041 | selectvm.connect("activate", select_vm)
1042 |
1043 | # create the run menu and attach it to the top item
1044 | runmenu = gtk.Menu()
1045 | runm.set_submenu(runmenu)
1046 |
1047 | # create the items for Run menu
1048 | run = gtk.MenuItem("Run")
1049 | runmenu.append(run)
1050 | run.connect("activate", run_mesh)
1051 |
1052 | stop = gtk.MenuItem("Stop")
1053 | runmenu.append(stop)
1054 | stop.connect("activate", stop_mesh)
1055 |
1056 | # create the tools menu and attach it to the top item
1057 | toolsmenu = gtk.Menu()
1058 | toolsm.set_submenu(toolsmenu)
1059 |
1060 | # create the items for Run menu
1061 | trace = gtk.CheckMenuItem("Trace route on")
1062 | trace.set_active(False)
1063 | toolsmenu.append(trace)
1064 | trace.connect("activate", traceon)
1065 |
1066 | head = gtk.CheckMenuItem("VM Headless on")
1067 | head.set_active(False)
1068 | toolsmenu.append(head)
1069 | head.connect("activate", headon)
1070 |
1071 | # append the top items
1072 | menubar.append(filem)
1073 | menubar.append(editm)
1074 | menubar.append(runm)
1075 | menubar.append(toolsm)
1076 | menubar.append(aboutm)
1077 |
1078 | # pack in a vbox
1079 | vbox = gtk.VBox(False, 2)
1080 | vbox.pack_start(menubar, False, False, 0)
1081 |
1082 | # Create the drawing area
1083 | drawing_area = gtk.DrawingArea()
1084 | drawing_area.set_size_request(1000, 1000)
1085 | drawing_area.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(0, 0, 0))
1086 | vbox.pack_start(drawing_area, True, True, 0)
1087 | drawing_area.show()
1088 |
1089 | # Signals used to handle backing pixmap
1090 | drawing_area.connect("expose_event", expose_event)
1091 | drawing_area.connect("configure_event", configure_event)
1092 |
1093 | # Event signals
1094 |
1095 | drawing_area.connect("button_press_event", button_press_event)
1096 | drawing_area.connect("button_release_event", button_release_event)
1097 |
1098 | drawing_area.set_events(gtk.gdk.EXPOSURE_MASK |
1099 | gtk.gdk.LEAVE_NOTIFY_MASK |
1100 | gtk.gdk.BUTTON_PRESS_MASK |
1101 | gtk.gdk.BUTTON_RELEASE_MASK |
1102 | gtk.gdk.BUTTON3_MOTION_MASK |
1103 | gtk.gdk.POINTER_MOTION_MASK |
1104 | gtk.gdk.POINTER_MOTION_HINT_MASK)
1105 |
1106 | # add the vbox to the window
1107 | self.add(vbox)
1108 | self.connect("destroy", gtk.main_quit)
1109 |
1110 | self.show_all()
1111 | gobject.timeout_add(2000, self.tick)
1112 | # gobject.idle_add(self.tick )
1113 | global password
1114 | password = get_password()
1115 | global dir_trabajo
1116 | dir_trabajo = os.getcwd()
1117 | if not os.path.isfile('colourful.rc'):
1118 | create_colorfull(dir_trabajo)
1119 | get_mesh(dir_trabajo)
1120 |
1121 | def tick(self):
1122 | self.queue_draw()
1123 | return True
1124 |
1125 |
1126 | MenuApp()
1127 |
1128 | gtk.main()
1129 |
--------------------------------------------------------------------------------
/vde2-2.3.2-patch.tar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dbritos/Network-mesh-emulator/c2eb1d1c279d61b66fa9bc280f942fc2d15d1462/vde2-2.3.2-patch.tar
--------------------------------------------------------------------------------