=====================================================================
 LAB 02 VIVA - SNMP-BASED NETWORK DEVICE MONITORING
=====================================================================

----- A. SNMP BASICS -----
Q1. What is SNMP?
A.  Simple Network Management Protocol - an application-layer protocol (UDP 161 for
    requests, UDP 162 for traps) used by a manager (NMS) to monitor and configure
    devices that run an agent.

Q2. Name the SNMP components.
A.  Manager (NMS), Agent (snmpd on the device), MIB (tree of managed objects),
    and the protocol operations. Objects are identified by OIDs.

Q3. What is a MIB and an OID?
A.  MIB = Management Information Base, a hierarchical database of objects.
    OID = dotted numeric path to an object, e.g. sysName = 1.3.6.1.2.1.1.5.0
    (iso.org.dod.internet.mgmt.mib-2.system.sysName.0). ".0" = scalar instance.

Q4. Differences between SNMPv1, v2c and v3?
A.  v1: community string, 32-bit counters only. v2c: adds GetBulk and 64-bit counters,
    still community-based (clear text). v3: authentication (MD5/SHA), encryption (DES/AES),
    user-based security model and access control - the only secure version.

Q5. What is a community string?
A.  Shared-secret "password" for v1/v2c (public = read-only, private = read-write by
    convention). Sent in plain text, so change defaults and restrict by source IP.

Q6. List the main SNMP operations.
A.  Get, GetNext, GetBulk (v2c+), Set, Response, Trap, Inform (v2c+).

Q7. Difference between trap and inform?
A.  Trap is an unacknowledged agent->manager notification; inform is acknowledged by the
    manager and retransmitted if lost.

Q8. Which transport does SNMP use and why?
A.  UDP - lightweight, connectionless, works even when the network is congested/faulty.
    Drawback: no delivery guarantee.

----- B. TASK 1 : snmpget -----
Q9. Difference between snmpget, snmpgetnext, snmpwalk and snmpbulkwalk?
A.  snmpget: exact OID. snmpgetnext: the next OID in the tree. snmpwalk: repeated GetNext
    over a subtree. snmpbulkwalk: same using GetBulk, faster.

Q10. What do sysName, sysDescr, sysUpTime represent? Give OIDs.
A.  sysName 1.3.6.1.2.1.1.5.0 - administratively assigned hostname.
    sysDescr 1.3.6.1.2.1.1.1.0 - hardware/OS description.
    sysUpTime 1.3.6.1.2.1.1.3.0 - time since the SNMP agent (re)initialised, in
    TimeTicks = hundredths of a second (so 8,640,000 ticks = 1 day).

Q11. Why is ".0" appended to sysName?
A.  Scalar objects have a single instance, index 0. Tabular objects use their row index.

Q12. How do you verify SNMP connectivity? What does "Timeout: No Response" mean?
A.  A successful snmpget on sysName. Timeout = agent not running/reachable, UDP 161 blocked,
    wrong community or wrong version, or ACL (view) restriction.

Q13. Why sysUpTime and not 'uptime' of the host?
A.  sysUpTime is agent restart time; hrSystemUptime (HOST-RESOURCES-MIB) is host boot time.
    A reset sysUpTime means the agent/device restarted - useful for spotting reboots.

Q14. Meaning of snmpget options -v2c, -c, -On, -Oqv?
A.  -v version, -c community, -On numeric OIDs, -Oqv quick print values only.

----- C. TASK 2 : snmpwalk / IF-MIB -----
Q15. Which MIB gives interface data? Which OID subtree?
A.  IF-MIB. ifTable = 1.3.6.1.2.1.2.2; ifXTable (64-bit, names, high speed) = 1.3.6.1.2.1.31.1.1.

Q16. Explain ifAdminStatus and ifOperStatus values.
A.  1 up, 2 down, 3 testing (oper adds 4 unknown, 5 dormant, 6 notPresent, 7 lowerLayerDown).
    Admin = what the administrator configured; Oper = actual state.

Q17. What does admin=up, oper=down indicate?
A.  A fault: cable unplugged, peer port down, SFP failure, or err-disable - the port is
    meant to work but the link is not up. (admin=down, oper=down is intentional shutdown.)

Q18. What is ifIndex? Is it stable across reboots?
A.  Unique integer per interface (row index of ifTable). Not guaranteed stable on some
    devices; use ifName/ifDescr or ifAlias to confirm identity.

Q19. Which objects hold octet counters? Why Counter32 vs Counter64?
A.  ifInOctets (…2.2.1.10) and ifOutOctets (…2.2.1.16): Counter32. ifHCInOctets/ifHCOutOctets
    (…31.1.1.1.6 / .10): Counter64. A 32-bit counter wraps at 4,294,967,296 - at 100 Mbit/s
    in ~5.7 min, at 1 Gbit/s in ~34 s - so HC counters are required for fast links.

Q20. What are ifInErrors, ifInDiscards, ifInUcastPkts?
A.  Errors: packets with errors (CRC, framing). Discards: valid packets dropped (buffer
    full / congestion). UcastPkts: unicast packet counts (used as denominator for rates).

