d5c3040d7abb25f74a41836ea9f48267019b0f8d
[csit.git] / resources / test_data / honeycomb / ietf_acl.py
1 # Copyright (c) 2016 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13
14 """Test variables for ietf-ACL test suite."""
15
16
17 def get_variables(test_case, name):
18     """Create and return a dictionary of test variables for the specified
19     test case.
20
21     :param test_case: Determines which test variables to return.
22     :param name: Name for the classify chain used in test.
23     :type test_case: str
24     :type name: str
25
26     :return: Dictionary of test variables - settings for Honeycomb's
27     ietf-acl node and packet fields to use in verification.
28     :rtype: dict
29     """
30
31     variables = {
32         # generic packet data
33         "src_ip": "16.0.0.1",
34         "dst_ip": "16.0.1.1",
35         "dst_net": "16.0.1.0",
36         "src_port": "1234",
37         "dst_port": "1234",
38         "src_mac": "01:02:03:04:05:06",
39         "dst_mac": "10:20:30:40:50:60"}
40
41     if test_case.lower() == "l2":
42         classify_vars = {
43             "classify_src": "12:23:34:45:56:67",
44             "classify_dst": "89:9A:AB:BC:CD:DE",
45             "classify_src2": "01:02:03:04:56:67",
46             "classify_dst2": "89:9A:AB:BC:50:60",
47             "src_mask": "00:00:00:00:FF:FF",
48             "dst_mask": "FF:FF:FF:FF:00:00",
49             }
50
51         acl_settings = {
52             "acl": [{
53                 "acl-type":
54                     "ietf-access-control-list:eth-acl",
55                 "acl-name": name,
56                 "access-list-entries": {"ace": [{
57                     "rule-name": "rule1",
58                     "matches": {
59                         "source-mac-address":
60                             classify_vars["classify_src"],
61                         "source-mac-address-mask":
62                             classify_vars["src_mask"],
63                         "destination-mac-address":
64                             classify_vars["classify_dst"],
65                         "destination-mac-address-mask":
66                             classify_vars["dst_mask"]
67                     },
68                     "actions": {
69                         "deny": {}
70                     }
71                 }]}
72             }]
73         }
74
75     elif test_case.lower() in ("l3_ip4", "l3_ip6", "l4"):
76         raise NotImplementedError
77     else:
78         raise Exception("Unrecognized test case {0}".format(test_case))
79
80     variables.update(classify_vars)
81     variables["acl_settings"] = acl_settings
82     return variables