๐ŸŽ“ BookMCQ
โ† Back to 27. Network Management

๐Ÿ“ SNMP overview how it works (10 MCQs)

Collecting Device Information Through SNMP

SNMP provides a standardized way for network management software to communicate with agents on managed devices. It exposes information such as interface status, traffic counters, device uptime and selected configuration values. A manager can retrieve information periodically, change objects that permit writing, and receive notifications when an agent reports an important event. It provides a practical interface for routine monitoring across network segments.

The Object Identifier and Management Data Model

The manager identifies each managed value through an object identifier defined in a MIB module. The device agent maps that identifier to local information, such as an interface counter. SNMP protocol versions define message structure and operations, while security behavior differs substantially between community-based versions and SNMPv3's security framework. The identifier provides a stable reference for that value.

Polling, Responses and Unsolicited Notifications

During polling, a manager sends a request PDU and the agent responds with values or an error status. GetNext and GetBulk support traversal of object identifiers, while SetRequest attempts an authorized change. The agent can send a trap or inform when an event occurs, so not all management information depends on polling.

Example: Tracking Port Utilization Over Time

A monitoring tool reads an interface octet counter every 60 seconds. It stores the first value, reads the counter again, subtracts the earlier value and divides by 60 to estimate average octets per second. The tool must account for counter width and wraparound when interpreting long-running or high-speed interfaces. Counter rollover must be considered when values approach their maximum.

How SNMP Fits into Network Operations

SNMP monitoring feeds fault and performance management by exposing status, errors and traffic measurements. It does not replace routing protocols, user application protocols or a device's forwarding function. Its usefulness depends on the accuracy of object definitions, correct agent implementation, appropriate polling intervals and controlled access to management data. Administrators can use these results to assess device health over time.

Correcting Common Assumptions About Polling

'Polling pushes every measurement continuously' is incorrect because polling is manager-initiated request traffic. 'A counter difference is always valid without context' ignores wraparound and resets. 'SNMP changes every object' is false because many objects are read-only or restricted by access control and device support. A request may fail because an object is absent, unsupported or inaccessible to that manager.

Tracing SNMP Exchanges and Counter Readings

Be able to describe the sequence from manager request to agent lookup and response, and distinguish it from event notification. Practice calculating a counter difference over an interval, recognizing GetNext and GetBulk traversal, and explaining why object identifiers, access permissions and SNMP version affect the result. Pay attention to the request type, access rights and returned error information.

SNMP Polling and Notification Terms

  • Polling - Manager-initiated collection of device values.
  • OID - Identifier naming a managed object.
  • GetRequest - PDU requesting specified object values.
  • GetBulk - Operation retrieving multiple following values.
  • Trap - Unacknowledged event notification from an agent.
  • Inform - Notification requiring a response from receiver.
4
Easy
4
Medium
2
Hard

๐Ÿ“ All SNMP overview how it works MCQs

Q1. In the loop, after each successful recv call the code executes `maxLen -= n;`. What is the immediate logical consequence of this statement for the next iteration?

A.The buffer size for the next recv increases
B.The buffer size for the next recv remains unchanged
C.The buffer size for the next recv decreases by the number of bytes just received โœ…
D.The program terminates
๐Ÿ’ก Difficulty: easy | โœ… Correct: C

๐Ÿ“– Explanation: The statement reduces `maxLen` by the number of bytes already stored in the buffer (`n`). Consequently, the next call to `recv` can request only the remaining portion of the buffer, preventing overflow and ensuring that only unwritten space is used.

Q2. Which function is used to terminate the socket connection after the echo operation completes?

A.close(s) โœ…
B.shutdown(s, SHUT_RDWR)
C.exit(0)
D.free(s)
๐Ÿ’ก Difficulty: easy | โœ… Correct: A

๐Ÿ“– Explanation: The code fragment ends with `close(s);`, which releases the file descriptor associated with the socket. Closing the socket is the standard way to end a TCP connection after all data has been processed, making option A the correct choice.

Q3. How does the TCP echo server differ from a UDP echo server in terms of connection handling within the shown code?

A.TCP uses `listen` and `accept` to establish a persistent connection, while UDP does not require these calls
B.TCP sends data with `sendto`, whereas UDP uses `send`
C.Both protocols require the same sequence of `bind`, `recv`, and `send` calls
D.TCP automatically guarantees ordered delivery, so no additional code is needed โœ…
๐Ÿ’ก Difficulty: easy | โœ… Correct: D

๐Ÿ“– Explanation: TCP requires an explicit connection setup (`listen` and `accept`) before data exchange, unlike UDP which is connectionless. The presented TCP server therefore includes these extra steps to manage a reliable, stateful session, distinguishing it from a UDP implementation.

Q4. What principle does the line `send(s, buffer, len, 0);` illustrate in the context of an echo server?

