1 # Copyright (c) 2013 by Gilbert Ramirez <gram@alumni.rice.edu>
3 # SPDX-License-Identifier: GPL-2.0-or-later
6 from suite_dfilter
.dfiltertest
import *
9 class TestDfilterRange
:
10 trace_file
= "ipx_rip.pcap"
12 def test_slice_1_pos(self
, checkDFilterCount
):
13 dfilter
= "ipx.src.node[1] == aa"
14 checkDFilterCount(dfilter
, 1)
16 def test_slice_2_pos(self
, checkDFilterCount
):
17 dfilter
= "ipx.src.node[1] == bb"
18 checkDFilterCount(dfilter
, 0)
20 def test_slice_1_neg(self
, checkDFilterCount
):
21 dfilter
= "ipx[-2:] == 04:53"
22 checkDFilterCount(dfilter
, 1)
24 def test_slice_1_hex_pos(self
, checkDFilterCount
):
25 dfilter
= "ipx.src.node[1] == 0xaa"
26 checkDFilterCount(dfilter
, 1)
28 def test_slice_1_hex_neg(self
, checkDFilterCount
):
29 dfilter
= "ipx.src.node[1] == 0xbb"
30 checkDFilterCount(dfilter
, 0)
32 def test_slice_2_pos(self
, checkDFilterCount
):
33 dfilter
= "ipx.src.node[3:2] == a3:e3"
34 checkDFilterCount(dfilter
, 1)
36 def test_slice_2_neg(self
, checkDFilterCount
):
37 dfilter
= "ipx.src.node[3:2] == cc:dd"
38 checkDFilterCount(dfilter
, 0)
40 def test_slice_string_1(self
, checkDFilterFail
):
41 dfilter
= "frame == \"00\"[1]"
42 checkDFilterFail(dfilter
, "Range is not supported for entity")
44 def test_slice_unparsed_1(self
, checkDFilterFail
):
45 dfilter
= "frame == b[1]"
46 error
= '"b" is not a valid protocol or protocol field'
47 checkDFilterFail(dfilter
, error
)
49 def test_slice_func_1(self
, checkDFilterSucceed
):
50 dfilter
= "string(ipx.src.node)[3:2] == \"cc:dd\""
51 checkDFilterSucceed(dfilter
)
53 # [i:j] i = start_offset, j = length
54 # [i-j] i = start_offset, j = end_offset, inclusive.
55 # [i] i = start_offset, length = 1
56 # [:j] start_offset = 0, length = j
57 # [i:] start_offset = i, end_offset = end_of_field
59 def test_slice_range_1(self
, checkDFilterSucceed
):
61 dfilter
= "frame[5:5] == 11:22:33:44:55"
62 checkDFilterSucceed(dfilter
)
64 def test_slice_range_2(self
, checkDFilterSucceed
):
65 # end offset is inclusive
66 dfilter
= "frame[5-10] == 11:22:33:44:55:66"
67 checkDFilterSucceed(dfilter
)
69 def test_slice_range_3(self
, checkDFilterSucceed
):
70 dfilter
= "frame[5] == 11"
71 checkDFilterSucceed(dfilter
)
73 def test_slice_range_4(self
, checkDFilterSucceed
):
74 dfilter
= "frame[:20] contains be:ef"
75 checkDFilterSucceed(dfilter
)
77 def test_slice_range_5(self
, checkDFilterSucceed
):
78 dfilter
= "frame[20:] contains :12345678"
79 checkDFilterSucceed(dfilter
)
81 def test_slice_exists_1(self
, checkDFilterCount
):
83 checkDFilterCount(dfilter
, 1)
85 def test_slice_exists_2(self
, checkDFilterCount
):
87 checkDFilterCount(dfilter
, 0)
89 def test_slice_exists_3(self
, checkDFilterCount
):
90 dfilter
= "frame[50-59]"
91 checkDFilterCount(dfilter
, 1)
93 def test_slice_exists_4(self
, checkDFilterCount
):
94 dfilter
= "frame[50-60]"
95 checkDFilterCount(dfilter
, 0)