2e7eee3ce7c34a5bfb7214d25c75587cfaa5b54d
[vpp.git] / src / vpp-api / 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::VHOST(8, "VHOST");
30 const interface::type_t interface::type_t::BOND(9, "Bond");
31
32 const interface::oper_state_t interface::oper_state_t::DOWN(0, "down");
33 const interface::oper_state_t interface::oper_state_t::UP(1, "up");
34
35 const interface::admin_state_t interface::admin_state_t::DOWN(0, "down");
36 const interface::admin_state_t interface::admin_state_t::UP(1, "up");
37
38 interface::type_t
39 interface::type_t::from_string(const std::string& str)
40 {
41   if ((str.find("Virtual") != std::string::npos) ||
42       (str.find("vhost") != std::string::npos)) {
43     return interface::type_t::VHOST;
44   } else if (str.find("Bond") != std::string::npos) {
45     return interface::type_t::BOND;
46   } else if (str.find("Ethernet") != std::string::npos) {
47     return interface::type_t::ETHERNET;
48   } else if (str.find("vxlan") != std::string::npos) {
49     return interface::type_t::VXLAN;
50   } else if (str.find("loop") != std::string::npos) {
51     return interface::type_t::LOOPBACK;
52   } else if (str.find("host-") != std::string::npos) {
53     return interface::type_t::AFPACKET;
54   } else if (str.find("local") != std::string::npos) {
55     return interface::type_t::LOCAL;
56   } else if (str.find("tap") != std::string::npos) {
57     return interface::type_t::TAP;
58   } else if (str.find("bvi") != std::string::npos) {
59     return interface::type_t::BVI;
60   }
61
62   return interface::type_t::UNKNOWN;
63 }
64
65 interface::type_t::type_t(int v, const std::string& s)
66   : enum_base<interface::type_t>(v, s)
67 {
68 }
69
70 interface::oper_state_t::oper_state_t(int v, const std::string& s)
71   : enum_base<interface::oper_state_t>(v, s)
72 {
73 }
74
75 interface::admin_state_t::admin_state_t(int v, const std::string& s)
76   : enum_base<interface::admin_state_t>(v, s)
77 {
78 }
79
80 interface::admin_state_t
81 interface::admin_state_t::from_int(uint8_t v)
82 {
83   if (0 == v) {
84     return (interface::admin_state_t::DOWN);
85   }
86   return (interface::admin_state_t::UP);
87 }
88
89 interface::oper_state_t
90 interface::oper_state_t::from_int(uint8_t v)
91 {
92   if (0 == v) {
93     return (interface::oper_state_t::DOWN);
94   }
95   return (interface::oper_state_t::UP);
96 }
97 }
98
99 /*
100  * fd.io coding-style-patch-verification: ON
101  *
102  * Local Variables:
103  * eval: (c-set-style "mozilla")
104  * End:
105  */