2 // Copyright (c) 2017 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 /****************************************************************************
19 * filename : :l3fwd_main.c
22 ******************************************************************************/
24 #include "l3fwd_common.h"
26 #include "l3fwd_lpm4.h"
27 #include "l3fwd_lpm6.h"
28 #include "interface.h"
30 #include "lib_icmpv6.h"
32 struct routing_info input_array[] = {
34 {IPv4(30, 12, 0, 1), 24, 0, 4,
35 {IPv4(192, 168, 0, 2), IPv4(1, 1, 1, 7), IPv4(120, 0, 0, 2),
36 IPv4(30, 40, 50, 60)}, {1, 1, 1, 1} },
38 {IPv4(40, 12, 0, 1), 24, 0, 4,
39 {IPv4(192, 168, 0, 2), IPv4(1, 1, 1, 7), IPv4(120, 0, 0, 2),
40 IPv4(30, 40, 50, 60)}, {1, 1, 1, 1} },
42 {IPv4(50, 12, 0, 1), 24, 0, 4,
43 {IPv4(192, 168, 0, 2), IPv4(1, 1, 1, 7), IPv4(120, 0, 0, 2),
44 IPv4(30, 40, 50, 60)}, {1, 1, 1, 1} },
46 {IPv4(60, 12, 0, 1), 24, 0, 4,
47 {IPv4(192, 168, 0, 2), IPv4(1, 1, 1, 7), IPv4(120, 0, 0, 2),
48 IPv4(30, 40, 50, 60)}, {1, 1, 1, 1} },
50 {IPv4(100, 100, 100, 100), 24, 0, 2,
51 {IPv4(120, 0, 0, 2), IPv4(120, 0, 0, 2)}, {1, 1} }, // FIb Path Available
53 {IPv4(200, 100, 100, 100), 24, 0, 2,
54 {IPv4(80, 0, 0, 2), IPv4(80, 40, 50, 60)}, {1, 1} }, // Fib path Not Available
56 {IPv4(30, 12, 0, 1), 24, 0, 1,
57 {IPv4(192, 168, 0, 2)}, {1} },
59 {IPv4(20, 12, 0, 1), 24, 0, 1,
60 {IPv4(120, 0, 0, 2)}, {1} },
64 struct ipv6_routing_info ipv6_input_array[] = {
66 {{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 48, 0, 2,
67 {{10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10},
68 {20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20}
73 {{2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, 48, 0, 2,
74 {{10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10},
75 {20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20}
83 printf(" *********** L3 Initialization START ************\n");
84 if (lpm_init() == 0) {
85 rte_exit(EXIT_FAILURE, "L3 Initialization IPv4 Failed\n");
87 if (lpm6_init() == 0) {
88 rte_exit(EXIT_FAILURE, "L3 Initialization for IPV6 Failed\n");
91 list_add_type(ETHER_TYPE_IPv4, l3fwd_rx_ipv4_packets);
92 list_add_type(ETHER_TYPE_IPv6, l3fwd_rx_ipv6_packets);
94 l3_protocol_type_add(IPPROTO_ICMP, ip_local_packets_process);
95 l3_protocol_type_add(IPPROTO_TCP, ip_forward_deliver);
96 l3_protocol_type_add(IPPROTO_UDP, ip_forward_deliver);
98 ipv6_l3_protocol_type_add(IPPROTO_ICMPV6, ipv6_local_deliver);
99 ipv6_l3_protocol_type_add(IPPROTO_TCP, ipv6_forward_deliver);
100 ipv6_l3_protocol_type_add(IPPROTO_UDP, ipv6_forward_deliver);
104 void populate_lpm_routes(void)
106 populate_lpm4_table_routes();
107 //populate_lpm6_table_routes();
110 void populate_lpm4_table_routes(void)
114 (" *********** L3 IPV4 Route Initialization START ************\n");
115 for (i = 0; i < MAX_ROUTES; i++) {
116 if (lpm4_table_route_add(&input_array[i])) {
118 printf("Total routes Added# %d\n", i + 1);
120 rte_exit(EXIT_FAILURE,
121 "L3 route addition failed for the route# %d\n",
126 (" *********** L3 IPV4 Route Initialization END ************\n\n");
129 void populate_lpm6_table_routes(void)
133 (" *********** L3 IPV6 Route Initialization START ************\n");
134 for (i = 0; i < 2; i++) {
135 if (lpm6_table_route_add(&ipv6_input_array[i])) {
137 printf("Added route # %d\n", i);
139 rte_exit(EXIT_FAILURE,
140 "L3 route addition failed for the route# %d\n",
144 printf(" *********** L3 IPV6 Route Initialization END ************\n");