FD.io VPP  v18.07.1-19-g511ce25
Vector Packet Processing
gbp_contract.cpp
Go to the documentation of this file.
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 #include "vom/gbp_contract.hpp"
19 
20 namespace VOM {
21 
22 singular_db<gbp_contract::key_t, gbp_contract> gbp_contract::m_db;
23 
24 gbp_contract::event_handler gbp_contract::m_evh;
25 
27  epg_id_t dst_epg_id,
28  const ACL::l3_list& acl)
29  : m_hw(false)
30  , m_src_epg_id(src_epg_id)
31  , m_dst_epg_id(dst_epg_id)
32  , m_acl(acl.singular())
33 {
34 }
35 
37  : m_hw(gbpc.m_hw)
38  , m_src_epg_id(gbpc.m_src_epg_id)
39  , m_dst_epg_id(gbpc.m_dst_epg_id)
40  , m_acl(gbpc.m_acl)
41 {
42 }
43 
45 {
46  sweep();
47 
48  // not in the DB anymore.
49  m_db.release(key(), this);
50 }
51 
54 {
55  return (std::make_pair(m_src_epg_id, m_dst_epg_id));
56 }
57 
58 bool
60 {
61  return ((key() == gbpc.key()) && (m_acl->handle() == gbpc.m_acl->handle()));
62 }
63 
64 void
65 gbp_contract::sweep()
66 {
67  if (m_hw) {
69  new gbp_contract_cmds::delete_cmd(m_hw, m_src_epg_id, m_dst_epg_id));
70  }
71  HW::write();
72 }
73 
74 void
76 {
77  if (m_hw) {
79  m_hw, m_src_epg_id, m_dst_epg_id, m_acl->handle()));
80  }
81 }
82 
83 std::string
85 {
86  std::ostringstream s;
87  s << "gbp-contract:[{" << m_src_epg_id << ", " << m_dst_epg_id << "}, "
88  << m_acl->to_string() << "]";
89 
90  return (s.str());
91 }
92 
93 void
94 gbp_contract::update(const gbp_contract& r)
95 {
96  /*
97  * create the table if it is not yet created
98  */
99  if (rc_t::OK != m_hw.rc()) {
101  m_hw, m_src_epg_id, m_dst_epg_id, m_acl->handle()));
102  }
103 }
104 
105 std::shared_ptr<gbp_contract>
106 gbp_contract::find_or_add(const gbp_contract& temp)
107 {
108  return (m_db.find_or_add(temp.key(), temp));
109 }
110 
111 std::shared_ptr<gbp_contract>
113 {
114  return (m_db.find(k));
115 }
116 
117 std::shared_ptr<gbp_contract>
119 {
120  return find_or_add(*this);
121 }
122 
123 void
124 gbp_contract::dump(std::ostream& os)
125 {
126  db_dump(m_db, os);
127 }
128 
130 {
131  OM::register_listener(this);
132  inspect::register_handler({ "gbp-contract" }, "GBP Contract", this);
133 }
134 
135 void
136 gbp_contract::event_handler::handle_replay()
137 {
138  m_db.replay();
139 }
140 
141 void
142 gbp_contract::event_handler::handle_populate(const client_db::key_t& key)
143 {
144  std::shared_ptr<gbp_contract_cmds::dump_cmd> cmd =
145  std::make_shared<gbp_contract_cmds::dump_cmd>();
146 
147  HW::enqueue(cmd);
148  HW::write();
149 
150  for (auto& record : *cmd) {
151  auto& payload = record.get_payload();
152 
153  std::shared_ptr<ACL::l3_list> acl =
154  ACL::l3_list::find(payload.contract.acl_index);
155 
156  if (acl) {
157  gbp_contract gbpc(payload.contract.src_epg, payload.contract.dst_epg,
158  *acl);
159  OM::commit(key, gbpc);
160 
161  VOM_LOG(log_level_t::DEBUG) << "read: " << gbpc.to_string();
162  }
163  }
164 }
165 
167 gbp_contract::event_handler::order() const
168 {
169  return (dependency_t::ENTRY);
170 }
171 
172 void
173 gbp_contract::event_handler::show(std::ostream& os)
174 {
175  db_dump(m_db, os);
176 }
177 
178 std::ostream&
179 operator<<(std::ostream& os, const gbp_contract::key_t& key)
180 {
181  os << "{ " << key.first << "," << key.second << "}";
182 
183  return (os);
184 }
185 
186 } // namespace VOM
187 
188 /*
189  * fd.io coding-style-patch-verification: ON
190  *
191  * Local Variables:
192  * eval: (c-set-style "mozilla")
193  * End:
194  */
const key_t key() const
Return the object&#39;s key.
#define VOM_LOG(lvl)
Definition: logger.hpp:181
void db_dump(const DB &db, std::ostream &os)
Print each of the objects in the DB into the stream provided.
const std::string key_t
In the opflex world each entity is known by a URI which can be converted into a string.
Definition: client_db.hpp:51
An ACL list comprises a set of match actions rules to be applied to packets.
Definition: acl_list.hpp:37
uint32_t epg_id_t
EPG IDs are 32 bit integers.
static void dump(std::ostream &os)
Dump all bridge_domain-doamin into the stream provided.
static void register_handler(const std::vector< std::string > &cmds, const std::string &help, command_handler *ch)
Register a command handler for inspection.
Definition: inspect.cpp:85
static rc_t write()
Write/Execute all commands hitherto enqueued.
Definition: hw.cpp:236
static const log_level_t DEBUG
Definition: logger.hpp:32
static std::shared_ptr< list > find(const handle_t &handle)
Definition: acl_list.hpp:135
gbp_contract(epg_id_t src_epg_id, epg_id_t dst_epg_id, const ACL::l3_list &acl)
Construct a GBP contract.
std::shared_ptr< gbp_contract > singular() const
Return the matching &#39;singular instance&#39;.
rc_t rc() const
Get the HW return code.
Definition: hw.hpp:118
bool operator==(const gbp_contract &bdae) const
comparison operator
void replay(void)
replay the object to create it in hardware
A entry in the ARP termination table of a Bridge Domain.
~gbp_contract()
Destructor.
std::pair< epg_id_t, epg_id_t > key_t
The key for a contract is the pari of EPG-IDs.
std::string to_string() const
Convert to string for debugging.
A command class that creates or updates the GBP contract.
static rc_t commit(const client_db::key_t &key, const OBJ &obj)
Make the State in VPP reflect the expressed desired state.
Definition: om.hpp:202
void event_handler(void *tls_async)
Definition: tls_async.c:311
dependency_t
There needs to be a strict order in which object types are read from VPP (at boot time) and replayed ...
Definition: types.hpp:43
static const rc_t OK
The HW write was successfull.
Definition: types.hpp:104
static void enqueue(cmd *f)
Enqueue A command for execution.
Definition: hw.cpp:194
std::ostream & operator<<(std::ostream &os, const std::pair< direction_t, interface::key_t > &key)
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
A representation of a method call to VPP.
Definition: cmd.hpp:32
void show(char *chroot_path, int verbose)
Definition: svmtool.c:105
static std::shared_ptr< gbp_contract > find(const key_t &k)
Find the instnace of the bridge_domain domain in the OM.
A cmd class that deletes a GBP contract.
Entries in Tables.
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:127