Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 1 | /* |
| 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: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 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. |
| 14 | */ |
| 15 | |
| 16 | #include <boost/algorithm/string.hpp> |
| 17 | |
| 18 | #include "vom/interface.hpp" |
| 19 | #include "vom/sub_interface.hpp" |
| 20 | #include "vom/tap_interface.hpp" |
| 21 | |
| 22 | namespace VOM { |
| 23 | std::unique_ptr<interface> |
| 24 | interface::new_interface(const vapi_payload_sw_interface_details& vd) |
| 25 | { |
| 26 | std::unique_ptr<interface> up_itf; |
| 27 | |
| 28 | /** |
| 29 | * Determine the interface type from the name and VLAN attributes |
| 30 | */ |
| 31 | std::string name = reinterpret_cast<const char*>(vd.interface_name); |
| 32 | type_t type = interface::type_t::from_string(name); |
| 33 | admin_state_t state = interface::admin_state_t::from_int(vd.link_up_down); |
| 34 | handle_t hdl(vd.sw_if_index); |
| 35 | l2_address_t l2_address(vd.l2_address, vd.l2_address_length); |
| 36 | |
| 37 | if (type_t::AFPACKET == type) { |
| 38 | /* |
| 39 | * need to strip VPP's "host-" prefix from the interface name |
| 40 | */ |
| 41 | name = name.substr(5); |
| 42 | } |
| 43 | /** |
| 44 | * if the tag is set, then we wrote that to specify a name to make |
| 45 | * the interface type more specific |
| 46 | */ |
| 47 | if (vd.tag[0] != 0) { |
| 48 | name = std::string(reinterpret_cast<const char*>(vd.tag)); |
| 49 | type = interface::type_t::from_string(name); |
| 50 | } |
| 51 | |
| 52 | /* |
| 53 | * pull out the other special cases |
| 54 | */ |
| 55 | if (type_t::TAP == type) { |
| 56 | /* |
| 57 | * TAP interface |
| 58 | */ |
| 59 | up_itf.reset(new tap_interface(hdl, name, state, route::prefix_t())); |
| 60 | } else if ((name.find(".") != std::string::npos) && (0 != vd.sub_id)) { |
| 61 | /* |
| 62 | * Sub-interface |
| 63 | * split the name into the parent and VLAN |
| 64 | */ |
| 65 | std::vector<std::string> parts; |
| 66 | boost::split(parts, name, boost::is_any_of(".")); |
| 67 | |
| 68 | interface parent(parts[0], type, state); |
| 69 | up_itf.reset(new sub_interface(hdl, parent, state, vd.sub_id)); |
| 70 | } else if (type_t::VXLAN == type) { |
| 71 | /* |
| 72 | * there's not enough inforation in a SW interface record to |
| 73 | * construct |
| 74 | * a VXLAN tunnel. so skip it. |
| 75 | */ |
| 76 | } else { |
| 77 | up_itf.reset(new interface(hdl, l2_address, name, type, state)); |
| 78 | } |
| 79 | |
| 80 | return (up_itf); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | /* |
| 85 | * fd.io coding-style-patch-verification: ON |
| 86 | * |
| 87 | * Local Variables: |
| 88 | * eval: (c-set-style "mozilla") |
| 89 | * End: |
| 90 | */ |