Android Automotive OS(AAOS)에서 네트워크 시뮬레이션

이 페이지에서는 확장 가능하고 유지 관리가 적은 방식으로 Android Automotive 하드웨어 기기에서 다양한 네트워크 조건을 시뮬레이션하는 방법을 설명합니다. 이 환경에 구애받지 않는 네트워크 시뮬레이션은 Android Automotive 하드웨어 기기에서 실행할 수 있는 일반적으로 사용 가능한 Linux 도구를 사용합니다.

다음 섹션에서는 Android Automotive 하드웨어 기기에서 네트워크 시뮬레이션을 설정하고 실행하는 방법을 설명합니다.

커널 요구 사항

테스트 대상 장치(DUT)에서 네트워크 시뮬레이션을 활성화하려면 Linux ifbnetem 모듈을 아래와 같이 커널 구성 파일에서 구성해야 합니다.

# Network simulation config fragment start
CONFIG_NET_SCH_NETEM=y
CONFIG_IFB=y
CONFIG_NET_ACT_MIRRED=y
# Network simulation config fragment end

시뮬레이션 설정

모든 네트워크 시뮬레이션 또는 조절 시뮬레이션은 테스트 대상 장치(DUT)에서 수행해야 합니다. 이 시뮬레이션은 Linux tcNetEm 유틸리티를 사용하여 제어 정책 및 규칙에 따라 네트워크 인터페이스 컨트롤러(NIC)의 네트워크 트래픽을 제어합니다.

시뮬레이션을 설정하려면 다음을 수행하십시오.

  1. DUT와 호스트 서버를 인터넷에 연결합니다.
  2. NetworkSimulation.sh 스크립트 섹션에 제공된 코드에서 복사하여 NetworkSimulation.sh 스크립트를 생성하고 호스트 서버에 다운로드합니다.
  3. 호스트 서버를 DUT에 연결합니다. adb devices -l 을 실행하여 DUT가 연결된 장치 목록에 나타나는지 확인하십시오.

설정 아키텍처에 대한 설명은 다음 그림을 참조하십시오.

nw-sim

그림 1. 설정 아키텍처

NetworkSimulation.sh 스크립트

NetworkSimulation.sh 스크립트 파일에는 네트워크 시뮬레이션을 실행하는 adb 명령이 포함되어 있습니다. 다음을 NetworkSimulation.sh 라는 파일에 복사합니다.

  #!/bin/bash

  latency=$1
  bandwidth=$2
  packetloss=$3

  # root device and set it to permissive mode
  adb root
  adb shell setenforce 0

  #Clear the current tc control
  adb shell tc qdisc del dev ifb0 root
  adb shell ip link set dev ifb0 down
  adb shell tc qdisc del dev wlan0 ingress
  adb shell tc qdisc del dev wlan0 root

  # Create a virtual device for ingress
  adb shell ip link set dev wlan0 up
  adb shell ip link set dev ifb0 up
  adb shell tc qdisc del dev wlan0 clsact
  adb shell tc qdisc add dev wlan0 handle ffff: ingress
  adb shell tc filter add dev wlan0 parent ffff: protocol all u32 match u32 0 0 action mirred egress redirect dev ifb0

  # Throttle upload bandwidth / latency / packet loss
  adb shell tc qdisc add dev wlan0 root handle 1: htb default 11
  adb shell tc class add dev wlan0 parent 1: classid 1:1 htb rate "$bandwidth"
  adb shell tc class add dev wlan0 parent 1:1 classid 1:11 htb rate "$bandwidth"
  adb shell tc qdisc add dev wlan0 parent 1:11 handle 10: netem delay "$latency" loss "$packetloss"

  # Throttle download bandwidth
  adb shell tc qdisc add dev ifb0 root handle 1: htb default 10
  adb shell tc class add dev ifb0 parent 1: classid 1:1 htb rate "$bandwidth"
  adb shell tc class add dev ifb0 parent 1:1 classid 1:10 htb rate "$bandwidth"

시뮬레이션 실행

네트워크 시뮬레이션을 실행하기 위해 NetworkSimulation.sh 스크립트 파일의 adb 명령은 명령줄 인수를 사용하여 원하는 값을 설정합니다.

시뮬레이션할 대기 시간, 대역폭 및 패킷 손실을 지정하려면 다음 명령줄 인수와 함께 NetworkSimulation.sh 스크립트를 실행하십시오.

  • 대기 시간, ms 단위로 지정됩니다.
  • 대역폭으로, kbit 또는 mbit로 지정됩니다.
  • 패킷 손실(%).

