Skip to content

Commit 1382f7a

Browse files
authored
[acl] Move ACL table constants to acltable.h (sonic-net#1671)
Signed-off-by: Danny Allen <daall@microsoft.com>
1 parent 48dc60e commit 1382f7a

File tree

4 files changed

+70
-81
lines changed

4 files changed

+70
-81
lines changed

orchagent/aclorch.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -3103,11 +3103,11 @@ void AclOrch::doAclTableTask(Consumer &consumer)
31033103

31043104
SWSS_LOG_DEBUG("TABLE ATTRIBUTE: %s : %s", attr_name.c_str(), attr_value.c_str());
31053105

3106-
if (attr_name == TABLE_DESCRIPTION)
3106+
if (attr_name == ACL_TABLE_DESCRIPTION)
31073107
{
31083108
newTable.description = attr_value;
31093109
}
3110-
else if (attr_name == TABLE_TYPE)
3110+
else if (attr_name == ACL_TABLE_TYPE)
31113111
{
31123112
if (!processAclTableType(attr_value, newTable.type))
31133113
{
@@ -3117,7 +3117,7 @@ void AclOrch::doAclTableTask(Consumer &consumer)
31173117
break;
31183118
}
31193119
}
3120-
else if (attr_name == TABLE_PORTS)
3120+
else if (attr_name == ACL_TABLE_PORTS)
31213121
{
31223122
if (!processAclTablePorts(attr_value, newTable))
31233123
{
@@ -3127,7 +3127,7 @@ void AclOrch::doAclTableTask(Consumer &consumer)
31273127
break;
31283128
}
31293129
}
3130-
else if (attr_name == TABLE_STAGE)
3130+
else if (attr_name == ACL_TABLE_STAGE)
31313131
{
31323132
if (!processAclTableStage(attr_value, newTable.stage))
31333133
{
@@ -3137,7 +3137,7 @@ void AclOrch::doAclTableTask(Consumer &consumer)
31373137
break;
31383138
}
31393139
}
3140-
else if (attr_name == TABLE_SERVICES)
3140+
else if (attr_name == ACL_TABLE_SERVICES)
31413141
{
31423142
// TODO: validate control plane ACL table has this attribute
31433143
continue;

orchagent/aclorch.h

+3-36
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,21 @@
88
#include <tuple>
99
#include <map>
1010
#include <condition_variable>
11+
1112
#include "orch.h"
1213
#include "switchorch.h"
1314
#include "portsorch.h"
1415
#include "mirrororch.h"
1516
#include "dtelorch.h"
1617
#include "observer.h"
1718

19+
#include "acltable.h"
20+
1821
// ACL counters update interval in the DB
1922
// Value is in seconds. Should not be less than 5 seconds
2023
// (in worst case update of 1265 counters takes almost 5 sec)
2124
#define COUNTERS_READ_INTERVAL 10
2225

23-
#define TABLE_DESCRIPTION "POLICY_DESC"
24-
#define TABLE_TYPE "TYPE"
25-
#define TABLE_PORTS "PORTS"
26-
#define TABLE_SERVICES "SERVICES"
27-
28-
#define TABLE_TYPE_L3 "L3"
29-
#define TABLE_TYPE_L3V6 "L3V6"
30-
#define TABLE_TYPE_MIRROR "MIRROR"
31-
#define TABLE_TYPE_MIRRORV6 "MIRRORV6"
32-
#define TABLE_TYPE_MIRROR_DSCP "MIRROR_DSCP"
33-
#define TABLE_TYPE_PFCWD "PFCWD"
34-
#define TABLE_TYPE_CTRLPLANE "CTRLPLANE"
35-
#define TABLE_TYPE_DTEL_FLOW_WATCHLIST "DTEL_FLOW_WATCHLIST"
36-
#define TABLE_TYPE_DTEL_DROP_WATCHLIST "DTEL_DROP_WATCHLIST"
37-
#define TABLE_TYPE_MCLAG "MCLAG"
38-
#define TABLE_TYPE_MUX "MUX"
39-
#define TABLE_TYPE_DROP "DROP"
40-
4126
#define RULE_PRIORITY "PRIORITY"
4227
#define MATCH_IN_PORTS "IN_PORTS"
4328
#define MATCH_OUT_PORTS "OUT_PORTS"
@@ -109,24 +94,6 @@
10994
#define RULE_OPER_ADD 0
11095
#define RULE_OPER_DELETE 1
11196

112-
typedef enum
113-
{
114-
ACL_TABLE_UNKNOWN,
115-
ACL_TABLE_L3,
116-
ACL_TABLE_L3V6,
117-
ACL_TABLE_MIRROR,
118-
ACL_TABLE_MIRRORV6,
119-
ACL_TABLE_MIRROR_DSCP,
120-
ACL_TABLE_PFCWD,
121-
ACL_TABLE_CTRLPLANE,
122-
ACL_TABLE_DTEL_FLOW_WATCHLIST,
123-
ACL_TABLE_DTEL_DROP_WATCHLIST,
124-
ACL_TABLE_MCLAG,
125-
ACL_TABLE_MUX,
126-
ACL_TABLE_DROP
127-
} acl_table_type_t;
128-
129-
typedef map<string, acl_table_type_t> acl_table_type_lookup_t;
13097
typedef map<string, sai_acl_entry_attr_t> acl_rule_attr_lookup_t;
13198
typedef map<string, sai_acl_ip_type_t> acl_ip_type_lookup_t;
13299
typedef map<string, sai_acl_dtel_flow_op_t> acl_dtel_flow_op_type_lookup_t;

orchagent/acltable.h

+45-17
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,35 @@
1-
#ifndef SWSS_ACLTABLE_H
2-
#define SWSS_ACLTABLE_H
1+
#pragma once
32

43
extern "C" {
54
#include "sai.h"
65
}
76

8-
#include <set>
97
#include <string>
10-
#include <vector>
11-
#include <map>
12-
13-
using namespace std;
14-
15-
/* TODO: move all acltable and aclrule implementation out of aclorch */
16-
17-
#define STAGE_INGRESS "INGRESS"
18-
#define STAGE_EGRESS "EGRESS"
19-
#define TABLE_INGRESS STAGE_INGRESS
20-
#define TABLE_EGRESS STAGE_EGRESS
21-
#define TABLE_STAGE "STAGE"
8+
#include <unordered_map>
9+
10+
// TODO: Move the rest of AclTable implementation out of AclOrch
11+
12+
#define ACL_TABLE_DESCRIPTION "POLICY_DESC"
13+
#define ACL_TABLE_STAGE "STAGE"
14+
#define ACL_TABLE_TYPE "TYPE"
15+
#define ACL_TABLE_PORTS "PORTS"
16+
#define ACL_TABLE_SERVICES "SERVICES"
17+
18+
#define STAGE_INGRESS "INGRESS"
19+
#define STAGE_EGRESS "EGRESS"
20+
21+
#define TABLE_TYPE_L3 "L3"
22+
#define TABLE_TYPE_L3V6 "L3V6"
23+
#define TABLE_TYPE_MIRROR "MIRROR"
24+
#define TABLE_TYPE_MIRRORV6 "MIRRORV6"
25+
#define TABLE_TYPE_MIRROR_DSCP "MIRROR_DSCP"
26+
#define TABLE_TYPE_PFCWD "PFCWD"
27+
#define TABLE_TYPE_CTRLPLANE "CTRLPLANE"
28+
#define TABLE_TYPE_DTEL_FLOW_WATCHLIST "DTEL_FLOW_WATCHLIST"
29+
#define TABLE_TYPE_DTEL_DROP_WATCHLIST "DTEL_DROP_WATCHLIST"
30+
#define TABLE_TYPE_MCLAG "MCLAG"
31+
#define TABLE_TYPE_MUX "MUX"
32+
#define TABLE_TYPE_DROP "DROP"
2233

2334
typedef enum
2435
{
@@ -27,6 +38,23 @@ typedef enum
2738
ACL_STAGE_EGRESS
2839
} acl_stage_type_t;
2940

30-
typedef map<string, acl_stage_type_t> acl_stage_type_lookup_t;
41+
typedef std::unordered_map<std::string, acl_stage_type_t> acl_stage_type_lookup_t;
3142

32-
#endif /* SWSS_ACLTABLE_H */
43+
typedef enum
44+
{
45+
ACL_TABLE_UNKNOWN,
46+
ACL_TABLE_L3,
47+
ACL_TABLE_L3V6,
48+
ACL_TABLE_MIRROR,
49+
ACL_TABLE_MIRRORV6,
50+
ACL_TABLE_MIRROR_DSCP,
51+
ACL_TABLE_PFCWD,
52+
ACL_TABLE_CTRLPLANE,
53+
ACL_TABLE_DTEL_FLOW_WATCHLIST,
54+
ACL_TABLE_DTEL_DROP_WATCHLIST,
55+
ACL_TABLE_MCLAG,
56+
ACL_TABLE_MUX,
57+
ACL_TABLE_DROP
58+
} acl_table_type_t;
59+
60+
typedef std::unordered_map<std::string, acl_table_type_t> acl_table_type_lookup_t;

tests/mock_tests/aclorch_ut.cpp

+17-23
Original file line numberDiff line numberDiff line change
@@ -748,10 +748,7 @@ namespace aclorch_test
748748
{
749749
for (const auto &fv : values)
750750
{
751-
if (fv.first == TABLE_DESCRIPTION)
752-
{
753-
}
754-
else if (fv.first == TABLE_TYPE)
751+
if (fv.first == ACL_TABLE_TYPE)
755752
{
756753
if (fv.second == TABLE_TYPE_L3)
757754
{
@@ -772,16 +769,16 @@ namespace aclorch_test
772769
return false;
773770
}
774771
}
775-
else if (fv.first == TABLE_STAGE)
772+
else if (fv.first == ACL_TABLE_STAGE)
776773
{
777-
if (fv.second == TABLE_INGRESS)
774+
if (fv.second == STAGE_INGRESS)
778775
{
779776
if (acl_table.stage != ACL_STAGE_INGRESS)
780777
{
781778
return false;
782779
}
783780
}
784-
else if (fv.second == TABLE_EGRESS)
781+
else if (fv.second == STAGE_EGRESS)
785782
{
786783
if (acl_table.stage != ACL_STAGE_EGRESS)
787784
{
@@ -793,9 +790,6 @@ namespace aclorch_test
793790
return false;
794791
}
795792
}
796-
else if (fv.first == TABLE_PORTS)
797-
{
798-
}
799793
}
800794

801795
return true;
@@ -951,17 +945,17 @@ namespace aclorch_test
951945

952946
for (const auto &acl_table_type : { TABLE_TYPE_L3, TABLE_TYPE_L3V6 })
953947
{
954-
for (const auto &acl_table_stage : { TABLE_INGRESS, TABLE_EGRESS })
948+
for (const auto &acl_table_stage : { STAGE_INGRESS, STAGE_EGRESS })
955949
{
956950
string acl_table_id = "acl_table_1";
957951

958952
auto kvfAclTable = deque<KeyOpFieldsValuesTuple>(
959953
{ { acl_table_id,
960954
SET_COMMAND,
961-
{ { TABLE_DESCRIPTION, "filter source IP" },
962-
{ TABLE_TYPE, acl_table_type },
963-
{ TABLE_STAGE, acl_table_stage },
964-
{ TABLE_PORTS, "1,2" } } } });
955+
{ { ACL_TABLE_DESCRIPTION, "filter source IP" },
956+
{ ACL_TABLE_TYPE, acl_table_type },
957+
{ ACL_TABLE_STAGE, acl_table_stage },
958+
{ ACL_TABLE_PORTS, "1,2" } } } });
965959
// FIXME: ^^^^^^^^^^^^^ fixed port
966960

967961
orch->doAclTableTask(kvfAclTable);
@@ -1012,12 +1006,12 @@ namespace aclorch_test
10121006
auto kvfAclTable = deque<KeyOpFieldsValuesTuple>(
10131007
{ { acl_table_id,
10141008
SET_COMMAND,
1015-
{ { TABLE_DESCRIPTION, "filter source IP" },
1016-
{ TABLE_TYPE, TABLE_TYPE_L3 },
1009+
{ { ACL_TABLE_DESCRIPTION, "filter source IP" },
1010+
{ ACL_TABLE_TYPE, TABLE_TYPE_L3 },
10171011
// ^^^^^^^^^^^^^ L3 ACL
1018-
{ TABLE_STAGE, TABLE_INGRESS },
1012+
{ ACL_TABLE_STAGE, STAGE_INGRESS },
10191013
// FIXME: ^^^^^^^^^^^^^ only support / test for ingress ?
1020-
{ TABLE_PORTS, "1,2" } } } });
1014+
{ ACL_TABLE_PORTS, "1,2" } } } });
10211015
// FIXME: ^^^^^^^^^^^^^ fixed port
10221016

10231017
orch->doAclTableTask(kvfAclTable);
@@ -1102,12 +1096,12 @@ namespace aclorch_test
11021096
auto kvfAclTable = deque<KeyOpFieldsValuesTuple>(
11031097
{ { acl_table_id,
11041098
SET_COMMAND,
1105-
{ { TABLE_DESCRIPTION, "filter source IP" },
1106-
{ TABLE_TYPE, TABLE_TYPE_L3V6 },
1099+
{ { ACL_TABLE_DESCRIPTION, "filter source IP" },
1100+
{ ACL_TABLE_TYPE, TABLE_TYPE_L3V6 },
11071101
// ^^^^^^^^^^^^^ L3V6 ACL
1108-
{ TABLE_STAGE, TABLE_INGRESS },
1102+
{ ACL_TABLE_STAGE, STAGE_INGRESS },
11091103
// FIXME: ^^^^^^^^^^^^^ only support / test for ingress ?
1110-
{ TABLE_PORTS, "1,2" } } } });
1104+
{ ACL_TABLE_PORTS, "1,2" } } } });
11111105
// FIXME: ^^^^^^^^^^^^^ fixed port
11121106

11131107
orch->doAclTableTask(kvfAclTable);

0 commit comments

Comments
 (0)