2015年11月9日 星期一


Android 平台架構之研讀

--- 你以為亞馬遜實體店是為了賣書?不,它是為了大數據!   see more at msn財經


•Android 的這種設系方式,主要是為了能同時吸收 Java 與 C 語言雙方的開放原始碼資源,讓 Google 可以快速的利用這些資源建構出一個足以與微軟和蘋果抗衡的手機系統。Google 利用 C 語言吸收了 Linux、OpenGL、SQLite、WebKit 等系統方面的資源,然後利用 Java 吸收了 Apache 函式庫等 Java 方面的資源,最後再利用 Dalvik 虛擬機 (DVM) 繞過昇陽 (Sun) 在 Java 上的專利,因而吸收了大量的開放原始碼程式,卻又巧妙的避開了商業上的某些智財權障礙。
•為了避免商業公司因為必須公開原始碼而不敢投入 Android 手機的開發,並且讓許多擴充與驅動程式能不需要開放原始碼,因此採用了規定較寬鬆的 Apache Software License 2.0,這種設計讓商業公司可以放心的投入 Android 手機的開發,而不需要太過擔心開放原始碼的問題。
•Google 仍然必須遵守這些開放原始碼的約定,像是 Linux 核心就使用了 GPL 2.0 的授權方式,並非 Android 所採用的 Apache 2.0 授權,因此 Android 的開發者仍然必須謹慎的辨認各個層次的授權屬性,以免侵犯開放原始碼的授權規範。


•整個 Android 系統的架構,除了展現了 Google 的程式技術之外,還是一種精巧的法律規避設計。Google 在程式與法律雙方面的能力,在 Android 系統中展現得相當淋漓盡致,非常值得學習。
Media framework: Media framework provides different media codecs allowing the recording and playback of different media formats
SQLite: SQLite is the database engine used in android for data storage purposes
WebKit: It is the browser engine used to display HTML content

OpenGL: Used to render 2D or 3D graphics content to the screen



The Mesh Function Test Report


道德經:
信言不美,美言不信。善者不辯,辯者不善。知者不博,博者不知。聖人不積,既以為人己愈有,既以與人己愈多。天之道,利而不害;聖人之道,為而不爭。

1. Background and definition for Robin mesh scheme
"robin mesh" is a stand alone system and concerns all network and transport related topics. Based on OpenWrt kamikaze. B.A.T.M.A.N detects neighbors and distant nodes by broadcasting, receiving, and rebroadcasting originator messages (OGM) according to the rules of the B.A.T.M.A.N. algorithm. These OGMs are flooding through the mesh-cloud until they get lost or nobody has to rebroadcast them any more. Once a node receives an OGM message initiated from a distant node it is aware of the existence of the node.
1.1 Definition
gateway node
The node which offers Internet connectivity is called a gateway node and has to be simply connected to a xDSL router, or also to a device acting as STA (with no AP) in the way of client bridge.
client (repeater) node
A repeater node is simply powered on and palced in good location forward other nodes. A node receive OGMs by other nodes actives in the mesh cloud and knows network topology within one or two minutes; then BATMAN arrange the node routing table in order to discover the best path to an internet gateway.
          
