Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

47 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

nSNMP - Modern .NET SNMP Library

.NET 9.0 License Build Status

A modern, high-performance SNMP (Simple Network Management Protocol) library for .NET 9.0, designed with clean architecture principles and comprehensive protocol support.

๐Ÿš€ Features

Protocol Support

  • SNMPv1 - Full support for basic SNMP operations
  • SNMPv2c - Community-based authentication with enhanced PDUs
  • SNMPv3 - Advanced security with authentication and privacy (USM)
    • Authentication protocols: MD5, SHA1, SHA256, SHA384, SHA512
    • Privacy protocols: DES, AES128, AES192, AES256

Core Capabilities

  • โœ… SNMP Operations: GET, GET-NEXT, GET-BULK, SET, WALK
  • โœ… SNMP Agent: Build custom SNMP agents with scalar and table providers
  • โœ… Trap Support: Send and receive SNMP traps
  • โœ… MIB Support: Parse and manage MIB files with symbolic OID resolution
  • โœ… Async/Await: Fully asynchronous operations with cancellation support
  • โœ… Performance: Optimized data structures and minimal allocations
  • โœ… Extensibility: Clean abstractions and dependency injection support

๐Ÿ“ฆ Project Structure

nSNMP/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ nSNMP.Abstractions/     # Core interfaces and contracts
โ”‚   โ”œโ”€โ”€ nSNMP.Core/             # Main SNMP implementation
โ”‚   โ”œโ”€โ”€ nSNMP.SMI/              # Structure of Management Information
โ”‚   โ”œโ”€โ”€ nSNMP.MIB/              # MIB parsing and management
โ”‚   โ””โ”€โ”€ nSNMP.Extensions/       # Fluent API and extensions
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ nSNMP.Core.Tests/       # Unit tests
โ”‚   โ”œโ”€โ”€ nSNMP.Integration.Tests/# Integration tests
โ”‚   โ”œโ”€โ”€ nSNMP.Benchmarks/       # Performance benchmarks
โ”‚   โ””โ”€โ”€ nSNMP.Fuzz/             # Fuzzing tests
โ””โ”€โ”€ samples/
    โ”œโ”€โ”€ SimpleSnmpGet/           # Basic SNMP GET example
    โ”œโ”€โ”€ SnmpScout/              # Network discovery tool
    โ””โ”€โ”€ SnmpTrapReceiver/       # Trap receiver service

๐Ÿ”ง Installation

Prerequisites

  • .NET 9.0 SDK or later
  • Visual Studio 2022, JetBrains Rider, or VS Code

Package Installation

# Coming soon to NuGet
dotnet add package nSNMP

Building from Source

git clone https://github.com/johmnym/nSNMP.git
cd nSNMP
dotnet build
dotnet test

๐Ÿ“– Quick Start

Basic SNMP GET Operation

using nSNMP.Manager;
using System.Net;

// Create SNMP client
var endpoint = new IPEndPoint(IPAddress.Parse("192.168.1.1"), 161);
using var client = new SnmpClient(endpoint, SnmpVersion.V2c, "public");

// Perform GET operation
var result = await client.GetAsync("1.3.6.1.2.1.1.1.0"); // sysDescr
Console.WriteLine($"System Description: {result[0].Value}");

Fluent API (Extensions)

using nSNMP.Extensions;

var client = SnmpClient.Create()
    .Target("192.168.1.1", 161)
    .Version(SnmpVersion.V2c)
    .Community("public")
    .Timeout(TimeSpan.FromSeconds(5))
    .Build();

// Fluent GET operation
var results = await client
    .Get("1.3.6.1.2.1.1.1.0", "1.3.6.1.2.1.1.3.0")
    .ExecuteAsync();

// Table walk
var interfaces = await client
    .Walk("1.3.6.1.2.1.2.2.1")
    .ToListAsync();

SNMPv3 Secure Operations

using nSNMP.Manager;
using nSNMP.Security;

// Create SNMPv3 credentials
var credentials = V3Credentials.AuthPriv(
    userName: "admin",
    authProtocol: AuthProtocol.SHA256,
    authPassword: "auth_password123",
    privProtocol: PrivProtocol.AES256,
    privPassword: "priv_password456"
);

// Create SNMPv3 client
using var client = new SnmpClientV3(endpoint, credentials);

// Discover engine parameters
await client.DiscoverEngineAsync();

// Perform secure GET
var result = await client.GetAsync("1.3.6.1.2.1.1.1.0");

Creating an SNMP Agent

using nSNMP.Agent;

// Create SNMP agent
var agent = new SnmpAgentHost("public", "private");

// Register scalar values
agent.MapScalar("1.3.6.1.2.1.1.1.0",
    OctetString.Create("My SNMP Agent v1.0"));
agent.MapScalar("1.3.6.1.2.1.1.3.0",
    TimeTicks.Create(123456));

// Register table provider
agent.RegisterTableProvider(
    ObjectIdentifier.Create("1.3.6.1.2.1.2.2.1"),
    new InterfaceTableProvider());

// Start the agent
await agent.StartAsync(port: 161);

MIB Management

using nSNMP.MIB;

// Load MIB files
var mibManager = new MibManager();
mibManager.LoadMibFile("RFC1213-MIB.mib");
mibManager.LoadMibDirectory("/usr/share/snmp/mibs");

// Resolve OIDs
var oid = mibManager.NameToOid("sysDescr");        // Returns 1.3.6.1.2.1.1.1
var name = mibManager.OidToName("1.3.6.1.2.1.1.1"); // Returns "system.sysDescr"

