2 * Copyright (c) 2015 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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include <vnet/vnet.h>
17 #include <vnet/devices/devices.h>
18 #include <vnet/feature/feature.h>
19 #include <vnet/ip/ip.h>
20 #include <vnet/ethernet/ethernet.h>
21 #include <vlib/stats/stats.h>
23 vnet_device_main_t vnet_device_main;
26 device_input_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
32 VLIB_REGISTER_NODE (device_input_node) = {
33 .function = device_input_fn,
34 .name = "device-input",
35 .runtime_data_bytes = sizeof (vnet_hw_if_rx_node_runtime_t),
36 .type = VLIB_NODE_TYPE_INPUT,
37 .state = VLIB_NODE_STATE_DISABLED,
38 .n_next_nodes = VNET_DEVICE_INPUT_N_NEXT_NODES,
39 .next_nodes = VNET_DEVICE_INPUT_NEXT_NODES,
42 VNET_FEATURE_ARC_INIT (device_input, static) =
44 .arc_name = "device-input",
45 .start_nodes = VNET_FEATURES ("device-input"),
46 .last_in_arc = "ethernet-input",
47 .arc_index_ptr = &feature_main.device_input_feature_arc_index,
50 VNET_FEATURE_INIT (l2_patch, static) = {
51 .arc_name = "device-input",
52 .node_name = "l2-patch",
53 .runs_before = VNET_FEATURES ("ethernet-input"),
56 VNET_FEATURE_INIT (worker_handoff, static) = {
57 .arc_name = "device-input",
58 .node_name = "worker-handoff",
59 .runs_before = VNET_FEATURES ("ethernet-input"),
62 VNET_FEATURE_INIT (span_input, static) = {
63 .arc_name = "device-input",
64 .node_name = "span-input",
65 .runs_before = VNET_FEATURES ("ethernet-input"),
68 VNET_FEATURE_INIT (p2p_ethernet_node, static) = {
69 .arc_name = "device-input",
70 .node_name = "p2p-ethernet-input",
71 .runs_before = VNET_FEATURES ("ethernet-input"),
74 VNET_FEATURE_INIT (ethernet_input, static) = {
75 .arc_name = "device-input",
76 .node_name = "ethernet-input",
77 .runs_before = 0, /* not before any other features */
81 input_rate_collector_fn (vlib_stats_collector_data_t *d)
83 vlib_stats_segment_t *sm = vlib_stats_get_segment ();
84 vlib_stats_entry_t *e2 = sm->directory_vector + d->private_data;
85 static u64 last_input_packets = 0;
88 now = vlib_time_now (vlib_get_main ());
89 u64 input_packets = vnet_get_aggregate_rx_packets ();
92 d->entry->value = (f64) (input_packets - last_input_packets) / dt;
93 last_input_packets = input_packets;
98 vnet_device_init (vlib_main_t * vm)
100 vnet_device_main_t *vdm = &vnet_device_main;
101 vlib_thread_main_t *tm = vlib_get_thread_main ();
102 vlib_thread_registration_t *tr;
103 vlib_stats_collector_reg_t reg = {};
106 vec_validate_aligned (vdm->workers, tm->n_vlib_mains - 1,
107 CLIB_CACHE_LINE_BYTES);
109 p = hash_get_mem (tm->thread_registrations_by_name, "workers");
110 tr = p ? (vlib_thread_registration_t *) p[0] : 0;
111 if (tr && tr->count > 0)
113 vdm->first_worker_thread_index = tr->first_index;
114 vdm->next_worker_thread_index = tr->first_index;
115 vdm->last_worker_thread_index = tr->first_index + tr->count - 1;
118 reg.private_data = vlib_stats_add_timestamp ("/sys/last_update");
119 reg.entry_index = vlib_stats_add_gauge ("/sys/input_rate");
120 reg.collect_fn = input_rate_collector_fn;
121 vlib_stats_register_collector_fn (®);
126 VLIB_INIT_FUNCTION (vnet_device_init);
129 * fd.io coding-style-patch-verification: ON
132 * eval: (c-set-style "gnu")