Android basics (no coding)
Lec4:introduction
Android Platform:
- Android is a Linux-based operating system designed primarily for touchscreen mobile devices such as smartphones and tablet
- Android is open source. It can be freely modified and distributed by device manufacturers 设备制造商, wireless carriers 无线运营商 and enthusiast developers 开发者
- •Android was unveiled 问世 in 2007, the first Android phone was sold 第一次售卖 in October 2008
**VPN:**It is recommended to get a VPN for this module. Some resources are easier to download with a VPN
Lec5:Application Structure
Application components:
-
Activities
-
Services
后台服务,无UI
A service is an app component that runs at the background. It does not have UI
Services may still run when the UIs of their corresponding apps are not shown.
[eg]: music play at the background
-
BroadcastReciever
接收来自Android系统和其他应用程序的广播,并响应预先编码的动作。–Receives broadcasts from Android system and other apps and responses with pre-coded actions.
[eg1]: The mechanism of “startup services” in the Android system is achieved by doing a broadcast when the system has finished starting up. 自启动
[eg2]: When the battery level changes, the system will also broadcast a message. BroadcastReceiver can then prompt the user to save his files. 没电提醒
-
ContentProvider
In Android, apps have separate storages for files, database etc 分内存给文件和数据库,An app cannot access other apps’ data directly
ContentProvider can be used to share and exchange data between apps 实现在不同的软件之间分享交换数据
Activity:
(Activity life circle, Creating activities, Starting activities, Closing activities, Transferring data)
-
Primary class for interacting with user. 用来和用户交互 In principle, each activity is associated with one UI.
-
An Android app may contain multiple activities.But only one main activity, which is the first activity presented to users. (like main() function) 有很多activity但是只有一个mainactivity,他被第一个展示给用户
-
Activities in an app first register themselves in the system. Then they can be called by other activities. 可以被其他activity调用
Activity :Back stack”
•When a new activity is launched, the previous activity will be paused and sent to the top of the back stack.
Activities in the back stack follows the rule of last-in-first-out
When the user clicks “back” button, the current activity will be destroyed. The top activity in the back stack will be activated and shown
!!Activity life cycle:
An activity has four states in its life cycle:
- Running: the activity is on the top of the screen and gained focus.
- Paused: the activity is partially covered by other activities.
- Stopped: the activity is completely covered by another running activity.
- Destroyed.
•When running short of memory, a stopped activity is more likely to get killed than a paused/running activity.
Each time the state of an activity is changed, its corresponding callback functions will be invoked
Full version !!!!important
- onCreate(): Initial setup, load persistent state.
- onRestart(): read cached state
- onStart(): reset application
- onResume(): start foreground-only behaviors
- onPause(): shutdown foreground-only behaviors
- For example: temporarily stop UI animations.
- onStop(): cache state
- onDestroy(): save persistent state
Good implementation of callback functions can make your app more robust and performant.
Possible issues with a bad implementation:
- Crashing if the user receives a phone call or switches to another app while using your app.
- Consuming valuable system resources when the user is not actively using it.
- Losing the user’s progress if they leave your app and return to it at a later time.
- Crashing or losing the user’s progress when the screen rotates between landscape and portrait orientation.
去年考题
Explain the life cycle of Android activities and rank the system’s likelihood 可能性 of killing an app in these states. Then, explain how the back stack serves this process.
At the beginning, the activity is launched and it initially set up and loads persistent state and then reset the application and start the foregrond-only behaviors. If the activity is paused, for example, it is covered by other activities, it will be directly killed when the activity is extremely lack of the memory. Otherwise, the activity will be put at the top of the back stack and can be resumed when the user returns to it. And when the activity is stoped, for example, user has a phone call or he/she turn on another application, the activity will be killed if the memory is in shortage, if not, it can be restarted when user navigate to the activity. However, if the activity is finished by the users or destroyed by the system, it will be directly destroyed and the life cycle is ended.
an activity is stopped and it is not included in a process > an activity is stopped and invisable > an activity is stopped but start a background service > an activity is paused > an activity is interacting with the user
When a new activity is launched, the previous activity will be paused and sent to the top of the back stack, which follows the rule of Last-in-First-out. When the user click the “back” button, the current activity will destroyed and the top activity in the stack will be resumed.
Lec11:2D graphics with Views
View.onDraw()
步骤:
-
Create your own View subclass.
-
Override onDraw() method in your View.
-
Use the canvas object passed from onDraw() to draw everything you want.
Use Paint to set the colur, style etc.
You View subclass is ready, just add it inside an Activity
Lec12:Graphic 2
BitmapDrawable
一个包装位图的Drawable,可以平铺、拉伸或对齐。•A Drawable that wraps a bitmap and can be tiled, stretched, or aligned.
Reasons:
- You can send this Bitmap object to another activity via an Intent. 发送到其他activity
- You can easily combine this Bitmap with others. 轻松和其他绑定
- Supports scaling, rotating and other operations. 方便进行各种图形操作
Vector Images
Vector Images VS Bitmaps
A vector image stores its line strokes, colours and other elements as “commands”.
•E.g. draw a line from (0% width, 0% height) to (59% width, 62% height).
每次打开它时,系统将通过再次运行这些命令来重新解释re-interpret它。
而位图(bmp, jpg, png)则由像素表示。使用非整数缩放会导致图像模糊(例如,将位图大小调整为原始大小的171%)
Lec13: Multi-Touch in Android
MotionEvent
•A MotionEvent object contains the information about the movements of finger, mouse, pen and trackball.
Every time a new finger (pointer) touches the screen. Android will assign a pointer index and a pointer ID to it.
Every time a finger lifts from the screen, that ID and index will be released
Each event describes an action happend. Based on the action type, we can carry out different operations
Lec14:System Services: Sensors and GPS 感应器和GPS
Sensors感应器
大部分安卓设备都会有传感器来测量物理环境,常见的传感器有:
- Motion sensors 运动传感器:3-axis Accelerometer,3-axis Magnetometer,Gyroscope
- Environmental sensors: Light sensor,Noise
Access sensors:
您可以通过Android传感器框架访问设备上的传感器,获取传感器原始数据 raw sensor data 。步骤:
- Determine which sensors are available on a device. 检测空闲传感器
- Determine an individual sensor’s capabilities, such as its maximum range, manufacturer, power requirements, and resolution. 确定单个传感器的功能,如最大范围、制造商、功率要求和分辨率。
- Register and unregister sensor event listeners that monitor sensor changes. . 注册和取消注册监视传感器变化的传感器事件侦听器。
- Acquire raw sensor data and define the minimum rate at which you acquire sensor data
Based on this LocationManager, there are two ways of obtaining location information:
•Network-based: Using cell tower and WiFi signal.
•Satellite-based: Using GPS.
获取用户位置的流程:
•Start application, get previous location stored locally
•Start listening for updates from the location providers.
•Maintain a “current best estimate” of location by filtering out new, but less accurate fixes.
•Stop listening for location updates.
•Take advantage of the last best location estimate
Is the most recent location the most accurate? — no neccessarily
可以得到更精确的位置通过:
检查检索到的位置是否明显比以前的估计更新。检查该位置声称的准确性是否比先前的估计更好或更差。检查新位置来自哪个提供商,并确定是否更信任它。
Considerations:
-
定位不准确的原因
•Multitude of location sources such as GPS, Cell-ID, and Wi-Fi have different errors
•User movement could affect location accuracy.
-
功耗 power consumption -位置测量确实消耗了电池。为了限制电量消耗:
•Return updates less frequently
•Restrict the set of Location Providers
•Always check last known measurement
•Turn off updates in Activity::onPause().
Lec15: Network
连接的类型:
•java.net - (Socket, URL)
•org.apache - (HttpRequest, HttpResponse)
•android.net - (URI, AndroidHttpClient, AudioStream)
HTTP Support
•HTTP is a protocol for communication between browsers and world wide web (WWW) servers.
Communication: HTTP documents are transferred
Parsing HTTP Response (XML) http响应
•It is quite common for Web APIs to return XML or JSON documents as query results.
Socket
伯克利套接字Berkeley sockets 是一个用于Internet套接字和Unix域套接字的应用程序编程接口(APl),用于进程间通信(IPC)。它通常被实现为一个可链接模块库。它起源于4.2BSD Unix操作系统,于年发布1983."套接字是网络通信路径本地端点的抽象表示(句柄)。
每个接口都含有五条信息:
•Protocol used.
•Local IP and local port.
•Remote IP and remote port.
Service Sockets
•On a real server, you should create a new thread to handle each Socket returned from accept().
Lec16: Context aware system上下文感知系统
Mobile HCL (human computer interaction):
-What?
involves study, planning, and design of the interation between users and computers.
-Diversity 设备交互的多样性:
•Size: hand-sized, decimetre-sized, vs body-sized, etc.
•Haptic input: two-handed vs one-handed vs hands free
•Single user vs shared interaction: personal space vs public space
•Posture for user: lying, sitting, standing, walking, etc.
•Distance of output display to input control: centimetre to metre.
Position during operation: fixed vs mobile
•Connectivity: stand-alone vs networked, wired vs wireless
•Tasking: single task vs multi-task devices
•Multimedia content access: voice and text communications, oriented alpha-numeric data or text-oriented, audiovisual-content access
•Integrated: embedded integrated devices vs dynamically interoperable devices
-User input:
keyboards (telephone keyboard, mobile mini keyboards, touch screen), voice, novel solutions…
-Virtual keyboards (on screen) 虚拟键盘的优点和缺点:
a keyboard is displayed on the screen
**Pros 优点:**使用简单, 节约物理空间
Cons 缺点: 需要输入的准确性, 缺少物理反馈, 需要屏幕空间来显示键盘
Improvement schemes 改进方法: 预测输入, 放大镜光标
-Character Recognition 字符识别:
Recognizing handwriting based on pen-tip movements and pen-up / pen-down signaling
识别手写的技术基于笔迹移动 pen-tip movements和下笔收笔的信号 pen-up/pen-down signaling
(需要较高的处理能力 processing power, 需要训练用户的笔迹 training samples of the user’s handwriting, 错误率一般都比较高 error rate)
-Voice Input (speech recognition 语音识别):
Converts spoken words into text or commands 将语音转换为文本或命令
20年前: 训练识别个人的声音 trained to an individual voice,
限制以特定命令词开头 limited to a fixed vocabulary commands at the very beginning
•Now commonly used in search engine, Call Centers, etc, -typically voice independent
现在通常用于搜索引擎,呼叫中心等,通常是语音独立
Advantages 优点:
解放双手 Hands free access and control, 节省空间 Screen space saved, 不会打断当前交互活动 Does not interrupt current interaction activities, such as driving.
Disadvantages 缺点:
处理器重 Often processor heavy, 容易被嘈杂环境影响 Susceptible to degradation in noisy environments, 很难识别口音 Difficulty in accent recognition
-New input solution:
- Virtual keyboard without screen
- Stephen Hawking’s Wheelchair
- Brain Computer Interface
-Security in Mobility 移动性的安全:
私人敏感信息 Private & sensitive information in mobility:
Personal information,Social networking,E-Campus/E-Government,E-Banking/E-Purse,E-Commerce (e.g. Taobao, eBay, Amazon)
安全威胁 Security threats:
Virus,Hackers,Unauthorized access
安全问题出现在两方面:device, networking
移动设备的安全:
•Authentication 授权 –security for devices 设备安全
•Encryption 加密 –security for wireless networking 网络安全
-Authentication 授权:
**一、User authentication (identity verification) 用户授权:**Convince system of your identity before it can act on your behalf 让电脑相信
验证什么?vertify:
what know?: password
what have?: IC card
Problems:
•Password –strength (brutal force), memory (easy forget), input (input in front of others)
•IC card –portability (hardware incompressible), lack of self-protection
二、 Biometric Authentication 生物认证技术:
验证什么?vertify:
what know?: password
what have?: IC card
who are you?: identity your physical characteristics or behavioral patterns, known as biometrics 物理或行为特征
Characteristics used include 特征包括:
fingerprint,speech,face or body profile,signature (usually dynamic),retina pattern 视网膜
什么样的生物信息可以用来认证?
•Universality 普遍性 (Every person should possess this characteristic)
•Uniqueness 独特性 (No two persons possess the same characteristic)
•Permanence 持久性 (Does not change in time, i.e., it is time invariant)
•Collectability 可收集性 (Can be quantitatively measured)
它可以潜在地作为一个特定应用的生物特征。
- Authentication Framework 认证框架:
User’s biometric data must be acquired, assessed, processed and stored in mobile devices in advance.
用户的生物特征数据必须事先获取、评估、处理并存储在移动设备中。
Context-Aware Systems 上下文感知系统
What?
能够意识到自己在物理、虚拟和用户环境中的情况的系统。Systems that are aware of their own situation in the physical, virtual, and user environment.
- Weather app shows local weather 天气程序显示当地天气
- Music player auto stop when calling 音乐播放器在接电话时自动停止
- Phone locking the screen when it gets close to the face 手机在靠近脸时自动锁定
Why?
Apps can be more intelligent and less attention hungry (more comfortable to use, more efficient…).
应用程序可以更智能,更少关注(使用更舒适,更高效……)
How to be?
根据来自环境或用户操作的上下文线索调整用户的操作或目标 Adapt users’ operation or goal based on contextual cues from the environment or the user’s actions
具体来说,感知环境并确定与系统任务相关的内容 Specifically, sense environment and determine what is relevant to the system’s task(s)
Classifying:
Passive context-aware systems 被动上下文感知系统: - new context is presented to the user, to inform them of change.
将新内容告诉用户,让用户来做出改变
用户可以显式地确定应用程序的使用是否应该更改 User can then explicitly determine if the use of an application should change
例如电池即将耗尽(触发警报并询问用户是否正在使用电池想要采取一些行动
Active context-aware system 主动的上下文感知系统:-behavior of the applications change automatically 根据情况自动改变
任务过滤信息过滤,基于当前无线网络速度 Task filtering - information filtering, based on current wireless network speed
基于上下文的任务激活(在旅行时更改时区)
Various ways:
•Proactive Triggering 主动触发: performing some interaction based on environmental perceptions
•Streamlining Interaction 简化交互: travel guide for current location (reducing irrelevant information)
•Memories for past events 对过去事件的记忆: based on spatial or feature-based cues (contextual retrieval)
•Reminders for future contexts 对未来内容的提醒: tagging details regarding current context for future access
•Optimizing patterns of behaviours 最优化行为模式: changing interface based on situation
•Sharing Experiences 分享: Social networking based on shared contexts
Context creation 上下文创建
可以根据传感器 sensor 数据(由设备或附近的传感器捕获)创建新的上下文
低级原始上下文——>高级上下文,原始数据可能需要缩放 scaled 或转换
Lower-level raw contexts -> higher level contexts
例如,温度计上的电信号应该转换成摄氏温度。
例如,绝对地理位置应转换为建筑物的地址或标识
抽象通常更有用:如:这张照片是去年圣诞节在我父母家拍的
[eg:] Google Street View Navigation
用户捕捉街景的图像并将其上传到服务器, 谷歌根据图像定位用户根据位置, 搜索相关地理信息, 显示用户图像上的导航信息
Challenges:
- 环境线索 Environmental cues 可能不准确或错误
- 用户上下文可能被错误地确定或预测, 或者预测
- 线索和上下文的表现缺乏一致性 Lack of alignment
- 上下文的应用可能会降低用户的隐私性
- 上下文感应的变化或应用中的变化可能会使用户超负荷或者打扰他们
Spatial Awareness 空间感知
What?
- 它连接上下文信息,如个人或传感器的位置、活动、一天中的时间以及与其他人或物体的距离 It connects contextual information such as an individual’s or sensor’s location, activity, the time of day, and proximity to other people or objects
- It is the key element of Location-based service (LBS) 基于地理位置的服务的关键
- It is often considered one of the main drivers for mobile services
-personal applications 个人应用:
•Navigation - Give me the direction to the nearest coffee shop
•Context Change - My route is congested, is there a better route?
•Tourism - Tell me about the building in front of me
•Emergency - I’m having a heart attack!
•Social networking - Any friends nearby?
•Tagging - Where were those photos taken?
•Tracking - My phone has been stolen - can it be tracked?
-Public applications 公共应用:
•Enterprise - Why does it always take so long to deliver to customer X?
•Government - What is the traffic condition now from Shanghai to Suzhou
•Public - How long before the next bus will arrive at this bus stop?
•Security - location-based access control
•Network routing - location-based routing
Location Acquisition 位置获取:
Traditional ways:
•Satellite based - GPS/Galileo/BDS/Glonass
•Network based - GMS/3G positioning systems
•Mechanic methods - dead reckoning/inertial navigation
New solutions:
•WLAN based positioning
•RFID based positioning
•Ultrasonic/sonar positioning 超声波
•Infrared Position 红外
•Image based positioning
Environmental noise based positioning 环境噪音
Satellite based Positioning 卫星定位:
GPS使用24到32颗卫星进行定位:
卫星广播定位无线电信号,无线电信号包含卫星的位置和时间
三边定位法:
移动设备测量信号传播距离,移动设备根据多个测量值计算其位置
Cellular Network based Positioning 基于蜂窝数据的定位:
蜂窝网络利用基站(BS、)进行手机定位:
BS为他们的位置配备了GPs,BS测量手机的无线电信号
Positioning method:
Cell-ID蜂窝数据id,Trilateration 边测量,Triangulation三角测量
WLAN based Positioning :
接入点(AP)广播无线电信号:
有点像卫星或BS,但是AP位置未知,AP无法测量移动设备的无线电信号定位
解决方案:
AP信号强度的地理数据库
通过搜索数据库定位移动用户
通常称为指纹/接收信号强度法
Mechanic Positioning Methods 机械定位法:
用户的当前位置可以通过什么来估计:
之前的位置,它在这段时间内的行进距离,这段时间的行进方向
Augmented Reality 增强现实:
结合实时直接视图的物理现实环境与虚拟CGl •Combining live direct view of a physical real-world environment with virtual CGI
通常是实时使用环境元素的语义 •Typically in real-time using the semantics of environmental elements
识别数字线索”(例如二维条形码 barcode),并与数字图像叠加
用处:
可以用于增强 enhance 环境, 提供环境细节通过projecting labels,或者路上的方向或者可以看到的建筑
还可以用于娱乐
还可以显示信息没有任何阻碍 (Head-up display)
Technological Challenges:
图像分析需要识别叠加图形的线索 Image analysis is required to identify cues to overlay graphics
•Positioning information required, to determine relative location of other artifacts that may be annotated
•Live video is required to project the graphics onto
去年考题:
Please list up to 5 possible or existing context-aware functions of a video sharing platform app that allow the app to adapt to different environments/situations. For each one, identify any potential related issues?Each idea, along with its potential issues, worth up to 4 marks. Similar ideas will be treated as one.(20marks)
- 该平台会感受重力的变化,在用户旋转手机时做出相应的显示方向改变 (很容易错误估计情况,disturb the users)
- 可以根据地理位置的上下文,给用户推荐他的所在地的相关视频 (有可能会侵犯用户隐私)
- 会感受用户在一个内容停留的时长,提醒用户点赞或关注 (打断用户观看视频,破坏观看体验)
- 可以检索用户上次看到的位置,并询问用户是否需要跳转(检测结果可能不准确,容易误触,用户容易错过,影响观看感受)
- 在有电话接入时,可以自动暂停视频 (电话挂断后并不能自动播放,打断用户;并不能正确估计上下文,在接通电话后仍然继续播放)
- 移动ip (隐私)
Lec17:Shortest path 最短路径问题
应用: Map Navigation, Network Routing, Computer Graphics
Problem description:
Shortest path problem: Among a set of vertices (V) connected by edges (E), there is a source vertex and a destination vertex. The goal is to find a path with the sum of the weights minimised.
• All edges are directed • All weights are non-negative
Dijkstra‘s Algorithm
Starting from a source vertex s in G(V,E)
Each node in V has a **distance-from-source **value. • Originally they are infinite. Except for s = 0.
Maintain two sets, S and Q、
- S contains the vertices whose minimum distance-from- source values have already been determined.
- Q = V - S
Repeatedly select the vertex u from Q
• u has the minimum distance-from-source estimate in Q
• Remove u from Q and add u to S
• Update the distances of all neighbouring vertices of u
Results would be a tree
Dijkstra follows a Greedy Approach, once a node is marked as visited it cannot be reconsidered even if there is another path with less cost or distance.
Single-source shortest-path problem in a more general settings: edge weight can be negative. • However, you can not use Dijkstra’s Algorithm for the shortest path problem if there is a negative cost vertex
Lec18: Wireless networks 无线网络
Radio Wave 无线电波:
一种具有波长 wave lengths 的电磁辐射 electromagnetic radiation
have frequency from 3 kHz to 300 GHz
Human hearing range • 20Hz ~ 20kHz 人类听不到电磁波
Properties:
Radio speed 速度 = wavelength 波长 * frequency
通过天线 antenna 转换电能
Antenna length is usually a multiple of a quarter-wavelength 波长, λ/4
高频: 更短的波长;更短的天线;距离越远,恶化 deteriorate 越明显
低频: 更长的波长;更长的天线
反射,折射,散射,衍射:
Modulation 调制:
通过无线电波传送信息:
- 把信息转换 convert 成电子信号 electronic signal
- 将电子信号加入到无线电信号 radio signal 中
这个过程被称为调制-改变无线电波的一个或多个特性 varying one or more properties of a radio wave
analog signal:模拟信号 amplitude modulation 振幅调制
frequency modulation 频率调制
Wireless Networking
Classification
根据不同的网络大小分类:
-
WWAN - Wireless Wide Area Networks 无线广域网
2G/3G/4G/5G cellular networks 蜂窝网络
-
WLAN - Wireless Local Area Networks 无线局域网
WIFI (wireless fidelity ), LiFi (Light fidelity)
-
WPAN - wireless personal area networks 无限个人区域网
bluetooth
在不同的层中:
5-Layer Network Model:
- appllication 应用层
- Transport 传输层
- network 网络层
- Data link数据链路层
- Physical 物理层
Wireless network is in the context of the physical and data link layers.无线电网络在物理层和数据链路层
多种接入方法:
-
Circuit-level solutions 电路级解决方案 -------- Physical 物理层
Frequency division multiple access (FDMA) 频分多址
Time division multiple access (TDMA) 时分多址
Space division multiple access (SDMA) 空间分多址
Code division multiple access (CDMA) 码分多址
-
Package level solutions --------------------------- Data link layer 数据链路层
Carrier Sense Multiple Access (CSMA) 载波侦听多路访问
Circuit-level solutions - Physical 物理层
FDMA - Frequency Division Multiple Access 频分
Each network user has its own frequency band 频带, separated by guard bands 保护频带
•Guard bands lead to a waste of capacity.
• Receivers tune to the right frequency.
• Number of frequencies is limited.
• The maximum flow rate per channel is fixed and small
支持数字数据和模拟数据的传输
TDMA - Time Division Multiple Access 时分
所有网络用户以相同的频率传输数据,但在不同的时间。
- Needs time synchronization 时间同步
- Users can be given different amounts of bandwidth 不同的带宽
只支持数字数据
SDMA - Space Division Multiple Access 空间分
Two pairs of users can use the same frequency without interfering each other when they are located far away 当两对用户相距较远时,他们可以使用相同的频率而互不干扰
- A strong signal will mask a small area 强信号会掩盖一小块区域
- Directional (smart) antennas are commonly used in SDMA to control the radio broadcast space 定向(智能)天线通常用于SDMA控制无线电广播空间
CDMA - Code Division Multiple Access 码分
在同一时间使用相同的频率和传输 transmit ,但使用不同的编码方法 coding methods
Mathematical background:
向量点乘 (内积)
Two vectors must have the same dimension
Two vectors are orthogonal 正交 if their dot product is zero
CDMA Coding makes use of the dot product and Kronecker product
Steps:
-
Given two senders that wants to communicate with the same base station.
给定两个想要与同一基站通信的发送方。
-
The base station will first generate two orthogonal 正交 spreading codes for these two senders.
两向量点乘为0为正交, 比如, (1,1)和 (1,-1)
-
After receiving the spreading codes, the communication will start.
[eg]:
Assume that
A wants to send data (1, 0, 1, 1), spreading code (1, 1). B wants to send data (0, 0, 1, 1), spreading code (1, -1).
Firstly, convert data to signal:
(1, 0, 1, 1) -> (1, -1, 1, 1) , (0, 0, 1, 1) -> (-1, -1, 1, 1)
Remember: data can be recovered as long as the spreading codes are orthogonal
CSMA - data link layer
Principle:
- Listen to medium and wait until it is free (no one else is talking)
- If the medium is not free, wait for a random back off time then start talking
CSMA with collision detection (CSMA/CD)
碰撞检测
过程:
- Listen to medium and wait until it is free
- Then start talking, but listen to see if someone else starts talking too
- If a collision occurs, stop and start talking after a random back off time
该方案用于基于hub的以太网 This scheme is used for hub-based Ethernet
Collision Detection:
Advantages: More efficient than basic CSMA 更有效
Disadvantages:
碰撞检测不可以用在无线局域网中,一方面是因为在无线网卡上实现碰撞检测对硬件要求非常高,二是因为隐藏站的存在,原因在下面第二点
- Requires ability to detect collisions 需要检测碰撞的能力
- What if in wireless channels? – Hidden nodes 由于无线电传播的特殊性,会存在隐藏站,进行碰撞检测的意义不大
- Sending signal is usually much stronger than the receiving signal. So, it is difficult to “listen” while transmitting
CSMA/CA
CSMA with collision avoidance (CSMA/CA) 碰撞避免--------用于WLAN
过程:
- Listen to medium and wait until it is free
- When the medium is free, send a “request to send” (RTS)
- Wait for a “clear to send” (CTS) from the receiver
- Transmit actual data packet after receiving the CTS
- Receive an acknowledgement (ACK) from the receiver
去年考题
Question C
A synchronous CDMA network has three mobile users: Alice, Bob and Carol. Alice is already assigned with a 4-bit spreading code (1,1,-1,-1). Answer the following two questions:
-
Develop a spreading code for Bob and Carol so that the three of them can transmit data at the same time without any interference.
(1,-1,1,-1), (1,1,1,1)
-
The raw data Alice wishes to transmitis(1,1); Bob wishes to transmit(0,0); Carol wishes to transmit (0,1). Show the encoding and decoding results based on the spreading codes you just developed in part(1). Assume a binary data 0 will be encoded as signal -1 and a binary data 1 will been coded assignal +1.
Question E
IEEE802.11 defines its physical and MAC layers based on CSMA/CA. Answer the following questions on CSMA/CA.
-
Describe the procedure of CSMA/CA and CSMA/CD.
CSMA/CA: 先在中间等待空位,当mediun空闲后,发送请求RTS (request to send),等待接收方发送CTS (clear to send), 收到以后发送数据包,等待接收方的确认信息 (ACK)
CSMA/CD:在medium等待空位;碰撞检测,检测talking时有没有其他人talking;如果碰撞发生,停止并在一段事件 a random back off time 后开始talking
-
Identify and briefly explain three reasons why CSMA/CD cannot be used for a wireless LAN
- 需要碰撞检测的能力
- 由于无线点传播的特殊性,会存在隐藏站 hidding nodes, 使碰撞检测没有意义
- 发送的信号远比接受的信号要强大,所以监听对于硬件的要求很高,非常困难
Lec19: WI-FI
WI-FI andWLAN
What is WI-FI?
Wireless local area network 无线局域网 (WLAN) products that are based on the Institute of Electrical and Electronics Engineers’ (IEEE) 802.11 standards.
What is IEEE 802.11?
A set of media access control (MAC) and physical layer (PHY) specifications for implementing WLAN communication in the 2.4, 5 and 6 GHz frequency bands
IEEE 802.11 – “Wi-Fi 0”
Released in 1997
使用未经许可的频率 Use unlicensed frequencies
Multiple different versions:
IEEE 802.11b – “Wi-Fi 1”
Released in 1999
• Operates on 2.4 GHz • Runs on 13 channels • Data Rate: to up 11 Mbps • Reality: 5 to 7 Mbps • Most widely deployed today. E.g., cordless phones, microwave ovens, and many Bluetooth products
IEEE 802.11a - “Wi-Fi 2”:
• Released in 1999 • Operates on 5 GHz • Runs on 12 channels • Data Rate: up to 54 Mbps • Reality: 25 to 27 Mbps • Not compatible with 802.11b devices • Not widely used.
IEEE 802.11g/n:
IEEE 802.11g - “Wi-Fi 3”
• Released in 2003 • An extension to 802.11b • Data Rate: up to 54 Mbps • 2.4 GHz
IEEE 802.11n - “Wi-Fi 4”
• Released in 2008 • An extension to 802.11a/g • Data Rate: up to 600 Mbps • 2.4 or 5 GHz
渠道与频率Channels & Frequency
Take 802.11b as an example
• 13 free channels, channel 14 is usually restricted • 3 channels are used in most cases
- 1, 6 and 11
- 2, 7 and 12
- 3, 8 and 13
22 MHz bandwidth for each channel
Wi-Fi: Network Architecture
802.11 defines two Wi-Fi network options:
Access Point 接入点 (AP): A device that allows wireless devices to connect to a wired network using Wi-Fi, or related standards
infrastructure Network:
“基础设施”指的是用于支持网络的AP和有线局域网等现实世界的基础设施
Wireless sta^ons (Computers) in an infrastructure network must communicate via the AP
Independent Network:
主要用于军事应用和研究。不需要AP,计算机可以直接通信。
Basic Service Set (BSS):
一个AP连同所有相关的移动用户称为一个基本服务集(BSS)。
对于基础架构网络,接入点的MAC地址作为BSS (BSSID)的ID。
对于一个独立的网络,将生成一个48位的数字字符串,其外观和功能与MAC地址类似。这个BSSID在每个包中
Service Set ID (SSID):
Issues with BSSID:
• BSSID is hard to remember. • For ad-hoc networks, BSSID is randomly generated each time.
Thus, another level of naming called a Service Set Identifier (SSID) is created.
• 32-byte identification string • E.g. our XJTLU network. •
You can create a Wi-Fi network with hidden SSID
Extended Service Set (ESS):
A larger Wi-Fi consis^ng of a number of BSS networks interconnected via a common backbone
In a Wi-Fi network contains multiple APs. The SSID then becomes the SSID for all APs, it’s also called ESSID. • ESSID and SSID refers to the same concept. 概念一样,但是SSID用的更普遍
Mobility in WIFI 移动性
切换检测和决策过程是特定于供应商的,不是由802.11标准规定的。用户对切换决策过程有更多的控制。信号强度和信噪比是最常用的指标。
当一台计算机从一个BSS移动到另一个BSS时,所有的节点都必须更新它们的数据库,这样DS (Distribution System)才能通过正确的AP分发数据包。
Wi-Fi Security
无线会带来安全威胁:• Eavesdropping 窃听 • Impersonating/spoofing 冒充欺骗• Jamming 干扰
如何解决?
- Service Set Identifier (SSID) hiding
- MAC address filtering 过滤
- Wired Equivalent Privacy (WEP) protocol 有线等效隐私(WEP)协议
SSID Hiding:
隐藏网络名称SSID,避免公开广播 broadcast,但是只能阻止一些没有经验的用户访问您的AP还有其他方法,比如探测请求/探测响应Probe requests/Probe responses关联请求/重新关联请求AssociaWon requests/Re-associaWon requests因此,SSID隐藏不被认为是一种安全可靠的措施。
MAC Address Filtering:
通过只允许有效的MAC地址访问网络来控制访问
优点:提供比SSID隐藏更强的安全性
缺点:增加管理开销administrative overhead,减少可伸缩性scalability,意志坚定的黑客仍然可以通过软件欺骗MAC地址来破解它
Wi-Fi Security:
• Only authorized users can access the Wi-Fi
• Data communication between mobile terminal and AP should be protected. 保护移动终端与AP之间的数据通信。
• WEP: Wired Equivalent Privacy 在线等效隐私
• WPA: Wi-Fi Protected Access
• IEEE 802.11i/WPA2
WEP:
WEP发布于1999年,是802.11b数据链路层的安全组件
要求:同一WLAN中的所有计算机和ap必须共享相同的密钥K(称为WEP密钥)由于可用密钥有限(24位),被证明容易受到野蛮武力攻击
破解WEP:
假设我们有一台计算机试图猜测AP的密码。每次尝试不断发送一个1500字节的数据包,网络速度为11Mbps(每秒100万比特:100万比特/秒)。它需要多长时间枚举通过所有密码的可能性?
Wi-Fi Protected Access (WPA):
Wi-Fi联盟基于IEEE 802.11i标准的早期版本(草案3)于2003年发布
三大目标:修正WEP中的所有安全漏洞,使现有WEP硬件也支持WPA,确保WPA与802.11i标准兼容
WPA2:
基础设施和自组织网络的强加密和身份验证(WPA1仅限于基础设施网络)
使用AES而不是RC4加密 encryption
从2006年开始,WPA2认证已成为所有新设备的强制性认证WPA2 certification has become mandatory for all new equipment certified by the Wi-Fi Alliance
无线数据链路层:流量管理 Wireless Data Link Layer: Traffic Management
Collision Avoidance 碰撞避免
MAC layer of 802.11:
CSMA/CA without RTS/CTS:
听媒体,直到它是免费的。
2.当介质空闲时,等待另一个时间间隔,然后发送数据包。1. AP将回复一个ACK帧到确认。
3.如果发生冲突,AP将要求所有发送方停止发送,并在再次发送之前等待一个随机的时间间隔。
The Hidden Terminal Problem:
“在无线网络中,当一个节点可以与无线接入点(AP)通信,但不能直接与与该AP通信的其他节点通信时,就会出现隐藏节点问题或隐藏终端问题。这就导致了介质访问控制子层的困难,因为多个节点可以同时向AP发送数据包,这在AP上产生了干扰,导致数据包都无法通过。”
例如,B是AP, A和C是计算机。A和C距离太远,无法探测到彼此的信号。带有冲突检测的载波侦听多路访问(CSMA/CD)不工作。A无法检测到C的信号没有RTS/CTS的CSMA/CD效率较低。
CSMA/CA with RTS/CTS:
为了防止隐藏终端问题,引入了CSMA/CA和RTS/CTS。这是一个可选函数。
本质上,设备可以在传输数据帧之前预留空中接口。发送请求(RTS):请求AP分配时间。清除发送(CTS): AP安排时间,然后通知网络中的每个人。
RTS and CTS Packets:
RTS和CTS帧都包含一个所谓的网络分配向量(NAV),用于通知其他设备空中接口被保留的时间段。RTS/CTS序列降低了设备的吞吐量。因此,这种机制应该只使用:如果预期网络负载非常高。客户端设备分散在更大的区域。
Lec20: Mobile IP 移动IP
互联网诞生时还没有使用移动计算机的想法,所以出现了一个问题就是当使用者移动时IP地址也会同时发生变化,为了解决这个问题就有了移动IP。
移动IP在当你是服务提供者时非常重要,需要很频繁地从一个网络跳到另一个
Mobile IP is important if your computer is a “service provider”, rather than a “service consumer” and need to move from one network to another frequently.
**[eg]😗*Emergency communication with permanent and quick reachability via the same IP address. Not useful if you are carrying your laptop around to just watch videos.
Issues with Normal IP Routing
Desktop 1 will not receive a single packet as soon as it leaves its home network.
Mobile IP:
-Goal:
拥有一个动态的IP地址并且使用相同的逻辑计算机名实现永久地可达到
have a dynamic IP address and still want to be permanently reachable using the same logical computer name
Core idea: tunnelling 隧道
Specification defined in RFC3344 “IP Mobility Support for IPv4"
Terminologies:
- Mobile node (MN) 移动节点 - An end-system or router that can change its point of attachment to the internet using mobile IP.
- Correspondent node (CN) 对应节点 - Another node that communicates with the MN.
- Home network (HN) 本地网络 - The network where MN belongs to.
- Foreign network (FN) 外地网络 - The network which MN is currently visiting.
- Care-of address (COA) 同址转交地址 - Define the current location of the MN from an IP point of view. All IP packets sent to the MN are delivered to the COA, not directly to the IP address of the MN. - Think of it as a “delegate IP”.
- Home agent (HA) 归属代理 - The HA provides several services for the MN and is located in the home network. The tunnel for packets toward the MN starts at the HA.
- Foreign agent (FA) 外地代理 - Like HA, it acts as tunnel endpoint and forward packets to the MN.
移动IP的效率很低,严重的情况成为两次穿越或2X,中等情况称为三角路由选择
两次穿越 double crossing: 发生在移动主机已经移动到与远程主机所在的同一网络 (站点)的情况,在远程主机与移动主机互相通信时如上图所示。
三角路由选择: 远程主机和移动主机并不在同一网络上
解决办法: 让远程主机把移动主机的转交地址和归属地址绑定起来
移动IP的RFC:RFC1701、RFC2003、RFC2004、RFC3024、RFC3344、RF
Agent Discovery Methods:
移动IP如何发现自己移动了呢????
Mobile IP describes two methods (RFC 1256):
-
Agent advertisement 代理通告 - foreign agents and home agents **advertise their presence **periodically using special agent advertisement messages 外地代理和归属代理广告他们的存在
在路由器使用ICMP路由器通告报文宣布自己连接的某个网络时,在这个分组上在附带一个代理通告
-
Agent solicitation 代理询问 - If no agent advertisements are present or the inter-arrival time is too high, the MN will actively sending packets to find agents 移动节点自己主动发送包找代理
找到代理后 After using either of these two methods, the MN will get a care-of-address (COA).
The FA 外地代理 will receive IP packets and forward to MN. • It is needed because the MN might have a LAN address instead of WAN address.
(LAN是路由器局域网的IP,路由分配,也可自己设定。WAN是广域网的IP,运营商给的,动态IP。)
If MN gets a WAN address, the COA will just be this WAN address. (also called colocated COA)
Registration of COA:
移动主机必须向外地代理登记,移动主机必须向它的归属代理登记(通常是由外地代理以移动主机的身份来完成的),如果截止期到了,那么移动主机必须更新登记,如果移动主机回归到网络,它就必须取消登记
Now MN has a COA in FN, it is time to register this **new COA **with the home agent
two situations possible:
- If the COA is at the FA. We need to form a **tunnel 隧道 ** from HA to FA.
- If the MN gets a WAN address. We need to form a tunnel from HA directly to MN
when COA is at the FA:
登记报文被封装成UDP用户数据报,代理使用熟知端口434,移动主机使用一个临时端口
UDP packets are used for registration requests (Need to reregister this binding before it expires):
报文:
when MN gets a WAN address
MN then becomes the endpoint of the tunnel itself.
Packets sent to HA will be forwarded directly to MN
IP packet delivery
- CN sends an IP packet to the MN.
- HA intercepts the packet, knowing that MN is currently not in its home network. A new header is put in front of the old IP header showing the COA as new destination and HA as source of the encapsulated packet.
- The foreign agent receives the packet, removes the additional header. Then forwards the original packet to MN.
- MN replies the CN. Packet goes to FA and then forwarded directly to CN.
https://docs.oracle.com/cd/E19455-01/806-7600/6jgfbep0v/index.html
去年考题
Mobile IP has been widely used to support mobility of users in networks. Answer the following questions on mobile IP.
-
Describe how mobile IP allows users to move from one network to another.
移动IP的功能实现主要分为三部分, 包括代理发现 agent discovery, 同址转交地址的登记 registration of COA, 数据收发 data delivery。当移动节点到达外地网络时,本地代理和外地代理会不断广播发出代理通告agent advertisement 来让设备知道自己移动了。如果没有收到代理通告的话,移动节点会发出代理询问 agent solicitation 来寻找代理。移动节点发送的代理询问被外地代理接收后,接受的外地代理会给移动节点发回一个代理通知。在建立代理后,移动节点要向外地代理和本地代理登记 registrate 同址转交地址 COA (care-of address),如果COA截止时间 cut-off 到了需要重新登记,并且要在回到本地网络时取消登记。在登记时,移动节点先给外地代理发送登记请求,随后外地代理给本地代理发送登记请求,在登记成功之后,本地代理HA 给外地代理FA发送登记回答 registration reply,最后FA给MN发送登记回答。最后在数据发送时,先从移动节点对数据进行封装wrapper 然后发送给FA, 在进行进一步的封装后,发送给HA, HA将数据解压unzip 后, 将数据包发送给对方。
-
Discuss any potential efficiency issues related to mobile IP.
移动IP的效率很低,尤其是在移动节点不在本地网络而且和远程主机distance host 在同一网络时,数据需要经过两次穿越 double crossing, 非常低效,对实时real time 的语音和图像有极大的损失,也加重了网络的负担,数据包在网络中运行时间大大增加。
ource of the encapsulated packet.
3. The foreign agent receives the packet, removes the additional header. Then forwards the original packet to MN.
4. MN replies the CN. Packet goes to FA and then forwarded directly to CN.
[外链图片转存中…(img-lRaZIjnw-1673285889453)]
https://docs.oracle.com/cd/E19455-01/806-7600/6jgfbep0v/index.html
去年考题
Mobile IP has been widely used to support mobility of users in networks. Answer the following questions on mobile IP.
-
Describe how mobile IP allows users to move from one network to another.
移动IP的功能实现主要分为三部分, 包括代理发现 agent discovery, 同址转交地址的登记 registration of COA, 数据收发 data delivery。当移动节点到达外地网络时,本地代理和外地代理会不断广播发出代理通告agent advertisement 来让设备知道自己移动了。如果没有收到代理通告的话,移动节点会发出代理询问 agent solicitation 来寻找代理。移动节点发送的代理询问被外地代理接收后,接受的外地代理会给移动节点发回一个代理通知。在建立代理后,移动节点要向外地代理和本地代理登记 registrate 同址转交地址 COA (care-of address),如果COA截止时间 cut-off 到了需要重新登记,并且要在回到本地网络时取消登记。在登记时,移动节点先给外地代理发送登记请求,随后外地代理给本地代理发送登记请求,在登记成功之后,本地代理HA 给外地代理FA发送登记回答 registration reply,最后FA给MN发送登记回答。最后在数据发送时,先从移动节点对数据进行封装wrapper 然后发送给FA, 在进行进一步的封装后,发送给HA, HA将数据解压unzip 后, 将数据包发送给对方。
-
Discuss any potential efficiency issues related to mobile IP.
移动IP的效率很低,尤其是在移动节点不在本地网络而且和远程主机distance host 在同一网络时,数据需要经过两次穿越 double crossing, 非常低效,对实时real time 的语音和图像有极大的损失,也加重了网络的负担,数据包在网络中运行时间大大增加。