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