blob: 417dc5f2eb7446ad102c83ca01943e867e877cd2 [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 <sstream>
17
18#include "vom/acl_l3_rule.hpp"
19
20namespace VOM {
21namespace ACL {
22l3_rule::l3_rule(uint32_t priority,
23 const action_t& action,
24 const route::prefix_t& src,
Mohsin Kazmi091871c2017-12-13 17:59:33 +010025 const route::prefix_t& dst,
26 uint8_t proto,
27 uint16_t srcport_or_icmptype_first,
28 uint16_t srcport_or_icmptype_last,
29 uint16_t dstport_or_icmpcode_first,
30 uint16_t dstport_or_icmpcode_last,
31 uint8_t tcp_flags_mask,
32 uint8_t tcp_flags_value)
Neale Ranns812ed392017-10-16 04:20:13 -070033 : m_priority(priority)
34 , m_action(action)
35 , m_src(src)
36 , m_dst(dst)
Mohsin Kazmi091871c2017-12-13 17:59:33 +010037 , m_proto(proto)
38 , m_srcport_or_icmptype_first(srcport_or_icmptype_first)
39 , m_srcport_or_icmptype_last(srcport_or_icmptype_last)
40 , m_dstport_or_icmpcode_first(dstport_or_icmpcode_first)
41 , m_dstport_or_icmpcode_last(dstport_or_icmpcode_last)
42 , m_tcp_flags_mask(tcp_flags_mask)
43 , m_tcp_flags_value(tcp_flags_value)
Neale Ranns812ed392017-10-16 04:20:13 -070044{
45}
46
47bool
48l3_rule::operator<(const l3_rule& other) const
49{
50 return (other.m_priority < m_priority);
51}
52
Neale Ranns812ed392017-10-16 04:20:13 -070053bool
54l3_rule::operator==(const l3_rule& rule) const
55{
56 return ((m_action == rule.m_action) && (m_src == rule.m_src) &&
57 (m_dst == rule.m_dst) && (m_proto == rule.m_proto) &&
58 (m_srcport_or_icmptype_first == rule.m_srcport_or_icmptype_first) &&
59 (m_srcport_or_icmptype_last == rule.m_srcport_or_icmptype_last) &&
60 (m_dstport_or_icmpcode_first == rule.m_dstport_or_icmpcode_first) &&
61 (m_dstport_or_icmpcode_last == rule.m_dstport_or_icmpcode_last) &&
62 (m_tcp_flags_mask == rule.m_tcp_flags_mask) &&
63 (m_tcp_flags_value == rule.m_tcp_flags_value));
64}
65
66std::string
67l3_rule::to_string() const
68{
69 std::ostringstream s;
70
71 s << "L3-rule:["
72 << "priority:" << m_priority << " action:" << m_action.to_string()
73 << " src:" << m_src.to_string() << " dst:" << m_dst.to_string()
74 << " proto:" << std::to_string(m_proto)
75 << " srcportfrom:" << m_srcport_or_icmptype_first
76 << " srcportto: " << m_srcport_or_icmptype_last
77 << " dstportfrom:" << m_dstport_or_icmpcode_first
78 << " dstportto:" << m_dstport_or_icmpcode_last
Mohsin Kazmi07085152017-12-05 14:48:58 +010079 << " tcpflagmask:" << std::to_string(m_tcp_flags_mask)
80 << " tcpflagvalue:" << std::to_string(m_tcp_flags_value) << "]";
Neale Ranns812ed392017-10-16 04:20:13 -070081
82 return (s.str());
83}
84
85void
86l3_rule::set_src_ip(route::prefix_t src)
87{
88 m_src = src;
89}
90
91void
92l3_rule::set_dst_ip(route::prefix_t dst)
93{
94 m_dst = dst;
95}
96
97void
98l3_rule::set_proto(uint8_t proto)
99{
100 m_proto = proto;
101}
102void
103l3_rule::set_src_from_port(uint16_t srcport_or_icmptype_first)
104{
105 m_srcport_or_icmptype_first = srcport_or_icmptype_first;
106}
107
108void
109l3_rule::set_src_to_port(uint16_t srcport_or_icmptype_last)
110{
111 m_srcport_or_icmptype_last = srcport_or_icmptype_last;
112}
113
114void
115l3_rule::set_dst_from_port(uint16_t dstport_or_icmpcode_first)
116{
117 m_dstport_or_icmpcode_first = dstport_or_icmpcode_first;
118}
119
120void
121l3_rule::set_dst_to_port(uint16_t dstport_or_icmpcode_last)
122{
123 m_dstport_or_icmpcode_last = dstport_or_icmpcode_last;
124}
125
126void
127l3_rule::set_tcp_flags_mask(uint8_t tcp_flags_mask)
128{
129 m_tcp_flags_mask = tcp_flags_mask;
130}
131
132void
133l3_rule::set_tcp_flags_value(uint8_t tcp_flags_value)
134{
135 m_tcp_flags_value = tcp_flags_value;
136}
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700137
138const route::prefix_t&
139l3_rule::src() const
140{
141 return m_src;
Neale Ranns812ed392017-10-16 04:20:13 -0700142}
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700143
144uint32_t
145l3_rule::priority() const
146{
147 return m_priority;
Neale Ranns812ed392017-10-16 04:20:13 -0700148}
149
Neale Ranns25b04942018-04-04 09:34:50 -0700150const action_t&
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700151l3_rule::action() const
152{
153 return m_action;
154}
155
156const route::prefix_t&
157l3_rule::dst() const
158{
159 return m_dst;
160}
161
162uint8_t
163l3_rule::proto() const
164{
165 return m_proto;
166}
167
168uint16_t
169l3_rule::srcport_or_icmptype_first() const
170{
171 return m_srcport_or_icmptype_first;
172}
173
174uint16_t
175l3_rule::srcport_or_icmptype_last() const
176{
177 return m_srcport_or_icmptype_last;
178}
179
180uint16_t
181l3_rule::dstport_or_icmpcode_first() const
182{
183 return m_dstport_or_icmpcode_first;
184}
185
186uint16_t
187l3_rule::dstport_or_icmpcode_last() const
188{
189 return m_dstport_or_icmpcode_last;
190}
191
192uint8_t
193l3_rule::tcp_flags_mask() const
194{
195 return m_tcp_flags_mask;
196}
197
198uint8_t
199l3_rule::tcp_flags_value() const
200{
201 return m_tcp_flags_value;
202}
203
204}; // namespace ACL
205}; // namespace VOM
206
Neale Ranns812ed392017-10-16 04:20:13 -0700207/*
208 * fd.io coding-style-patch-verification: ON
209 *
210 * Local Variables:
211 * eval: (c-set-style "mozilla")
212 * End:
213 */