VPP Object Model (VOM)
[vpp.git] / src / vpp-api / vom / acl_binding.cpp
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/acl_binding.hpp"
17 #include "vom/om.hpp"
18
19 namespace VOM {
20 namespace ACL {
21 template <>
22 void
23 l2_binding::event_handler::handle_populate(const client_db::key_t& key)
24 {
25   /*
26 * dump VPP Bridge domains
27 */
28   std::shared_ptr<l2_binding::dump_cmd> cmd(new l2_binding::dump_cmd());
29
30   HW::enqueue(cmd);
31   HW::write();
32
33   for (auto& record : *cmd) {
34     auto& payload = record.get_payload();
35
36     std::shared_ptr<interface> itf = interface::find(payload.sw_if_index);
37
38     for (int ii = 0; ii < payload.count; ii++) {
39       std::shared_ptr<l2_list> acl = l2_list::find(payload.acls[ii]);
40
41       l2_binding binding(direction_t::INPUT, *itf, *acl);
42
43       OM::commit(key, binding);
44     }
45   }
46 }
47
48 template <>
49 void
50 l3_binding::event_handler::handle_populate(const client_db::key_t& key)
51 {
52   std::shared_ptr<l3_binding::dump_cmd> cmd(new l3_binding::dump_cmd());
53
54   HW::enqueue(cmd);
55   HW::write();
56
57   for (auto& record : *cmd) {
58     auto& payload = record.get_payload();
59
60     std::shared_ptr<interface> itf = interface::find(payload.sw_if_index);
61     uint8_t n_input = payload.n_input;
62
63     for (int ii = 0; ii < payload.count; ii++) {
64       std::shared_ptr<l3_list> acl = l3_list::find(payload.acls[ii]);
65
66       if (n_input) {
67         l3_binding binding(direction_t::INPUT, *itf, *acl);
68         n_input--;
69         OM::commit(key, binding);
70       } else {
71         l3_binding binding(direction_t::OUTPUT, *itf, *acl);
72         OM::commit(key, binding);
73       }
74     }
75   }
76 }
77 };
78
79 std::ostream&
80 operator<<(std::ostream& os,
81            const std::pair<direction_t, interface::key_type>& key)
82 {
83   os << "[" << key.first.to_string() << " " << key.second << "]";
84
85   return (os);
86 }
87 };
88
89 /*
90  * fd.io coding-style-patch-verification: ON
91  *
92  * Local Variables:
93  * eval: (c-set-style "mozilla")
94  * End:
95  */