This paper presents a highly scalable sensor network simulation environment that allows users to evaluate the effects of different architectural choices and strategies on the lifetime and performance of a sensor network. This tool can also be used to evaluate new approaches (e.g., routing protocols, cooperation algorithms), and compare them with the ones already in place. The simulator incorporates models for the different functional units composing a sensor node and characterizes the energy consumption of each. GTSNetS is designed in a modular and efficient way favoring the ease of use and extension. The simulator also allows the user to choose from different implementations of energy models, accuracy models, communication protocols, application classes and types of sensors. New models can be easily added if necessary. Simulation results from a set of tests are reported to demonstrate some of the capabilities of the simulator. We present a case study using our tool to measure the performance of an existing algorithm that provides fault-tolerance for distributed detection using a wireless sensor network. The simulator gives results that are in accordance with the ones reported in the original paper describing the simulated algorithm. Tests were also performed to evaluate the simulator scalability as the network size increases. In particular, it was found that this tool could simulate sensor networks of several hundred thousand nodes while using less than 2 GB of memory, which exceeds the capabilities of existing simulators by an order of magnitude. The simulation execution time also scales well with the network size.