File: pim_vif.cc

package info (click to toggle)
xorp 1.6-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 53,200 kB
  • ctags: 61,417
  • sloc: cpp: 399,321; sh: 24,357; ansic: 20,231; python: 5,142; makefile: 3,964; lex: 1,632; yacc: 1,474; awk: 956; sed: 33
file content (2011 lines) | stat: -rw-r--r-- 53,311 bytes parent folder | download
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
// -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-

// Copyright (c) 2001-2009 XORP, Inc.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License, Version 2, June
// 1991 as published by the Free Software Foundation. Redistribution
// and/or modification of this program under the terms of any other
// version of the GNU General Public License is not permitted.
// 
// 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. For more details,
// see the GNU General Public License, Version 2, a copy of which can be
// found in the XORP LICENSE.gpl file.
// 
// XORP Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
// http://xorp.net

#ident "$XORP: xorp/pim/pim_vif.cc,v 1.74 2009/01/05 18:31:03 jtc Exp $"


//
// PIM virtual interfaces implementation.
//


#include "pim_module.h"
#include "libxorp/xorp.h"
#include "libxorp/xlog.h"
#include "libxorp/debug.h"
#include "libxorp/random.h"
#include "libxorp/ipvx.hh"

#include "libproto/checksum.h"

#include "pim_node.hh"
#include "pim_vif.hh"


//
// Exported variables
//

//
// Local constants definitions
//

//
// Local structures/classes, typedefs and macros
//

//
// Local variables
//

//
// Local functions prototypes
//


/**
 * PimVif::PimVif:
 * @pim_node: The PIM node this interface belongs to.
 * @vif: The generic Vif interface that contains various information.
 * 
 * PIM protocol vif constructor.
 **/
PimVif::PimVif(PimNode& pim_node, const Vif& vif)
    : ProtoUnit(pim_node.family(), pim_node.module_id()),
      Vif(vif),
      _pim_node(pim_node),
      _dr_addr(pim_node.family()),
      _pim_nbr_me(*this, IPvX::ZERO(pim_node.family()), PIM_VERSION_DEFAULT),
      _domain_wide_addr(IPvX::ZERO(pim_node.family())),
      _hello_triggered_delay(PIM_HELLO_HELLO_TRIGGERED_DELAY_DEFAULT),
      _hello_period(PIM_HELLO_HELLO_PERIOD_DEFAULT,
		    callback(this, &PimVif::set_hello_period_callback)),
      _hello_holdtime(PIM_HELLO_HELLO_HOLDTIME_DEFAULT,
		      callback(this, &PimVif::set_hello_holdtime_callback)),
      _dr_priority(PIM_HELLO_DR_PRIORITY_DEFAULT,
		   callback(this, &PimVif::set_dr_priority_callback)),
      _propagation_delay(PIM_PROPAGATION_DELAY_MSEC_DEFAULT,
			 callback(this,
				  &PimVif::set_propagation_delay_callback)),
      _override_interval(PIM_OVERRIDE_INTERVAL_MSEC_DEFAULT,
			 callback(this,
				  &PimVif::set_override_interval_callback)),
      _is_tracking_support_disabled(false,
				    callback(this,
					     &PimVif::set_is_tracking_support_disabled_callback)),
      _accept_nohello_neighbors(false),
      _genid(xorp_random() % 0xffffffffU,
	     callback(this, &PimVif::set_genid_callback)),
      _join_prune_period(PIM_JOIN_PRUNE_PERIOD_DEFAULT,
			 callback(this,
				  &PimVif::set_join_prune_period_callback)),
      _join_prune_holdtime(PIM_JOIN_PRUNE_HOLDTIME_DEFAULT),
      _assert_time(PIM_ASSERT_ASSERT_TIME_DEFAULT),
      _assert_override_interval(PIM_ASSERT_ASSERT_OVERRIDE_INTERVAL_DEFAULT),
      //
      _pimstat_hello_messages_received(0),
      _pimstat_hello_messages_sent(0),
      _pimstat_hello_messages_rx_errors(0),
      _pimstat_register_messages_received(0),
      _pimstat_register_messages_sent(0),
      _pimstat_register_messages_rx_errors(0),
      _pimstat_register_stop_messages_received(0),
      _pimstat_register_stop_messages_sent(0),
      _pimstat_register_stop_messages_rx_errors(0),
      _pimstat_join_prune_messages_received(0),
      _pimstat_join_prune_messages_sent(0),
      _pimstat_join_prune_messages_rx_errors(0),
      _pimstat_bootstrap_messages_received(0),
      _pimstat_bootstrap_messages_sent(0),
      _pimstat_bootstrap_messages_rx_errors(0),
      _pimstat_assert_messages_received(0),
      _pimstat_assert_messages_sent(0),
      _pimstat_assert_messages_rx_errors(0),
      _pimstat_graft_messages_received(0),
      _pimstat_graft_messages_sent(0),
      _pimstat_graft_messages_rx_errors(0),
      _pimstat_graft_ack_messages_received(0),
      _pimstat_graft_ack_messages_sent(0),
      _pimstat_graft_ack_messages_rx_errors(0),
      _pimstat_candidate_rp_messages_received(0),
      _pimstat_candidate_rp_messages_sent(0),
      _pimstat_candidate_rp_messages_rx_errors(0),
      //
      _pimstat_unknown_type_messages(0),
      _pimstat_unknown_version_messages(0),
      _pimstat_neighbor_unknown_messages(0),
      _pimstat_bad_length_messages(0),
      _pimstat_bad_checksum_messages(0),
      _pimstat_bad_receive_interface_messages(0),
      _pimstat_rx_interface_disabled_messages(0),
      _pimstat_rx_register_not_rp(0),
      _pimstat_rp_filtered_source(0),
      _pimstat_unknown_register_stop(0),
      _pimstat_rx_join_prune_no_state(0),
      _pimstat_rx_graft_graft_ack_no_state(0),
      _pimstat_rx_graft_on_upstream_interface(0),
      _pimstat_rx_candidate_rp_not_bsr(0),
      _pimstat_rx_bsr_when_bsr(0),
      _pimstat_rx_bsr_not_rpf_interface(0),
      _pimstat_rx_unknown_hello_option(0),
      _pimstat_rx_data_no_state(0),
      _pimstat_rx_rp_no_state(0),
      _pimstat_rx_aggregate(0),
      _pimstat_rx_malformed_packet(0),
      _pimstat_no_rp(0),
      _pimstat_no_route_upstream(0),
      _pimstat_rp_mismatch(0),
      _pimstat_rpf_neighbor_unknown(0),
      //
      _pimstat_rx_join_rp(0),
      _pimstat_rx_prune_rp(0),
      _pimstat_rx_join_wc(0),
      _pimstat_rx_prune_wc(0),
      _pimstat_rx_join_sg(0),
      _pimstat_rx_prune_sg(0),
      _pimstat_rx_join_sg_rpt(0),
      _pimstat_rx_prune_sg_rpt(0),
      //
      _usage_by_pim_mre_task(0)
{
    _buffer_send = BUFFER_MALLOC(BUF_SIZE_DEFAULT);
    _buffer_send_hello = BUFFER_MALLOC(BUF_SIZE_DEFAULT);
    _buffer_send_bootstrap = BUFFER_MALLOC(BUF_SIZE_DEFAULT);
    _proto_flags = 0;
    
    set_proto_version_default(PIM_VERSION_DEFAULT);
    
    set_default_config();
    
    set_should_send_pim_hello(true);
}

/**
 * PimVif::~PimVif:
 * @: 
 * 
 * PIM protocol vif destructor.
 * 
 **/
PimVif::~PimVif()
{
    string error_msg;

    stop(error_msg);
    
    BUFFER_FREE(_buffer_send);
    BUFFER_FREE(_buffer_send_hello);
    BUFFER_FREE(_buffer_send_bootstrap);
    
    // Remove all PIM neighbor entries
    while (! _pim_nbrs.empty()) {
	PimNbr *pim_nbr = _pim_nbrs.front();
	_pim_nbrs.pop_front();
	// TODO: perform the appropriate actions
	delete_pim_nbr(pim_nbr);
    }
}

