vxlan: vxlan/vxlan.api API cleanup
[vpp.git] / extras / vom / vom / bond_member.hpp
1 /*
2  * Copyright (c) 2018 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 #ifndef __VOM_BOND_MEMBER_H__
17 #define __VOM_BOND_MEMBER_H__
18
19 #include "vom/interface.hpp"
20 #include <vapi/bond.api.vapi.hpp>
21
22 namespace VOM {
23 /**
24  * A bond-member. e.g. a bond_member interface
25  */
26 class bond_member
27 {
28 public:
29   /**
30    * A member interface mode
31    */
32   struct mode_t : enum_base<mode_t>
33   {
34     /**
35      * Active member interface mode
36      */
37     const static mode_t ACTIVE;
38     /**
39      * Passive member interface mode
40      */
41     const static mode_t PASSIVE;
42
43     /**
44      * Convert VPP's value of the bond to a mode
45      */
46     static const mode_t from_numeric_val(uint8_t v);
47
48   private:
49     /**
50      * Private constructor taking the value and the string name
51      */
52     mode_t(int v, const std::string& s);
53   };
54
55   /**
56    * A member interface rate
57    */
58   struct rate_t : enum_base<rate_t>
59   {
60     /**
61      * Fast member interface rate
62      */
63     const static rate_t FAST;
64     /**
65      * SLOW member interface rate
66      */
67     const static rate_t SLOW;
68
69     /**
70      * Convert VPP's value of the bond to a mode
71      */
72     static const rate_t from_numeric_val(uint8_t v);
73
74   private:
75     /**
76      * Private constructor taking the value and the string name
77      */
78     rate_t(int v, const std::string& s);
79   };
80
81   bond_member(const interface& itf, mode_t mode, rate_t rate);
82
83   ~bond_member();
84   bond_member(const bond_member& o);
85
86   /**
87    * convert to VPP
88    */
89   void to_vpp(vapi_payload_bond_enslave& bond_enslave) const;
90
91   /**
92    * set the mode
93    */
94   void set(mode_t mode);
95
96   /**
97    * set the rate
98    */
99   void set(rate_t rate);
100
101   /**
102    * convert to string
103    */
104   std::string to_string(void) const;
105
106   /**
107    * less-than operator
108    */
109   bool operator<(const bond_member& mem_itf) const;
110
111   /**
112    * Get the interface handle
113    */
114   const handle_t hdl(void) const;
115
116   /**
117    * equality operator
118    */
119   bool operator==(const bond_member& i) const;
120
121 private:
122   /**
123    * Refernece conter lock on the parent
124    */
125   const std::shared_ptr<interface> m_itf;
126
127   /**
128    * passive vs active member
129    */
130   mode_t m_mode;
131
132   /**
133    * slow 90sec. vs. fast 3sec timeout
134    */
135   rate_t m_rate;
136 };
137 }
138
139 /*
140  * fd.io coding-style-patch-verification: ON
141  *
142  * Local Variables:
143  * eval: (c-set-style "mozilla")
144  * End:
145  */
146
147 #endif