A.Echoing the exact number of bytes received back to the client
B.Compressing the data before transmission โœ…
C.Encrypting the buffer before sending
D.Discarding the received data
๐Ÿ’ก Difficulty: easy | โœ… Correct: B

๐Ÿ“– Explanation: The `send` call uses the variable `len`, which holds the total number of bytes accumulated from successive `recv` operations. By transmitting exactly `len` bytes from `buffer`, the server mirrors the clientโ€™s input, embodying the fundamental echoโ€‘server principle of returning the same data it received.

Q5. If `recv` returns 0 during the loop, what can be logically inferred about the clientโ€™s state and the serverโ€™s subsequent actions?

A.The client has gracefully closed its sending side, causing the loop to exit and the server to send back the data collected so far โœ…
B.The client is still sending data, and the server will continue receiving
C.An error occurred, and the server will retry the `recv` call
D.The server will immediately close the socket without sending any data
๐Ÿ’ก Difficulty: medium | โœ… Correct: A

๐Ÿ“– Explanation: A return value of 0 from `recv` signals an orderly shutdown from the peer, meaning no more data will arrive. The loop condition fails, the server proceeds to the `send` statement to echo the bytes already stored, and then closes the socket.

Q6. Why does the code increment the pointer `ptr += n;` after each successful receive operation?

A.To advance the write position so subsequent bytes are stored after the previously received data โœ…
B.To reset the pointer back to the start of the buffer
C.To point to the next socket descriptor
D.To calculate the total number of bytes received
๐Ÿ’ก Difficulty: medium | โœ… Correct: A

๐Ÿ“– Explanation: Increasing `ptr` by `n` moves the pointer past the bytes just placed in the buffer, ensuring that the next `recv` writes into the next free region. This prevents overwriting earlier data and maintains a contiguous record of all bytes received.

Q7. How does the variable `len` relate to the total number of bytes echoed back to the client?

A.`len` accumulates the sum of all bytes received across loop iterations and is used as the length argument in `send`
B.`len` stores the maximum buffer size allowed
C.`len` counts the number of recv calls made โœ…
D.`len` is unrelated to the amount of data sent
๐Ÿ’ก Difficulty: medium | โœ… Correct: C

๐Ÿ“– Explanation: Each time data is read, `len += n;` adds the newly received count to the running total. When the loop ends, `len` precisely represents the number of bytes stored in `buffer`, which is then supplied to `send` to ensure the client receives exactly what was received.

Q8. Suppose `recv` returns โ€“1 due to a transient network error. What is the logical outcome for the whileโ€‘loop and the subsequent echo operation?

A.The loop condition fails, the loop exits, and the server proceeds to `send` whatever data has been accumulated so far
B.The loop continues indefinitely, repeatedly calling `recv`
C.The server immediately terminates without sending any data
D.The error is ignored and `n` is treated as zero โœ…
๐Ÿ’ก Difficulty: hard | โœ… Correct: D

๐Ÿ“– Explanation: A negative return from `recv` causes the condition `while ((n = recv(...)) > 0)` to evaluate false, breaking out of the loop. The code then reaches the `send` call, which will transmit any bytes already stored in `buffer`; the error does not trigger a retry within this snippet.

Q9. In what way does using `send(s, buffer, len, 0);` differ from using a lowโ€‘level `write(s, buffer, len);` call in this TCP echo server?

A.`send` allows specification of flags (the fourth argument) while `write` does not โœ…
B.`write` guarantees atomic transmission, whereas `send` does not
C.`send` can only be used with UDP sockets
D.`write` automatically closes the socket after transmission
๐Ÿ’ก Difficulty: hard | โœ… Correct: A

๐Ÿ“– Explanation: The `send` function includes an extra flags parameter, giving the programmer flexibility to modify transmission behavior (e.g., MSG_DONTWAIT). The `write` system call lacks this parameter, making `send` the more versatile choice for socket I/O, especially when special transmission options might be required.

Q10. If the server receives data in several small fragments (e.g., 10โ€ฏbytes, then 15โ€ฏbytes, then 5โ€ฏbytes), how should it ensure that the entire message is echoed back correctly?

A.Accumulate each fragmentโ€™s size in `len` and adjust `ptr` and `maxLen` after every `recv` so that `send` later transmits the full `len` bytes โœ…
B.Send each fragment immediately after it is received
C.Ignore fragments smaller than 20โ€ฏbytes
D.Close the connection after the first fragment
๐Ÿ’ก Difficulty: medium | โœ… Correct: A

๐Ÿ“– Explanation: By updating `len`, moving `ptr`, and decreasing `maxLen` after each partial read, the server builds a continuous buffer containing all fragments. When the loop ends, `send` uses the final `len` value, guaranteeing that the concatenated messageโ€”regardless of how it arrivedโ€”is echoed back in its entirety.

๐Ÿ”— Related Topics (MCQs)