Commit 05a69151 authored by Pedro Oliveira's avatar Pedro Oliveira

uptime neighbor

parent ddf6baad
import netifaces import netifaces
import time
from prettytable import PrettyTable from prettytable import PrettyTable
from Interface import Interface from Interface import Interface
...@@ -57,11 +57,15 @@ def add_protocol(protocol_number, protocol_obj): ...@@ -57,11 +57,15 @@ def add_protocol(protocol_number, protocol_obj):
def list_neighbors(): def list_neighbors():
global 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()): for ip, neighbor in list(neighbors.items()):
import socket, struct # TODO atualmente conversao manual de numero para string ip import socket, struct # TODO atualmente conversao manual de numero para string ip
ip = socket.inet_ntoa(struct.pack('!L', 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) print(t)
return str(t) return str(t)
......
from threading import Timer from threading import Timer
import time
from utils import KEEP_ALIVE_PERIOD_NO_TIMEOUT, KEEP_ALIVE_PERIOD_TIMEOUT from utils import KEEP_ALIVE_PERIOD_NO_TIMEOUT, KEEP_ALIVE_PERIOD_TIMEOUT
from Interface import Interface from Interface import Interface
import Main import Main
...@@ -10,6 +11,7 @@ class Neighbor: ...@@ -10,6 +11,7 @@ class Neighbor:
self.generation_id = generation_id self.generation_id = generation_id
self.neighbor_liveness_timer = None self.neighbor_liveness_timer = None
self.set_keep_alive_period(keep_alive_period) 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): def set_keep_alive_period(self, keep_alive_period: int):
self.keep_alive_period = keep_alive_period self.keep_alive_period = keep_alive_period
...@@ -32,6 +34,7 @@ class Neighbor: ...@@ -32,6 +34,7 @@ class Neighbor:
self.neighbor_liveness_timer.cancel() self.neighbor_liveness_timer.cancel()
self.neighbor_liveness_timer = Timer(4 * self.keep_alive_period, self.remove) self.neighbor_liveness_timer = Timer(4 * self.keep_alive_period, self.remove)
self.neighbor_liveness_timer.start() self.neighbor_liveness_timer.start()
self.time_of_last_update = time.time()
def remove(self): def remove(self):
print('HELLO TIMER EXPIRED... remove neighbor') print('HELLO TIMER EXPIRED... remove neighbor')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment