Skip to content

Commit

Permalink
[acl-loader]: acl-loader integration. (#1000)
Browse files Browse the repository at this point in the history
* [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.
  • Loading branch information
oleksandrivantsiv authored and lguohan committed Nov 2, 2017
1 parent 967030f commit 29f67eb
Show file tree
Hide file tree
Showing 17 changed files with 27 additions and 396 deletions.
24 changes: 0 additions & 24 deletions dockers/docker-orchagent/mirror.json.j2

This file was deleted.

1 change: 0 additions & 1 deletion dockers/docker-orchagent/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ mkdir -p /etc/swss/config.d/

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

export platform=`sonic-cfggen -v platform`
Expand Down
16 changes: 1 addition & 15 deletions dockers/docker-orchagent/swssconfig.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,6 @@

set -e

function config_acl {
if [ -f "/etc/sonic/acl.json" ]; then
mkdir -p /etc/swss/config.d/acl
rm -rf /etc/swss/config.d/acl/*
translate_acl -m /etc/sonic/minigraph.xml -o /etc/swss/config.d/acl /etc/sonic/acl.json
for filename in /etc/swss/config.d/acl/*.json; do
[ -e "$filename" ] || break
swssconfig $filename
done
fi
}

function fast_reboot {
case "$(cat /proc/cmdline)" in
*fast-reboot*)
Expand All @@ -39,7 +27,7 @@ fast_reboot

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

SWSSCONFIG_ARGS="00-copp.config.json ipinip.json mirror.json ports.json switch.json "
SWSSCONFIG_ARGS="00-copp.config.json ipinip.json ports.json switch.json "

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

config_acl
14 changes: 7 additions & 7 deletions src/sonic-config-engine/minigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
class minigraph_encoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, (
ipaddress.IPv4Network, ipaddress.IPv6Network,
ipaddress.IPv4Network, ipaddress.IPv6Network,
ipaddress.IPv4Address, ipaddress.IPv6Address
)):
return str(obj)
Expand Down Expand Up @@ -129,7 +129,7 @@ def parse_dpg(dpg, hname):
intfname = lointf.find(str(QName(ns, "AttachTo"))).text
ipprefix = lointf.find(str(QName(ns1, "PrefixStr"))).text
lo_intfs[(intfname, ipprefix)] = {}

mgmtintfs = child.find(str(QName(ns, "ManagementIPInterfaces")))
mgmt_intf = {}
for mgmtintf in mgmtintfs.findall(str(QName(ns1, "ManagementIPInterface"))):
Expand Down Expand Up @@ -175,7 +175,7 @@ def parse_dpg(dpg, hname):
aclintfs = child.find(str(QName(ns, "AclInterfaces")))
acls = {}
for aclintf in aclintfs.findall(str(QName(ns, "AclInterface"))):
aclname = aclintf.find(str(QName(ns, "InAcl"))).text.lower().replace(" ", "_").replace("-", "_")
aclname = aclintf.find(str(QName(ns, "InAcl"))).text.upper().replace(" ", "_").replace("-", "_")
aclattach = aclintf.find(str(QName(ns, "AttachTo"))).text.split(';')
acl_intfs = []
is_mirror = False
Expand All @@ -193,7 +193,7 @@ def parse_dpg(dpg, hname):
acl_intfs = port_alias_map.values()
break;
if acl_intfs:
acls[aclname] = { 'policy_desc': aclname, 'ports': acl_intfs, 'type': 'mirror' if is_mirror else 'L3'}
acls[aclname] = { 'policy_desc': aclname, 'ports': acl_intfs, 'type': 'MIRROR' if is_mirror else 'L3'}
return intfs, lo_intfs, mgmt_intf, vlans, pcs, acls
return None, None, None, None, None, None

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

results = {}
results['DEVICE_METADATA'] = {'localhost': {
results['DEVICE_METADATA'] = {'localhost': {
'bgp_asn': bgp_asn,
'deployment_id': deployment_id,
'hostname': hostname,
Expand Down Expand Up @@ -423,13 +423,13 @@ def parse_device_desc_xml(filename):
(lo_prefix, mgmt_prefix, hostname, hwsku, d_type) = parse_device(root)

results = {}
results['DEVICE_METADATA'] = {'localhost': {
results['DEVICE_METADATA'] = {'localhost': {
'hostname': hostname,
'hwsku': hwsku,
}}

results['LOOPBACK_INTERFACE'] = {('lo', lo_prefix): {}}

mgmt_intf = {}
mgmtipn = ipaddress.IPNetwork(mgmt_prefix)
gwaddr = ipaddress.IPAddress(int(mgmtipn.network) + 1)
Expand Down
2 changes: 1 addition & 1 deletion src/sonic-config-engine/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def get_test_suite():
author_email='taoyl@microsoft.com',
url='https://github.com/Azure/sonic-buildimage',
py_modules=['portconfig', 'minigraph', 'openconfig_acl', 'sonic_platform'],
scripts=['sonic-cfggen', 'translate_acl'],
scripts=['sonic-cfggen'],
install_requires=['lxml', 'jinja2', 'netaddr', 'ipaddr', 'pyyaml', 'pyangbind'],
test_suite='setup.get_test_suite',
)
14 changes: 0 additions & 14 deletions src/sonic-config-engine/tests/sample_output/mirror.json

This file was deleted.

46 changes: 0 additions & 46 deletions src/sonic-config-engine/tests/sample_output/rules_for_dataacl.json

This file was deleted.

This file was deleted.

10 changes: 0 additions & 10 deletions src/sonic-config-engine/tests/sample_output/table_dataacl.json

This file was deleted.

10 changes: 0 additions & 10 deletions src/sonic-config-engine/tests/sample_output/table_everflow.json

This file was deleted.

58 changes: 0 additions & 58 deletions src/sonic-config-engine/tests/test_acl.py

This file was deleted.

21 changes: 13 additions & 8 deletions src/sonic-config-engine/tests/test_cfggen.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os

class TestCfgGen(TestCase):

def setUp(self):
self.test_dir = os.path.dirname(os.path.realpath(__file__))
self.script_file = os.path.join(self.test_dir, '..', 'sonic-cfggen')
Expand All @@ -29,7 +29,7 @@ def test_dummy_run(self):
argument = ''
output = self.run_script(argument)
self.assertEqual(output, '')

def test_device_desc(self):
argument = '-v "DEVICE_METADATA[\'localhost\'][\'hwsku\']" -M "' + self.sample_device_desc + '"'
output = self.run_script(argument)
Expand All @@ -44,17 +44,17 @@ def test_minigraph_sku(self):
argument = '-v "DEVICE_METADATA[\'localhost\'][\'hwsku\']" -m "' + self.sample_graph + '"'
output = self.run_script(argument)
self.assertEqual(output.strip(), 'Force10-Z9100')

def test_print_data(self):
argument = '-m "' + self.sample_graph + '" --print-data'
output = self.run_script(argument)
self.assertTrue(len(output.strip()) > 0)

def test_jinja_expression(self):
argument = '-m "' + self.sample_graph + '" -v "DEVICE_METADATA[\'localhost\'][\'type\']"'
output = self.run_script(argument)
self.assertEqual(output.strip(), 'LeafRouter')

def test_additional_json_data(self):
argument = '-a \'{"key1":"value1"}\' -v key1'
output = self.run_script(argument)
Expand All @@ -64,7 +64,7 @@ def test_read_yaml(self):
argument = '-v yml_item -y ' + os.path.join(self.test_dir, 'test.yml')
output = self.run_script(argument)
self.assertEqual(output.strip(), '[\'value1\', \'value2\']')

def test_render_template(self):
argument = '-y ' + os.path.join(self.test_dir, 'test.yml') + ' -t ' + os.path.join(self.test_dir, 'test.j2')
output = self.run_script(argument)
Expand All @@ -73,13 +73,18 @@ def test_render_template(self):
def test_minigraph_acl(self):
argument = '-m "' + self.sample_graph_t0 + '" -p "' + self.port_config + '" -v ACL_TABLE'
output = self.run_script(argument)
self.assertEqual(output.strip(), "{'dataacl': {'type': 'L3', 'policy_desc': 'dataacl', 'ports': ['Ethernet112', 'Ethernet116', 'Ethernet120', 'Ethernet124']}}")
self.assertEqual(output.strip(), "{'DATAACL': {'type': 'L3', 'policy_desc': 'DATAACL', 'ports': ['Ethernet112', 'Ethernet116', 'Ethernet120', 'Ethernet124']}}")

def test_minigraph_everflow(self):
argument = '-m "' + self.sample_graph_t0 + '" -p "' + self.port_config + '" -v MIRROR_SESSION'
output = self.run_script(argument)
self.assertEqual(output.strip(), "{'everflow0': {'src_ip': '10.1.0.32', 'dst_ip': '2.2.2.2'}}")

def test_minigraph_interfaces(self):
argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v \'INTERFACE.keys()\''
output = self.run_script(argument)
self.assertEqual(output.strip(), "[('Ethernet0', '10.0.0.58/31'), ('Ethernet0', 'FC00::75/126')]")

def test_minigraph_vlans(self):
argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v VLAN'
output = self.run_script(argument)
Expand Down
Loading

0 comments on commit 29f67eb

Please sign in to comment.