1
|
|
|
"""Kytos Core-Defined Exceptions.""" |
2
|
|
|
|
3
|
|
|
|
4
|
1 |
|
class KytosCoreException(Exception): |
5
|
|
|
"""Exception thrown when KytosCore is broken.""" |
6
|
|
|
|
7
|
1 |
|
def __str__(self): |
8
|
|
|
"""Return message of KytosCoreException.""" |
9
|
|
|
return 'KytosCore exception: ' + super().__str__() |
10
|
|
|
|
11
|
|
|
|
12
|
1 |
|
class KytosSwitchOfflineException(Exception): |
13
|
|
|
"""Exception thrown when a switch is offline.""" |
14
|
|
|
|
15
|
1 |
|
def __init__(self, switch): |
16
|
|
|
"""Require a switch. |
17
|
|
|
|
18
|
|
|
Args: |
19
|
|
|
switch (:class:`~kytos.core.switch.Switch`): A switch offline. |
20
|
|
|
""" |
21
|
|
|
super().__init__() |
22
|
|
|
self.switch = switch |
23
|
|
|
|
24
|
1 |
|
def __str__(self): |
25
|
|
|
"""Return message of KytosSwitchOfflineException.""" |
26
|
|
|
msg = 'The switch {} is not reachable. Please check the connection ' |
27
|
|
|
msg += 'between the switch and the controller.' |
28
|
|
|
return msg.format(self.switch.dpid) |
29
|
|
|
|
30
|
|
|
|
31
|
1 |
|
class KytosEventException(Exception): |
32
|
|
|
"""Exception thrown when a KytosEvent have an illegal use.""" |
33
|
|
|
|
34
|
1 |
|
def __init__(self, message="KytosEvent exception", event=None): |
35
|
|
|
"""Assign parameters to instance variables. |
36
|
|
|
|
37
|
|
|
Args: |
38
|
|
|
message (string): message from KytosEventException. |
39
|
|
|
event (:class:`~kytos.core.events.KytosEvent`): Event malformed. |
40
|
|
|
""" |
41
|
|
|
super().__init__() |
42
|
|
|
self.message = message |
43
|
|
|
self.event = event |
44
|
|
|
|
45
|
1 |
|
def __str__(self): |
46
|
|
|
"""Return the full message from KytosEventException.""" |
47
|
|
|
message = self.message |
48
|
|
|
if self.event: |
49
|
|
|
message += ". EventType: " + type(self.event) |
50
|
|
|
return message |
51
|
|
|
|
52
|
|
|
|
53
|
1 |
|
class KytosWrongEventType(KytosEventException): |
54
|
|
|
"""Exception related to EventType. |
55
|
|
|
|
56
|
|
|
When related to buffers, it means that the EventType is not allowed on |
57
|
|
|
that buffer. |
58
|
|
|
""" |
59
|
|
|
|
60
|
|
|
|
61
|
1 |
|
class KytosNoTagAvailableError(Exception): |
62
|
|
|
"""Exception raised when a link has no vlan available.""" |
63
|
|
|
|
64
|
1 |
|
def __init__(self, link): |
65
|
|
|
"""Require a link. |
66
|
|
|
|
67
|
|
|
Args: |
68
|
|
|
link (:class:`~kytos.core.link.Link`): A link with no vlan |
69
|
|
|
available. |
70
|
|
|
""" |
71
|
|
|
super().__init__() |
72
|
|
|
self.link = link |
73
|
|
|
|
74
|
1 |
|
def __str__(self): |
75
|
|
|
"""Full message.""" |
76
|
|
|
msg = f'Link {self.link.id} has no vlan available.' |
77
|
|
|
return msg |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
# Exceptions related to NApps |
81
|
|
|
|
82
|
|
|
|
83
|
1 |
|
class KytosNAppException(Exception): |
84
|
|
|
"""Exception raised on a KytosNApp.""" |
85
|
|
|
|
86
|
1 |
|
def __init__(self, message="KytosNApp exception"): |
87
|
|
|
"""Assign the parameters to instance variables. |
88
|
|
|
|
89
|
|
|
Args: |
90
|
|
|
message (string): message from KytosNAppException. |
91
|
|
|
""" |
92
|
|
|
super().__init__() |
93
|
|
|
self.message = message |
94
|
|
|
|
95
|
1 |
|
def __str__(self): |
96
|
|
|
"""Return the message from KytosNAppException.""" |
97
|
|
|
return self.message |
98
|
|
|
|
99
|
|
|
|
100
|
1 |
|
class KytosNAppMissingInitArgument(KytosNAppException): |
101
|
|
|
"""Exception thrown when NApp have a missing init argument.""" |
102
|
|
|
|
103
|
1 |
|
def __init__(self, message="KytosNAppMissingInitArgument"): |
104
|
|
|
"""Assing parameters to instance variables. |
105
|
|
|
|
106
|
|
|
Args: |
107
|
|
|
message (str): Name of the missed argument. |
108
|
|
|
""" |
109
|
|
|
super().__init__(message=message) |
110
|
|
|
|