清華大學 計算機網路 期末考

(+5)【 單選題 】
(5%) 1. Which of the following statements are correct for delivering packets (datagrams) over the Internet ?
(a) All packets destined to the same destination will be forwarded along the same routing path.
(b) The routing path of a packet is determined first before the packet is sending into the Internet.
(c) The Internet is reliable so that all packets will be received by the destination correctly.
(d) A packet may be partitioned into several fragments by routers.
(e) All fragments of a packet will be forwarded along the same path to the destination.
(+5)【 複選題 】
(5%)2. Which of the following statements are correct for “statistical multiplexing” ?
(a) Data are transmitted based on demand of each flow.
(b) Data are transmitted based on the arrival time of each flow.
(c) The bandwidth used by different flows may be different.
(d)The statistical multiplexing is fair due to the bandwidth used by different flows are the same.
(e)It provides better link utilization than TDM (Time-Division-Multiplexing) and FDM (Frequency-Division- Multiplexing).
(+5)【 複選題 】
(5%) 3. Which of the following are correct for CSMA/CD (Carrier Sense Multiple Access with Collision Detection) protocol ?
(a)Listen (carrier sense) before transmit.
(b)If channel is sensed idle, then transmit entire frame without considering if frame collision is detected.
(c)If channel is sensed idle, then transmit a frame and stop the transmission when a collision is detected.
(d)If channel is sensed busy, then defer transmission until the channel is idle.
(e)If channel is sensed busy, then defer transmission for a random time.
(+5)【 複選題 】
(5%) 4. The “collision window” of the CSMA/CD protocol is time required to detect a collision. Which of the following are correct for collision window ? Assume the one way propagation time of the network is “a”
(a)The collision window is equal to a
(b)The collision window is equal to 2a
(c)The worst case scenario happens when the two hosts are at opposite ends of the Ethernet
(d)The best case scenario happens when the two hosts are close to each other.
(e)The worst case scenario happens when the two hosts are close to each other.
(+5)【 複選題 】
(5%) 5. What are the purposes of RTS and CTS control frames used in IEEE 802.11 wireless LAN ?
(a)Reserve the wireless channel for a time period
(b)Informs all nearby nodes that a transmission is about to begin
(c)These two frames also contain data to transmit.
(d)The sender is asking the receiver to send back a frame after a time period
(e)The duration field in the RTS and CTS frames is used to specify the time period needs to transmit the frame
(+5)【 複選題 】
(5%) 6. Which of the following statements about the CSMA/CA are correct ?
(a)A station with a pending MPDU may transmit immediately when it detects the medium is free.
(b)A station with a pending MPDU may transmit when it detects a free medium for greater than or equal to a DIFS time.
(c)If the medium is busy when a station desires to transmit an MPDU, the station can transmit the MPDU when it detects a free medium for greater than or equal to a DIFS time.
(d)In CSMA/CA protocol, no packet collision will happen as the “collision avoidance” mechanism is used.
(e)If the medium is busy when a station desires to transmit an MPDU, the Random Backoff Time algorithm shall be followed after it detects a free medium for greater than or equal to a DIFS time.
(+5)【 複選題 】
(5%) 7. Consider the procedure to maintain the spanning tree of IEEE 802.1D spanning tree algorithm. For a bridge B with three ports x,y,z and root bridge ID = w, rpc = p. Assume port x is an R port, port y is a D port, port z is blocked and connected to a LAN M. Also assume port z has a transmission cost of c. What actions will be taken by the bridge B if the hello BPDUs suppose to be periodically received from port z are lost for a long time (a timeout event) ?
(a) Port z is selected as a new R port.
(b) Port z is selected as a D port.
(c) A BPDU (with root bridge ID = w, rpc =p) is forwarded to port z
(d) A BPDU (with root bridge ID = w, rpc = p+c) is forwarded to port z.
(e) A BPDU (with root bridge ID = w, rpc =p) is forwarded to port y.
(+5)【 複選題 】
(5%) 8. Consider the procedure to construct the spanning tree. When a bridge B (with root bridge ID = w, rpc = p) receives a BPDU (with root bridge ID = m, rpc =q) from port x (with a transmission cost of c). Assume w > m. Then what actions will be taken by bridge B ?
(a) port x will be selected as a new D port.
(b) port x will be selected as a new R port.
(c) A BPDU (with root bridge ID = m, rpc =q) will be forwarded to all the ports, except port x.
(d) A BPDU (with root bridge ID = w, rpc =q+c) will be forwarded to all the ports, except port x.
(e) A BPDU (with root bridge ID = m, rpc =q+c) will be forwarded to all the ports, except port x.
(+4)【 複選題 】
(4%) 9. Which of the following tagging rules for a “hybrid link” are correct ?
(a)For each VLAN, all frames traversing a particular hybrid link can be tagged in different ways.
(b)For each VLAN, all frames traversing a particular hybrid link must be tagged the same way: all implicitly tagged or all carrying the same explicit tag.
(c)There can be a mix of implicitly and explicit tagged frames but they must be for different VLANs.
(d)All the frames must be tagged explicitly.
(e)A frame traversing a particular hybrid will be tagged or untagged depends on which VLAN the frame came from.
(+6)【 填充題 】
(6%) 10. Consider the following VLAN configuration. For switch 1, what are the “member set” and “untagged set” of each VLAN ? please answer the port “number” for each of the following questions.
注意:在每一個VLAN中的答案請依數字大小排序,答案請由"," 隔開,並且答案欄裡不要輸入任何空白字元(答案後面也不要有空白)
EX:若A空格答案有4 2 1 3,請填入:1,2,3,4(注意逗號是英文輸入法的逗號,若不確定請直接複製 ",")
Member set:
VLAN1:__A__
VLAN2:__B__
VLAN3:__C__
 
