vom: Add TAPv2 support
[vpp.git] / extras / vom / vom / interface_types.cpp
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 "vom/interface.hpp"
17 namespace VOM {
18 /*
19  * constants and enums
20  */
21 const interface::type_t interface::type_t::UNKNOWN(0, "unknown");
22 const interface::type_t interface::type_t::BVI(1, "BVI");
23 const interface::type_t interface::type_t::ETHERNET(2, "Ethernet");
24 const interface::type_t interface::type_t::VXLAN(3, "VXLAN");
25 const interface::type_t interface::type_t::AFPACKET(4, "AFPACKET");
26 const interface::type_t interface::type_t::LOOPBACK(5, "LOOPBACK");
27 const interface::type_t interface::type_t::LOCAL(6, "LOCAL");
28 const interface::type_t interface::type_t::TAP(7, "TAP");
29 const interface::type_t interface::type_t::TAPV2(8, "TAPV2");
30 const interface::type_t interface::type_t::VHOST(9, "VHOST");
31 const interface::type_t interface::type_t::BOND(10, "Bond");
32
33 const interface::oper_state_t interface::oper_state_t::DOWN(0, "down");
34 const interface::oper_state_t interface::oper_state_t::UP(1, "up");
35
36 const interface::admin_state_t interface::admin_state_t::DOWN(0, "down");
37 const interface::admin_state_t interface::admin_state_t::UP(1, "up");
38
39 const interface::stats_type_t interface::stats_type_t::DETAILED(0, "detailed");
40 const interface::stats_type_t interface::stats_type_t::NORMAL(1, "normal");
41
42 interface::type_t
43 interface::type_t::from_string(const std::string& str)
44 {
45   if ((str.find("Virtual") != std::string::npos) ||
46       (str.find("vhost") != std::string::npos) ||
47       (str.find("vhu") != std::string::npos)) {
48     return interface::type_t::VHOST;
49   } else if (str.find("Bond") != std::string::npos) {
50     return interface::type_t::BOND;
51   } else if (str.find("Ethernet") != std::string::npos) {
52     return interface::type_t::ETHERNET;
53   } else if (str.find("vxlan") != std::string::npos) {
54     return interface::type_t::VXLAN;
55   } else if ((str.find("loop") != std::string::npos) ||
56              (str.find("recirc") != std::string::npos)) {
57     return interface::type_t::LOOPBACK;
58   } else if (str.find("host-") != std::string::npos) {
59     return interface::type_t::AFPACKET;
60   } else if (str.find("local") != std::string::npos) {
61     return interface::type_t::LOCAL;
62   } else if ((str.find("tapcli") != std::string::npos) ||
63              (str.find("tuntap") != std::string::npos)) {
64     return interface::type_t::TAP;
65   } else if (str.find("tap") != std::string::npos) {
66     return interface::type_t::TAPV2;
67   } else if (str.find("bvi") != std::string::npos) {
68     return interface::type_t::BVI;
69   }
70
71   return interface::type_t::UNKNOWN;
72 }
73
74 interface::type_t::type_t(int v, const std::string& s)
75   : enum_base<interface::type_t>(v, s)
76 {
77 }
78
79 interface::oper_state_t::oper_state_t(int v, const std::string& s)
80   : enum_base<interface::oper_state_t>(v, s)
81 {
82 }
83
84 interface::admin_state_t::admin_state_t(int v, const std::string& s)
85   : enum_base<interface::admin_state_t>(v, s)
86 {
87 }
88
89 interface::stats_type_t::stats_type_t(int v, const std::string& s)
90   : enum_base<interface::stats_type_t>(v, s)
91 {
92 }
93
94 interface::admin_state_t
95 interface::admin_state_t::from_int(uint8_t v)
96 {
97   if (0 == v) {
98     return (interface::admin_state_t::DOWN);
99   }
100   return (interface::admin_state_t::UP);
101 }
102
103 interface::oper_state_t
104 interface::oper_state_t::from_int(uint8_t v)
105 {
106   if (0 == v) {
107     return (interface::oper_state_t::DOWN);
108   }
109   return (interface::oper_state_t::UP);
110 }
111 }
112
113 /*
114  * fd.io coding-style-patch-verification: ON
115  *
116  * Local Variables:
117  * eval: (c-set-style "mozilla")
118  * End:
119  */