
tcpdump can be executed as a background process. A capture file, a filter and an interface can be defined Once the process is launched, traffic can be sent After that, the process can be stopped and the capture file can be read and verified if any packets have been captured For the specific DSCP scenario, a filter is defined based on the DSCP marking value configured for the QoS policy Change-Id: I68a6529284aee27f162e7c27a322b83b767e2504
46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
# Copyright (c) 2021 Red Hat, Inc.
|
|
#
|
|
# All Rights Reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
from __future__ import absolute_import
|
|
from __future__ import division
|
|
|
|
import dpkt
|
|
from oslo_log import log
|
|
|
|
import tobiko
|
|
|
|
|
|
LOG = log.getLogger(__name__)
|
|
|
|
|
|
def assert_pcap_content(pcap: dpkt.pcap.Reader, expect_empty: bool):
|
|
actual_empty = True
|
|
for _ in pcap:
|
|
actual_empty = False
|
|
break
|
|
testcase = tobiko.get_test_case()
|
|
LOG.debug(f'Is the obtained pcap file empty? {actual_empty}')
|
|
testcase.assertEqual(expect_empty, actual_empty)
|
|
|
|
|
|
def assert_pcap_is_empty(pcap: dpkt.pcap.Reader):
|
|
LOG.debug('This test expects an empty pcap capture')
|
|
assert_pcap_content(pcap, True)
|
|
|
|
|
|
def assert_pcap_is_not_empty(pcap: dpkt.pcap.Reader):
|
|
LOG.debug('This test expects a non-empty pcap capture')
|
|
assert_pcap_content(pcap, False)
|