Untagged set:
 
VLAN1:__D__
VLAN2:__E__
VLAN3:__F__
A=ANS:2,3,4,5
B=ANS:7,11,12
C=ANS:6,7,8,9
D=ANS:2,3,4,5
E=ANS:11,12
F=ANS:8,9
(+5)【 複選題 】
(5%)11. Let SeqNumToAck denote the largest sequence number not yet acknowledged, such that all frames with sequence number less than SeqNumToAck have been received. Which of the following statements are correct for the “cumulative acknowledgement” ?  
(a)The receiver acknowledges SeqNumToAck+k to sender if a frame with sequence number of SeqNumToAck + k, k > 0, is received.
(b)The receiver acknowledges SeqNumToAck to sender if a frame with sequence number of SeqNumToAck + k, k > 0, is received.
(c)The receiver then sets LFR = SeqNumToAck + 1 and LAF = LFR + RWS-1.
(d)The receiver then sets LFR = SeqNumToAck and LAF = LFR + RWS.
(e)The receiver then sets LFR = SeqNumToAck - 1 and LAF = LFR + RWS.
(+5)【 單選題 】
(5%)12. Let MaxSeqNum be the total number of available sequence numbers.  Assume RWS = SWS, then which of the following relationship is sufficient to distinguish between different frames of the same sequence number ? 
(a)SWS + 1 ≤ MaxSeqNum
(b)SWS ≤ (MaxSeqNum+1)/2
(c)SWS = (MaxSeqNum+1)/2
(d)SWS < MaxSeqNum x 2
(e)SWS < (MaxSeqNum+1)/2
(+6)【 填充題 】
(6%)13. With the CIDR, what is the “prefix” for all the networks 192.4.16 through 192.4.31 ? Assume the prefix is represented as         192.4.a/b, and therefore
      a = _______A_______
      b = _______B_______
 
