Skip to content

Commit 29f67eb

Browse files
oleksandrivantsivlguohan
authored andcommitted
[acl-loader]: acl-loader integration. (#1000)
* [acl-loader]: acl-loader integration. acl-loader was inplemented based on translate_acl source code. acl-loader can't be tested with unittest. Same testcases will be covered with testbed tests. - Remove translate_acl utility and tests. - Remove mirror template. - Do not run ACL rules and mirror configuration generators. - Adopt minigraph parser to work with acl-loader. * Update sonic-swss-common and sonic-swss submodules. Enable ACL dynamic config feature. * Update sonic-utilities submodule. Include fix for acl-loader incremental update command. * [sonic-cfggen]: Add test for everflow cfggen configuration.
1 parent 967030f commit 29f67eb

17 files changed

+27
-396
lines changed

dockers/docker-orchagent/mirror.json.j2

-24
This file was deleted.

dockers/docker-orchagent/start.sh

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ mkdir -p /etc/swss/config.d/
44

55
sonic-cfggen -m /etc/sonic/minigraph.xml -d -t /usr/share/sonic/templates/switch.json.j2 > /etc/swss/config.d/switch.json
66
sonic-cfggen -m /etc/sonic/minigraph.xml -d -t /usr/share/sonic/templates/ipinip.json.j2 > /etc/swss/config.d/ipinip.json
7-
sonic-cfggen -m /etc/sonic/minigraph.xml -d -t /usr/share/sonic/templates/mirror.json.j2 > /etc/swss/config.d/mirror.json
87
sonic-cfggen -m /etc/sonic/minigraph.xml -d -t /usr/share/sonic/templates/ports.json.j2 > /etc/swss/config.d/ports.json
98

109
export platform=`sonic-cfggen -v platform`

dockers/docker-orchagent/swssconfig.sh

+1-15
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,6 @@
22

33
set -e
44

5-
function config_acl {
6-
if [ -f "/etc/sonic/acl.json" ]; then
7-
mkdir -p /etc/swss/config.d/acl
8-
rm -rf /etc/swss/config.d/acl/*
9-
translate_acl -m /etc/sonic/minigraph.xml -o /etc/swss/config.d/acl /etc/sonic/acl.json
10-
for filename in /etc/swss/config.d/acl/*.json; do
11-
[ -e "$filename" ] || break
12-
swssconfig $filename
13-
done
14-
fi
15-
}
16-
175
function fast_reboot {
186
case "$(cat /proc/cmdline)" in
197
*fast-reboot*)
@@ -39,7 +27,7 @@ fast_reboot
3927

4028
HWSKU=`sonic-cfggen -m /etc/sonic/minigraph.xml -d -v "DEVICE_METADATA['localhost']['hwsku']"`
4129

42-
SWSSCONFIG_ARGS="00-copp.config.json ipinip.json mirror.json ports.json switch.json "
30+
SWSSCONFIG_ARGS="00-copp.config.json ipinip.json ports.json switch.json "
4331

4432
if [ "$HWSKU" == "Force10-S6000" ]; then
4533
SWSSCONFIG_ARGS+="td2.32ports.buffers.json td2.32ports.qos.json "
@@ -56,5 +44,3 @@ for file in $SWSSCONFIG_ARGS; do
5644
swssconfig /etc/swss/config.d/$file
5745
sleep 1
5846
done
59-
60-
config_acl

src/sonic-config-engine/minigraph.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
class minigraph_encoder(json.JSONEncoder):
3030
def default(self, obj):
3131
if isinstance(obj, (
32-
ipaddress.IPv4Network, ipaddress.IPv6Network,
32+
ipaddress.IPv4Network, ipaddress.IPv6Network,
3333
ipaddress.IPv4Address, ipaddress.IPv6Address
3434
)):
3535
return str(obj)
@@ -129,7 +129,7 @@ def parse_dpg(dpg, hname):
129129
intfname = lointf.find(str(QName(ns, "AttachTo"))).text
130130
ipprefix = lointf.find(str(QName(ns1, "PrefixStr"))).text
131131
lo_intfs[(intfname, ipprefix)] = {}
132-
132+
133133
mgmtintfs = child.find(str(QName(ns, "ManagementIPInterfaces")))
134134
mgmt_intf = {}
135135
for mgmtintf in mgmtintfs.findall(str(QName(ns1, "ManagementIPInterface"))):
@@ -175,7 +175,7 @@ def parse_dpg(dpg, hname):
175175
aclintfs = child.find(str(QName(ns, "AclInterfaces")))
176176
acls = {}
177177
for aclintf in aclintfs.findall(str(QName(ns, "AclInterface"))):
178-
aclname = aclintf.find(str(QName(ns, "InAcl"))).text.lower().replace(" ", "_").replace("-", "_")
178+
aclname = aclintf.find(str(QName(ns, "InAcl"))).text.upper().replace(" ", "_").replace("-", "_")
179179
aclattach = aclintf.find(str(QName(ns, "AttachTo"))).text.split(';')
180180
acl_intfs = []
181181
is_mirror = False
@@ -193,7 +193,7 @@ def parse_dpg(dpg, hname):
193193
acl_intfs = port_alias_map.values()
194194
break;
195195
if acl_intfs:
196-
acls[aclname] = { 'policy_desc': aclname, 'ports': acl_intfs, 'type': 'mirror' if is_mirror else 'L3'}
196+
acls[aclname] = { 'policy_desc': aclname, 'ports': acl_intfs, 'type': 'MIRROR' if is_mirror else 'L3'}
197197
return intfs, lo_intfs, mgmt_intf, vlans, pcs, acls
198198
return None, None, None, None, None, None
199199

@@ -358,7 +358,7 @@ def parse_xml(filename, platform=None, port_config_file=None):
358358
port_speeds = parse_deviceinfo(child, hwsku)
359359

360360
results = {}
361-
results['DEVICE_METADATA'] = {'localhost': {
361+
results['DEVICE_METADATA'] = {'localhost': {
362362
'bgp_asn': bgp_asn,
363363
'deployment_id': deployment_id,
364364
'hostname': hostname,
@@ -423,13 +423,13 @@ def parse_device_desc_xml(filename):
423423
(lo_prefix, mgmt_prefix, hostname, hwsku, d_type) = parse_device(root)
424424

425425
results = {}
426-
results['DEVICE_METADATA'] = {'localhost': {
426+
results['DEVICE_METADATA'] = {'localhost': {
427427
'hostname': hostname,
428428
'hwsku': hwsku,
429429
}}
430430

431431
results['LOOPBACK_INTERFACE'] = {('lo', lo_prefix): {}}
432-
432+
433433
mgmt_intf = {}
434434
mgmtipn = ipaddress.IPNetwork(mgmt_prefix)
435435
gwaddr = ipaddress.IPAddress(int(mgmtipn.network) + 1)

src/sonic-config-engine/setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def get_test_suite():
1616
author_email='[email protected]',
1717
url='https://github.com/Azure/sonic-buildimage',
1818
py_modules=['portconfig', 'minigraph', 'openconfig_acl', 'sonic_platform'],
19-
scripts=['sonic-cfggen', 'translate_acl'],
19+
scripts=['sonic-cfggen'],
2020
install_requires=['lxml', 'jinja2', 'netaddr', 'ipaddr', 'pyyaml', 'pyangbind'],
2121
test_suite='setup.get_test_suite',
2222
)

src/sonic-config-engine/tests/sample_output/mirror.json

-14
This file was deleted.

src/sonic-config-engine/tests/sample_output/rules_for_dataacl.json

-46
This file was deleted.

src/sonic-config-engine/tests/sample_output/rules_for_everflow.json

-14
This file was deleted.

src/sonic-config-engine/tests/sample_output/table_dataacl.json

-10
This file was deleted.

src/sonic-config-engine/tests/sample_output/table_everflow.json

-10
This file was deleted.

src/sonic-config-engine/tests/test_acl.py

-58
This file was deleted.

src/sonic-config-engine/tests/test_cfggen.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44

55
class TestCfgGen(TestCase):
6-
6+
77
def setUp(self):
88
self.test_dir = os.path.dirname(os.path.realpath(__file__))
99
self.script_file = os.path.join(self.test_dir, '..', 'sonic-cfggen')
@@ -29,7 +29,7 @@ def test_dummy_run(self):
2929
argument = ''
3030
output = self.run_script(argument)
3131
self.assertEqual(output, '')
32-
32+
3333
def test_device_desc(self):
3434
argument = '-v "DEVICE_METADATA[\'localhost\'][\'hwsku\']" -M "' + self.sample_device_desc + '"'
3535
output = self.run_script(argument)
@@ -44,17 +44,17 @@ def test_minigraph_sku(self):
4444
argument = '-v "DEVICE_METADATA[\'localhost\'][\'hwsku\']" -m "' + self.sample_graph + '"'
4545
output = self.run_script(argument)
4646
self.assertEqual(output.strip(), 'Force10-Z9100')
47-
47+
4848
def test_print_data(self):
4949
argument = '-m "' + self.sample_graph + '" --print-data'
5050
output = self.run_script(argument)
5151
self.assertTrue(len(output.strip()) > 0)
52-
52+
5353
def test_jinja_expression(self):
5454
argument = '-m "' + self.sample_graph + '" -v "DEVICE_METADATA[\'localhost\'][\'type\']"'
5555
output = self.run_script(argument)
5656
self.assertEqual(output.strip(), 'LeafRouter')
57-
57+
5858
def test_additional_json_data(self):
5959
argument = '-a \'{"key1":"value1"}\' -v key1'
6060
output = self.run_script(argument)
@@ -64,7 +64,7 @@ def test_read_yaml(self):
6464
argument = '-v yml_item -y ' + os.path.join(self.test_dir, 'test.yml')
6565
output = self.run_script(argument)
6666
self.assertEqual(output.strip(), '[\'value1\', \'value2\']')
67-
67+
6868
def test_render_template(self):
6969
argument = '-y ' + os.path.join(self.test_dir, 'test.yml') + ' -t ' + os.path.join(self.test_dir, 'test.j2')
7070
output = self.run_script(argument)
@@ -73,13 +73,18 @@ def test_render_template(self):
7373
def test_minigraph_acl(self):
7474
argument = '-m "' + self.sample_graph_t0 + '" -p "' + self.port_config + '" -v ACL_TABLE'
7575
output = self.run_script(argument)
76-
self.assertEqual(output.strip(), "{'dataacl': {'type': 'L3', 'policy_desc': 'dataacl', 'ports': ['Ethernet112', 'Ethernet116', 'Ethernet120', 'Ethernet124']}}")
76+
self.assertEqual(output.strip(), "{'DATAACL': {'type': 'L3', 'policy_desc': 'DATAACL', 'ports': ['Ethernet112', 'Ethernet116', 'Ethernet120', 'Ethernet124']}}")
77+
78+
def test_minigraph_everflow(self):
79+
argument = '-m "' + self.sample_graph_t0 + '" -p "' + self.port_config + '" -v MIRROR_SESSION'
80+
output = self.run_script(argument)
81+
self.assertEqual(output.strip(), "{'everflow0': {'src_ip': '10.1.0.32', 'dst_ip': '2.2.2.2'}}")
7782

7883
def test_minigraph_interfaces(self):
7984
argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v \'INTERFACE.keys()\''
8085
output = self.run_script(argument)
8186
self.assertEqual(output.strip(), "[('Ethernet0', '10.0.0.58/31'), ('Ethernet0', 'FC00::75/126')]")
82-
87+
8388
def test_minigraph_vlans(self):
8489
argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v VLAN'
8590
output = self.run_script(argument)

0 commit comments

Comments
 (0)