Changeset 227
- Timestamp:
- 08/31/08 19:57:20 (4 months ago)
- Files:
-
- nethorus/app/models/bridge.rb (modified) (2 diffs)
- nethorus/test/fixtures/bridges.yml (modified) (1 diff)
- nethorus/test/unit/bridge_test.rb (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
nethorus/app/models/bridge.rb
r218 r227 24 24 An object representing a bridge within a device. 25 25 26 = Overview 27 28 A bridge object represents an IEEE 802.11 Ethernet bridge. 29 30 Each bridge object must be associated with exactly one Device, however one 31 Device may have several bridges - this is the case in which several 32 instances of Spanning Tree Protocol (STP) are running on a device. 33 34 A bridge object may have one or more associated StpPorts. 35 36 = Attributes 37 38 Each 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 26 61 =end 27 62 … … 98 133 99 134 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* 102 147 103 148 def before_validation 104 149 105 if !self.dot1d_stp_max_age.nil? && self.dot1d_stp_max_age < = 99150 if !self.dot1d_stp_max_age.nil? && self.dot1d_stp_max_age < 100 106 151 logger.warn "dot1d_stp_max_age is #{self.dot1d_stp_max_age} - multiplying by 100" 107 152 self.dot1d_stp_max_age = self.dot1d_stp_max_age * 100 108 153 end 109 154 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" 111 157 self.dot1d_stp_hello_time = self.dot1d_stp_hello_time * 100 112 158 end 113 159 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" 115 162 self.dot1d_stp_hold_time = self.dot1d_stp_hold_time * 100 116 163 end 117 164 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" 119 167 self.dot1d_stp_forward_delay = self.dot1d_stp_forward_delay * 100 120 168 end 121 169 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" 123 172 self.dot1d_stp_bridge_max_age = self.dot1d_stp_bridge_max_age * 100 124 173 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" 127 177 self.dot1d_stp_bridge_hello_time = self.dot1d_stp_bridge_hello_time * 100 128 178 end 129 179 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" 131 182 self.dot1d_stp_bridge_forward_delay = self.dot1d_stp_bridge_forward_delay * 100 132 183 end nethorus/test/fixtures/bridges.yml
r168 r227 1 1 test_bridge_1: 2 2 device_id: 1 3 dot1d_base_bridge_address: 80001234567890AB3 dot1d_base_bridge_address: 0123456789AB 4 4 dot1d_base_num_ports: 24 5 5 dot1d_base_type: transparent-only 6 6 dot1d_stp_protocol_specification: ieee8021d 7 7 dot1d_stp_priority: 32768 8 dot1d_stp_designated_root: 20001234567890AB8 dot1d_stp_designated_root: 8000111111111111 9 9 dot1d_stp_root_cost: 30 10 10 dot1d_stp_root_port: 1 nethorus/test/unit/bridge_test.rb
r216 r227 220 220 # Test the dot1d_stp_bridge_max_age 221 221 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 222 231 @bridge.dot1d_stp_bridge_max_age = 600 223 232 assert(@bridge.valid?, "A bridge should be valid with a dot1d_stp_bridge_max_age of 600") 224 233 225 @bridge.dot1d_stp_bridge_max_age = 599226 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 = 4000229 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 = 4001232 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 = 600235 234 236 235 … … 282 281 283 282 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}") 291 308 292 309 … … 294 311 295 312 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 311 370 end 312 371
