blob: 2c134f0740b80236a5d93110ff4dce609f93fc1c [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 Ranns10e7a9f2017-11-14 08:40:43 -080035 * Bridge Domain Learning mode
36 */
37 struct learning_mode_t : enum_base<learning_mode_t>
38 {
39 const static learning_mode_t ON;
40 const static learning_mode_t OFF;
41
42 private:
43 /**
44 * Private constructor taking the value and the string name
45 */
46 learning_mode_t(int v, const std::string& s);
47 };
48
49 /**
Neale Ranns812ed392017-10-16 04:20:13 -070050 * The value of the defaultbridge domain
51 */
52 const static uint32_t DEFAULT_TABLE = 0;
53
54 /**
55 * Construct a new object matching the desried state
56 */
Neale Ranns10e7a9f2017-11-14 08:40:43 -080057 bridge_domain(uint32_t id,
58 const learning_mode_t& lmode = learning_mode_t::ON);
59
Neale Ranns812ed392017-10-16 04:20:13 -070060 /**
61 * Copy Constructor
62 */
63 bridge_domain(const bridge_domain& o);
Neale Ranns10e7a9f2017-11-14 08:40:43 -080064
Neale Ranns812ed392017-10-16 04:20:13 -070065 /**
66 * Destructor
67 */
68 ~bridge_domain();
69
70 /**
71 * Return the matchin 'singular' instance of the bridge-domain
72 */
73 std::shared_ptr<bridge_domain> singular() const;
74
75 /**
76 * convert to string format for debug purposes
77 */
78 std::string to_string(void) const;
79
80 /**
81 * Return VPP's handle for this obejct
82 */
83 uint32_t id() const;
84
85 /**
86 * Static function to find the bridge_domain in the model
87 */
88 static std::shared_ptr<bridge_domain> find(uint32_t id);
89
90 /**
91 * Dump all bridge-doamin into the stream provided
92 */
93 static void dump(std::ostream& os);
94
Neale Ranns812ed392017-10-16 04:20:13 -070095private:
96 /**
97 * Class definition for listeners to OM events
98 */
99 class event_handler : public OM::listener, public inspect::command_handler
100 {
101 public:
102 event_handler();
103 virtual ~event_handler() = default;
104
105 /**
106 * Handle a populate event
107 */
108 void handle_populate(const client_db::key_t& key);
109
110 /**
111 * Handle a replay event
112 */
113 void handle_replay();
114
115 /**
116 * Show the object in the Singular DB
117 */
118 void show(std::ostream& os);
119
120 /**
121 * Get the sortable Id of the listener
122 */
123 dependency_t order() const;
124 };
125
126 /**
127 * Instance of the event handler to register with OM
128 */
129 static event_handler m_evh;
130
131 /**
132 * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
133 */
134 void update(const bridge_domain& obj);
135
136 /**
137 * Find or add an singular of a Bridge-Domain in the object_base Model
138 */
139 static std::shared_ptr<bridge_domain> find_or_add(const bridge_domain& temp);
140
141 /*
142 * It's the OM class that calls singular()
143 */
144 friend class OM;
145
146 /**
147 * It's the singular_db class that calls replay()
148 */
149 friend class singular_db<uint32_t, bridge_domain>;
150
151 /**
152 * Sweep/reap the object if still stale
153 */
154 void sweep(void);
155
156 /**
157 * replay the object to create it in hardware
158 */
159 void replay(void);
160
161 /**
162 * The ID we assign to this BD and the HW result in VPP
163 */
164 HW::item<uint32_t> m_id;
165
166 /**
Neale Ranns10e7a9f2017-11-14 08:40:43 -0800167 * The leanring mode of the bridge
168 */
169 learning_mode_t m_learning_mode;
170
171 /**
Neale Ranns812ed392017-10-16 04:20:13 -0700172 * A map of all interfaces key against the interface's name
173 */
174 static singular_db<uint32_t, bridge_domain> m_db;
175};
176};
177
178/*
179 * fd.io coding-style-patch-verification: ON
180 *
181 * Local Variables:
182 * eval: (c-set-style "mozilla")
183 * End:
184 */
185
186#endif