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 TestDfilterProtocol
:
10 trace_file
= "http.pcap"
12 def test_slice_1(self
, checkDFilterCount
):
13 dfilter
= "ip[0:2] == 45:00"
14 checkDFilterCount(dfilter
, 1)
16 def test_slice_2(self
, checkDFilterCount
):
17 dfilter
= "ip[0:2] == 00:00"
18 checkDFilterCount(dfilter
, 0)
20 def test_slice_3(self
, checkDFilterCount
):
21 dfilter
= "ip[2:2] == 00:c1"
22 checkDFilterCount(dfilter
, 1)
24 def test_contains_1(self
, checkDFilterCount
):
25 dfilter
= "eth contains 6b"
26 checkDFilterCount(dfilter
, 1)
28 def test_contains_2(self
, checkDFilterCount
):
29 dfilter
= "eth contains 09:6b:88"
30 checkDFilterCount(dfilter
, 1)
32 def test_contains_3(self
, checkDFilterCount
):
33 dfilter
= "eth contains 00:e0:81:00:b0:28:00:09:6b:88:f5:c9:08:00"
34 checkDFilterCount(dfilter
, 1)
36 def test_contains_4(self
, checkDFilterCount
):
37 dfilter
= "eth contains ff:ff:ff"
38 checkDFilterCount(dfilter
, 0)
40 def test_contains_5(self
, checkDFilterCount
):
41 dfilter
= 'http contains "HEAD"'
42 checkDFilterCount(dfilter
, 1)
44 def test_protocol_1(self
, checkDFilterSucceed
):
45 dfilter
= 'frame contains aa.bb.ff'
46 checkDFilterSucceed(dfilter
)
48 def test_protocol_2(self
, checkDFilterFail
):
49 dfilter
= 'frame contains aa.bb.hh'
50 checkDFilterFail(dfilter
, '"aa.bb.hh" is not a valid byte string')
52 def test_protocol_3(self
, checkDFilterFail
):
53 dfilter
= 'ip.port == 5'
54 checkDFilterFail(dfilter
, '"ip.port" is not a valid protocol or protocol field')