@@ -35,168 +35,165 @@ char *zlog_conf = "conf/zlog.conf";
35
35
#endif
36
36
37
37
static void signal_handler (int signum ) {
38
- if (signum == SIGINT || signum == SIGTERM ) {
39
- dzlog_info ("Signal %d received, preparing to exit..." ,
40
- signum );
41
- force_quit = true;
42
- }
38
+ if (signum == SIGINT || signum == SIGTERM ) {
39
+ dzlog_info ("Signal %d received, preparing to exit..." ,
40
+ signum );
41
+ force_quit = true;
42
+ }
43
43
}
44
44
45
-
46
45
int main (int argc , char * * argv ) {
47
-
48
-
49
- /* General return value */
50
- int ret ;
51
- char err_msg [MAX_ERROR_MESSAGE_LENGTH ];
52
- /* Quantity of ports */
53
- uint16_t port_quantity ;
54
- /* Quantity of slave works */
55
- uint16_t worker_quantity ;
56
- uint16_t port_id = 0 ;
57
-
58
- /* Setup environment of DPDK */
59
- ret = rte_eal_init (argc , argv );
60
- if (ret < 0 ) {
61
- smto_exit (EXIT_FAILURE , "invalid EAL arguments" );
62
- }
63
-
64
- /* Setup zlog */
65
- ret = dzlog_init (zlog_conf , "main" );
66
- if (ret ) {
67
- smto_exit (EXIT_FAILURE , "zlog init failed" );
68
- }
69
-
70
- /* Check the instruction */
46
+ /* General return value */
47
+ int ret ;
48
+ char err_msg [MAX_ERROR_MESSAGE_LENGTH ];
49
+ /* Quantity of ports */
50
+ uint16_t port_quantity ;
51
+ /* Quantity of slave works */
52
+ uint16_t worker_quantity ;
53
+ uint16_t port_id = 0 ;
54
+
55
+ /* Setup environment of DPDK */
56
+ ret = rte_eal_init (argc , argv );
57
+ if (ret < 0 ) {
58
+ smto_exit (EXIT_FAILURE , "invalid EAL arguments" );
59
+ }
60
+
61
+ /* Setup zlog */
62
+ ret = dzlog_init (zlog_conf , "main" );
63
+ if (ret ) {
64
+ smto_exit (EXIT_FAILURE , "zlog init failed" );
65
+ }
66
+
67
+ /* Check the instruction */
71
68
#if defined(__SSE2__ )
72
- dzlog_debug ("Find SSE2 support" );
69
+ dzlog_debug ("Find SSE2 support" );
73
70
#else
74
71
#error No vector engine (SSE, NEON, ALTIVEC) available, check your toolchain
75
72
#endif
76
73
77
- /* Listen to the shutdown event */
78
- force_quit = false;
79
- signal (SIGINT , signal_handler );
80
- signal (SIGTERM , signal_handler );
81
-
82
- dzlog_debug ("Running on socket #%d" , rte_socket_id ());
83
-
84
- /* Check the quantity of network ports */
85
- port_quantity = rte_eth_dev_count_avail ();
86
- if (port_quantity < 1 ) {
87
- smto_exit (EXIT_FAILURE , "no enough Ethernet ports found" );
88
- } else if (port_quantity > 2 ) {
89
- dzlog_warn ("%d ports detected, but we only use two" , port_quantity );
90
- }
91
-
92
- /* Check the quantity of workers */
93
- worker_quantity = rte_lcore_count ();
94
- if (worker_quantity != GENERAL_QUEUES_QUANTITY + 1 ) {
95
- snprintf (err_msg , MAX_ERROR_MESSAGE_LENGTH ,
96
- "worker quantity does not match the queue quantity, it should be %u rather than %u" ,
97
- GENERAL_QUEUES_QUANTITY + 1 , worker_quantity );
98
- smto_exit (EXIT_FAILURE , err_msg );
99
- }
100
-
101
- /* Initialize the memory pool of dpdk */
102
- struct rte_mempool * mbuf_pool = rte_pktmbuf_pool_create ("mbuf_pool" , NUM_MBUFS , CACHE_SIZE , 0 ,
103
- RTE_MBUF_DEFAULT_BUF_SIZE ,
104
- rte_socket_id ());
105
- if (mbuf_pool == NULL ) {
106
- smto_exit (EXIT_FAILURE , "cannot init mbuf pool" );
74
+ /* Listen to the shutdown event */
75
+ force_quit = false;
76
+ signal (SIGINT , signal_handler );
77
+ signal (SIGTERM , signal_handler );
78
+
79
+ dzlog_debug ("Running on socket #%d" , rte_socket_id ());
80
+
81
+ /* Check the quantity of network ports */
82
+ port_quantity = rte_eth_dev_count_avail ();
83
+ if (port_quantity < 1 ) {
84
+ smto_exit (EXIT_FAILURE , "no enough Ethernet ports found" );
85
+ } else if (port_quantity > 2 ) {
86
+ dzlog_warn ("%d ports detected, but we only use two" , port_quantity );
87
+ }
88
+
89
+ /* Check the quantity of workers */
90
+ worker_quantity = rte_lcore_count ();
91
+ if (worker_quantity != GENERAL_QUEUES_QUANTITY + 1 ) {
92
+ snprintf (err_msg , MAX_ERROR_MESSAGE_LENGTH ,
93
+ "worker quantity does not match the queue quantity, it should be %u rather than %u" ,
94
+ GENERAL_QUEUES_QUANTITY + 1 , worker_quantity );
95
+ smto_exit (EXIT_FAILURE , err_msg );
96
+ }
97
+
98
+ /* Initialize the memory pool of dpdk */
99
+ struct rte_mempool * mbuf_pool = rte_pktmbuf_pool_create ("mbuf_pool" , NUM_MBUFS , CACHE_SIZE , 0 ,
100
+ RTE_MBUF_DEFAULT_BUF_SIZE ,
101
+ rte_socket_id ());
102
+ if (mbuf_pool == NULL ) {
103
+ smto_exit (EXIT_FAILURE , "cannot init mbuf pool" );
104
+ }
105
+
106
+ /* Config port and setup hairpin mode */
107
+ if (port_quantity == 1 ) {
108
+ dzlog_debug ("ONE port hairpin mode" );
109
+ port_id = rte_eth_find_next_owned_by (0 , RTE_ETH_DEV_NO_OWNER );
110
+ init_port (port_id , mbuf_pool );
111
+ setup_one_port_hairpin (port_id );
112
+ } else {
113
+ dzlog_debug ("TWO port hairpin mode unsupported" );
114
+ smto_exit (EXIT_FAILURE , "WO port hairpin mode unsupported" );
115
+ /* Initialize the network port and do some configure */
116
+ RTE_ETH_FOREACH_DEV (port_id ) {
117
+ init_port (port_id , mbuf_pool );
107
118
}
108
-
109
- /* Config port and setup hairpin mode */
110
- if (port_quantity == 1 ) {
111
- dzlog_debug ("ONE port hairpin mode" );
112
- port_id = rte_eth_find_next_owned_by (0 , RTE_ETH_DEV_NO_OWNER );
113
- init_port (port_id , mbuf_pool );
114
- setup_one_port_hairpin (port_id );
115
- } else {
116
- dzlog_debug ("TWO port hairpin mode unsupported" );
117
- smto_exit (EXIT_FAILURE , "WO port hairpin mode unsupported" );
118
- /* Initialize the network port and do some configure */
119
- RTE_ETH_FOREACH_DEV (port_id ) {
120
- init_port (port_id , mbuf_pool );
121
- }
122
- setup_two_port_hairpin ();
123
- }
124
-
125
-
126
- struct rte_flow * flow = 0 ;
127
- struct rte_flow_error flow_error = {0 };
128
- flow = create_default_jump_flow (port_id , & flow_error );
129
- if (flow == NULL ) {
130
- snprintf (err_msg , MAX_ERROR_MESSAGE_LENGTH ,
131
- "the default jump flow create failed: %s" , flow_error .message );
132
- smto_exit (EXIT_FAILURE , err_msg );
133
- }
134
- flow = create_default_rss_flow (port_id , GENERAL_QUEUES_QUANTITY , & flow_error );
135
- if (flow == NULL ) {
136
- snprintf (err_msg , MAX_ERROR_MESSAGE_LENGTH ,
137
- "the default rss flow create failed: %s" , flow_error .message );
138
- smto_exit (EXIT_FAILURE , err_msg );
139
- }
140
-
141
- /* Create flow hash map */
142
- struct rte_hash_parameters flow_hash_map_parameter = {
143
- .name = "flow_hash_table" ,
144
- .entries = MAX_HASH_ENTRIES ,
145
- .key_len = sizeof (union ipv4_5tuple_host ),
146
- .hash_func = ipv4_hash_crc ,
147
- .hash_func_init_val = 0 ,
148
- .extra_flag = RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF
149
- };
150
- struct rte_hash * flow_hash_map = rte_hash_create (& flow_hash_map_parameter );
151
- if (flow_hash_map == NULL ) {
152
- snprintf (err_msg , MAX_ERROR_MESSAGE_LENGTH , "unable to create flow hash table" );
153
- smto_exit (EXIT_FAILURE , err_msg );
154
- }
155
-
156
- if (register_aged_event (port_id , flow_hash_map )) {
157
- smto_exit (EXIT_FAILURE , "cannot register from age timeout event" );
158
- }
159
-
160
- uint16_t lcore_id = 0 ;
161
- uint16_t index = 0 ;
162
- struct worker_parameter worker_params [GENERAL_QUEUES_QUANTITY ];
163
- RTE_LCORE_FOREACH_WORKER (lcore_id ) {
164
- worker_params [index ].port_id = port_id ;
165
- worker_params [index ].queue_id = index ;
166
- worker_params [index ].flow_hash_map = flow_hash_map ;
167
- rte_power_init (lcore_id );
168
- ret = rte_power_set_freq (lcore_id , 2 );
169
- if (ret < 0 ) {
170
- dzlog_warn ("worker #%u does not running at the fixed frequency" , lcore_id );
171
- }
172
- rte_eal_remote_launch (process_loop , & worker_params [index ], lcore_id );
173
- index ++ ;
119
+ setup_two_port_hairpin ();
120
+ }
121
+
122
+ struct rte_flow * flow = 0 ;
123
+ struct rte_flow_error flow_error = {0 };
124
+ flow = create_default_jump_flow (port_id , & flow_error );
125
+ if (flow == NULL ) {
126
+ snprintf (err_msg , MAX_ERROR_MESSAGE_LENGTH ,
127
+ "the default jump flow create failed: %s" , flow_error .message );
128
+ smto_exit (EXIT_FAILURE , err_msg );
129
+ }
130
+ flow = create_default_rss_flow (port_id , GENERAL_QUEUES_QUANTITY , & flow_error );
131
+ if (flow == NULL ) {
132
+ snprintf (err_msg , MAX_ERROR_MESSAGE_LENGTH ,
133
+ "the default rss flow create failed: %s" , flow_error .message );
134
+ smto_exit (EXIT_FAILURE , err_msg );
135
+ }
136
+
137
+ /* Create flow hash map */
138
+ struct rte_hash_parameters flow_hash_map_parameter = {
139
+ .name = "flow_hash_table" ,
140
+ .entries = MAX_HASH_ENTRIES ,
141
+ .key_len = sizeof (union ipv4_5tuple_host ),
142
+ .hash_func = ipv4_hash_crc ,
143
+ .hash_func_init_val = 0 ,
144
+ .extra_flag = RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF
145
+ };
146
+ struct rte_hash * flow_hash_map = rte_hash_create (& flow_hash_map_parameter );
147
+ if (flow_hash_map == NULL ) {
148
+ snprintf (err_msg , MAX_ERROR_MESSAGE_LENGTH , "unable to create flow hash table" );
149
+ smto_exit (EXIT_FAILURE , err_msg );
150
+ }
151
+
152
+ if (register_aged_event (port_id , flow_hash_map )) {
153
+ smto_exit (EXIT_FAILURE , "cannot register from age timeout event" );
154
+ }
155
+
156
+ uint16_t lcore_id = 0 ;
157
+ uint16_t index = 0 ;
158
+ struct worker_parameter worker_params [GENERAL_QUEUES_QUANTITY ];
159
+ RTE_LCORE_FOREACH_WORKER (lcore_id ) {
160
+ worker_params [index ].port_id = port_id ;
161
+ worker_params [index ].queue_id = index ;
162
+ worker_params [index ].flow_hash_map = flow_hash_map ;
163
+ #ifndef VM
164
+ rte_power_init (lcore_id );
165
+ ret = rte_power_set_freq (lcore_id , 2 );
166
+ #endif
167
+ if (ret < 0 ) {
168
+ dzlog_warn ("worker #%u does not running at the fixed frequency" , lcore_id );
174
169
}
175
-
176
-
177
- rte_eal_mp_wait_lcore ();
178
-
179
-
180
- /* free the memory of flow metadata and the flow hash map*/
181
- int32_t key_count = rte_hash_count (flow_hash_map );
182
- dzlog_debug ("%d flow keys has been added into flow hash map" , key_count );
183
- if (key_count > 0 ) {
184
- char format_key [MAX_ERROR_MESSAGE_LENGTH ];
185
- const void * key = 0 ;
186
- void * data = 0 ;
187
- uint32_t * next = 0 ;
188
- uint32_t current = rte_hash_iterate (flow_hash_map , & key , & data , next );
189
- for (; current != - ENOENT ; current = rte_hash_iterate (flow_hash_map , & key , & data , next )) {
190
- int32_t del_key = rte_hash_del_key (flow_hash_map , key );
191
- ret = rte_hash_free_key_with_position (flow_hash_map , del_key );
192
- if (ret ) {
193
- dump_pkt_info ((union ipv4_5tuple_host * ) key , -1 , format_key , MAX_ERROR_MESSAGE_LENGTH );
194
- dzlog_error ("cannot free hash key(%s)" , format_key );
195
- }
196
- rte_free (data );
197
- }
170
+ rte_eal_remote_launch (process_loop , & worker_params [index ], lcore_id );
171
+ index ++ ;
172
+ }
173
+
174
+ rte_eal_mp_wait_lcore ();
175
+
176
+
177
+ /* free the memory of flow metadata and the flow hash map*/
178
+ int32_t key_count = rte_hash_count (flow_hash_map );
179
+ dzlog_debug ("%d flow keys has been added into flow hash map" , key_count );
180
+ if (key_count > 0 ) {
181
+ char format_key [MAX_ERROR_MESSAGE_LENGTH ];
182
+ const void * key = 0 ;
183
+ void * data = 0 ;
184
+ uint32_t * next = 0 ;
185
+ uint32_t current = rte_hash_iterate (flow_hash_map , & key , & data , next );
186
+ for (; current != - ENOENT ; current = rte_hash_iterate (flow_hash_map , & key , & data , next )) {
187
+ int32_t del_key = rte_hash_del_key (flow_hash_map , key );
188
+ ret = rte_hash_free_key_with_position (flow_hash_map , del_key );
189
+ if (ret ) {
190
+ dump_pkt_info ((union ipv4_5tuple_host * ) key , -1 , format_key , MAX_ERROR_MESSAGE_LENGTH );
191
+ dzlog_error ("cannot free hash key(%s)" , format_key );
192
+ }
193
+ rte_free (data );
198
194
}
199
- rte_hash_free (flow_hash_map );
195
+ }
196
+ rte_hash_free (flow_hash_map );
200
197
201
- smto_exit (EXIT_SUCCESS , "SUCCESS! All core stop running!" );
198
+ smto_exit (EXIT_SUCCESS , "SUCCESS! All core stop running!" );
202
199
}
0 commit comments