Fix compilation issue with older gcc
[samplevnf.git] / common / VIL / l2l3_stack / l3fwd_main.c
1 /*
2 // Copyright (c) 2017 Intel Corporation
3 //
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
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 */
16
17 /****************************************************************************
18 *
19 * filename : :l3fwd_main.c
20 *
21 *
22 ******************************************************************************/
23
24 #include "l3fwd_common.h"
25 #include "l2_proto.h"
26 #include "l3fwd_lpm4.h"
27 #include "l3fwd_lpm6.h"
28 #include "interface.h"
29 #include "lib_arp.h"
30 #include "lib_icmpv6.h"
31
32 struct routing_info input_array[] = {
33 #if MULTIPATH_FEAT
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} },
37
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} },
41
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} },
45
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} },
49
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
52
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
55 #else
56         {IPv4(30, 12, 0, 1), 24, 0, 1,
57          {IPv4(192, 168, 0, 2)}, {1} },
58
59         {IPv4(20, 12, 0, 1), 24, 0, 1,
60          {IPv4(120, 0, 0, 2)}, {1} },
61 #endif
62 };
63
64 struct ipv6_routing_info ipv6_input_array[] = {
65
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}
69                 },
70          {1, 1}
71          },
72
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}
76                 },
77          {1, 1}
78          },
79 };
80
81 void l3fwd_init(void)
82 {
83         printf(" *********** L3  Initialization START ************\n");
84         if (lpm_init() == 0) {
85                 rte_exit(EXIT_FAILURE, "L3 Initialization IPv4 Failed\n");
86         }
87         if (lpm6_init() == 0) {
88                 rte_exit(EXIT_FAILURE, "L3 Initialization for IPV6 Failed\n");
89         }
90
91         list_add_type(ETHER_TYPE_IPv4, l3fwd_rx_ipv4_packets);
92         list_add_type(ETHER_TYPE_IPv6, l3fwd_rx_ipv6_packets);
93
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);
97
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);
101
102 }
103
104 void populate_lpm_routes(void)
105 {
106         populate_lpm4_table_routes();
107         //populate_lpm6_table_routes();
108 }
109
110 void populate_lpm4_table_routes(void)
111 {
112         uint8_t i;
113         printf
114                         (" *********** L3 IPV4 Route Initialization START ************\n");
115         for (i = 0; i < MAX_ROUTES; i++) {
116                 if (lpm4_table_route_add(&input_array[i])) {
117
118                         printf("Total routes Added# %d\n", i + 1);
119                 } else {
120                         rte_exit(EXIT_FAILURE,
121                                  "L3 route addition failed for the route# %d\n",
122                                  i);
123                 }
124         }
125         printf
126                         (" *********** L3 IPV4 Route Initialization END ************\n\n");
127 }
128
129 void populate_lpm6_table_routes(void)
130 {
131         uint8_t i;
132         printf
133                         (" *********** L3 IPV6 Route Initialization START ************\n");
134         for (i = 0; i < 2; i++) {
135                 if (lpm6_table_route_add(&ipv6_input_array[i])) {
136
137                         printf("Added route # %d\n", i);
138                 } else {
139                         rte_exit(EXIT_FAILURE,
140                                  "L3 route addition failed for the route# %d\n",
141                                  i);
142                 }
143         }
144         printf(" *********** L3 IPV6 Route Initialization END ************\n");
145 }