A=ANS:16
B=ANS:20
(+4)【 複選題 】
(4%)14. Which of the following statements are correct for “Link State” routing protocol ? Assume that each node knows the cost of the link to each of its directly connected neighbors. 
(a)Each node constructs a one dimensional array (a vector) containing the “distances” (costs) to all other nodes and distributes that vector to its immediate neighbors.
(b)Each node constructs a one dimensional array (a vector) containing the “distances” (costs) to all other nodes and distributes that vector to all other nodes.
(c)Each node constructs a one dimensional array (a vector) containing the “distances” (costs) to its immediate neighbors and distributes that vector to its immediate neighbors.
(d)Each node constructs a one dimensional array (a vector) containing the “distances” (costs) to its immediate neighbors and distributes that vector to all other nodes.
(e)The link state packets (LSP) are sent to all other nodes by using reliable flooding algorithm.
(+5)【 複選題 】
(5%)15. Which of the following statements are correct for “flow control and congestion control” ?
(a)Flow control involves preventing senders from overrunning the capacity of the receivers
(b)Flow control involves preventing senders from overrunning the capacity of the networks.
(c)Congestion control involves preventing senders from overrunning the capacity of the networks.
(d)Congestion control involves preventing senders from overrunning the capacity of the receivers.
(e)Congestion control involves preventing senders from overrunning the capacity of the receivers and networks.
(+5)【 單選題 】
(5%) 16. For the Additive Increase Multiplicative Decrease (AIMD) mechanism used in TCP congestion control, TCP does not wait for an entire window’s worth of ACKs to add 1 packet’s worth to the congestion window, but instead increments CongestionWindow by a little (denoted as increment) for each ACK. Which of the following is correct for this increment ?
(a) Increment =1/CongestionWindow
(b) Increment = 1/MSS
(c) Increment = MSS/CongestionWindow
(d) Increment = MSS (MSS/CongestionWindow)
(e) Increment = MSS/(CongestionWindow+MSS);
(+5)【 複選題 】
(5%) 17. Which of the following statements are correct for “slow start” in TCP congestion control ?
(a) Slow start effectively increases the congestion window linearly
(b) Slow start is used to increase the congestion window rapidly from a cold start
(c) When the ACK for a packet arrives TCP source, the TCP source adds 1 packet size of MSS to CongestionWindow
(d) When the ACK for a packet arrives TCP source, the TCP source doubles the size of CongestionWindow
(e) Slow start effectively doubles the number of packets the TCP source has in transit every RTT
(+5)【 複選題 】
(5%) 18. Which of the following statements are correct for a TCP source to handle the “packet lost” in congestion control ?
(a) After receives 3 duplicate ACKs, the CongestionWindow is cut in half and then grows linearly.
(b) After receives 3 duplicate ACKs, the CongestionWindow is set to 1 MSS and then grows linearly.
(c) After timeout event happes, the CongestionWindow is set to 1 MSS; the window then grows exponentially to a threshold, and then grows linearly.
(d) After timeout event happes, the CongestionWindow is set to 1 MSS; the window then grows linearly.
(e) After timeout event happes, the CongestionWindow is cut in half; the window then grows exponentially to a threshold, and then grows linearly.
(+10)【 填充題 】
(10%) 19. Consider the following figure to demonstrate the growth of CongestionWindow size for different “packet lost” events in TCP congestion control. We can use the following events to “describe” the curve in this figure. Initially, the connection is in slow start period with CongestionWindow size = 1 (1MSS).
        Event 1: 3-duplicate ACKs happens at 5th RTT
        Event 2: Timeout happens at 10th RTT
        Event 3: 3-duplicate ACKs happens again at 18th RTT.
        And we have a = 16 (window size), b = 8 (window size), c = 12 (window size), d = 6 (Threshold), e = 10 (window size), f = 5       (Threshold) as shown in the figure.
 
  Now, consider we have the following events:
        Event 1: 3-duplicate ACKs happens at 4th RTT
        Event 2: Timeout happens at 17th RTT
        Event 3: 3-duplicate ACKs happens again at 25th RTT.
        Then we have 