Diagram 1-1 gateway node                    Diagram 1-2 client node
1.2 ROBIN interfaces
node
ath0
ath2
ath1
eth0
gateway
mesh and forward iface
batman WPA-PSK AP iface - default gateawy for private wlan users
batman open AP iface - default gateawy for pubblic wlan users
WAN iface
administratrive tasks on eth0:1
client
mesh and forward iface
batman WPA-PSK AP iface - default gateawy for private wlan users
br0 (ath1-eth0 bridge)
default gateawy for pub.wlan and wired users
node
tun iface (gate0)
Gateway and client
If a gateway is found batman will create a tun device and alters the routing table accordingly by setting a default route. Once you want Internet your traffic will end up in batman which will than contact the gateway and ask for an IP for the tun interface. The gateway will send an IP back so that your tun interface has an IP. Your traffic will be tunnelled to the gateway as long as you need it. At the end your client will release the IP.
2. Getting access to a node
Getting the first access to a node requires that you login via ssh (on windows you would need to install something like Putty). We can ssh to a node through,
(please see below diagram 2, ssh login by account root and password 0p3nm35h)
·         gateway node
o    wifi connection using open_AP IP or WPA-PSK_AP IP addresses
o    wired connection to a "free" ethernet port of the DSL Router (if combo) or via switch which connects DSL router
·         repeater (client) node
o    wired cable or wifi connection using open_AP IP or WPA-PSK_AP IP addresses
Diagram 2 -- ssh login by account root and password 0p3nm35h
3. Mesh Function Test
The mesh function is adopting from ROBIN mesh scheme, for our target board AP51 with 8M flash/16MB RAM, added to OpenWrt trunk code base, surely to play a role of mesh node.
The sources are coming from the open resource site, thanks to all forum developers.
OpenWrt Revision: kamikaze_trunk, or equivalent to Kamikaze 8.x
ROBIN Mesh Revision: beta-1.21.11
OpenWrt:
svn co https://svn.openwrt.org/openwrt/packages packages
ROBIN Mesh:
svn co https://svn2.hosted-projects.com/ansanto/robin/openwrt/kamikaze_8/packages/robin-mesh robin-mesh
3.1 Nodes Deployment -- serial chaining placement
number
Node
Mesh IP addr
MAC id

1
Gateway
5.33.192.154
00:12:cf:21:c0:9b
Internet connectivity
2
Client 1
5.131.126.160
00:12:cf:83:7e:a1
Forward other nodes
3
Client 2
5.28.131.152
00:18:84:1c:83:99
Forward other nodes
The customer’s firmware is a reference sample. So, I do two experiments, the first one is using customer’s one as reference. And the version I built (i.e. accton built version) is our main goal of experiment to practice. The test network diagram, please see below diagram 3.
Diagram 3 -- The AP 51 mesh function test network
3.2 Test considerations – choose a better WIFI bit rate at Taichung office area
The distance is away from 1.18 m between two nodes at various bit rate.
Bit rate
5.5
11
12
18
24
36
48
54
Throughput(avg)
2.35
3.35
3.19
3.20
3.12
3.19
3.21
3.38
The distance is away from 10.5 m between two nodes at various bit rate.
Bit rate
5.5
11
12
18
24
36
48
54
Throughput(avg)
2.32
3.4
3.1
2.6
2.46
2.5
2.57
2.6
So, I judge to use 11Mbps as bit rate for wifi radio 11g mode, and turn off the traffic control function for the mesh function, the testings are performed at the rate of 11 Mbps of this choice.
3.3 Test result
The test case is using Chariot TCP end-to-end throughput script.
The wifi 11g mode bit rate is set to 11Mbps.
Disable the traffic control
The background noise and interference is also existing.
End-to-end throughput
Taichung Office (12F)
Average
Mbps
Max
Mbps
Min
Mbps
Distance
Topology
Changed
Client 1 to gateway node
3.431
4.082
1.684
One hop(10.56m)
Y
Client 2 To Gateway node
2.617
3.941
1.156
Two hops(12.54m)
Y
Table 3-1 -- The action-built-version test result summary (office area,12F)
End-to-end throughput
Taichung Baseroom(B2)
Average
Mbps
Max
Mbps
Min
Mbps
Distance
Topology
Changed
Client 1 to gateway node
3.955
4.145
3.320
One hop(17.25m)
Y
Client 2 To Gateway node
3.639
4.324
1.001
Two hops(12.75m)
Y
Table 3-2 – The action-built-version test result summary (baseroom, B2)
Compressed image
Original raw version
Version With Mesh
Kernel
768KB
768KB
Root file system
1280KB
2560KB
Table 3-3 -- The action-built-version Size changed with compression
4. The result of Accton built firmware
The test settings on AP51 mesh function test are set up as below,
(a)The wifi 11g mode bit rate is set to 11Mbps.
(b) Disable the traffic control
(c)The test case is using
1. Chariot TCP end-to-end throughput script.
   2. Iperf
