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>
25 static struct rte_sched_subport_params subport_param[] = {
27 .tb_rate = 1250000000,
30 .tc_rate = {1250000000, 1250000000, 1250000000, 1250000000,
31 1250000000, 1250000000, 1250000000, 1250000000, 1250000000,
32 1250000000, 1250000000, 1250000000, 1250000000},
37 static struct rte_sched_pipe_params pipe_profile[] = {
42 .tc_rate = {305175, 305175, 305175, 305175, 305175, 305175,
43 305175, 305175, 305175, 305175, 305175, 305175, 305175},
47 .wrr_weights = {1, 1, 1, 1},
51 static struct rte_sched_port_params port_param = {
52 .socket = 0, /* computed */
53 .rate = 0, /* computed */
55 .frame_overhead = RTE_SCHED_FRAME_OVERHEAD_DEFAULT,
56 .n_subports_per_port = 1,
57 .n_pipes_per_subport = 1024,
58 .qsize = {32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32},
59 .pipe_profiles = pipe_profile,
61 .n_max_pipe_profiles = 1,
65 #define MBUF_DATA_SZ (2048 + RTE_PKTMBUF_HEADROOM)
66 #define MEMPOOL_CACHE_SZ 0
70 static struct rte_mempool *
73 struct rte_mempool * mp;
75 mp = rte_mempool_lookup("test_sched");
77 mp = rte_pktmbuf_pool_create("test_sched", NB_MBUF,
78 MEMPOOL_CACHE_SZ, 0, MBUF_DATA_SZ, SOCKET);
84 prepare_pkt(struct rte_sched_port *port, struct rte_mbuf *mbuf)
86 struct rte_ether_hdr *eth_hdr;
87 struct rte_vlan_hdr *vlan1, *vlan2;
88 struct rte_ipv4_hdr *ip_hdr;
90 /* Simulate a classifier */
91 eth_hdr = rte_pktmbuf_mtod(mbuf, struct rte_ether_hdr *);
92 vlan1 = (struct rte_vlan_hdr *)(ð_hdr->ether_type);
93 vlan2 = (struct rte_vlan_hdr *)(
94 (uintptr_t)ð_hdr->ether_type + sizeof(struct rte_vlan_hdr));
95 eth_hdr = (struct rte_ether_hdr *)(
96 (uintptr_t)ð_hdr->ether_type +
97 2 * sizeof(struct rte_vlan_hdr));
98 ip_hdr = (struct rte_ipv4_hdr *)(
99 (uintptr_t)eth_hdr + sizeof(eth_hdr->ether_type));
101 vlan1->vlan_tci = rte_cpu_to_be_16(SUBPORT);
102 vlan2->vlan_tci = rte_cpu_to_be_16(PIPE);
103 eth_hdr->ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
104 ip_hdr->dst_addr = RTE_IPV4(0,0,TC,QUEUE);
107 rte_sched_port_pkt_write(port, mbuf, SUBPORT, PIPE, TC, QUEUE,
117 * test main entrance for library sched
122 struct rte_mempool *mp = NULL;
123 struct rte_sched_port *port = NULL;
125 struct rte_mbuf *in_mbufs[10];
126 struct rte_mbuf *out_mbufs[10];
131 mp = create_mempool();
132 TEST_ASSERT_NOT_NULL(mp, "Error creating mempool\n");
134 port_param.socket = 0;
135 port_param.rate = (uint64_t) 10000 * 1000 * 1000 / 8;
137 port = rte_sched_port_config(&port_param);
138 TEST_ASSERT_NOT_NULL(port, "Error config sched port\n");
140 err = rte_sched_subport_config(port, SUBPORT, subport_param);
141 TEST_ASSERT_SUCCESS(err, "Error config sched, err=%d\n", err);
143 for (pipe = 0; pipe < port_param.n_pipes_per_subport; pipe ++) {
144 err = rte_sched_pipe_config(port, SUBPORT, pipe, 0);
145 TEST_ASSERT_SUCCESS(err, "Error config sched pipe %u, err=%d\n", pipe, err);
148 for (i = 0; i < 10; i++) {
149 in_mbufs[i] = rte_pktmbuf_alloc(mp);
150 TEST_ASSERT_NOT_NULL(in_mbufs[i], "Packet allocation failed\n");
151 prepare_pkt(port, in_mbufs[i]);
155 err = rte_sched_port_enqueue(port, in_mbufs, 10);
156 TEST_ASSERT_EQUAL(err, 10, "Wrong enqueue, err=%d\n", err);
158 err = rte_sched_port_dequeue(port, out_mbufs, 10);
159 TEST_ASSERT_EQUAL(err, 10, "Wrong dequeue, err=%d\n", err);
161 for (i = 0; i < 10; i++) {
162 enum rte_color color;
163 uint32_t subport, traffic_class, queue;
165 color = rte_sched_port_pkt_read_color(out_mbufs[i]);
166 TEST_ASSERT_EQUAL(color, RTE_COLOR_YELLOW, "Wrong color\n");
168 rte_sched_port_pkt_read_tree_path(port, out_mbufs[i],
169 &subport, &pipe, &traffic_class, &queue);
171 TEST_ASSERT_EQUAL(subport, SUBPORT, "Wrong subport\n");
172 TEST_ASSERT_EQUAL(pipe, PIPE, "Wrong pipe\n");
173 TEST_ASSERT_EQUAL(traffic_class, TC, "Wrong traffic_class\n");
174 TEST_ASSERT_EQUAL(queue, QUEUE, "Wrong queue\n");
179 struct rte_sched_subport_stats subport_stats;
181 rte_sched_subport_read_stats(port, SUBPORT, &subport_stats, &tc_ov);
183 TEST_ASSERT_EQUAL(subport_stats.n_pkts_tc[TC-1], 10, "Wrong subport stats\n");
185 struct rte_sched_queue_stats queue_stats;
187 rte_sched_queue_read_stats(port, QUEUE, &queue_stats, &qlen);
189 TEST_ASSERT_EQUAL(queue_stats.n_pkts, 10, "Wrong queue stats\n");
192 rte_sched_port_free(port);
197 REGISTER_TEST_COMMAND(sched_autotest, test_sched);