1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
# Copyright (c) 2016 Cisco and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Test variables for ietf-ACL test suite."""
def get_variables(test_case, name):
"""Create and return a dictionary of test variables for the specified
test case.
:param test_case: Determines which test variables to return.
:param name: Name for the classify chain used in test.
:type test_case: str
:type name: str
:return: Dictionary of test variables - settings for Honeycomb's
ietf-acl node and packet fields to use in verification.
:rtype: dict
"""
test_case = test_case.lower()
variables = {
# Variables for control packet, should always pass through DUT
"src_ip": "16.0.0.1",
"dst_ip": "16.0.1.1",
"dst_net": "16.0.1.0",
"src_port": "1234",
"dst_port": "1234",
"src_mac": "01:02:03:04:05:06",
"dst_mac": "10:20:30:40:50:60"}
test_vars = {
"l2": {
# MACs classified directly
"classify_src": "12:23:34:45:56:67",
"classify_dst": "89:9A:AB:BC:CD:DE",
# MACs classified through mask
"classify_src2": "01:02:03:04:56:67",
"classify_dst2": "89:9A:AB:BC:50:60",
"src_mask": "00:00:00:00:FF:FF",
"dst_mask": "FF:FF:FF:FF:00:00"
},
"l3_ip4": {
# IPs for DUT interface setup
"dut_to_tg_if1_ip": "16.0.0.2",
"dut_to_tg_if2_ip": "192.168.0.2",
"gateway": "192.168.0.1",
# classified networks
"classify_src_net": "16.0.2.0",
"classify_dst_net": "16.0.3.0",
# IPs in classified networks
"classify_src": "16.0.2.1",
"classify_dst": "16.0.3.1",
"prefix_length": 24
},
"l3_ip6": {
# Override control packet addresses with IPv6
"src_ip": "10::1",
"dst_ip": "11::1",
"dst_net": "11::",
# IPs for DUT interface setup
"dut_to_tg_if1_ip": "10::2",
"dut_to_tg_if2_ip": "20::2",
"gateway": "20::1",
# classified networks
"classify_src_net": "12::",
"classify_dst_net": "13::",
# IPs in classified networks
"classify_src": "12::1",
"classify_dst": "13::1",
"prefix_length": 64
},
"mixed": {
# IPs for DUT interface setup
"dut_to_tg_if1_ip": "16.0.0.2",
"dut_to_tg_if2_ip": "192.168.0.2",
"gateway": "192.168.0.1",
# classified networks
"classify_src_net": "16.0.2.0",
"classify_dst_net": "16.0.3.0",
# IPs in classified networks
"classify_src_ip": "16.0.2.1",
"classify_dst_ip": "16.0.3.1",
"prefix_length": 24,
# MACs classified through mask
"classify_src_mac": "01:02:03:04:56:67",
"classify_dst_mac": "89:9A:AB:BC:50:60",
"src_mask": "00:00:00:00:FF:FF",
"dst_mask": "FF:FF:FF:FF:00:00"
}
}
acl_data = {
# ACL configuration for L2 tests
"l2": {
"acl": [{
"acl-type":
"ietf-access-control-list:eth-acl",
"acl-name": name,
"access-list-entries": {"ace": [{
"rule-name": "rule1",
"matches": {
"source-mac-address":
test_vars["l2"]["classify_src"],
"source-mac-address-mask":
test_vars["l2"]["src_mask"],
"destination-mac-address":
test_vars["l2"]["classify_dst"],
"destination-mac-address-mask":
test_vars["l2"]["dst_mask"]
},
"actions": {
"deny": {}
}
}]}
}]
},
# ACL configuration for L3 IPv4 tests
"l3_ip4": {
"acl": [{
"acl-type":
"ietf-access-control-list:ipv4-acl",
"acl-name": name,
"access-list-entries": {"ace": [{
"rule-name": "rule1",
"matches": {
"source-ipv4-network":
"{0}/{1}".format(
test_vars["l3_ip4"]["classify_src_net"],
test_vars["l3_ip4"]["prefix_length"]),
"destination-ipv4-network":
"{0}/{1}".format(
test_vars["l3_ip4"]["classify_dst_net"],
test_vars["l3_ip4"]["prefix_length"]),
"protocol": 17
},
"actions": {
"deny": {}
}
}]}
}]
},
# ACL settings for L3 IPv6 tests
"l3_ip6": {
"acl": [{
"acl-type":
"ietf-access-control-list:ipv6-acl",
"acl-name": name,
"access-list-entries": {"ace": [{
"rule-name": "rule1",
"matches": {
"source-ipv6-network":
"{0}/{1}".format(
test_vars["l3_ip6"]["classify_src_net"],
test_vars["l3_ip6"]["prefix_length"]),
"destination-ipv6-network":
"{0}/{1}".format(
test_vars["l3_ip6"]["classify_dst_net"],
test_vars["l3_ip6"]["prefix_length"]),
"protocol": 17
},
"actions": {
"deny": {}
}
}]}
}]
},
"mixed": {
"acl": [{
"acl-type":
"vpp-acl:mixed-acl",
"acl-name": name,
"access-list-entries": {"ace": [{
"rule-name": "rule1",
"matches": {
"vpp-acl:source-mac-address":
test_vars["mixed"]["classify_src_mac"],
"vpp-acl:source-mac-address-mask":
test_vars["mixed"]["src_mask"],
"vpp-acl:destination-mac-address":
test_vars["mixed"]["classify_dst_mac"],
"vpp-acl:destination-mac-address-mask":
test_vars["mixed"]["dst_mask"],
"vpp-acl:source-ipv4-network":
"{0}/{1}".format(
test_vars["mixed"]["classify_src_net"],
test_vars["mixed"]["prefix_length"]),
"vpp-acl:destination-ipv4-network":
"{0}/{1}".format(
test_vars["mixed"]["classify_dst_net"],
test_vars["mixed"]["prefix_length"]),
"vpp-acl:protocol": 17
},
"actions": {
"deny": {}
}
}]}
}]
}
}
try:
variables.update(test_vars[test_case])
variables.update(
{"acl_settings": acl_data[test_case]}
)
except KeyError:
raise Exception("Unrecognized test case {0}."
" Valid options are: {1}".format(
test_case, acl_data.keys()))
return variables
|