blob: c7f84e9ec3f7cc0c50697f97a92b27676c7945b6 [file] [log] [blame]
Neale Ranns812ed392017-10-16 04:20:13 -07001/*
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_BRIDGE_DOMAIN_H__
17#define __VOM_BRIDGE_DOMAIN_H__
18
Neale Ranns812ed392017-10-16 04:20:13 -070019#include "vom/enum_base.hpp"
20#include "vom/hw.hpp"
21#include "vom/inspect.hpp"
22#include "vom/object_base.hpp"
23#include "vom/om.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070024#include "vom/singular_db.hpp"
25
Neale Ranns812ed392017-10-16 04:20:13 -070026namespace VOM {
27/**
28 * A base class for all object_base in the VPP object_base-Model.
29 * provides the abstract interface.
30 */
31class bridge_domain : public object_base
32{
33public:
34 /**
Neale Rannsfd920602017-11-23 12:15:00 -080035 * Key Type for Bridge Domains in the sigular DB
36 */
37 typedef uint32_t key_t;
38
39 /**
Neale Ranns10e7a9f2017-11-14 08:40:43 -080040 * Bridge Domain Learning mode
41 */
42 struct learning_mode_t : enum_base<learning_mode_t>
43 {
44 const static learning_mode_t ON;
45 const static learning_mode_t OFF;
46
47 private:
48 /**
49 * Private constructor taking the value and the string name
50 */
51 learning_mode_t(int v, const std::string& s);
52 };
53
54 /**
Neale Ranns812ed392017-10-16 04:20:13 -070055 * The value of the defaultbridge domain
56 */
57 const static uint32_t DEFAULT_TABLE = 0;
58
59 /**
60 * Construct a new object matching the desried state
61 */
Neale Ranns10e7a9f2017-11-14 08:40:43 -080062 bridge_domain(uint32_t id,
63 const learning_mode_t& lmode = learning_mode_t::ON);
64
Neale Ranns812ed392017-10-16 04:20:13 -070065 /**
66 * Copy Constructor
67 */
68 bridge_domain(const bridge_domain& o);
Neale Ranns10e7a9f2017-11-14 08:40:43 -080069
Neale Ranns812ed392017-10-16 04:20:13 -070070 /**
71 * Destructor
72 */
73 ~bridge_domain();
74
75 /**
Neale Rannsfd920602017-11-23 12:15:00 -080076 * Comparison operator - for UT
77 */
78 bool operator==(const bridge_domain& b) const;
79
80 /**
81 * Return the bridge domain's VPP ID
82 */
83 uint32_t id() const;
84
85 /**
86 * Return the bridge domain's key
87 */
88 const key_t& key() const;
89
90 /**
Neale Ranns812ed392017-10-16 04:20:13 -070091 * Return the matchin 'singular' instance of the bridge-domain
92 */
93 std::shared_ptr<bridge_domain> singular() const;
94
95 /**
96 * convert to string format for debug purposes
97 */
98 std::string to_string(void) const;
99
100 /**
Neale Ranns812ed392017-10-16 04:20:13 -0700101 * Static function to find the bridge_domain in the model
102 */
Neale Rannsfd920602017-11-23 12:15:00 -0800103 static std::shared_ptr<bridge_domain> find(const key_t& key);
Neale Ranns812ed392017-10-16 04:20:13 -0700104
105 /**
106 * Dump all bridge-doamin into the stream provided
107 */
108 static void dump(std::ostream& os);
109
Neale Ranns812ed392017-10-16 04:20:13 -0700110private:
111 /**
112 * Class definition for listeners to OM events
113 */
114 class event_handler : public OM::listener, public inspect::command_handler
115 {
116 public:
117 event_handler();
118 virtual ~event_handler() = default;
119
120 /**
121 * Handle a populate event
122 */
123 void handle_populate(const client_db::key_t& key);
124
125 /**
126 * Handle a replay event
127 */
128 void handle_replay();
129
130 /**
131 * Show the object in the Singular DB
132 */
133 void show(std::ostream& os);
134
135 /**
136 * Get the sortable Id of the listener
137 */
138 dependency_t order() const;
139 };
140
141 /**
142 * Instance of the event handler to register with OM
143 */
144 static event_handler m_evh;
145
146 /**
147 * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
148 */
149 void update(const bridge_domain& obj);
150
151 /**
152 * Find or add an singular of a Bridge-Domain in the object_base Model
153 */
154 static std::shared_ptr<bridge_domain> find_or_add(const bridge_domain& temp);
155
156 /*
157 * It's the OM class that calls singular()
158 */
159 friend class OM;
160
161 /**
162 * It's the singular_db class that calls replay()
163 */
Neale Rannsfd920602017-11-23 12:15:00 -0800164 friend class singular_db<key_t, bridge_domain>;
Neale Ranns812ed392017-10-16 04:20:13 -0700165
166 /**
167 * Sweep/reap the object if still stale
168 */
169 void sweep(void);
170
171 /**
172 * replay the object to create it in hardware
173 */
174 void replay(void);
175
176 /**
177 * The ID we assign to this BD and the HW result in VPP
178 */
179 HW::item<uint32_t> m_id;
180
181 /**
Neale Ranns10e7a9f2017-11-14 08:40:43 -0800182 * The leanring mode of the bridge
183 */
184 learning_mode_t m_learning_mode;
185
186 /**
Neale Ranns812ed392017-10-16 04:20:13 -0700187 * A map of all interfaces key against the interface's name
188 */
Neale Rannsfd920602017-11-23 12:15:00 -0800189 static singular_db<key_t, bridge_domain> m_db;
Neale Ranns812ed392017-10-16 04:20:13 -0700190};
191};
192
193/*
194 * fd.io coding-style-patch-verification: ON
195 *
196 * Local Variables:
197 * eval: (c-set-style "mozilla")
198 * End:
199 */
200
201#endif