(d)The test field is at Taichung office area(12 Floor), and baseroom(B2), respectively.
4.1. One hop end-to-end throughput measurement
The data is generated by iperf (see diagram 4-1-1). Meanwhile, we watch on the batman packets activities, by using command “batman –c –d 1” and “batman –c –d 4” on the console command line(see diagram 4-1-2, 4-1-3). And after then, we use chariot to measure the throughput (see diagram 4-1-4).
Diagram 4-1-1: Iperf bandwidth monitoring

 Diagram 4-1-2 hops forwarding


Diagram 4-1-3 neighbors

Diagram 4-1-4 chariot throughput
4.2. Two hops end-to-end measurement(Office area, 12F)
The data is generated by iperf (see diagram 4-2-1). Meanwhile, we watch on the batman packets activities, by use command “batman –c –d 1” and “batman –c –d 4” on the console command line (see diagram 4-2-2, diagram 4-2-3). And then, we use chariot to measure the throughput(see diagram 4-2-4).
Diagram 4-2-1 iperf bandwidth monitoring

Diagram 4-2-2 hops forwarding

Diagram 4-2-3 neighbor

Diagram 4-2-4 chariot throughput


4.3 Remove the middle hop
Remove middle way hop, then add it again after 3 minutes.
1. To see from hop to hop activities
2. To see how fast the changes when recover the throughput if remove the middle hop. Shown as diagram 4-3-1.
Diagram 4-3-1 Remove the middle hop
4.4 Topology changed
We can use command “batman –c –d 1” or “batman –c –d 2”, or “batman –c –d 4”, to see detailed packet forwarding and mesh topology changed.


4.5 The test result in baseroom (B2)
4.5.1. One hop end-to-end throughput measurement


4.5.1. Two hop end-to-end throughput measurement


USB auto-mounting lighting considerations



道德經:
反者道之動;弱者道之用。天下萬物生於有,有生於無。

USB device detection method is UUID (Unversally unique identifier) as a USB storage(disk) identifier, This method can surely distinguish and identify a general USB disk with USB 3G dongle storage, even it is a USB printer, in theoretics and in practice,
In short, when any USB device( a USB disk, 3G/4G dongle, printer ) is inserting, just only two detecting states will occur, one is mounted successfully, and the second is  mounting failure. In the UUID identifying method, we just have two conditions:
Ø   Case I: If it is “mount successfully”, then it means the USB device is a  disk (storage) only, it is impossible a 3G/4G dongle, even a printer

Ø   Case II: If it is "mounting failure", then it means the USB device is a unrecognized or unsupported device.
Ø   Case III: If it is remove the USB disk from USB port, then the USB LED shall be turn off.
Attention:
USB LED ON/OFF doesn’t mean software meaning of “safe removal” for the USB disk

USB disk 卸載之安全考量

道德經:
致虛極,守靜篤。萬物並作,吾以觀復。

The Safe Removal just means a software safely protect buffer/cache to USB disk instead of when suddenly unplug the disk from the USB port, by handling the important things of “sync”, “shutdown” and “un-mount” procedures. Despite we don’t have a grayed soft panel icon to tell the “Safe Removal” status at web page, but just turn off a USB LED to tell the USB disk is really unplugged from the USB port at this ‘unplug’ case. When a user press “REMOVE” button on the web page, then WebUI calls server side CGI “runtime” to handle the case of safe remove by calling core unplugging helper. The first step is to flush needed file system bufferes(caches) to USB storage for safety, the remaining steps are listed in the below flow chart. The later steps will also do “pre-unmount” the USB disk. When the user see the web page message box “You can safely remove the USB disk”, then he can really take the action of “remove” to the USB storage from USB port.