Article 28BCH CodeSOD: Mapping Every Possibility

CodeSOD: Mapping Every Possibility

by
Ellis Morning
from The Daily WTF on (#28BCH)

512px-Capture_all.PNG

Today, Aaron L. shares the tale of an innocent little network mapping program that killed itself with its own thoroughness:

I was hired to take over development on a network topology mapper that came from an acquisition. The product did not work except in small test environments. Every customer demo was a failure.

The code below was used to determine if two ports on two different switches are connected. This process was repeated for every switch in the network. As the number of switches, ports, and MAC addresses increased the run time of the product went up exponentially and typically crashed with an array index out of bounds exception. The code below is neatly presented, the actual code took me over a day of repeatedly saying "WTF?" before I realized the original programmer had no idea what a Map or Set or List was. But after eliminating the arrays the flawed matching algorithm was still there and so shortly all of the acquired code was thrown away and the mapper was re-written from scratch with more efficient ways of connecting switches.

public class Switch { Array[] allMACs = new Array[numMACs]; Array[] portIndexes = new Array[numPorts]; Array[] ports = new Array[numPorts]; public void load() { // load allMACs by reading switch via SNMP // psuedo code to avoid lots of irrelevant SNMP code int portCounter = 0; int macCounter = 0; for each port { ports[portCounter] = port; portIndexes[portCounter] = macCounter; for each MAC on port { allMACs[macCounter++] = MAC; } } } public Array[] getMACsForPort(int port) { int startIndex; int endIndex; for (int ictr = 0; ictr 
otter-icon.png [Advertisement] Onsite, remote, bare-metal or cloud - create, configure and orchestrate 1,000s of servers, all from the same dashboard while continually monitoring for drift and allowing for instantaneous remediation. Download Otter today! TheDailyWtf?d=yIl2AUoC8zATWgAV3ROazo
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments