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
2
Issues
2
List
Boards
Labels
Milestones
Merge Requests
4
Merge Requests
4
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
nexedi
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:
os
.
O_WRONLY
|
os
.
O_CREAT
|
os
.
O_TRUNC
)
)
self
.
iface
=
iface
self
.
_lastTrafic
=
self
.
_getTrafic
()
self
.
_bandwidth
=
None
self
.
_prefix
=
prefix
self
.
_creation_date
=
time
.
time
()
self
.
_bandwidth
=
None
self
.
_last_trafic
=
None
# TODO : update the stats
def
refresh
(
self
):
...
...
@@ -25,23 +26,35 @@ class Connection:
%
(
self
.
_prefix
,
self
.
process
.
returncode
),
3
)
return
False
trafic
=
self
.
_getTrafic
()
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
)
self
.
_updateBandwidth
()
return
True
def
_
getTrafic
(
self
):
def
_
updateBandwidth
(
self
):
try
:
f_rx
=
open
(
'/sys/class/net/%s/statistics/rx_bytes'
%
self
.
iface
,
'r'
)
f_tx
=
open
(
'/sys/class/net/%s/statistics/tx_bytes'
%
self
.
iface
,
'r'
)
return
int
(
f_rx
.
read
())
+
int
(
f_tx
.
read
())
except
Exception
:
return
0
f_rx
=
open
(
'/sys/class/net/%s/statistics/rx_bytes'
%
self
.
iface
,
'r'
)
f_tx
=
open
(
'/sys/class/net/%s/statistics/tx_bytes'
%
self
.
iface
,
'r'
)
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
:
...
...
vifibnet.py
View file @
f233c4d7
...
...
@@ -61,8 +61,8 @@ def getConfig():
# args to be removed ?
_
(
'--proto'
,
default
=
'udp'
,
help
=
'The protocol used by other peers to connect'
)
_
(
'--connection-count'
,
default
=
3
0
,
type
=
int
,
help
=
'Number of
client connection
s'
)
_
(
'--connection-count'
,
default
=
2
0
,
type
=
int
,
help
=
'Number of
tunnel
s'
)
_
(
'--refresh-rate'
,
default
=
0.05
,
type
=
float
,
help
=
'The ratio of connections to drop when refreshing the connections'
)
# 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