File: ldp.cc

package info (click to toggle)
ns2 2.35%2Bdfsg-3.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 78,808 kB
  • sloc: cpp: 172,923; tcl: 107,130; perl: 6,391; sh: 6,143; ansic: 5,846; makefile: 816; awk: 525; csh: 355
file content (632 lines) | stat: -rw-r--r-- 17,723 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
// -*-	Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*-

/*
 * ldp.cc
 * Copyright (C) 2000 by the University of Southern California
 * $Id: ldp.cc,v 1.9 2005/08/25 18:58:09 johnh Exp $
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 *
 *
 * The copyright of this module includes the following
 * linking-with-specific-other-licenses addition:
 *
 * In addition, as a special exception, the copyright holders of
 * this module give you permission to combine (via static or
 * dynamic linking) this module with free software programs or
 * libraries that are released under the GNU LGPL and with code
 * included in the standard release of ns-2 under the Apache 2.0
 * license or under otherwise-compatible licenses with advertising
 * requirements (or modified versions of such code, with unchanged
 * license).  You may copy and distribute such a system following the
 * terms of the GNU GPL for this module and the licenses of the
 * other code concerned, provided that you include the source code of
 * that other code when and as the GNU GPL requires distribution of
 * source code.
 *
 * Note that people who make modified versions of this module
 * are not obligated to grant this special exception for their
 * modified versions; it is their choice whether to do so.  The GNU
 * General Public License gives permission to release a modified
 * version without this exception; this exception also makes it
 * possible to release a modified version which carries forward this
 * exception.
 *
 */

//
// Original source contributed by Gaeil Ahn. See below.
//
// $Header: /cvsroot/nsnam/ns-2/mpls/ldp.cc,v 1.9 2005/08/25 18:58:09 johnh Exp $

/**************************************************************************
* Copyright (c) 2000 by Gaeil Ahn                                   	  *
* Everyone is permitted to copy and distribute this software.		  *
* Please send mail to fog1@ce.cnu.ac.kr when you modify or distribute     *
* this sources.								  *
**************************************************************************/

/***********************************************************
*                                                          *
*    File: File for LDP & CR-LDP protocol                   *
*    Author: Gaeil Ahn (fog1@ce.cnu.ac.kr), Jan. 2000      *
*                                                          *
***********************************************************/

#include "config.h"

#include <iostream>

#include "ldp.h"

int hdr_ldp::offset_;

static class LDPHeaderClass : public PacketHeaderClass {
public:
	LDPHeaderClass() : PacketHeaderClass("PacketHeader/LDP", 
					     sizeof(hdr_ldp)) {
		bind_offset(&hdr_ldp::offset_);
	}
} class_ldphdr;

static class LDPClass : public TclClass {
public:
	LDPClass() : TclClass("Agent/LDP") {}
	TclObject* create(int, const char*const*) {
		return (new LDPAgent());
	}
} class_agentldp;

LDPAgent::LDPAgent() : Agent(PT_LDP), 
	new_msgid_(0), trace_ldp_(0), peer_(0)
{
	MSGT_.NB      = 0;
}

void LDPAgent::delay_bind_init_all()
{
	delay_bind_init_one("trace_ldp_");
	Agent::delay_bind_init_all();
}

int LDPAgent::delay_bind_dispatch(const char *varName, const char *localName, 
				  TclObject *tracer)
{
	if (delay_bind_bool(varName,localName,"trace_ldp_",&trace_ldp_,tracer))
		return TCL_OK;
	return Agent::delay_bind_dispatch(varName, localName, tracer);
}

int LDPAgent::PKTsize(const char *pathvec, const char *er)
{
	// header size for Version, PDU Length, and LDP Identifier
	int psize = 10; 
	// size for message type and message id
	psize += 8; 
    
	int len = strlen(pathvec);
	if (len > 1) {
		psize += 4;   // size for path vector header
		for (int i=0; i<len; i++)
			if ( *(pathvec+i) == ' ' ) {
				psize += 4;   // size for path vector data
			}  
	}     

	len = strlen(er);
	if (len > 1) { 
		psize += 4;   // size for explicit route header
		for (int i=0; i<len; i++)
			if (*(er+i) == ' ')
				psize += 4;   // size for explicit route data 
	}
	return (psize);
}

