Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pim_dm
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
pim_dm
Commits
05a69151
Commit
05a69151
authored
Jul 23, 2017
by
Pedro Oliveira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
uptime neighbor
parent
ddf6baad
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
3 deletions
+10
-3
Main.py
Main.py
+7
-3
Neighbor.py
Neighbor.py
+3
-0
No files found.
Main.py
View file @
05a69151
import
netifaces
import
time
from
prettytable
import
PrettyTable
from
Interface
import
Interface
...
...
@@ -57,11 +57,15 @@ def add_protocol(protocol_number, protocol_obj):
def
list_neighbors
():
global
neighbors
t
=
PrettyTable
([
'Neighbor IP'
,
'KeepAlive'
,
"Generation ID"
])
check_time
=
time
.
time
()
t
=
PrettyTable
([
'Neighbor IP'
,
'KeepAlive'
,
"Generation ID"
,
"Uptime"
])
for
ip
,
neighbor
in
list
(
neighbors
.
items
()):
import
socket
,
struct
# TODO atualmente conversao manual de numero para string ip
ip
=
socket
.
inet_ntoa
(
struct
.
pack
(
'!L'
,
ip
))
t
.
add_row
([
ip
,
neighbor
.
keep_alive_period
,
neighbor
.
generation_id
])
uptime
=
check_time
-
neighbor
.
time_of_last_update
uptime
=
0
if
(
uptime
<
0
)
else
uptime
t
.
add_row
([
ip
,
neighbor
.
keep_alive_period
,
neighbor
.
generation_id
,
time
.
strftime
(
"%H:%M:%S"
,
time
.
gmtime
(
uptime
))])
print
(
t
)
return
str
(
t
)
...
...
Neighbor.py
View file @
05a69151
from
threading
import
Timer
import
time
from
utils
import
KEEP_ALIVE_PERIOD_NO_TIMEOUT
,
KEEP_ALIVE_PERIOD_TIMEOUT
from
Interface
import
Interface
import
Main
...
...
@@ -10,6 +11,7 @@ class Neighbor:
self
.
generation_id
=
generation_id
self
.
neighbor_liveness_timer
=
None
self
.
set_keep_alive_period
(
keep_alive_period
)
self
.
time_of_last_update
=
time
.
time
()
def
set_keep_alive_period
(
self
,
keep_alive_period
:
int
):
self
.
keep_alive_period
=
keep_alive_period
...
...
@@ -32,6 +34,7 @@ class Neighbor:
self
.
neighbor_liveness_timer
.
cancel
()
self
.
neighbor_liveness_timer
=
Timer
(
4
*
self
.
keep_alive_period
,
self
.
remove
)
self
.
neighbor_liveness_timer
.
start
()
self
.
time_of_last_update
=
time
.
time
()
def
remove
(
self
):
print
(
'HELLO TIMER EXPIRED... remove neighbor'
)
...
...
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