Motr  M0
node_helper.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2013-2020 Seagate Technology LLC and/or its Affiliates
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * For any questions about this software or licensing,
18  * please email opensource@seagate.com or cortx-questions@seagate.com.
19  *
20  */
21 
22 
23 #include "lib/misc.h" /* M0_IN */
24 
25 #include "net/test/node_helper.h"
26 
35  const struct m0_net_test_cmd_init *icmd)
36 {
37  M0_PRE(nh != NULL);
39 
40  M0_SET0(nh);
42  nh->ntnh_role = icmd->ntci_role;
43  nh->ntnh_type = icmd->ntci_type;
44  nh->ntnh_test_initialized = true;
45  nh->ntnh_transfers_max_nr = icmd->ntci_msg_nr == 0 ?
46  UINT64_MAX : icmd->ntci_msg_nr;
49 }
50 
52 {
53  return nh != NULL;
54 }
55 
57 {
59 
61 }
62 
64 {
66 
68  nh->ntnh_sd_copy = nh->ntnh_sd;
70 }
71 
73  struct m0_net_test_cmd_status_data *sd)
74 {
76 
78  *sd = nh->ntnh_sd_copy;
81 }
82 
85  enum m0_net_test_nh_msg_status status,
86  enum m0_net_test_nh_msg_direction direction)
87 {
88  struct m0_net_test_cmd_status_data *sd = &nh->ntnh_sd;
89  struct m0_net_test_msg_nr *msg_nr;
90  struct m0_net_test_mps *mps;
91 
93  M0_PRE(M0_IN(type, (MT_MSG, MT_BULK, MT_TRANSFER)));
94  M0_PRE(M0_IN(status, (MS_SUCCESS, MS_FAILED, MS_BAD)));
95  M0_PRE(M0_IN(direction, (MD_SEND, MD_RECV, MD_BOTH)));
96  M0_PRE(equi(type == MT_TRANSFER, direction == MD_BOTH));
97 
98  if (type == MT_MSG) {
99  msg_nr = direction == MD_SEND ? &sd->ntcsd_msg_nr_send :
100  &sd->ntcsd_msg_nr_recv;
101  } else if (type == MT_BULK) {
102  msg_nr = direction == MD_SEND ? &sd->ntcsd_bulk_nr_send :
103  &sd->ntcsd_bulk_nr_recv;
104  } else {
105  msg_nr = &sd->ntcsd_transfers;
106  }
107 
108  /* update 'number of messages' statistics */
109  ++msg_nr->ntmn_total;
110  msg_nr->ntmn_failed += status == MS_FAILED;
111  msg_nr->ntmn_bad += status == MS_BAD;
112  /* update 'messages per second' statistics */
113  if (type != MT_TRANSFER &&
115  mps = direction == MD_SEND ? &sd->ntcsd_mps_send :
116  &sd->ntcsd_mps_recv;
117  m0_net_test_mps_add(mps, msg_nr->ntmn_total, m0_time_now());
118  }
120  /* update 'finished' flag */
122  if (msg_nr->ntmn_total == nh->ntnh_transfers_max_nr) {
124  sd->ntcsd_finished = true;
125  }
126  }
127 }
128 
130 {
132 
134 }
135 
137 {
139 
141  return false;
143  return true;
144 }
145 
147  const struct m0_net_test_cmd *cmd,
148  struct m0_net_test_cmd *reply)
149 {
151  M0_PRE(cmd != NULL && cmd->ntc_type == M0_NET_TEST_CMD_STATUS);
152  M0_PRE(reply != NULL);
153 
155  m0_net_test_nh_sd_get_locked(nh, &reply->ntc_status_data);
156 }
157 
162 /*
163  * Local variables:
164  * c-indentation-style: "K&R"
165  * c-basic-offset: 8
166  * tab-width: 8
167  * fill-column: 79
168  * scroll-step: 1
169  * End:
170  */
#define M0_PRE(cond)
m0_net_test_nh_msg_type
Definition: node_helper.h:48
M0_INTERNAL void m0_mutex_unlock(struct m0_mutex *mutex)
Definition: mutex.c:66
#define NULL
Definition: misc.h:38
struct m0_net_test_mps ntcsd_mps_recv
Definition: commands.h:186
struct m0_net_test_stats ntcsd_rtt
Definition: commands.h:192
uint64_t m0_time_t
Definition: time.h:37
void m0_net_test_nh_sd_copy_locked(struct m0_net_test_nh *nh)
Definition: node_helper.c:63
void m0_net_test_stats_reset(struct m0_net_test_stats *stats)
Definition: stats.c:46
void m0_net_test_nh_sd_update_rtt(struct m0_net_test_nh *nh, m0_time_t rtt)
Definition: node_helper.c:129
#define M0_SET0(obj)
Definition: misc.h:64
M0_INTERNAL void m0_mutex_lock(struct m0_mutex *mutex)
Definition: mutex.c:49
enum m0_net_test_role ntnh_role
Definition: node_helper.h:64
struct m0_net_test_msg_nr ntcsd_bulk_nr_send
Definition: commands.h:170
uint64_t ntnh_transfers_max_nr
Definition: node_helper.h:93
enum m0_net_test_type ntnh_type
Definition: node_helper.h:66
struct m0_net_test_cmd_status_data ntnh_sd_copy
Definition: node_helper.h:84
struct m0_net_test_msg_nr ntcsd_transfers
Definition: commands.h:174
m0_net_test_nh_msg_status
Definition: node_helper.h:42
#define equi(a, b)
Definition: misc.h:297
m0_net_test_nh_msg_direction
Definition: node_helper.h:55
bool m0_net_test_nh_transfer_next(struct m0_net_test_nh *nh)
Definition: node_helper.c:136
size_t ntmn_bad
Definition: stats.h:322
enum m0_net_test_role ntci_role
Definition: commands.h:104
#define M0_ASSERT(cond)
m0_time_t m0_time_now(void)
Definition: time.c:134
struct m0_mutex ntnh_sd_copy_lock
Definition: node_helper.h:86
struct m0_net_test_mps ntcsd_mps_send
Definition: commands.h:184
struct m0_net_test_msg_nr ntcsd_msg_nr_recv
Definition: commands.h:168
void m0_net_test_nh_cmd_status(struct m0_net_test_nh *nh, const struct m0_net_test_cmd *cmd, struct m0_net_test_cmd *reply)
Definition: node_helper.c:146
m0_time_t m0_net_test_mps_add(struct m0_net_test_mps *mps, unsigned long messages, m0_time_t timestamp)
Definition: stats.c:241
void m0_net_test_nh_sd_update(struct m0_net_test_nh *nh, enum m0_net_test_nh_msg_type type, enum m0_net_test_nh_msg_status status, enum m0_net_test_nh_msg_direction direction)
Definition: node_helper.c:83
M0_INTERNAL void m0_mutex_init(struct m0_mutex *mutex)
Definition: mutex.c:35
#define UINT64_MAX
Definition: types.h:44
uint64_t ntci_msg_nr
Definition: commands.h:112
size_t ntmn_total
Definition: stats.h:308
struct m0_net_test_msg_nr ntcsd_msg_nr_send
Definition: commands.h:166
enum m0_net_test_type ntci_type
Definition: commands.h:106
void m0_net_test_nh_fini(struct m0_net_test_nh *nh)
Definition: node_helper.c:56
void m0_net_test_nh_sd_get_locked(struct m0_net_test_nh *nh, struct m0_net_test_cmd_status_data *sd)
Definition: node_helper.c:72
void m0_net_test_nh_init(struct m0_net_test_nh *nh, const struct m0_net_test_cmd_init *icmd)
Definition: node_helper.c:34
bool ntnh_test_initialized
Definition: node_helper.h:88
struct m0_net_test_msg_nr ntcsd_bulk_nr_recv
Definition: commands.h:172
M0_INTERNAL void m0_mutex_fini(struct m0_mutex *mutex)
Definition: mutex.c:42
size_t ntmn_failed
Definition: stats.h:316
enum m0_net_test_cmd_type ntc_type
Definition: commands.h:204
bool m0_net_test_nh__invariant(struct m0_net_test_nh *nh)
Definition: node_helper.c:51
struct m0_net_test_cmd_status_data ntnh_sd
Definition: node_helper.h:82
int type
Definition: dir.c:1031
static struct m0_dtm_oper_descr reply
Definition: transmit.c:94
uint64_t ntnh_transfers_started_nr
Definition: node_helper.h:95
void m0_net_test_stats_time_add(struct m0_net_test_stats *stats, m0_time_t time)
Definition: stats.c:161