a = _____   (window size), 
b = _____   (window size), 
c = _____   (window size), 
d = _____   (Threshold), 
e = _____   (window size), 
f = ______  (Threshold).
 
And what is the CongestionWindow size at the following points?
At 2nd RTT :__________g______
At 18th RTT :__________h_____
At 23th RTT :__________i______
At 29th RTT :__________j______

a=ANS:8
b=ANS:4
c=ANS:16
d=ANS:8
e=ANS:12
f=ANS:6
g=ANS:2
h=ANS:1
i=ANS:10
j=ANS:9

加入Button後,List 無法選擇

情況:加入Button後,按list沒有反應。
解決辦法:XML裡的Button要加入  android:focusable="false"

範例:
  <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="下一題"
        android:id="@+id/buttonNext"
        android:onClick="clickNext"
        android:focusable="false"
        android:layout_alignBottom="@android:id/list"
        android:layout_alignParentBottom="true"/>

[Android] SQLiteDatabase

參考資料:http://developer.android.com/intl/zh-tw/reference/android/database/sqlite/SQLiteDatabase.html

使用SQLiteDatabase需要import android.database.sqlite.SQLiteDatabase

SQLiteDatabase類別用於管理資料庫,可以Create,Delete,執行SQL Command。

常用Method

voidexecSQL(String sql)
Execute a single SQL statement that is NOT a SELECT or any other SQL statement that returns data.
例如create table,drop table

public void execSQL (String sql)

Added in API level 1
Execute a single SQL statement that is NOT a SELECT or any other SQL statement that returns data.
It has no means to return any data (such as the number of affected rows). Instead, you're encouraged to use insert(String, String, ContentValues),update(String, ContentValues, String, String[]), et al, when possible.
When using enableWriteAheadLogging(), journal_mode is automatically managed by this class. So, do not set journal_mode using "PRAGMA journal_mode'" statement if your app is using enableWriteAheadLogging()
Parameters
sqlthe SQL statement to be executed. Multiple statements separated by semicolons are not supported.
Throws
SQLExceptionif the SQL string is invalid

