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/interface_factory.hpp"
19 #include "vom/sub_interface.hpp"
20 #include "vom/tap_interface.hpp"
23 std::shared_ptr<interface>
24 interface_factory::new_interface(const vapi_payload_sw_interface_details& vd)
26 std::shared_ptr<interface> sp;
29 * Determine the interface type from the name and VLAN attributes
31 std::string name = reinterpret_cast<const char*>(vd.interface_name);
32 interface::type_t type = interface::type_t::from_string(name);
33 interface::admin_state_t state =
34 interface::admin_state_t::from_int(vd.link_up_down);
35 handle_t hdl(vd.sw_if_index);
36 l2_address_t l2_address(vd.l2_address, vd.l2_address_length);
38 if (interface::type_t::AFPACKET == type) {
40 * need to strip VPP's "host-" prefix from the interface name
42 name = name.substr(5);
45 * if the tag is set, then we wrote that to specify a name to make
46 * the interface type more specific
49 name = std::string(reinterpret_cast<const char*>(vd.tag));
50 type = interface::type_t::from_string(name);
54 * pull out the other special cases
56 if (interface::type_t::TAP == type) {
60 sp = tap_interface(name, state, route::prefix_t()).singular();
61 } else if ((name.find(".") != std::string::npos) && (0 != vd.sub_id)) {
64 * split the name into the parent and VLAN
66 std::vector<std::string> parts;
67 boost::split(parts, name, boost::is_any_of("."));
69 interface parent(parts[0], type, state);
70 sp = sub_interface(parent, state, vd.sub_id).singular();
71 } else if (interface::type_t::VXLAN == type) {
73 * there's not enough information in a SW interface record to
74 * construct a VXLAN tunnel. so skip it.
77 sp = interface(name, type, state).singular();
82 * set the handle on the intterface - N.B. this is the sigluar instance
92 * fd.io coding-style-patch-verification: ON
95 * eval: (c-set-style "mozilla")