6a9383aba0b780d629c9a6ae1022624a6412996e
[vpp.git] / src / vpp-api / vom / acl_l3_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_l3_rule.hpp"
19
20 namespace VOM {
21 namespace ACL {
22 l3_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
40 bool
41 l3_rule::operator<(const l3_rule& other) const
42 {
43   return (other.m_priority < m_priority);
44 }
45
46 bool
47 l3_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
59 std::string
60 l3_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:" << std::to_string(m_tcp_flags_mask)
73     << " tcpflagvalue:" << std::to_string(m_tcp_flags_value) << "]";
74
75   return (s.str());
76 }
77
78 void
79 l3_rule::set_src_ip(route::prefix_t src)
80 {
81   m_src = src;
82 }
83
84 void
85 l3_rule::set_dst_ip(route::prefix_t dst)
86 {
87   m_dst = dst;
88 }
89
90 void
91 l3_rule::set_proto(uint8_t proto)
92 {
93   m_proto = proto;
94 }
95 void
96 l3_rule::set_src_from_port(uint16_t srcport_or_icmptype_first)
97 {
98   m_srcport_or_icmptype_first = srcport_or_icmptype_first;
99 }
100
101 void
102 l3_rule::set_src_to_port(uint16_t srcport_or_icmptype_last)
103 {
104   m_srcport_or_icmptype_last = srcport_or_icmptype_last;
105 }
106
107 void
108 l3_rule::set_dst_from_port(uint16_t dstport_or_icmpcode_first)
109 {
110   m_dstport_or_icmpcode_first = dstport_or_icmpcode_first;
111 }
112
113 void
114 l3_rule::set_dst_to_port(uint16_t dstport_or_icmpcode_last)
115 {
116   m_dstport_or_icmpcode_last = dstport_or_icmpcode_last;
117 }
118
119 void
120 l3_rule::set_tcp_flags_mask(uint8_t tcp_flags_mask)
121 {
122   m_tcp_flags_mask = tcp_flags_mask;
123 }
124
125 void
126 l3_rule::set_tcp_flags_value(uint8_t tcp_flags_value)
127 {
128   m_tcp_flags_value = tcp_flags_value;
129 }
130
131 const route::prefix_t&
132 l3_rule::src() const
133 {
134   return m_src;
135 }
136
137 uint32_t
138 l3_rule::priority() const
139 {
140   return m_priority;
141 }
142
143 action_t
144 l3_rule::action() const
145 {
146   return m_action;
147 }
148
149 const route::prefix_t&
150 l3_rule::dst() const
151 {
152   return m_dst;
153 }
154
155 uint8_t
156 l3_rule::proto() const
157 {
158   return m_proto;
159 }
160
161 uint16_t
162 l3_rule::srcport_or_icmptype_first() const
163 {
164   return m_srcport_or_icmptype_first;
165 }
166
167 uint16_t
168 l3_rule::srcport_or_icmptype_last() const
169 {
170   return m_srcport_or_icmptype_last;
171 }
172
173 uint16_t
174 l3_rule::dstport_or_icmpcode_first() const
175 {
176   return m_dstport_or_icmpcode_first;
177 }
178
179 uint16_t
180 l3_rule::dstport_or_icmpcode_last() const
181 {
182   return m_dstport_or_icmpcode_last;
183 }
184
185 uint8_t
186 l3_rule::tcp_flags_mask() const
187 {
188   return m_tcp_flags_mask;
189 }
190
191 uint8_t
192 l3_rule::tcp_flags_value() const
193 {
194   return m_tcp_flags_value;
195 }
196
197 }; // namespace ACL
198 }; // namespace VOM
199
200 /*
201  * fd.io coding-style-patch-verification: ON
202  *
203  * Local Variables:
204  * eval: (c-set-style "mozilla")
205  * End:
206  */