OTCL/C++	Linkages	
T	S	Pradeep	Kumar	
http://www.pradeepkumar.org	
http://www.nsnam.com		
pradeepkumarts@gmail.com
TCLCL	Classes
Simple	Agent
class	TSPAgent	:	public	Agent	{	
public:	
								TSPAgent();	
protected:	
								int	command(int	argc,	const	char*const*	argv);	
private:	
								int				tsp_var1;	
								double	tsp_var2;	
								void			TSPPrivFunc(void);	
};
Simple	Agent
static	class	TSPAgentClass	:	public	TclClass	{	
public:	
							TSPAgentClass()	:	TclClass("Agent/TSPAgentOtcl")	{}	
								TclObject*	create(int,	const	char*const*)	{	
																return(new	TSPAgent());	
								}	
}	class_tsp_agent;	
TSPAgent::TSPAgent()	:	Agent(PT_UDP)	{	
							bind("tsp_var1_otcl",	&tsp_var1);	
							bind("tsp_var2_otcl",	&tsp_var2);	
}
Simple	Agent
int	TSPAgent::command(int	argc,	const	char*const*	
argv)	{	
						if(argc	==	2)	{	
											if(strcmp(argv[1],	"call-tsp-priv-func")	==	0)	{	
																		TSPPrivFunc();	
																		return(TCL_OK);	
											}	
						}	
					return(Agent::command(argc,	argv));	
}
Simple	Agent
void	TSPAgent::TSPPrivFunc(void)	{	
Tcl&	tcl	=	Tcl::instance();	
tcl.eval("puts	"Message	From	TSPPrivFunc"");	
tcl.evalf("puts	"					tsp_var1	=	%d"",	tsp_var1);	
tcl.evalf("puts	"					tsp_var2	=	%f"",	tsp_var2);	
}
Creation	of	a	Simple	Agent
#name	it	as	.tcl	file	
#	Create	TSPAgent		
set	myagent	[new	Agent/TSPAgentOtcl]	
#	Set	configurable	parameters	of	TSPAgent	
$myagent	set	tsp_var1_otcl	2	
$myagent	set	tsp_var2_otcl	3.14	
#	Give	a	command	to	TSPAgent	
$myagent	call-tsp-priv-fun
Case	study	–	2	–	Multimedia	over	udp
• to	build	a	multimedia	application	that	runs	
over	a	UDP	connection,		
• five	rate	media	scaling	
• by	changing	encoding	and	transmission	policy	
pairs	associated	with	scale	parameter	values.
Case	study	–	2	–	Multimedia	over	udp
• Based	on	5	rate	
– 0		 0.3mb	
– 1	 0.6mb	
– 2	 0.9mb	
– 3	 1.2mb	
– 4	 1.5mb	
– Packetsize		 1000	
– Random	 false
Case	study	–	2	–	Multimedia	over	udp
ÒWhen	connection	established,	Sender/receiver	
agree	on	5	different	sets	of	encoding	and	
transmission	policy	pairs.	
ÒSender	sends	with	scale	0	but	changes	the	
transmission	rates	according	to	the	value	that	the	
receiver	notifies.	
ÒThe	receiver	is	responsible	for	monitoring	the	
network	congestion	and	determine	the	scale	
factor.	If	congestion,	then	the	receiver	reduces	the	
scale	factor.
Where	to	modify
• ~ns-2.34	is	the	folder	where	all	the	cc	modules	
are	located
Topic Where	to	modify
Routing	Protocol		
(AODV,	DSDV,	DSR)
~ns-2.34/aodv/aodv.cc,	aodv_rtable.cc,	etc
Mobile	Node	(Energy,	Propagation,	
Antenna)
~ns-2.34/mobile/*.cc	and	*.h
TCP	(Vegas,	Reno,	New	Reno,	etc) ~ns-2.34/tcp/	*.cc
New	packet,	agent	to	be	added ~ns-2.34/common/packet.h,	agent.h
Wireless	Physical	layer	or	MAC	Layer	
modification
~ns-2.34/mac/*.cc
Where	to	modify
Topic Where	to	modify
MPLS ~ns-2.34/mpls
Adding	a	new	Queue ~ns-2.34/queue/*.cc	and	*.h
Adding	a	new	application ~ns-2.34/apps/app.h
Sensors ~ns-2.34/sensor-net	(still	to	be	developed)
Examples	(more	than	100) ~ns-2.34/tcl/ex/
What	not	lot	more	in	NS2

OTcl and C++ linkages in NS2