-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathinterface.py
More file actions
66 lines (56 loc) · 1.76 KB
/
interface.py
File metadata and controls
66 lines (56 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from networkx import exception
from node import Node
class Interface:
"""A class for interface model"""
def __init__(
self,
target: Node,
metric: int,
local_ip: str,
util: float,
capacity: int,
remote_ip: str = None,
linknum: int = 1,
latency: int = 0,
):
self.target = target
self.metric = metric
self.util = 0 # util
self.capacity = capacity
self.local_ip = local_ip
self.remote_ip = remote_ip
self._failed = False
self._on_spf = False
self.link_num = linknum
self.latency = latency
self.highlight = False
def __repr__(self):
return self.local_ip
def _networkX(self):
return {"metric": self.metric}
def utilization(self):
"""Returns utilization percent = (self.traffic/self.capacity)*100 """
if self.capacity == 0:
return 0
else:
return round((self.util / self.capacity) * 100, 3)
def get_label(self):
return str(self.local_ip)
def failInterface(self):
"""TODO fail the other end of the interafce ? """
self._failed = True
self.util = 0
for interface in self.target.interfaces:
if interface.remote_ip == self.local_ip:
interface._failed = True
interface.util = 0
def unfailInterface(self):
"""TODO fail the other end of the interafce ? """
self._failed = False
self.util = 0
for interface in self.target.interfaces:
if interface.remote_ip == self.local_ip:
interface._failed = False
interface.util = 0
def change_metric(self, value):
self.metric = value