/**
 * PimVif::set_default_config:
 * @: 
 * 
 * Set configuration to default values.
 **/
void
PimVif::set_default_config()
{
    // Protocol version
    set_proto_version(proto_version_default());
    
    // Hello-related configurable parameters
    hello_triggered_delay().reset();
    hello_period().reset();
    hello_holdtime().reset();
    dr_priority().reset();
    propagation_delay().reset();
    override_interval().reset();
    is_tracking_support_disabled().reset();
    accept_nohello_neighbors().reset();
    
    // Hello-related non-configurable parameters
    genid().set(xorp_random() % 0xffffffffU);
    
    // Join/Prune-related parameters
    _join_prune_period.reset();
    _join_prune_holdtime.reset();
}

/**
 * PimVif::set_proto_version:
 * @proto_version: The protocol version to set.
 * 
 * Set protocol version.
 * 
 * Return value: %XORP_OK is @proto_version is valid, otherwise %XORP_ERROR.
 **/
int
PimVif::set_proto_version(int proto_version)
{
    if ((proto_version < PIM_VERSION_MIN) || (proto_version > PIM_VERSION_MAX))
	return (XORP_ERROR);
    
    ProtoUnit::set_proto_version(proto_version);
    
    return (XORP_OK);
}

/**
 * PimVif::pim_mrt:
 * @: 
 * 
 * Get the PIM Multicast Routing Table.
 * 
 * Return value: A reference to the PIM Multicast Routing Table.
 **/
PimMrt&
PimVif::pim_mrt() const
{
    return (_pim_node.pim_mrt());
}

/**
 * PimVif::start:
 * @error_msg: The error message (if error).
 * 
 * Start PIM on a single virtual interface.
 * 
 * Return value: %XORP_OK on success, otherwise %XORP_ERROR.
 **/
int
PimVif::start(string& error_msg)
{
    if (! is_enabled())
	return (XORP_OK);

    if (is_up() || is_pending_up())
	return (XORP_OK);

    if (! is_underlying_vif_up()) {
	error_msg = "underlying vif is not UP";
	return (XORP_ERROR);
    }

    //
    // Start the vif only if it is of the appropriate type:
    // multicast-capable (loopback excluded), or PIM Register vif.
    //
    if (! ((is_multicast_capable() && (! is_loopback()))
           || is_pim_register())) {
	error_msg = "the interface is not multicast capable";
	return (XORP_ERROR);
    }

    if (update_primary_and_domain_wide_address(error_msg) != XORP_OK)
	return (XORP_ERROR);

    if (ProtoUnit::start() != XORP_OK) {
	error_msg = "internal error";
	return (XORP_ERROR);
    }
    
    //
    // Register as a receiver with the kernel
    //
    if (pim_node().register_receiver(name(),
				     name(),
				     pim_node().ip_protocol_number(),
				     false)
	!= XORP_OK) {
	error_msg = c_format("cannot register as a receiver on vif %s "
			     "with the kernel",
			     name().c_str());
	return (XORP_ERROR);
    }

    //
    // Register as a protocol with the MFEA
    //
    if (pim_node().register_protocol(name(),
				     name(),
				     pim_node().ip_protocol_number())
	!= XORP_OK) {
	error_msg = c_format("cannot register as a protocol on vif %s "
			     "with the MFEA",
			     name().c_str());
	return (XORP_ERROR);
    }
    
    if (! is_pim_register()) {    
	//
	// Join the appropriate multicast groups: ALL-PIM-ROUTERS
	//
	const IPvX group = IPvX::PIM_ROUTERS(family());
	if (pim_node().join_multicast_group(name(),
					    name(),
					    pim_node().ip_protocol_number(),
					    group)
	    != XORP_OK) {
	    error_msg = c_format("cannot join group %s on vif %s",
				 cstring(group), name().c_str());
	    return (XORP_ERROR);
	}
	
	pim_hello_start();
	
	//
	// Add MLD6/IGMP membership tracking
	//
	pim_node().add_protocol_mld6igmp(vif_index());
    }
    
    //
    // Add the tasks to take care of the PimMre processing
    //
    pim_node().pim_mrt().add_task_start_vif(vif_index());
    pim_node().pim_mrt().add_task_my_ip_address(vif_index());
    pim_node().pim_mrt().add_task_my_ip_subnet_address(vif_index());

    XLOG_INFO("Interface started: %s%s",
	      this->str().c_str(), flags_string().c_str());
    
    return (XORP_OK);
}

/**
 * PimVif::stop:
 * @error_msg: The error message (if error).
 * 
 * Gracefully stop PIM on a single virtual interface.
 * XXX: The graceful stop will attempt to send Join/Prune, Assert, etc.
 * messages for all multicast routing entries to gracefully clean-up
 * state with neighbors.
 * XXX: After the multicast routing entries cleanup is completed,
 * PimVif::final_stop() is called to complete the job.
 * 
 * Return value: %XORP_OK on success, otherwise %XORP_ERROR.
 **/
int
PimVif::stop(string& error_msg)
{
    int ret_value = XORP_OK;

    if (is_down())
	return (XORP_OK);
    
    if (! (is_up() || is_pending_up() || is_pending_down())) {
	error_msg = "the vif state is not UP or PENDING_UP or PENDING_DOWN";
	return (XORP_ERROR);
    }

    if (ProtoUnit::pending_stop() != XORP_OK) {
	error_msg = "internal error";
	ret_value = XORP_ERROR;
    }

    //
    // Add the tasks to take care of the PimMre processing
    //
    pim_node().pim_mrt().add_task_stop_vif(vif_index());
    pim_node().pim_mrt().add_task_my_ip_address(vif_index());
    pim_node().pim_mrt().add_task_my_ip_subnet_address(vif_index());

    //
    // Add the shutdown operation of this vif as a shutdown task
    // for the node.
    //
    pim_node().incr_shutdown_requests_n();	// XXX: for PIM-stop-vif

    if (! is_pim_register()) {
	//
	// Delete MLD6/IGMP membership tracking
	//
	pim_node().delete_protocol_mld6igmp(vif_index());
	
	set_i_am_dr(false);
    }
    
    _dr_addr = IPvX::ZERO(family());
    
    return (ret_value);
}

/**
 * PimVif::final_stop:
 * @error_msg: The error message (if error).
 * 
 * Completely stop PIM on a single virtual interface.
 * 
 * Return value: %XORP_OK on success, otherwise %XORP_ERROR.
 **/
int
PimVif::final_stop(string& error_msg)
{
    int ret_value = XORP_OK;
    
    if (! (is_up() || is_pending_up() || is_pending_down())) {
	error_msg = "the vif state is not UP or PENDING_UP or PENDING_DOWN";
	return (XORP_ERROR);
    }
    
    if (! is_pim_register()) {
	//
	// Delete MLD6/IGMP membership tracking
	//
	if (is_up() || is_pending_up())
	    pim_node().delete_protocol_mld6igmp(vif_index());
	
	pim_hello_stop();
	
	set_i_am_dr(false);
    }

    //
    // XXX: we don't have to explicitly leave the multicast groups
    // we have joined on that interface, because this will happen
    // automatically when we stop the vif through the MFEA.
    //
    
    if (ProtoUnit::stop() != XORP_OK) {
	error_msg = "internal error";
	ret_value = XORP_ERROR;
    }
    
    _dr_addr = IPvX::ZERO(family());
    _hello_timer.unschedule();
    _hello_once_timer.unschedule();
    
    // Remove all PIM neighbor entries
    while (! _pim_nbrs.empty()) {
	PimNbr *pim_nbr = _pim_nbrs.front();
	_pim_nbrs.pop_front();
	// TODO: perform the appropriate actions
	delete_pim_nbr(pim_nbr);
    }
    
    //
    // Unregister as a protocol with the MFEA
    //
    if (pim_node().unregister_protocol(name(), name()) != XORP_OK) {
	XLOG_ERROR("Cannot unregister as a protocol on vif %s with the MFEA",
		   name().c_str());
	ret_value = XORP_ERROR;
    }

    //
    // Unregister as a receiver with the kernel
    //
    if (pim_node().unregister_receiver(name(),
				       name(),
				       pim_node().ip_protocol_number())
	!= XORP_OK) {
	XLOG_ERROR("Cannot unregister as a receiver on vif %s with the kernel",
		   name().c_str());
	ret_value = XORP_ERROR;
    }

    XLOG_INFO("Interface stopped: %s%s",
	      this->str().c_str(), flags_string().c_str());

    //
    // Inform the node that the vif has completed the shutdown
    //
    pim_node().vif_shutdown_completed(name());

    //
    // Remove the shutdown operation of this vif as a shutdown task
    // for the node.
    //
    pim_node().decr_shutdown_requests_n();	// XXX: for PIM-stop-vif

    return (ret_value);
}