void LDPAgent::PKTinit(hdr_ldp *hdrldp, int msgtype, 
		       const char *pathvec, const char *er)
{
	hdrldp->msgtype = msgtype;
	hdrldp->msgid   = new_msgid_;
	hdrldp->fec     = -1;
	hdrldp->label   = -1;
	hdrldp->reqmsgid= -1;
	hdrldp->status  = -1;

	int i;
	int len = strlen(pathvec);
	hdrldp->pathvec = (char *) malloc(len+1);
	for (i=0; i<len; i++) { 
		if ( *(pathvec+i) == ' ' )
			*(hdrldp->pathvec+i) = '_';
		else
			*(hdrldp->pathvec+i) = *(pathvec+i);
	}
	*(hdrldp->pathvec+len) = '\0';

	len = strlen(er);
	hdrldp->er = (char *) malloc(len+1);
	for (i=0; i<len; i++) { 
		if ( *(er+i) == ' ' )
			*(hdrldp->er+i) = '_';
		else
			*(hdrldp->er+i) = *(er+i);
	}
	*(hdrldp->er+len) = '\0';

	hdrldp->lspid = -1;
	hdrldp->rc    = -1;
}

int LDPAgent::command(int argc, const char*const* argv)
{
	Tcl& tcl = Tcl::instance();
	if (argc == 2) {      
		if (strcmp(argv[1], "msgtbl-dump") == 0) {              
			MSGTdump();
			return (TCL_OK);
		} else if (strcmp(argv[1], "new-msgid") == 0) {
			tcl.resultf("%d", ++new_msgid_);
			return (TCL_OK);
		} else if (strcmp(argv[1], "peer-ldpnode") == 0) {
			tcl.resultf("%d", peer_);
			return (TCL_OK);
		}
	} else if (argc == 3) {
		if (strcmp(argv[1], "set-peer") == 0) {
			peer_ = atoi(argv[2]);
			return (TCL_OK);
		}

		// The following is shared by all if-s in this branch
		int MsgID = atoi(argv[2]);
		int msgid,fec,lspid,src,pmsgid,labelop;
		int entrynb = MSGTlocate(MsgID);
		MSGTlookup(entrynb,msgid,fec,lspid,src,pmsgid,labelop);

		if (strcmp(argv[1], "msgtbl-clear") == 0) {
			/* <agent> MSGTdelete MsgID */
			if (entrynb > -1)  
				MSGTdelete(entrynb);
			return (TCL_OK);
		} else if (strcmp(argv[1], "msgtbl-get-src") == 0) {
			/* <agent> GetMSGTsrc MsgID */
			tcl.resultf("%d", src);
			return (TCL_OK);
		} else if (strcmp(argv[1], "msgtbl-get-reqmsgid") == 0)	{
			/* <agent> GetMSGTpmsgid msgid */
			tcl.resultf("%d",pmsgid);
			return (TCL_OK);
		} else if (strcmp(argv[1], "msgtbl-get-labelop") == 0) {
			/* <agent> GetMSGTlabelpass msgid */
			tcl.resultf("%d", labelop);
			return (TCL_OK);
		} else if (strcmp(argv[1], "msgtbl-get-erlspid") == 0) {
			/* 
			 * <agent> msgtbl-get-erlspid <msgid>
			 */
			tcl.resultf("%d",MSGT_.Entry[entrynb].ERLspID);
			return (TCL_OK);
		} else if (strcmp(argv[1], "msgtbl-set-labelpass") == 0) {
			/* 
			 * <agent> msgtbl-set-labelpass <msgid>
			 */
			MSGT_.Entry[entrynb].LabelOp = LDP_LabelPASS;
			return (TCL_OK);
		} 
	} else if (argc == 4) {      
		if (strcmp(argv[1], "notification-msg") == 0) {
			/* 
			 * <agent> notification-msg <status> <lspid>
			 */
			size_ = PKTsize("*", "*");
			if ( atoi(argv[3]) > -1 )  /* packet size adjustment */
				size_ += 16;
			else
				size_ += 8;
			Packet* pkt = allocpkt();
			hdr_ldp *hdrldp = hdr_ldp::access(pkt);
			PKTinit(hdrldp, LDP_NotificationMSG, "*", "*");

			if (strcmp(argv[2], "LoopDetected") == 0)
				hdrldp->status = LDP_LoopDetected;
			else if (strcmp(argv[2], "NoRoute") == 0)
				hdrldp->status  = LDP_NoRoute;
       
			hdrldp->lspid   = atoi(argv[3]);
			send(pkt, 0);
			return (TCL_OK);
		} else if (strcmp(argv[1], "withdraw-msg") == 0) {
			/* 
			 * <agent> withdraw-msg <fec> <lspid>
			 */
			size_ = PKTsize("*","*");
			if ( atoi(argv[3]) > -1 )  /* packet size adjustment */
				size_ += 16;
			else
				size_ += 8;
			Packet* pkt = allocpkt();
			hdr_ldp *hdrldp = hdr_ldp::access(pkt);
			PKTinit(hdrldp, LDP_WithdrawMSG, "*", "*");
			hdrldp->fec    = atoi(argv[2]);
			hdrldp->lspid  = atoi(argv[3]);
			send(pkt, 0);
			return (TCL_OK);
		} else if (strcmp(argv[1], "release-msg") == 0) {
			/* 
			 * <agent> release-msg <fec> <lspid>
			 */
			size_ = PKTsize("*","*");
			if ( atoi(argv[3]) > -1 )  /* packet size adjustment */
				size_ += 16;
			else
				size_ += 8;
			Packet* pkt = allocpkt();
			hdr_ldp *hdrldp = hdr_ldp::access(pkt);
			PKTinit(hdrldp, LDP_ReleaseMSG,"*","*");
			hdrldp->fec     = atoi(argv[2]);
			hdrldp->lspid   = atoi(argv[3]);
			send(pkt, 0);
			return (TCL_OK);
		} else if (strcmp(argv[1], "request-msg") == 0) {
			/* 
			 * <agent> request-msg <fec> <pathvec>
			 */
			size_ = PKTsize(argv[3],"*");
			size_ += 8;      /* packet size adjustment */
			Packet* pkt = allocpkt();
			hdr_ldp *hdrldp = hdr_ldp::access(pkt);
			PKTinit(hdrldp, LDP_RequestMSG, argv[3], "*");
			hdrldp->fec     = atoi(argv[2]);
			send(pkt, 0);
			return (TCL_OK);
		} else if (strcmp(argv[1], "msgtbl-set-labelstack") == 0) {
			/*
			 * <agent> msgtbl-set-labelstack <msgid> <erlspid>
			 */
			int MsgID   = atoi(argv[2]);
			int ERLspID = atoi(argv[3]);
			int entrynb = MSGTlocate(MsgID);
			MSGT_.Entry[entrynb].LabelOp = LDP_LabelSTACK;
			MSGT_.Entry[entrynb].ERLspID = ERLspID;
			return (TCL_OK);
		} 
	} else if (argc == 5) {      
		if (strcmp(argv[1], "msgtbl-get-msgid") == 0) {
			/* 
			 * <classifier> msgtbl-get-msgid <FEC> <LspID> <Src>
			 */
			int msgid,tmp;
			int fec    = atoi(argv[2]);
			int LspID  = atoi(argv[3]);
			int src    = atoi(argv[4]);     
			int entrynb = MSGTlocate(fec,LspID,src);

			MSGTlookup(entrynb,msgid,tmp,tmp,tmp,tmp,tmp);
			tcl.resultf("%d", msgid);
			return (TCL_OK);
		}
	} else if (argc == 6) {
		if (strcmp(argv[1], "mapping-msg") == 0) {
			/* 
			 * <agent> mapping <fec> <label> <pathvec> <premsgid>
			 */
			size_ = PKTsize(argv[4],"*");
			if ( atoi(argv[5]) > -1 )  /* packet size adjustment*/
				size_ += 24;
			else
				size_ += 16;
         		Packet* pkt = allocpkt();
			hdr_ldp *hdrldp = hdr_ldp::access(pkt);
			PKTinit(hdrldp, LDP_MappingMSG, argv[4], "*");
			hdrldp->fec     = atoi(argv[2]);
			hdrldp->label   = atoi(argv[3]);
			hdrldp->reqmsgid= atoi(argv[5]);
			send(pkt, 0);
			return (TCL_OK);
		} else if (strcmp(argv[1], "cr-mapping-msg") == 0) {
			/* 
			 * <agent> cr-mapping-msg <fec> <label> <lspid>
			 *         <premsgid>
			 */
			size_ = PKTsize("*","*");
			size_ += 32;      /* packet size adjustment */
			Packet* pkt = allocpkt();
			hdr_ldp *hdrldp = hdr_ldp::access(pkt);
			PKTinit(hdrldp, LDP_MappingMSG, "*", "*");
			hdrldp->fec     = atoi(argv[2]);
			hdrldp->label   = atoi(argv[3]);
			hdrldp->lspid   = atoi(argv[4]);
			hdrldp->reqmsgid= atoi(argv[5]);
			send(pkt, 0);
			return (TCL_OK);
		}
	} else if (argc == 7) {      
		if (strcmp(argv[1], "cr-request-msg") == 0) {
			/* 
			 * <agent> cr-request <fec> <pathvec> <er> <lspid> <rc>
			 */
			size_ = PKTsize(argv[3],argv[4]);
			if (atoi(argv[6]) > -1)  /* packet size adjustment */
				size_ += 24;
			else
				size_ += 16;
			Packet* pkt = allocpkt();
			hdr_ldp *hdrldp = hdr_ldp::access(pkt);
			PKTinit(hdrldp, LDP_RequestMSG, argv[3], argv[4]);
			hdrldp->fec     = atoi(argv[2]);
			hdrldp->lspid   = atoi(argv[5]);
			hdrldp->rc      = atoi(argv[6]);
			send(pkt, 0);
			return (TCL_OK);
		} else if (strcmp(argv[1], "msgtbl-install") == 0) {
			/* 
			 * <agent> msgtbl-install <msgid> <FEC> <LspID> 
			 *         <Src> <Pmsgid>
			 */
			int msgid  = atoi(argv[2]);
			int fec    = atoi(argv[3]);
			int LspID  = atoi(argv[4]);
			int src    = atoi(argv[5]);     
			int PMsgID = atoi(argv[6]);     
			int entrynb = MSGTinsert(msgid,fec,LspID,src,PMsgID);
			tcl.resultf("%d", entrynb);
			return (TCL_OK);
		}
	}
	return (Agent::command(argc, argv));
}

void LDPAgent::recv(Packet* pkt, Handler*)
{
	char out[400];  
	Tcl& tcl = Tcl::instance();

	hdr_ldp *hdrldp = hdr_ldp::access(pkt);
	int msgtype = hdrldp->msgtype;
	int msgid   = hdrldp->msgid;
	int fec     = hdrldp->fec;
	int label   = hdrldp->label;
	int reqmsgid= hdrldp->reqmsgid;
	int status  = hdrldp->status;
	int lspid   = hdrldp->lspid;
	int rc      = hdrldp->rc;
  
	char pathvec[400];
	char er[400];
	strcpy(pathvec, hdrldp->pathvec);
	strcpy(er, hdrldp->er);

	ns_addr_t src = hdr_ip::access(pkt)->src_;
	trace(src, hdrldp);

	free(hdrldp->pathvec);
	free(hdrldp->er);
	Packet::free(pkt);

	switch (msgtype) {
	case LDP_NotificationMSG:    /* Notification   */
		char code[30];
		strcpy(code, parse_status(status));
		sprintf(out, "%s get-notification-msg %d %s %d", 
			name(), src.addr_, code, lspid);
		tcl.eval(out);
		break;

	case LDP_MappingMSG:    /* Label Mapping  */
		if (lspid >= 0) {
			/* CR-LDP */
			sprintf(out, "%s get-cr-mapping-msg %d %d %d %d %d %d",
				name(), msgid, src.addr_, fec, 
				label, lspid, reqmsgid);
		} else { 
			sprintf(out, "%s get-mapping-msg %d %d %d %d %s %d", 
				name(), msgid, src.addr_, fec, 
				label, pathvec, reqmsgid);
		}
		tcl.eval(out);
		break;

	case LDP_RequestMSG:    /* Label Request  */
		if (lspid >= 0) { 
			sprintf(out,
				"%s get-cr-request-msg %d %d %d %s %s %d %d", 
				name(), msgid, src.addr_, fec, pathvec,
				er, lspid, rc);
		} else { 
			sprintf(out, "%s get-request-msg %d %d %d %s", 
				name(), msgid, src.addr_, fec, pathvec);
		}
		tcl.eval(out);
		break;

	case LDP_WithdrawMSG:    /* Label Withdraw */
		sprintf(out, "%s get-withdraw-msg %d %d %d", 
			name(), src.addr_, fec, lspid);
		tcl.eval(out);
		break;

	case LDP_ReleaseMSG:    /* Label Release */
		sprintf(out, "%s get-release-msg %d %d %d", 
			name(), src.addr_, fec, lspid);
		tcl.eval(out);
		break;
	}
}

int LDPAgent::MSGTinsert(int MsgID, int FEC, int LspID, int Src, int PMsgID)
{
	if (MSGT_.NB == LDP_MaxMSGTEntryNB - 1)
		return(-1);

	if (MSGTlocate(FEC, LspID, Src) > -1)
		return(-1);
    
	MSGT_.Entry[MSGT_.NB].MsgID     = MsgID;
	MSGT_.Entry[MSGT_.NB].FEC       = FEC;
	MSGT_.Entry[MSGT_.NB].LspID     = LspID;
	MSGT_.Entry[MSGT_.NB].Src       = Src;
	MSGT_.Entry[MSGT_.NB].PMsgID    = PMsgID;
	MSGT_.Entry[MSGT_.NB].LabelOp   = LDP_LabelALLOC;
	MSGT_.Entry[MSGT_.NB].ERLspID   = -1;
    
	MSGT_.NB++;

	return(MSGT_.NB-1);
}

void LDPAgent::MSGTdelete(int entrynb)
{
	if ( (entrynb > -1) && (entrynb < MSGT_.NB) ) {
		MSGT_.Entry[entrynb].MsgID = -1;
		MSGT_.Entry[entrynb].FEC   = MSGT_.Entry[entrynb].LspID  = -1;
		MSGT_.Entry[entrynb].Src   = MSGT_.Entry[entrynb].PMsgID = -1;
		MSGT_.Entry[entrynb].LabelOp = -1;
		MSGT_.Entry[entrynb].ERLspID = -1;
	}   
}

int LDPAgent::MSGTlocate(int MsgID)
{
	if ( MsgID < 0 )
		return(-1);
    
	for (int i=0; i<MSGT_.NB; i++) {
		if ( MSGT_.Entry[i].MsgID == MsgID )
			return(i);
	}

	return(-1);
}

int LDPAgent::MSGTlocate(int FEC, int LspID, int Src)
{
	int i;
	if ( (FEC < 0) && (Src < 0) ) {
		if ( LspID > -1) {
			for (i=0; i<MSGT_.NB; i++)
				if ( MSGT_.Entry[i].LspID  == LspID )
					return(i);
		}
		return(-1);
	}
       
	for (i=0; i<MSGT_.NB; i++) {
		if ( (MSGT_.Entry[i].FEC   == FEC  ) &&
		     (MSGT_.Entry[i].LspID == LspID) &&
		     (MSGT_.Entry[i].Src   == Src  ) )
			
			return(i);
	}

	return(-1);
}

void LDPAgent::MSGTlookup(int entrynb, int &MsgID, int &FEC, int &LspID, 
			  int &Src, int &PMsgID, int &LabelOp)
{
	if ( (entrynb > -1) && (entrynb < MSGT_.NB) ) {  
		MsgID    = MSGT_.Entry[entrynb].MsgID;
		FEC      = MSGT_.Entry[entrynb].FEC;
		LspID    = MSGT_.Entry[entrynb].LspID;
		Src      = MSGT_.Entry[entrynb].Src;
		PMsgID   = MSGT_.Entry[entrynb].PMsgID;
		LabelOp= MSGT_.Entry[entrynb].LabelOp;
	} else {  
		MsgID = FEC = LspID = Src = PMsgID = LabelOp = -1;
	}
}

