def test_tx_packet_reformat(self):
        """
        Creates packet reformat (encap) action on TX and with QP action on RX
        verifies that the packet was encapsulated as expected.
        """
        self.client = Mlx5FlowResources(**self.dev_info)
        outer = u.gen_outer_headers(self.client.msg_size)
        # Due to encapsulation action Ipv4 and UDP checksum of the outer header
        # will be recalculated, need to skip them during packet validation.
        ipv4_id_idx = [18, 19]
        ipv4_chksum_idx = [24, 25]
        udp_chksum_idx = [34, 35]
        # Server will receive encaped packet so message size must include the
        # length of the outer part.
        self.server = Mlx5FlowResources(msg_size=self.client.msg_size +
                                        len(outer),
                                        **self.dev_info)
        empty_bytes_arr = bytes(MAX_MATCH_PARAM_SIZE)
        empty_value_param = Mlx5FlowMatchParameters(len(empty_bytes_arr),
                                                    empty_bytes_arr)

        # TX steering
        tx_matcher = self.client.create_matcher(
            empty_bytes_arr, u.MatchCriteriaEnable.NONE,
            e.IBV_FLOW_ATTR_FLAGS_EGRESS, dve.MLX5DV_FLOW_TABLE_TYPE_NIC_TX_)
        # Create encap action
        reformat_action = Mlx5PacketReformatFlowAction(
            self.client.ctx,
            data=outer,
            reformat_type=dve.
            MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL_,
            ft_type=dve.MLX5DV_FLOW_TABLE_TYPE_NIC_TX_)
        action_reformat_attr = Mlx5FlowActionAttr(
            flow_action=reformat_action,
            action_type=dve.MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION)
        self.client.flow = Mlx5Flow(tx_matcher, empty_value_param,
                                    [action_reformat_attr], 1)

        # RX steering
        rx_matcher = self.server.create_matcher(empty_bytes_arr,
                                                u.MatchCriteriaEnable.NONE)
        action_qp_attr = Mlx5FlowActionAttr(
            action_type=dve.MLX5DV_FLOW_ACTION_DEST_IBV_QP, qp=self.server.qp)
        self.server.flow = Mlx5Flow(rx_matcher, empty_value_param,
                                    [action_qp_attr], 1)

        # Send traffic and validate packet
        packet = u.gen_packet(self.client.msg_size)
        u.raw_traffic(self.client,
                      self.server,
                      self.iters,
                      expected_packet=outer + packet,
                      skip_idxs=ipv4_id_idx + ipv4_chksum_idx + udp_chksum_idx)
 def test_smac_matcher_to_qp_flow(self):
     """
     Creates a matcher to match on outer source mac and a flow that forwards
     packets to QP when matching on source mac.
     """
     self.create_players(Mlx5FlowResources)
     smac_mask = bytes([0xff] * 6)
     matcher = self.server.create_matcher(smac_mask,
                                          u.MatchCriteriaEnable.OUTER)
     smac_value = struct.pack(
         '!6s', bytes.fromhex(PacketConsts.SRC_MAC.replace(':', '')))
     value_param = Mlx5FlowMatchParameters(len(smac_value), smac_value)
     action_qp = Mlx5FlowActionAttr(
         action_type=dve.MLX5DV_FLOW_ACTION_DEST_IBV_QP, qp=self.server.qp)
     self.server.flow = Mlx5Flow(matcher, value_param, [action_qp], 1)
     u.raw_traffic(self.client, self.server, self.iters)