blob: 129be8faefe4627ef4fa4ea652e6f1e14abab0dc [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#include "vom/acl_list.hpp"
17#include "vom/logger.hpp"
18
19namespace VOM {
20namespace ACL {
21template <>
22void
23l2_list::event_handler::handle_populate(const client_db::key_t& key)
24{
25 /* hack to get this function instantiated */
26 m_evh.order();
27
28 /*
29* dump VPP Bridge domains
30*/
31 std::shared_ptr<l2_list::dump_cmd> cmd(new l2_list::dump_cmd());
32
33 HW::enqueue(cmd);
34 HW::write();
35
36 for (auto& record : *cmd) {
37 auto& payload = record.get_payload();
38
39 const handle_t hdl(payload.acl_index);
40 l2_list acl(hdl, std::string(reinterpret_cast<const char*>(payload.tag)));
41
42 for (unsigned int ii = 0; ii < payload.count; ii++) {
43 const route::prefix_t pfx(payload.r[ii].is_ipv6,
44 payload.r[ii].src_ip_addr,
45 payload.r[ii].src_ip_prefix_len);
46 l2_rule rule(ii, action_t::from_int(payload.r[ii].is_permit), pfx,
47 { payload.r[ii].src_mac }, { payload.r[ii].src_mac_mask });
48
49 acl.insert(rule);
50 }
51 VOM_LOG(log_level_t::DEBUG) << "dump: " << acl.to_string();
52
53 /*
54* Write each of the discovered ACLs into the OM,
55* but disable the HW Command q whilst we do, so that no
56* commands are sent to VPP
57*/
58 OM::commit(key, acl);
59 }
60}
61
62template <>
63void
64l3_list::event_handler::handle_populate(const client_db::key_t& key)
65{
66 /* hack to get this function instantiated */
67 m_evh.order();
68
69 /*
70* dump VPP Bridge domains
71*/
72 std::shared_ptr<l3_list::dump_cmd> cmd(new l3_list::dump_cmd());
73
74 HW::enqueue(cmd);
75 HW::write();
76
77 for (auto& record : *cmd) {
78 auto& payload = record.get_payload();
79
80 const handle_t hdl(payload.acl_index);
81 l3_list acl(hdl, std::string(reinterpret_cast<const char*>(payload.tag)));
82
83 for (unsigned int ii = 0; ii < payload.count; ii++) {
84 const route::prefix_t src(payload.r[ii].is_ipv6,
85 payload.r[ii].src_ip_addr,
86 payload.r[ii].src_ip_prefix_len);
87 const route::prefix_t dst(payload.r[ii].is_ipv6,
88 payload.r[ii].dst_ip_addr,
89 payload.r[ii].dst_ip_prefix_len);
90 l3_rule rule(ii, action_t::from_int(payload.r[ii].is_permit), src, dst);
91
92 acl.insert(rule);
93 }
94 VOM_LOG(log_level_t::DEBUG) << "dump: " << acl.to_string();
95
96 /*
97* Write each of the discovered ACLs into the OM,
98* but disable the HW Command q whilst we do, so that no
99* commands are sent to VPP
100*/
101 OM::commit(key, acl);
102 }
103}
104};
105};
106
107/*
108 * fd.io coding-style-patch-verification: ON
109 *
110 * Local Variables:
111 * eval: (c-set-style "mozilla")
112 * End:
113 */