1f7f9fdabc83dbcb9f2894edd4c0fa3e923432e4
[vpp.git] / src / vpp-api / vom / acl_l2_rule.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 <sstream>
17
18 #include "vom/acl_l2_rule.hpp"
19
20 namespace VOM {
21 namespace ACL {
22
23 l2_rule::l2_rule(uint32_t priority,
24                  const action_t& action,
25                  const route::prefix_t& ip,
26                  const mac_address_t& mac,
27                  const mac_address_t& mac_mask)
28   : m_priority(priority)
29   , m_action(action)
30   , m_src_ip(ip)
31   , m_mac(mac)
32   , m_mac_mask(mac_mask)
33 {
34 }
35
36 bool
37 l2_rule::operator<(const l2_rule& other) const
38 {
39   return (other.m_priority < m_priority);
40 }
41
42 void
43 l2_rule::to_vpp(vapi_type_macip_acl_rule& rule) const
44 {
45   rule.is_permit = m_action.value();
46   m_src_ip.to_vpp(&rule.is_ipv6, rule.src_ip_addr, &rule.src_ip_prefix_len);
47   m_mac.to_bytes(rule.src_mac, 6);
48   m_mac_mask.to_bytes(rule.src_mac_mask, 6);
49 }
50
51 bool
52 l2_rule::operator==(const l2_rule& rule) const
53 {
54   return ((m_action == rule.m_action) && (m_src_ip == rule.m_src_ip) &&
55           (m_mac == rule.m_mac) && (m_mac_mask == rule.m_mac_mask));
56 }
57
58 std::string
59 l2_rule::to_string() const
60 {
61   std::ostringstream s;
62
63   s << "L2-rule:["
64     << "priority:" << m_priority << " action:" << m_action.to_string()
65     << " ip:" << m_src_ip.to_string() << " mac:" << m_mac
66     << " mac-mask:" << m_mac_mask << "]";
67
68   return (s.str());
69 }
70 }
71 }
72 /*
73  * fd.io coding-style-patch-verification: ON
74  *
75  * Local Variables:
76  * eval: (c-set-style "mozilla")
77  * End:
78  */