/**
 * Enable PIM on a single virtual interface.
 * 
 * If an unit is not enabled, it cannot be start, or pending-start.
 */
void
PimVif::enable()
{
    ProtoUnit::enable();

    XLOG_INFO("Interface enabled: %s%s",
	      this->str().c_str(), flags_string().c_str());
}

/**
 * Disable PIM on a single virtual interface.
 * 
 * If an unit is disabled, it cannot be start or pending-start.
 * If the unit was runnning, it will be stop first.
 */
void
PimVif::disable()
{
    string error_msg;

    stop(error_msg);
    ProtoUnit::disable();

    XLOG_INFO("Interface disabled: %s%s",
	      this->str().c_str(), flags_string().c_str());
}

/**
 * PimVif::pim_send:
 * @src: The message source address.
 * @dst: The message destination address.
 * @message_type: The PIM type of the message.
 * @buffer: The buffer with the rest of the message.
 * @error_msg: The error message (if error).
 * 
 * Send PIM message.
 * XXX: The beginning of the @buffer must have been reserved
 * for the PIM header.
 * 
 * Return value: %XORP_OK on success, otherwise %XORP_ERROR.
 **/
int
PimVif::pim_send(const IPvX& src, const IPvX& dst,
		 uint8_t message_type, buffer_t *buffer,
		 string& error_msg)
{
    uint8_t pim_vt;
    uint16_t cksum;
    uint16_t cksum2 = 0;
    int ip_tos = -1;
    int ret_value;
    size_t datalen;
    int ttl = MINTTL;
    bool ip_internet_control = true;	// XXX: might be overwritten below

    if (! (is_up() || is_pending_down()))
	return (XORP_ERROR);

    //
    // Some of the messages should never be send via the PIM Register vif
    //
    if (is_pim_register()) {
	switch (message_type) {
	case PIM_HELLO:
	case PIM_JOIN_PRUNE:
	case PIM_BOOTSTRAP:
	case PIM_ASSERT:
	case PIM_GRAFT:
	case PIM_GRAFT_ACK:
	    return (XORP_ERROR);	// Those messages are not allowed
	case PIM_REGISTER:
	case PIM_REGISTER_STOP:
	case PIM_CAND_RP_ADV:
	    break;			// Those messages are probably OK
	default:
	    break;
	}
    }

    //
    // Some of the messages need to be send by unicast across the domain.
    // For those messages we need to modify some of the sending values.
    //
    if (dst.is_unicast()) {
	switch (message_type) {
	case PIM_REGISTER:
	    // XXX: The ip_tos is copied from the inner IP header
	    ip_internet_control = false;
	    // FALLTHROUGH
	case PIM_REGISTER_STOP:
	case PIM_CAND_RP_ADV:
	    ttl = IPDEFTTL;
	    break;
	default:
	    break;
	}
    }
    
    //
    // If necessary, send first a Hello message
    //
    if (should_send_pim_hello()) {
	switch (message_type) {
	case PIM_JOIN_PRUNE:
	case PIM_BOOTSTRAP:		// XXX: not in the spec yet
	case PIM_ASSERT:
	    pim_hello_first_send();
	    break;
	default:
	    break;
	}
    }
    
    //
    // Compute the TOS
    //
    switch (message_type) {
    case PIM_REGISTER:
	//
	// If PIM Register, then copy the TOS from the inner header
	// to the outer header. Strictly speaking, we need to do it
	// only for Registers with data (i.e., not for Null Registers),
	// but for simplicity we do it for Null Registers as well.
	//
	switch (family()) {
#ifndef HOST_OS_WINDOWS
	case AF_INET:
	{
	    struct ip ip4_header;
	    
	    BUFFER_COPYGET_DATA_OFFSET(&ip4_header, buffer, sizeof(uint32_t),
				       sizeof(ip4_header));
	    ip_tos = ip4_header.ip_tos;
	    break;
	}
#endif
	
#ifdef HAVE_IPV6
	case AF_INET6:
	{
	    struct ip6_hdr ip6_header;
	    
	    BUFFER_COPYGET_DATA_OFFSET(&ip6_header, buffer, sizeof(uint32_t),
				       sizeof(ip6_header));
	    // Get the Traffic Class
	    ip_tos = (ntohl(ip6_header.ip6_flow) >> 20) & 0xff;
	    break;
	}
#endif // HAVE_IPV6
	
	default:
	    XLOG_UNREACHABLE();
	    return (XORP_ERROR);
	}
	
    default:
	break;
    }
    
    //
    // Prepare the PIM header
    //
    // TODO: XXX: PAVPAVPAV: use 'buffer = buffer_send_prepare()' ???
    // Point the buffer to the protocol header
    datalen = BUFFER_DATA_SIZE(buffer);
    BUFFER_RESET_TAIL(buffer);
    //
    pim_vt = PIM_MAKE_VT(proto_version(), message_type);
    BUFFER_PUT_OCTET(pim_vt, buffer);		// PIM version and message type
    BUFFER_PUT_OCTET(0, buffer);		// Reserved
    BUFFER_PUT_HOST_16(0, buffer);		// Zero the checksum field
    // Restore the buffer to include the data
    BUFFER_RESET_TAIL(buffer);
    BUFFER_PUT_SKIP(datalen, buffer);
    
    //
    // Compute the checksum
    //
    if (is_ipv6()) {
	//
	// XXX: The checksum for IPv6 includes the IPv6 "pseudo-header"
	// as described in RFC 2460.
	//
	size_t ph_len;
	if (message_type == PIM_REGISTER)
	    ph_len = PIM_REGISTER_HEADER_LENGTH;
	else
	    ph_len = BUFFER_DATA_SIZE(buffer);
	cksum2 = calculate_ipv6_pseudo_header_checksum(src, dst, ph_len,
						       IPPROTO_PIM);
    }
    
    // XXX: The checksum for PIM_REGISTER excludes the encapsulated data packet
    switch (message_type) {
    case PIM_REGISTER:
	cksum = inet_checksum(BUFFER_DATA_HEAD(buffer),
			      PIM_REGISTER_HEADER_LENGTH);
	break;
    default:
	cksum = inet_checksum(BUFFER_DATA_HEAD(buffer),
			      BUFFER_DATA_SIZE(buffer));
	break;
    }
    
    cksum = inet_checksum_add(cksum, cksum2);
    BUFFER_COPYPUT_INET_CKSUM(cksum, buffer, 2);	// XXX: the checksum

    XLOG_TRACE(pim_node().is_log_trace(),
	       "TX %s from %s to %s on vif %s",
	       PIMTYPE2ASCII(message_type),
	       cstring(src),
	       cstring(dst),
	       name().c_str());
    
    //
    // Send the message
    //
    ret_value = pim_node().pim_send(name(), name(),
				    src, dst,
				    pim_node().ip_protocol_number(),
				    ttl, ip_tos,
				    false, // router alert is deprecated
				    ip_internet_control,
				    buffer, error_msg);
    
    //
    // Actions after the message is sent
    //
    if (ret_value == XORP_OK) {
	switch (message_type) {
	case PIM_HELLO:
	    set_should_send_pim_hello(false);
	    break;
	default:
	    break;
	}
    }
    
    //
    // Keep statistics per message type
    //
    if (ret_value == XORP_OK) {
	switch (message_type) {
	case PIM_HELLO:
	    ++_pimstat_hello_messages_sent;
	    break;
	case PIM_REGISTER:
	    ++_pimstat_register_messages_sent;
	    break;
	case PIM_REGISTER_STOP:
	    ++_pimstat_register_stop_messages_sent;
	    break;
	case PIM_JOIN_PRUNE:
	    ++_pimstat_join_prune_messages_sent;
	    break;
	case PIM_BOOTSTRAP:
	    ++_pimstat_bootstrap_messages_sent;
	    break;
	case PIM_ASSERT:
	    ++_pimstat_assert_messages_sent;
	    break;
	case PIM_GRAFT:
	    ++_pimstat_graft_messages_sent;
	    break;
	case PIM_GRAFT_ACK:
	    ++_pimstat_graft_ack_messages_sent;
	    break;
	case PIM_CAND_RP_ADV:
	    ++_pimstat_candidate_rp_messages_sent;
	    break;
	default:
	    break;
	}
    }
    
    return (ret_value);
    
 buflen_error:
    XLOG_UNREACHABLE();
    XLOG_ERROR("TX %s from %s to %s on vif %s: "
	       "packet cannot fit into sending buffer",
	       PIMTYPE2ASCII(message_type),
	       cstring(src), cstring(dst),
	       name().c_str());
    return (XORP_ERROR);

#ifndef HOST_OS_WINDOWS
 rcvlen_error:
    // XXX: this should not happen. The only way to jump here
    // is if we are trying to send a PIM Register message that did not
    // contain an IP header, but this is not a valid PIM Register message.
    XLOG_UNREACHABLE();
    return (XORP_ERROR);
#endif
}

