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 | #ifndef __VOM_L2_ACL_RULE_H__ |
| 17 | #define __VOM_L2_ACL_RULE_H__ |
| 18 | |
| 19 | #include "vom/acl_types.hpp" |
| 20 | #include "vom/prefix.hpp" |
| 21 | |
| 22 | #include <vapi/acl.api.vapi.hpp> |
| 23 | |
| 24 | namespace VOM { |
| 25 | namespace ACL { |
| 26 | /** |
| 27 | * An ACL rule is the building block of an ACL. An ACL, which is |
| 28 | * the object applied to an interface, is comprised of an ordersed |
| 29 | * sequence of ACL rules. |
| 30 | * This class is a wrapper around the VAPI generated struct and exports |
| 31 | * an API with better types. |
| 32 | */ |
| 33 | class l2_rule |
| 34 | { |
| 35 | public: |
| 36 | /** |
| 37 | * Construct a new object matching the desried state |
| 38 | */ |
| 39 | l2_rule(uint32_t priority, |
| 40 | const action_t& action, |
| 41 | const route::prefix_t& ip, |
| 42 | const mac_address_t& mac, |
| 43 | const mac_address_t& mac_mask); |
| 44 | |
| 45 | /** |
| 46 | * Copy Constructor |
| 47 | */ |
| 48 | l2_rule(const l2_rule& o) = default; |
| 49 | |
| 50 | /** |
| 51 | * Destructor |
| 52 | */ |
| 53 | ~l2_rule() = default; |
| 54 | |
| 55 | /** |
| 56 | * convert to string format for debug purposes |
| 57 | */ |
| 58 | std::string to_string() const; |
| 59 | |
| 60 | /** |
| 61 | * less-than operator |
| 62 | */ |
| 63 | bool operator<(const l2_rule& rule) const; |
| 64 | |
| 65 | /** |
| 66 | * comparison operator (for testing) |
| 67 | */ |
| 68 | bool operator==(const l2_rule& rule) const; |
| 69 | |
| 70 | /** |
| 71 | * Convert to VPP API fromat |
| 72 | */ |
| 73 | void to_vpp(vapi_type_macip_acl_rule& rule) const; |
| 74 | |
| 75 | private: |
| 76 | /** |
| 77 | * Priority. Used to sort the rules in a list in the order |
| 78 | * in which they are applied |
| 79 | */ |
| 80 | uint32_t m_priority; |
| 81 | |
| 82 | /** |
| 83 | * Action on match |
| 84 | */ |
| 85 | action_t m_action; |
| 86 | |
| 87 | /** |
| 88 | * Source Prefix |
| 89 | */ |
| 90 | route::prefix_t m_src_ip; |
| 91 | |
| 92 | /** |
| 93 | * Source Mac |
| 94 | */ |
| 95 | mac_address_t m_mac; |
| 96 | |
| 97 | /** |
| 98 | * Source MAC mask |
| 99 | */ |
| 100 | mac_address_t m_mac_mask; |
| 101 | }; |
| 102 | }; |
| 103 | }; |
| 104 | |
| 105 | /* |
| 106 | * fd.io coding-style-patch-verification: ON |
| 107 | * |
| 108 | * Local Variables: |
| 109 | * eval: (c-set-style "mozilla") |
| 110 | * End: |
| 111 | */ |
| 112 | |
| 113 | #endif |