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

add port speed and fec configuration in sonic fanout #498

Merged
merged 1 commit into from
Mar 9, 2018
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
4 changes: 2 additions & 2 deletions ansible/library/conn_graph_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ def parse_graph(self):
start_dev = link.attrib['StartDevice']
end_dev = link.attrib['EndDevice']
if start_dev:
self.links[start_dev][link.attrib['StartPort']] = {'peerdevice':link.attrib['EndDevice'], 'peerport': link.attrib['EndPort']}
self.links[start_dev][link.attrib['StartPort']] = {'peerdevice':link.attrib['EndDevice'], 'peerport': link.attrib['EndPort'], 'speed': link.attrib['BandWidth']}
if end_dev:
self.links[end_dev][link.attrib['EndPort']] = {'peerdevice': link.attrib['StartDevice'], 'peerport': link.attrib['StartPort']}
self.links[end_dev][link.attrib['EndPort']] = {'peerdevice': link.attrib['StartDevice'], 'peerport': link.attrib['StartPort'], 'speed': link.attrib['BandWidth']}
self.devices = deviceinfo
self.vlanport = devicel2info

Expand Down
25 changes: 16 additions & 9 deletions ansible/library/port_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class SonicPortAliasMap():
def __init__(self, hwsku):
self.filename = ''
self.hwsku = hwsku
self.portmap = []
return

def findfile(self):
Expand All @@ -52,27 +51,35 @@ def findfile(self):
self.filename = rootdir+'/'+PORTMAP_FILE

def get_portmap(self):
aliases = []
portmap = {}
aliasmap = {}
self.findfile()
if self.filename == '':
raise Exception("Something wrong when trying to find the portmap file, either the hwsku is not available or file location is not correct")
with open(self.filename) as f:
lines = f.readlines()
alias=False
has_alias=False
while len(lines) != 0:
line = lines.pop(0)
if re.match('^#', line):
title=re.sub('#', '', line.strip().lower()).split()
if 'alias' in title:
index = title.index('alias')
alias = True
has_alias = True
else:
if re.match('^Ethernet', line):
mapping = line.split()
if alias and len(mapping) > index:
self.portmap.append(mapping[index])
name = mapping[0]
if has_alias and len(mapping) > index:
alias = mapping[index]
else:
self.portmap.append(mapping[0])
return
alias = name
aliases.append(alias)
portmap[name] = alias
aliasmap[alias] = name

return (aliases, portmap, aliasmap)

def main():
module = AnsibleModule(
Expand All @@ -84,8 +91,8 @@ def main():
m_args = module.params
try:
allmap = SonicPortAliasMap(m_args['hwsku'])
allmap.get_portmap()
module.exit_json(ansible_facts={'port_alias': allmap.portmap})
(aliases, portmap, aliasmap) = allmap.get_portmap()
module.exit_json(ansible_facts={'port_alias': aliases, 'port_name_map': portmap, 'port_alias_map': aliasmap})
except (IOError, OSError), e:
fail_msg = "IO error" + str(e)
module.fail_json(msg=fail_msg)
Expand Down
6 changes: 5 additions & 1 deletion ansible/roles/fanout/tasks/fanout_sonic.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
- debug: msg="{{ device_info }}"

- name: find interface name mapping
port_alias: hwsku="{{ device_info["HwSku"] }}"
connection: local

- name: prepare fanout switch admin login info
set_fact: ansible_user={{ fanout_sonic_user }} ansible_password={{ fanout_sonic_password }}

Expand All @@ -17,7 +21,7 @@
ansible_python_interpreter: docker exec -i swss python

- name: generate config_db.json
shell: sonic-cfggen -j /etc/sonic/vlan.json -j /etc/sonic/init_cfg.json --print-data > /etc/sonic/config_db.json
shell: sonic-cfggen -H -j /etc/sonic/vlan.json -j /etc/sonic/init_cfg.json --print-data > /etc/sonic/config_db.json
become: yes

- name: reload config_db.json
Expand Down
23 changes: 17 additions & 6 deletions ansible/roles/fanout/templates/sonic_deploy.j2
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@
}
},

"PORT": {
{% for alias in device_conn %}
"{{ port_alias_map[alias] }}": {
{% if device_conn[alias]['speed'] == "100000" %}
"fec" : "rs",
{% endif %}
"speed" : "{{ device_conn[alias]['speed'] }}"
}{% if not loop.last %},{% endif %}
{% endfor %}
},

"VLAN": {
{% for vlanid in device_vlan_list | unique %}
"Vlan{{ vlanid }}": {
Expand All @@ -17,17 +28,17 @@

{% set ns = {'firstPrinted': False} %}
"VLAN_MEMBER": {
{% for port in device_port_vlans %}
{% if device_port_vlans[port]['mode'] == 'Access' %}
{% for alias in device_port_vlans %}
{% if device_port_vlans[alias]['mode'] == 'Access' %}
{% if ns.firstPrinted %},{% endif %}
"Vlan{{ device_port_vlans[port]['vlanids'] }}|{{ port }}": {
"Vlan{{ device_port_vlans[alias]['vlanids'] }}|{{ port_alias_map[alias] }}": {
"tagging_mode" : "untagged"
}
{% if ns.update({'firstPrinted': True}) %} {% endif %}
{% elif device_port_vlans[port]['mode'] == 'Trunk' %}
{% for vlanid in device_port_vlans[port]['vlanlist'] %}
{% elif device_port_vlans[alias]['mode'] == 'Trunk' %}
{% for vlanid in device_port_vlans[alias]['vlanlist'] %}
{% if ns.firstPrinted %},{% endif %}
"Vlan{{ vlanid }}|{{ port }}": {
"Vlan{{ vlanid }}|{{ port_alias_map[alias] }}": {
"tagging_mode" : "tagged"
}
{% if ns.update({'firstPrinted': True}) %} {% endif %}
Expand Down