/**
 * PimVif::pim_recv:
 * @src: The message source address.
 * @dst: The message destination address.
 * @buffer: The buffer with the received message.
 * 
 * Receive PIM message and pass it for processing.
 * 
 * Return value: %XORP_OK on success, otherwise %XORP_ERROR.
 **/
int
PimVif::pim_recv(const IPvX& src, const IPvX& dst, buffer_t *buffer)
{
    int ret_value = XORP_ERROR;
    
    if (! is_up()) {
	++_pimstat_rx_interface_disabled_messages;
	return (XORP_ERROR);
    }
    
    ret_value = pim_process(src, dst, buffer);
    
    return (ret_value);
}

/**
 * PimVif::pim_process:
 * @src: The message source address.
 * @dst: The message destination address.
 * @buffer: The buffer with the message.
 * 
 * Process PIM message and pass the control to the type-specific functions.
 * 
 * Return value: %XORP_OK on success, otherwise %XORP_ERROR.
 **/
int
PimVif::pim_process(const IPvX& src, const IPvX& dst, buffer_t *buffer)
{
    uint8_t pim_vt;
    uint16_t cksum;
    uint16_t cksum2 = 0;
    uint8_t message_type, proto_version;
    PimNbr *pim_nbr;
    int ret_value = XORP_ERROR;
    
    // Ignore my own PIM messages
    if (pim_node().is_my_addr(src))
	return (XORP_ERROR);
    
    //
    // Message length check.
    //
    if (BUFFER_DATA_SIZE(buffer) < PIM_MINLEN) {
	XLOG_WARNING("RX packet from %s to %s on vif %s: "
		     "too short data field (%u bytes)",
		     cstring(src), cstring(dst),
		     name().c_str(),
		     XORP_UINT_CAST(BUFFER_DATA_SIZE(buffer)));
	++_pimstat_bad_length_messages;
	return (XORP_ERROR);
    }
    
    //
    // Get the message type and PIM protocol version.
    // XXX: First we need the message type to verify correctly the checksum.
    //
    BUFFER_GET_OCTET(pim_vt, buffer);
    BUFFER_GET_SKIP_REVERSE(1, buffer);		// Rewind back
    message_type = PIM_VT_T(pim_vt);
    proto_version = PIM_VT_V(pim_vt);

    //
    // Some of the messages should never be received via the PIM Register vif
    //
    if (is_pim_register()) {
	switch (message_type) {
	case PIM_HELLO:
	case PIM_JOIN_PRUNE:
	case PIM_BOOTSTRAP:
	case PIM_ASSERT:
	case PIM_GRAFT:
	case PIM_GRAFT_ACK:
	    return (XORP_ERROR);	// Those messages are not allowed
	case PIM_REGISTER:
	case PIM_REGISTER_STOP:
	case PIM_CAND_RP_ADV:
	    break;			// Those messages are probably OK
	default:
	    break;
	}
    }
    
    //
    // Checksum verification.
    //
    if (is_ipv6()) {
	//
	// XXX: The checksum for IPv6 includes the IPv6 "pseudo-header"
	// as described in RFC 2460.
	//
	size_t ph_len;
	if (message_type == PIM_REGISTER)
	    ph_len = PIM_REGISTER_HEADER_LENGTH;
	else
	    ph_len = BUFFER_DATA_SIZE(buffer);
	cksum2 = calculate_ipv6_pseudo_header_checksum(src, dst, ph_len,
						       IPPROTO_PIM);
    }
    
    switch (message_type) {
    case PIM_REGISTER:
	cksum = inet_checksum(BUFFER_DATA_HEAD(buffer),
			      PIM_REGISTER_HEADER_LENGTH);
	cksum = inet_checksum_add(cksum, cksum2);
	if (cksum == 0)
	    break;
	//
	// XXX: Some non-spec compliant (the PC name for "buggy" :)
	// PIM-SM implementations compute the PIM_REGISTER
	// checksum over the whole packet instead of only the first 8 octets.
	// Hence, if the checksum fails over the first 8 octets, try over
	// the whole packet.
	//
	// FALLTHROUGH
	
    default:
	cksum = inet_checksum(BUFFER_DATA_HEAD(buffer),
			      BUFFER_DATA_SIZE(buffer));
	cksum = inet_checksum_add(cksum, cksum2);

	if (cksum == 0)
	    break;

	//
	// If this is a PIM Register packet, and if it was truncated
	// by the kernel (e.g., in some *BSD systems), then ignore the
	// checksum error.
	//
	if (message_type == PIM_REGISTER) {
	    bool is_truncated = false;

	    switch (family()) {
	    case AF_INET:
		if (BUFFER_DATA_SIZE(buffer) == PIM_REG_MINLEN)
		    is_truncated = true;
		break;
#ifdef HAVE_IPV6	
	    case AF_INET6:
		if (BUFFER_DATA_SIZE(buffer) == PIM6_REG_MINLEN)
		    is_truncated = true;
		break;
#endif // HAVE_IPV6
	    default:
		XLOG_UNREACHABLE();
		return (XORP_ERROR);
	    }

	    if (is_truncated)
		break;		// XXX: accept the truncated PIM Register
	}

	XLOG_WARNING("RX packet from %s to %s on vif %s: "
		     "checksum error",
		     cstring(src), cstring(dst),
		     name().c_str());
	++_pimstat_bad_checksum_messages;
	return (XORP_ERROR);
    }
    
    //
    // Protocol version check.
    //
    // Note about protocol version checking (based on clarification/suggestion
    // from Mark Handley).
    // The expectation is that any protocol version increase would be
    // signalled in PIM Hello messages, and newer versions would be
    // required to fall back to the version understood by everybody,
    // or refuse to communicate with older versions (as they choose).
    // Hence, we drop everything other than a PIM Hello message
    // with version greather than the largest one we understand
    // (PIM_VERSION_MAX), but we log a warning. On the other hand,
    // we don't understand anything about versions smaller than
    // PIM_VERSION_MIN, hence we drop all messages with that version.
    if ((proto_version < PIM_VERSION_MIN)
	|| ((proto_version > PIM_VERSION_MAX)
	    && (message_type != PIM_HELLO))) {
	XLOG_WARNING("RX %s from %s to %s on vif %s: "
		     "invalid PIM version: %d",
		     PIMTYPE2ASCII(message_type),
		     cstring(src), cstring(dst),
		     name().c_str(),
		     proto_version);
	++_pimstat_unknown_version_messages;
	return (XORP_ERROR);
    }

    //
    // Source address check.
    //
    if (! src.is_unicast()) {
	// Source address must always be unicast
	// The kernel should have checked that, but just in case
	XLOG_WARNING("RX %s from %s to %s on vif %s: "
		     "source must be unicast",
		     PIMTYPE2ASCII(message_type),
		     cstring(src), cstring(dst),
		     name().c_str());
	ret_value = XORP_ERROR;
	goto ret_label;
    }
    if (src.af() != family()) {
	// Invalid source address family
	XLOG_WARNING("RX %s from %s to %s on vif %s: "
		     "invalid source address family "
		     "(received %d expected %d)",
		     PIMTYPE2ASCII(message_type),
		     cstring(src), cstring(dst),
		     name().c_str(),
		     src.af(), family());
    }
    switch (message_type) {
    case PIM_HELLO:
    case PIM_JOIN_PRUNE:
    case PIM_ASSERT:
    case PIM_GRAFT:
    case PIM_GRAFT_ACK:
    case PIM_BOOTSTRAP:
	// Source address must be directly connected
	if (! pim_node().is_directly_connected(*this, src)) {
	    XLOG_WARNING("RX %s from %s to %s on vif %s: "
			 "source must be directly connected",
			 PIMTYPE2ASCII(message_type),
			 cstring(src), cstring(dst),
			 name().c_str());
	    ret_value = XORP_ERROR;
	    goto ret_label;
	}
#if 0
	// TODO: this check has to be fixed in case we use GRE tunnels
	if (! src.is_linklocal_unicast()) {
	    XLOG_WARNING("RX %s from %s to %s on vif %s: "
			 "source is not a link-local address",
			 PIMTYPE2ASCII(message_type),
			 cstring(src), cstring(dst),
			 name().c_str());
	    ret_value = XORP_ERROR;
	    goto ret_label;
	}
#endif // 0/1
	break;
    case PIM_REGISTER:
    case PIM_REGISTER_STOP:
    case PIM_CAND_RP_ADV:
	// Source address can be anywhere
	// TODO: any source address check?
	break;
    default:
	break;
    }
    
    //
    // Destination address check.
    //
    if (dst.af() != family()) {
	// Invalid destination address family
	XLOG_WARNING("RX %s from %s to %s on vif %s: "
		     "invalid destination address family "
		     "(received %d expected %d)",
		     PIMTYPE2ASCII(message_type),
		     cstring(src), cstring(dst),
		     name().c_str(),
		     dst.af(), family());
    }
    switch (message_type) {
    case PIM_HELLO:
    case PIM_JOIN_PRUNE:
    case PIM_ASSERT:
    case PIM_GRAFT:
	// Destination must be multicast
	if (! dst.is_multicast()) {
	    XLOG_WARNING("RX %s from %s to %s on vif %s: "
			 "destination must be multicast",
			 PIMTYPE2ASCII(message_type),
			 cstring(src), cstring(dst),
			 name().c_str());
	    ret_value = XORP_ERROR;
	    goto ret_label;
	}
#ifdef HAVE_IPV6
	if (is_ipv6()) {
	    //
	    // TODO: Multicast address scope check for IPv6
	    //
	}
#endif  // HAVE_IPV6
	if (dst != IPvX::PIM_ROUTERS(family())) {
	    XLOG_WARNING("RX %s from %s to %s on vif %s: "
			 "destination must be ALL-PIM-ROUTERS multicast group",
			 PIMTYPE2ASCII(message_type),
			 cstring(src), cstring(dst),
			 name().c_str());
	    ret_value = XORP_ERROR;
	    goto ret_label;
	}
	break;
    case PIM_REGISTER:
    case PIM_REGISTER_STOP:
    case PIM_GRAFT_ACK:
    case PIM_CAND_RP_ADV:
	// Destination must be unicast
	if (! dst.is_unicast()) {
	    XLOG_WARNING("RX %s from %s to %s on vif %s: "
			 "destination must be unicast",
			 PIMTYPE2ASCII(message_type),
			 cstring(src), cstring(dst),
			 name().c_str());
	    ret_value = XORP_ERROR;
	    goto ret_label;
	}
	break;
	
    case PIM_BOOTSTRAP:
	// Destination can be either unicast or multicast
	if (! (dst.is_unicast() || dst.is_multicast())) {
	    XLOG_WARNING("RX %s from %s to %s on vif %s: "
			 "destination must be either unicast or multicast",
			 PIMTYPE2ASCII(message_type),
			 cstring(src), cstring(dst),
			 name().c_str());
	    ret_value = XORP_ERROR;
	    goto ret_label;
	}
#ifdef HAVE_IPV6
	if (dst.is_unicast()) {
	    // TODO: address check (if any)
	}
	if (dst.is_multicast()) {
	    if (dst != IPvX::PIM_ROUTERS(family())) {
		XLOG_WARNING("RX %s from %s to %s on vif %s: "
			     "destination must be ALL-PIM-ROUTERS multicast group",
			     PIMTYPE2ASCII(message_type),
			     cstring(src), cstring(dst),
			     name().c_str());
		ret_value = XORP_ERROR;
		goto ret_label;
	    }
	    
	    if (is_ipv6()) {
		//
		// TODO: Multicast address scope check for IPv6
		//
	    }
	}
#endif  // HAVE_IPV6
	break;
    default:
	break;
    }
    
    //
    // Message-specific checks.
    //
    switch (message_type) {
    case PIM_HELLO:
    case PIM_JOIN_PRUNE:
    case PIM_ASSERT:
	// PIM-SM and PIM-DM messages
	break;
    case PIM_REGISTER:
    case PIM_REGISTER_STOP:
    case PIM_BOOTSTRAP:
    case PIM_CAND_RP_ADV:
	// PIM-SM only messages
	if (proto_is_pimdm()) {
	    XLOG_WARNING("RX %s from %s to %s on vif %s: "
			 "message type is PIM-SM specific",
			 PIMTYPE2ASCII(message_type),
			 cstring(src), cstring(dst),
			 name().c_str());
	    ret_value = XORP_ERROR;
	    goto ret_label;
	}
	break;
    case PIM_GRAFT:
    case PIM_GRAFT_ACK:
	// PIM-DM only messages
	if (proto_is_pimsm()) {
	    XLOG_WARNING("RX %s from %s to %s on vif %s: "
			 "message type is PIM-DM specific",
			 PIMTYPE2ASCII(message_type),
			 cstring(src), cstring(dst),
			 name().c_str());
	    ret_value = XORP_ERROR;
	    goto ret_label;
	}
	break;
    default:
	XLOG_WARNING("RX %s from %s to %s on vif %s: "
		     "message type (%d) is unknown",
		     PIMTYPE2ASCII(message_type),
		     cstring(src), cstring(dst),
		     name().c_str(),
		     message_type);
	ret_value = XORP_ERROR;
	goto ret_label;
    }
    
    //
    // Origin router neighbor check.
    //
    pim_nbr = pim_nbr_find(src);
    switch (message_type) {
    case PIM_HELLO:
	// This could be a new neighbor
	break;
    case PIM_JOIN_PRUNE:
    case PIM_BOOTSTRAP:
    case PIM_ASSERT:
    case PIM_GRAFT:
    case PIM_GRAFT_ACK:
	// Those messages must be originated by a neighbor router
	if (((pim_nbr == NULL)
	     || ((pim_nbr != NULL) && (pim_nbr->is_nohello_neighbor())))
	    && accept_nohello_neighbors().get()) {
	    // We are configured to interoperate with neighbors that
	    // do not send Hello messages first.
	    // XXX: fake that we have received a Hello message with
	    // large enough Hello holdtime.
	    buffer_t *tmp_hello_buffer = BUFFER_MALLOC(BUF_SIZE_DEFAULT);
	    uint16_t tmp_default_holdtime
		= max(PIM_HELLO_HELLO_HOLDTIME_DEFAULT,
		      PIM_JOIN_PRUNE_HOLDTIME_DEFAULT);
	    bool is_nohello_neighbor = false;
	    if (pim_nbr == NULL)
		is_nohello_neighbor = true;
	    BUFFER_RESET(tmp_hello_buffer);
	    BUFFER_PUT_HOST_16(PIM_HELLO_HOLDTIME_OPTION, tmp_hello_buffer);
	    BUFFER_PUT_HOST_16(PIM_HELLO_HOLDTIME_LENGTH, tmp_hello_buffer);
	    BUFFER_PUT_HOST_16(tmp_default_holdtime, tmp_hello_buffer);
	    pim_hello_recv(pim_nbr, src, dst, tmp_hello_buffer, proto_version);
	    BUFFER_FREE(tmp_hello_buffer);
	    pim_nbr = pim_nbr_find(src);
	    if ((pim_nbr != NULL) && is_nohello_neighbor)
		pim_nbr->set_is_nohello_neighbor(is_nohello_neighbor);
	}
	if (pim_nbr == NULL) {
	    XLOG_WARNING("RX %s from %s to %s on vif %s: "
			 "sender is not a PIM-neighbor router",
			 PIMTYPE2ASCII(message_type),
			 cstring(src), cstring(dst),
			 name().c_str());
	    ++_pimstat_neighbor_unknown_messages;
	    ret_value = XORP_ERROR;
	    goto ret_label;
	}
	break;
    case PIM_REGISTER:
    case PIM_REGISTER_STOP:
    case PIM_CAND_RP_ADV:
	// Those messages may be originated by a remote router
	break;
    default:
	break;
    }
    
    XLOG_TRACE(pim_node().is_log_trace(),
	       "RX %s from %s to %s on vif %s",
	       PIMTYPE2ASCII(message_type),
	       cstring(src), cstring(dst),
	       name().c_str());
    
    /*
     * Process each message based on its type.
     */
    BUFFER_GET_SKIP(sizeof(struct pim), buffer);
    switch (message_type) {
    case PIM_HELLO:
	ret_value = pim_hello_recv(pim_nbr, src, dst, buffer, proto_version);
	break;
    case PIM_REGISTER:
	ret_value = pim_register_recv(pim_nbr, src, dst, buffer);
	break;
    case PIM_REGISTER_STOP:
	ret_value = pim_register_stop_recv(pim_nbr, src, dst, buffer);
	break;
    case PIM_JOIN_PRUNE:
	ret_value = pim_join_prune_recv(pim_nbr, src, dst, buffer,
					message_type);
	break;
    case PIM_BOOTSTRAP:
	ret_value = pim_bootstrap_recv(pim_nbr, src, dst, buffer);
	break;
    case PIM_ASSERT:
	ret_value = pim_assert_recv(pim_nbr, src, dst, buffer);
	break;
    case PIM_GRAFT:
	ret_value = pim_graft_recv(pim_nbr, src, dst, buffer);
	break;
    case PIM_GRAFT_ACK:
	ret_value = pim_graft_ack_recv(pim_nbr, src, dst, buffer);
	break;
    case PIM_CAND_RP_ADV:
	ret_value = pim_cand_rp_adv_recv(pim_nbr, src, dst, buffer);
	break;
    default:
	break;
    }
    
 ret_label:
    
    //
    // Keep statistics per message type
    //
    if (ret_value == XORP_OK) {
	switch (message_type) {
	case PIM_HELLO:
	    ++_pimstat_hello_messages_received;
	    break;
	case PIM_REGISTER:
	    ++_pimstat_register_messages_received;
	    break;
	case PIM_REGISTER_STOP:
	    ++_pimstat_register_stop_messages_received;
	    break;
	case PIM_JOIN_PRUNE:
	    ++_pimstat_join_prune_messages_received;
	    break;
	case PIM_BOOTSTRAP:
	    ++_pimstat_bootstrap_messages_received;
	    break;
	case PIM_ASSERT:
	    ++_pimstat_assert_messages_received;
	    break;
	case PIM_GRAFT:
	    ++_pimstat_graft_messages_received;
	    break;
	case PIM_GRAFT_ACK:
	    ++_pimstat_graft_ack_messages_received;
	    break;
	case PIM_CAND_RP_ADV:
	    ++_pimstat_candidate_rp_messages_received;
	    break;
	default:
	    ++_pimstat_unknown_type_messages;
	    break;
	}
    } else {
	switch (message_type) {
	case PIM_HELLO:
	    ++_pimstat_hello_messages_rx_errors;
	    break;
	case PIM_REGISTER:
	    ++_pimstat_register_messages_rx_errors;
	    break;
	case PIM_REGISTER_STOP:
	    ++_pimstat_register_stop_messages_rx_errors;
	    break;
	case PIM_JOIN_PRUNE:
	    ++_pimstat_join_prune_messages_rx_errors;
	    break;
	case PIM_BOOTSTRAP:
	    ++_pimstat_bootstrap_messages_rx_errors;
	    break;
	case PIM_ASSERT:
	    ++_pimstat_assert_messages_rx_errors;
	    break;
	case PIM_GRAFT:
	    ++_pimstat_graft_messages_rx_errors;
	    break;
	case PIM_GRAFT_ACK:
	    ++_pimstat_graft_ack_messages_rx_errors;
	    break;
	case PIM_CAND_RP_ADV:
	    ++_pimstat_candidate_rp_messages_rx_errors;
	    break;
	default:
	    ++_pimstat_unknown_type_messages;
	    break;
	}
    }
    
    return (ret_value);
    
 rcvlen_error:    
    XLOG_UNREACHABLE();
    XLOG_WARNING("RX packet from %s to %s on vif %s: "
		 "some fields are too short",
		 cstring(src), cstring(dst),
		 name().c_str());
    ++_pimstat_rx_malformed_packet;
    return (XORP_ERROR);
    
 buflen_error:
    XLOG_UNREACHABLE();
    XLOG_WARNING("RX packet from %s to %s on vif %s: "
		 "internal error",
		 cstring(src), cstring(dst),
		 name().c_str());
    return (XORP_ERROR);
}

