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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include "vom/acl_list.hpp"
17 #include "vom/acl_list_cmds.hpp"
18 #include "vom/logger.hpp"
24 l2_list::event_handler::handle_populate(const client_db::key_t& key)
26 /* hack to get this function instantiated */
30 * dump VPP Bridge domains
32 std::shared_ptr<list_cmds::l2_dump_cmd> cmd(new list_cmds::l2_dump_cmd());
37 for (auto& record : *cmd) {
38 auto& payload = record.get_payload();
40 const handle_t hdl(payload.acl_index);
41 l2_list acl(hdl, std::string(reinterpret_cast<const char*>(payload.tag)));
43 for (unsigned int ii = 0; ii < payload.count; ii++) {
44 const route::prefix_t pfx(payload.r[ii].is_ipv6,
45 payload.r[ii].src_ip_addr,
46 payload.r[ii].src_ip_prefix_len);
47 l2_rule rule(ii, action_t::from_int(payload.r[ii].is_permit), pfx,
48 { payload.r[ii].src_mac }, { payload.r[ii].src_mac_mask });
52 VOM_LOG(log_level_t::DEBUG) << "dump: " << acl.to_string();
55 * Write each of the discovered ACLs into the OM,
56 * but disable the HW Command q whilst we do, so that no
57 * commands are sent to VPP
65 l3_list::event_handler::handle_populate(const client_db::key_t& key)
67 /* hack to get this function instantiated */
71 * dump VPP Bridge domains
73 std::shared_ptr<list_cmds::l3_dump_cmd> cmd(new list_cmds::l3_dump_cmd());
78 for (auto& record : *cmd) {
79 auto& payload = record.get_payload();
81 const handle_t hdl(payload.acl_index);
82 l3_list acl(hdl, std::string(reinterpret_cast<const char*>(payload.tag)));
84 for (unsigned int ii = 0; ii < payload.count; ii++) {
85 const route::prefix_t src(payload.r[ii].is_ipv6,
86 payload.r[ii].src_ip_addr,
87 payload.r[ii].src_ip_prefix_len);
88 const route::prefix_t dst(payload.r[ii].is_ipv6,
89 payload.r[ii].dst_ip_addr,
90 payload.r[ii].dst_ip_prefix_len);
91 l3_rule rule(ii, action_t::from_int(payload.r[ii].is_permit), src, dst);
95 VOM_LOG(log_level_t::DEBUG) << "dump: " << acl.to_string();
98 * Write each of the discovered ACLs into the OM,
99 * but disable the HW Command q whilst we do, so that no
100 * commands are sent to VPP
102 OM::commit(key, acl);
108 l3_list::update(const l3_list& obj)
111 * always update the instance with the latest rule set
113 if (!m_hdl || obj.m_rules != m_rules) {
114 HW::enqueue(new list_cmds::l3_update_cmd(m_hdl, m_key, m_rules));
117 * We don't, can't, read the priority from VPP,
118 * so the is equals check above does not include the priorty.
119 * but we save it now.
121 m_rules = obj.m_rules;
125 l2_list::update(const l2_list& obj)
128 * always update the instance with the latest rule set
130 if (!m_hdl || obj.m_rules != m_rules) {
131 HW::enqueue(new list_cmds::l2_update_cmd(m_hdl, m_key, m_rules));
134 * We don't, can't, read the priority from VPP,
135 * so the is equals check above does not include the priorty.
136 * but we save it now.
138 m_rules = obj.m_rules;
141 * Sweep/reap the object if still stale
148 HW::enqueue(new list_cmds::l3_delete_cmd(m_hdl));
157 HW::enqueue(new list_cmds::l2_delete_cmd(m_hdl));
163 * Replay the objects state to HW
167 l3_list::replay(void)
170 HW::enqueue(new list_cmds::l3_update_cmd(m_hdl, m_key, m_rules));
175 l2_list::replay(void)
178 HW::enqueue(new list_cmds::l2_update_cmd(m_hdl, m_key, m_rules));
186 * fd.io coding-style-patch-verification: ON
189 * eval: (c-set-style "mozilla")