AT_COPYRIGHT([Copyright (c) 2022 Red Hat, Inc.

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.])

# The goal is to run as many as possible of the system-traffic tests with
# OVS tc offload enabled. We do this by overriding the
# OVS_TRAFFIC_VSWITCHD_START() with offloading enabled.
m4_define([OVS_TRAFFIC_VSWITCHD_START],
  [AT_CHECK([modprobe openvswitch])
   on_exit 'modprobe -r openvswitch'
   m4_foreach([mod], [[vport_geneve], [vport_gre], [vport_lisp], [vport_stt], [vport_vxlan]],
              [modprobe -q mod || echo "Module mod not loaded."
               on_exit 'modprobe -q -r mod'
              ])
   on_exit 'ovs-dpctl del-dp ovs-system'
   on_exit 'ovs-appctl dpctl/flush-conntrack'
   _OVS_VSWITCHD_START([], [-- set Open_vSwitch . other_config:hw-offload=true $3])
   dnl Add bridges, ports, etc.
   AT_CHECK([ovs-vsctl -- _ADD_BR([br0]) -- $1 m4_if([$2], [], [], [| uuidfilt])], [0], [$2])
])

# Macro to exclude tests that will fail with TC offload enabled.
# We currently have the below tests disabled in system-traffic.at
# for the following reasons:
#
#  TC does not support moving ports to a different namespace than vswitchd's
#  namespace, so we need to disable this test.
#    - 'conntrack - multiple namespaces, internal ports'
#
#  The kernel's tcf_ct_act() function does not seem to take care of any (QinQ)
#  VLAN headers causing commits to fail. However, if this is solved, we have to
#  make sure conntrack does not break the VLAN boundary, i.e., putting together
#  two packets with different CVLAN+SVLAN values.
#    - 'conntrack - IPv4 fragmentation + cvlan'
#
#  Fragmentation handling in ct zone 9 does not seem to work correctly.
#  When moving this test over to the default zone all works fine.
#    - 'conntrack - Fragmentation over vxlan'
#
#  Occasionally we fail with invalid byte counts.
#    - 'datapath - truncate and output to gre tunnel by simulated packets'
#    - 'datapath - truncate and output to gre tunnel'
#
m4_define([CHECK_NO_TC_OFFLOAD],
[
     AT_SKIP_IF([:])
])

# Conntrack ALGs are not supported for tc.
m4_define([CHECK_CONNTRACK_ALG],
[
     AT_SKIP_IF([:])
])

# Conntrack timeout not supported for tc.
m4_define([CHECK_CONNTRACK_TIMEOUT],
[
     AT_SKIP_IF([:])
])