void LDPAgent::MSGTdump()
{
	for (int i = 0; i < MSGT_.NB; i++) {
		cerr << "  # MsgID =" << MSGT_.Entry[i].MsgID << "  ";
		cerr << "  # FEC   =" << MSGT_.Entry[i].FEC   << "  ";
		cerr << "  # LspID =" << MSGT_.Entry[i].LspID << "  ";
		cerr << "  # Src   =" << MSGT_.Entry[i].Src   << "  ";
		cerr << "  # PMsgID=" << MSGT_.Entry[i].PMsgID<< "  ";
		cerr << "  # LabelOp=" << MSGT_.Entry[i].LabelOp << "\n";
	}
}

void LDPAgent::trace(ns_addr_t src, hdr_ldp *hdrldp)
{
	// XXX will be changed later to directly write to a output channel
	// instead of sending stuff to otcl
	if (trace_ldp_ == 1) { 
		const char *msgtype = parse_msgtype(hdrldp->msgtype,
						    hdrldp->lspid);
		const char *status = (hdrldp->msgtype == 0x0001) ? 
			parse_status(hdrldp->status) : "*";
		Tcl::instance().evalf("%s trace-ldp-packet %d %d %s %d %d %d "
				      "%s %d %s %d %d %s %7f",
				      name(),
				      src.addr_,
				      src.port_,
				      msgtype, 
				      hdrldp->msgid, 
				      hdrldp->fec, 
				      hdrldp->label, 
				      hdrldp->pathvec, 
				      hdrldp->lspid, 
				      hdrldp->er, 
				      hdrldp->rc, 
				      hdrldp->reqmsgid,
				      status,
				      Scheduler::instance().clock());  
	}	
}

char* LDPAgent::parse_msgtype(int msgtype, int lspid)
{

	switch (msgtype) {
	case LDP_NotificationMSG:    /* Notification   */
		return("Notification");

	case LDP_MappingMSG:    /* Label Mapping  */
		if (lspid >= 0)          /* CR-LDP */
			return("CR-Mapping");
		else
			return("Mapping");
		
	case LDP_RequestMSG:    /* Label Request  */
		if (lspid >= 0)
			return("CR-Request");
		else
			return("Request");
		
	case LDP_WithdrawMSG:    /* Label Withdraw */
		return("Withdraw");
		
	case LDP_ReleaseMSG:    /* Label Release */
		return("Release");
	}

	return ("Error");
}

char* LDPAgent::parse_status(int status)
{
	switch (status) {
	case LDP_LoopDetected:
		return "LoopDetected";
		
	case LDP_NoRoute:
		return "NoRoute";
		
	default:
		return "Unknown";
	}
}