9239779dd99ff3707e4e23f802f6b76e0a5d0a11
[vpp.git] / src / plugins / gbp / gbp_learn.c
1 /*
2  * Copyright (c) 2018 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #include <plugins/gbp/gbp.h>
17 #include <plugins/gbp/gbp_learn.h>
18 #include <plugins/gbp/gbp_bridge_domain.h>
19 #include <vlibmemory/api.h>
20
21 #include <vnet/util/throttle.h>
22 #include <vnet/l2/l2_input.h>
23 #include <vnet/fib/fib_table.h>
24 #include <vnet/vxlan-gbp/vxlan_gbp_packet.h>
25
26 /**
27  * Grouping of global data for the GBP source EPG classification feature
28  */
29 typedef struct gbp_learn_main_t_
30 {
31   /**
32    * Next nodes for L2 output features
33    */
34   u32 gl_l2_input_feat_next[32];
35
36   /**
37    * logger - VLIB log class
38    */
39   vlib_log_class_t gl_logger;
40
41   /**
42    * throttles for the DP leanring
43    */
44   throttle_t gl_l2_throttle;
45   throttle_t gl_l3_throttle;
46 } gbp_learn_main_t;
47
48 /**
49  * The maximum learning rate per-hashed EP
50  */
51 #define GBP_ENDPOINT_HASH_LEARN_RATE (1e-2)
52
53 static gbp_learn_main_t gbp_learn_main;
54
55 #define GBP_LEARN_DBG(...)                                      \
56     vlib_log_debug (gbp_learn_main.gl_logger, __VA_ARGS__);
57
58 #define foreach_gbp_learn                      \
59   _(DROP,    "drop")
60
61 typedef enum
62 {
63 #define _(sym,str) GBP_LEARN_ERROR_##sym,
64   foreach_gbp_learn
65 #undef _
66     GBP_LEARN_N_ERROR,
67 } gbp_learn_error_t;
68
69 static char *gbp_learn_error_strings[] = {
70 #define _(sym,string) string,
71   foreach_gbp_learn
72 #undef _
73 };
74
75 typedef enum
76 {
77 #define _(sym,str) GBP_LEARN_NEXT_##sym,
78   foreach_gbp_learn
79 #undef _
80     GBP_LEARN_N_NEXT,
81 } gbp_learn_next_t;
82
83 typedef struct gbp_learn_l2_t_
84 {
85   ip46_address_t ip;
86   mac_address_t mac;
87   u32 sw_if_index;
88   u32 bd_index;
89   epg_id_t epg;
90   ip46_address_t outer_src;
91   ip46_address_t outer_dst;
92 } gbp_learn_l2_t;
93
94
95 static void
96 gbp_learn_l2_cp (const gbp_learn_l2_t * gl2)
97 {
98   ip46_address_t *ips = NULL;
99
100   GBP_LEARN_DBG ("L2 EP: %U %U, %d",
101                  format_mac_address_t, &gl2->mac,
102                  format_ip46_address, &gl2->ip, IP46_TYPE_ANY, gl2->epg);
103
104   vec_add1 (ips, gl2->ip);
105
106   ASSERT (!ip46_address_is_zero (&gl2->outer_src));
107   ASSERT (!ip46_address_is_zero (&gl2->outer_dst));
108
109   /*
110    * flip the source and dst, since that's how it was received, this API
111    * takes how it's sent
112    */
113   gbp_endpoint_update (gl2->sw_if_index, ips,
114                        &gl2->mac, gl2->epg,
115                        (GBP_ENDPOINT_FLAG_LEARNT |
116                         GBP_ENDPOINT_FLAG_REMOTE),
117                        &gl2->outer_dst, &gl2->outer_src, NULL);
118 }
119
120 static void
121 gbp_learn_l2_ip4_dp (const u8 * mac, const ip4_address_t * ip,
122                      u32 bd_index, u32 sw_if_index, epg_id_t epg,
123                      const ip4_address_t * outer_src,
124                      const ip4_address_t * outer_dst)
125 {
126   gbp_learn_l2_t gl2 = {
127     .sw_if_index = sw_if_index,
128     .bd_index = bd_index,
129     .epg = epg,
130     .ip.ip4 = *ip,
131     .outer_src.ip4 = *outer_src,
132     .outer_dst.ip4 = *outer_dst,
133   };
134   mac_address_from_bytes (&gl2.mac, mac);
135
136   ASSERT (!ip46_address_is_zero (&gl2.outer_src));
137   ASSERT (!ip46_address_is_zero (&gl2.outer_dst));
138
139   vl_api_rpc_call_main_thread (gbp_learn_l2_cp, (u8 *) & gl2, sizeof (gl2));
140 }
141
142 static void
143 gbp_learn_l2_ip6_dp (const u8 * mac, const ip6_address_t * ip,
144                      u32 bd_index, u32 sw_if_index, epg_id_t epg,
145                      const ip4_address_t * outer_src,
146                      const ip4_address_t * outer_dst)
147 {
148   gbp_learn_l2_t gl2 = {
149     .sw_if_index = sw_if_index,
150     .bd_index = bd_index,
151     .epg = epg,
152     .ip.ip6 = *ip,
153     .outer_src.ip4 = *outer_src,
154     .outer_dst.ip4 = *outer_dst,
155   };
156   mac_address_from_bytes (&gl2.mac, mac);
157
158   vl_api_rpc_call_main_thread (gbp_learn_l2_cp, (u8 *) & gl2, sizeof (gl2));
159 }
160
161 static void
162 gbp_learn_l2_dp (const u8 * mac, u32 bd_index, u32 sw_if_index,
163                  epg_id_t epg,
164                  const ip4_address_t * outer_src,
165                  const ip4_address_t * outer_dst)
166 {
167   gbp_learn_l2_t gl2 = {
168     .sw_if_index = sw_if_index,
169     .bd_index = bd_index,
170     .epg = epg,
171     .outer_src.ip4 = *outer_src,
172     .outer_dst.ip4 = *outer_dst,
173   };
174   mac_address_from_bytes (&gl2.mac, mac);
175
176   vl_api_rpc_call_main_thread (gbp_learn_l2_cp, (u8 *) & gl2, sizeof (gl2));
177 }
178
179 /**
180  * per-packet trace data
181  */
182 typedef struct gbp_learn_l2_trace_t_
183 {
184   /* per-pkt trace data */
185   mac_address_t mac;
186   u32 sw_if_index;
187   u32 new;
188   u32 throttled;
189   u32 epg;
190   u32 d_bit;
191 } gbp_learn_l2_trace_t;
192
193 always_inline void
194 gbp_learn_get_outer (const ethernet_header_t * eh0,
195                      ip4_address_t * outer_src, ip4_address_t * outer_dst)
196 {
197   ip4_header_t *ip0;
198   u8 *buff;
199
200   /* rewind back to the ivxlan header */
201   buff = (u8 *) eh0;
202   buff -= (sizeof (vxlan_gbp_header_t) +
203            sizeof (udp_header_t) + sizeof (ip4_header_t));
204
205   ip0 = (ip4_header_t *) buff;
206
207   *outer_src = ip0->src_address;
208   *outer_dst = ip0->dst_address;
209 }
210
211 static uword
212 gbp_learn_l2 (vlib_main_t * vm,
213               vlib_node_runtime_t * node, vlib_frame_t * frame)
214 {
215   u32 n_left_from, *from, *to_next, next_index, thread_index, seed;
216   gbp_learn_main_t *glm;
217   f64 time_now;
218
219   glm = &gbp_learn_main;
220   next_index = 0;
221   n_left_from = frame->n_vectors;
222   from = vlib_frame_vector_args (frame);
223   time_now = vlib_time_now (vm);
224   thread_index = vm->thread_index;
225
226   seed = throttle_seed (&glm->gl_l2_throttle, thread_index, time_now);
227
228   while (n_left_from > 0)
229     {
230       u32 n_left_to_next;
231
232       vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
233
234       while (n_left_from > 0 && n_left_to_next > 0)
235         {
236           ip4_address_t outer_src, outer_dst;
237           u32 bi0, sw_if_index0, t0, epg0;
238           const ethernet_header_t *eh0;
239           gbp_learn_next_t next0;
240           gbp_endpoint_t *ge0;
241           vlib_buffer_t *b0;
242
243           next0 = GBP_LEARN_NEXT_DROP;
244           bi0 = from[0];
245           to_next[0] = bi0;
246           from += 1;
247           to_next += 1;
248           n_left_from -= 1;
249           n_left_to_next -= 1;
250
251           b0 = vlib_get_buffer (vm, bi0);
252           sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
253
254           eh0 = vlib_buffer_get_current (b0);
255           epg0 = vnet_buffer2 (b0)->gbp.src_epg;
256
257           next0 = vnet_l2_feature_next (b0, glm->gl_l2_input_feat_next,
258                                         L2INPUT_FEAT_GBP_LEARN);
259
260           ge0 = gbp_endpoint_find_mac (eh0->src_address,
261                                        vnet_buffer (b0)->l2.bd_index);
262
263           if (vnet_buffer2 (b0)->gbp.flags & VXLAN_GBP_GPFLAGS_D)
264             {
265               ge0 = NULL;
266               t0 = 1;
267               goto trace;
268             }
269
270           /*
271            * check for new EP or a moved EP
272            */
273           if (NULL == ge0 || ge0->ge_sw_if_index != sw_if_index0)
274
275             {
276               /*
277                * use the last 4 bytes of the mac address as the hash for the EP
278                */
279               t0 = throttle_check (&glm->gl_l2_throttle, thread_index,
280                                    *((u32 *) (eh0->src_address + 2)), seed);
281               if (!t0)
282                 {
283                   gbp_learn_get_outer (eh0, &outer_src, &outer_dst);
284
285                   switch (clib_net_to_host_u16 (eh0->type))
286                     {
287                     case ETHERNET_TYPE_IP4:
288                       {
289                         const ip4_header_t *ip0;
290
291                         ip0 = (ip4_header_t *) (eh0 + 1);
292
293                         gbp_learn_l2_ip4_dp (eh0->src_address,
294                                              &ip0->src_address,
295                                              vnet_buffer (b0)->l2.bd_index,
296                                              sw_if_index0, epg0,
297                                              &outer_src, &outer_dst);
298
299                         break;
300                       }
301                     case ETHERNET_TYPE_IP6:
302                       {
303                         const ip6_header_t *ip0;
304
305                         ip0 = (ip6_header_t *) (eh0 + 1);
306
307                         gbp_learn_l2_ip6_dp (eh0->src_address,
308                                              &ip0->src_address,
309                                              vnet_buffer (b0)->l2.bd_index,
310                                              sw_if_index0, epg0,
311                                              &outer_src, &outer_dst);
312
313                         break;
314                       }
315                     default:
316                       gbp_learn_l2_dp (eh0->src_address,
317                                        vnet_buffer (b0)->l2.bd_index,
318                                        sw_if_index0, epg0,
319                                        &outer_src, &outer_dst);
320                       break;
321                     }
322                 }
323             }
324           else
325             {
326               /*
327                * this update could happen simultaneoulsy from multiple workers
328                * but that's ok we are not interested in being very accurate.
329                */
330               t0 = 0;
331               ge0->ge_last_time = time_now;
332             }
333         trace:
334           if (PREDICT_FALSE ((b0->flags & VLIB_BUFFER_IS_TRACED)))
335             {
336               gbp_learn_l2_trace_t *t =
337                 vlib_add_trace (vm, node, b0, sizeof (*t));
338               clib_memcpy (t->mac.bytes, eh0->src_address, 6);
339               t->new = (NULL == ge0);
340               t->throttled = t0;
341               t->sw_if_index = sw_if_index0;
342               t->epg = epg0;
343               t->d_bit = ! !(vnet_buffer2 (b0)->gbp.flags &
344                              VXLAN_GBP_GPFLAGS_D);
345             }
346
347           /* verify speculative enqueue, maybe switch current next frame */
348           vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
349                                            to_next, n_left_to_next,
350                                            bi0, next0);
351         }
352
353       vlib_put_next_frame (vm, node, next_index, n_left_to_next);
354     }
355
356   return frame->n_vectors;
357 }
358
359 /* packet trace format function */
360 static u8 *
361 format_gbp_learn_l2_trace (u8 * s, va_list * args)
362 {
363   CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
364   CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
365   gbp_learn_l2_trace_t *t = va_arg (*args, gbp_learn_l2_trace_t *);
366
367   s = format (s, "new:%d throttled:%d d-bit:%d mac:%U itf:%d epg:%d",
368               t->new, t->throttled, t->d_bit,
369               format_mac_address_t, &t->mac, t->sw_if_index, t->epg);
370
371   return s;
372 }
373
374 /* *INDENT-OFF* */
375 VLIB_REGISTER_NODE (gbp_learn_l2_node) = {
376   .function = gbp_learn_l2,
377   .name = "gbp-learn-l2",
378   .vector_size = sizeof (u32),
379   .format_trace = format_gbp_learn_l2_trace,
380   .type = VLIB_NODE_TYPE_INTERNAL,
381
382   .n_errors = ARRAY_LEN(gbp_learn_error_strings),
383   .error_strings = gbp_learn_error_strings,
384
385   .n_next_nodes = GBP_LEARN_N_NEXT,
386
387   .next_nodes = {
388     [GBP_LEARN_NEXT_DROP] = "error-drop",
389   },
390 };
391
392 VLIB_NODE_FUNCTION_MULTIARCH (gbp_learn_l2_node, gbp_learn_l2);
393 /* *INDENT-ON* */
394
395 typedef struct gbp_learn_l3_t_
396 {
397   ip46_address_t ip;
398   u32 fib_index;
399   u32 sw_if_index;
400   epg_id_t epg;
401   ip46_address_t outer_src;
402   ip46_address_t outer_dst;
403 } gbp_learn_l3_t;
404
405 static void
406 gbp_learn_l3_cp (const gbp_learn_l3_t * gl3)
407 {
408   ip46_address_t *ips = NULL;
409
410   GBP_LEARN_DBG ("L3 EP: %U, %d", format_ip46_address, &gl3->ip,
411                  IP46_TYPE_ANY, gl3->epg);
412
413   vec_add1 (ips, gl3->ip);
414
415   gbp_endpoint_update (gl3->sw_if_index, ips, NULL, gl3->epg,
416                        (GBP_ENDPOINT_FLAG_REMOTE |
417                         GBP_ENDPOINT_FLAG_LEARNT),
418                        &gl3->outer_dst, &gl3->outer_src, NULL);
419 }
420
421 static void
422 gbp_learn_ip4_dp (const ip4_address_t * ip,
423                   u32 fib_index, u32 sw_if_index, epg_id_t epg,
424                   const ip4_address_t * outer_src,
425                   const ip4_address_t * outer_dst)
426 {
427   /* *INDENT-OFF* */
428   gbp_learn_l3_t gl3 = {
429     .ip = {
430       .ip4 = *ip,
431     },
432     .sw_if_index = sw_if_index,
433     .fib_index = fib_index,
434     .epg = epg,
435     .outer_src.ip4 = *outer_src,
436     .outer_dst.ip4 = *outer_dst,
437   };
438   /* *INDENT-ON* */
439
440   vl_api_rpc_call_main_thread (gbp_learn_l3_cp, (u8 *) & gl3, sizeof (gl3));
441 }
442
443 static void
444 gbp_learn_ip6_dp (const ip6_address_t * ip,
445                   u32 fib_index, u32 sw_if_index, epg_id_t epg,
446                   const ip4_address_t * outer_src,
447                   const ip4_address_t * outer_dst)
448 {
449   /* *INDENT-OFF* */
450   gbp_learn_l3_t gl3 = {
451     .ip = {
452       .ip6 = *ip,
453     },
454     .sw_if_index = sw_if_index,
455     .fib_index = fib_index,
456     .epg = epg,
457     .outer_src.ip4 = *outer_src,
458     .outer_dst.ip4 = *outer_dst,
459   };
460   /* *INDENT-ON* */
461
462   vl_api_rpc_call_main_thread (gbp_learn_l3_cp, (u8 *) & gl3, sizeof (gl3));
463 }
464
465 /**
466  * per-packet trace data
467  */
468 typedef struct gbp_learn_l3_trace_t_
469 {
470   /* per-pkt trace data */
471   ip46_address_t ip;
472   u32 sw_if_index;
473   u32 new;
474   u32 throttled;
475   u32 epg;
476 } gbp_learn_l3_trace_t;
477
478 static uword
479 gbp_learn_l3 (vlib_main_t * vm,
480               vlib_node_runtime_t * node, vlib_frame_t * frame,
481               fib_protocol_t fproto)
482 {
483   u32 n_left_from, *from, *to_next, next_index, thread_index, seed;
484   gbp_learn_main_t *glm;
485   f64 time_now;
486
487   glm = &gbp_learn_main;
488   next_index = 0;
489   n_left_from = frame->n_vectors;
490   from = vlib_frame_vector_args (frame);
491   time_now = vlib_time_now (vm);
492   thread_index = vm->thread_index;
493
494   seed = throttle_seed (&glm->gl_l3_throttle, thread_index, time_now);
495
496   while (n_left_from > 0)
497     {
498       u32 n_left_to_next;
499
500       vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
501
502       while (n_left_from > 0 && n_left_to_next > 0)
503         {
504           u32 bi0, sw_if_index0, t0, epg0, fib_index0;
505           CLIB_UNUSED (const ip4_header_t *) ip4_0;
506           CLIB_UNUSED (const ip6_header_t *) ip6_0;
507           ip4_address_t outer_src, outer_dst;
508           ethernet_header_t *eth0;
509           gbp_learn_next_t next0;
510           gbp_endpoint_t *ge0;
511           vlib_buffer_t *b0;
512
513           next0 = GBP_LEARN_NEXT_DROP;
514           bi0 = from[0];
515           to_next[0] = bi0;
516           from += 1;
517           to_next += 1;
518           n_left_from -= 1;
519           n_left_to_next -= 1;
520
521           b0 = vlib_get_buffer (vm, bi0);
522           sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
523           epg0 = vnet_buffer2 (b0)->gbp.src_epg;
524           ip6_0 = NULL;
525           ip4_0 = NULL;
526
527           vnet_feature_next (&next0, b0);
528
529           if (vnet_buffer2 (b0)->gbp.flags & VXLAN_GBP_GPFLAGS_D)
530             {
531               t0 = 1;
532               ge0 = NULL;
533               goto trace;
534             }
535
536           fib_index0 = fib_table_get_index_for_sw_if_index (fproto,
537                                                             sw_if_index0);
538
539           if (FIB_PROTOCOL_IP6 == fproto)
540             {
541               ip6_0 = vlib_buffer_get_current (b0);
542               eth0 = (ethernet_header_t *) (((u8 *) ip6_0) - sizeof (*eth0));
543
544               gbp_learn_get_outer (eth0, &outer_src, &outer_dst);
545
546               ge0 = gbp_endpoint_find_ip6 (&ip6_0->src_address, fib_index0);
547
548               if (NULL == ge0)
549                 {
550                   t0 = throttle_check (&glm->gl_l3_throttle,
551                                        thread_index,
552                                        ip6_address_hash_to_u32
553                                        (&ip6_0->src_address), seed);
554
555                   if (!t0)
556                     {
557                       gbp_learn_ip6_dp (&ip6_0->src_address,
558                                         fib_index0, sw_if_index0, epg0,
559                                         &outer_src, &outer_dst);
560                     }
561                 }
562               else
563                 {
564                   /*
565                    * this update could happen simultaneoulsy from multiple
566                    * workers but that's ok we are not interested in being
567                    * very accurate.
568                    */
569                   t0 = 0;
570                   ge0->ge_last_time = time_now;
571                 }
572             }
573           else
574             {
575               ip4_0 = vlib_buffer_get_current (b0);
576               eth0 = (ethernet_header_t *) (((u8 *) ip4_0) - sizeof (*eth0));
577
578               gbp_learn_get_outer (eth0, &outer_src, &outer_dst);
579               ge0 = gbp_endpoint_find_ip4 (&ip4_0->src_address, fib_index0);
580
581               if (NULL == ge0)
582                 {
583                   t0 = throttle_check (&glm->gl_l3_throttle, thread_index,
584                                        ip4_0->src_address.as_u32, seed);
585
586                   if (!t0)
587                     {
588                       gbp_learn_ip4_dp (&ip4_0->src_address,
589                                         fib_index0, sw_if_index0, epg0,
590                                         &outer_src, &outer_dst);
591                     }
592                 }
593               else
594                 {
595                   /*
596                    * this update could happen simultaneoulsy from multiple
597                    * workers but that's ok we are not interested in being
598                    * very accurate.
599                    */
600                   t0 = 0;
601                   ge0->ge_last_time = time_now;
602                 }
603             }
604         trace:
605           if (PREDICT_FALSE ((b0->flags & VLIB_BUFFER_IS_TRACED)))
606             {
607               gbp_learn_l3_trace_t *t;
608
609               t = vlib_add_trace (vm, node, b0, sizeof (*t));
610               if (FIB_PROTOCOL_IP6 == fproto && ip6_0)
611                 ip46_address_set_ip6 (&t->ip, &ip6_0->src_address);
612               if (FIB_PROTOCOL_IP4 == fproto && ip4_0)
613                 ip46_address_set_ip4 (&t->ip, &ip4_0->src_address);
614               t->new = (NULL == ge0);
615               t->throttled = t0;
616               t->sw_if_index = sw_if_index0;
617               t->epg = epg0;
618             }
619
620           vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
621                                            to_next, n_left_to_next,
622                                            bi0, next0);
623         }
624
625       vlib_put_next_frame (vm, node, next_index, n_left_to_next);
626     }
627
628   return frame->n_vectors;
629 }
630
631 /* packet trace format function */
632 static u8 *
633 format_gbp_learn_l3_trace (u8 * s, va_list * args)
634 {
635   CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
636   CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
637   gbp_learn_l3_trace_t *t = va_arg (*args, gbp_learn_l3_trace_t *);
638
639   s = format (s, "new:%d throttled:%d ip:%U itf:%d epg:%d",
640               t->new, t->throttled,
641               format_ip46_address, &t->ip, IP46_TYPE_ANY, t->sw_if_index,
642               t->epg);
643
644   return s;
645 }
646
647 static uword
648 gbp_learn_ip4 (vlib_main_t * vm,
649                vlib_node_runtime_t * node, vlib_frame_t * frame)
650 {
651   return (gbp_learn_l3 (vm, node, frame, FIB_PROTOCOL_IP4));
652 }
653
654 static uword
655 gbp_learn_ip6 (vlib_main_t * vm,
656                vlib_node_runtime_t * node, vlib_frame_t * frame)
657 {
658   return (gbp_learn_l3 (vm, node, frame, FIB_PROTOCOL_IP6));
659 }
660
661 /* *INDENT-OFF* */
662 VLIB_REGISTER_NODE (gbp_learn_ip4_node) = {
663   .function = gbp_learn_ip4,
664   .name = "gbp-learn-ip4",
665   .vector_size = sizeof (u32),
666   .format_trace = format_gbp_learn_l3_trace,
667   .type = VLIB_NODE_TYPE_INTERNAL,
668 };
669
670 VLIB_NODE_FUNCTION_MULTIARCH (gbp_learn_ip4_node, gbp_learn_ip4);
671
672 VNET_FEATURE_INIT (gbp_learn_ip4, static) =
673 {
674   .arc_name = "ip4-unicast",
675   .node_name = "gbp-learn-ip4",
676 };
677
678 VLIB_REGISTER_NODE (gbp_learn_ip6_node) = {
679   .function = gbp_learn_ip6,
680   .name = "gbp-learn-ip6",
681   .vector_size = sizeof (u32),
682   .format_trace = format_gbp_learn_l3_trace,
683   .type = VLIB_NODE_TYPE_INTERNAL,
684 };
685
686 VLIB_NODE_FUNCTION_MULTIARCH (gbp_learn_ip6_node, gbp_learn_ip6);
687
688 VNET_FEATURE_INIT (gbp_learn_ip6, static) =
689 {
690   .arc_name = "ip6-unicast",
691   .node_name = "gbp-learn-ip6",
692 };
693
694 /* *INDENT-ON* */
695
696 void
697 gbp_learn_enable (u32 sw_if_index, gbb_learn_mode_t mode)
698 {
699   if (GBP_LEARN_MODE_L2 == mode)
700     l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_GBP_LEARN, 1);
701   else
702     {
703       vnet_feature_enable_disable ("ip4-unicast",
704                                    "gbp-learn-ip4", sw_if_index, 1, 0, 0);
705       vnet_feature_enable_disable ("ip6-unicast",
706                                    "gbp-learn-ip6", sw_if_index, 1, 0, 0);
707     }
708 }
709
710 void
711 gbp_learn_disable (u32 sw_if_index, gbb_learn_mode_t mode)
712 {
713   if (GBP_LEARN_MODE_L2 == mode)
714     l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_GBP_LEARN, 0);
715   else
716     {
717       vnet_feature_enable_disable ("ip4-unicast",
718                                    "gbp-learn-ip4", sw_if_index, 0, 0, 0);
719       vnet_feature_enable_disable ("ip6-unicast",
720                                    "gbp-learn-ip6", sw_if_index, 0, 0, 0);
721     }
722 }
723
724 static clib_error_t *
725 gbp_learn_init (vlib_main_t * vm)
726 {
727   gbp_learn_main_t *glm = &gbp_learn_main;
728   vlib_thread_main_t *tm = &vlib_thread_main;
729
730   /* Initialize the feature next-node indices */
731   feat_bitmap_init_next_nodes (vm,
732                                gbp_learn_l2_node.index,
733                                L2INPUT_N_FEAT,
734                                l2input_get_feat_names (),
735                                glm->gl_l2_input_feat_next);
736
737   throttle_init (&glm->gl_l2_throttle,
738                  tm->n_vlib_mains, GBP_ENDPOINT_HASH_LEARN_RATE);
739
740   throttle_init (&glm->gl_l3_throttle,
741                  tm->n_vlib_mains, GBP_ENDPOINT_HASH_LEARN_RATE);
742
743   glm->gl_logger = vlib_log_register_class ("gbp", "learn");
744
745   return 0;
746 }
747
748 VLIB_INIT_FUNCTION (gbp_learn_init);
749
750 /*
751  * fd.io coding-style-patch-verification: ON
752  *
753  * Local Variables:
754  * eval: (c-set-style "gnu")
755  * End:
756  */