(OK)(OK) seem-tools-CLI-semi-auto.sh
#!/bin/sh
#------------------------------------------------------------------------------------------
# This tool (seem-tools-CLI-semi-auto.sh) is released under GNU GPL v2,v3
# Author: Tongguang Zhang
# Date: 2016-06-18
#
# Note, Prerequisites for using this script: You have already installed Docker and NS3.
# Path in my notebook:
# NS3: /opt/tools/network_simulators/ns3/ns-allinone-3.25/
#------------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------------
# (OK)(OK)(All in CLI) Fedora23 + Docker(centos-manet) + NS3 + MANETs - testing
#------------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------------
# function create_docker()
# Description:
# create docker_node_num of dockers
# receive one parameter, that is docker_node_num
#------------------------------------------------------------------------------------------
destroy_docker(){
# docker_node_num
for((id=1; id<={id}"
tap="tap_d_{id}"
ifconfig {bridge} {bridge} &>/dev/null
ifconfig {tap} &>/dev/null
ifconfig {id}" &>/dev/null
docker rm "docker_android_node_num of dockers
# receive three parameters, that are docker_node_num, android_node_num, VM_image
#------------------------------------------------------------------------------------------
create_android(){
# 2, that is, android_node_num
# 4, that is, PATH of *.vdi
# You will also have to make sure that your kernel has ethernet filtering (ebtables, bridge-nf,
# arptables) disabled. If you do not do this, only STP and ARP traffic will be allowed to
# flow across your bridge and your whole scenario will not work.
cd /proc/sys/net/bridge
for f in bridge-nf-*; do echo 0 > 2; id++))
do
# to determine whether VM_image exists
# vm_image={id}
# exists=`VBoxManage list vms | awk -F \" '{print {vm_image} | wc -l | cat`
# if [ {vm_image} does not exist"
# exit
# fi
# SET VARIABLES
bridge="br_a_{id}"
# look at VirtualBox Gloable Setting, that is, vboxnet0: 192.168.56.1, 192.168.56.2(DHCPD), (3-254)
#host0={host0}"
#eth0_a_ip="112.26.2.{tap}
#ip link set up dev {tap} 0.0.0.0 promisc up
brctl addbr {bridge} {bridge}
ifconfig {bridge} 0.0.0.0 promisc up
# VBoxManage modifyvm android-x86_64-6.0-rc1-{bridge}
# VBoxManage startvm android-x86_64-6.0-rc1-{id}"
# VBoxManage hostonlyif create
# VBoxManage hostonlyif ipconfig vboxnet0 --ip 10.0.0.10 --netmask 255.255.255.0
# VBoxManage list hostonlyifs
# VBoxManage list dhcpservers
# VBoxManage list bridgedifs
# VBoxManage modifyvm {id} --nic1 hostonly --nictype1 Am79C973 --hostonlyadapter1 vboxnet0 --nic2 bridged --bridgeadapter2 3{bridge} --nic3 none --nic4 none
# gnome-terminal -x bash -c "VBoxManage startvm {id}"
# sleep 30
#
# adb connect {eth0_a_ip}:5555 root
# sleep 1
# adb connect {eth0_a_ip}:5555 root
# sleep 1
# adb connect {eth0_a_ip}:5555 shell mkdir -p /opt/android-on-linux/quagga/out/etc
# adb -s {eth0_a_ip}:5555 shell cp /system/xbin/quagga/etc/ospf6d.conf /opt/android-on-linux/quagga/out/etc/
# adb -s {eth0_a_ip}:5555 shell /system/xbin/quagga/ospf6d -d
# adb -s {eth0_a_ip}:5555 shell ifconfig eth1 {eth0_a_ip}:5555 shell ifconfig eth0 down
# VBoxManage createvm --name android-x86_64-6.0-rc1-1 --ostype Linux_64 --register
# VBoxManage modifyvm android-x86_64-6.0-rc1-1 --memory 1024 --vram 128 --usb off --audio pulse --audiocontroller sb16 --acpi on --rtcuseutc off --boot1 disk --boot2 dvd --nic1 hostonly --nictype1 Am79C973 --hostonlyadapter1 vboxnet0
# VBoxManage storagectl android-x86_64-6.0-rc1-1 --name "IDE Controller" --add ide --controller PIIX4
# VBoxManage storageattach android-x86_64-6.0-rc1-1 --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium android-x86_64-6.0-rc1-1.vdi
# VBoxManage startvm android-x86_64-6.0-rc1-1
echo "VBoxManage startvm {id}"
gnome-terminal -x bash -c "VBoxManage createvm --name {id} --ostype Linux_64 --register; \
VBoxManage modifyvm {id} --memory 1024 --vram 128 --usb off --audio pulse --audiocontroller sb16 --acpi on --rtcuseutc off --boot1 disk --boot2 dvd --nic1 bridged --bridgeadapter1 34/{id}.vdi; \
VBoxManage storageattach {id} --storagectl \"IDE Controller\" --port 0 --device 0 --type hdd --medium 33android_node_num of androids
# receive two parameters, that are android_node_num, VM_image
#------------------------------------------------------------------------------------------
destroy_android(){
# android_node_num
# 1; id++))
do
echo "VBoxManage controlvm {id} poweroff"
VBoxManage controlvm {id} poweroff &>/dev/null
VBoxManage unregistervm {id} &>/dev/null
rm "/root/VirtualBox VMs/{id}" -rf &>/dev/null
sleep 1
bridge="br_a_{id}"
ifconfig {bridge} {bridge} &>/dev/null
ifconfig {tap} &>/dev/null
done
}
#------------------------------------------------------------------------------------------
# usage()
# script usage
#------------------------------------------------------------------------------------------
usage(){
cat <<-EOU
Usage: seem-tools-CLI-semi-auto.sh a b c
a, the value is create or destroy
b, the number of dockers to be created
c, the number of androids to be created
Note: b + c <= 254
For example:
[root@localhost fedora23server-share]# pwd
/opt/share-vm/fedora23server-share
[root@localhost fedora23server-share]# ls seem-tools-CLI-semi-auto.sh
seem-tools-CLI-semi-auto.sh
[root@localhost fedora23server-share]#
./seem-tools-CLI-semi-auto.sh create 25 0 centos-manet android-x86_64-6.0-rc1- PATH_of_*.vdi
./seem-tools-CLI-semi-auto.sh destroy 25 0 centos-manet android-x86_64-6.0-rc1- PATH_of_*.vdi
./seem-tools-CLI-semi-auto.sh create 0 5 centos-manet android-x86_64-6.0-rc1- PATH_of_*.vdi
./seem-tools-CLI-semi-auto.sh destroy 0 5 centos-manet android-x86_64-6.0-rc1- PATH_of_*.vdi
./seem-tools-CLI-semi-auto.sh create 20 5 centos-manet android-x86_64-6.0-rc1- PATH_of_*.vdi
./seem-tools-CLI-semi-auto.sh destroy 20 5 centos-manet android-x86_64-6.0-rc1- PATH_of_*.vdi
EOU
}
#------------------------------------------------------------------------------------------
# function create_ns3_manet_seem_cc()
# receive two parameter, that is docker_node_num, android_node_num
#------------------------------------------------------------------------------------------
create_ns3_manet_seem_cc(){
echo "create seem-manet.cc from seem-manet-template.cc"
cd /opt/tools/network_simulators/ns3/ns-allinone-3.25/ns-3.25/scratch
rm seem-manet.cc -f &>/dev/null
cp seem-manet-template.cc seem-manet.cc
# after the 302 line of /opt/tools/network_simulators/ns3/ns-allinone-3.25/ns-3.25/scratch/seem-manet-template.cc
str='302a \\n '
for((id=1; id<={id}"
ns={id}\")); tapBridge.SetAttribute (\"DeviceName\", StringValue (\"{id}), adhocDevices.Get ({tap}\"));\n tapBridge.Install (adhocNodes.Get ({ns}));\n "
#inter="tapBridge.SetAttribute (\"DeviceName\", StringValue (\"{str}[1
b=[a+1]; id<={id}"
ns={host1}\")); tapBridge.SetAttribute (\"DeviceName\", StringValue (\"{id}), adhocDevices.Get ({tap}\"));\n tapBridge.Install (adhocNodes.Get ({ns}));\n "
#inter="tapBridge.SetAttribute (\"DeviceName\", StringValue (\"{str}[host1+1]
done
# sed -i '302a \\n tapBridge.SetAttribute ("DeviceName", StringValue ("tap_a_1"));\n tapBridge.Install (adhocNodes.Get (0), adhocDevices.Get (0));\n tapBridge.SetAttribute ("DeviceName", StringValue ("tap_a_2"));\n tapBridge.Install (adhocNodes.Get (0), adhocDevices.Get (0));' seem-manet.cc
sed -i "1), that is, the value is create or destroy
# para2 (3), that is, the number of androids to be created
# para4 (5), that is, VM image, such as, android-x86_64-6.0-rc1-
# para6 (id type -i 2
b=# -eq 6 ]; then
if [ 2 -lt 0 ] || [ 1 == "create" ]||[ 1 in
create)
if [ 2 3 -gt 0 ]; then create_android 3 6; fi
if [ 2 2
fi
;;
destroy)
if [ 2
rm /var/run/netns -rf &>/dev/null
fi
if [ 3 $5
ifconfig vboxnet0 down &>/dev/null
fi
;;
esac
else
usage
fi
# [root@localhost virtualbox-os]# pwd
# /run/media/root/158a840e-63fa-4544-b0b8-dc0d40c79241/virtualbox-os
# [root@localhost virtualbox-os]# ls
# android-x86_64-6.0-rc1-0.vdi android-x86_64-6.0-rc1-2.vdi android-x86_64-6.0-rc1-4.vdi
# android-x86_64-6.0-rc1-1.vdi android-x86_64-6.0-rc1-3.vdi android-x86_64-6.0-rc1-5.vdi
# [root@localhost virtualbox-os]#
#-----------------------------------------------------------------------------
# 25 docker (centos)
#-----------------------------------------------------------------------------
# systemctl start docker.service
# ./seem-tools-CLI-semi-auto.sh create 25 0 centos-manet android-x86_64-6.0-rc1- /run/media/root/158a840e-63fa-4544-b0b8-dc0d40c79241/virtualbox-os
# ./seem-tools-CLI-semi-auto.sh destroy 25 0 centos-manet android-x86_64-6.0-rc1- /run/media/root/158a840e-63fa-4544-b0b8-dc0d40c79241/virtualbox-os
# cd /opt/tools/network_simulators/ns3/ns-allinone-3.25/ns-3.25
# ./waf --run scratch/seem-manet --vis
# ./waf --run scratch/seem-manet-25-docker --vis
# ./waf --run scratch/seem-manet-5-docker --vis
#
# docker run --privileged -it -d --name "docker_1" centos-manet
# docker ps -a
# docker attach docker_1
# docker stop docker_1
# docker rm docker_1
# docker ps
# docker rmi 2c067614b89f
#-----------------------------------------------------------------------------
# 5 android-x86_64
#-----------------------------------------------------------------------------
#
# ./seem-tools-CLI-semi-auto.sh create 0 5 centos-manet android-x86_64-6.0-rc1- /run/media/root/158a840e-63fa-4544-b0b8-dc0d40c79241/virtualbox-os
#
# ./seem-tools-CLI-semi-auto.sh destroy 0 5 centos-manet android-x86_64-6.0-rc1- /run/media/root/158a840e-63fa-4544-b0b8-dc0d40c79241/virtualbox-os
#
# cd /opt/tools/network_simulators/ns3/ns-allinone-3.25/ns-3.25
# ./waf --run scratch/seem-manet --vis
# ./waf --run scratch/seem-manet-5-android --vis
#
#------------------------------------------------------------------------------------------
# So far, All is OK
#------------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------------
# This tool (seem-tools-CLI-semi-auto.sh) is released under GNU GPL v2,v3
# Author: Tongguang Zhang
# Date: 2016-06-18
#
# Note, Prerequisites for using this script: You have already installed Docker and NS3.
# Path in my notebook:
# NS3: /opt/tools/network_simulators/ns3/ns-allinone-3.25/
#------------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------------
# (OK)(OK)(All in CLI) Fedora23 + Docker(centos-manet) + NS3 + MANETs - testing
#------------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------------
# function create_docker()
# Description:
# create docker_node_num of dockers
# receive one parameter, that is docker_node_num
#------------------------------------------------------------------------------------------
destroy_docker(){
# docker_node_num
for((id=1; id<={id}"
tap="tap_d_{id}"
ifconfig {bridge} {bridge} &>/dev/null
ifconfig {tap} &>/dev/null
ifconfig {id}" &>/dev/null
docker rm "docker_android_node_num of dockers
# receive three parameters, that are docker_node_num, android_node_num, VM_image
#------------------------------------------------------------------------------------------
create_android(){
# 2, that is, android_node_num
# 4, that is, PATH of *.vdi
# You will also have to make sure that your kernel has ethernet filtering (ebtables, bridge-nf,
# arptables) disabled. If you do not do this, only STP and ARP traffic will be allowed to
# flow across your bridge and your whole scenario will not work.
cd /proc/sys/net/bridge
for f in bridge-nf-*; do echo 0 > 2; id++))
do
# to determine whether VM_image exists
# vm_image={id}
# exists=`VBoxManage list vms | awk -F \" '{print {vm_image} | wc -l | cat`
# if [ {vm_image} does not exist"
# exit
# fi
# SET VARIABLES
bridge="br_a_{id}"
# look at VirtualBox Gloable Setting, that is, vboxnet0: 192.168.56.1, 192.168.56.2(DHCPD), (3-254)
#host0={host0}"
#eth0_a_ip="112.26.2.{tap}
#ip link set up dev {tap} 0.0.0.0 promisc up
brctl addbr {bridge} {bridge}
ifconfig {bridge} 0.0.0.0 promisc up
# VBoxManage modifyvm android-x86_64-6.0-rc1-{bridge}
# VBoxManage startvm android-x86_64-6.0-rc1-{id}"
# VBoxManage hostonlyif create
# VBoxManage hostonlyif ipconfig vboxnet0 --ip 10.0.0.10 --netmask 255.255.255.0
# VBoxManage list hostonlyifs
# VBoxManage list dhcpservers
# VBoxManage list bridgedifs
# VBoxManage modifyvm {id} --nic1 hostonly --nictype1 Am79C973 --hostonlyadapter1 vboxnet0 --nic2 bridged --bridgeadapter2 3{bridge} --nic3 none --nic4 none
# gnome-terminal -x bash -c "VBoxManage startvm {id}"
# sleep 30
#
# adb connect {eth0_a_ip}:5555 root
# sleep 1
# adb connect {eth0_a_ip}:5555 root
# sleep 1
# adb connect {eth0_a_ip}:5555 shell mkdir -p /opt/android-on-linux/quagga/out/etc
# adb -s {eth0_a_ip}:5555 shell cp /system/xbin/quagga/etc/ospf6d.conf /opt/android-on-linux/quagga/out/etc/
# adb -s {eth0_a_ip}:5555 shell /system/xbin/quagga/ospf6d -d
# adb -s {eth0_a_ip}:5555 shell ifconfig eth1 {eth0_a_ip}:5555 shell ifconfig eth0 down
# VBoxManage createvm --name android-x86_64-6.0-rc1-1 --ostype Linux_64 --register
# VBoxManage modifyvm android-x86_64-6.0-rc1-1 --memory 1024 --vram 128 --usb off --audio pulse --audiocontroller sb16 --acpi on --rtcuseutc off --boot1 disk --boot2 dvd --nic1 hostonly --nictype1 Am79C973 --hostonlyadapter1 vboxnet0
# VBoxManage storagectl android-x86_64-6.0-rc1-1 --name "IDE Controller" --add ide --controller PIIX4
# VBoxManage storageattach android-x86_64-6.0-rc1-1 --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium android-x86_64-6.0-rc1-1.vdi
# VBoxManage startvm android-x86_64-6.0-rc1-1
echo "VBoxManage startvm {id}"
gnome-terminal -x bash -c "VBoxManage createvm --name {id} --ostype Linux_64 --register; \
VBoxManage modifyvm {id} --memory 1024 --vram 128 --usb off --audio pulse --audiocontroller sb16 --acpi on --rtcuseutc off --boot1 disk --boot2 dvd --nic1 bridged --bridgeadapter1 34/{id}.vdi; \
VBoxManage storageattach {id} --storagectl \"IDE Controller\" --port 0 --device 0 --type hdd --medium 33android_node_num of androids
# receive two parameters, that are android_node_num, VM_image
#------------------------------------------------------------------------------------------
destroy_android(){
# android_node_num
# 1; id++))
do
echo "VBoxManage controlvm {id} poweroff"
VBoxManage controlvm {id} poweroff &>/dev/null
VBoxManage unregistervm {id} &>/dev/null
rm "/root/VirtualBox VMs/{id}" -rf &>/dev/null
sleep 1
bridge="br_a_{id}"
ifconfig {bridge} {bridge} &>/dev/null
ifconfig {tap} &>/dev/null
done
}
#------------------------------------------------------------------------------------------
# usage()
# script usage
#------------------------------------------------------------------------------------------
usage(){
cat <<-EOU
Usage: seem-tools-CLI-semi-auto.sh a b c
a, the value is create or destroy
b, the number of dockers to be created
c, the number of androids to be created
Note: b + c <= 254
For example:
[root@localhost fedora23server-share]# pwd
/opt/share-vm/fedora23server-share
[root@localhost fedora23server-share]# ls seem-tools-CLI-semi-auto.sh
seem-tools-CLI-semi-auto.sh
[root@localhost fedora23server-share]#
./seem-tools-CLI-semi-auto.sh create 25 0 centos-manet android-x86_64-6.0-rc1- PATH_of_*.vdi
./seem-tools-CLI-semi-auto.sh destroy 25 0 centos-manet android-x86_64-6.0-rc1- PATH_of_*.vdi
./seem-tools-CLI-semi-auto.sh create 0 5 centos-manet android-x86_64-6.0-rc1- PATH_of_*.vdi
./seem-tools-CLI-semi-auto.sh destroy 0 5 centos-manet android-x86_64-6.0-rc1- PATH_of_*.vdi
./seem-tools-CLI-semi-auto.sh create 20 5 centos-manet android-x86_64-6.0-rc1- PATH_of_*.vdi
./seem-tools-CLI-semi-auto.sh destroy 20 5 centos-manet android-x86_64-6.0-rc1- PATH_of_*.vdi
EOU
}
#------------------------------------------------------------------------------------------
# function create_ns3_manet_seem_cc()
# receive two parameter, that is docker_node_num, android_node_num
#------------------------------------------------------------------------------------------
create_ns3_manet_seem_cc(){
echo "create seem-manet.cc from seem-manet-template.cc"
cd /opt/tools/network_simulators/ns3/ns-allinone-3.25/ns-3.25/scratch
rm seem-manet.cc -f &>/dev/null
cp seem-manet-template.cc seem-manet.cc
# after the 302 line of /opt/tools/network_simulators/ns3/ns-allinone-3.25/ns-3.25/scratch/seem-manet-template.cc
str='302a \\n '
for((id=1; id<={id}"
ns={id}\")); tapBridge.SetAttribute (\"DeviceName\", StringValue (\"{id}), adhocDevices.Get ({tap}\"));\n tapBridge.Install (adhocNodes.Get ({ns}));\n "
#inter="tapBridge.SetAttribute (\"DeviceName\", StringValue (\"{str}[1
b=[a+1]; id<={id}"
ns={host1}\")); tapBridge.SetAttribute (\"DeviceName\", StringValue (\"{id}), adhocDevices.Get ({tap}\"));\n tapBridge.Install (adhocNodes.Get ({ns}));\n "
#inter="tapBridge.SetAttribute (\"DeviceName\", StringValue (\"{str}[host1+1]
done
# sed -i '302a \\n tapBridge.SetAttribute ("DeviceName", StringValue ("tap_a_1"));\n tapBridge.Install (adhocNodes.Get (0), adhocDevices.Get (0));\n tapBridge.SetAttribute ("DeviceName", StringValue ("tap_a_2"));\n tapBridge.Install (adhocNodes.Get (0), adhocDevices.Get (0));' seem-manet.cc
sed -i "1), that is, the value is create or destroy
# para2 (3), that is, the number of androids to be created
# para4 (5), that is, VM image, such as, android-x86_64-6.0-rc1-
# para6 (id type -i 2
b=# -eq 6 ]; then
if [ 2 -lt 0 ] || [ 1 == "create" ]||[ 1 in
create)
if [ 2 3 -gt 0 ]; then create_android 3 6; fi
if [ 2 2
fi
;;
destroy)
if [ 2
rm /var/run/netns -rf &>/dev/null
fi
if [ 3 $5
ifconfig vboxnet0 down &>/dev/null
fi
;;
esac
else
usage
fi
# [root@localhost virtualbox-os]# pwd
# /run/media/root/158a840e-63fa-4544-b0b8-dc0d40c79241/virtualbox-os
# [root@localhost virtualbox-os]# ls
# android-x86_64-6.0-rc1-0.vdi android-x86_64-6.0-rc1-2.vdi android-x86_64-6.0-rc1-4.vdi
# android-x86_64-6.0-rc1-1.vdi android-x86_64-6.0-rc1-3.vdi android-x86_64-6.0-rc1-5.vdi
# [root@localhost virtualbox-os]#
#-----------------------------------------------------------------------------
# 25 docker (centos)
#-----------------------------------------------------------------------------
# systemctl start docker.service
# ./seem-tools-CLI-semi-auto.sh create 25 0 centos-manet android-x86_64-6.0-rc1- /run/media/root/158a840e-63fa-4544-b0b8-dc0d40c79241/virtualbox-os
# ./seem-tools-CLI-semi-auto.sh destroy 25 0 centos-manet android-x86_64-6.0-rc1- /run/media/root/158a840e-63fa-4544-b0b8-dc0d40c79241/virtualbox-os
# cd /opt/tools/network_simulators/ns3/ns-allinone-3.25/ns-3.25
# ./waf --run scratch/seem-manet --vis
# ./waf --run scratch/seem-manet-25-docker --vis
# ./waf --run scratch/seem-manet-5-docker --vis
#
# docker run --privileged -it -d --name "docker_1" centos-manet
# docker ps -a
# docker attach docker_1
# docker stop docker_1
# docker rm docker_1
# docker ps
# docker rmi 2c067614b89f
#-----------------------------------------------------------------------------
# 5 android-x86_64
#-----------------------------------------------------------------------------
#
# ./seem-tools-CLI-semi-auto.sh create 0 5 centos-manet android-x86_64-6.0-rc1- /run/media/root/158a840e-63fa-4544-b0b8-dc0d40c79241/virtualbox-os
#
# ./seem-tools-CLI-semi-auto.sh destroy 0 5 centos-manet android-x86_64-6.0-rc1- /run/media/root/158a840e-63fa-4544-b0b8-dc0d40c79241/virtualbox-os
#
# cd /opt/tools/network_simulators/ns3/ns-allinone-3.25/ns-3.25
# ./waf --run scratch/seem-manet --vis
# ./waf --run scratch/seem-manet-5-android --vis
#
#------------------------------------------------------------------------------------------
# So far, All is OK
#------------------------------------------------------------------------------------------
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通