Public Methods
voidbeginTransaction()
Begins a transaction in EXCLUSIVE mode.
voidbeginTransactionNonExclusive()
Begins a transaction in IMMEDIATE mode.
voidbeginTransactionWithListener(SQLiteTransactionListener transactionListener)
Begins a transaction in EXCLUSIVE mode.
voidbeginTransactionWithListenerNonExclusive(SQLiteTransactionListener transactionListener)
Begins a transaction in IMMEDIATE mode.
SQLiteStatementcompileStatement(String sql)
Compiles an SQL statement into a reusable pre-compiled statement object.
static SQLiteDatabasecreate(SQLiteDatabase.CursorFactory factory)
Create a memory backed SQLite database.
intdelete(String table, String whereClause, String[] whereArgs)
Convenience method for deleting rows in the database.
static booleandeleteDatabase(File file)
Deletes a database including its journal file and other auxiliary files that may have been created by the database engine.
voiddisableWriteAheadLogging()
This method disables the features enabled by enableWriteAheadLogging().
booleanenableWriteAheadLogging()
This method enables parallel execution of queries from multiple threads on the same database.
voidendTransaction()
End a transaction.
voidexecSQL(String sql)
Execute a single SQL statement that is NOT a SELECT or any other SQL statement that returns data.
voidexecSQL(String sql, Object[] bindArgs)
Execute a single SQL statement that is NOT a SELECT/INSERT/UPDATE/DELETE.
static StringfindEditTable(String tables)
Finds the name of the first table, which is editable.
List<Pair<StringString>>getAttachedDbs()
Returns list of full pathnames of all attached databases including the main database by executing 'pragma database_list' on the database.
longgetMaximumSize()
Returns the maximum size the database may grow to.
longgetPageSize()
Returns the current database page size, in bytes.
final StringgetPath()
Gets the path to the database file.
Map<StringString>getSyncedTables()
This method was deprecated in API level 11. This method no longer serves any useful purpose and has been deprecated.
intgetVersion()
Gets the database version.
booleaninTransaction()
Returns true if the current thread has a transaction pending.
longinsert(String table, String nullColumnHack, ContentValues values)
Convenience method for inserting a row into the database.
longinsertOrThrow(String table, String nullColumnHack, ContentValues values)
Convenience method for inserting a row into the database.
longinsertWithOnConflict(String table, String nullColumnHack, ContentValues initialValues, int conflictAlgorithm)
General method for inserting a row into the database.
booleanisDatabaseIntegrityOk()
Runs 'pragma integrity_check' on the given database (and all the attached databases) and returns true if the given database (and all its attached databases) pass integrity_check, false otherwise.
booleanisDbLockedByCurrentThread()
Returns true if the current thread is holding an active connection to the database.
booleanisDbLockedByOtherThreads()
This method was deprecated in API level 16. Always returns false. Do not use this method.
booleanisOpen()
Returns true if the database is currently open.
booleanisReadOnly()
Returns true if the database is opened as read only.
booleanisWriteAheadLoggingEnabled()
Returns true if write-ahead logging has been enabled for this database.
voidmarkTableSyncable(String table, String foreignKey, String updateTable)
This method was deprecated in API level 11. This method no longer serves any useful purpose and has been deprecated.
voidmarkTableSyncable(String table, String deletedTable)
This method was deprecated in API level 11. This method no longer serves any useful purpose and has been deprecated.
booleanneedUpgrade(int newVersion)
Returns true if the new version code is greater than the current database version.
static SQLiteDatabaseopenDatabase(String path, SQLiteDatabase.CursorFactory factory, int flags, DatabaseErrorHandler errorHandler)
Open the database according to the flags OPEN_READWRITE OPEN_READONLY CREATE_IF_NECESSARY and/or NO_LOCALIZED_COLLATORS.
static SQLiteDatabaseopenDatabase(String path, SQLiteDatabase.CursorFactory factory, int flags)
Open the database according to the flags OPEN_READWRITE OPEN_READONLY CREATE_IF_NECESSARY and/or NO_LOCALIZED_COLLATORS.
static SQLiteDatabaseopenOrCreateDatabase(String path, SQLiteDatabase.CursorFactory factory, DatabaseErrorHandler errorHandler)
Equivalent to openDatabase(path, factory, CREATE_IF_NECESSARY, errorHandler).
static SQLiteDatabaseopenOrCreateDatabase(String path, SQLiteDatabase.CursorFactory factory)
Equivalent to openDatabase(path, factory, CREATE_IF_NECESSARY).
static SQLiteDatabaseopenOrCreateDatabase(File file, SQLiteDatabase.CursorFactory factory)
Equivalent to openDatabase(file.getPath(), factory, CREATE_IF_NECESSARY).
Cursorquery(String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy, String limit)
Query the given table, returning a Cursor over the result set.
Cursorquery(boolean distinct, String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy, String limit, CancellationSignal cancellationSignal)
Query the given URL, returning a Cursor over the result set.
Cursorquery(String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy)
Query the given table, returning a Cursor over the result set.
Cursorquery(boolean distinct, String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy, String limit)
Query the given URL, returning a Cursor over the result set.
CursorqueryWithFactory(SQLiteDatabase.CursorFactory cursorFactory, boolean distinct, String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy, String limit, CancellationSignal cancellationSignal)
Query the given URL, returning a Cursor over the result set.
CursorqueryWithFactory(SQLiteDatabase.CursorFactory cursorFactory, boolean distinct, String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy, String limit)
Query the given URL, returning a Cursor over the result set.
CursorrawQuery(String sql, String[] selectionArgs, CancellationSignal cancellationSignal)
Runs the provided SQL and returns a Cursor over the result set.
CursorrawQuery(String sql, String[] selectionArgs)
Runs the provided SQL and returns a Cursor over the result set.
CursorrawQueryWithFactory(SQLiteDatabase.CursorFactory cursorFactory, String sql, String[] selectionArgs, String editTable)
Runs the provided SQL and returns a cursor over the result set.
CursorrawQueryWithFactory(SQLiteDatabase.CursorFactory cursorFactory, String sql, String[] selectionArgs, String editTable, CancellationSignal cancellationSignal)
Runs the provided SQL and returns a cursor over the result set.
static intreleaseMemory()
Attempts to release memory that SQLite holds but does not require to operate properly.
longreplace(String table, String nullColumnHack, ContentValues initialValues)
Convenience method for replacing a row in the database.
longreplaceOrThrow(String table, String nullColumnHack, ContentValues initialValues)
Convenience method for replacing a row in the database.
voidsetForeignKeyConstraintsEnabled(boolean enable)
Sets whether foreign key constraints are enabled for the database.
voidsetLocale(Locale locale)
Sets the locale for this database.
voidsetLockingEnabled(boolean lockingEnabled)
This method was deprecated in API level 16. This method now does nothing. Do not use.
voidsetMaxSqlCacheSize(int cacheSize)
Sets the maximum size of the prepared-statement cache for this database.
longsetMaximumSize(long numBytes)
Sets the maximum size the database will grow to.
voidsetPageSize(long numBytes)
Sets the database page size.
voidsetTransactionSuccessful()
Marks the current transaction as successful.
voidsetVersion(int version)
Sets the database version.
StringtoString()
Returns a string containing a concise, human-readable description of this object.
intupdate(String table, ContentValues values, String whereClause, String[] whereArgs)
Convenience method for updating rows in the database.
intupdateWithOnConflict(String table, ContentValues values, String whereClause, String[] whereArgs, int conflictAlgorithm)
Convenience method for updating rows in the database.
booleanyieldIfContended()
This method was deprecated in API level 3. if the db is locked more than once (becuase of nested transactions) then the lock will not be yielded. Use yieldIfContendedSafely instead.
booleanyieldIfContendedSafely(long sleepAfterYieldDelay)
Temporarily end the transaction to let other threads run.
booleanyieldIfContendedSafely()
Temporarily end the transaction to let other threads run.
Protected Methods
voidfinalize()
Invoked when the garbage collector has detected that this instance is no longer reachable.
voidonAllReferencesReleased()
Called when the last reference to the object was released by a call to releaseReference() or close().