/**
 * PimVif::buffer_send_prepare:
 * @: 
 * 
 * Reset and prepare the default buffer for sending data.
 * 
 * Return value: The prepared buffer.
 **/
buffer_t *
PimVif::buffer_send_prepare()
{
    return (buffer_send_prepare(_buffer_send));
}

/**
 * PimVif::buffer_send_prepare:
 * @buffer: The buffer to prepare.
 * 
 * Reset and prepare buffer @buffer for sendign data.
 * 
 * Return value: The prepared buffer.
 **/
buffer_t *
PimVif::buffer_send_prepare(buffer_t *buffer)
{
    BUFFER_RESET(buffer);
    BUFFER_PUT_SKIP_PIM_HEADER(buffer);
    
    return (buffer);
    
 buflen_error:
    XLOG_UNREACHABLE();
    XLOG_ERROR("INTERNAL buffer_send_prepare() ERROR: buffer size too small");
    return (NULL);
}

/**
 * PimVif::update_primary_and_domain_wide_address:
 * @error_msg: The error message (if error).
 * 
 * Update the primary and the domain-wide reachable addresses.
 * 
 * The primary address should be a link-local unicast address, and
 * is used for transmitting the multicast control packets on the LAN.
 * The domain-wide reachable address is the address that should be
 * reachable by all PIM-SM routers in the domain
 * (e.g., the Cand-BSR, or the Cand-RP address).
 * 
 * Return value: %XORP_OK on success, otherwise %XORP_ERROR.
 **/
int
PimVif::update_primary_and_domain_wide_address(string& error_msg)
{
    bool i_was_dr = false;
    IPvX primary_a(IPvX::ZERO(family()));
    IPvX domain_wide_a(IPvX::ZERO(family()));

    //
    // Reset the primary and the domain-wide addresses if they are not
    // valid anymore.
    //
    if (Vif::find_address(primary_addr()) == NULL) {
	if (primary_addr() == dr_addr()) {
	    // Reset the DR address
	    _dr_addr = IPvX::ZERO(family());
	    i_was_dr = true;
	}
	pim_nbr_me().set_primary_addr(IPvX::ZERO(family()));
    }
    if (Vif::find_address(domain_wide_addr()) == NULL)
	set_domain_wide_addr(IPvX::ZERO(family()));

    list<VifAddr>::const_iterator iter;
    for (iter = addr_list().begin(); iter != addr_list().end(); ++iter) {
	const VifAddr& vif_addr = *iter;
	const IPvX& addr = vif_addr.addr();
	if (! addr.is_unicast())
	    continue;
	if (addr.is_linklocal_unicast()) {
	    if (primary_a.is_zero())
		primary_a = addr;
	    continue;
	}
	//
	// XXX: assume that everything else can be a domain-wide reachable
	// address.
	//
	if (domain_wide_a.is_zero())
	    domain_wide_a = addr;
    }

    //
    // XXX: In case of IPv6 if there is no link-local address we may try
    // to use the the domain-wide address as a primary address,
    // but the PIM-SM spec is clear that the multicast PIM messages are
    // to be originated from a link-local address.
    // Hence, only in case of IPv4 we assign the domain-wide address
    // to the primary address.
    //
    if (is_ipv4()) {
	if (primary_a.is_zero())
	    primary_a = domain_wide_a;
    }

    //
    // Check that the interface has a primary and a domain-wide reachable
    // addresses.
    //
    if (primary_addr().is_zero() && primary_a.is_zero()) {
	error_msg = "invalid primary address";
	return (XORP_ERROR);
    }
    if (domain_wide_addr().is_zero() && domain_wide_a.is_zero()) {
	error_msg = "invalid domain-wide address";
	return (XORP_ERROR);
    }

    if (primary_addr().is_zero())
	pim_nbr_me().set_primary_addr(primary_a); // Set my PimNbr address
    if (domain_wide_addr().is_zero())
	set_domain_wide_addr(domain_wide_a);

    if (i_was_dr)
	pim_dr_elect();

    return (XORP_OK);
}

