Changeset 227

Show
Ignore:
Timestamp:
08/31/08 19:57:20 (4 months ago)
Author:
pwh
Message:
  • bridge_test.rb: Corrected plenty of mistakes in test code and added extra
    tests thanks to rcov.
  • bridges.yml: Corrected the designated root and base bridge addresses of
    the example bridge.
  • bridge.rb: Added documentation for the bridge model.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • nethorus/app/models/bridge.rb

    r218 r227  
    2424An object representing a bridge within a device. 
    2525 
     26= Overview 
     27 
     28A bridge object represents an IEEE 802.11 Ethernet bridge. 
     29 
     30Each bridge object must be associated with exactly one Device, however one 
     31Device may have several bridges - this is the case in which several 
     32instances of Spanning Tree Protocol (STP) are running on a device. 
     33 
     34A bridge object may have one or more associated StpPorts. 
     35 
     36= Attributes 
     37 
     38Each bridge object may have the following attributes: 
     39 
     40* *device_id* - a foreign key holding the value of the device to which this bridge belongs. 
     41* *dot1d_base_bridge_address* (REQUIRED) - the MAC address of this bridge.  This is combined with the value of *dot1d_stp_priority* to make a Bridge ID. 
     42* *dot1d_base_num_ports* - the number of ports in this bridge. 
     43* *dot1d_base_type* - the type of bridging this bridge can perform.  The only supported value is 'transparent-only'. 
     44* *dot1d_stp_protocol_specification* -  
     45* *dot1d_stp_priority* -  
     46* *dot1d_stp_time_since_topology_change* - 
     47* *dot1d_stp_topology_changes* -  
     48* *dot1d_stp_designated_root* -  
     49* *dot1d_stp_root_cost* - 
     50* *dot1d_stp_root_port* -  
     51* *dot1d_stp_max_age* -  
     52* *dot1d_stp_hello_time* -  
     53* *dot1d_stp_hold_time* -  
     54* *dot1d_stp_forward_delay* -  
     55* *dot1d_stp_bridge_max_age* -  
     56* *dot1d_stp_bridge_hello_time* -  
     57* *dot1d_stp_bridge_forward_delay* -  
     58* *created_at* -  
     59* *updated_at* -  
     60 
    2661=end 
    2762 
     
    98133 
    99134 
    100   # TODO: Some bridges set the timer values to seconds, not centi-seconds 
    101   # (1/100th of a second).  This is a hack to get around this problem. 
     135  # Some items of network equipment violate the BRIDGE-MIB and return values 
     136  # in seconds, rather than centi-seconds.  This model will automatically 
     137  # upscale the following attributes by a factor of 100 for the specified 
     138  # values: 
     139 
     140  #  * *dot1d_stp_max_age* 
     141  #  * *dot1d_stp_hello_time* 
     142  #  * *dot1d_stp_hold_time* 
     143  #  * *dot1d_stp_forward_delay* 
     144  #  * *dot1d_stp_bridge_max_age* - values between 6 and 40 will be upscaled by a factor of 100 
     145  #  * *dot1d_stp_bridge_hello_time* - values between 1 and 100 will be upscaled by a factor of 100 
     146  #  * *dot1d_stp_bridge_forward_delay* 
    102147 
    103148  def before_validation 
    104149 
    105     if !self.dot1d_stp_max_age.nil? && self.dot1d_stp_max_age <= 99 
     150    if !self.dot1d_stp_max_age.nil? && self.dot1d_stp_max_age < 100 
    106151      logger.warn "dot1d_stp_max_age is #{self.dot1d_stp_max_age} - multiplying by 100" 
    107152      self.dot1d_stp_max_age = self.dot1d_stp_max_age * 100 
    108153    end       
    109154 
    110     if !self.dot1d_stp_hello_time.nil? && self.dot1d_stp_hello_time <= 99 
     155    if !self.dot1d_stp_hello_time.nil? && self.dot1d_stp_hello_time < 100 
     156      logger.warn "dot1d_stp_hello_time is #{self.dot1d_stp_hello_time} - multiplying by 100" 
    111157      self.dot1d_stp_hello_time = self.dot1d_stp_hello_time * 100 
    112158    end 
    113159     
    114     if !self.dot1d_stp_hold_time.nil? && self.dot1d_stp_hold_time <= 99 
     160    if !self.dot1d_stp_hold_time.nil? && self.dot1d_stp_hold_time < 100 
     161      logger.warn "dot1d_stp_hold_time is #{self.dot1d_stp_hold_time} - multiplying by 100" 
    115162      self.dot1d_stp_hold_time = self.dot1d_stp_hold_time * 100 
    116163    end 
    117164     
    118     if !self.dot1d_stp_forward_delay.nil? && self.dot1d_stp_forward_delay <= 99 
     165    if !self.dot1d_stp_forward_delay.nil? && self.dot1d_stp_forward_delay < 100 
     166      logger.warn "dot1d_stp_forward_delay is #{self.dot1d_stp_forward_delay} - multiplying by 100" 
    119167      self.dot1d_stp_forward_delay = self.dot1d_stp_forward_delay * 100 
    120168    end 
    121169     
    122     if !self.dot1d_stp_bridge_max_age.nil? && self.dot1d_stp_bridge_max_age <= 99 
     170    if !self.dot1d_stp_bridge_max_age.nil? && self.dot1d_stp_bridge_max_age < 40 
     171      logger.warn "dot1d_stp_bridge_max_age is #{self.dot1d_stp_bridge_max_age} - multiplying by 100" 
    123172      self.dot1d_stp_bridge_max_age = self.dot1d_stp_bridge_max_age * 100 
    124173    end 
    125      
    126     if !self.dot1d_stp_bridge_hello_time.nil? && self.dot1d_stp_bridge_hello_time <= 99 
     174 
     175    if !self.dot1d_stp_bridge_hello_time.nil? && self.dot1d_stp_bridge_hello_time < 10 
     176      logger.warn "dot1d_stp_bridge_hello_time is #{self.dot1d_stp_bridge_hello_time} - multiplying by 100" 
    127177      self.dot1d_stp_bridge_hello_time = self.dot1d_stp_bridge_hello_time * 100 
    128178    end 
    129179 
    130     if !self.dot1d_stp_bridge_forward_delay.nil? && self.dot1d_stp_bridge_forward_delay <= 99 
     180    if !self.dot1d_stp_bridge_forward_delay.nil? && self.dot1d_stp_bridge_forward_delay < 100 
     181      logger.warn "dot1d_stp_bridge_forward_delay is #{self.dot1d_stp_bridge_forward_delay} - multiplying by 100" 
    131182      self.dot1d_stp_bridge_forward_delay = self.dot1d_stp_bridge_forward_delay * 100 
    132183    end 
  • nethorus/test/fixtures/bridges.yml

    r168 r227  
    11test_bridge_1: 
    22  device_id:                        1 
    3   dot1d_base_bridge_address:        80001234567890AB 
     3  dot1d_base_bridge_address:        0123456789AB 
    44  dot1d_base_num_ports:             24 
    55  dot1d_base_type:                  transparent-only 
    66  dot1d_stp_protocol_specification: ieee8021d 
    77  dot1d_stp_priority:               32768 
    8   dot1d_stp_designated_root:        20001234567890AB 
     8  dot1d_stp_designated_root:        8000111111111111 
    99  dot1d_stp_root_cost:              30 
    1010  dot1d_stp_root_port:              1 
  • nethorus/test/unit/bridge_test.rb

    r216 r227  
    220220    # Test the dot1d_stp_bridge_max_age 
    221221 
     222    @bridge.dot1d_stp_bridge_max_age = 4001 
     223    assert(!@bridge.valid?, "A bridge should not be valid with a dot1d_stp_bridge_max_age of 4001") 
     224 
     225    @bridge.dot1d_stp_bridge_max_age = 4000 
     226    assert(@bridge.valid?, "A bridge should be valid with a dot1d_stp_bridge_max_age of 4000") 
     227 
     228    @bridge.dot1d_stp_bridge_max_age = 599 
     229    assert(!@bridge.valid?, "A bridge should not be valid with a dot1d_stp_bridge_max_age of 599") 
     230 
    222231    @bridge.dot1d_stp_bridge_max_age = 600 
    223232    assert(@bridge.valid?, "A bridge should be valid with a dot1d_stp_bridge_max_age of 600") 
    224233 
    225     @bridge.dot1d_stp_bridge_max_age = 599 
    226     assert(!@bridge.valid?, "A bridge should not be valid with a dot1d_stp_bridge_max_age of 599") 
    227  
    228     @bridge.dot1d_stp_bridge_max_age = 4000 
    229     assert(@bridge.valid?, "A bridge should be valid with a dot1d_stp_bridge_max_age of 4000") 
    230  
    231     @bridge.dot1d_stp_bridge_max_age = 4001 
    232     assert(!@bridge.valid?, "A bridge should not be valid with a dot1d_stp_bridge_max_age of 4001") 
    233  
    234     @bridge.dot1d_stp_bridge_max_age = 600 
    235234 
    236235 
     
    282281     
    283282    bridge.dot1d_stp_max_age = 1 
    284     assert(bridge.valid? && bridge_dot1d_stp_max_age = 100, "Specifying dot1d_stp_max_age =< 50 should multiply the value by 100 (centisecond hack) - we used 1") 
    285  
    286     bridge.dot1d_stp_max_age = 50 
    287     assert(bridge.valid? && bridge_dot1d_stp_max_age = 5000, "Specifying dot1d_stp_max_age =< 50 should multiply the value by 100 (centisecond hack) - we used 50") 
    288    
    289     bridge.dot1d_stp_max_age = 51 
    290     assert(bridge.valid? && bridge_dot1d_stp_max_age = 51, "Specifying dot1d_stp_max_age =< 50 should multiply the value by 100 (centisecond hack) - we used 51") 
     283    assert(bridge.valid? && bridge.dot1d_stp_max_age == 100, "Specifying dot1d_stp_max_age < 100 should multiply the value by 100 (centisecond hack) - we used 1") 
     284 
     285    bridge.dot1d_stp_max_age = 99 
     286    assert(bridge.valid? && bridge.dot1d_stp_max_age == 9900, "Specifying dot1d_stp_max_age < 100 should multiply the value by 100 (centisecond hack) - we used 99") 
     287 
     288    bridge.dot1d_stp_max_age = 100 
     289    assert(bridge.valid? && bridge.dot1d_stp_max_age == 100, "Specifying dot1d_stp_max_age >= 100 should NOT multiply the value by 100 (centisecond hack) - we used 100") 
     290   
     291    bridge.dot1d_stp_max_age = 101 
     292    assert(bridge.valid? && bridge.dot1d_stp_max_age == 101, "Specifying dot1d_stp_max_age >= 101 should NOT multiply the value by 100 (centisecond hack) - we used 101") 
     293 
     294 
     295    # Test recalculation for low values of dot1d_stp_bridge_max_age 
     296     
     297    bridge.dot1d_stp_bridge_max_age = 6 
     298    assert(bridge.valid? && bridge.dot1d_stp_bridge_max_age == 600, "Specifying dot1d_stp_bridge_max_age < 40 should multiply the value by 100 (centisecond hack) - we used 6 and got #{bridge.dot1d_stp_bridge_max_age}") 
     299 
     300    bridge.dot1d_stp_bridge_max_age = 39 
     301    assert(bridge.valid? && bridge.dot1d_stp_bridge_max_age == 3900, "Specifying dot1d_stp_bridge_max_age < 40 should multiply the value by 100 (centisecond hack) - we used 39 and got #{bridge.dot1d_stp_bridge_max_age}") 
     302 
     303    bridge.dot1d_stp_bridge_max_age = 600 
     304    assert(bridge.valid? && bridge.dot1d_stp_bridge_max_age == 600, "Specifying dot1d_stp_bridge_max_age >= 40 should NOT multiply the value by 100 (centisecond hack) - we used 600 and got #{bridge.dot1d_stp_bridge_max_age}") 
     305 
     306    bridge.dot1d_stp_bridge_max_age = 601 
     307    assert(bridge.valid? && bridge.dot1d_stp_bridge_max_age == 601, "Specifying dot1d_stp_bridge_max_age >= 40 should NOT multiply the value by 100 (centisecond hack) - we used 601 and got #{bridge.dot1d_stp_bridge_max_age}") 
    291308 
    292309 
     
    294311 
    295312    bridge.dot1d_stp_hello_time = 1 
    296     assert(bridge.valid? && bridge_dot1d_stp_hello_time = 100, "Specifying dot1d_stp_hello_time =< 50 should multiply the value by 100 (centisecond hack) - we used 1") 
    297  
    298     bridge.dot1d_stp_hello_time = 50 
    299     assert(bridge.valid? && bridge_dot1d_stp_hello_time = 5000, "Specifying dot1d_stp_hello_time =< 50 should multiply the value by 100 (centisecond hack) - we used 50") 
    300    
    301     bridge.dot1d_stp_hello_time = 51 
    302     assert(bridge.valid? && bridge_dot1d_stp_hello_time = 51, "Specifying dot1d_stp_hello_time =< 50 should multiply the value by 100 (centisecond hack) - we used 51") 
    303  
    304   end 
    305  
    306  
    307   # Test the device/bridge relationship 
    308    
    309   def test_device_bridge_relationship 
    310    
     313    assert(bridge.valid? && bridge.dot1d_stp_hello_time == 100, "Specifying dot1d_stp_hello_time =< 100 should multiply the value by 100 (centisecond hack) - we used 1 and got #{bridge.dot1d_stp_hello_time}") 
     314 
     315    bridge.dot1d_stp_hello_time = 99 
     316    assert(bridge.valid? && bridge.dot1d_stp_hello_time == 9900, "Specifying dot1d_stp_hello_time < 100 should multiply the value by 100 (centisecond hack) - we used 99 and got #{bridge.dot1d_stp_hello_time}") 
     317   
     318    bridge.dot1d_stp_hello_time = 100 
     319    assert(bridge.valid? && bridge.dot1d_stp_hello_time == 100, "Specifying dot1d_stp_hello_time >= 100 should multiply the value by 100 (centisecond hack) - we used 100 and got #{bridge.dot1d_stp_hello_time}") 
     320 
     321 
     322    # Test recalculation for low values of dot1d_stp_bridge_hello_time 
     323 
     324    bridge.dot1d_stp_bridge_hello_time = 1 
     325    assert(bridge.valid? && bridge.dot1d_stp_bridge_hello_time == 100, "Specifying dot1d_stp_bridge_hello_time < 10 should multiply the value by 100 (centisecond hack) - we used 1 and got #{bridge.dot1d_stp_bridge_hello_time}") 
     326 
     327    bridge.dot1d_stp_bridge_hello_time = 9 
     328    assert(bridge.valid? && bridge.dot1d_stp_bridge_hello_time == 900, "Specifying dot1d_stp_bridge_hello_time < 100 should multiply the value by 100 (centisecond hack) - we used 9 and got #{bridge.dot1d_stp_bridge_hello_time}") 
     329   
     330    bridge.dot1d_stp_bridge_hello_time = 100 
     331    assert(bridge.valid? && bridge.dot1d_stp_bridge_hello_time == 100, "Specifying dot1d_stp_bridge_hello_time >= 100 should NOT multiply the value by 100 (centisecond hack) - we used 100 and got #{bridge.dot1d_stp_bridge_hello_time}") 
     332 
     333 
     334    # Test recalculation for low values of dot1d_stp_bridge_forward_delay 
     335 
     336    bridge.dot1d_stp_bridge_forward_delay = 1 
     337    assert(bridge.valid? && bridge.dot1d_stp_bridge_forward_delay == 100, "Specifying dot1d_stp_bridge_forward_delay =< 50 should multiply the value by 100 (centisecond hack) - we used 1") 
     338 
     339    bridge.dot1d_stp_bridge_forward_delay = 99 
     340    assert(bridge.valid? && bridge.dot1d_stp_bridge_forward_delay == 9900, "Specifying dot1d_stp_bridge_forward_delay =< 50 should multiply the value by 100 (centisecond hack) - we used 99") 
     341   
     342    bridge.dot1d_stp_bridge_forward_delay = 100 
     343    assert(bridge.valid? && bridge.dot1d_stp_bridge_forward_delay == 100, "Specifying dot1d_stp_bridge_forward_delay =< 50 should multiply the value by 100 (centisecond hack) - we used 100") 
     344 
     345  end 
     346 
     347 
     348  # Test the is_the_root_bridge? method 
     349   
     350  def test_is_the_root_bridge 
     351   
     352    @bridge.dot1d_base_bridge_address = '111111111111' 
     353    @bridge.dot1d_stp_designated_root = '8000111111111111' 
     354 
     355    assert(@bridge.is_the_root_bridge? == :true) 
     356 
     357    @bridge.dot1d_base_bridge_address = '222222222222' 
     358     
     359    assert(@bridge.is_the_root_bridge? == :false) 
     360   
     361  end 
     362 
     363 
     364  # Test the dot1d_stp_root_port_interface method 
     365   
     366  def test_dot1d_stp_root_port_interface 
     367   
     368    # TODO: Write tests for dot1d_stp_root_port_interface 
     369     
    311370  end 
    312371