blob: 5d3b8914aca930a9952f7f80e62ff3a2a5a8df23 [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_ROUTE_DOMAIN_H__
17#define __VOM_ROUTE_DOMAIN_H__
18
19#include "vom/object_base.hpp"
20#include "vom/om.hpp"
21#include "vom/prefix.hpp"
22#include "vom/singular_db.hpp"
23
24#include <vapi/ip.api.vapi.hpp>
25
26namespace VOM {
27/**
28 * A route-domain is a VRF.
29 * creating a route-domain object will construct both an IPv4
30 * and IPv6 table.
31 */
32class route_domain : public object_base
33{
34public:
35 /**
36 * The Key for a route-domain
37 */
38 typedef route::table_id_t key_t;
39
40 /**
41 * Construct a new object matching the desried state
42 */
43 route_domain(route::table_id_t id);
44
45 /**
46 * Copy Constructor
47 */
48 route_domain(const route_domain& o);
49
50 /**
51 * Destructor
52 */
53 ~route_domain();
54
55 /**
56 * Return the matching 'singular instance'
57 */
58 std::shared_ptr<route_domain> singular() const;
59
60 /**
61 * Debug print function
62 */
63 std::string to_string() const;
64
65 /**
66 * Get the table ID
67 */
68 route::table_id_t table_id() const;
69
70 /**
71 * Get the route-domain's key
72 */
73 key_t key() const;
74
75 /**
76 * Find the instnace of the route domain in the OM
77 */
78 static std::shared_ptr<route_domain> find(const route_domain& temp);
79
80 /**
81 * Dump all route-doamin into the stream provided
82 */
83 static void dump(std::ostream& os);
84
85 /**
86 * Return the sigular instance for the default table
87 */
88 static std::shared_ptr<route_domain> get_default();
89
90 /**
91 * replay the object to create it in hardware
92 */
93 void replay(void);
94
95 /**
96 * A command class that creates the IP table
97 */
98 class create_cmd
99 : public rpc_cmd<HW::item<bool>, rc_t, vapi::Ip_table_add_del>
100 {
101 public:
102 /**
103 * Constructor
104 */
105 create_cmd(HW::item<bool>& item, l3_proto_t proto, route::table_id_t id);
106
107 /**
108 * Issue the command to VPP/HW
109 */
110 rc_t issue(connection& con);
111
112 /**
113 * convert to string format for debug purposes
114 */
115 std::string to_string() const;
116
117 /**
118 * Comparison operator - only used for UT
119 */
120 bool operator==(const create_cmd& i) const;
121
122 private:
123 /**
124 * table-ID to create
125 */
126 route::table_id_t m_id;
127
128 /**
129 * L3 protocol of the table
130 */
131 l3_proto_t m_proto;
132 };
133
134 /**
135 * A cmd class that Deletes the IP Table
136 */
137 class delete_cmd
138 : public rpc_cmd<HW::item<bool>, rc_t, vapi::Ip_table_add_del>
139 {
140 public:
141 /**
142 * Constructor
143 */
144 delete_cmd(HW::item<bool>& item, l3_proto_t proto, route::table_id_t id);
145
146 /**
147 * Issue the command to VPP/HW
148 */
149 rc_t issue(connection& con);
150
151 /**
152 * convert to string format for debug purposes
153 */
154 std::string to_string() const;
155
156 /**
157 * Comparison operator - only used for UT
158 */
159 bool operator==(const delete_cmd& i) const;
160
161 private:
162 /**
163 * table-ID to create
164 */
165 route::table_id_t m_id;
166
167 /**
168 * L3 protocol of the table
169 */
170 l3_proto_t m_proto;
171 };
172
173private:
174 /**
175 * Commit the acculmulated changes into VPP. i.e. to a 'HW" write.
176 */
177 void update(const route_domain& obj);
178
179 /**
180 * Find or add the instnace of the route domain in the OM
181 */
182 static std::shared_ptr<route_domain> find_or_add(const route_domain& temp);
183
184 /*
185 * It's the OM class that updates the objects in HW
186 */
187 friend class OM;
188
189 /**
190 * It's the singular_db class that calls replay()
191 */
192 friend class singular_db<route::table_id_t, route_domain>;
193
194 /**
195 * Sweep/reap the object if still stale
196 */
197 void sweep(void);
198
199 /**
200 * HW configuration for the result of creating the v4 table
201 */
202 HW::item<bool> m_hw_v4;
203
204 /**
205 * HW configuration for the result of creating the v6 table
206 */
207 HW::item<bool> m_hw_v6;
208
209 /**
210 * VPP understands Table-IDs not table names.
211 * The table IDs for V4 and V6 are the same.
212 */
213 route::table_id_t m_table_id;
214
215 /**
216 * A map of all interfaces key against the interface's name
217 */
218 static singular_db<route::table_id_t, route_domain> m_db;
219};
220};
221
222/*
223 * fd.io coding-style-patch-verification: ON
224 *
225 * Local Variables:
226 * eval: (c-set-style "mozilla")
227 * End:
228 */
229
230#endif