1
|
|
|
""" |
2
|
|
|
Test tracing.trace_entries |
3
|
|
|
""" |
4
|
|
|
|
5
|
1 |
|
import pytest |
6
|
|
|
|
7
|
1 |
|
from napps.amlight.sdntrace.tracing.trace_entries import TraceEntries |
8
|
|
|
|
9
|
|
|
|
10
|
1 |
|
class TestDpid: |
11
|
|
|
"""Test all combinations for DPID""" |
12
|
|
|
|
13
|
1 |
|
def setup_method(self): |
14
|
|
|
"""Set up before each test method""" |
15
|
1 |
|
self.trace_entries = TraceEntries() |
16
|
|
|
|
17
|
1 |
|
def test_incorrect_dpid_int(self): |
18
|
|
|
"""DPID cannot be integer""" |
19
|
1 |
|
with pytest.raises(ValueError): |
20
|
1 |
|
self.trace_entries.dpid = 0 |
21
|
|
|
|
22
|
1 |
|
def test_incorrect_dpid_empty_str(self): |
23
|
|
|
"""DPID cannot be an empty str""" |
24
|
1 |
|
with pytest.raises(ValueError): |
25
|
1 |
|
self.trace_entries.dpid = "" |
26
|
|
|
|
27
|
1 |
|
def test_incorrect_dpid_invalid_characters_plus(self): |
28
|
|
|
"""DPID cannot be a special character (only ':' is allowed)""" |
29
|
1 |
|
with pytest.raises(ValueError): |
30
|
1 |
|
self.trace_entries.dpid = "+" |
31
|
|
|
|
32
|
1 |
|
def test_incorrect_dpid_invalid_characters_comma(self): |
33
|
|
|
"""DPID cannot be a special character (only ':' is allowed)""" |
34
|
1 |
|
with pytest.raises(ValueError): |
35
|
1 |
|
self.trace_entries.dpid = "," |
36
|
|
|
|
37
|
1 |
|
def test_incorrect_dpid_invalid_length(self): |
38
|
|
|
"""DPID cannot be longer than 16 without ':'""" |
39
|
1 |
|
with pytest.raises(ValueError): |
40
|
1 |
|
self.trace_entries.dpid = "00000000000000001" |
41
|
|
|
|
42
|
1 |
|
def test_correct_dpid_char(self): |
43
|
|
|
"""Correct DPID with char""" |
44
|
1 |
|
self.trace_entries.dpid = "1" |
45
|
|
|
|
46
|
1 |
|
def test_read_dpid_char(self): |
47
|
|
|
"""Read DPID '1'""" |
48
|
1 |
|
self.test_correct_dpid_char() |
49
|
1 |
|
assert self.trace_entries.dpid == "1" |
50
|
|
|
|
51
|
1 |
|
def test_correct_dpid_complete(self): |
52
|
|
|
"""Correct DPID with colons, numbers, and letters""" |
53
|
1 |
|
self.trace_entries.dpid = "ab:cd:ef:ab:cd:ef:00:01" |
54
|
|
|
|
55
|
1 |
|
def test_read_dpid_complete(self): |
56
|
|
|
"""Read DPID '1'""" |
57
|
1 |
|
self.test_correct_dpid_complete() |
58
|
1 |
|
assert self.trace_entries.dpid == "ab:cd:ef:ab:cd:ef:00:01" |
59
|
|
|
|
60
|
|
|
|
61
|
1 |
|
class TestInPort: |
62
|
|
|
"""Test all combinations for IN_PORT""" |
63
|
|
|
|
64
|
1 |
|
def setup_method(self): |
65
|
|
|
"""Set up before each test method""" |
66
|
1 |
|
self.trace_entries = TraceEntries() |
67
|
|
|
|
68
|
1 |
|
def test_incorrect_in_port_char(self): |
69
|
|
|
"""IN_PORT cannot be a char""" |
70
|
1 |
|
with pytest.raises(ValueError): |
71
|
1 |
|
self.trace_entries.in_port = "1" |
72
|
|
|
|
73
|
1 |
|
def test_incorrect_in_port_negative(self): |
74
|
|
|
"""IN_PORT cannot be negative""" |
75
|
1 |
|
with pytest.raises(ValueError): |
76
|
1 |
|
self.trace_entries.in_port = -1 |
77
|
|
|
|
78
|
1 |
|
def test_correct_in_port(self): |
79
|
|
|
"""IN_PORT Correct""" |
80
|
1 |
|
self.trace_entries.in_port = 1 |
81
|
|
|
|
82
|
1 |
|
def test_read_in_port(self): |
83
|
|
|
"""Read DPID '1'""" |
84
|
1 |
|
self.test_correct_in_port() |
85
|
1 |
|
assert self.trace_entries.in_port == 1 |
86
|
|
|
|
87
|
|
|
|
88
|
1 |
|
class TestDlSrc: |
89
|
|
|
"""Test all combinations for DL_SRC""" |
90
|
|
|
|
91
|
1 |
|
def setup_method(self): |
92
|
|
|
"""Set up before each test method""" |
93
|
1 |
|
self.trace_entries = TraceEntries() |
94
|
|
|
|
95
|
1 |
|
def test_incorrect_dl_src_int(self): |
96
|
|
|
"""dl_src cannot be integer""" |
97
|
1 |
|
with pytest.raises(ValueError): |
98
|
1 |
|
self.trace_entries.dl_src = 0 |
99
|
|
|
|
100
|
1 |
|
def test_incorrect_dl_src_empty_str(self): |
101
|
|
|
"""dl_src cannot be an empty str""" |
102
|
1 |
|
with pytest.raises(ValueError): |
103
|
1 |
|
self.trace_entries.dl_src = "" |
104
|
|
|
|
105
|
1 |
|
def test_incorrect_dl_src_invalid_characters_plus(self): |
106
|
|
|
"""dl_src only accepts ':' snd '-'""" |
107
|
1 |
|
with pytest.raises(ValueError): |
108
|
1 |
|
self.trace_entries.dl_src = "+" |
109
|
|
|
|
110
|
1 |
|
def test_incorrect_dl_src_invalid_characters_comma(self): |
111
|
|
|
"""dl_src cannot be a special character (only ':' is allowed)""" |
112
|
1 |
|
with pytest.raises(ValueError): |
113
|
1 |
|
self.trace_entries.dl_src = "," |
114
|
|
|
|
115
|
1 |
|
def test_incorrect_dl_src_invalid_length(self): |
116
|
|
|
"""dl_src cannot be longer than 16 without ':'""" |
117
|
1 |
|
with pytest.raises(ValueError): |
118
|
1 |
|
self.trace_entries.dl_src = "000000000000000001" |
119
|
|
|
|
120
|
1 |
|
def test_correct_dl_src_char(self): |
121
|
|
|
"""Correct dl_src with char""" |
122
|
1 |
|
self.trace_entries.dl_src = "ab:cd:ef:ab:cd:00" |
123
|
|
|
|
124
|
1 |
|
def test_read_dl_src_char(self): |
125
|
|
|
"""Read dl_src '1'""" |
126
|
1 |
|
self.test_correct_dl_src_char() |
127
|
1 |
|
assert self.trace_entries.dl_src == "ab:cd:ef:ab:cd:00" |
128
|
|
|
|
129
|
|
|
|
130
|
1 |
|
class TestDlDst: |
131
|
|
|
"""Test all combinations for DL_DST""" |
132
|
|
|
|
133
|
1 |
|
def setup_method(self): |
134
|
|
|
"""Set up before each test method""" |
135
|
1 |
|
self.trace_entries = TraceEntries() |
136
|
|
|
|
137
|
1 |
|
def test_incorrect_dl_dst_int(self): |
138
|
|
|
"""dl_dst cannot be integer""" |
139
|
1 |
|
with pytest.raises(ValueError): |
140
|
1 |
|
self.trace_entries.dl_dst = 0 |
141
|
|
|
|
142
|
1 |
|
def test_incorrect_dl_dst_empty_str(self): |
143
|
|
|
"""dl_dst cannot be an empty str""" |
144
|
1 |
|
with pytest.raises(ValueError): |
145
|
1 |
|
self.trace_entries.dl_dst = "" |
146
|
|
|
|
147
|
1 |
|
def test_incorrect_dl_dst_invalid_characters_plus(self): |
148
|
|
|
"""dl_dst only accepts ':' snd '-'""" |
149
|
1 |
|
with pytest.raises(ValueError): |
150
|
1 |
|
self.trace_entries.dl_dst = "+" |
151
|
|
|
|
152
|
1 |
|
def test_incorrect_dl_dst_invalid_characters_comma(self): |
153
|
|
|
"""dl_dst cannot be a special character (only ':' is allowed)""" |
154
|
1 |
|
with pytest.raises(ValueError): |
155
|
1 |
|
self.trace_entries.dl_dst = "," |
156
|
|
|
|
157
|
1 |
|
def test_incorrect_dl_dst_invalid_length(self): |
158
|
|
|
"""dl_dst cannot be longer than 16 without ':'""" |
159
|
1 |
|
with pytest.raises(ValueError): |
160
|
1 |
|
self.trace_entries.dl_dst = "000000000000000001" |
161
|
|
|
|
162
|
1 |
|
def test_correct_dl_dst_char(self): |
163
|
|
|
"""Correct dl_dst with char""" |
164
|
1 |
|
self.trace_entries.dl_dst = "ab:cd:ef:ab:cd:00" |
165
|
|
|
|
166
|
1 |
|
def test_read_dl_dst_char(self): |
167
|
|
|
"""Read dl_dst '1'""" |
168
|
1 |
|
self.test_correct_dl_dst_char() |
169
|
1 |
|
assert self.trace_entries.dl_dst == "ab:cd:ef:ab:cd:00" |
170
|
|
|
|
171
|
|
|
|
172
|
1 |
|
class TestDlVlan: |
173
|
|
|
"""Test all combinations for DL_VLAN""" |
174
|
|
|
|
175
|
1 |
|
def setup_method(self): |
176
|
|
|
"""Set up before each test method""" |
177
|
1 |
|
self.trace_entries = TraceEntries() |
178
|
|
|
|
179
|
1 |
|
def test_incorrect_dl_vlan_char(self): |
180
|
|
|
"""dl_vlan cannot be a char""" |
181
|
1 |
|
with pytest.raises(ValueError): |
182
|
1 |
|
self.trace_entries.dl_vlan = "1" |
183
|
|
|
|
184
|
1 |
|
def test_incorrect_dl_vlan_negative(self): |
185
|
|
|
"""dl_vlan cannot be negative""" |
186
|
1 |
|
with pytest.raises(ValueError): |
187
|
1 |
|
self.trace_entries.dl_vlan = -1 |
188
|
|
|
|
189
|
1 |
|
def test_incorrect_dl_vlan_too_big(self): |
190
|
|
|
"""dl_vlan cannot be bigger than 4095""" |
191
|
1 |
|
with pytest.raises(ValueError): |
192
|
1 |
|
self.trace_entries.dl_vlan = 4096 |
193
|
|
|
|
194
|
1 |
|
def test_correct_dl_vlan(self): |
195
|
|
|
"""dl_vlan Correct""" |
196
|
1 |
|
self.trace_entries.dl_vlan = 1 |
197
|
|
|
|
198
|
1 |
|
def test_read_dl_vlan(self): |
199
|
|
|
"""Read DPID '1'""" |
200
|
1 |
|
self.test_correct_dl_vlan() |
201
|
1 |
|
assert self.trace_entries.dl_vlan == 1 |
202
|
|
|
|
203
|
|
|
|
204
|
1 |
|
class TestDlType: |
205
|
|
|
"""Test all combinations for dl_type""" |
206
|
|
|
|
207
|
1 |
|
def setup_method(self): |
208
|
|
|
"""Set up before each test method""" |
209
|
1 |
|
self.trace_entries = TraceEntries() |
210
|
|
|
|
211
|
1 |
|
def test_incorrect_dl_type_char(self): |
212
|
|
|
"""dl_type cannot be a char""" |
213
|
1 |
|
with pytest.raises(ValueError): |
214
|
1 |
|
self.trace_entries.dl_type = "1" |
215
|
|
|
|
216
|
1 |
|
def test_incorrect_dl_type_negative(self): |
217
|
|
|
"""dl_type cannot be negative""" |
218
|
1 |
|
with pytest.raises(ValueError): |
219
|
1 |
|
self.trace_entries.dl_type = -1 |
220
|
|
|
|
221
|
1 |
|
def test_incorrect_dl_type_too_big(self): |
222
|
|
|
"""dl_type cannot be bigger than 4095""" |
223
|
1 |
|
with pytest.raises(ValueError): |
224
|
1 |
|
self.trace_entries.dl_type = 65536 |
225
|
|
|
|
226
|
1 |
|
def test_correct_dl_type(self): |
227
|
|
|
"""dl_type Correct""" |
228
|
1 |
|
self.trace_entries.dl_type = 1 |
229
|
|
|
|
230
|
1 |
|
def test_read_dl_type(self): |
231
|
|
|
"""Read DPID '1'""" |
232
|
1 |
|
self.test_correct_dl_type() |
233
|
1 |
|
assert self.trace_entries.dl_type == 1 |
234
|
|
|
|
235
|
|
|
|
236
|
1 |
|
class TestDlVlanPcp: |
237
|
|
|
"""Test all combinations for dl_vlan_pcp""" |
238
|
|
|
|
239
|
1 |
|
def setup_method(self): |
240
|
|
|
"""Set up before each test method""" |
241
|
1 |
|
self.trace_entries = TraceEntries() |
242
|
|
|
|
243
|
1 |
|
def test_incorrect_dl_vlan_pcp_char(self): |
244
|
|
|
"""dl_vlan_pcp cannot be a char""" |
245
|
1 |
|
with pytest.raises(ValueError): |
246
|
1 |
|
self.trace_entries.dl_vlan_pcp = "1" |
247
|
|
|
|
248
|
1 |
|
def test_incorrect_dl_vlan_pcp_negative(self): |
249
|
|
|
"""dl_vlan_pcp cannot be negative""" |
250
|
1 |
|
with pytest.raises(ValueError): |
251
|
1 |
|
self.trace_entries.dl_vlan_pcp = -1 |
252
|
|
|
|
253
|
1 |
|
def test_incorrect_dl_vlan_pcp_too_big(self): |
254
|
|
|
"""dl_vlan_pcp cannot be bigger than 7""" |
255
|
1 |
|
with pytest.raises(ValueError): |
256
|
1 |
|
self.trace_entries.dl_vlan_pcp = 8 |
257
|
|
|
|
258
|
1 |
|
def test_correct_dl_vlan_pcp(self): |
259
|
|
|
"""dl_vlan_pcp Correct""" |
260
|
1 |
|
self.trace_entries.dl_vlan_pcp = 1 |
261
|
|
|
|
262
|
1 |
|
def test_read_dl_vlan_pcp(self): |
263
|
|
|
"""Read DPID '1'""" |
264
|
1 |
|
self.test_correct_dl_vlan_pcp() |
265
|
1 |
|
assert self.trace_entries.dl_vlan_pcp == 1 |
266
|
|
|
|
267
|
|
|
|
268
|
1 |
|
class TestNwTos: |
269
|
|
|
"""Test all combinations for nw_tos""" |
270
|
|
|
|
271
|
1 |
|
def setup_method(self): |
272
|
|
|
"""Set up before each test method""" |
273
|
1 |
|
self.trace_entries = TraceEntries() |
274
|
|
|
|
275
|
1 |
|
def test_incorrect_nw_tos_char(self): |
276
|
|
|
"""nw_tos cannot be a char""" |
277
|
1 |
|
with pytest.raises(ValueError): |
278
|
1 |
|
self.trace_entries.nw_tos = "1" |
279
|
|
|
|
280
|
1 |
|
def test_incorrect_nw_tos_negative(self): |
281
|
|
|
"""nw_tos cannot be negative""" |
282
|
1 |
|
with pytest.raises(ValueError): |
283
|
1 |
|
self.trace_entries.nw_tos = -1 |
284
|
|
|
|
285
|
1 |
|
def test_incorrect_nw_tos_too_big(self): |
286
|
|
|
"""nw_tos cannot be bigger than 7""" |
287
|
1 |
|
with pytest.raises(ValueError): |
288
|
1 |
|
self.trace_entries.nw_tos = 8 |
289
|
|
|
|
290
|
1 |
|
def test_correct_nw_tos(self): |
291
|
|
|
"""nw_tos Correct""" |
292
|
1 |
|
self.trace_entries.nw_tos = 1 |
293
|
|
|
|
294
|
1 |
|
def test_read_nw_tos(self): |
295
|
|
|
"""Read DPID '1'""" |
296
|
1 |
|
self.test_correct_nw_tos() |
297
|
1 |
|
assert self.trace_entries.nw_tos == 1 |
298
|
|
|
|
299
|
|
|
|
300
|
1 |
|
class TestNwSrc: |
301
|
|
|
"""Test all combinations for NW_SRC""" |
302
|
|
|
|
303
|
1 |
|
def setup_method(self): |
304
|
|
|
"""Set up before each test method""" |
305
|
1 |
|
self.trace_entries = TraceEntries() |
306
|
|
|
|
307
|
1 |
|
def test_incorrect_nw_src_int(self): |
308
|
|
|
"""nw_src cannot be integer""" |
309
|
1 |
|
with pytest.raises(ValueError): |
310
|
1 |
|
self.trace_entries.nw_src = 0 |
311
|
|
|
|
312
|
1 |
|
def test_incorrect_nw_src_empty_str(self): |
313
|
|
|
"""nw_src cannot be an empty str""" |
314
|
1 |
|
with pytest.raises(ValueError): |
315
|
1 |
|
self.trace_entries.nw_src = "" |
316
|
|
|
|
317
|
1 |
|
def test_incorrect_nw_src_invalid_characters_plus(self): |
318
|
|
|
"""nw_src only accepts '.'""" |
319
|
1 |
|
with pytest.raises(ValueError): |
320
|
1 |
|
self.trace_entries.nw_src = "+" |
321
|
|
|
|
322
|
1 |
|
def test_incorrect_nw_src_256(self): |
323
|
|
|
"""Correct nw_src with char""" |
324
|
1 |
|
with pytest.raises(ValueError): |
325
|
1 |
|
self.trace_entries.nw_src = "0.0.0.256" |
326
|
|
|
|
327
|
1 |
|
def test_correct_nw_src_zeroed(self): |
328
|
|
|
"""Correct nw_src with char""" |
329
|
1 |
|
self.trace_entries.nw_src = "0.0.0.0" |
330
|
|
|
|
331
|
1 |
|
def test_read_nw_src_char(self): |
332
|
|
|
"""Read nw_src '1'""" |
333
|
1 |
|
self.test_correct_nw_src_zeroed() |
334
|
1 |
|
assert self.trace_entries.nw_src == "0.0.0.0" |
335
|
|
|
|
336
|
1 |
|
def test_correct_nw_src_255(self): |
337
|
|
|
"""Correct nw_src with char""" |
338
|
1 |
|
self.trace_entries.nw_src = "255.255.255.255" |
339
|
|
|
|
340
|
1 |
|
def test_read_nw_src_char_255(self): |
341
|
|
|
"""Read nw_src '1'""" |
342
|
1 |
|
self.test_correct_nw_src_255() |
343
|
1 |
|
assert self.trace_entries.nw_src == "255.255.255.255" |
344
|
|
|
|
345
|
|
|
|
346
|
1 |
|
class TestNwDst: |
347
|
|
|
"""Test all combinations for NW_DST""" |
348
|
|
|
|
349
|
1 |
|
def setup_method(self): |
350
|
|
|
"""Set up before each test method""" |
351
|
1 |
|
self.trace_entries = TraceEntries() |
352
|
|
|
|
353
|
1 |
|
def test_incorrect_nw_dst_int(self): |
354
|
|
|
"""nw_dst cannot be integer""" |
355
|
1 |
|
with pytest.raises(ValueError): |
356
|
1 |
|
self.trace_entries.nw_dst = 0 |
357
|
|
|
|
358
|
1 |
|
def test_incorrect_nw_dst_empty_str(self): |
359
|
|
|
"""nw_dst cannot be an empty str""" |
360
|
1 |
|
with pytest.raises(ValueError): |
361
|
1 |
|
self.trace_entries.nw_dst = "" |
362
|
|
|
|
363
|
1 |
|
def test_incorrect_nw_dst_invalid_characters_plus(self): |
364
|
|
|
"""nw_dst only accepts '.'""" |
365
|
1 |
|
with pytest.raises(ValueError): |
366
|
1 |
|
self.trace_entries.nw_dst = "+" |
367
|
|
|
|
368
|
1 |
|
def test_incorrect_nw_dst_256(self): |
369
|
|
|
"""Correct nw_dst with char""" |
370
|
1 |
|
with pytest.raises(ValueError): |
371
|
1 |
|
self.trace_entries.nw_dst = "0.0.0.256" |
372
|
|
|
|
373
|
1 |
|
def test_correct_nw_dst_zeroed(self): |
374
|
|
|
"""Correct nw_dst with char""" |
375
|
1 |
|
self.trace_entries.nw_dst = "0.0.0.0" |
376
|
|
|
|
377
|
1 |
|
def test_read_nw_dst_char(self): |
378
|
|
|
"""Read nw_dst '1'""" |
379
|
1 |
|
self.test_correct_nw_dst_zeroed() |
380
|
1 |
|
assert self.trace_entries.nw_dst == "0.0.0.0" |
381
|
|
|
|
382
|
1 |
|
def test_correct_nw_dst_255(self): |
383
|
|
|
"""Correct nw_dst with char""" |
384
|
1 |
|
self.trace_entries.nw_dst = "255.255.255.255" |
385
|
|
|
|
386
|
1 |
|
def test_read_nw_dst_char_255(self): |
387
|
|
|
"""Read nw_dst '1'""" |
388
|
1 |
|
self.test_correct_nw_dst_255() |
389
|
1 |
|
assert self.trace_entries.nw_dst == "255.255.255.255" |
390
|
|
|
|
391
|
|
|
|
392
|
1 |
|
class TestTpSrc: |
393
|
|
|
"""Test all combinations for tp_src""" |
394
|
|
|
|
395
|
1 |
|
def setup_method(self): |
396
|
|
|
"""Set up before each test method""" |
397
|
1 |
|
self.trace_entries = TraceEntries() |
398
|
|
|
|
399
|
1 |
|
def test_incorrect_tp_src_char(self): |
400
|
|
|
"""tp_src cannot be a char""" |
401
|
1 |
|
with pytest.raises(ValueError): |
402
|
1 |
|
self.trace_entries.tp_src = "1" |
403
|
|
|
|
404
|
1 |
|
def test_incorrect_tp_src_negative(self): |
405
|
|
|
"""tp_src cannot be negative""" |
406
|
1 |
|
with pytest.raises(ValueError): |
407
|
1 |
|
self.trace_entries.tp_src = -1 |
408
|
|
|
|
409
|
1 |
|
def test_incorrect_tp_src_too_big(self): |
410
|
|
|
"""tp_src cannot be bigger than 4095""" |
411
|
1 |
|
with pytest.raises(ValueError): |
412
|
1 |
|
self.trace_entries.tp_src = 65536 |
413
|
|
|
|
414
|
1 |
|
def test_correct_tp_src(self): |
415
|
|
|
"""tp_src Correct""" |
416
|
1 |
|
self.trace_entries.tp_src = 1 |
417
|
|
|
|
418
|
1 |
|
def test_read_tp_src(self): |
419
|
|
|
"""Read DPID '1'""" |
420
|
1 |
|
self.test_correct_tp_src() |
421
|
1 |
|
assert self.trace_entries.tp_src == 1 |
422
|
|
|
|
423
|
|
|
|
424
|
1 |
|
class TestTpDst: |
425
|
|
|
"""Test all combinations for tp_dst""" |
426
|
|
|
|
427
|
1 |
|
def setup_method(self): |
428
|
|
|
"""Set up before each test method""" |
429
|
1 |
|
self.trace_entries = TraceEntries() |
430
|
|
|
|
431
|
1 |
|
def test_incorrect_tp_dst_char(self): |
432
|
|
|
"""tp_dst cannot be a char""" |
433
|
1 |
|
with pytest.raises(ValueError): |
434
|
1 |
|
self.trace_entries.tp_dst = "1" |
435
|
|
|
|
436
|
1 |
|
def test_incorrect_tp_dst_negative(self): |
437
|
|
|
"""tp_dst cannot be negative""" |
438
|
1 |
|
with pytest.raises(ValueError): |
439
|
1 |
|
self.trace_entries.tp_dst = -1 |
440
|
|
|
|
441
|
1 |
|
def test_incorrect_tp_dst_too_big(self): |
442
|
|
|
"""tp_dst cannot be bigger than 4095""" |
443
|
1 |
|
with pytest.raises(ValueError): |
444
|
1 |
|
self.trace_entries.tp_dst = 65536 |
445
|
|
|
|
446
|
1 |
|
def test_correct_tp_dst(self): |
447
|
|
|
"""tp_dst Correct""" |
448
|
1 |
|
self.trace_entries.tp_dst = 1 |
449
|
|
|
|
450
|
1 |
|
def test_read_tp_dst(self): |
451
|
|
|
"""Read DPID '1'""" |
452
|
1 |
|
self.test_correct_tp_dst() |
453
|
1 |
|
assert self.trace_entries.tp_dst == 1 |
454
|
|
|
|
455
|
|
|
|
456
|
1 |
|
class TestLoadEntries: |
457
|
|
|
"""Now, load all entries at once""" |
458
|
|
|
|
459
|
1 |
|
def setup_method(self): |
460
|
|
|
"""Set up before each test method""" |
461
|
1 |
|
self.trace_entries = TraceEntries() |
462
|
|
|
|
463
|
1 |
|
def test_missing_trace(self): |
464
|
|
|
"""key trace is mandatory""" |
465
|
1 |
|
with pytest.raises(ValueError): |
466
|
1 |
|
entries = {} |
467
|
1 |
|
self.trace_entries.load_entries(entries) |
468
|
|
|
|
469
|
1 |
|
def test_trace_non_dict(self): |
470
|
|
|
"""key trace has to be a dict""" |
471
|
1 |
|
with pytest.raises(ValueError): |
472
|
1 |
|
entries = {"trace:": 0} |
473
|
1 |
|
self.trace_entries.load_entries(entries) |
474
|
|
|
|
475
|
1 |
|
def test_missing_switch(self): |
476
|
|
|
"""key trace/switch is mandatory""" |
477
|
1 |
|
with pytest.raises(ValueError): |
478
|
1 |
|
entries = {"trace": {}} |
479
|
1 |
|
self.trace_entries.load_entries(entries) |
480
|
|
|
|
481
|
1 |
|
def test_missing_dpid(self): |
482
|
|
|
"""key trace/switch is mandatory""" |
483
|
1 |
|
with pytest.raises(ValueError): |
484
|
1 |
|
dpid = {} |
485
|
1 |
|
switch = {"switch": dpid} |
486
|
1 |
|
entries = {"trace": switch} |
487
|
1 |
|
self.trace_entries.load_entries(entries) |
488
|
|
|
|
489
|
1 |
|
def test_missing_in_port(self): |
490
|
|
|
"""key trace/switch is mandatory""" |
491
|
1 |
|
with pytest.raises(ValueError): |
492
|
1 |
|
dpid = {"dpid": "a"} |
493
|
1 |
|
switch = {"switch": dpid} |
494
|
1 |
|
entries = {"trace": switch} |
495
|
1 |
|
self.trace_entries.load_entries(entries) |
496
|
|
|
|
497
|
1 |
|
def test_invalid_eth(self): |
498
|
|
|
"""key trace/switch is mandatory""" |
499
|
1 |
|
with pytest.raises(ValueError): |
500
|
1 |
|
eth = 0 |
501
|
1 |
|
dpid = {"dpid": "a", "in_port": 1} |
502
|
1 |
|
switch = {"switch": dpid, "eth": eth} |
503
|
1 |
|
entries = {"trace": switch} |
504
|
1 |
|
self.trace_entries.load_entries(entries) |
505
|
|
|
|
506
|
1 |
|
def test_default_eth(self): |
507
|
|
|
"""Test default eth""" |
508
|
1 |
|
dpid = {"dpid": "a", "in_port": 1} |
509
|
1 |
|
switch = {"switch": dpid} |
510
|
1 |
|
entries = {"trace": switch} |
511
|
1 |
|
self.trace_entries.load_entries(entries) |
512
|
1 |
|
assert not self.trace_entries.dl_vlan |
513
|
|
|
|
514
|
1 |
|
def test_minimally_correct(self): |
515
|
|
|
"""key trace/switch is mandatory""" |
516
|
1 |
|
eth = {"dl_vlan": 100} |
517
|
1 |
|
dpid = {"dpid": "a", "in_port": 1} |
518
|
1 |
|
switch = {"switch": dpid, "eth": eth} |
519
|
1 |
|
entries = {"trace": switch} |
520
|
1 |
|
self.trace_entries.load_entries(entries) |
521
|
1 |
|
assert self.trace_entries.dl_vlan == eth["dl_vlan"] |
522
|
1 |
|
assert self.trace_entries.dpid == dpid["dpid"] |
523
|
1 |
|
assert self.trace_entries.in_port == dpid["in_port"] |
524
|
|
|
|
525
|
1 |
|
def test_proto_missing_tp(self): |
526
|
|
|
"""Test missing tp when nw_proto is present""" |
527
|
1 |
|
dpid = {"dpid": "a", "in_port": 1} |
528
|
1 |
|
ip = {"nw_proto": 6} |
529
|
1 |
|
switch = {"switch": dpid, "ip": ip} |
530
|
1 |
|
entries = {"trace": switch} |
531
|
1 |
|
with pytest.raises(ValueError): |
532
|
1 |
|
self.trace_entries.load_entries(entries) |
533
|
|
|
|
534
|
1 |
|
def test_proto_without_tp(self): |
535
|
|
|
"""Test define proto without needing tp""" |
536
|
1 |
|
dpid = {"dpid": "a", "in_port": 1} |
537
|
1 |
|
ip = {"nw_proto": 1} |
538
|
1 |
|
switch = {"switch": dpid, "ip": ip} |
539
|
1 |
|
entries = {"trace": switch} |
540
|
1 |
|
self.trace_entries.load_entries(entries) |
541
|
|
|
assert self.trace_entries.nw_proto == ip["nw_proto"] |
542
|
|
|
|