VOM reshuffle
[vpp.git] / src / vpp-api / vom / tap_interface.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_TAP_INTERFACE_H__
17 #define __VOM_TAP_INTERFACE_H__
18
19 #include "vom/interface.hpp"
20
21 namespace VOM {
22 /**
23  * A tap-interface. e.g. a tap interface
24  */
25 class tap_interface : public interface
26 {
27 public:
28   tap_interface(const std::string& name,
29                 admin_state_t state,
30                 route::prefix_t prefix);
31
32   tap_interface(const std::string& name,
33                 admin_state_t state,
34                 route::prefix_t prefix,
35                 const l2_address_t& l2_address);
36
37   ~tap_interface();
38   tap_interface(const tap_interface& o);
39
40   /**
41    * Return the matching 'singular instance' of the TAP interface
42    */
43   std::shared_ptr<tap_interface> singular() const;
44
45 private:
46   /**
47    * Class definition for listeners to OM events
48    */
49   class event_handler : public OM::listener, public inspect::command_handler
50   {
51   public:
52     event_handler();
53     virtual ~event_handler() = default;
54
55     /**
56      * Handle a populate event
57      */
58     void handle_populate(const client_db::key_t& key);
59
60     /**
61      * Handle a replay event
62      */
63     void handle_replay();
64
65     /**
66      * Show the object in the Singular DB
67      */
68     void show(std::ostream& os);
69
70     /**
71      * Get the sortable Id of the listener
72      */
73     dependency_t order() const;
74   };
75   static event_handler m_evh;
76
77   /**
78    * Construct with a handle
79    */
80   tap_interface(const handle_t& hdl,
81                 const std::string& name,
82                 admin_state_t state,
83                 route::prefix_t prefix);
84
85   friend class interface_factory;
86
87   /**
88    * Ip Prefix
89    */
90   route::prefix_t m_prefix;
91
92   l2_address_t m_l2_address;
93
94   /**
95    * interface is a friend so it can construct with handles
96    */
97   friend class interface;
98
99   /**
100    * Return the matching 'instance' of the sub-interface
101    *  over-ride from the base class
102    */
103   std::shared_ptr<interface> singular_i() const;
104
105   /**
106    * Virtual functions to construct an interface create commands.
107    */
108   virtual std::queue<cmd*>& mk_create_cmd(std::queue<cmd*>& cmds);
109
110   /**
111    * Virtual functions to construct an interface delete commands.
112    */
113   virtual std::queue<cmd*>& mk_delete_cmd(std::queue<cmd*>& cmds);
114
115   /*
116    * It's the OM class that call singular()
117    */
118   friend class OM;
119 };
120 }
121
122 /*
123  * fd.io coding-style-patch-verification: ON
124  *
125  * Local Variables:
126  * eval: (c-set-style "mozilla")
127  * End:
128  */
129
130 #endif