/**
 * PimVif::calculate_ipv6_pseudo_header_checksum:
 * @src: the source address of the pseudo-header.
 * @dst: the destination address of the pseudo-header.
 * @len: the upper-layer packet length of the pseudo-header
 * (in host-order).
 * @protocol: the upper-layer protocol number.
 * 
 * Calculate the checksum of an IPv6 "pseudo-header" as described
 * in RFC 2460.
 * 
 * Return value: the checksum of the IPv6 "pseudo-header".
 **/
uint16_t
PimVif::calculate_ipv6_pseudo_header_checksum(const IPvX& src, const IPvX& dst,
					      size_t len, uint8_t protocol)
{
    struct ip6_pseudo_hdr {
	struct in6_addr	ip6_src;	// Source address
	struct in6_addr	ip6_dst;	// Destination address
	uint32_t	ph_len;		// Upper-layer packet length
	uint8_t		ph_zero[3];	// Zero
	uint8_t		ph_next;	// Upper-layer protocol number
    } ip6_pseudo_header;	// TODO: may need __attribute__((__packed__))
    
    src.copy_out(ip6_pseudo_header.ip6_src);
    dst.copy_out(ip6_pseudo_header.ip6_dst);
    ip6_pseudo_header.ph_len = htonl(len);
    ip6_pseudo_header.ph_zero[0] = 0;
    ip6_pseudo_header.ph_zero[1] = 0;
    ip6_pseudo_header.ph_zero[2] = 0;
    ip6_pseudo_header.ph_next = protocol;
    
    uint16_t cksum = inet_checksum(
	reinterpret_cast<const uint8_t *>(&ip6_pseudo_header),
	sizeof(ip6_pseudo_header));
    
    return (cksum);
}

/**
 * PimVif::pim_nbr_find:
 * @nbr_addr: The address of the neighbor to search for.
 * 
 * Find a PIM neighbor by its address.
 * 
 * Return value: The #PimNbr entry for the neighbor if found, otherwise %NULL.
 **/
PimNbr *
PimVif::pim_nbr_find(const IPvX& nbr_addr)
{
    list<PimNbr *>::iterator iter;
    for (iter = _pim_nbrs.begin(); iter != _pim_nbrs.end(); ++iter) {
	PimNbr *pim_nbr = *iter;
	if (pim_nbr->is_my_addr(nbr_addr))
	    return (pim_nbr);
    }
    
    return (NULL);
}

void
PimVif::add_pim_nbr(PimNbr *pim_nbr)
{
    TimeVal now;
    
    TimerList::system_gettimeofday(&now);
    pim_nbr->set_startup_time(now);
    
    _pim_nbrs.push_back(pim_nbr);
}

void
PimVif::delete_pim_nbr_from_nbr_list(PimNbr *pim_nbr)
{
    list<PimNbr *>::iterator iter;
    
    iter = find(_pim_nbrs.begin(), _pim_nbrs.end(), pim_nbr);
    if (iter != _pim_nbrs.end()) {
	XLOG_TRACE(pim_node().is_log_trace(),
		   "Delete neighbor %s on vif %s",
		   cstring(pim_nbr->primary_addr()), name().c_str());
	_pim_nbrs.erase(iter);
    }
}

int
PimVif::delete_pim_nbr(PimNbr *pim_nbr)
{
    delete_pim_nbr_from_nbr_list(pim_nbr);
    
    if (find(pim_node().processing_pim_nbr_list().begin(),
	     pim_node().processing_pim_nbr_list().end(),
	     pim_nbr) == pim_node().processing_pim_nbr_list().end()) {
	//
	// The PimNbr is not on the processing list, hence move it there
	//
	if (pim_nbr->pim_mre_rp_list().empty()
	    && pim_nbr->pim_mre_wc_list().empty()
	    && pim_nbr->pim_mre_sg_list().empty()
	    && pim_nbr->pim_mre_sg_rpt_list().empty()
	    && pim_nbr->processing_pim_mre_rp_list().empty()
	    && pim_nbr->processing_pim_mre_wc_list().empty()
	    && pim_nbr->processing_pim_mre_sg_list().empty()
	    && pim_nbr->processing_pim_mre_sg_rpt_list().empty()) {
	    delete pim_nbr;
	} else {
	    pim_node().processing_pim_nbr_list().push_back(pim_nbr);
	    pim_node().pim_mrt().add_task_pim_nbr_changed(Vif::VIF_INDEX_INVALID,
							  pim_nbr->primary_addr());
	}
    }
    
    return (XORP_OK);
}

bool
PimVif::is_lan_delay_enabled() const
{
    list<PimNbr *>::const_iterator iter;
    for (iter = _pim_nbrs.begin(); iter != _pim_nbrs.end(); ++iter) {
	const PimNbr *pim_nbr = *iter;
	if (! pim_nbr->is_lan_prune_delay_present()) {
	    return (false);
	}
    }
    
    return (true);
}

const TimeVal&
PimVif::effective_propagation_delay() const
{
    static TimeVal tv;
    uint16_t delay;

    do {
	if (! is_lan_delay_enabled()) {
	    delay = _propagation_delay.get_initial_value();
	    break;
	}

	delay = _propagation_delay.get();
	list<PimNbr *>::const_iterator iter;
	for (iter = _pim_nbrs.begin(); iter != _pim_nbrs.end(); ++iter) {
	    PimNbr *pim_nbr = *iter;
	    if (pim_nbr->propagation_delay() > delay)
		delay = pim_nbr->propagation_delay();
	}

	break;
    } while (false);

    // XXX: delay is in milliseconds
    tv = TimeVal(delay / 1000, (delay % 1000) * 1000);

    return (tv);
}

const TimeVal&
PimVif::effective_override_interval() const
{
    static TimeVal tv;
    uint16_t delay;

    do {
	if (! is_lan_delay_enabled()) {
	    delay = _override_interval.get_initial_value();
	    break;
	}

	delay = _override_interval.get();
	list<PimNbr *>::const_iterator iter;
	for (iter = _pim_nbrs.begin(); iter != _pim_nbrs.end(); ++iter) {
	    PimNbr *pim_nbr = *iter;
	    if (pim_nbr->override_interval() > delay)
		delay = pim_nbr->override_interval();
	}

	break;
    } while (false);

    // XXX: delay is in milliseconds
    tv = TimeVal(delay / 1000, (delay % 1000) * 1000);

    return (tv);
}

bool
PimVif::is_lan_suppression_state_enabled() const
{
    if (! is_lan_delay_enabled())
	return (true);
    
    list<PimNbr *>::const_iterator iter;
    for (iter = _pim_nbrs.begin(); iter != _pim_nbrs.end(); ++iter) {
	PimNbr *pim_nbr = *iter;
	if (! pim_nbr->is_tracking_support_disabled()) {
	    return (true);
	}
    }
    
    return (false);
}

