2 * Copyright (c) 2017 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 <boost/algorithm/string.hpp>
18 #include "vom/bond_interface.hpp"
19 #include "vom/bond_member.hpp"
20 #include "vom/interface_factory.hpp"
21 #include "vom/sub_interface.hpp"
22 #include "vom/tap_interface.hpp"
25 std::shared_ptr<interface>
26 interface_factory::new_interface(const vapi_payload_sw_interface_details& vd)
28 std::shared_ptr<interface> sp;
31 * Determine the interface type from the name and VLAN attributes
33 std::string name = reinterpret_cast<const char*>(vd.interface_name);
34 interface::type_t type = interface::type_t::from_string(name);
35 interface::admin_state_t state =
36 interface::admin_state_t::from_int(vd.link_up_down);
37 handle_t hdl(vd.sw_if_index);
38 l2_address_t l2_address(vd.l2_address, vd.l2_address_length);
41 if (interface::type_t::AFPACKET == type) {
43 * need to strip VPP's "host-" prefix from the interface name
45 name = name.substr(5);
48 * if the tag is set, then we wrote that to specify a name to make
49 * the interface type more specific
52 tag = std::string(reinterpret_cast<const char*>(vd.tag));
55 if (!tag.empty() && interface::type_t::LOOPBACK == type) {
57 type = interface::type_t::from_string(name);
61 * pull out the other special cases
63 if (interface::type_t::TAP == type) {
67 sp = tap_interface(name, state, route::prefix_t()).singular();
68 if (sp && !tag.empty())
70 } else if ((name.find(".") != std::string::npos) && (0 != vd.sub_id)) {
73 * split the name into the parent and VLAN
75 std::vector<std::string> parts;
76 boost::split(parts, name, boost::is_any_of("."));
78 interface parent(parts[0], type, state, tag);
79 sp = sub_interface(parent, state, vd.sub_id).singular();
80 } else if (interface::type_t::VXLAN == type) {
82 * there's not enough information in a SW interface record to
83 * construct a VXLAN tunnel. so skip it. They have
84 * their own dump routines
86 } else if (interface::type_t::VHOST == type) {
88 * vhost interface already exist in db, look for it using
91 sp = interface::find(hdl);
98 } else if (interface::type_t::BOND == type) {
99 sp = bond_interface(name, state, l2_address,
100 bond_interface::mode_t::UNSPECIFIED)
103 sp = interface(name, type, state, tag).singular();
108 * set the handle on the intterface - N.B. this is the sigluar instance
117 std::shared_ptr<interface>
118 interface_factory::new_vhost_user_interface(
119 const vapi_payload_sw_interface_vhost_user_details& vd)
121 std::shared_ptr<interface> sp;
122 std::string name = reinterpret_cast<const char*>(vd.sock_filename);
123 interface::type_t type = interface::type_t::from_string(name);
124 handle_t hdl(vd.sw_if_index);
126 sp = interface(name, type, interface::admin_state_t::DOWN).singular();
131 std::shared_ptr<bond_interface>
132 interface_factory::new_bond_interface(
133 const vapi_payload_sw_interface_bond_details& vd)
135 std::shared_ptr<bond_interface> sp;
136 std::string name = reinterpret_cast<const char*>(vd.interface_name);
137 handle_t hdl(vd.sw_if_index);
138 bond_interface::mode_t mode =
139 bond_interface::mode_t::from_numeric_val(vd.mode);
140 bond_interface::lb_t lb = bond_interface::lb_t::from_numeric_val(vd.lb);
141 sp = bond_interface::find(hdl);
150 interface_factory::new_bond_member_interface(
151 const vapi_payload_sw_interface_slave_details& vd)
153 std::shared_ptr<bond_member> sp;
154 std::string name = reinterpret_cast<const char*>(vd.interface_name);
155 handle_t hdl(vd.sw_if_index);
156 bond_member::mode_t mode =
157 bond_member::mode_t::from_numeric_val(vd.is_passive);
158 bond_member::rate_t rate =
159 bond_member::rate_t::from_numeric_val(vd.is_long_timeout);
160 std::shared_ptr<interface> itf = interface::find(hdl);
161 bond_member bm(*itf, mode, rate);
167 * fd.io coding-style-patch-verification: ON
170 * eval: (c-set-style "mozilla")