Amazing technological breakthrough possible @S-Logix pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to create a new agent in NS2?

  • // Create the New Agent (XY) class as a subclass of Agentclass XYAgent : public Agent {

  • // Declare the constructor of XYAgentXYAgent();

  • // Create command function with two arguments argc – argument count and argv – argument valueint command(int argc, const char*const* argv);

  • // Declare two variablesint a,b;

  • // Declare own functionint add(int, int);};static class XYAgentClass : public TclClass {public:XYAgentClass() : TclClass("Agent/XYAgentOtcl") {}TclObject* create(int, const char*const*) {return(new XYAgent());}}class_xy_agent;

  • //Define Addition functionint XYAgent::add(int num1, int num2){Tcl& tcl = Tcl::instance();tcl.evalf("puts \" Result of Addition = %d\"", num1+num2);}

  • Invoking the creating agent in Tcl
    set xyagent [new Agent / XYAgent]
    $xyagent set a 5
    $xyagent set b 10
    $xyagent add $a $b