vxlan: vxlan/vxlan.api API cleanup
[vpp.git] / extras / vom / vom / arp_proxy_config.hpp
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 #ifndef __VOM_ARP_PROXY_CONFIG_H__
17 #define __VOM_ARP_PROXY_CONFIG_H__
18
19 #include "vom/hw.hpp"
20 #include "vom/inspect.hpp"
21 #include "vom/object_base.hpp"
22 #include "vom/om.hpp"
23 #include "vom/singular_db.hpp"
24
25 namespace VOM {
26 /**
27  * A representation of LLDP client configuration on an interface
28  */
29 class arp_proxy_config : public object_base
30 {
31 public:
32   /**
33    * Key type
34    */
35   typedef std::pair<boost::asio::ip::address_v4, boost::asio::ip::address_v4>
36     key_t;
37
38   /**
39    * Construct a new object matching the desried state
40    */
41   arp_proxy_config(const boost::asio::ip::address_v4& low,
42                    const boost::asio::ip::address_v4& high);
43
44   /**
45    * Copy Constructor
46    */
47   arp_proxy_config(const arp_proxy_config& o);
48
49   /**
50    * Destructor
51    */
52   ~arp_proxy_config();
53
54   /**
55    * Return the 'singular' of the LLDP config that matches this object
56    */
57   std::shared_ptr<arp_proxy_config> singular() const;
58
59   /**
60    * convert to string format for debug purposes
61    */
62   std::string to_string() const;
63
64   /**
65    * Dump all LLDP configs into the stream provided
66    */
67   static void dump(std::ostream& os);
68
69 private:
70   /**
71    * Class definition for listeners to OM events
72    */
73   class event_handler : public OM::listener, public inspect::command_handler
74   {
75   public:
76     event_handler();
77     virtual ~event_handler() = default;
78
79     /**
80      * Handle a populate event
81      */
82     void handle_populate(const client_db::key_t& key);
83
84     /**
85      * Handle a replay event
86      */
87     void handle_replay();
88
89     /**
90      * Show the object in the Singular DB
91      */
92     void show(std::ostream& os);
93
94     /**
95      * Get the sortable Id of the listener
96      */
97     dependency_t order() const;
98   };
99
100   /**
101    * event_handler to register with OM
102    */
103   static event_handler m_evh;
104
105   /**
106    * Enquue commonds to the VPP command Q for the update
107    */
108   void update(const arp_proxy_config& obj);
109
110   /**
111    * Find or add LLDP config to the OM
112    */
113   static std::shared_ptr<arp_proxy_config> find_or_add(
114     const arp_proxy_config& temp);
115
116   /*
117    * It's the OM class that calls singular()
118    */
119   friend class OM;
120
121   /**
122    * It's the singular_db class that calls replay()
123    */
124   friend class singular_db<arp_proxy_config::key_t, arp_proxy_config>;
125
126   /**
127    * Sweep/reap the object if still stale
128    */
129   void sweep(void);
130
131   /**
132    * replay the object to create it in hardware
133    */
134   void replay(void);
135
136   /**
137    * Address range
138    */
139   const boost::asio::ip::address_v4 m_low;
140   const boost::asio::ip::address_v4 m_high;
141
142   /**
143    * A map of all ArpProxy configs keyed against the interface.
144    */
145   static singular_db<arp_proxy_config::key_t, arp_proxy_config> m_db;
146
147   /**
148    * HW configuration for the config. The bool representing the
149    * do/don't configured/unconfigured.
150    */
151   HW::item<bool> m_config;
152 };
153
154 std::ostream& operator<<(std::ostream& os, const arp_proxy_config::key_t& key);
155 };
156
157 /*
158  * fd.io coding-style-patch-verification: ON
159  *
160  * Local Variables:
161  * eval: (c-set-style "mozilla")
162  * End:
163  */
164
165 #endif