Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

C/C++

The C++ Chain of Responsibility Pattern and Network Events


A Link Failure in The Service Provider Network

Let's assume that the network has been operating with no problems when suddenly Link 1 (in Figure) 1 fails. Such a failure could be due to an errant digger cutting a fiber optic cable in two. The result of such a link failure is that our LSP123 has to now find another path, such as R2, R7, R6, & R5. Fortunately, all the traffic can now be moved onto the backup LSP. So, the enterprise end users should see no immediate service interruption. However, notice that the backup LSP has only 8Mbps bandwidth, whereas the main LSP has 10Mbps. So, there is a possibility of congestion on the backup LSP.

One or both of R2 and R3 will pick up the failure of Link 1 with the result that an event message will be sent to the network management system (NMS). So, we've lost the link and the notification message has been passed into the NMS. Let's now take a quick look inside the NMS.

An NMS Under The Hood

A generic NMS consists of numerous interacting applications. One such application handles the thousands of different events that can occur. Let's see what a generic C++-based event handler might look like in Listing 1.

typedef int Event;
const Event No_Event_Support = -1;

class EventHandler {
public:
  EventHandler(EventHandler* = 0, Event = No_Event_Support);
  virtual bool HasEventSupport();
  virtual void SetHandler(EventHandler*, Event);
  virtual void HandleEvent();
private:
  EventHandler* _successor;
  Event _event; };

Listing 1: A generic network event handler class.

When is the handler in Listing 1 used? Well, it's used when an entity (such as an LSP) manages a network event, such as the link failure we saw in Figure 1. Each managed entity in our fictitious NMS models a real world entity and is a subclass of EventHandler. This means that each such entity has the ability to handle and (hopefully) respond in a meaningful fashion to events.

Getting back to Listing 1, the constructor for EventHandler initializes (to zero) a linked list of event handlers. This is the key to the event management scheme—the handlers pass the event along until an appropriate handler is found. In this way, the NMS plays a kind of pass-the-parcel game with events. This key design decision has the effect of distributing the event management intelligence among the NMS classes rather than focusing it in one central class.

Often, NMS products don't use this approach—instead, many commercial products use a centralized event handler. The centralized approach requires a big event server that tries to field all incoming events from the network. Event messages are received, parsed and then the event server has to decide what to do. This monolithic approach is unnatural and potentially brittle.

Thanks to the chain of responsibility pattern, I use a devolved model—equipping each managed object to do some specific event handling. So, if object X can't process the event, it passes that event onto object Y, etc. I'll review the design tradeoffs later.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.