summaryrefslogtreecommitdiffstats
path: root/src/vnet/l2/l2_bvi_node.c
blob: dd7e1df46ced0335a3ef4d641b57467c775b6cc6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
 * l2_bvi.c : layer 2 Bridged Virtual Interface
 *
 * Copyright (c) 2013 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <vnet/l2/l2_bvi.h>

/**
 * send packets to l2-input.
 */
VNET_DEVICE_CLASS_TX_FN (bvi_device_class) (vlib_main_t * vm,
					    vlib_node_runtime_t * node,
					    vlib_frame_t * frame)
{
  u32 sw_if_indices[VLIB_FRAME_SIZE], *sw_if_index;
  vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b;
  u16 nexts[VLIB_FRAME_SIZE];
  u32 n_left, *from;

  n_left = frame->n_vectors;
  from = vlib_frame_vector_args (frame);

  vlib_get_buffers (vm, from, bufs, n_left);

  b = bufs;
  sw_if_index = sw_if_indices;

  /* It's all going to l2-input */
  clib_memset_u16 (nexts, 0, VLIB_FRAME_SIZE);

  /*
   * For each packet:
   *  - fixup the L2 length of the packet
   *  - set the RX interface (which the bridge will use) to the
   *    TX interface (which routing has chosen)
   *  - Set the TX interface to the special ID so the DP knows this is a BVI
   * Don't counts packets and bytes, that's done in the bviX-output node
   */
  while (n_left >= 4)
    {
      /* Prefetch next iteration. */
      if (PREDICT_TRUE (n_left >= 8))
	{
	  /* LOAD pre-fetch since meta and packet data is read */
	  vlib_prefetch_buffer_header (b[4], LOAD);
	  vlib_prefetch_buffer_header (b[5], LOAD);
	  vlib_prefetch_buffer_header (b[6], LOAD);
	  vlib_prefetch_buffer_header (b[7], LOAD);

	  vlib_prefetch_buffer_data (b[4], LOAD);
	  vlib_prefetch_buffer_data (b[5], LOAD);
	  vlib_prefetch_buffer_data (b[6], LOAD);
	  vlib_prefetch_buffer_data (b[7], LOAD);
	}

      vnet_update_l2_len (b[0]);
      vnet_update_l2_len (b[1]);
      vnet_update_l2_len (b[2]);
      vnet_update_l2_len (b[3]);

      sw_if_index[0] = vnet_buffer (b[0])->sw_if_index[VLIB_TX];
      sw_if_index[1] = vnet_buffer (b[1])->sw_if_index[VLIB_TX];
      sw_if_index[2] = vnet_buffer (b[2])->sw_if_index[VLIB_TX];
      sw_if_index[3] = vnet_buffer (b[3])->sw_if_index[VLIB_TX];

      vnet_buffer (b[0])->sw_if_index[VLIB_TX] = L2INPUT_BVI;
      vnet_buffer (b[1])->sw_if_index[VLIB_TX] = L2INPUT_BVI;
      vnet_buffer (b[2])->sw_if_index[VLIB_TX] = L2INPUT_BVI;
      vnet_buffer (b[3])->sw_if_index[VLIB_TX] = L2INPUT_BVI;

      vnet_buffer (b[0])->sw_if_index[VLIB_RX] = sw_if_index[0];
      vnet_buffer (b[1])->sw_if_index[VLIB_RX] = sw_if_index[1];
      vnet_buffer (b[2])->sw_if_index[VLIB_RX] = sw_if_index[2];
      vnet_buffer (b[3])->sw_if_index[VLIB_RX] = sw_if_index[3];

      b += 4;
      n_left -= 4;
      sw_if_index += 4;
    }
  while (n_left)
    {
      sw_if_index[0] = vnet_buffer (b[0])->sw_if_index[VLIB_TX];
      vnet_buffer (b[0])->sw_if_index[VLIB_TX] = L2INPUT_BVI;
      vnet_buffer (b[0])->sw_if_index[VLIB_RX] = sw_if_index[0];

      vnet_update_l2_len (b[0]);

      b += 1;
      n_left -= 1;
      sw_if_index += 1;
    }

  vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors);

  return frame->n_vectors;
}

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */
/span> ed->data[3] = _s_idx; \ } #define VCL_EVT_CLOSE_HANDLER(_s, _rv, ...) \ { \ ELOG_TYPE_DECLARE (_e) = \ { \ .format = "session_close:rv:%d", \ .format_args = "i4", \ }; \ VCL_DECLARE_ETD (_s, _e, 1); \ ed->data[0] = _rv; \ } #define VCL_EVT_SESSION_TIMEOUT_HANDLER(_s, _state, ...) \ { \ ELOG_TYPE_DECLARE (_e) = \ { \ .format = "ERR: timeout state:%d", \ .format_args = "i4", \ }; \ VCL_DECLARE_ETD (_s, _e, 1); \ ed->data[0] = _state; \ } #define VCL_EVT_TIMEOUT_HANDLER(_vcm, _state, ...) \ { \ ELOG_TYPE_DECLARE (_e) = \ { \ .format = "ERR: timeout state:%d", \ .format_args = "i4", \ }; \ struct { u32 data; } * ed; \ ed = ELOG_TRACK_DATA (&_vcm->elog_main, _e, _vcm->elog_track); \ ed->data[0] = _state; \ } #define VCL_EVT_DETACH_HANDLER(_vcm, ...) \ { \ ELOG_TYPE_DECLARE (_e) = \ { \ .format = "app_detach:C:%d", \ .format_args = "i4", \ }; \ struct { u32 data; } * ed; \ ed = ELOG_TRACK_DATA (&_vcm->elog_main, _e, _vcm->elog_track); \ ed->data = _vcm->my_client_index; \ } #define VCL_EVT_UNBIND_HANDLER(_s, ...) \ { \ ELOG_TYPE_DECLARE (_e) = \ { \ .format = "unbind: handle:%x", \ .format_args = "i8", \ }; \ struct { u64 data; } * ed; \ ed = ELOG_TRACK_DATA (&vcm->elog_main, _e, _s->elog_track); \ ed->data = _s->vpp_handle; \ } #define VCL_EVT_EPOLL_CREATE_HANDLER(_s, _s_idx, ...) \ { \ VCL_EVT_SESSION_INIT_HANDLER (_s, _s_idx); \ ELOG_TYPE_DECLARE (_e) = \ { \ .format = "create epoll vep_idx: %d", \ .format_args = "i4", \ }; \ VCL_DECLARE_ETD (_s, _e, 1); \ ed->data[0] = _s_idx; \ } #define VCL_EVT_EPOLL_CTLADD_HANDLER(_s, _evts, _evt_data, ...) \ { \ ELOG_TYPE_DECLARE (_e) = \ { \ .format = "epoll_ctladd: events:%x data:%x", \ .format_args = "i4", \ }; \ struct { \ u32 events; \ u64 event_data; \ } * ed; \ ed = ELOG_TRACK_DATA (&vcm->elog_main, _e, _s->elog_track); \ ed->events = _evts; \ ed->event_data = _evt_data; \ } #define VCL_EVT_EPOLL_CTLDEL_HANDLER(_s, _vep_idx, ...) \ { \ ELOG_TYPE_DECLARE (_e) = \ { \ .format = "epoll_ctldel: vep:%d", \ .format_args = "i4", \ }; \ VCL_DECLARE_ETD (_s, _e, 1); \ ed->data[0] = _vep_idx; \ } #define vcl_elog_init(_vcm) \ { \ _vcm->elog_main.lock = clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES, \ CLIB_CACHE_LINE_BYTES);\ _vcm->elog_main.lock[0] = 0; \ _vcm->elog_main.event_ring_size = _vcm->cfg.event_ring_size; \ elog_init (&_vcm->elog_main, _vcm->elog_main.event_ring_size); \ elog_enable_disable (&_vcm->elog_main, 1); \ } #define vcl_elog_stop(_vcm) \ { \ clib_error_t *error = 0; \ char *chroot_file = (char *) format (0, "%s/%d-%d-vcl-elog%c", \ _vcm->cfg.event_log_path, \ _vcm->my_client_index, \ getpid (), 0); \ error = elog_write_file (&_vcm->elog_main, chroot_file, \ 1 /* flush ring */ ); \ if (error) \ clib_error_report (error); \ clib_warning ("[%d] Event Log:'%s' ", getpid (), chroot_file); \ vec_free (chroot_file); \ } #define CONCAT_HELPER(_a, _b) _a##_b #define CC(_a, _b) CONCAT_HELPER(_a, _b) #define vcl_evt(_evt, _args...) CC(_evt, _HANDLER)(_args) #else #define vcl_evt(_evt, _args...) #define vcl_elog_init(_vcm) #define vcl_elog_stop(_vcm) #endif #endif /* SRC_VCL_VCL_DEBUG_H_ */ /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */