Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
re6stnet
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
zhifan huang
re6stnet
Commits
f233c4d7
Commit
f233c4d7
authored
Jul 20, 2012
by
Ulysse Beaugnon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better calculation of the bandidth
parent
8e011be5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
18 deletions
+31
-18
tunnel.py
tunnel.py
+29
-16
vifibnet.py
vifibnet.py
+2
-2
No files found.
tunnel.py
View file @
f233c4d7
...
@@ -13,9 +13,10 @@ class Connection:
...
@@ -13,9 +13,10 @@ class Connection:
os
.
O_WRONLY
|
os
.
O_CREAT
|
os
.
O_TRUNC
)
)
os
.
O_WRONLY
|
os
.
O_CREAT
|
os
.
O_TRUNC
)
)
self
.
iface
=
iface
self
.
iface
=
iface
self
.
_lastTrafic
=
self
.
_getTrafic
()
self
.
_bandwidth
=
None
self
.
_prefix
=
prefix
self
.
_prefix
=
prefix
self
.
_creation_date
=
time
.
time
()
self
.
_bandwidth
=
None
self
.
_last_trafic
=
None
# TODO : update the stats
# TODO : update the stats
def
refresh
(
self
):
def
refresh
(
self
):
...
@@ -25,23 +26,35 @@ class Connection:
...
@@ -25,23 +26,35 @@ class Connection:
%
(
self
.
_prefix
,
self
.
process
.
returncode
),
3
)
%
(
self
.
_prefix
,
self
.
process
.
returncode
),
3
)
return
False
return
False
trafic
=
self
.
_getTrafic
()
self
.
_updateBandwidth
()
if
self
.
_bandwidth
==
None
:
self
.
_bandwidth
=
trafic
-
self
.
_lastTrafic
else
:
self
.
_bandwidth
=
(
1
-
smooth
)
*
self
.
_bandwidth
+
smooth
*
trafic
self
.
_lastTrafic
=
trafic
utils
.
log
(
'New bandwidth calculated on iface %s : %sb'
%
self
.
_bandwidth
,
4
)
return
True
return
True
def
_
getTrafic
(
self
):
def
_
updateBandwidth
(
self
):
try
:
try
:
f_rx
=
open
(
'/sys/class/net/%s/statistics/rx_bytes'
%
self
.
iface
,
'r'
)
f_rx
=
open
(
'/sys/class/net/%s/statistics/rx_bytes'
%
f_tx
=
open
(
'/sys/class/net/%s/statistics/tx_bytes'
%
self
.
iface
,
'r'
)
self
.
iface
,
'r'
)
return
int
(
f_rx
.
read
())
+
int
(
f_tx
.
read
())
f_tx
=
open
(
'/sys/class/net/%s/statistics/tx_bytes'
%
except
Exception
:
self
.
iface
,
'r'
)
return
0
trafic
=
int
(
f_rx
.
read
())
+
int
(
f_tx
.
read
())
t
=
time
.
time
()
if
bool
(
self
.
_last_trafic
):
bw
=
(
trafic
-
self
.
_last_trafic
)
/
(
t
-
self
.
_last_trafic_update
)
if
bool
(
self
.
_bandwidth
):
self
.
_bandwidth
=
(
1
-
smooth
)
*
self
.
_bandwidth
+
smooth
*
bw
else
:
self
.
_bandwidth
=
bw
utils
.
log
(
'New bandwidth calculated on iface %s : %s'
%
(
self
.
iface
,
self
.
_bandwidth
),
4
)
self
.
_last_trafic_update
=
t
self
.
_last_trafic
=
trafic
except
IOError
:
# This just means that the interface is downs
utils
.
log
(
'Unable to calculate bandwidth on iface %s'
%
self
.
iface
,
4
)
class
TunnelManager
:
class
TunnelManager
:
...
...
vifibnet.py
View file @
f233c4d7
...
@@ -61,8 +61,8 @@ def getConfig():
...
@@ -61,8 +61,8 @@ def getConfig():
# args to be removed ?
# args to be removed ?
_
(
'--proto'
,
default
=
'udp'
,
_
(
'--proto'
,
default
=
'udp'
,
help
=
'The protocol used by other peers to connect'
)
help
=
'The protocol used by other peers to connect'
)
_
(
'--connection-count'
,
default
=
3
0
,
type
=
int
,
_
(
'--connection-count'
,
default
=
2
0
,
type
=
int
,
help
=
'Number of
client connection
s'
)
help
=
'Number of
tunnel
s'
)
_
(
'--refresh-rate'
,
default
=
0.05
,
type
=
float
,
_
(
'--refresh-rate'
,
default
=
0.05
,
type
=
float
,
help
=
'The ratio of connections to drop when refreshing the connections'
)
help
=
'The ratio of connections to drop when refreshing the connections'
)
# Openvpn options
# Openvpn options
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment