Did you work before with NS2? did you write an agents before ? If the answer is no you need to start with implementing ping protocol in NS2. many online PDFs show you how to start with ping. Afterthat, you can modifyit to get new protocols and agents.