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