Query範例

public Cursor query (String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, StringorderBy, String limit)

Added in API level 1
Query the given table, returning a Cursor over the result set.
Parameters
tableThe table name to compile the query against.
columnsA list of which columns to return. Passing null will return all columns, which is discouraged to prevent reading data from storage that isn't going to be used.
selectionA filter declaring which rows to return, formatted as an SQL WHERE clause (excluding the WHERE itself). Passing null will return all rows for the given table.
selectionArgsYou may include ?s in selection, which will be replaced by the values from selectionArgs, in order that they appear in the selection. The values will be bound as Strings.
groupByA filter declaring how to group rows, formatted as an SQL GROUP BY clause (excluding the GROUP BY itself). Passing null will cause the rows to not be grouped.
havingA filter declare which row groups to include in the cursor, if row grouping is being used, formatted as an SQL HAVING clause (excluding the HAVING itself). Passing null will cause all row groups to be included, and is required when row grouping is not being used.
orderByHow to order the rows, formatted as an SQL ORDER BY clause (excluding the ORDER BY itself). Passing null will use the default sort order, which may be unordered.
limitLimits the number of rows returned by the query, formatted as LIMIT clause. Passing null denotes no LIMIT clause.
Returns
  • Cursor object, which is positioned before the first entry. Note that Cursors are not synchronized, see the documentation for more details.
See Also