// Get MIB object details
var obj = mibManager.GetObject("sysDescr");
Console.WriteLine($"OID: {obj.Oid}");
Console.WriteLine($"Type: {obj.Syntax}");
Console.WriteLine($"Access: {obj.Access}");

๐Ÿ› ๏ธ Advanced Features

Circuit Breaker Pattern

var client = SnmpClient.Create()
    .Target("192.168.1.1")
    .WithCircuitBreaker(
        failureThreshold: 5,
        recoveryTimeout: TimeSpan.FromSeconds(30))
    .Build();

Retry Policies

var client = SnmpClient.Create()
    .Target("192.168.1.1")
    .WithRetryPolicy(
        maxRetries: 3,
        backoffMultiplier: 2.0)
    .Build();

Bulk Operations

// Efficient bulk retrieval
var results = await client.GetBulkAsync(
    nonRepeaters: 2,
    maxRepetitions: 10,
    oids: new[] { "1.3.6.1.2.1.1", "1.3.6.1.2.1.2" }
);

๐Ÿงช Testing

Running Tests

# Run all tests
dotnet test

# Run specific test project
dotnet test tests/nSNMP.Core.Tests

# Run with coverage
dotnet test --collect:"XPlat Code Coverage"

# Run integration tests
dotnet test tests/nSNMP.Integration.Tests

# Run benchmarks
dotnet run -c Release --project tests/nSNMP.Benchmarks

Test Categories

  • Unit Tests: Fast, isolated tests for individual components
  • Integration Tests: Tests with real SNMP agents (using Docker)
  • Fuzz Tests: Security and robustness testing
  • Benchmarks: Performance measurements and comparisons

๐Ÿ“Š Performance

The library is optimized for high performance with:

  • Sorted collections for O(log n) OID lookups
  • Memory pooling for reduced allocations
  • Async I/O for scalable operations
  • Minimal boxing with generic value types
  • Thread-safe concurrent operations

Benchmark Results (2025-09-28)

Performance measurements on Apple M2, .NET 9.0:

Operation Mean Time Memory Description
OID Parsing 1.831 ฮผs 1.2 KB Parse OID string to object
VarBind Creation 319.7 ns 32 B Create SNMP variable binding
SHA256 Auth 1.307 ฮผs 144 B SNMPv3 authentication

Key Performance Metrics:

  • โšก Ultra-fast VarBind creation at ~320 nanoseconds - critical for high-throughput SNMP operations
  • ๐Ÿš€ Efficient OID parsing at ~1.8 microseconds - excellent for protocol processing
  • ๐Ÿ”’ Strong security performance with SHA256 authentication at ~1.3 microseconds
  • ๐Ÿ’พ Memory efficient with minimal allocations across all operations
  • ๐Ÿ“ˆ Consistent performance with low variance across all benchmarks

Run full benchmarks with: dotnet run -c Release --project tests/nSNMP.Benchmarks

๐Ÿ”’ Security

SNMPv3 Security Features

  • Authentication: HMAC-MD5, HMAC-SHA1/SHA2 family
  • Privacy: DES-CBC, AES-CFB (128/192/256 bit)
  • Timeliness: Protection against replay attacks
  • User-based Security Model (USM): Per-user authentication and privacy

Best Practices

  • Always use SNMPv3 with authentication and privacy in production
  • Rotate credentials regularly
  • Use strong passwords (minimum 8 characters)
  • Implement access control lists (ACLs) on agents
  • Monitor and log SNMP access attempts

๐Ÿ“š Documentation

API Documentation

Full API documentation is available at: [Coming Soon]

Common OIDs Reference

System Group:
1.3.6.1.2.1.1.1.0 - sysDescr
1.3.6.1.2.1.1.2.0 - sysObjectID
1.3.6.1.2.1.1.3.0 - sysUpTime
1.3.6.1.2.1.1.4.0 - sysContact
1.3.6.1.2.1.1.5.0 - sysName
1.3.6.1.2.1.1.6.0 - sysLocation

Interface Table:
1.3.6.1.2.1.2.2.1.1 - ifIndex
1.3.6.1.2.1.2.2.1.2 - ifDescr
1.3.6.1.2.1.2.2.1.5 - ifSpeed
1.3.6.1.2.1.2.2.1.8 - ifOperStatus

๐Ÿค Contributing

We welcome contributions!

Development Setup

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Code Style

  • Follow C# coding conventions
  • Use meaningful variable and method names
  • Add XML documentation for public APIs
  • Write unit tests for new features
  • Ensure all tests pass before submitting PR

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ“ฎ Support

๐Ÿ—บ๏ธ Roadmap

v1.0 (Current)

  • โœ… Core SNMP v1/v2c/v3 implementation
  • โœ… Basic MIB support
  • โœ… Agent framework
  • โœ… Fluent API

v1.1 (Planned)

  • ๐Ÿ”„ Enhanced MIB compiler
  • ๐Ÿ”„ SNMP proxy support
  • ๐Ÿ”„ Performance optimizations
  • ๐Ÿ”„ Additional security providers

v2.0 (Future)

  • ๐Ÿ“‹ SNMP over TLS (RFC 6353)
  • ๐Ÿ“‹ IPv6 support improvements
  • ๐Ÿ“‹ Cloud-native features
  • ๐Ÿ“‹ Distributed tracing integration

Built with โค๏ธ

About

SNMP for .NET

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages