diff --git a/platform/vs/docker-sonic-vs/Dockerfile.j2 b/platform/vs/docker-sonic-vs/Dockerfile.j2 index 3210a6814a53..6969ed556592 100644 --- a/platform/vs/docker-sonic-vs/Dockerfile.j2 +++ b/platform/vs/docker-sonic-vs/Dockerfile.j2 @@ -42,7 +42,8 @@ RUN apt-get install -y net-tools \ python-tabulate \ bash-completion \ libelf1 \ - libmnl0 + libmnl0 \ + lldpd RUN pip install setuptools RUN pip install py2_ipaddress @@ -84,6 +85,15 @@ COPY ["supervisord.conf", "/etc/supervisor/conf.d/"] COPY ["files/configdb-load.sh", "/usr/bin/"] COPY ["files/arp_update", "/usr/bin"] +COPY ["interfaces.j2", "/usr/share/sonic/templates/"] +COPY ["deployment_id_asn_map.yml", "/etc/sonic/"] +COPY ["teamd.sh", "/usr/bin/"] +COPY ["teamd.j2", "/usr/share/sonic/templates/"] +COPY ["bgpcfgd", "/usr/bin/"] +COPY ["sonic_version.yml", "/etc/sonic/sonic_version.yml"] +COPY ["*.j2", "/usr/share/sonic/templates/"] +COPY ["minigraph.xml", "/etc/sonic/"] + RUN echo "docker-sonic-vs" > /etc/hostname RUN touch /etc/quagga/zebra.conf diff --git a/platform/vs/docker-sonic-vs/bgpcfgd b/platform/vs/docker-sonic-vs/bgpcfgd new file mode 100755 index 000000000000..012a766c20b9 --- /dev/null +++ b/platform/vs/docker-sonic-vs/bgpcfgd @@ -0,0 +1,65 @@ +#!/usr/bin/env python + +import sys +import redis +import subprocess +import syslog +from swsssdk import ConfigDBConnector + +class BGPConfigDaemon: + + def __init__(self): + self.config_db = ConfigDBConnector() + self.config_db.connect() + self.bgp_asn = self.config_db.get_entry('DEVICE_METADATA', 'localhost')['bgp_asn'] + self.bgp_neighbor = self.config_db.get_table('BGP_NEIGHBOR') + + def __run_command(self, command): +# print command + p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) + stdout = p.communicate()[0] + p.wait() + if p.returncode != 0: + syslog.syslog(syslog.LOG_ERR, '[bgp cfgd] command execution returned {}. Command: "{}", stdout: "{}"'.format(p.returncode, command, stdout)) + + def metadata_handler(self, key, data): + if key == 'localhost' and data.has_key('bgp_asn'): + if data['bgp_asn'] != self.bgp_asn: + syslog.syslog(syslog.LOG_INFO, '[bgp cfgd] ASN changed to {} from {}, restart BGP...'.format(data['bgp_asn'], self.bgp_asn)) + self.__run_command("supervisorctl restart start.sh") + self.__run_command("service quagga restart") + self.bgp_asn = data['bgp_asn'] + + def bgp_handler(self, key, data): + syslog.syslog(syslog.LOG_INFO, '[bgp cfgd] value for {} changed to {}'.format(key, data)) + if not data: + # Neighbor is deleted + command = "vtysh -c 'configure terminal' -c 'router bgp {}' -c 'no neighbor {}'".format(self.bgp_asn, key) + self.__run_command(command) + self.bgp_neighbor.pop(key) + else: + command = "vtysh -c 'configure terminal' -c 'router bgp {}' -c 'neighbor {} remote-as {}'".format(self.bgp_asn, key, data['asn']) + self.__run_command(command) + if data.has_key('name'): + command = "vtysh -c 'configure terminal' -c 'router bgp {}' -c 'neighbor {} description {}'".format(self.bgp_asn, key, data['name']) + self.__run_command(command) + if data.has_key('admin_status'): + command_mod = 'no ' if data['admin_status'] == 'up' else '' + command = "vtysh -c 'configure terminal' -c 'router bgp {}' -c '{}neighbor {} shutdown'".format(self.bgp_asn, command_mod, key) + self.__run_command(command) + self.bgp_neighbor[key] = data + + def start(self): + self.config_db.subscribe('BGP_NEIGHBOR', + lambda table, key, data: self.bgp_handler(key, data)) + self.config_db.subscribe('DEVICE_METADATA', + lambda table, key, data: self.metadata_handler(key, data)) + self.config_db.listen() + + +def main(): + daemon = BGPConfigDaemon() + daemon.start() + +if __name__ == "__main__": + main() diff --git a/platform/vs/docker-sonic-vs/bgpd.conf.j2 b/platform/vs/docker-sonic-vs/bgpd.conf.j2 new file mode 100644 index 000000000000..ee3aba2c23c3 --- /dev/null +++ b/platform/vs/docker-sonic-vs/bgpd.conf.j2 @@ -0,0 +1,134 @@ +! +{% block banner %} +! =========== Managed by sonic-cfggen DO NOT edit manually! ==================== +! generated by templates/quagga/bgpd.conf.j2 with config DB data +! file: bgpd.conf +! +{% endblock banner %} +! +{% block system_init %} +hostname {{ DEVICE_METADATA['localhost']['hostname'] }} +password zebra +log syslog informational +log facility local4 +! enable password {# {{ en_passwd }} TODO: param needed #} +{% endblock system_init %} +! +{% if DEVICE_METADATA['localhost'].has_key('bgp_asn') %} +{% block bgp_init %} +! +! bgp multiple-instance +! +route-map FROM_BGP_SPEAKER_V4 permit 10 +! +route-map TO_BGP_SPEAKER_V4 deny 10 +! +router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }} + bgp log-neighbor-changes + bgp bestpath as-path multipath-relax + no bgp default ipv4-unicast +{# Advertise graceful restart capability for ToR #} +{% if DEVICE_METADATA['localhost']['type'] == 'ToRRouter' %} + bgp graceful-restart +{% endif %} +{% for (name, prefix) in LOOPBACK_INTERFACE %} +{% if prefix | ipv4 and name == 'Loopback0' %} + bgp router-id {{ prefix | ip }} +{% endif %} +{% endfor %} +{# advertise loopback #} +{% for (name, prefix) in LOOPBACK_INTERFACE %} +{% if prefix | ipv4 and name == 'Loopback0' %} + network {{ prefix | ip }}/32 +{% elif prefix | ipv6 and name == 'Loopback0' %} + address-family ipv6 + network {{ prefix | ip }}/64 + exit-address-family +{% endif %} +{% endfor %} +{% endblock bgp_init %} +{% endif %} +{% block vlan_advertisement %} +{% for (name, prefix) in VLAN_INTERFACE %} +{% if prefix | ipv4 %} + network {{ prefix }} +{% elif prefix | ipv6 %} + address-family ipv6 + network {{ prefix }} + exit-address-family +{% endif %} +{% endfor %} +{% endblock vlan_advertisement %} +{% block bgp_sessions %} +{% for neighbor_addr, bgp_session in BGP_NEIGHBOR.iteritems() %} +{% if bgp_session['asn'] | int != 0 %} + neighbor {{ neighbor_addr }} remote-as {{ bgp_session['asn'] }} + neighbor {{ neighbor_addr }} description {{ bgp_session['name'] }} +{# set the bgp neighbor timers if they have not default values #} +{% if (bgp_session['keepalive'] is defined and bgp_session['keepalive'] | int != 60) + or (bgp_session['holdtime'] is defined and bgp_session['holdtime'] | int != 180) %} + neighbor {{ neighbor_addr }} timers {{ bgp_session['keepalive'] }} {{ bgp_session['holdtime'] }} +{% endif %} +{% if bgp_session.has_key('admin_status') and bgp_session['admin_status'] == 'down' or not bgp_session.has_key('admin_status') and DEVICE_METADATA['localhost'].has_key('default_bgp_status') and DEVICE_METADATA['localhost']['default_bgp_status'] == 'down' %} + neighbor {{ neighbor_addr }} shutdown +{% endif %} +{% if neighbor_addr | ipv4 %} + address-family ipv4 +{% if DEVICE_METADATA['localhost']['type'] == 'ToRRouter' %} + neighbor {{ neighbor_addr }} allowas-in 1 +{% endif %} + neighbor {{ neighbor_addr }} activate + neighbor {{ neighbor_addr }} soft-reconfiguration inbound + maximum-paths 64 + exit-address-family +{% endif %} +{% if neighbor_addr | ipv6 %} + address-family ipv6 +{% if DEVICE_METADATA['localhost']['type'] == 'ToRRouter' %} + neighbor {{ neighbor_addr }} allowas-in 1 +{% endif %} + neighbor {{ neighbor_addr }} activate + neighbor {{ neighbor_addr }} soft-reconfiguration inbound + maximum-paths 64 + exit-address-family +{% endif %} +{% endif %} +{% endfor %} +{% endblock bgp_sessions %} +{% block bgp_peers_with_range %} +{% if BGP_PEER_RANGE %} +{% for bgp_peer in BGP_PEER_RANGE.values() %} + neighbor {{ bgp_peer['name'] }} peer-group + neighbor {{ bgp_peer['name'] }} passive + neighbor {{ bgp_peer['name'] }} remote-as {{ deployment_id_asn_map[DEVICE_METADATA['localhost']['deployment_id']] }} + neighbor {{ bgp_peer['name'] }} ebgp-multihop 255 + neighbor {{ bgp_peer['name'] }} soft-reconfiguration inbound +{% for (name, prefix) in LOOPBACK_INTERFACE %} +{% if name == 'Loopback1' %} + neighbor {{ bgp_peer['name'] }} update-source {{ prefix | ip }} +{% endif %} +{% endfor %} + neighbor {{ bgp_peer['name'] }} route-map FROM_BGP_SPEAKER_V4 in + neighbor {{ bgp_peer['name'] }} route-map TO_BGP_SPEAKER_V4 out +{% for ip_range in bgp_peer['ip_range'] %} + bgp listen range {{ip_range}} peer-group {{ bgp_peer['name'] }} +{% endfor %} + address-family ipv4 + neighbor {{ bgp_peer['name'] }} activate + maximum-paths 64 + exit-address-family + address-family ipv6 + neighbor {{ bgp_peer['name'] }} activate + maximum-paths 64 + exit-address-family +{% endfor %} +{% endif %} +{% endblock bgp_peers_with_range %} +! +{% if DEVICE_METADATA['localhost'].has_key('bgp_asn') %} +maximum-paths 64 +! +route-map ISOLATE permit 10 +set as-path prepend {{ DEVICE_METADATA['localhost']['bgp_asn'] }} +{% endif %} +! diff --git a/platform/vs/docker-sonic-vs/deployment_id_asn_map.yml b/platform/vs/docker-sonic-vs/deployment_id_asn_map.yml new file mode 100644 index 000000000000..36168f828954 --- /dev/null +++ b/platform/vs/docker-sonic-vs/deployment_id_asn_map.yml @@ -0,0 +1,2 @@ +deployment_id_asn_map: + "1" : 65432 diff --git a/platform/vs/docker-sonic-vs/interfaces.j2 b/platform/vs/docker-sonic-vs/interfaces.j2 new file mode 100644 index 000000000000..da2499ee5047 --- /dev/null +++ b/platform/vs/docker-sonic-vs/interfaces.j2 @@ -0,0 +1,66 @@ +# +{% block banner %} +# =============== Managed by SONiC Config Engine DO NOT EDIT! =============== +# generated from /usr/share/sonic/templates/interfaces.j2 using sonic-cfggen +# file: /etc/network/interfaces +# +{% endblock banner %} +{% block loopback %} +# The loopback network interface +auto lo +iface lo inet loopback +# Use command 'ip addr list dev lo' to check all addresses +{% for (name, prefix) in LOOPBACK_INTERFACE %} +iface lo {{ 'inet' if prefix | ipv4 else 'inet6' }} static + address {{ prefix | ip }} + netmask {{ prefix | netmask if prefix | ipv4 else prefix | prefixlen }} +# +{% endfor %} +{% endblock loopback %} +{% block mgmt_interface %} + +# The management network interface +auto eth0 +{% if MGMT_INTERFACE %} +{% for (name, prefix) in MGMT_INTERFACE %} +iface eth0 {{ 'inet' if prefix | ipv4 else 'inet6' }} static + address {{ prefix | ip }} + netmask {{ prefix | netmask if prefix | ipv4 else prefix | prefixlen }} + ########## management network policy routing rules + # management port up rules + up ip {{ '-4' if prefix | ipv4 else '-6' }} route add default via {{ MGMT_INTERFACE[(name, prefix)]['gwaddr'] }} dev eth0 table default + up ip {{ '-4' if prefix | ipv4 else '-6' }} route add {{ prefix | network }}/{{ prefix | prefixlen }} dev eth0 table default + up ip {{ '-4' if prefix | ipv4 else '-6' }} rule add from {{ prefix | ip }}/{{ '32' if prefix | ipv4 else '128' }} table default +{% for route in MGMT_INTERFACE[(name, prefix)]['forced_mgmt_routes'] %} + up ip rule add to {{ route }} table default +{% endfor %} + # management port down rules + down ip {{ '-4' if prefix | ipv4 else '-6' }} route delete default via {{ MGMT_INTERFACE[(name, prefix)]['gwaddr'] }} dev eth0 table default + down ip {{ '-4' if prefix | ipv4 else '-6' }} route delete {{ prefix | network }}/{{ prefix | prefixlen }} dev eth0 table default + down ip {{ '-4' if prefix | ipv4 else '-6' }} rule delete from {{ prefix | ip }}/{{ '32' if prefix | ipv4 else '128' }} table default +{% for route in MGMT_INTERFACE[(name, prefix)]['forced_mgmt_routes'] %} + down ip rule delete to {{ route }} table default +{% endfor %} +{# TODO: COPP policy type rules #} +{% endfor %} +{% else %} +iface eth0 inet dhcp +{% endif %} +# +{% endblock mgmt_interface %} +{% block front_panel_interfaces %} +{% if PORTCHANNEL %} +# "|| true" is added to suppress the error when interface is already a member of LAG +# "ip link show | grep -q master" is added to ensure interface is enslaved +{% for pc in PORTCHANNEL.keys()|sort %} +{% for member in PORTCHANNEL[pc]['members'] %} +allow-hotplug {{ member }} +iface {{ member }} inet manual + pre-up teamdctl {{ pc }} port add {{ member }} || true + post-up ip link show {{ member }} | grep -q master && ifconfig {{ member }} up + post-down ifconfig {{ member }} down +# +{% endfor %} +{% endfor %} +{% endif %} +{% endblock front_panel_interfaces %} diff --git a/platform/vs/docker-sonic-vs/isolate.j2 b/platform/vs/docker-sonic-vs/isolate.j2 new file mode 100755 index 000000000000..cfcd023ea1f3 --- /dev/null +++ b/platform/vs/docker-sonic-vs/isolate.j2 @@ -0,0 +1,20 @@ +#!/bin/bash +## vtysh only accepts script in stdin, so cannot be directly used in shebang +## Cut the tail of this script and feed vtysh stdin +sed -n -e '9,$p' < "$0" | vtysh "$@" +## Exit with vtysh return code +exit $? + +## vtysh script start from next line, which line number MUST equal in 'sed' command above + +configure terminal + router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }} +{% for neighbor_addr in BGP_NEIGHBOR %} + neighbor {{ neighbor_addr }} route-map ISOLATE out +{% endfor %} + exit +exit + +{% for neighbor_addr in BGP_NEIGHBOR %} +clear ip bgp {{ neighbor_addr }} soft out +{% endfor %} diff --git a/platform/vs/docker-sonic-vs/minigraph.xml b/platform/vs/docker-sonic-vs/minigraph.xml new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/platform/vs/docker-sonic-vs/sonic_version.yml b/platform/vs/docker-sonic-vs/sonic_version.yml new file mode 100644 index 000000000000..9af91ff2420e --- /dev/null +++ b/platform/vs/docker-sonic-vs/sonic_version.yml @@ -0,0 +1,8 @@ +ld_version: 'refs_tags_20180324.02' +debian_version: '8.10' +kernel_version: '3.16.0-5-amd64' +asic_type: broadcom +commit_id: 'f12620c' +build_date: Tue Mar 27 01:53:07 UTC 2018 +build_number: 353 +built_by: sonicbld@jenkins-slave-phx-2 diff --git a/platform/vs/docker-sonic-vs/start.sh b/platform/vs/docker-sonic-vs/start.sh index d16e9535c218..af15d619e832 100755 --- a/platform/vs/docker-sonic-vs/start.sh +++ b/platform/vs/docker-sonic-vs/start.sh @@ -1,9 +1,15 @@ #!/bin/bash -e # generate configuration - [ -d /etc/sonic ] || mkdir -p /etc/sonic +# Set correct platform string +HWSKU=$(sonic-cfggen -m -v DEVICE_METADATA.localhost.hwsku) +platform=$(find /usr/share/sonic/device -name $HWSKU | sed 's/.*\(x86.*\)\/.*/\1/') + +mkdir -p /host +echo "onie_platform=$platform" > /host/machine.conf + SYSTEM_MAC_ADDRESS=$(ip link show eth0 | grep ether | awk '{print $2}') sonic-cfggen -a '{"DEVICE_METADATA":{"localhost": {"mac": "'$SYSTEM_MAC_ADDRESS'"}}}' --print-data > /etc/sonic/init_cfg.json @@ -28,6 +34,22 @@ supervisorctl start redis-server /usr/bin/configdb-load.sh +# load configuration from minigraph +if [ -r /etc/sonic/minigraph.xml ]; then + sonic-cfggen -m -H --write-to-db +fi + +# from interfaces-config.sh +# not adding usb0 interface for bfn platform +# to add support for ipv6 +sysctl -w net.ipv6.conf.all.disable_ipv6=0 +ifdown --force eth0 +sonic-cfggen -d -t /usr/share/sonic/templates/interfaces.j2 > /etc/network/interfaces +[ -f /var/run/dhclient.eth0.pid ] && kill `cat /var/run/dhclient.eth0.pid` && rm -f /var/run/dhclient.eth0.pid +service networking restart +ifdown lo && ifup lo +# + supervisorctl start syncd supervisorctl start orchagent @@ -40,7 +62,8 @@ supervisorctl start neighsyncd supervisorctl start teamsyncd -supervisorctl start fpmsyncd +# started by quagga below +# supervisorctl start fpmsyncd supervisorctl start portmgrd @@ -48,7 +71,8 @@ supervisorctl start intfmgrd supervisorctl start vlanmgrd -supervisorctl start zebra +# started by quagga below +# supervisorctl start zebra supervisorctl start buffermgrd @@ -57,3 +81,78 @@ VLAN=`sonic-cfggen -d -v 'VLAN.keys() | join(" ") if VLAN'` if [ "$VLAN" != "" ]; then supervisorctl start arp_update fi + + +# from teamd start.sh + +TEAMD_CONF_PATH=/etc/teamd + +rm -rf $TEAMD_CONF_PATH +mkdir -p $TEAMD_CONF_PATH + +SONIC_ASIC_TYPE=$(sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type) + +if [ "$SONIC_ASIC_TYPE" == "mellanox" ]; then + MAC_ADDRESS=$(sonic-cfggen -d -v DEVICE_METADATA.localhost.mac) +else + MAC_ADDRESS=$(ip link show eth0 | grep ether | awk '{print $2}') +fi + +# Align last byte +if [ "$SONIC_ASIC_TYPE" == "mellanox" -o "$SONIC_ASIC_TYPE" == "centec" ]; then + last_byte=$(python -c "print '$MAC_ADDRESS'[-2:]") + aligned_last_byte=$(python -c "print format(int(int('$last_byte', 16) & 0b11000000), '02x')") # put mask and take away the 0x prefix + MAC_ADDRESS=$(python -c "print '$MAC_ADDRESS'[:-2] + '$aligned_last_byte'") # put aligned byte into the end of MAC +fi + +for pc in `sonic-cfggen -d -v "PORTCHANNEL.keys() | join(' ') if PORTCHANNEL"`; do + sonic-cfggen -d -a '{"pc":"'$pc'","hwaddr":"'$MAC_ADDRESS'"}' -t /usr/share/sonic/templates/teamd.j2 > $TEAMD_CONF_PATH/$pc.conf + # bring down all member ports before starting teamd + for member in $(sonic-cfggen -d -v "PORTCHANNEL['$pc']['members'] | join(' ')" ); do + if [ -L /sys/class/net/$member ]; then + ip link set $member down + fi + done +done + +mkdir -p /var/sonic +echo "# Config files managed by sonic-config-engine" > /var/sonic/config_status + +#rsyslog already included above +#rm -f /var/run/rsyslogd.pid +#supervisorctl start rsyslogd + +supervisorctl start teamd +# + +# from quagga start.sh +mkdir -p /etc/quagga +sonic-cfggen -d -y /etc/sonic/deployment_id_asn_map.yml -t /usr/share/sonic/templates/bgpd.conf.j2 > /etc/quagga/bgpd.conf +sonic-cfggen -d -t /usr/share/sonic/templates/zebra.conf.j2 > /etc/quagga/zebra.conf + +sonic-cfggen -d -t /usr/share/sonic/templates/isolate.j2 > /usr/sbin/bgp-isolate +chown root:root /usr/sbin/bgp-isolate +chmod 0755 /usr/sbin/bgp-isolate + +sonic-cfggen -d -t /usr/share/sonic/templates/unisolate.j2 > /usr/sbin/bgp-unisolate +chown root:root /usr/sbin/bgp-unisolate +chmod 0755 /usr/sbin/bgp-unisolate + +mkdir -p /var/sonic +echo "# Config files managed by sonic-config-engine" > /var/sonic/config_status + +# rm -f /var/run/rsyslogd.pid + +supervisorctl start bgpcfgd + +# started already +# supervisorctl start rsyslogd + +# Start Quagga processes + +supervisorctl start zebra + +supervisorctl start bgpd + +supervisorctl start fpmsyncd + diff --git a/platform/vs/docker-sonic-vs/supervisord.conf b/platform/vs/docker-sonic-vs/supervisord.conf index 1f6dfad60cf0..4700ba8b343b 100644 --- a/platform/vs/docker-sonic-vs/supervisord.conf +++ b/platform/vs/docker-sonic-vs/supervisord.conf @@ -138,3 +138,20 @@ autostart=false autorestart=false stdout_logfile=syslog stderr_logfile=syslog + +[program:bgpcfgd] +command=/usr/bin/bgpcfgd +priority=2 +autostart=false +autorestart=false +startsecs=0 +stdout_logfile=syslog +stderr_logfile=syslog + +[program:teamd] +command=/usr/bin/teamd.sh +priority=3 +autostart=false +autorestart=false +stdout_logfile=syslog +stderr_logfile=syslog diff --git a/platform/vs/docker-sonic-vs/teamd.j2 b/platform/vs/docker-sonic-vs/teamd.j2 new file mode 100644 index 000000000000..9f53534a808b --- /dev/null +++ b/platform/vs/docker-sonic-vs/teamd.j2 @@ -0,0 +1,25 @@ +{ + "device": "{{ pc }}", + "hwaddr": "{{ hwaddr }}", + "runner": { + "name": "lacp", + "active": true, +{% if PORTCHANNEL[pc]['fallback'] and ((PORTCHANNEL[pc]['members'] | length) == 1) %} + "fallback": {{ PORTCHANNEL[pc]['fallback'] }}, +{% else %} +{# Use 75% links upperbound as min-links #} + "min_ports": {{ (PORTCHANNEL[pc]['members'] | length * 0.75) | round(0, 'ceil') | int }}, +{% endif %} + "tx_hash": ["eth", "ipv4", "ipv6"] + }, + "link_watch": { + "name": "ethtool" + }, + "ports": { +{% for member in PORTCHANNEL[pc]['members'] %} + "{{ member }}": {}{% if not loop.last %},{% endif %} + +{% endfor %} + } +} + diff --git a/platform/vs/docker-sonic-vs/teamd.sh b/platform/vs/docker-sonic-vs/teamd.sh new file mode 100755 index 000000000000..2b6d9fb53970 --- /dev/null +++ b/platform/vs/docker-sonic-vs/teamd.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +TEAMD_CONF_PATH=/etc/teamd + +function start_app { + rm -f /var/run/teamd/* + if [ "$(ls -A $TEAMD_CONF_PATH)" ]; then + for f in $TEAMD_CONF_PATH/*; do + teamd -f $f -d + done + fi + teamsyncd & +} + +function clean_up { + if [ "$(ls -A $TEAMD_CONF_PATH)" ]; then + for f in $TEAMD_CONF_PATH/*; do + teamd -f $f -k + done + fi + pkill -9 teamsyncd + exit +} + +trap clean_up SIGTERM SIGKILL + +start_app +read diff --git a/platform/vs/docker-sonic-vs/unisolate.j2 b/platform/vs/docker-sonic-vs/unisolate.j2 new file mode 100755 index 000000000000..2a0780745d75 --- /dev/null +++ b/platform/vs/docker-sonic-vs/unisolate.j2 @@ -0,0 +1,20 @@ +#!/bin/bash +## vtysh only accepts script in stdin, so cannot be directly used in shebang +## Cut the tail of this script and feed vtysh stdin +sed -n -e '9,$p' < "$0" | vtysh "$@" +## Exit with vtysh return code +exit $? + +## vtysh script start from next line, which line number MUST equal in 'sed' command above + +configure terminal + router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }} +{% for neighbor_ip in BGP_NEIGHBOR %} + no neighbor {{ neighbor_ip }} route-map ISOLATE out +{% endfor %} + exit +exit + +{% for neighbor_ip in BGP_NEIGHBOR %} +clear ip bgp {{ neighbor_ip }} soft out +{% endfor %} diff --git a/platform/vs/docker-sonic-vs/zebra.conf.j2 b/platform/vs/docker-sonic-vs/zebra.conf.j2 new file mode 100644 index 000000000000..e4586e72dd62 --- /dev/null +++ b/platform/vs/docker-sonic-vs/zebra.conf.j2 @@ -0,0 +1,76 @@ +! +{% block banner %} +! =========== Managed by sonic-cfggen DO NOT edit manually! ==================== +! generated by templates/quagga/zebra.conf.j2 using config DB data +! file: zebra.conf +! +{% endblock banner %} +! +{% block sys_init %} +hostname {{ DEVICE_METADATA['localhost']['hostname'] }} +password zebra +enable password zebra +{% endblock sys_init %} +! +{% block interfaces %} +! Enable link-detect (default disabled) +{% for (name, prefix) in INTERFACE %} +interface {{ name }} +link-detect +! +{% endfor %} +{% for pc in PORTCHANNEL %} +interface {{ pc }} +link-detect +! +{% endfor %} +{% endblock interfaces %} +! +{% block default_route %} +! set static default route to mgmt gateway as a backup to learned default +{% for (name, prefix) in MGMT_INTERFACE %} +{% if prefix | ipv4 %} +ip route 0.0.0.0/0 {{ MGMT_INTERFACE[(name, prefix)]['gwaddr'] }} 200 +{% endif %} +{% endfor %} +{% endblock default_route %} +! +{% block source_loopback %} +{% set lo_ipv4_addrs = [] %} +{% set lo_ipv6_addrs = [] %} +{% if LOOPBACK_INTERFACE %} +{% for (name, prefix) in LOOPBACK_INTERFACE %} +{% if name == 'Loopback0' %} +{% if prefix | ipv6 %} +{% if lo_ipv6_addrs.append(prefix) %} +{% endif %} +{% else %} +{% if lo_ipv4_addrs.append(prefix) %} +{% endif %} +{% endif %} +{% endif %} +{% endfor %} +{% endif %} +! Set ip source to loopback for bgp learned routes +route-map RM_SET_SRC permit 10 + set src {{ lo_ipv4_addrs[0] | ip }} +! +{% if lo_ipv6_addrs|length > 0 %} +route-map RM_SET_SRC6 permit 10 + set src {{ lo_ipv6_addrs[0] | ip }} +! +{% endif %} +ip protocol bgp route-map RM_SET_SRC +! +{% if lo_ipv6_addrs|length > 0 %} +ipv6 protocol bgp route-map RM_SET_SRC6 +! +{% endif %} +{% endblock source_loopback %} +! +{% block logging %} +log syslog informational +log facility local4 +{% endblock logging %} +! +