1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
13 #include <rte_cycles.h>
14 #include <rte_ether.h>
16 #include <rte_byteorder.h>
17 #include <rte_sched.h>
24 #define MAX_SCHED_SUBPORT_PROFILES 8
26 static struct rte_sched_pipe_params pipe_profile[] = {
31 .tc_rate = {305175, 305175, 305175, 305175, 305175, 305175,
32 305175, 305175, 305175, 305175, 305175, 305175, 305175},
36 .wrr_weights = {1, 1, 1, 1},
40 static struct rte_sched_subport_profile_params
43 .tb_rate = 1250000000,
45 .tc_rate = {1250000000, 1250000000, 1250000000, 1250000000,
46 1250000000, 1250000000, 1250000000, 1250000000, 1250000000,
47 1250000000, 1250000000, 1250000000, 1250000000},
52 static struct rte_sched_subport_params subport_param[] = {
54 .n_pipes_per_subport_enabled = 1024,
55 .qsize = {32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32},
56 .pipe_profiles = pipe_profile,
58 .n_max_pipe_profiles = 1,
62 static struct rte_sched_port_params port_param = {
63 .socket = 0, /* computed */
64 .rate = 0, /* computed */
66 .frame_overhead = RTE_SCHED_FRAME_OVERHEAD_DEFAULT,
67 .n_subports_per_port = 1,
68 .n_subport_profiles = 1,
69 .subport_profiles = subport_profile,
70 .n_max_subport_profiles = MAX_SCHED_SUBPORT_PROFILES,
71 .n_pipes_per_subport = 1024,
75 #define MBUF_DATA_SZ (2048 + RTE_PKTMBUF_HEADROOM)
76 #define MEMPOOL_CACHE_SZ 0
80 static struct rte_mempool *
83 struct rte_mempool * mp;
85 mp = rte_mempool_lookup("test_sched");
87 mp = rte_pktmbuf_pool_create("test_sched", NB_MBUF,
88 MEMPOOL_CACHE_SZ, 0, MBUF_DATA_SZ, SOCKET);
94 prepare_pkt(struct rte_sched_port *port, struct rte_mbuf *mbuf)
96 struct rte_ether_hdr *eth_hdr;
97 struct rte_vlan_hdr *vlan1, *vlan2;
98 struct rte_ipv4_hdr *ip_hdr;
100 /* Simulate a classifier */
101 eth_hdr = rte_pktmbuf_mtod(mbuf, struct rte_ether_hdr *);
102 vlan1 = (struct rte_vlan_hdr *)(ð_hdr->ether_type);
103 vlan2 = (struct rte_vlan_hdr *)(
104 (uintptr_t)ð_hdr->ether_type + sizeof(struct rte_vlan_hdr));
105 eth_hdr = (struct rte_ether_hdr *)(
106 (uintptr_t)ð_hdr->ether_type +
107 2 * sizeof(struct rte_vlan_hdr));
108 ip_hdr = (struct rte_ipv4_hdr *)(
109 (uintptr_t)eth_hdr + sizeof(eth_hdr->ether_type));
111 vlan1->vlan_tci = rte_cpu_to_be_16(SUBPORT);
112 vlan2->vlan_tci = rte_cpu_to_be_16(PIPE);
113 eth_hdr->ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
114 ip_hdr->dst_addr = RTE_IPV4(0,0,TC,QUEUE);
117 rte_sched_port_pkt_write(port, mbuf, SUBPORT, PIPE, TC, QUEUE,
127 * test main entrance for library sched
132 struct rte_mempool *mp = NULL;
133 struct rte_sched_port *port = NULL;
135 struct rte_mbuf *in_mbufs[10];
136 struct rte_mbuf *out_mbufs[10];
141 mp = create_mempool();
142 TEST_ASSERT_NOT_NULL(mp, "Error creating mempool\n");
144 port_param.socket = 0;
145 port_param.rate = (uint64_t) 10000 * 1000 * 1000 / 8;
147 port = rte_sched_port_config(&port_param);
148 TEST_ASSERT_NOT_NULL(port, "Error config sched port\n");
150 err = rte_sched_subport_config(port, SUBPORT, subport_param, 0);
151 TEST_ASSERT_SUCCESS(err, "Error config sched, err=%d\n", err);
153 for (pipe = 0; pipe < subport_param[0].n_pipes_per_subport_enabled; pipe++) {
154 err = rte_sched_pipe_config(port, SUBPORT, pipe, 0);
155 TEST_ASSERT_SUCCESS(err, "Error config sched pipe %u, err=%d\n", pipe, err);
158 for (i = 0; i < 10; i++) {
159 in_mbufs[i] = rte_pktmbuf_alloc(mp);
160 TEST_ASSERT_NOT_NULL(in_mbufs[i], "Packet allocation failed\n");
161 prepare_pkt(port, in_mbufs[i]);
165 err = rte_sched_port_enqueue(port, in_mbufs, 10);
166 TEST_ASSERT_EQUAL(err, 10, "Wrong enqueue, err=%d\n", err);
168 err = rte_sched_port_dequeue(port, out_mbufs, 10);
169 TEST_ASSERT_EQUAL(err, 10, "Wrong dequeue, err=%d\n", err);
171 for (i = 0; i < 10; i++) {
172 enum rte_color color;
173 uint32_t subport, traffic_class, queue;
175 color = rte_sched_port_pkt_read_color(out_mbufs[i]);
176 TEST_ASSERT_EQUAL(color, RTE_COLOR_YELLOW, "Wrong color\n");
178 rte_sched_port_pkt_read_tree_path(port, out_mbufs[i],
179 &subport, &pipe, &traffic_class, &queue);
181 TEST_ASSERT_EQUAL(subport, SUBPORT, "Wrong subport\n");
182 TEST_ASSERT_EQUAL(pipe, PIPE, "Wrong pipe\n");
183 TEST_ASSERT_EQUAL(traffic_class, TC, "Wrong traffic_class\n");
184 TEST_ASSERT_EQUAL(queue, QUEUE, "Wrong queue\n");
189 struct rte_sched_subport_stats subport_stats;
191 rte_sched_subport_read_stats(port, SUBPORT, &subport_stats, &tc_ov);
193 TEST_ASSERT_EQUAL(subport_stats.n_pkts_tc[TC-1], 10, "Wrong subport stats\n");
195 struct rte_sched_queue_stats queue_stats;
197 rte_sched_queue_read_stats(port, QUEUE, &queue_stats, &qlen);
199 TEST_ASSERT_EQUAL(queue_stats.n_pkts, 10, "Wrong queue stats\n");
202 rte_sched_port_free(port);
207 REGISTER_TEST_COMMAND(sched_autotest, test_sched);