예를 들어 300ms 대기 시간, 100kbit 대역폭 및 50% 패킷 손실을 설정하려면 다음을 실행합니다.

bash NetworkSimulation.sh 300ms 100kbit 50%

100ms 지연, 1mbit 대역폭 및 0% 패킷 손실을 설정하려면 다음을 실행합니다.

bash NetworkSimulation.sh 100ms 1mbit 0%

시뮬레이션 확인

NetworkSimulation.sh 스크립트를 실행한 후 Linux pingcurl 명령을 사용하여 네트워크 시뮬레이션이 올바르게 구성되고 예상대로 실행되고 있는지 확인하십시오. ping 명령을 사용하여 대기 시간을 확인하고 curl 명령을 사용하여 대역폭을 확인합니다.

예를 들어, 다음은 bash NetworkSimulation.sh 100ms 500kbit 10% 로 실행된 시뮬레이션에 대한 ping 의 예상 출력입니다.

BUILD:/ # ping -c 20 www.google.com
PING www.google.com (172.217.5.100) 56(84) bytes of data.
64 bytes from sfo03s07-in-f4.1e100.net (172.217.5.100): icmp_seq=1 ttl=119 time=103 ms
64 bytes from sfo03s07-in-f4.1e100.net (172.217.5.100): icmp_seq=2 ttl=119 time=105 ms
64 bytes from sfo03s07-in-f4.1e100.net (172.217.5.100): icmp_seq=3 ttl=119 time=103 ms
64 bytes from sfo03s07-in-f4.1e100.net (172.217.5.100): icmp_seq=5 ttl=119 time=103 ms
64 bytes from sfo03s07-in-f4.1e100.net (172.217.5.100): icmp_seq=6 ttl=119 time=103 ms
64 bytes from sfo03s07-in-f4.1e100.net (172.217.5.100): icmp_seq=7 ttl=119 time=103 ms
64 bytes from sfo03s07-in-f4.1e100.net (172.217.5.100): icmp_seq=9 ttl=119 time=103 ms
64 bytes from sfo03s07-in-f4.1e100.net (172.217.5.100): icmp_seq=10 ttl=119 time=103 ms
64 bytes from sfo03s07-in-f4.1e100.net (172.217.5.100): icmp_seq=11 ttl=119 time=185 ms
64 bytes from sfo03s07-in-f4.1e100.net (172.217.5.100): icmp_seq=12 ttl=119 time=103 ms
64 bytes from sfo03s07-in-f4.1e100.net (172.217.5.100): icmp_seq=13 ttl=119 time=103 ms
64 bytes from sfo03s07-in-f4.1e100.net (172.217.5.100): icmp_seq=14 ttl=119 time=103 ms
64 bytes from sfo03s07-in-f4.1e100.net (172.217.5.100): icmp_seq=15 ttl=119 time=103 ms
64 bytes from sfo03s07-in-f4.1e100.net (172.217.5.100): icmp_seq=16 ttl=119 time=103 ms
64 bytes from sfo03s07-in-f4.1e100.net (172.217.5.100): icmp_seq=17 ttl=119 time=103 ms
64 bytes from sfo03s07-in-f4.1e100.net (172.217.5.100): icmp_seq=18 ttl=119 time=103 ms
64 bytes from sfo03s07-in-f4.1e100.net (172.217.5.100): icmp_seq=19 ttl=119 time=103 ms
64 bytes from sfo03s07-in-f4.1e100.net (172.217.5.100): icmp_seq=20 ttl=119 time=103 ms

--- www.google.com ping statistics ---
20 packets transmitted, 18 received, 10% packet loss, time 19040ms
rtt min/avg/max/mdev = 103.394/108.307/185.756/18.791 ms

이 예는 ping 이 10%의 패킷 손실과 108ms에 가까운 평균 대기 시간을 보고함을 보여줍니다. 이는 시뮬레이션에 지정된 100ms 값에 대해 예상한 것입니다. 보고된 대기 시간이 지정된 값과 약간 차이가 나는 것은 정상입니다.

동일한 예에서 다음은 curl 명령 실행의 예상 출력입니다.

BUILD:/sdcard/DCIM # curl https://images-assets.nasa.gov/image/PIA15416/PIA15416~orig.jpg -o foo.jpg
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 6598k  100 6598k    0     0  49220      0  0:02:17  0:02:17 --:--:-- 47574

이 예는 curl 이 49220Bps로 평균 다운로드 속도를 보고함을 보여줍니다. 이는 시뮬레이션에 지정된 500kbit에 대해 예상한 대로입니다. 보고된 대역폭이 지정된 값과 약간 차이가 나는 것은 정상입니다.