4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 #include <rte_cycles.h>
43 #include <rte_ether.h>
45 #include <rte_byteorder.h>
46 #include <rte_sched.h>
54 static struct rte_sched_subport_params subport_param[] = {
56 .tb_rate = 1250000000,
59 .tc_rate = {1250000000, 1250000000, 1250000000, 1250000000},
64 static struct rte_sched_pipe_params pipe_profile[] = {
69 .tc_rate = {305175, 305175, 305175, 305175},
72 .wrr_weights = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
76 static struct rte_sched_port_params port_param = {
77 .socket = 0, /* computed */
78 .rate = 0, /* computed */
80 .frame_overhead = RTE_SCHED_FRAME_OVERHEAD_DEFAULT,
81 .n_subports_per_port = 1,
82 .n_pipes_per_subport = 1024,
83 .qsize = {32, 32, 32, 32},
84 .pipe_profiles = pipe_profile,
89 #define MBUF_DATA_SZ (2048 + RTE_PKTMBUF_HEADROOM)
90 #define MEMPOOL_CACHE_SZ 0
94 static struct rte_mempool *
97 struct rte_mempool * mp;
99 mp = rte_mempool_lookup("test_sched");
101 mp = rte_pktmbuf_pool_create("test_sched", NB_MBUF,
102 MEMPOOL_CACHE_SZ, 0, MBUF_DATA_SZ, SOCKET);
108 prepare_pkt(struct rte_mbuf *mbuf)
110 struct ether_hdr *eth_hdr;
111 struct vlan_hdr *vlan1, *vlan2;
112 struct ipv4_hdr *ip_hdr;
114 /* Simulate a classifier */
115 eth_hdr = rte_pktmbuf_mtod(mbuf, struct ether_hdr *);
116 vlan1 = (struct vlan_hdr *)(ð_hdr->ether_type );
117 vlan2 = (struct vlan_hdr *)((uintptr_t)ð_hdr->ether_type + sizeof(struct vlan_hdr));
118 eth_hdr = (struct ether_hdr *)((uintptr_t)ð_hdr->ether_type + 2 *sizeof(struct vlan_hdr));
119 ip_hdr = (struct ipv4_hdr *)((uintptr_t)eth_hdr + sizeof(eth_hdr->ether_type));
121 vlan1->vlan_tci = rte_cpu_to_be_16(SUBPORT);
122 vlan2->vlan_tci = rte_cpu_to_be_16(PIPE);
123 eth_hdr->ether_type = rte_cpu_to_be_16(ETHER_TYPE_IPv4);
124 ip_hdr->dst_addr = IPv4(0,0,TC,QUEUE);
127 rte_sched_port_pkt_write(mbuf, SUBPORT, PIPE, TC, QUEUE, e_RTE_METER_YELLOW);
136 * test main entrance for library sched
141 struct rte_mempool *mp = NULL;
142 struct rte_sched_port *port = NULL;
144 struct rte_mbuf *in_mbufs[10];
145 struct rte_mbuf *out_mbufs[10];
150 mp = create_mempool();
151 TEST_ASSERT_NOT_NULL(mp, "Error creating mempool\n");
153 port_param.socket = 0;
154 port_param.rate = (uint64_t) 10000 * 1000 * 1000 / 8;
156 port = rte_sched_port_config(&port_param);
157 TEST_ASSERT_NOT_NULL(port, "Error config sched port\n");
159 err = rte_sched_subport_config(port, SUBPORT, subport_param);
160 TEST_ASSERT_SUCCESS(err, "Error config sched, err=%d\n", err);
162 for (pipe = 0; pipe < port_param.n_pipes_per_subport; pipe ++) {
163 err = rte_sched_pipe_config(port, SUBPORT, pipe, 0);
164 TEST_ASSERT_SUCCESS(err, "Error config sched pipe %u, err=%d\n", pipe, err);
167 for (i = 0; i < 10; i++) {
168 in_mbufs[i] = rte_pktmbuf_alloc(mp);
169 TEST_ASSERT_NOT_NULL(in_mbufs[i], "Packet allocation failed\n");
170 prepare_pkt(in_mbufs[i]);
174 err = rte_sched_port_enqueue(port, in_mbufs, 10);
175 TEST_ASSERT_EQUAL(err, 10, "Wrong enqueue, err=%d\n", err);
177 err = rte_sched_port_dequeue(port, out_mbufs, 10);
178 TEST_ASSERT_EQUAL(err, 10, "Wrong dequeue, err=%d\n", err);
180 for (i = 0; i < 10; i++) {
181 enum rte_meter_color color;
182 uint32_t subport, traffic_class, queue;
184 color = rte_sched_port_pkt_read_color(out_mbufs[i]);
185 TEST_ASSERT_EQUAL(color, e_RTE_METER_YELLOW, "Wrong color\n");
187 rte_sched_port_pkt_read_tree_path(out_mbufs[i],
188 &subport, &pipe, &traffic_class, &queue);
190 TEST_ASSERT_EQUAL(subport, SUBPORT, "Wrong subport\n");
191 TEST_ASSERT_EQUAL(pipe, PIPE, "Wrong pipe\n");
192 TEST_ASSERT_EQUAL(traffic_class, TC, "Wrong traffic_class\n");
193 TEST_ASSERT_EQUAL(queue, QUEUE, "Wrong queue\n");
198 struct rte_sched_subport_stats subport_stats;
200 rte_sched_subport_read_stats(port, SUBPORT, &subport_stats, &tc_ov);
202 TEST_ASSERT_EQUAL(subport_stats.n_pkts_tc[TC-1], 10, "Wrong subport stats\n");
204 struct rte_sched_queue_stats queue_stats;
206 rte_sched_queue_read_stats(port, QUEUE, &queue_stats, &qlen);
208 TEST_ASSERT_EQUAL(queue_stats.n_pkts, 10, "Wrong queue stats\n");
211 rte_sched_port_free(port);
216 REGISTER_TEST_COMMAND(sched_autotest, test_sched);