A Good Program Design?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • crokett
    The Full Monte
    • Jan 2003
    • 10627
    • Mebane, NC, USA.
    • Ryobi BT3000

    A Good Program Design?

    I have been playing with the existing code I have and it has some limitations based on where we want to go with it. I think I want to reimplement it as Object-Oriented so....

    A fabric is composed of switches (and devices but those can come later). The switches are composed of modules. The modules in turn have the physical ports on them. The switches are interconnected through interswitch links (ISLs) There may be multiple ISLs from one switch to another and those may be grouped so the switch treats them as one link - so 3 2Gigabit links are treated as 1 6gigabit trunk, or 4 2Gb links may be treated as 2 4Gb trunks with 2 links in each trunk.

    Going back to my somewhat hazy memory of the OO programming courses I audited once upon a time I see at least 4 clases that mirror what a fabric looks like in real life and probably 5.


    A Fabric object that holds switches as a dynamic array of switch objects. and a dynamic array of ISLs. The fabric class doesn't really have any attributes of its own other than maybe a fabric name. I can scan the first switch file to find out how big the switch array needs to be, then create the fabric object with all the switches.

    A switch object is in turn composed of module objects. The modules may or may not be port modules - some modules are the brains of the switch. The modules in turn are composed of an array of port objects. There are a few special port cases that are virtual ports, those may be defined at switch level since they really aren't attached to a module.

    I want a fifth class for ISLs that is an attribute of the fabric. The fabric will have an array of ISLs. This will be important for future use. The ISL in turn will be an array of port objects.

    What do you think?
    David

    The chief cause of failure in this life is giving up what you want most for what you want at the moment.
  • pierhogunn
    Veteran Member
    • Sep 2003
    • 1567
    • Harrisburg, NC, USA.

    #2
    Sounds reasonable, as long as you are able to add properties to the individual ports while they are inside the modules, and you don't limit the length of the port name to 16 - 32 characters ( go for 64)
    It's Like I've always said, it's amazing what an agnostic can't do if he dosent know whether he believes in anything or not

    Monty Python's Flying Circus

    Dan in Harrisburg, NC

    Comment

    • Thom2
      Resident BT3Central Research Ass.
      • Jan 2003
      • 1786
      • Stevens, PA, USA.
      • Craftsman 22124

      #3
      methinks they goofed and put "hooked on jibberish" tapes in your "hooked on phonics" package

      I'd call and get a refund
      If it ain't broke.. don't fix it!!!... but you can always 'hop it up'
      **one and only purchaser of a BT3C official thong**

      Comment

      • Sawduster
        Established Member
        • Dec 2002
        • 342
        • Cedar Park, TX, USA.

        #4
        And all that so you can choose between a orange and a blue light.
        Jerry

        \"Those who expect to reap the blessings of freedom must, like men, undergo the fatigue of supporting it.\"
        ~ Thomas Paine ~





        http://www.sawdustersplace.com

        Comment

        • Alex Franke
          Veteran Member
          • Feb 2007
          • 2641
          • Chapel Hill, NC
          • Ryobi BT3100

          #5
          Here's what I came up with based on your description:

          Code:
          // Something that is "treated as one link" -- either a switch or a trunk
          public interface ILinkable 
          { }
          
          public class Fabric
          {
          	// "The fabric class doesn't really have any attributes of its own other than maybe a fabric name."
          	public string Name = String.Empty; 
          
          	// "A fabric is composed of switches (and devices but those can come later)."
          	public List<ILinkable> Resources = new List<ILinkable>(); // Switches and trunks
          	public List<Device> Devices = new List<Device>(); 
          }
          
          public class Switch : ILinkable
          {
          	// "The switches are composed of modules."
          	// "A switch object is in turn composed of module objects."
          	// "The modules may or may not be port modules - some modules are the brains of the switch."
          	public List<Module> Modules = new List<Module>();
          
          	// "There are a few special port cases that are virtual ports, those may be 
          	// defined at switch level since they really aren't attached to a module."
          	public List<VirtualPort> VirtualPorts = new List<VirtualPort>(); 
          
          	// "The switches are interconnected through interswitch links (ISLs) 
          	// There may be multiple ISLs from one switch to another"
          	public List<ILinkable> ISLs = new List<ILinkable>();
          }
          
          // "...and those [ISLs] may be grouped so the switch treats them as one link
          // so 3 2Gigabit links are treated as 1 6gigabit trunk, or 4 2Gb links 
          // may be treated as 2 4Gb trunks with 2 links in each trunk"
          public class Trunk : List<Switch>, ILinkable
          {
          	public Trunk( params Switch[] switches )
          	{
          		this.AddRange( switches ); 
          	}
          }
          
          // "The modules may or may not be port modules"
          public class Module
          { }
          
          // "The modules may or may not be port modules"
          public class PortModule : Module
          {
          	// "The modules in turn have the physical ports on them."
          	public List<Port> Ports = new List<Port>();
          
          	public PortModule()
          	{ }
          	public PortModule( params string[] standardPortNames )
          	{
          		foreach ( string s in standardPortNames )
          			Ports.Add( new Port( s ) ); 
          	}
          }
          
          public class Port
          {
          	public string Name = String.Empty;
          	public Port( string name )
          	{
          		Name = name;
          	}
          }
          
          // "There are a few special port cases that are virtual ports,"
          public class VirtualPort
          {
          	public string Name = String.Empty;
          
          	public VirtualPort( string name )
          	{
          		Name = name; 
          	}
          }
          
          // "(and devices but those can come later)"
          public class Device
          { }
          And here's some code that sets it up...

          Code:
          // Create the fabric
          Fabric Fabric = new Fabric();
          
          // Create some switches
          Switch TwoGB1 = new Switch();
          Switch TwoGB2 = new Switch();
          Switch TwoGB3 = new Switch();
          Switch TwoGB4 = new Switch();
          Switch SomeOtherSwitch1 = new Switch();
          Switch SomeOtherSwitch2 = new Switch();
          
          // Create some ISLs
          TwoGB1.ISLs.Add( TwoGB2 );
          TwoGB1.ISLs.Add( TwoGB3 );
          TwoGB1.ISLs.Add( TwoGB4 );
          TwoGB2.ISLs.Add( TwoGB4 );
          TwoGB3.ISLs.Add( TwoGB1 );
          TwoGB4.ISLs.Add( TwoGB1 );
          TwoGB4.ISLs.Add( TwoGB2 );
          TwoGB4.ISLs.Add( TwoGB3 );
          SomeOtherSwitch1.ISLs.Add( TwoGB1 );
          SomeOtherSwitch1.ISLs.Add( TwoGB2 );
          SomeOtherSwitch1.ISLs.Add( SomeOtherSwitch2 );
          SomeOtherSwitch2.ISLs.Add( TwoGB4 );
          SomeOtherSwitch2.ISLs.Add( SomeOtherSwitch1 ); 
          
          // Add some modules
          TwoGB1.Modules.Add( new Module() ); // A non-port module
          TwoGB1.Modules.Add( new PortModule( "Port 1", "Port 2", "Port 3" ) ); // A port module
          
          // Add some virtual ports
          TwoGB2.VirtualPorts.Add( new VirtualPort( "Virtual Port 1" ) );
          TwoGB2.VirtualPorts.Add( new VirtualPort( "Virtual Port 2" ) ); 
          
          // Create some trunks
          Trunk SixGBTrunk = new Trunk( TwoGB1, TwoGB2, TwoGB3 );
          Trunk FourGBTrunk1 = new Trunk( TwoGB1, TwoGB2 );
          Trunk FourGBTrunk2 = new Trunk( TwoGB3, TwoGB4 );
          
          // Add the switches and trunks to the fabric
          Fabric.Resources.Add( SixGBTrunk );
          Fabric.Resources.Add( FourGBTrunk1 );
          Fabric.Resources.Add( FourGBTrunk2 );
          Fabric.Resources.Add( SomeOtherSwitch1 );
          Fabric.Resources.Add( SomeOtherSwitch2 );
          online at http://www.theFrankes.com
          while ( !( succeed = try() ) ) ;
          "Life is short, Art long, Occasion sudden and dangerous, Experience deceitful, and Judgment difficult." -Hippocrates

          Comment

          • thrytis
            Senior Member
            • May 2004
            • 552
            • Concord, NC, USA.
            • Delta Unisaw

            #6
            Are you likely to expand the types of switches you have to support? I've worked with some switches that have modules in them which run their own operating systems and are in effect independent devices. These modules can have their own ports, or even modules that contain ports. Also, i've seen routers that contain modules (not running their own OS) that contain modules which contain the ports, though i don't know of any switches like this. Of course you can never come up with an object model complete enough to handle whatever disturbing creations the switch engineers come up with.

            If you ever have to support routers you'll need a lot more to handle network layer, though you're probably best dealing with that when the requirement comes up.
            Eric

            Comment

            • JR
              The Full Monte
              • Feb 2004
              • 5633
              • Eugene, OR
              • BT3000

              #7
              I can't comment on the code design, but wondering if you also need to worry about router domains, hop counts, that sort of thing.


              JR
              JR

              Comment

              • crokett
                The Full Monte
                • Jan 2003
                • 10627
                • Mebane, NC, USA.
                • Ryobi BT3000

                #8
                Originally posted by Sawduster
                And all that so you can choose between a orange and a blue light.
                Huh?
                David

                The chief cause of failure in this life is giving up what you want most for what you want at the moment.

                Comment

                • Sawduster
                  Established Member
                  • Dec 2002
                  • 342
                  • Cedar Park, TX, USA.

                  #9
                  Originally posted by crokett
                  Huh?
                  Exactly what I said when I read the original post.
                  Jerry

                  \"Those who expect to reap the blessings of freedom must, like men, undergo the fatigue of supporting it.\"
                  ~ Thomas Paine ~





                  http://www.sawdustersplace.com

                  Comment

                  • crokett
                    The Full Monte
                    • Jan 2003
                    • 10627
                    • Mebane, NC, USA.
                    • Ryobi BT3000

                    #10
                    Alex,

                    That looks to be a pretty good start (and much better documented than I'd do) . It also posed a different way of working the ISLs. I think at the Fabric level just knowing which switches are connected to which via name is enough - I don't necessarily have to track the number of ports, etc in a trunk. I can do that down in the switch object.
                    David

                    The chief cause of failure in this life is giving up what you want most for what you want at the moment.

                    Comment

                    • Alex Franke
                      Veteran Member
                      • Feb 2007
                      • 2641
                      • Chapel Hill, NC
                      • Ryobi BT3100

                      #11
                      Originally posted by crokett
                      That looks to be a pretty good start (and much better documented than I'd do) . It also posed a different way of working the ISLs. I think at the Fabric level just knowing which switches are connected to which via name is enough - I don't necessarily have to track the number of ports, etc in a trunk. I can do that down in the switch object.
                      Cool -- I hope it's helpful. I can only guess at what you're actually talking about here -- many of those terms are new to me. I've never been much of a networking guy... =)
                      online at http://www.theFrankes.com
                      while ( !( succeed = try() ) ) ;
                      "Life is short, Art long, Occasion sudden and dangerous, Experience deceitful, and Judgment difficult." -Hippocrates

                      Comment

                      Working...