-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdsragent.cc
4847 lines (4022 loc) · 156 KB
/
dsragent.cc
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
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* dsragent.cc
* Copyright (C) 2000 by the University of Southern California
* $Id: dsragent.cc,v 1.38 2009/12/30 22:06:34 tom_henderson 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.
*
*/
//
// Other copyrights might apply to parts of this software and are so
// noted when applicable.
//
/*
dsragent.cc
requires a radio model such that sendPacket returns true
iff the packet is recieved by the destination node.
Ported from CMU/Monarch's code, appropriate copyright applies.
*/
extern "C" {
#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <float.h>
}
#include <string>
#include <iostream>
#include <stdlib.h>
#include <object.h>
#include <agent.h>
#include <trace.h>
#include <packet.h>
#include <scheduler.h>
#include <random.h>
#include <mac.h>
#include <ll.h>
#include <cmu-trace.h>
#include "path.h"
#include "srpacket.h"
#include "routecache.h"
#include "requesttable.h"
#include "dsragent.h"
/*==============================================================
Declarations and global defintions
------------------------------------------------------------*/
// #define NEW_IFQ_LOGIC
// #define NEW_REQUEST_LOGIC
#define NEW_SALVAGE_LOGIC
#ifdef NEW_SALVAGE_LOGIC
/*
* Maximum number of times that a packet may be salvaged.
*/
static int dsr_salvage_max_attempts = 15;
/*
* Maximum number of Route Requests that can be sent for a salvaged
* packets that was originated at another node.
*/
static int dsr_salvage_max_requests = 1;
/*
* May an intermediate node send a propagating Route Request for
* a salvaged packet that was originated elsewhere.
*/
static bool dsr_salvage_allow_propagating = 0;
#endif
/* couple of flowstate constants... */
static const bool dsragent_enable_flowstate = true;
static const bool dsragent_prefer_default_flow = true;
static const bool dsragent_prefer_shorter_over_default = true;
static const bool dsragent_always_reestablish = true;
static const int min_adv_interval = 5;
static const int default_flow_timeout = 60;
//#define DSRFLOW_VERBOSE
//ACU281 Code Section Begin
//static int* baitList;
//static int* suspectList; /* address of node that 'Index' node want us to monitor it */
//static int* suspectListPackets; /*number of Data packet that Node 'Index' send to suspect node,
// -and we must monitor forwarding for that node */
static const int traceit = 0;
static const int traceit2 = 0;
static const int traceit3 = 0;
static const int traceit4 = 0;
static const int traceit5 = 1;
static const int TEST_PACKET_NUMBER=6;
static const int verbose = 1;
static const int verbose_srr = 1;
static const int verbose_ssalv = 1;
//static bool malicious;
//ACU281 Code Section End
/*
static const int verbose = 0;
static const int verbose_srr = 0;
static const int verbose_ssalv = 1;
*/
#define DEFINED_Test_Pkt_DELAY 2.0
DSRAgent_List DSRAgent::agthead = { 0 };
Time arp_timeout = 30.0e-3; // (sec) arp request timeout
Time rt_rq_period = 0.5; // (sec) length of one backoff period
Time rt_rq_max_period = 10.0; // (sec) maximum time between rt reqs
Time send_timeout = SEND_TIMEOUT; // (sec) how long a packet can live in sendbuf
#if 0
/* used in route reply holdoffs, which are currently disabled -dam 5/98 */
Time rt_rep_holdoff_period = 3.0e-3; // secs (about 2*process_time)
// to determine how long to sit on our rt reply we pick a number
// U(O.0,rt_rep_holdoff_period) + (our route length-1)*rt_rep_holdoff
#endif //0
Time grat_hold_down_time = 1.0; // (sec) min time between grat replies for
// same route
Time max_err_hold = 1.0; // (sec)
// maximum time between when we recv a route error told to us, and when we
// transmit a propagating route request that can carry that data. used to
// keep us from propagating stale route error data
/*************** selectors ******************/
bool dsragent_snoop_forwarded_errors = true;
// give errors we forward to our cache?
bool dsragent_snoop_source_routes = true;
// should we snoop on any source routes we see?
bool dsragent_reply_only_to_first_rtreq = false;
// should we only respond to the first route request we receive from a host?
bool dsragent_propagate_last_error = true;
// should we take the data from the last route error msg sent to us
// and propagate it around on the next propagating route request we do?
// this is aka grat route error propagation
bool dsragent_send_grat_replies = true;
// should we send gratuitous replies to effect route shortening?
bool dsragent_salvage_with_cache = true;
// should we consult our cache for a route if we get a xmitfailure
// and salvage the packet using the route if possible
bool dsragent_use_tap = true;
// should we listen to a promiscuous tap?
bool dsragent_reply_from_cache_on_propagating = true;
// should we consult the route cache before propagating rt req's and
// answer if possible?
bool dsragent_ring_zero_search = true;
// should we send a non-propagating route request as the first action
// in each route discovery action?
// NOTE: to completely turn off replying from cache, you should
// set both dsragent_ring_zero_search and
// dsragent_reply_from_cache_on_propagating to false
bool dsragent_dont_salvage_bad_replies = true;
// if we have an xmit failure on a packet, and the packet contains a
// route reply, should we scan the reply to see if contains the dead link?
// if it does, we won't salvage the packet unless there's something aside
// from a reply in it (in which case we salvage, but cut out the rt reply)
bool dsragent_require_bi_routes = true;
// do we need to have bidirectional source routes?
// [XXX this flag doesn't control all the behaviors and code that assume
// bidirectional links -dam 5/14/98]
#if 0
bool lsnode_holdoff_rt_reply = true;
// if we have a cached route to reply to route_request with, should we
// hold off and not send it for a while?
bool lsnode_require_use = true;
// do we require ourselves to hear a route requestor use a route
// before we withold our route, or is merely hearing another (better)
// route reply enough?
#endif
/*
Our strategy is as follows:
- it's only worth discovering bidirectional routes, since all data
paths will have to have to be bidirectional for 802.11 ACKs to work
- reply to all route requests for us that we recv (not just the first one)
but reply to them by reversing the route and unicasting. don't do
a route request (since that will end up returning the requestor lots of
routes that are potentially unidirectional). By reversing the discovered
route for the route reply, only routes that are bidirectional will make it
back the original requestor
- once a packet goes into the sendbuffer, it can't be piggybacked on a
route request. the code assumes that the only thing that removes
packets from the send buff is the StickPktIn routine, or the route reply
arrives routine
*/
/* Callback helpers */
void
XmitFailureCallback(Packet *pkt, void *data)
{
DSRAgent *agent = (DSRAgent *)data; // cast of trust
agent->xmitFailed(pkt);
}
void
XmitFlowFailureCallback(Packet *pkt, void *data)
{
DSRAgent *agent = (DSRAgent *)data;
agent->xmitFlowFailed(pkt);
}
/*===========================================================================
SendBuf management and helpers
---------------------------------------------------------------------------*/
void
SendBufferTimer::expire(Event *)
{
a_->sendBufferCheck();
resched(BUFFER_CHECK + BUFFER_CHECK * Random::uniform(1.0));
}
void
DSRAgent::dropSendBuff(SRPacket &p)
// log p as being dropped by the sendbuffer in DSR agent
{
trace("Ssb %.5f _%s_ dropped %s -> %s", Scheduler::instance().clock(),
net_id.dump(), p.src.dump(), p.dest.dump());
drop(p.pkt, DROP_RTR_QTIMEOUT);
p.pkt = 0;
p.route.reset();
}
void
DSRAgent::stickPacketInSendBuffer(SRPacket& p)
{
Time min = DBL_MAX;
int min_index = 0;
int c;
if (verbose)
trace("Sdebug %.5f _%s_ stuck into send buff %s -> %s",
Scheduler::instance().clock(),
net_id.dump(), p.src.dump(), p.dest.dump());
for (c = 0 ; c < SEND_BUF_SIZE ; c ++)
if (send_buf[c].p.pkt == NULL)
{
send_buf[c].t = Scheduler::instance().clock();
send_buf[c].p = p;
return;
}
else if (send_buf[c].t < min)
{
min = send_buf[c].t;
min_index = c;
}
// kill somebody
dropSendBuff(send_buf[min_index].p);
send_buf[min_index].t = Scheduler::instance().clock();
send_buf[min_index].p = p;
}
void
DSRAgent::sendBufferCheck()
// see if any packets in send buffer need route requests sent out
// for them, or need to be expired
{ // this is called about once a second. run everybody through the
// get route for pkt routine to see if it's time to do another
// route request or what not
int c;
for (c = 0 ; c <SEND_BUF_SIZE ; c++) {
if (send_buf[c].p.pkt == NULL)
continue;
if (Scheduler::instance().clock() - send_buf[c].t > send_timeout) {
dropSendBuff(send_buf[c].p);
send_buf[c].p.pkt = 0;
continue;
}
#ifdef DEBUG
trace("Sdebug %.5f _%s_ checking for route for dst %s",
Scheduler::instance().clock(), net_id.dump(),
send_buf[c].p.dest.dump());
#endif
handlePktWithoutSR(send_buf[c].p, true);
#ifdef DEBUG
if (send_buf[c].p.pkt == NULL)
trace("Sdebug %.5f _%s_ sendbuf pkt to %s liberated by handlePktWOSR",
Scheduler::instance().clock(), net_id.dump(),
send_buf[c].p.dest.dump());
#endif
}
}
/*==============================================================
Route Request backoff
------------------------------------------------------------*/
static bool
BackOffTest(Entry *e, Time time)
// look at the entry and decide if we can send another route
// request or not. update entry as well
{
Time next = ((Time) (0x1 << (e->rt_reqs_outstanding * 2))) * rt_rq_period;
if (next > rt_rq_max_period)
next = rt_rq_max_period;
if (next + e->last_rt_req > time)
return false;
// don't let rt_reqs_outstanding overflow next on the LogicalShiftsLeft's
if (e->rt_reqs_outstanding < 15)
e->rt_reqs_outstanding++;
e->last_rt_req = time;
return true;
}
/*===========================================================================
DSRAgent OTcl linkage
---------------------------------------------------------------------------*/
static class DSRAgentClass : public TclClass {
public:
DSRAgentClass() : TclClass("Agent/DSRAgent") {}
TclObject* create(int, const char*const*) {
return (new DSRAgent);
}
} class_DSRAgent;
/*===========================================================================
DSRAgent methods
---------------------------------------------------------------------------*/
DSRAgent::DSRAgent(): Agent(PT_DSR), ptimer(this), request_table(128), route_cache(NULL),
send_buf_timer(this), flow_table(), ars_table()
{
//ACU281 Code Section Begin
is_in_Promisc_mode=false;
timer_triggered=false;
sim_time=Scheduler::instance().clock();
is_in_waiting_4forward=false;
malicious=false;
initialBait=0;
inform_SeqNumber=0;
int numberOfNodes=God::instance()->nodes();
safe_value=2*numberOfNodes;
baitList=new int [numberOfNodes];
inform_seq_table=new int [numberOfNodes];
malicious_list=new int [numberOfNodes];
malicious_list_condidate=new int [numberOfNodes];
malicious_list_cond_time=new double [numberOfNodes];
malicious_list_cond_recv_pkt=new int [numberOfNodes];
malicious_node_index=-1;
// suspectList=new int [numberOfNodes];
// suspectListPackets=new int [numberOfNodes];
is_in_Promisc_mode=false;
for (int i=0;i<numberOfNodes;++i)
{
malicious_list_condidate[i]=i;
malicious_list_cond_time[i]=0.0;
malicious_list_cond_recv_pkt[i]=0;
baitList[i]=i;
inform_seq_table[i]=0;
}
//ACU281 Code Section End
int c;
route_request_num = 1;
//MCBDS
test_packet_num=1;
route_cache = makeRouteCache();
for (c = 0 ; c < RTREP_HOLDOFF_SIZE ; c++)
rtrep_holdoff[c].requested_dest = invalid_addr;
num_heldoff_rt_replies = 0;
target_ = 0;
logtarget = 0;
grat_hold_victim = 0;
for (c = 0; c < RTREP_HOLDOFF_SIZE ; c++) {
grat_hold[c].t = 0;
grat_hold[c].p.reset();
}
//bind("off_SR_", &off_sr_);
//bind("off_ll_", &off_ll_);
//bind("off_mac_", &off_mac_);
//bind("off_ip_", &off_ip_);
ll = 0;
ifq = 0;
mac_ = 0;
LIST_INSERT_HEAD(&agthead, this, link);
#ifdef DSR_FILTER_TAP
bzero(tap_uid_cache, sizeof(tap_uid_cache));
#endif
route_error_held = false;
//initiateBaitPhase();
}
void DSRAgent::initiateBaitPhase()
{
//ACU281 Code Section Begin
//int myAddr =ID(net_id.getNSAddr_t(), ::IP).getNSAddr_t();
int myAddr2=net_id.getNSAddr_t();
//if(traceit2==1){trace("ACU281: %u, %u \n %s, %S",myAddr,myAddr2,ID(net_id.getNSAddr_t(), ::IP).dump(),net_id.dump());}
int nn=0;
int totalNodes=God::instance()->nodes();
nsaddr_t nodeNeighbor;
if(traceit==1){ trace("___________");
trace("Node %u of %u Start finding a neighbor node to use as Bait",myAddr2,totalNodes);}
//if(traceit2==1){trace("ACU281: Total Nodes Number is: %u",totalNodes);}
for ( nn=0;nn<totalNodes;++nn)
{
//trace("nn=%u",nn);
//if(nn!=myAddr2 && God::instance()->IsNeighbor(myAddr2,nn))
// break;
if(nn!=myAddr2 && God::instance()->hops(myAddr2,nn)<=1)
{
nodeNeighbor=(nsaddr_t)nn;
baitList[myAddr2]=nn;
ID nodeNeighborID=ID(nodeNeighbor,::IP);
trace("%u is Neighbor to %u . \t So choose [%u] as Bait and send a RReq'",myAddr2,nn,(int)nodeNeighborID.getNSAddr_t());
getRouteForPacketPRIME(nodeNeighborID,false);
++initialBait;
break;
}
//getRouteForPacketPRIME(,false);
}
}
DSRAgent::~DSRAgent()
{
fprintf(stderr,"DFU: Don't do this! I haven't figured out ~DSRAgent\n");
exit(-1);
}
//MCBDS
//Timer
void PrintTimer::handle(Event* e)
{
// fprintf (stderr, "This is a test for the usage of timer [%u] %f.\n", (int)(agent->net_id.addr),Scheduler::instance().clock());
agent->myTimer2();
//DSRAgent::trace("ACU281:: Timer triggered");
//if you want to slchedule this timer periodically
//#define DEFINED_DELAY 1.0 //sec
Scheduler::instance().schedule(this, &intr, DEFINED_Test_Pkt_DELAY);
}
void
DSRAgent::Terminate()
{
if(traceit==1){ trace("___________");
trace("Terminate() start \t\t[Node %s]",net_id.dump());}
if(traceit5)
{
std::string malStr="";
char tmp[3];
for(int ii=0;ii<=malicious_node_index;++ii)
{
//itoa(ii,tmp,10);
sprintf(tmp,"%d",ii);
malStr+=",";
sprintf(tmp,"%d",(int)malicious_list[ii]);
malStr+=std::string(tmp)+", ";
}
trace("ACU281:: Malicious list: %s",malStr.c_str());
}
int c;
for (c = 0 ; c < SEND_BUF_SIZE ; c++) {
if (send_buf[c].p.pkt) {
drop(send_buf[c].p.pkt, DROP_END_OF_SIMULATION);
send_buf[c].p.pkt = 0;
}
}
if(traceit==1){ trace("___________");
trace("Terminate() end \t\t[Node %s]",net_id.dump());}
}
void
DSRAgent::testinit()
{
if(traceit==1){ trace("___________");
trace("testinit begin start \t\t[Node %s]",net_id.dump());}
struct hdr_sr hsr;
if (net_id == ID(1,::IP))
{
printf("adding route to 1\n");
hsr.init();
hsr.append_addr( 1, NS_AF_INET );
hsr.append_addr( 2, NS_AF_INET );
hsr.append_addr( 3, NS_AF_INET );
hsr.append_addr( 4, NS_AF_INET );
route_cache->addRoute(Path(hsr.addrs(),
hsr.num_addrs()), 0.0, ID(1,::IP));
}
if (net_id == ID(3,::IP))
{
printf("adding route to 3\n");
hsr.init();
hsr.append_addr( 3, NS_AF_INET );
hsr.append_addr( 2, NS_AF_INET );
hsr.append_addr( 1, NS_AF_INET );
route_cache->addRoute(Path(hsr.addrs(),
hsr.num_addrs()), 0.0, ID(3,::IP));
}
if(traceit==1){ trace("___________");
trace("testinit end \t\t[Node %s]",net_id.dump());}
}
int
DSRAgent::command(int argc, const char*const* argv)
{
if(traceit==1){ trace("___________");
trace("command start \t\t[Node %s]",net_id.dump());}
TclObject *obj;
if (argc == 2)
{
if (strcasecmp(argv[1], "testinit") == 0)
{
testinit();
return TCL_OK;
}
//ACU281 Code Section Begin
if(strcasecmp(argv[1], "hacker") == 0) {
malicious = true;
trace("Node %s starts to be a Malicious Node",net_id.dump());
return TCL_OK;
}
//ACU281 Code Section End
if (strcasecmp(argv[1], "reset") == 0)
{
Terminate();
return Agent::command(argc, argv);
}
if (strcasecmp(argv[1], "check-cache") == 0)
{
return route_cache->command(argc, argv);
}
if (strcasecmp(argv[1], "startdsr") == 0)
{
if (ID(1,::IP) == net_id)
{ // log the configuration parameters of the dsragent
trace("Sconfig %.5f tap: %s snoop: rts? %s errs? %s",
Scheduler::instance().clock(),
dsragent_use_tap ? "on" : "off",
dsragent_snoop_source_routes ? "on" : "off",
dsragent_snoop_forwarded_errors ? "on" : "off");
trace("Sconfig %.5f salvage: %s !bd replies? %s",
Scheduler::instance().clock(),
dsragent_salvage_with_cache ? "on" : "off",
dsragent_dont_salvage_bad_replies ? "on" : "off");
trace("Sconfig %.5f grat error: %s grat reply: %s",
Scheduler::instance().clock(),
dsragent_propagate_last_error ? "on" : "off",
dsragent_send_grat_replies ? "on" : "off");
trace("Sconfig %.5f $reply for props: %s ring 0 search: %s",
Scheduler::instance().clock(),
dsragent_reply_from_cache_on_propagating ? "on" : "off",
dsragent_ring_zero_search ? "on" : "off");
}
// cheap source of jitter
send_buf_timer.sched(BUFFER_CHECK
+ BUFFER_CHECK * Random::uniform(1.0));
return route_cache->command(argc,argv);
}
}
else if(argc == 3)
{
if (strcasecmp(argv[1], "addr") == 0)
{
int temp;
temp = Address::instance().str2addr(argv[2]);
net_id = ID(temp, ::IP);
flow_table.setNetAddr(net_id.addr);
route_cache->net_id = net_id;
return TCL_OK;
}
else if(strcasecmp(argv[1], "mac-addr") == 0)
{
MAC_id = ID(atoi(argv[2]), ::MAC);
route_cache->MAC_id = MAC_id;
return TCL_OK;
}
else if(strcasecmp(argv[1], "rt_rq_max_period") == 0)
{
rt_rq_max_period = strtod(argv[2],NULL);
return TCL_OK;
}
else if(strcasecmp(argv[1], "rt_rq_period") == 0)
{
rt_rq_period = strtod(argv[2],NULL);
return TCL_OK;
}
else if(strcasecmp(argv[1], "send_timeout") == 0)
{
send_timeout = strtod(argv[2],NULL);
return TCL_OK;
}
if( (obj = TclObject::lookup(argv[2])) == 0)
{
fprintf(stderr, "DSRAgent: %s lookup of %s failed\n", argv[1],
argv[2]);
return TCL_ERROR;
}
if (strcasecmp(argv[1], "log-target") == 0) {
logtarget = (Trace*) obj;
return route_cache->command(argc, argv);
}
else if (strcasecmp(argv[1], "tracetarget") == 0 )
{
logtarget = (Trace*) obj;
return route_cache->command(argc, argv);
}
else if (strcasecmp(argv[1], "install-tap") == 0)
{
mac_ = (Mac*) obj;
mac_->installTap(this);
return TCL_OK;
}
else if (strcasecmp(argv[1], "node") == 0)
{
node_ = (MobileNode *) obj;
return TCL_OK;
}
else if (strcasecmp (argv[1], "port-dmux") == 0)
{
port_dmux_ = (NsObject *) obj;
return TCL_OK;
}
}
else if (argc == 4)
{
if (strcasecmp(argv[1], "add-ll") == 0)
{
if( (obj = TclObject::lookup(argv[2])) == 0) {
fprintf(stderr, "DSRAgent: %s lookup of %s failed\n", argv[1],
argv[2]);
return TCL_ERROR;
}
ll = (NsObject*) obj;
if( (obj = TclObject::lookup(argv[3])) == 0) {
fprintf(stderr, "DSRAgent: %s lookup of %s failed\n", argv[1],
argv[3]);
return TCL_ERROR;
}
ifq = (CMUPriQueue *) obj;
return TCL_OK;
}
}
if(traceit==1){ trace("___________");
trace("command end \t\t[Node %s]",net_id.dump());}
return Agent::command(argc, argv);
}
void
DSRAgent::sendOutBCastPkt(Packet *p)
{
if(traceit==1){ trace("___________");
trace("sendOutBCastPkt(Packet *p) start \t\t[Node %s]",net_id.dump());}
hdr_cmn *cmh = hdr_cmn::access(p);
if(cmh->direction() == hdr_cmn::UP)
cmh->direction() = hdr_cmn::DOWN;
// no jitter required
Scheduler::instance().schedule(ll, p, 0.0);
if(traceit==1){ trace("___________");
trace("sendOutBCastPkt(Packet *p) end \t\t[Node %s]",net_id.dump());}
}
void
DSRAgent::recv(Packet* packet, Handler*)
/* handle packets with a MAC destination address of this host, or
the MAC broadcast addr */
{
if(traceit==1){ trace("___________");
trace("recv(Packet* packet, Handler*) start \t\t[Node %s]",net_id.dump());}
if(traceit2){
std::string Str=" ";
char tmp[3];
for(int ii=0;ii<=malicious_node_index;++ii)
{
//itoa(ii,tmp,10);
sprintf(tmp,"%d",ii);
Str+="["+std::string(tmp)+"]=";
sprintf(tmp,"%d",(int)malicious_list[ii]);
Str+=std::string(tmp)+", ";
}
trace("ACU281:: Content of malicious_list: %s",Str.c_str());
}
hdr_sr *srh = hdr_sr::access(packet);
hdr_ip *iph = hdr_ip::access(packet);
hdr_cmn *cmh = hdr_cmn::access(packet);
if(srh->inform_msg())
{
if(traceit2)
trace("ACU281: recv packet is Inform Message");
}
// special process for GAF
if (cmh->ptype() == PT_GAF) {
if (iph->daddr() == (int)IP_BROADCAST) {
if(cmh->direction() == hdr_cmn::UP)
cmh->direction() = hdr_cmn::DOWN;
Scheduler::instance().schedule(ll,packet,0);
return;
} else {
target_->recv(packet, (Handler*)0);
return;
}
}
assert(cmh->size() >= 0);
SRPacket p(packet, srh);
//p.dest = ID(iph->dst(),::IP);
//p.src = ID(iph->src(),::IP);
p.dest = ID((Address::instance().get_nodeaddr(iph->daddr())),::IP);
p.src = ID((Address::instance().get_nodeaddr(iph->saddr())),::IP);
if(traceit==1){ trace("___________");
trace("recv(Packet* packet, Handler*) InFunction \t\t[Node %s]\t %s -> %s",net_id.dump(), p.src.dump(),p.dest.dump());
trace(p.route.dump());}
/*
//ACU281 Code Section Begin
if (malicious==true)
{
if(traceit==1){ trace("___________");
trace("[Node %s]: Ha ha ha ha, I am a Malicious Node :D",net_id.dump());}
}
else
{
if(traceit==1){ trace("___________");
trace("[Node %s]: He he he he, I am NOT a Malicious Node :p",net_id.dump());}
}
//ACU281 Code Section End
*/
assert(logtarget != 0);
if (srh->valid() != 1) {
//ACU281 Code Section Begin
if(initialBait<1 )
{
initiateBaitPhase();
return;
}
//ACU281 Code Section End
unsigned int dst = cmh->next_hop();
if (dst == IP_BROADCAST) {
// extensions for mobileIP --Padma, 04/99.
// Brdcast pkt - treat differently
if (p.src == net_id)
{
// I have originated this pkt
sendOutBCastPkt(packet);
}else
//hand it over to port-dmux
port_dmux_->recv(packet, (Handler*)0);
} else {
// this must be an outgoing packet, it doesn't have a SR header on it
srh->init(); // give packet an SR header now
cmh->size() += IP_HDR_LEN; // add on IP header size
if (verbose)
trace("S %.9f _%s_ originating %s -> %s",
Scheduler::instance().clock(), net_id.dump(), p.src.dump(),
p.dest.dump());
handlePktWithoutSR(p, false);
goto done;
}
}
else if (srh->valid() == 1)
{
if(srh->test_Packet())
if(traceit2)
trace("ACU281:: Test Packet Received");
if(srh->inform_msg())
{
handleInformMessage(p);
goto done;
}
if (p.dest == net_id || p.dest == IP_broadcast)
{ // this packet is intended for us
handlePacketReceipt(p);
goto done;
}
// should we check to see if it's an error packet we're handling
// and if so call processBrokenRouteError to snoop
if (dsragent_snoop_forwarded_errors && srh->route_error())
{
processBrokenRouteError(p);
}
if(malicious_node_index>=0 && srh->route_reply() )
if( isMalicious((int)(p.src.getNSAddr_t())))
{
if(traceit==1)
trace("ACU281: Reply Packet (RREP) received from Malicious node [%u], so I'm Drop it",(int)(p.src.getNSAddr_t()));
Packet::free(p.pkt);
p.pkt =0;
goto done;
}
if (srh->route_request())
{ // propagate a route_request that's not for us
//ACU281 Code Section Begin
if (malicious==true )
{
if(traceit==1){ trace("___________");
trace("[Node %s]: Ha ha ha ha, I am a Malicious Node :D (so I'm sending a Fake RRep)",net_id.dump());}
sendFakeRRep(p);
}
else
{
if(traceit==1){ trace("___________");
trace("[Node %s]: I am NOT a Malicious Node :) (so I'm handleRouteRequest(p) )",net_id.dump());}
handleRouteRequest(p);
}
//ACU281 Code Section End
//handleRouteRequest(p);
}
else
{ // we're not the intended final recpt, but we're a hop
//ACU281 Code Section Begin
/*==============================================================
If packet is RREP, calculate K' and attach it
------------------------------------------------------------*/
//ACU281 Code Section Begin
if (srh->route_reply() && p.src!=net_id)
{
if(traceit==1){ trace("___________"); trace("ACU281: [Node %s] srh->route_reply_len()= %u",net_id.dump(),srh->route_reply_len());}
srh->addKPrime_New(net_id.getNSAddr_t());
// bool indx=false;
// for(int jj=0;jj<srh->route_reply_len();++jj)
// {
// sr_addr tmp=srh->reply_addrs()[jj];
// // trace("Route Reply Content %s",ID(srh->reply_addrs()[jj].addr, ::IP).dump());
// if(traceit==1){trace("Route Reply Content %u",((int)((tmp.addr))));}
// // trace("Route Reply Content %s",p.route[jj].dump());
// if(indx)
// {
// //trace("sssssssssssss=%u",(int)tmp.addr);
// kp->kP_[kp->kP_len_++]=tmp;
// }
// else{
// if((int)tmp.addr==(int)net_id.getNSAddr_t())
// {
// kp->kP_Sender_=tmp;
//
// indx=true;
// }
// }
// }
// if(indx)
// {
// srh->addKPrime(*kp);
// if(traceit==1){ trace("___________");
// trace("KPList Size is:%u",srh->kPrimeListSize());}
// }
// ACU281 Code Section End
}
if (malicious==true && !srh->route_reply())
{
if(traceit==1){ trace("___________");
trace("[Node %s]: Ha ha ha ha, I am a Malicious Node :D (so I'm Drop Data Packet)",net_id.dump());}
Packet::free(p.pkt);
p.pkt =0;
}
else
{
if(traceit==1){ trace("___________");
trace("[Node %s]: I am NOT a Malicious Node :) (so I'm handleForwarding(p) )",net_id.dump());}
trace("Before handleforward: route is %s",p.route.dump());