Like this article? We recommend
The C# Code
Let's now have a look at the main Lsp class in Listing 7.
Listing 7 The Lsp Class
namespace LspEvents { // The callback interface. public interface ILspStatus { void GettingCongested(string msg); void FullyCongested(string msg); void CannotForwardData(string msg); } public class Lsp { // The set of connected sinks. ArrayList clientSinks = new ArrayList(); // Attach to the event source. public void Attach(ILspStatus sink) { clientSinks.Add(sink); } // Detach from the event source. public void Detach(ILspStatus sink) { clientSinks.Remove(sink); } #region Internal state data #endregion public Lsp() { } public Lsp(string lspName, int sourceNode, int destinationNode, string path, int requiredBandwidth, int maximumBandwidth) { #region Constructor #endregion } public void ForwardSomeData(int requiredBandwidth) { #region Use the LSP #endregion } } }
The Lsp class in Listing 7 includes the definition of the following:
- The callback interface with three domain-specific events
- Event sink attachment and detachment logic
- State data that describes the internal state of the LSP
- C# properties for describing the required bandwidth
- Two constructors
- A service method for forwarding data
Let's now put all the code fragments together.