Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 | /* * Copyright (c) 2017-2024 Apple Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in * compliance with the License. The rights granted to you under the License * may not be used to create, or enable the creation or redistribution of, * unlawful or unlicensed copies of an Apple operating system, or to * circumvent, violate, or enable the circumvention or violation of, any * terms of an Apple operating system software license agreement. * * Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. * * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ /* * Try to create many flows on many ports, part of: * <rdar://problem/29003665> need to control skywalk behavior at limit of too many flows */ #include <assert.h> #include <errno.h> #include <stdio.h> #include <spawn.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/types.h> #include <sys/sysctl.h> #include <darwintest.h> #include "skywalk_test_driver.h" #include "skywalk_test_utils.h" #include "skywalk_test_common.h" static void do_flows(nexus_controller_t ncd, const uuid_t fsw, nexus_port_t nx_port_start, int nports, int nflows_per_port, uuid_t flows[]) { for (int i = 0; i < nports; i++) { for (int j = 0; j < nflows_per_port; j++) { int error; uuid_generate_random(flows[i * nflows_per_port + j]); error = sktc_bind_tcp4_flow(ncd, fsw, 0, nx_port_start + i, flows[i * nflows_per_port + j]); SKTC_ASSERT_ERR(!error); // XXX some of these are expected } } } static void undo_flows(nexus_controller_t ncd, const uuid_t fsw, int nflows, const uuid_t flows[]) { for (int i = 0; i < nflows; i++) { int error; uuid_string_t uuidstr; uuid_unparse_upper(flows[i], uuidstr); //T_LOG("Destroying flow %s\n", uuidstr); error = sktc_unbind_flow(ncd, fsw, flows[i]); SKTC_ASSERT_ERR(!error); } } static int skt_manyflows_common(int nports, int nflows_per_port) { struct sktc_nexus_handles handles; sktc_create_flowswitch(&handles, 0); uuid_t flows[nports * nflows_per_port]; do_flows(handles.controller, handles.fsw_nx_uuid, NEXUS_PORT_FLOW_SWITCH_CLIENT, nports, nflows_per_port, flows); undo_flows(handles.controller, handles.fsw_nx_uuid, sizeof(flows) / sizeof(flows[0]), flows); sktc_cleanup_flowswitch(&handles); return 0; } static int skt_mf10x10_main(int argc, char *argv[]) { return skt_manyflows_common(10, 10); } static int skt_mf10x100_main(int argc, char *argv[]) { return skt_manyflows_common(10, 100); } static int skt_mf100x10_main(int argc, char *argv[]) { return skt_manyflows_common(100, 10); } static int skt_mf100x100_main(int argc, char *argv[]) { return skt_manyflows_common(100, 100); } struct skywalk_test skt_mf10x10 = { "mf10x10", "test binds 10 ports with 10 flows per port", SK_FEATURE_SKYWALK | SK_FEATURE_NEXUS_NETIF | SK_FEATURE_NEXUS_FLOWSWITCH | SK_FEATURE_NETNS, skt_mf10x10_main, { NULL }, sktc_ifnet_feth0_create, sktc_ifnet_feth0_destroy, }; struct skywalk_test skt_mf10x100 = { "mf10x100", "test binds 10 ports with 100 flows per port", SK_FEATURE_SKYWALK | SK_FEATURE_NEXUS_NETIF | SK_FEATURE_NEXUS_FLOWSWITCH | SK_FEATURE_NETNS, skt_mf10x100_main, { NULL }, sktc_ifnet_feth0_create, sktc_ifnet_feth0_destroy, }; struct skywalk_test skt_mf100x10 = { "mf100x10", "test binds 100 ports with 10 flows per port", SK_FEATURE_SKYWALK | SK_FEATURE_NEXUS_NETIF | SK_FEATURE_NEXUS_FLOWSWITCH | SK_FEATURE_NETNS, skt_mf100x10_main, { NULL }, sktc_ifnet_feth0_create, sktc_ifnet_feth0_destroy, }; struct skywalk_test skt_mf100x100 = { "mf100x100", "test binds 100 ports with 100 flows per port", SK_FEATURE_SKYWALK | SK_FEATURE_NEXUS_NETIF | SK_FEATURE_NEXUS_FLOWSWITCH | SK_FEATURE_NETNS, skt_mf100x100_main, { NULL }, sktc_ifnet_feth0_create, sktc_ifnet_feth0_destroy, }; /****************************************************************/ static int skt_mf1xall_common(bool stop_on_error) { int error; int first, last; size_t size; int i, nports, count; size = sizeof(first); error = sysctlbyname("net.inet.ip.portrange.first", &first, &size, NULL, 0); SKTC_ASSERT_ERR(!error); assert(size == sizeof(first)); size = sizeof(last); error = sysctlbyname("net.inet.ip.portrange.last", &last, &size, NULL, 0); SKTC_ASSERT_ERR(!error); assert(size == sizeof(last)); if (last < first) { nports = first - last + 1; } else { nports = last - first + 1; } /* Check that there are at least 512 ephemeral ports in the range * so that we can fill up our flows */ assert(nports >= 512); struct sktc_nexus_handles handles; sktc_create_flowswitch(&handles, 0); uuid_t flows[nports]; uuid_t extraflow; count = 0; /* Bind all the ephemeral ports */ for (i = 0; i < nports; i++) { uuid_generate_random(flows[i]); error = sktc_bind_tcp4_flow(handles.controller, handles.fsw_nx_uuid, 0, NEXUS_PORT_FLOW_SWITCH_CLIENT, flows[i]); if (error) { /* flow_entry_alloc currently returns ENOMEM * flow_namespace_create returns EADDRNOTAVAIL */ SKTC_ASSERT_ERR(errno == ENOMEM); uuid_clear(flows[i]); if (stop_on_error) { break; } } else { count++; } } T_LOG("bound %d flows out of %d\n", count, nports); assert(count == 512); /* The default number of flows is currently 512 */ T_LOG("try one more and verify it fails\n"); /* Now try one more and verify it fails */ uuid_generate_random(extraflow); error = sktc_bind_tcp4_flow(handles.controller, handles.fsw_nx_uuid, 0, NEXUS_PORT_FLOW_SWITCH_CLIENT, extraflow); SKTC_ASSERT_ERR(error == -1); SKTC_ASSERT_ERR(errno == ENOMEM); uuid_clear(extraflow); /* Unbind all the flows */ for (i = 0; i < nports; i++) { if (!uuid_is_null(flows[i])) { error = sktc_unbind_flow(handles.controller, handles.fsw_nx_uuid, flows[i]); SKTC_ASSERT_ERR(!error); } } sktc_cleanup_flowswitch(&handles); return 0; } int skt_mf1xall_main(int argc, char *argv[]) { return skt_mf1xall_common(true); } int skt_mf1xallslow_main(int argc, char *argv[]) { return skt_mf1xall_common(false); } struct skywalk_test skt_mf1xall = { "mf1xall", "test binds all the ephemeral port flows on a single port until it hits failure", SK_FEATURE_SKYWALK | SK_FEATURE_NEXUS_NETIF | SK_FEATURE_NEXUS_FLOWSWITCH | SK_FEATURE_NETNS, skt_mf1xall_main, { NULL }, sktc_ifnet_feth0_create, sktc_ifnet_feth0_destroy, }; struct skywalk_test skt_mf1xallslow = { "mf1xallslow", "test binds all the ephemeral port flows on a single port ", SK_FEATURE_SKYWALK | SK_FEATURE_NEXUS_NETIF | SK_FEATURE_NEXUS_FLOWSWITCH | SK_FEATURE_NETNS, skt_mf1xallslow_main, { NULL }, sktc_ifnet_feth0_create, sktc_ifnet_feth0_destroy, }; /****************************************************************/ uuid_t mcflows[100 * 100]; struct sktc_nexus_handles mchandles; static uuid_string_t fsw_uuid_string; static void skt_mc10x10_init(void) { sktc_ifnet_feth0_create(); sktc_create_flowswitch(&mchandles, 0); do_flows(mchandles.controller, mchandles.fsw_nx_uuid, NEXUS_PORT_FLOW_SWITCH_CLIENT, 10, 10, mcflows); uuid_unparse(mchandles.fsw_nx_uuid, fsw_uuid_string); } static void skt_mc10x100_init(void) { sktc_ifnet_feth0_create(); sktc_create_flowswitch(&mchandles, 0); do_flows(mchandles.controller, mchandles.fsw_nx_uuid, NEXUS_PORT_FLOW_SWITCH_CLIENT, 10, 100, mcflows); uuid_unparse(mchandles.fsw_nx_uuid, fsw_uuid_string); } static void skt_mc100x10_init(void) { sktc_ifnet_feth0_create(); sktc_create_flowswitch(&mchandles, 0); do_flows(mchandles.controller, mchandles.fsw_nx_uuid, NEXUS_PORT_FLOW_SWITCH_CLIENT, 100, 10, mcflows); uuid_unparse(mchandles.fsw_nx_uuid, fsw_uuid_string); } static void skt_mc100x100_init(void) { sktc_ifnet_feth0_create(); sktc_create_flowswitch(&mchandles, 0); do_flows(mchandles.controller, mchandles.fsw_nx_uuid, NEXUS_PORT_FLOW_SWITCH_CLIENT, 100, 100, mcflows); uuid_unparse(mchandles.fsw_nx_uuid, fsw_uuid_string); } static void skt_mc100_fini(void) { undo_flows(mchandles.controller, mchandles.fsw_nx_uuid, 100, mcflows); sktc_cleanup_flowswitch(&mchandles); sktc_ifnet_feth0_destroy(); } static void skt_mc1000_fini(void) { undo_flows(mchandles.controller, mchandles.fsw_nx_uuid, 10 * 100, mcflows); sktc_cleanup_flowswitch(&mchandles); sktc_ifnet_feth0_destroy(); } static void skt_mc10000_fini(void) { undo_flows(mchandles.controller, mchandles.fsw_nx_uuid, 100 * 100, mcflows); sktc_cleanup_flowswitch(&mchandles); sktc_ifnet_feth0_destroy(); } int skt_mcflows_main(int argc, char *argv[]) { char buf[1] = { 0 }; ssize_t ret; int error; uuid_t fsw_uuid; channel_t channel; assert(argc == 6); assert(!strcmp(argv[3], "--child")); int child = atoi(argv[4]); error = uuid_parse(argv[5], fsw_uuid); SKTC_ASSERT_ERR(!error); T_LOG("opening channel %d on fsw %s\n", NEXUS_PORT_FLOW_SWITCH_CLIENT + child, argv[5]); channel = sktu_channel_create_extended(fsw_uuid, NEXUS_PORT_FLOW_SWITCH_CLIENT + child, CHANNEL_DIR_TX_RX, CHANNEL_RING_ID_ANY, NULL, -1, -1, -1, -1, -1, -1, 1, -1, -1); assert(channel); if ((ret = write(MPTEST_SEQ_FILENO, buf, sizeof(buf))) == -1) { SKT_LOG("write fail: %s\n", strerror(errno)); return 1; } assert(ret == 1); /* Wait for go signal */ if ((ret = read(MPTEST_SEQ_FILENO, buf, sizeof(buf))) == -1) { SKT_LOG("read fail: %s\n", strerror(errno)); return 1; } assert(ret == 1); os_channel_destroy(channel); return 0; } struct skywalk_mptest skt_mc10x10 = { "mc10x10", "test forks 10 processes each opening a channel with 10 flows", SK_FEATURE_SKYWALK | SK_FEATURE_NEXUS_NETIF | SK_FEATURE_NEXUS_FLOWSWITCH | SK_FEATURE_NETNS, 10, skt_mcflows_main, {NULL, NULL, NULL, NULL, NULL, fsw_uuid_string}, skt_mc10x10_init, skt_mc100_fini, }; struct skywalk_mptest skt_mc10x100 = { "mc10x100", "test forks 10 processes each opening a channel with 100 flows", SK_FEATURE_SKYWALK | SK_FEATURE_NEXUS_NETIF | SK_FEATURE_NEXUS_FLOWSWITCH | SK_FEATURE_NETNS, 10, skt_mcflows_main, {NULL, NULL, NULL, NULL, NULL, fsw_uuid_string}, skt_mc10x100_init, skt_mc1000_fini, }; struct skywalk_mptest skt_mc100x10 = { "mc100x10", "test forks 100 processes each opening a channel with 10 flows", SK_FEATURE_SKYWALK | SK_FEATURE_NEXUS_NETIF | SK_FEATURE_NEXUS_FLOWSWITCH | SK_FEATURE_NETNS, 100, skt_mcflows_main, {NULL, NULL, NULL, NULL, NULL, fsw_uuid_string}, skt_mc100x10_init, skt_mc1000_fini, }; struct skywalk_mptest skt_mc100x100 = { "mc100x100", "test forks 100 processes each opening a channel with 100 flows", SK_FEATURE_SKYWALK | SK_FEATURE_NEXUS_NETIF | SK_FEATURE_NEXUS_FLOWSWITCH | SK_FEATURE_NETNS, 100, skt_mcflows_main, {NULL, NULL, NULL, NULL, NULL, fsw_uuid_string}, skt_mc100x100_init, skt_mc10000_fini, }; |