//
// Compute the randomized 't_suppressed' interval:
// t_suppressed = rand(1.1 * t_periodic, 1.4 * t_periodic) when
//			Suppression_Enabled(I) is true, 0 otherwise
//
const TimeVal&
PimVif::upstream_join_timer_t_suppressed() const
{
    static TimeVal tv;
    
    if (is_lan_suppression_state_enabled()) {
	tv = TimeVal(_join_prune_period.get(), 0);
	tv = random_uniform(
	    tv * PIM_JOIN_PRUNE_SUPPRESSION_TIMEOUT_RANDOM_FACTOR_MIN,
	    tv * PIM_JOIN_PRUNE_SUPPRESSION_TIMEOUT_RANDOM_FACTOR_MAX);
    } else {
	tv = TimeVal::ZERO();
    }
    
    return (tv);
}

//
// Compute the randomized 't_override' interval value for Upstream Join Timer:
// t_override = rand(0, Effective_Override_Interval(I))
//
const struct TimeVal&
PimVif::upstream_join_timer_t_override() const
{
    static TimeVal tv;
    
    // XXX: explicitly assign the value to 'tv' every time this method
    // is called, because 'tv' is static.
    tv = effective_override_interval();
    
    // Randomize
    tv = random_uniform(tv);
    
    return (tv);
}

// Return the J/P_Override_Interval
const TimeVal&
PimVif::jp_override_interval() const
{
    static TimeVal tv;
    TimeVal res1, res2;
    
    res1 = effective_propagation_delay();
    res2 = effective_override_interval();
    tv = res1 + res2;
    
    return (tv);
}

/**
 * PimVif::i_am_dr:
 * @: 
 * 
 * Test if the protocol instance is a DR (Designated Router)
 * on a virtual interface.
 * 
 * Return value: True if the protocol instance is DR on a virtual interface,
 * otherwise false.
 **/
bool
PimVif::i_am_dr() const
{
    if (_proto_flags & PIM_VIF_DR)
	return (true);
    else
	return (false);
}

/**
 * PimVif::set_i_am_dr:
 * @v: If true, set the %PIM_VIF_DR flag, otherwise reset it.
 * 
 * Set/reset the %PIM_VIF_DR (Designated Router) flag on a virtual interface.
 **/
void
PimVif::set_i_am_dr(bool v)
{
    if (v) {
	_proto_flags |= PIM_VIF_DR;
    } else {
	_proto_flags &= ~PIM_VIF_DR;
    }
    pim_node().set_pim_vifs_dr(vif_index(), v);
}

void
PimVif::incr_usage_by_pim_mre_task()
{
    _usage_by_pim_mre_task++;
}

void
PimVif::decr_usage_by_pim_mre_task()
{
    string error_msg;

    XLOG_ASSERT(_usage_by_pim_mre_task > 0);
    _usage_by_pim_mre_task--;
    
    if (_usage_by_pim_mre_task == 0) {
	if (is_pending_down()) {
	    final_stop(error_msg);
	}
    }
}

void
PimVif::add_alternative_subnet(const IPvXNet& subnet)
{
    list<IPvXNet>::iterator iter;

    iter = find(_alternative_subnet_list.begin(),
		_alternative_subnet_list.end(),
		subnet);
    if (iter != _alternative_subnet_list.end())
	return;		// Already added

    _alternative_subnet_list.push_back(subnet);

    //
    // Add the tasks to take care of the PimMre processing
    //
    pim_node().pim_mrt().add_task_my_ip_subnet_address(vif_index());
}

void
PimVif::delete_alternative_subnet(const IPvXNet& subnet)
{
    list<IPvXNet>::iterator iter;

    iter = find(_alternative_subnet_list.begin(),
		_alternative_subnet_list.end(),
		subnet);
    if (iter == _alternative_subnet_list.end())
	return;		// No such subnet

    _alternative_subnet_list.erase(iter);

    //
    // Add the tasks to take care of the PimMre processing
    //
    pim_node().pim_mrt().add_task_my_ip_subnet_address(vif_index());
}

void
PimVif::remove_all_alternative_subnets()
{
    if (_alternative_subnet_list.empty())
	return;		// No alternative subnets to remove

    _alternative_subnet_list.clear();

    //
    // Add the tasks to take care of the PimMre processing
    //
    pim_node().pim_mrt().add_task_my_ip_subnet_address(vif_index());
}

// TODO: temporary here. Should go to the Vif class after the Vif
// class starts using the ProtoUnit class
string
PimVif::flags_string() const
{
    string flags;
    
    if (is_up())
	flags += " UP";
    if (is_down())
	flags += " DOWN";
    if (is_pending_up())
	flags += " PENDING_UP";
    if (is_pending_down())
	flags += " PENDING_DOWN";
    if (is_ipv4())
	flags += " IPv4";
    if (is_ipv6())
	flags += " IPv6";
    if (is_enabled())
	flags += " ENABLED";
    if (is_disabled())
	flags += " DISABLED";
    
    return (flags);
}

void
PimVif::clear_pim_statistics()
{
    _pimstat_hello_messages_received.reset();
    _pimstat_hello_messages_sent.reset();
    _pimstat_hello_messages_rx_errors.reset();
    _pimstat_register_messages_received.reset();
    _pimstat_register_messages_sent.reset();
    _pimstat_register_messages_rx_errors.reset();
    _pimstat_register_stop_messages_received.reset();
    _pimstat_register_stop_messages_sent.reset();
    _pimstat_register_stop_messages_rx_errors.reset();
    _pimstat_join_prune_messages_received.reset();
    _pimstat_join_prune_messages_sent.reset();
    _pimstat_join_prune_messages_rx_errors.reset();
    _pimstat_bootstrap_messages_received.reset();
    _pimstat_bootstrap_messages_sent.reset();
    _pimstat_bootstrap_messages_rx_errors.reset();
    _pimstat_assert_messages_received.reset();
    _pimstat_assert_messages_sent.reset();
    _pimstat_assert_messages_rx_errors.reset();
    _pimstat_graft_messages_received.reset();
    _pimstat_graft_messages_sent.reset();
    _pimstat_graft_messages_rx_errors.reset();
    _pimstat_graft_ack_messages_received.reset();
    _pimstat_graft_ack_messages_sent.reset();
    _pimstat_graft_ack_messages_rx_errors.reset();
    _pimstat_candidate_rp_messages_received.reset();
    _pimstat_candidate_rp_messages_sent.reset();
    _pimstat_candidate_rp_messages_rx_errors.reset();
    //
    _pimstat_unknown_type_messages.reset();
    _pimstat_unknown_version_messages.reset();
    _pimstat_neighbor_unknown_messages.reset();
    _pimstat_bad_length_messages.reset();
    _pimstat_bad_checksum_messages.reset();
    _pimstat_bad_receive_interface_messages.reset();
    _pimstat_rx_interface_disabled_messages.reset();
    _pimstat_rx_register_not_rp.reset();
    _pimstat_rp_filtered_source.reset();
    _pimstat_unknown_register_stop.reset();
    _pimstat_rx_join_prune_no_state.reset();
    _pimstat_rx_graft_graft_ack_no_state.reset();
    _pimstat_rx_graft_on_upstream_interface.reset();
    _pimstat_rx_candidate_rp_not_bsr.reset();
    _pimstat_rx_bsr_when_bsr.reset();
    _pimstat_rx_bsr_not_rpf_interface.reset();
    _pimstat_rx_unknown_hello_option.reset();
    _pimstat_rx_data_no_state.reset();
    _pimstat_rx_rp_no_state.reset();
    _pimstat_rx_aggregate.reset();
    _pimstat_rx_malformed_packet.reset();
    _pimstat_no_rp.reset();
    _pimstat_no_route_upstream.reset();
    _pimstat_rp_mismatch.reset();
    _pimstat_rpf_neighbor_unknown.reset();
    //
    _pimstat_rx_join_rp.reset();
    _pimstat_rx_prune_rp.reset();
    _pimstat_rx_join_wc.reset();
    _pimstat_rx_prune_wc.reset();
    _pimstat_rx_join_sg.reset();
    _pimstat_rx_prune_sg.reset();
    _pimstat_rx_join_sg_rpt.reset();
    _pimstat_rx_prune_sg_rpt.reset();
}