@@ -33,11 +33,12 @@ def is_mount_needed(virt_io, vmid):
33
33
return False
34
34
35
35
36
- def tap_uos_net (names , vmid , config ):
36
+ def tap_uos_net (names , virt_io , vmid , config ):
37
37
uos_type = names ['uos_types' ][vmid ]
38
38
board_name = names ['board_name' ]
39
39
40
40
vm_name = launch_cfg_lib .undline_name (uos_type ).lower ()
41
+
41
42
if uos_type in ("CLEARLINUX" , "ANDROID" , "ALIOS" ):
42
43
if board_name in ("apl-mrb" , "apl-up2" ):
43
44
print ('if [ ! -f "/data/{}/{}.img" ]; then' .format (vm_name , vm_name ), file = config )
@@ -54,26 +55,13 @@ def tap_uos_net(names, vmid, config):
54
55
if uos_type in ("VXWORKS" , "ZEPHYR" , "WINDOWS" , "PREEMPT-RT LINUX" ):
55
56
print ("vm_name={}_vm$1" .format (vm_name ), file = config )
56
57
57
- if uos_type in ("CLEARLINUX" , "ANDROID" , "ALIOS" ):
58
- if board_name in ("apl-mrb" , "apl-up2" ):
59
- print ("# create a unique tap device for each VM" , file = config )
60
- print ("tap=tap_$3" , file = config )
61
- print ('tap_exist=$(ip a | grep "$tap" | awk \' {print $1}\' )' , file = config )
62
- print ('if [ "$tap_exist"x != "x" ]; then' , file = config )
63
- print (' echo "tap device existed, reuse $tap"' , file = config )
64
- print ("else" , file = config )
65
- print (" ip tuntap add dev $tap mode tap" , file = config )
66
- print ("fi" , file = config )
67
- print ("" , file = config )
68
- print ("# if acrn-br0 exists, add VM's unique tap device under it" , file = config )
69
- print ("br_exist=$(ip a | grep acrn-br0 | awk '{print $1}')" , file = config )
70
- print ('if [ "$br_exist"x != "x" -a "$tap_exist"x = "x" ]; then' , file = config )
71
- print (' echo "acrn-br0 bridge aleady exists, adding new tap device to it..."' , file = config )
72
- print (' ip link set "$tap" master acrn-br0' , file = config )
73
- print (' ip link set dev "$tap" down' , file = config )
74
- print (' ip link set dev "$tap" up' , file = config )
75
- print ("fi" , file = config )
76
- print ("" , file = config )
58
+ for net in virt_io ['network' ][vmid ]:
59
+ if net :
60
+ net_name = net
61
+ if ',' in net :
62
+ net_name = net .split (',' )[0 ]
63
+ print ("tap_net {}" .format (net_name ), file = config )
64
+
77
65
print ("#check if the vm is running or not" , file = config )
78
66
print ("vm_ps=$(pgrep -a -f acrn-dm)" , file = config )
79
67
print ('result=$(echo $vm_ps | grep -w "${vm_name}")' , file = config )
@@ -252,9 +240,44 @@ def log_level_set(uos_type, config):
252
240
print ('logger_setting="--logger_setting console,level=4;kmsg,level=3;disk,level=5"' , file = config )
253
241
print ("" , file = config )
254
242
243
+ def tap_network (virt_io , vmid , config ):
244
+
245
+ none_i = 0
246
+ tap_net_list = virt_io ['network' ][vmid ]
247
+ for net in tap_net_list :
248
+ if net == None :
249
+ none_i += 1
250
+ tap_net_num = len (tap_net_list ) - none_i
251
+
252
+ if tap_net_num >= 1 :
253
+ print ("function tap_net() {" , file = config )
254
+ print ("# create a unique tap device for each VM" , file = config )
255
+ print ("tap=$1" , file = config )
256
+ print ('tap_exist=$(ip a | grep "$tap" | awk \' {print $1}\' )' , file = config )
257
+ print ('if [ "$tap_exist"x != "x" ]; then' , file = config )
258
+ print (' echo "tap device existed, reuse $tap"' , file = config )
259
+ print ("else" , file = config )
260
+ print (" ip tuntap add dev $tap mode tap" , file = config )
261
+ print ("fi" , file = config )
262
+ print ("" , file = config )
263
+ print ("# if acrn-br0 exists, add VM's unique tap device under it" , file = config )
264
+ print ("br_exist=$(ip a | grep acrn-br0 | awk '{print $1}')" , file = config )
265
+ print ('if [ "$br_exist"x != "x" -a "$tap_exist"x = "x" ]; then' , file = config )
266
+ print (' echo "acrn-br0 bridge aleady exists, adding new tap device to it..."' , file = config )
267
+ print (' ip link set "$tap" master acrn-br0' , file = config )
268
+ print (' ip link set dev "$tap" down' , file = config )
269
+ print (' ip link set dev "$tap" up' , file = config )
270
+ print ("fi" , file = config )
271
+ print ("}" , file = config )
272
+ print ("" , file = config )
273
+
274
+
275
+ def launch_begin (names , virt_io , vmid , config ):
276
+ board_name = names ['board_name' ]
277
+ uos_type = names ['uos_types' ][vmid ]
255
278
256
- def launch_begin (board_name , uos_type , config ):
257
279
launch_uos = launch_cfg_lib .undline_name (uos_type ).lower ()
280
+ tap_network (virt_io , vmid , config )
258
281
run_container (board_name , uos_type , config )
259
282
print ("function launch_{}()" .format (launch_uos ), file = config )
260
283
print ("{" , file = config )
@@ -434,6 +457,14 @@ def virtio_args_set(dm, virt_io, vmid, config):
434
457
if blk :
435
458
print (" -s {},virtio-blk,{} \\ " .format (launch_cfg_lib .virtual_dev_slot ("virtio-blk{}" .format (blk )), blk .strip (':' )), file = config )
436
459
460
+ # virtio-net set, the value type is a list
461
+ for net in virt_io ['network' ][vmid ]:
462
+ if net :
463
+ net_name = net
464
+ if ',' in net :
465
+ net_name = net .split (',' )[0 ]
466
+ print (" -s {},virtio-net,{} \\ " .format (launch_cfg_lib .virtual_dev_slot ("virtio-net{}" .format (net )), net_name ), file = config )
467
+
437
468
438
469
def dm_arg_set (names , sel , virt_io , dm , vmid , config ):
439
470
@@ -473,7 +504,6 @@ def dm_arg_set(names, sel, virt_io, dm, vmid, config):
473
504
print (" --pm_notify_channel uart \\ " , file = config )
474
505
print (' --pm_by_vuart pty,/run/acrn/life_mngr_$vm_name \\ ' , file = config )
475
506
print (' -l com2,/run/acrn/life_mngr_$vm_name \\ ' , file = config )
476
- print (" -s {},virtio-net,tap0 \\ " .format (launch_cfg_lib .virtual_dev_slot ("virtio-net" )), file = config )
477
507
478
508
# mac_seed
479
509
if uos_type in ("CLEARLINUX" , "ANDROID" , "ALIOS" ):
@@ -525,10 +555,6 @@ def dm_arg_set(names, sel, virt_io, dm, vmid, config):
525
555
launch_cfg_lib .virtual_dev_slot ("virtio-console(hvc0)" ),
526
556
launch_cfg_lib .RE_CONSOLE_MAP ['virtio-console(hvc0)' ]), file = config )
527
557
528
- if uos_type in ("CLEARLINUX" , "ANDROID" , "ALIOS" ):
529
- if board_name in ("apl-mrb" , "apl-up2" ):
530
- print (" -s {},virtio-net,$tap \\ " .format (launch_cfg_lib .virtual_dev_slot ("virtio-net" )), file = config )
531
-
532
558
if uos_type in ("CLEARLINUX" , "ANDROID" , "ALIOS" ):
533
559
print (" -s {},virtio-hyper_dmabuf \\ " .format (launch_cfg_lib .virtual_dev_slot ("virtio-hyper_dmabuf" )), file = config )
534
560
if board_name == "apl-mrb" :
@@ -558,8 +584,8 @@ def gen(names, pt_sel, virt_io, dm, vmid, config):
558
584
pt .gen_pt_head (names , pt_sel , vmid , config )
559
585
560
586
# gen launch header
561
- launch_begin (board_name , uos_type , config )
562
- tap_uos_net (names , vmid , config )
587
+ launch_begin (names , virt_io , vmid , config )
588
+ tap_uos_net (names , virt_io , vmid , config )
563
589
564
590
# passthrough device
565
591
pt .gen_pt (names , pt_sel , vmid , config )
0 commit comments