/* * Copyright (c) 2015 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. */ /* * interface_format.c: interface formatting * * Copyright (c) 2008 Eliot Dresselhaus * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include #include #include #include #include u8 * format_vtr (u8 * s, va_list * args) { u32 vtr_op = va_arg (*args, u32); u32 dot1q = va_arg (*args, u32); u32 tag1 = va_arg (*args, u32); u32 tag2 = va_arg (*args, u32); switch (vtr_op) { case L2_VTR_DISABLED: return format (s, "none"); case L2_VTR_PUSH_1: return format (s, "push-1 %s %d", dot1q ? "dot1q" : "dot1ad", tag1); case L2_VTR_PUSH_2: return format (s, "push-2 %s %d %d", dot1q ? "dot1q" : "dot1ad", tag1, tag2); case L2_VTR_POP_1: return format (s, "pop-1"); case L2_VTR_POP_2: return format (s, "pop-2"); case L2_VTR_TRANSLATE_1_1: return format (s, "trans-1-1 %s %d", dot1q ? "dot1q" : "dot1ad", tag1); case L2_VTR_TRANSLATE_1_2: return format (s, "trans-1-2 %s %d %d", dot1q ? "dot1q" : "dot1ad", tag1, tag2); case L2_VTR_TRANSLATE_2_1: return format (s, "trans-2-1 %s %d", dot1q ? "dot1q" : "dot1ad", tag1); case L2_VTR_TRANSLATE_2_2: return format (s, "trans-2-2 %s %d %d", dot1q ? "dot1q" : "dot1ad", tag1, tag2); default: return format (s, "none"); } } u8 * format_vnet_sw_interface_flags (u8 * s, va_list * args) { u32 flags = va_arg (*args, u32); if (flags & VNET_SW_INTERFACE_FLAG_ERROR) s = format (s, "error"); else { s = format (s, "%s", (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "down"); if (flags & VNET_SW_INTERFACE_FLAG_PUNT) s = format (s, "/punt"); } return s; } u8 * format_vnet_hw_interface_rx_mode (u8 * s, va_list * args) { vnet_hw_interface_rx_mode mode = va_arg (*args, vnet_hw_interface_rx_mode); if (mode == VNET_HW_INTERFACE_RX_MODE_POLLING) return format (s, "polling"); if (mode == VNET_HW_INTERFACE_RX_MODE_INTERRUPT) return format (s, "interrupt"); if (mode == VNET_HW_INTERFACE_RX_MODE_ADAPTIVE) return format (s, "adaptive"); return format (s, "unknown"); } u8 * format_vnet_hw_interface_link_speed (u8 * s, va_list * args) { u32 link_speed = va_arg (*args, u32); if (link_speed == 0) return format (s, "unknown"); if (link_speed >= 1000000) return format (s, "%f Gbps", (f64) link_speed / 1000000); if (link_speed >= 1000) return format (s, "%f Mbps", (f64) link_speed / 1000); return format (s, "%u Kbps", link_speed); } u8 * format_vnet_hw_interface (u8 * s, va_list * args) { vnet_main_t *vnm = va_arg (*args, vnet_main_t *); vnet_hw_interface_t *hi = va_arg (*args, vnet_hw_interface_t *); vnet_hw_interface_class_t *hw_class; vnet_device_class_t *dev_class; int verbose = va_arg (*args, int); u32 indent; if (!hi) return format (s, "%=32s%=6s%=8s%s", "Name", "Idx", "Link", "Hardware"); indent = format_get_indent (s); s = format (s, "%-32v%=6d", hi->name, hi->hw_if_index); if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) s = format (s, "%=8s", "slave"); else s = format (s, "%=8s", hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP ? "up" : "down"); hw_class = vnet_get_hw_interface_class (vnm, hi->hw_class_index); dev_class = vnet_get_device_class (vnm, hi->dev_class_index); if (hi->bond_info && (hi->bond_info != VNET_HW_INTERFACE_BOND_INFO_SLAVE)) { int hw_idx; s = format (s, "Slave-Idx:"); clib_bitmap_foreach (hw_idx, hi->bond_info, s = format (s, " %d", hw_idx)); } else if (dev_class->format_device_name) s = format (s, "%U", dev_class->format_device_name, hi->dev_instance); else s = format (s, "%s%d", dev_class->name, hi->dev_instance); s = format (s, "\n%ULink speed: %U", format_white_space, indent + 2, format_vnet_hw_interface_link_speed, hi->link_speed); if (verbose) { if (hw_class->format_device) s = format (s, "\n%U%U", format_white_space, indent + 2, hw_class->format_device, hi->hw_if_index, verbose); else { s = format (s, "\n%U%s", format_white_space, indent + 2, hw_class->name); if (hw_class->format_address && vec_len (hi->hw_address) > 0) s = format (s, " address %U", hw_class->format_address, hi->hw_address); } if (dev_class->format_device) s = format (s, "\n%U%U", format_white_space, indent + 2, dev_class->format_device, hi->dev_instance, verbose); } return s; } u8 * format_vnet_sw_interface_name (u8 * s, va_list * args) { vnet_main_t *vnm = va_arg (*args, vnet_main_t *); vnet_sw_interface_t *si = va_arg (*args, vnet_sw_interface_t *); vnet_sw_interface_t *si_sup = vnet_get_sup_sw_interface (vnm, si->sw_if_index); vnet_hw_interface_t *hi_sup; ASSERT (si_sup->type == V
;;; plugin-cmake-skel.el - vpp engine plug-in foo.am skeleton
;;;
;;; Copyright (c) 2016 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.

(require 'skeleton)

(define-skeleton skel-plugin-cmakelists-text-fragment
"Insert a plug-in 'CMakeLists.txt' skeleton "
nil
'(if (not (boundp 'plugin-name))
     (setq plugin-name (read-string "Plugin name: ")))
'(setq PLUGIN-NAME (upcase plugin-name))

"
# Copyright (c) <current-year> <your-organization>
# 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.

add_vpp_plugin("plugin-name"
  SOURCES
  " plugin-name ".c 
  node.c 
  " plugin-name "_periodic.c
  " plugin-name ".h

  MULTIARCH_SOURCES
  node.c 

  API_FILES
  " plugin-name".api

  INSTALL_HEADERS
  " plugin-name "_all_api_h.h
  " plugin-name "_msg_enum.h

  API_TEST_SOURCES
  " plugin-name "_test.c
)
")
))) { hw_if_index = p[0]; id_specified = 1; } else if (unformat (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index)) id_specified = 0; else goto done; hi = vnet_get_hw_interface (vnm, hw_if_index); if (!id_specified) { sw_if_index = hi->sw_if_index; } else { if (!(p = hash_get (hi->sub_interface_sw_if_index_by_id, id))) goto done; sw_if_index = p[0]; } if (!vnet_sw_interface_is_api_visible (vnm, sw_if_index)) goto done; *result = sw_if_index; error = 1; done: vec_free (if_name); return error; } uword unformat_vnet_sw_interface_flags (unformat_input_t * input, va_list * args) { u32 *result = va_arg (*args, u32 *); u32 flags = 0; if (unformat (input, "up")) flags |= VNET_SW_INTERFACE_FLAG_ADMIN_UP; else if (unformat (input, "down")) flags &= ~VNET_SW_INTERFACE_FLAG_ADMIN_UP; else if (unformat (input, "punt")) flags |= VNET_SW_INTERFACE_FLAG_PUNT; else if (unformat (input, "enable")) flags &= ~VNET_SW_INTERFACE_FLAG_PUNT; else return 0; *result = flags; return 1; } uword unformat_vnet_hw_interface_flags (unformat_input_t * input, va_list * args) { u32 *result = va_arg (*args, u32 *); u32 flags = 0; if (unformat (input, "up")) flags |= VNET_HW_INTERFACE_FLAG_LINK_UP; else if (unformat (input, "down")) flags &= ~VNET_HW_INTERFACE_FLAG_LINK_UP; else return 0; *result = flags; return 1; } /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */