Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[minigraph]: Add portchannels/vlans dictionary and update teamd templates #408

Merged
merged 1 commit into from
Mar 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions dockers/docker-fpm/zebra.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ interface {{ interface['alias'] }}
link-detect
!
{% endfor %}
{% for interface in minigraph_portchannel_interfaces %}
interface {{ interface['name'] }}
link-detect
!
{% endfor %}
{% endblock interfaces %}
!
{% block default_route %}
Expand Down
2 changes: 1 addition & 1 deletion dockers/docker-teamd/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

mkdir -p /etc/teamd

for pc in `sonic-cfggen -m /etc/sonic/minigraph.xml -v "' '.join(minigraph_portchannel_interfaces.keys())"`; do
for pc in `sonic-cfggen -m /etc/sonic/minigraph.xml -v "minigraph_portchannels.keys() | join(' ')"`; do
sonic-cfggen -m /etc/sonic/minigraph.xml -a '{"pc":"'$pc'"}' -t /usr/share/sonic/templates/teamd.j2 >/etc/teamd/$pc.conf
done

Expand Down
4 changes: 2 additions & 2 deletions dockers/docker-teamd/teamd.j2
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"name": "lacp",
"active": true,
{# Use 75% links upperbound as min-links #}
"min_ports": {{ minigraph_portchannel_interfaces[pc] | length * 0.75 | round(0, 'ceil') | int}},
"min_ports": {{ minigraph_portchannels[pc]['members'] | length * 0.75 | round(0, 'ceil') | int}},
"tx_hash": ["eth", "ipv4", "ipv6"]
},
"link_watch": {
"name": "ethtool"
},
"ports": {
{% for member in minigraph_portchannel_interfaces[pc] %}
{% for member in minigraph_portchannels[pc]['members'] %}
"{{member}}": {}{% if not loop.last %},{% endif %}

{% endfor %}
Expand Down
12 changes: 10 additions & 2 deletions src/sonic-config-engine/minigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ def parse_dpg(dpg, hname):

pcintfs = child.find(str(QName(ns, "PortChannelInterfaces")))
pc_intfs = []
Copy link
Contributor

@taoyl-ms taoyl-ms Mar 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As PC interfaces are no longer in minigraph_interfaces (actually not in this PR but in #381), I think we need to update zebra.conf.j2 as well to configure bgp on pc interfaces correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated. please check.

pcs = {}
for pcintf in pcintfs.findall(str(QName(ns, "PortChannel"))):
pcintfname = pcintf.find(str(QName(ns, "Name"))).text
pcintfmbr = pcintf.find(str(QName(ns, "AttachTo"))).text
Expand All @@ -191,6 +192,7 @@ def parse_dpg(dpg, hname):
for addrtuple in pc_map.get(pcintfname, []):
pc_attributes.update(addrtuple)
pc_intfs.append(copy.deepcopy(pc_attributes))
pcs[pcintfname] = pc_attributes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to keep 'members' (and 'vlanid') information duplicated in both minigraph_xxx_interfaces and minigraph_xxx? Or shall we let minigraph_xxx_interfaces to have only the same information with minigraph_interfaces?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which means, name, alias, addr, mask, subnet, and peer_addr

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would vote for removing the duplicated information but not here in this commit. i'll submit a separate pull request to address this as well as adding some unit tests to make sure that the generated configuration files are not changed before/after new code changes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.


lointfs = child.find(str(QName(ns, "LoopbackIPInterfaces")))
lo_intfs = []
Expand Down Expand Up @@ -221,6 +223,7 @@ def parse_dpg(dpg, hname):

vlanintfs = child.find(str(QName(ns, "VlanInterfaces")))
vlan_intfs = []
vlans = {}
for vintf in vlanintfs.findall(str(QName(ns, "VlanInterface"))):
vintfname = vintf.find(str(QName(ns, "Name"))).text
vlanid = vintf.find(str(QName(ns, "VlanID"))).text
Expand All @@ -233,9 +236,10 @@ def parse_dpg(dpg, hname):
for addrtuple in vlan_map.get(vintfname, []):
vlan_attributes.update(addrtuple)
vlan_intfs.append(copy.deepcopy(vlan_attributes))
vlans[vintfname] = vlan_attributes


return intfs, lo_intfs, mgmt_intf, vlan_intfs, pc_intfs
return intfs, lo_intfs, mgmt_intf, vlan_intfs, pc_intfs, vlans, pcs
return None, None, None, None, None

def parse_cpg(cpg, hname):
Expand Down Expand Up @@ -362,6 +366,8 @@ def parse_xml(filename, platform=None):
intfs = None
vlan_intfs = None
pc_intfs = None
vlans = None
pcs = None
mgmt_intf = None
lo_intf = None
neighbors = None
Expand All @@ -386,7 +392,7 @@ def parse_xml(filename, platform=None):

for child in root:
if child.tag == str(QName(ns, "DpgDec")):
(intfs, lo_intfs, mgmt_intf, vlan_intfs, pc_intfs) = parse_dpg(child, hostname)
(intfs, lo_intfs, mgmt_intf, vlan_intfs, pc_intfs, vlans, pcs) = parse_dpg(child, hostname)
elif child.tag == str(QName(ns, "CpgDec")):
(bgp_sessions, bgp_asn) = parse_cpg(child, hostname)
elif child.tag == str(QName(ns, "PngDec")):
Expand All @@ -409,6 +415,8 @@ def parse_xml(filename, platform=None):
results['minigraph_interfaces'] = sorted(intfs, key=lambda x: x['name'])
results['minigraph_vlan_interfaces'] = vlan_intfs
results['minigraph_portchannel_interfaces'] = pc_intfs
results['minigraph_vlans'] = vlans
results['minigraph_portchannels'] = pcs
results['minigraph_mgmt_interface'] = mgmt_intf
results['minigraph_lo_interfaces'] = lo_intfs
results['minigraph_neighbors'] = neighbors
Expand Down