Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 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 | |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 42 | bool |
| 43 | l2_rule::operator==(const l2_rule& rule) const |
| 44 | { |
| 45 | return ((m_action == rule.m_action) && (m_src_ip == rule.m_src_ip) && |
| 46 | (m_mac == rule.m_mac) && (m_mac_mask == rule.m_mac_mask)); |
| 47 | } |
| 48 | |
| 49 | std::string |
| 50 | l2_rule::to_string() const |
| 51 | { |
| 52 | std::ostringstream s; |
| 53 | |
| 54 | s << "L2-rule:[" |
| 55 | << "priority:" << m_priority << " action:" << m_action.to_string() |
| 56 | << " ip:" << m_src_ip.to_string() << " mac:" << m_mac |
| 57 | << " mac-mask:" << m_mac_mask << "]"; |
| 58 | |
| 59 | return (s.str()); |
| 60 | } |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 61 | |
| 62 | uint32_t |
| 63 | l2_rule::priority() const |
| 64 | { |
| 65 | return m_priority; |
| 66 | } |
| 67 | |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame^] | 68 | const action_t& |
Neale Ranns | 9ef1c0a | 2017-11-03 04:39:05 -0700 | [diff] [blame] | 69 | l2_rule::action() const |
| 70 | { |
| 71 | return m_action; |
| 72 | } |
| 73 | |
| 74 | const route::prefix_t& |
| 75 | l2_rule::src_ip() const |
| 76 | { |
| 77 | return m_src_ip; |
| 78 | } |
| 79 | |
| 80 | const mac_address_t& |
| 81 | l2_rule::mac() const |
| 82 | { |
| 83 | return m_mac; |
| 84 | } |
| 85 | |
| 86 | const mac_address_t& |
| 87 | l2_rule::mac_mask() const |
| 88 | { |
| 89 | return m_mac_mask; |
| 90 | } |
Neale Ranns | 812ed39 | 2017-10-16 04:20:13 -0700 | [diff] [blame] | 91 | } |
| 92 | } |
| 93 | /* |
| 94 | * fd.io coding-style-patch-verification: ON |
| 95 | * |
| 96 | * Local Variables: |
| 97 | * eval: (c-set-style "mozilla") |
| 98 | * End: |
| 99 | */ |