Q21. Meaning of ifSpeed vs ifHighSpeed?
A.  ifSpeed: bit/s as Gauge32 (maxes out at ~4.29 Gbit/s). ifHighSpeed: Mbit/s, used for
    links >= 10 Gbit/s.

Q22. What is a Counter type? Can you use a single reading?
A.  A monotonically increasing value that wraps to 0. A single reading is meaningless -
    you need two samples and their difference.

----- D. TASK 3 : throughput & utilisation -----
Q23. State the formulae.
A.  delta = octets2 - octets1 ; bps = delta x 8 / interval ;
    Util % = bps / ifSpeed x 100.
    Full duplex: compute In and Out separately (take max). Half duplex: (delta_in+delta_out) x 8 /
    (interval x speed) x 100.

Q24. Worked example: Δ in-octets = 12,500,000 over 10 s on a 100 Mbit/s port.
A.  12,500,000 x 8 / 10 = 10,000,000 bit/s = 10 Mbit/s -> 10 % utilisation.

Q25. How do you handle counter wrap?
A.  If new < old, add 2^32 (or 2^64): delta = new + 2^bits - old. Valid if at most one wrap per
    interval - so poll often enough or use 64-bit counters. A restart of the agent also
    resets counters (check sysUpTime).

Q26. Why multiply by 8?
A.  Octets are bytes; link speed is in bits per second.

Q27. How does the polling interval affect accuracy?
A.  Short intervals show bursts but are noisy and load the device; long intervals smooth the
    value and hide bursts. 30-300 s is typical; use actual elapsed time (not the sleep value)
    in the formula, as the script does.

Q28. Why can utilisation read >100 % in your lab?
A.  Loopback reports a nominal ifSpeed of 10 Mbit/s but is software-limited by CPU, not by
    link speed. Also, In and Out traffic of lo are the same packets. On real hardware >100 %
    indicates a wrong ifSpeed or counter wrap/timing error.

Q29. Why does eth0 show speed 0 / n/a?
A.  Virtual NICs (VM/container) do not negotiate a speed, so ifSpeed is 0 - no division.

----- E. TASK 4 : abnormal conditions & thresholds -----
Q30. What abnormal condition did you identify?
A.  (Fill with your result.) e.g. veth0: ifAdminStatus=up but ifOperStatus=down (lowerLayerDown)
    = link failure; or an error rate of 3.5 % (CRC/duplex mismatch); or utilisation > 85 %.

Q31. What alert threshold do you recommend and why?
A.  Link down (admin up, oper != up): critical immediately (2 consecutive polls to avoid
    flaps). Utilisation: warning 70 %, critical 85 % averaged over 5 min. Error rate:
    warning 0.1 %, critical 1 % of packets. Discards: warning 0.5 %. Rationale: healthy
    links should have ~0 errors; 70 % leaves headroom for bursts and planning; averaging
    avoids false alarms from momentary spikes.

Q32. Causes of high input errors?
A.  Bad cable/connector, duplex mismatch, EMI, faulty NIC/SFP, speed mismatch.

Q33. Causes of discards without errors?
A.  Congestion/oversubscription, small buffers, QoS drops, microbursts, ACL drops.

Q34. What is alert fatigue and how do you avoid it?
A.  Too many false/low-value alerts cause real ones to be ignored. Use sustained thresholds,
    hysteresis, severity levels, dependency suppression (e.g. don't alert on child ports when
    the uplink is down).

Q35. Polling vs traps - which is better?
A.  Complementary. Traps (linkDown/linkUp) give instant notification; polling gives trends,
    detects lost traps and silent failures. Production uses both.

Q36. Which tools would you use for continuous monitoring?
A.  Nagios, Zabbix, LibreNMS, PRTG, Prometheus + snmp_exporter + Grafana, MRTG/Cacti
    (RRD graphs).

----- F. EXTRA / CONFIGURATION -----
Q37. How is the agent configured here?
A.  /etc/snmp/snmpd.conf: "agentaddress udp:161", "rocommunity labpublic default" (read-only),
    sysLocation, sysContact, sysName. Restart with systemctl restart snmpd.

Q38. How would you secure SNMP?
A.  Use SNMPv3 authPriv (createUser + rouser), restrict by source IP/view, firewall UDP 161,
    remove default 'public'/'private', read-only access unless writes are required.

Q39. Create an SNMPv3 user quickly?
A.  sudo net-snmp-create-v3-user -ro -A authpass123 -a SHA -X privpass123 -x AES labuser
    snmpget -v3 -l authPriv -u labuser -a SHA -A authpass123 -x AES -X privpass123 127.0.0.1 sysName.0

Q40. What is RMON and how does it differ from basic SNMP polling?
A.  RMON (RFC 2819) lets the device itself collect statistics, history and alarms
    (thresholds with rising/falling events), reducing polling load.

----- G. QUICK ONE-LINERS -----
 * SNMP port: UDP 161 (queries), 162 (traps)     * Timeticks: 1/100 s
 * snmpwalk = repeated GetNext                    * v2c Counter64 = HC counters
 * Throughput = Δoctets x 8 / Δt                  * Util = bps / speed x 100
 * Admin-up + Oper-down = fault                   * Never rely on one counter sample
