, which would store simulation data for further analysis. They are not men- tioned here. See details in [29]. 16.4 General Network Simulators for SIP Although general formal modeling and simulation tools are useful in analysis of SIP, they lack the simulation of a network environment. Now a lot of network simulators supporting SIP can help to solve the problem. Although SIP is an application-layer protocol, it always interacts with other lower-layer protocols, such as TCP, UDP, etc. What's more, systems such as VoIP based on SIP do not only consider SIP itself, the network environment, traffic and QoS problems are also important for a whole system, which should be tested and simulated through simulations. 16.4.1 NS-2 and SIP Modeling Network Simulation version 2 (NS-2) is a discrete event simulator targeted at networking research from the Virtual Internetwork Testbed project VINT. NS-2 is free and provides substantial support for simulation of TCP, routing, and multicast protocols over wired and wireless (local and satellite) net- works [16]. In order to simulate a SIP-based system, we use NS-2 with the addition of the SIP module, SIP Patch. We tested some versions of SIP Patch for the NS-2 network simulator, containing the simple 2.1b9a SIP Patch from [16] and the recent 2.26 SIP Patch from [30]. SIP Patch gives the original support for SIP-based simulation and most SIP modules in it can simulate bidirectional dialogue between two SIP agents that send SIP requests, establish topology, and trace SIP events during the simulation through NAM-The Network Animator; see Figure 16.15 as a media test example in SIP Patch 2.26. SIP modules can run over UDP (unreliable), TCP or SCTP (reliable). Figure 16.15 is an example of SIP over UDP. In the patch, sip_udp.cc and sip_udp.h define the standard SIP over UDP and the file trace.cc has been modified to allow the tracing of SIP events during the simulation. The nodes in the topology graph are first defined as NS nodes and then attached to significant objects. For example, th