-
Notifications
You must be signed in to change notification settings - Fork 1k
add csonic testbed support #1720
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
Draft
lguohan
wants to merge
2
commits into
sonic-net:master
Choose a base branch
from
lguohan:csonic
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # snmp variables | ||
| snmp_rocommunity: strcommunity | ||
| snmp_location: str | ||
| bgp_gr_timer: 700 | ||
|
|
||
| csonic_image_mount_dir: /data/csonic |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| - include_tasks: csonic_config.yml | ||
|
|
||
| - name: Create cSONiC container csonic_{{ vm_set_name }}_{{ inventory_hostname }} | ||
| become: yes | ||
| docker_container: | ||
| name: csonic_{{ vm_set_name }}_{{ inventory_hostname }} | ||
| image: "{{ csonic_image }}" | ||
| pull: no | ||
| state: started | ||
| restart: yes | ||
| tty: yes | ||
| network_mode: container:net_{{ vm_set_name }}_{{ inventory_hostname }} | ||
| detach: True | ||
| capabilities: | ||
| - net_admin | ||
| privileged: yes | ||
| volumes: | ||
| - /{{ csonic_image_mount_dir }}/csonic_{{ vm_set_name }}_{{ inventory_hostname }}/sonic:/var/sonic | ||
| - /{{ csonic_image_mount_dir }}/csonic_{{ vm_set_name }}_{{ inventory_hostname }}/frr:/etc/frr | ||
| delegate_to: "{{ VM_host[0] }}" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| - name: Get netbase container info | ||
| docker_container_info: | ||
| name: net_{{ vm_set_name }}_{{ inventory_hostname }} | ||
| register: ctninfo | ||
| delegate_to: "{{ VM_host[0] }}" | ||
| become: yes | ||
|
|
||
| - debug: msg="{{ ctninfo.container.State.Pid }}" | ||
|
|
||
| - name: Get front panel port in netbase container | ||
| shell: nsenter -t {{ ctninfo.container.State.Pid }} -n ip link show | grep -E eth[0-9]+ | wc -l | ||
| register: fp_num | ||
| delegate_to: "{{ VM_host[0] }}" | ||
| become: yes | ||
|
|
||
| - debug: msg="{{ fp_num }}" | ||
|
|
||
| - name: Set EOS backplane port name | ||
| set_fact: bp_ifname="Ethernet{{ fp_num.stdout|int - 1}}" | ||
|
|
||
| - name: create directory for sonic config | ||
| become: yes | ||
| file: | ||
| path: "/{{ csonic_image_mount_dir }}/csonic_{{ vm_set_name }}_{{ inventory_hostname }}/sonic" | ||
| state: directory | ||
| delegate_to: "{{ VM_host[0] }}" | ||
|
|
||
| - name: create config db | ||
| become: yes | ||
| template: src="configdb-{{ topo }}-{{ props.swrole }}.j2" | ||
| dest="/{{ csonic_image_mount_dir }}/csonic_{{ vm_set_name }}_{{ inventory_hostname }}/sonic/config_db.json" | ||
| delegate_to: "{{ VM_host[0] }}" | ||
|
|
||
| - name: create directory for frr config | ||
| become: yes | ||
| file: | ||
| path: "/{{ csonic_image_mount_dir }}/csonic_{{ vm_set_name }}_{{ inventory_hostname }}/frr" | ||
| state: directory | ||
| delegate_to: "{{ VM_host[0] }}" | ||
|
|
||
| - name: create frr bgpd config | ||
| become: yes | ||
| template: src="frr-{{ topo }}-{{ props.swrole }}.j2" | ||
| dest="/{{ csonic_image_mount_dir }}/csonic_{{ vm_set_name }}_{{ inventory_hostname }}/frr/bgpd.conf" | ||
| delegate_to: "{{ VM_host[0] }}" | ||
|
|
||
| - name: create zebra config | ||
| become: yes | ||
| template: src="zebra-{{ topo }}-{{ props.swrole }}.j2" | ||
| dest="/{{ csonic_image_mount_dir }}/csonic_{{ vm_set_name }}_{{ inventory_hostname }}/frr/zebra.conf" | ||
| delegate_to: "{{ VM_host[0] }}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| - debug: msg="{{ vm_type }}" | ||
| - debug: msg="{{ vm_set_name }}" | ||
|
|
||
| - name: Load topo variables | ||
| include_vars: "vars/topo_{{ topo }}.yml" | ||
|
|
||
| - name: Include server vars | ||
| include_vars: "{{ host_var_file }}" | ||
|
|
||
| - name: Find current server group | ||
| set_fact: current_server={{ group_names | extract_by_prefix('server_') }} | ||
|
|
||
| - name: Extract VM names from the inventory | ||
| set_fact: VM_list={{ groups[current_server] | filter_by_prefix('VM') }} | ||
|
|
||
| - name: Get VM host name | ||
| set_fact: VM_host={{ groups[current_server] | difference(VM_list) }} | ||
|
|
||
| - name: Generate hostname for target VM | ||
| set_fact: hostname={{ VM_list | extract_hostname(topology['VMs'], VM_base, inventory_hostname) }} | ||
| when: topology['VMs'] is defined | ||
|
|
||
| - fail: | ||
| msg: "cannot find {{ inventory_hostname }} in the topology" | ||
| when: hostname == "hostname not found" | ||
|
|
||
| - name: Set properties list to default value, when properties are not defined | ||
| set_fact: properties_list=[] | ||
| when: configuration is not defined or configuration[hostname] is not defined or configuration[hostname]['properties'] is not defined | ||
|
|
||
| - name: Set properties list to values, when they're defined | ||
| set_fact: properties_list="{{ configuration[hostname]['properties'] }}" | ||
| when: configuration and configuration[hostname] and configuration[hostname]['properties'] is defined | ||
|
|
||
| - name: Expand {{ hostname }} properties into props | ||
| set_fact: props="{{ configuration_properties[item] | combine(props | default({})) }}" | ||
| with_items: "{{ properties_list }}" | ||
| when: hostname in configuration and configuration_properties[item] is defined | ||
|
|
||
| - include_tasks: csonic.yml | ||
| when: vm_type == "csonic" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| {% set host = configuration[hostname] %} | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need to support backplane interface |
||
| { | ||
| {% for name, iface in host['interfaces'].items() %} | ||
| {% if name.startswith('Port-Channel') %} | ||
| "PORTCHANNEL": { | ||
| "{{ name | replace("-", "") }}": { | ||
| "admin_status": "up", | ||
| "mtu": "9100" | ||
| } | ||
| }, | ||
| "PORTCHANNEL_INTERFACE": { | ||
| "{{ name | replace("-", "") }}": {}, | ||
| {% if iface['ipv4'] is defined %} | ||
| "{{ name | replace("-", "") }}|{{ iface['ipv4'] }}": {}, | ||
| {% endif %} | ||
| {% if iface['ipv6'] is defined %} | ||
| "{{ name | replace("-", "") }}|{{ iface['ipv6'] }}": {} | ||
| {% endif %} | ||
| }, | ||
| {% endif %} | ||
| {% if iface['lacp'] is defined %} | ||
| "PORTCHANNEL_MEMBER": { | ||
| {% set index = name | replace("Ethernet", "") | int - 1 %} | ||
| "PortChannel{{ iface['lacp'] }}|Ethernet{{ index * 4}}": {} | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need to bring up the Ethernet interface |
||
| }, | ||
| {% endif %} | ||
| {% endfor %} | ||
| {% for name, iface in host['interfaces'].items() %} | ||
| {% if name.startswith('Loopback') %} | ||
| "LOOPBACK_INTERFACE": { | ||
| "{{ name }}": {}, | ||
| {% if iface['ipv4'] is defined %} | ||
| "{{ name }}|{{ iface['ipv4'] }}": {}, | ||
| {% endif %} | ||
| {% if iface['ipv6'] is defined %} | ||
| "{{ name }}|{{ iface['ipv6'] }}": {} | ||
| {% endif %} | ||
| } | ||
| {% endif %} | ||
| {% endfor %} | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| {% set host = configuration[hostname] %} | ||
| ! | ||
| hostname {{ hostname }} | ||
| password zebra | ||
| enable password zebra | ||
| ! | ||
| log syslog informational | ||
| log facility local4 | ||
| ! | ||
| router bgp {{ host['bgp']['asn'] }} | ||
| bgp router-id {{ host['interfaces']['Loopback0']['ipv4'] | ipaddr('address') }} | ||
| ! | ||
| {% for asn, remote_ips in host['bgp']['peers'].items() %} | ||
| {% for remote_ip in remote_ips %} | ||
| neighbor {{ remote_ip }} remote-as {{ asn }} | ||
| neighbor {{ remote_ip }} description {{ asn }} | ||
| {% if remote_ip | ipv6 %} | ||
| address-family ipv6 unicast | ||
| neighbor {{ remote_ip }} activate | ||
| exit | ||
| {% endif %} | ||
| {% endfor %} | ||
| {% endfor %} | ||
| neighbor {{ props.nhipv4 }} remote-as {{ host['bgp']['asn'] }} | ||
| neighbor {{ props.nhipv4 }} description exabgp_v4 | ||
| neighbor {{ props.nhipv6 }} remote-as {{ host['bgp']['asn'] }} | ||
| neighbor {{ props.nhipv6 }} description exabgp_v6 | ||
| address-family ipv6 | ||
| neighbor {{ props.nhipv6 }} activate | ||
| exit | ||
| ! | ||
| {% for name, iface in host['interfaces'].items() if name.startswith('Loopback') %} | ||
| {% if iface['ipv4'] is defined %} | ||
| address-family ipv4 unicast | ||
| network {{ iface['ipv4'] }} | ||
| {% endif %} | ||
| {% if iface['ipv6'] is defined %} | ||
| address-family ipv6 unicast | ||
| network {{ iface['ipv6'] }} | ||
| {% endif %} | ||
| {% endfor %} | ||
| ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| {% set host = configuration[hostname] %} | ||
| hostname {{ hostname }} | ||
| password zebra | ||
| enable password zebra | ||
| ! | ||
| log syslog informational | ||
| log facility local4 | ||
| ! | ||
| ! end of template: common/daemons.common.conf.j2! | ||
| ! | ||
| ! | ||
| ! Enable link-detect (default disabled) | ||
| {% for name, iface in host['interfaces'].items() %} | ||
| interface {{ name }} | ||
| link detect | ||
| ! | ||
| {% endfor %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,10 +12,10 @@ | |
|
|
||
| DOCUMENTATION = ''' | ||
| --- | ||
| module: ceos_network | ||
| module: cnet_network | ||
| version_added: "0.1" | ||
| author: Guohan Lu ([email protected]) | ||
| short_description: Create network for ceos container | ||
| short_description: Create network for container | ||
| description: | ||
| the module creates follow network interfaces | ||
| - 1 management interface which is added to management bridge | ||
|
|
@@ -30,7 +30,7 @@ | |
|
|
||
| EXAMPLES = ''' | ||
| - name: Create VMs network | ||
| ceos_network: | ||
| cnet_network: | ||
| name: net_{{ vm_set_name }}_{{ vm_name }} | ||
| vm_name: "{{ vm_name }}" | ||
| fp_mtu: "{{ fp_mtu_size }}" | ||
|
|
@@ -42,8 +42,8 @@ | |
| DEFAULT_MTU = 0 | ||
| NUM_FP_VLANS_PER_FP = 4 | ||
| VM_SET_NAME_MAX_LEN = 8 # used in interface names. So restricted | ||
| CMD_DEBUG_FNAME = "/tmp/ceos_network.cmds.%s.txt" | ||
| EXCEPTION_DEBUG_FNAME = "/tmp/ceos_network.exception.%s.txt" | ||
| CMD_DEBUG_FNAME = "/tmp/cnet_network.cmds.%s.txt" | ||
| EXCEPTION_DEBUG_FNAME = "/tmp/cnet_network.exception.%s.txt" | ||
|
|
||
| OVS_FP_BRIDGE_REGEX = 'br-%s-\d+' | ||
| OVS_FP_BRIDGE_TEMPLATE = 'br-%s-%d' | ||
|
|
@@ -316,4 +316,3 @@ def main(): | |
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| - name: Create VMs network | ||
| become: yes | ||
| vm_topology: | ||
| cmd: 'create' | ||
| vm_names: "{{ VM_hosts }}" | ||
| fp_mtu: "{{ fp_mtu_size }}" | ||
| max_fp_num: "{{ max_fp_num }}" | ||
|
|
||
| - include_tasks: add_cnet.yml | ||
| with_items: "{{ VM_targets }}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| - name: Remove cSONiC container csonic_{{ vm_set_name }}_{{ item }} | ||
| become: yes | ||
| docker_container: | ||
| name: csonic_{{ vm_set_name }}_{{ item }} | ||
| state: absent | ||
|
|
||
| - name: Remove net base container net_{{ vm_set_name }}_{{ item }} | ||
| become: yes | ||
| docker_container: | ||
| name: net_{{ vm_set_name }}_{{ item }} | ||
| state: absent |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| - include_tasks: remove_csonic.yml | ||
| with_items: "{{ VM_targets }}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to support ipv6