blob: 0c92c02ad223abb4ceb032b5748bc41a6b37927b [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"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070017#include "vom/acl_list_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070018#include "vom/logger.hpp"
19
20namespace VOM {
21namespace ACL {
22template <>
23void
24l2_list::event_handler::handle_populate(const client_db::key_t& key)
25{
26 /* hack to get this function instantiated */
27 m_evh.order();
28
29 /*
30* dump VPP Bridge domains
31*/
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070032 std::shared_ptr<list_cmds::l2_dump_cmd> cmd(new list_cmds::l2_dump_cmd());
Neale Ranns812ed392017-10-16 04:20:13 -070033
34 HW::enqueue(cmd);
35 HW::write();
36
37 for (auto& record : *cmd) {
38 auto& payload = record.get_payload();
39
40 const handle_t hdl(payload.acl_index);
41 l2_list acl(hdl, std::string(reinterpret_cast<const char*>(payload.tag)));
42
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 });
49
50 acl.insert(rule);
51 }
52 VOM_LOG(log_level_t::DEBUG) << "dump: " << acl.to_string();
53
54 /*
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
58*/
59 OM::commit(key, acl);
60 }
61}
62
63template <>
64void
65l3_list::event_handler::handle_populate(const client_db::key_t& key)
66{
67 /* hack to get this function instantiated */
68 m_evh.order();
69
70 /*
71* dump VPP Bridge domains
72*/
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070073 std::shared_ptr<list_cmds::l3_dump_cmd> cmd(new list_cmds::l3_dump_cmd());
Neale Ranns812ed392017-10-16 04:20:13 -070074
75 HW::enqueue(cmd);
76 HW::write();
77
78 for (auto& record : *cmd) {
79 auto& payload = record.get_payload();
80
81 const handle_t hdl(payload.acl_index);
82 l3_list acl(hdl, std::string(reinterpret_cast<const char*>(payload.tag)));
83
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);
92
93 acl.insert(rule);
94 }
95 VOM_LOG(log_level_t::DEBUG) << "dump: " << acl.to_string();
96
97 /*
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
101*/
102 OM::commit(key, acl);
103 }
104}
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700105
106template <>
107void
108l3_list::update(const l3_list& obj)
109{
110 /*
111 * always update the instance with the latest rule set
112 */
113 if (!m_hdl || obj.m_rules != m_rules) {
114 HW::enqueue(new list_cmds::l3_update_cmd(m_hdl, m_key, m_rules));
115 }
116 /*
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.
120 */
121 m_rules = obj.m_rules;
122}
123template <>
124void
125l2_list::update(const l2_list& obj)
126{
127 /*
128 * always update the instance with the latest rule set
129 */
130 if (!m_hdl || obj.m_rules != m_rules) {
131 HW::enqueue(new list_cmds::l2_update_cmd(m_hdl, m_key, m_rules));
132 }
133 /*
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.
137 */
138 m_rules = obj.m_rules;
139}
140/**
141 * Sweep/reap the object if still stale
142 */
143template <>
144void
145l3_list::sweep(void)
146{
147 if (m_hdl) {
148 HW::enqueue(new list_cmds::l3_delete_cmd(m_hdl));
149 }
150 HW::write();
151}
152template <>
153void
154l2_list::sweep(void)
155{
156 if (m_hdl) {
157 HW::enqueue(new list_cmds::l2_delete_cmd(m_hdl));
158 }
159 HW::write();
160}
161
162/**
163 * Replay the objects state to HW
164 */
165template <>
166void
167l3_list::replay(void)
168{
169 if (m_hdl) {
170 HW::enqueue(new list_cmds::l3_update_cmd(m_hdl, m_key, m_rules));
171 }
172}
173template <>
174void
175l2_list::replay(void)
176{
177 if (m_hdl) {
178 HW::enqueue(new list_cmds::l2_update_cmd(m_hdl, m_key, m_rules));
179 }
180}
181
182}; // namespace ACL
183}; // namespace VOM
Neale Ranns812ed392017-10-16 04:20:13 -0700184
185/*
186 * fd.io coding-style-patch-verification: ON
187 *
188 * Local Variables:
189 * eval: (c-set-style "mozilla")
190 * End:
191 */