forked from QratorLabs/ASPA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unit_tests.py
300 lines (243 loc) · 13.9 KB
/
unit_tests.py
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
import unittest
from aspa_logic import *
# just an example for the tests
aspa_records = {
IPv4: {
3356: {6695},
2914: {0},
174: {0},
6695: {0},
13238: {6762, 174, 9002, 6939, 208722, 1299, 3356},
43247: {13238},
12389: {1273, 1299, 3257, 3356, 3491, 5511},
8342: {12389, 8359},
3: {4},
4: {3},
},
IPv6: {
}
}
aspa_manager = ASPA(aspa_records)
class ASPATests(unittest.TestCase):
def __init__(self, *args, **kwargs):
super(ASPATests, self).__init__(*args, **kwargs)
def test_upstream_path_valid(self):
aspath = [Segment(3356, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_upflow_path(aspath, 3356, IPv4), Valid)
aspath = [Segment(3356, AS_SEQUENCE), Segment(3356, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_upflow_path(aspath, 3356, IPv4), Valid)
aspath = [Segment(13238, AS_SEQUENCE), Segment(3356, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_upflow_path(aspath, 3356, IPv4), Valid)
aspath = [Segment(13238, AS_SEQUENCE), Segment(13238, AS_SEQUENCE),
Segment(3356, AS_SEQUENCE), Segment(3356, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_upflow_path(aspath, 3356, IPv4), Valid)
aspath = [Segment(43247, AS_SEQUENCE), Segment(13238, AS_SEQUENCE),
Segment(3356, AS_SEQUENCE), Segment(3356, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_upflow_path(aspath, 3356, IPv4), Valid)
def test_upstream_path_invalid(self):
# aspath with zero length
aspath = []
with self.subTest():
self.assertEqual(aspa_manager.check_upflow_path(aspath, 3356, IPv4), Invalid)
# invalid neighbor
aspath = [Segment(2914, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_upflow_path(aspath, 3356, IPv4), Invalid)
# invalid aspa
aspath = [Segment(3356, AS_SEQUENCE), Segment(2914, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_upflow_path(aspath, 2914, IPv4), Invalid)
# invalid aspa + set in the beginning
aspath = [Segment(3356, AS_SET), Segment(3356, AS_SEQUENCE), Segment(2914, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_upflow_path(aspath, 2914, IPv4), Invalid)
# invalid aspa + set at the end
aspath = [Segment(3356, AS_SEQUENCE), Segment(2914, AS_SEQUENCE), Segment(2914, AS_SET)]
with self.subTest():
self.assertEqual(aspa_manager.check_upflow_path(aspath, 2914, IPv4), Invalid)
# invalid aspa in the middle
aspath = [Segment(3356, AS_SEQUENCE), Segment(12389, AS_SEQUENCE), Segment(2914, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_upflow_path(aspath, 2914, IPv4), Invalid)
# invalid aspa in the middle + prepend
aspath = [Segment(3356, AS_SEQUENCE), Segment(12389, AS_SEQUENCE), Segment(12389, AS_SEQUENCE), Segment(2914, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_upflow_path(aspath, 2914, IPv4), Invalid)
def test_upstream_path_unknown(self):
# unknown pair at the origin
aspath = [Segment(1, AS_SEQUENCE), Segment(13238, AS_SEQUENCE), Segment(3356, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_upflow_path(aspath, 3356, IPv4), Unknown)
# unknown pair in the middle
aspath = [Segment(13238, AS_SEQUENCE), Segment(9002, AS_SEQUENCE), Segment(3356, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_upflow_path(aspath, 3356, IPv4), Unknown)
# two unknown pairs
aspath = [Segment(13238, AS_SEQUENCE), Segment(9002, AS_SEQUENCE), Segment(1, AS_SEQUENCE), Segment(3356, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_upflow_path(aspath, 3356, IPv4), Unknown)
# two unknown pairs
aspath = [Segment(8342, AS_SEQUENCE), Segment(8359, AS_SEQUENCE), Segment(3, AS_SEQUENCE), Segment(4, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_upflow_path(aspath, 4, IPv4), Unknown)
def test_downstream_path_valid(self):
# single T1 in the path
aspath = [Segment(3356, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_downflow_path(aspath, 3356, IPv4), Valid)
# just an ISP
aspath = [Segment(12389, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_downflow_path(aspath, 12389, IPv4), Valid)
# ISP + T1
aspath = [Segment(12389, AS_SEQUENCE), Segment(3356, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_downflow_path(aspath, 3356, IPv4), Valid)
# ISP + T1 + T1
aspath = [Segment(12389, AS_SEQUENCE), Segment(3356, AS_SEQUENCE), Segment(2914, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_downflow_path(aspath, 2914, IPv4), Valid)
# ISP + T1 + T1 + ISP (upflow and downflow fragments)
aspath = [Segment(12389, AS_SEQUENCE), Segment(3356, AS_SEQUENCE),
Segment(174, AS_SEQUENCE), Segment(13238, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_downflow_path(aspath, 13238, IPv4), Valid)
# ISP + T1 + T1 + ISP + prepend (upflow and downflow fragments)
aspath = [Segment(12389, AS_SEQUENCE), Segment(3356, AS_SEQUENCE), Segment(3356, AS_SEQUENCE),
Segment(174, AS_SEQUENCE), Segment(13238, AS_SEQUENCE), Segment(13238, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_downflow_path(aspath, 13238, IPv4), Valid)
# ISP c2p T1 ? ISP p2c ISP
aspath = [Segment(12389, AS_SEQUENCE), Segment(3356, AS_SEQUENCE),
Segment(208722, AS_SEQUENCE), Segment(13238, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_downflow_path(aspath, 13238, IPv4), Valid)
# ISP c2p T1 ? ISP p2c ISP + prepend
aspath = [Segment(12389, AS_SEQUENCE), Segment(3356, AS_SEQUENCE), Segment(3356, AS_SEQUENCE),
Segment(208722, AS_SEQUENCE), Segment(208722, AS_SEQUENCE), Segment(13238, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_downflow_path(aspath, 13238, IPv4), Valid)
def test_downstream_path_invalid(self):
# invalid neighbor
aspath = [Segment(3356, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_downflow_path(aspath, 2914, IPv4), Invalid)
# T1, T1, T1
aspath = [Segment(3356, AS_SEQUENCE), Segment(2914, AS_SEQUENCE), Segment(174, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_downflow_path(aspath, 174, IPv4), Invalid)
# T1, ISP, T1
aspath = [Segment(3356, AS_SEQUENCE), Segment(12389, AS_SEQUENCE), Segment(174, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_downflow_path(aspath, 174, IPv4), Invalid)
# Leak of the peer
aspath = [Segment(13238, AS_SEQUENCE), Segment(20485, AS_SEQUENCE), Segment(174, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_downflow_path(aspath, 174, IPv4), Invalid)
# Leak of the peer
aspath = [Segment(13238, AS_SEQUENCE), Segment(20485, AS_SEQUENCE), Segment(174, AS_SEQUENCE), Segment(3356, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_downflow_path(aspath, 174, IPv4), Invalid)
def test_downstream_path_unknown(self):
# Unknowns + T1
aspath = [Segment(1, AS_SEQUENCE), Segment(2, AS_SEQUENCE), Segment(174, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_downflow_path(aspath, 174, IPv4), Unknown)
# Unknown in the beginning
aspath = [Segment(1, AS_SEQUENCE), Segment(12389, AS_SEQUENCE), Segment(3356, AS_SEQUENCE),
Segment(174, AS_SEQUENCE), Segment(13238, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_downflow_path(aspath, 13238, IPv4), Unknown)
# Unknown in the downflow segment
aspath = [Segment(12389, AS_SEQUENCE), Segment(3356, AS_SEQUENCE),
Segment(174, AS_SEQUENCE), Segment(1, AS_SEQUENCE), Segment(2, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_downflow_path(aspath, 2, IPv4), Unknown)
# Multiple unknowns in the middle without Invalids
aspath = [Segment(8342, AS_SEQUENCE), Segment(12389, AS_SEQUENCE),
Segment(1, AS_SEQUENCE), Segment(2, AS_SEQUENCE), Segment(208722, AS_SEQUENCE), Segment(13238, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_downflow_path(aspath, 13238, IPv4), Unknown)
# Unknown in the end
aspath = [Segment(12389, AS_SEQUENCE), Segment(3356, AS_SEQUENCE),
Segment(174, AS_SEQUENCE), Segment(13238, AS_SEQUENCE), Segment(1, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_downflow_path(aspath, 1, IPv4), Unknown)
def test_downstream_path_unverifiable(self):
# Unknown in the beginning
aspath = [Segment(1, AS_SET), Segment(12389, AS_SEQUENCE), Segment(3356, AS_SEQUENCE),
Segment(174, AS_SEQUENCE), Segment(13238, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_downflow_path(aspath, 13238, IPv4), Unverifiable)
# Unknown in the middle
aspath = [Segment(12389, AS_SEQUENCE), Segment(3356, AS_SEQUENCE),
Segment(174, AS_SEQUENCE), Segment(1, AS_SET), Segment(13238, Unverifiable)]
with self.subTest():
self.assertEqual(aspa_manager.check_downflow_path(aspath, 1, IPv4), Unverifiable)
# Unknown in the end
aspath = [Segment(12389, AS_SEQUENCE), Segment(3356, AS_SEQUENCE),
Segment(174, AS_SEQUENCE), Segment(13238, AS_SEQUENCE), Segment(1, AS_SET)]
with self.subTest():
self.assertEqual(aspa_manager.check_downflow_path(aspath, 1, IPv4), Unverifiable)
# Leak of the peer
aspath = [Segment(13238, AS_SEQUENCE), Segment(20485, AS_SET), Segment(174, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_downflow_path(aspath, 174, IPv4), Unverifiable)
def test_ix_path_valid(self):
# single T1 in the path through IX without 6695 in the path
aspath = [Segment(3356, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_ix_path(aspath, 6695, IPv4), Valid)
# ISP in the path through IX without 6695 in the path
aspath = [Segment(1, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_ix_path(aspath, 6695, IPv4), Valid)
# single T1 in the path with 6695 in the path
aspath = [Segment(3356, AS_SEQUENCE), Segment(6695, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_ix_path(aspath, 6695, IPv4), Valid)
# ISP in the path through IX without 6695 in the path
aspath = [Segment(1, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_ix_path(aspath, 6695, IPv4), Valid)
# non trasparent IX with ASPA record
aspath = [Segment(12389, AS_SEQUENCE), Segment(3356, AS_SEQUENCE), Segment(6695, AS_SEQUENCE),
Segment(174, AS_SEQUENCE), Segment(13238, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_downflow_path(aspath, 13238, IPv4), Valid)
def test_ix_path_invalid(self):
# T1, T1, IX without 6695 in the path
aspath = [Segment(2914, AS_SEQUENCE), Segment(3356, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_ix_path(aspath, 6695, IPv4), Invalid)
# T1, T1, IX with 6695 in the path
aspath = [Segment(2914, AS_SEQUENCE), Segment(3356, AS_SEQUENCE), Segment(6695, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_ix_path(aspath, 6695, IPv4), Invalid)
# single T1 in the path through IX with 4635 in the path, though ASPA for 4635 doesn't exist
aspath = [Segment(3356, AS_SEQUENCE), Segment(4635, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_ix_path(aspath, 4635, IPv4), Invalid)
# T1 + AS1 in the path through IX with 4635 in the path, though ASPA for 4635 doesn't exist
aspath = [Segment(3356, AS_SEQUENCE), Segment(1, AS_SEQUENCE), Segment(4635, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_ix_path(aspath, 4635, IPv4), Invalid)
def test_ix_path_unknown(self):
# ISP unkown ISP in the path through IX without 6695 in the path
aspath = [Segment(1, AS_SEQUENCE), Segment(2, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_ix_path(aspath, 6695, IPv4), Unknown)
# ISP unknown ISP in the path through IX with 6695 in the path
aspath = [Segment(1, AS_SEQUENCE), Segment(2, AS_SEQUENCE), Segment(6695, AS_SEQUENCE)]
with self.subTest():
self.assertEqual(aspa_manager.check_ix_path(aspath, 6695, IPv4), Unknown)
if __name__ == '__main__':
# aspa_manager = ASPA(aspa_records)
# aspath = [Segment(3356, AS_SEQUENCE), Segment(1, AS_SEQUENCE), Segment(4635, AS_SEQUENCE)]
# print(aspa_manager.check_ix_path(aspath, 4635, IPv4) == Invalid)
unittest.main()