Skip to content

Commit

Permalink
[vs]: build sonic vs kvm image (#2269)
Browse files Browse the repository at this point in the history
Signed-off-by: Guohan Lu <gulv@microsoft.com>
  • Loading branch information
lguohan authored Nov 21, 2018
1 parent 465ebba commit 64a2b1c
Show file tree
Hide file tree
Showing 40 changed files with 1,275 additions and 97 deletions.
2 changes: 1 addition & 1 deletion build_debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/hooks/union-fsck
pushd $FILESYSTEM_ROOT/usr/share/initramfs-tools/scripts/init-bottom && sudo patch -p1 < $OLDPWD/files/initramfs-tools/udev.patch; popd

## Install latest intel ixgbe driver
sudo cp target/debs/ixgbe.ko $FILESYSTEM_ROOT/lib/modules/${LINUX_KERNEL_VERSION}-amd64/kernel/drivers/net/ethernet/intel/ixgbe/ixgbe.ko
sudo cp target/files/ixgbe.ko $FILESYSTEM_ROOT/lib/modules/${LINUX_KERNEL_VERSION}-amd64/kernel/drivers/net/ethernet/intel/ixgbe/ixgbe.ko

## Install docker
echo '[INFO] Install docker'
Expand Down
26 changes: 25 additions & 1 deletion build_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,30 @@ elif [ "$IMAGE_TYPE" = "raw" ]; then
mv $OUTPUT_RAW_IMAGE.gz $OUTPUT_RAW_IMAGE
echo "The compressed raw image is in $OUTPUT_RAW_IMAGE"

elif [ "$IMAGE_TYPE" = "kvm" ]; then

echo "Build KVM image"
KVM_IMAGE_DISK=${OUTPUT_KVM_IMAGE%.gz}
sudo rm -f $KVM_IMAGE_DISK $KVM_IMAGE_DISK.gz

generate_onie_installer_image

SONIC_USERNAME=$USERNAME PASSWD=$PASSWORD sudo -E ./build_kvm_image.sh $KVM_IMAGE_DISK $onie_recovery_image $OUTPUT_ONIE_IMAGE $KVM_IMAGE_DISK_SIZE

[ -r $KVM_IMAGE_DISK ] || {
echo "Error : $KVM_IMAGE_DISK not generated!"
exit 1
}

gzip $KVM_IMAGE_DISK

[ -r $KVM_IMAGE_DISK.gz ] || {
echo "Error : gzip $KVM_IMAGE_DISK failed!"
exit 1
}

echo "The compressed kvm image is in $KVM_IMAGE_DISK.gz"

## Use 'aboot' as target machine category which includes Aboot as bootloader
elif [ "$IMAGE_TYPE" = "aboot" ]; then
echo "Build Aboot installer"
Expand Down Expand Up @@ -104,6 +128,6 @@ elif [ "$IMAGE_TYPE" = "aboot" ]; then
zip -g $OUTPUT_ABOOT_IMAGE $ABOOT_BOOT_IMAGE
rm $ABOOT_BOOT_IMAGE
else
echo "Error: Non supported target platform: $TARGET_PLATFORM"
echo "Error: Non supported image type $IMAGE_TYPE"
exit 1
fi
77 changes: 77 additions & 0 deletions build_kvm_image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/sh -ex

# Copyright (C) 2014 Curt Brune <curt@cumulusnetworks.com>
#
# SPDX-License-Identifier: GPL-2.0

MEM=2048
DISK=$1
ONIE_RECOVERY_ISO=$2
INSTALLER=$3
DISK_SIZE=$4

INSTALLER_DISK="./sonic-installer.img"

# VM will listen on telnet port $KVM_PORT
KVM_PORT=9000

on_exit()
{
rm -f $kvm_log
}

kvm_log=$(mktemp)
trap on_exit EXIT

create_disk()
{
echo "Creating SONiC kvm disk : $DISK of size $DISK_SIZE GB"
qemu-img create -f qcow2 $DISK ${DISK_SIZE}G
}

prepare_installer_disk()
{
fallocate -l 1024M $INSTALLER_DISK

mkfs.vfat $INSTALLER_DISK

tmpdir=$(mktemp -d)

mount -o loop $INSTALLER_DISK $tmpdir

cp $INSTALLER $tmpdir/onie-installer.bin

umount $tmpdir
}

create_disk
prepare_installer_disk

/usr/bin/kvm -m $MEM \
-name "onie" \
-boot "order=cd,once=d" -cdrom "$ONIE_RECOVERY_ISO" \
-device e1000,netdev=onienet \
-netdev user,id=onienet,hostfwd=:0.0.0.0:3041-:22 \
-vnc 0.0.0.0:0 \
-vga std \
-drive file=$DISK,media=disk,if=virtio,index=0 \
-drive file=$INSTALLER_DISK,if=virtio,index=1 \
-serial telnet:localhost:$KVM_PORT,server > $kvm_log 2>&1 &

kvm_pid=$!

sleep 2.0

[ -d "/proc/$kvm_pid" ] || {
echo "ERROR: kvm died."
cat $kvm_log
exit 1
}

echo "to kill kvm: sudo kill $kvm_pid"

./check_install.py -u $SONIC_USERNAME -P $PASSWD -p $KVM_PORT

kill $kvm_pid

exit 0
54 changes: 54 additions & 0 deletions check_install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python

import pexpect
import argparse
import sys
import time

def main():

parser = argparse.ArgumentParser(description='test_login cmdline parser')
parser.add_argument('-u', default="admin", help='login user name')
parser.add_argument('-P', default="YourPaSsWoRd", help='login password')
parser.add_argument('-p', type=int, default=9000, help='local port')

args = parser.parse_args()

KEY_UP = '\x1b[A'
KEY_DOWN = '\x1b[B'
KEY_RIGHT = '\x1b[C'
KEY_LEFT = '\x1b[D'

login_prompt = 'sonic login:'
passwd_prompt = 'Password:'
cmd_prompt = "%s@sonic:~\$ $" % args.u
grub_selection = "The highlighted entry will be executed"

p = pexpect.spawn("telnet 127.0.0.1 %s" % args.p, timeout=600, logfile=sys.stdout)

# select ONIE embed
p.expect(grub_selection)
p.sendline(KEY_DOWN)

# install sonic image
while True:
i = p.expect([login_prompt, passwd_prompt, grub_selection, cmd_prompt])
if i == 0:
# send user name
p.sendline(args.u)
elif i == 1:
# send password
p.sendline(args.P)
elif i == 2:
# select onie install
p.sendline()
else:
break

# check version
time.sleep(5)
p.sendline('show version')
p.expect([cmd_prompt])

if __name__ == '__main__':
main()
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{# Default values which will be used if no actual configura available #}
{% set default_cable = '300m' %}
{% set default_speed = '100G' %}
{% set default_ports_num = 32 -%}

{# Port configuration to cable length look-up table #}
Expand Down Expand Up @@ -66,97 +67,62 @@
{% endfor %}
}
},
{%if switch_role == 'ToRRouter' %}
{% set ingress_lossless_pool_size = '4194304' %}
{% set ingress_lossy_pool_size = '7340032' %}
{% set egress_lossless_pool_size = '16777152' %}
{% set egress_lossy_pool_size = '7340032' %}
{% else %}
{% set ingress_lossless_pool_size = '2097152' %}
{% set ingress_lossy_pool_size = '5242880' %}
{% set egress_lossless_pool_size = '16777152' %}
{% set egress_lossy_pool_size = '5242880' %}
{%endif %}
"BUFFER_POOL": {
"ingress_lossless_pool": {
"size": "{{ ingress_lossless_pool_size }}",
"type": "ingress",
"mode": "dynamic"
},
"ingress_lossy_pool": {
"size": "{{ ingress_lossy_pool_size }}",
"size": "12766208",
"type": "ingress",
"mode": "dynamic"
},
"egress_lossless_pool": {
"size": "{{ egress_lossless_pool_size }}",
"size": "12766208",
"type": "egress",
"mode": "dynamic"
"mode": "static"
},
"egress_lossy_pool": {
"size": "{{ egress_lossy_pool_size }}",
"size": "8072396",
"type": "egress",
"mode": "dynamic"
}
},
"BUFFER_PROFILE": {
"ingress_lossless_profile": {
"pool":"[BUFFER_POOL|ingress_lossless_pool]",
"size":"0",
"dynamic_th":"0"
"xon":"18432",
"xoff":"40560",
"size":"41808",
"dynamic_th":"-4",
"xon_offset":"2496"
},
"ingress_lossy_profile": {
"pool":"[BUFFER_POOL|ingress_lossy_pool]",
"pool":"[BUFFER_POOL|ingress_lossless_pool]",
"size":"0",
"dynamic_th":"3"
},
"egress_lossless_profile": {
"pool":"[BUFFER_POOL|egress_lossless_pool]",
"size":"0",
"dynamic_th":"7"
"static_th":"12766208"
},
"egress_lossy_profile": {
"pool":"[BUFFER_POOL|egress_lossy_pool]",
"size":"4096",
"dynamic_th":"3"
},
"pg_lossy_profile": {
"pool":"[BUFFER_POOL|ingress_lossy_pool]",
"size":"0",
"dynamic_th":"3"
},
"q_lossless_profile": {
"pool":"[BUFFER_POOL|egress_lossless_pool]",
"size":"0",
"dynamic_th":"7"
},
"q_lossy_profile": {
"pool":"[BUFFER_POOL|egress_lossy_pool]",
"size":"0",
"size":"1518",
"dynamic_th":"3"
}
},
"BUFFER_PORT_INGRESS_PROFILE_LIST": {
"{{ port_names }}": {
"profile_list" : "[BUFFER_PROFILE|ingress_lossless_profile],[BUFFER_PROFILE|ingress_lossy_profile]"
}
},
"BUFFER_PORT_EGRESS_PROFILE_LIST": {
"{{ port_names }}": {
"profile_list" : "[BUFFER_PROFILE|egress_lossless_profile],[BUFFER_PROFILE|egress_lossy_profile]"
}
},
"BUFFER_PG": {
"{{ port_names }}|3-4": {
"profile" : "[BUFFER_PROFILE|ingress_lossless_profile]"
},
"{{ port_names }}|0-1": {
"profile" : "[BUFFER_PROFILE|pg_lossy_profile]"
"profile" : "[BUFFER_PROFILE|ingress_lossy_profile]"
}
},
"BUFFER_QUEUE": {
"{{ port_names }}|3-4": {
"profile" : "[BUFFER_PROFILE|q_lossless_profile]"
"profile" : "[BUFFER_PROFILE|egress_lossless_profile]"
},
"{{ port_names }}|0-1": {
"profile" : "[BUFFER_PROFILE|q_lossy_profile]"
"profile" : "[BUFFER_PROFILE|egress_lossy_profile]"
}
}
}
34 changes: 34 additions & 0 deletions device/virtual/x86_64-kvm_x86_64-r0/Force10-S6000/lanemap.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
; comment
# comment
eth1:29,30,31,32
eth2:25,26,27,28
eth3:37,38,39,40
eth4:33,34,35,36
eth5:41,42,43,44
eth6:45,46,47,48
eth7:5,6,7,8
eth8:1,2,3,4
eth9:9,10,11,12
eth10:13,14,15,16
eth11:21,22,23,24
eth12:17,18,19,20
eth13:49,50,51,52
eth14:53,54,55,56
eth15:61,62,63,64
eth16:57,58,59,60
eth17:65,66,67,68
eth18:69,70,71,72
eth19:77,78,79,80
eth20:73,74,75,76
eth21:105,106,107,108
eth22:109,110,111,112
eth23:117,118,119,120
eth24:113,114,115,116
eth25:121,122,123,124
eth26:125,126,127,128
eth27:85,86,87,88
eth28:81,82,83,84
eth29:89,90,91,92
eth30:93,94,95,96
eth31:97,98,99,100
eth32:101,102,103,104
33 changes: 33 additions & 0 deletions device/virtual/x86_64-kvm_x86_64-r0/Force10-S6000/port_config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# name lanes alias
Ethernet0 29,30,31,32 fortyGigE0/0
Ethernet4 25,26,27,28 fortyGigE0/4
Ethernet8 37,38,39,40 fortyGigE0/8
Ethernet12 33,34,35,36 fortyGigE0/12
Ethernet16 41,42,43,44 fortyGigE0/16
Ethernet20 45,46,47,48 fortyGigE0/20
Ethernet24 5,6,7,8 fortyGigE0/24
Ethernet28 1,2,3,4 fortyGigE0/28
Ethernet32 9,10,11,12 fortyGigE0/32
Ethernet36 13,14,15,16 fortyGigE0/36
Ethernet40 21,22,23,24 fortyGigE0/40
Ethernet44 17,18,19,20 fortyGigE0/44
Ethernet48 49,50,51,52 fortyGigE0/48
Ethernet52 53,54,55,56 fortyGigE0/52
Ethernet56 61,62,63,64 fortyGigE0/56
Ethernet60 57,58,59,60 fortyGigE0/60
Ethernet64 65,66,67,68 fortyGigE0/64
Ethernet68 69,70,71,72 fortyGigE0/68
Ethernet72 77,78,79,80 fortyGigE0/72
Ethernet76 73,74,75,76 fortyGigE0/76
Ethernet80 105,106,107,108 fortyGigE0/80
Ethernet84 109,110,111,112 fortyGigE0/84
Ethernet88 117,118,119,120 fortyGigE0/88
Ethernet92 113,114,115,116 fortyGigE0/92
Ethernet96 121,122,123,124 fortyGigE0/96
Ethernet100 125,126,127,128 fortyGigE0/100
Ethernet104 85,86,87,88 fortyGigE0/104
Ethernet108 81,82,83,84 fortyGigE0/108
Ethernet112 89,90,91,92 fortyGigE0/112
Ethernet116 93,94,95,96 fortyGigE0/116
Ethernet120 97,98,99,100 fortyGigE0/120
Ethernet124 101,102,103,104 fortyGigE0/124
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{%- include 'qos_config.j2' %}
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ SAI_WARM_BOOT_READ_FILE=/var/cache/sai_warmboot.bin
SAI_WARM_BOOT_WRITE_FILE=/var/cache/sai_warmboot.bin
SAI_VS_SWITCH_TYPE=SAI_VS_SWITCH_TYPE_BCM56850
SAI_VS_HOSTIF_USE_TAP_DEVICE=true
SAI_VS_INTERFACE_LANE_MAP_FILE=/usr/share/sonic/hwsku/lanemap.ini
Loading

0 comments on commit 64a2b1c

Please sign in to comment.