Total Pageviews

Disclaimer

This is a personal web page. The views expressed on this blog are mine and do not necessarily reflect the views of my current employer.

I am currently employed by Morgan Stanley.

November 21, 2010

BigDipper Light: First Asynchronous Sample

Microsoft invents a series of patterns for .NET asynchronous API design. However, no every pattern meet all requirements. For #SNMP, currently the Begin/End pattern is still the most suitable as it can be used in extension methods.

Today I built the first sample for our asynchronous API and soon detected a few issues. Luckily the issues were resolved in our latest change set (http://sharpsnmplib.codeplex.com/SourceControl/changeset/changes/faffeafa130c) and below is the sample code,

using System;
using System.Collections.Generic;
using System.Net;
using Lextm.SharpSnmpLib;
using Lextm.SharpSnmpLib.Messaging;
using Lextm.SharpSnmpLib.Security;

namespace TestAsyncGet
{
    class Program
    {
        static void Main(string[] args)
        {
            GetRequestMessage message = new GetRequestMessage(0,
                VersionCode.V1,
                new OctetString("public"),
                new List<Variable> {new Variable(new ObjectIdentifier("1.3.6.1.1.1.0"))});
            var endpoint = new IPEndPoint(IPAddress.Loopback, 161);
            message.BeginGetResponse(endpoint, new UserRegistry(), endpoint.GetSocket(), ar => {
                var response = message.EndGetResponse(ar);
                Console.WriteLine(response);
            });
            Console.Read();
        }
    }
}

[Update: The API is refined, http://sharpsnmplib.codeplex.com/wikipage?title=600009&referringTitle=KB]

November 20, 2010

BigDipper Light: Asynchronous Calls Coming

It was at the very beginning that users call for asynchronous GetResponse. Well, I did not provide them as I was not happy to provide the same copy of code several times in several places. Besides, .NET Framework offers so many approaches to make synchronous calls in asynchronous way.

But now we are working on our 7.0 release, and with new extension methods there is no longer a need to duplicate code undesirably, so why not give asynchronous calls a chance to shine? Here it is.

In the latest change set, http://sharpsnmplib.codeplex.com/SourceControl/changeset/changes/9e97111b90dc, two methods are added to SnmpMessageExtension. They are BeginGetResponse and EndGetResponse. Because I follow .NET Framework's async pattern, you should be familiar with how to call them correctly.

Note that comparing to GetResponse, the timeout parameter is not present. For asynchronous calls, I think it is no longer necessary to pass timeout in.

The current implementation is subject to change, as the two methods are early experiments. They will be further enhanced so as to meet your high expectations.

Stay tuned.

November 14, 2010

HoneyCell Drops: New Branch for 6.1

We have a new release in plan, 6.1 http://sharpsnmplib.codeplex.com/releases/view/55626. It should be available some day in Dec or Jan I think (not yet determined).

In order to make sure this is "purely" a bug fix release compared to previous ones, I started to use branching. A new branch named 6.1 was created, and it already has two change sets at this moment.

A bug was found when I worked on the default branch for 7.0, http://sharpsnmplib.codeplex.com/workitem/7213. So the first change set was checked in last night. Today I also merged the changes on snmptrapd from default branch to 6.1 branch. Note that this is another nice and small sample to show how to construct SnmpEngine.

With SVN, managing branches can be slow and tough, but now everything is so easy now in Mercurial,

5174205681_9de17383ae_m.jpg

HoneyCell Drops: SNMP Pipeline And Our Agent Demo

A long time ago I wrote an agent demo for #SNMP. It is interesting to know how far we were away from a complete demo. You can still find the post here,

http://www.lextm.com/2008/10/snmp-design-incomplete-agent-demo.html

More than two years passed and now we have 6.0 release out. How about a new post on our agent technical details? This one is for snmpd.

If this is the first time you download #SNMP source code, you will find that snmpd folder is named strangely. Well, our SNMP agent uses a UNIX name :)

When you open snmpd.csproj in Visual Studio (or another IDE), you should first check what are its references.

Dependencies

There are several references you should pay attention to,
  • SharpSnmpLib*.dll are our #SNMP Library components.
  • *Unity*.dll are Microsoft Unity Application Block components.
IoC, Facade, and Pipeline

As Unity is used, all necessary construction is performed by it. We no longer need to construct an Agent object, because that class is too old to be used. We try to construct an SnmpEngine instead.

SnmpEngine is the facade that you should put on top. It is a very complex class that replaces our old Agent. To construct it, we need: an EngineGroup object, which contains all engine global objects; A Listener object, which monitors incoming SNMP message; An SnmpApplicationFactory, who manages the pipelines.

SnmpApplicationFactory creates new pipelines when its pipeline pool is full of busy pipelines. The objects we pass to its constructor finally goes into each pipeline as they are shared among them (at this moment).

A pipeline is in fact an SnmpApplication object. It has several processing phases and each phase utilizes a few helper classes, which you can extend.

An SNMP message captured by Listener will be packaged as an SnmpContext object. This context object is passed to the pipeline and processed in each phase to generate a correct response message.

Pipeline in Details

Currently (in 6.0) we only have four phases in the pipeline,
  1. Authentication
  2. Request handler mapping
  3. Request handler executing
  4. Logging request
After phase 4, the pipeline is reused by SnmpApplicationFactory for future messages.

We may add an authorization phase to achieve user based authorization, but it is not yet designed and implemented.

*Authentication
Via app.config you can see how the primary membership provider (ComposedMembershipProvider) is created and injected into the pipeline. The request is checked by the provider and dropped if it does not contain a proper community name.

ComposedMembershipProvider is a special membership provider, who allows you to support different SNMP versions. If you only target a specific version, you can use the version specific provider as primary one.

*Request handler mapping
For authenticated message, in this phase it is verified again and mapped to a message handler.

Message handlers are injected to the pipeline, too. So you can analyze app.config to know how many handlers are there already, and how each registers its interested message (SNMP version and verb).

For example, GetV1MessageHandler is only interested in v1 GET messages, while GetMessageHandler in v2 and v3 GET messages.

Carefully configure the existing handlers, you can achieve different SNMP engine configurations, so as to meet different requirements.

*Request handler executing
Once a message handler is found for the message, in this phase the handler performs the requested operation and generate a response message.

You should notice that *V1MessageHandler classes follow RFC 1157 specification to handle v1 messages, while other handler classes follow RFC 3416 to handle v2 and v3 messages.

*Logging request
In this phase the response message is sent back, while the logger logs the processing into log files.

ObjectStore and ISnmpObject

When a handler tries to do a typical SNMP operation, it looks into the ObjectStore object to locate the specified object.

Currently we only have a few sample objects created, to test out the pipeline. You can find them under Lextm.SharpSnmpLib.Objects namespace.

If you want to write more objects, you can follow our sample ones.

ObjectStore is not yet thread safe, which will be improved in the future.

The Last Words

You should take a look at MainForm.cs and read what extra lines are required to configure the SnmpEngine object, how to start and stop it.

As the sample is released under MIT license, you can feel free to use it as a starting point of your own SNMP agent.

Our browser sample also uses the pipeline to handle trap messages, and once you are familiar with snmpd, you can switch to it to learn how to construct a browser side pipeline accordingly.

The pipeline greatly enhances our message processing infrastructure, and you should spare some time to go through its current status.

A lot of improvements will be provided in the future to further enhance this useful design.

Stay tuned.

November 13, 2010

BigDipper Light: Planned Release Details

HoneyCell 6.0 is our last release that has some binaries targeting .NET 2.0 SP2. This is because .NET 2.0 SP2 support is not yet expired. As BigDipper is to be released in next May, all 7.0 binaries will be targeting .NET 3.5 SP1 (.NET 2.0 SP2 support expires next April).

Therefore, today I started to clean up .NET 2.0 stuffs in our master/default branch. Well, it is amazing! All duplicate code that live for a long time is removed completely, and new extension methods are created.


Have to confess that there are lots of changes today already, and luckily we have enough test cases to ensure that the changes do not break anything critical.

Stay tuned.

HoneyCell Drops: Final Release on Nov 12

After five beta builds, the final release of #SNMP 6.0 became available on Nov 12. 

Because this time the release notes are already embedded in the download page, you can take a look at it while your browser downloads the packages for you.


Help docs are packaged in a separate ZIP.

Please pay attention to the (Breaking) changes if you want to migrate from an old release.

Any question or suggestion can be discussed here, http://sharpsnmplib.codeplex.com/discussions

November 09, 2010

HoneyCell Drops: Final Comes This Weekend

Probably you heard from my tweets that we are going to release #SNMP 6.0 final this weekend, so beta 5 is the last beta,

The new API is much more stable now, so you can try them out if you like.

The help files will be available in the final release package.

Stay tuned.