Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

184 lines
4.8 KiB

  1. /*++
  2. Copyright (c) 1995-1998 Microsoft Corporation
  3. Module Name:
  4. lkuptst.h
  5. Abstract:
  6. Contains routines for testing an implementation
  7. for the generalized best matching prefix lookup
  8. interface.
  9. Author:
  10. Chaitanya Kodeboyina (chaitk) 30-Jun-1998
  11. Revision History:
  12. --*/
  13. #ifndef __LKUPTST_H
  14. #define __LKUPTST_H
  15. #include "lookup.h"
  16. // Constants
  17. #define MAX_FNAME_LEN 255
  18. #define MAX_LINE_LEN 255
  19. #define BITSINBYTE 8
  20. #define ADDRSIZE 32
  21. #define NUMBYTES 4
  22. #define MAXLEVEL 32
  23. #define MAXROUTES 64000
  24. #define ERROR_IPLMISC_BASE -100
  25. #define ERROR_WRONG_CMDUSAGE ERROR_IPLMISC_BASE - 1
  26. #define ERROR_OPENING_DATABASE ERROR_IPLMISC_BASE - 2
  27. #define ERROR_MAX_NUM_ROUTES ERROR_IPLMISC_BASE - 3
  28. // Macros
  29. #define FHalf(B) (B) >> 4
  30. #define BHalf(B) (B) & 0xF
  31. #define Print printf
  32. #define Assert(S) assert(S)
  33. #define SUCCESS(S) (S == NO_ERROR)
  34. #define Error(S, E) { \
  35. fprintf(stderr, S, E); \
  36. }
  37. #define Fatal(S, E) { \
  38. fprintf(stderr, S, E); \
  39. exit(E); \
  40. }
  41. #define ClearMemory(pm, nb) memset((pm), 0, (nb))
  42. #if PROF
  43. #define PROFVARS LARGE_INTEGER PCStart; /* PerformanceCountStart */ \
  44. LARGE_INTEGER PCStop; /* PerformanceCountStop */ \
  45. LARGE_INTEGER PCFreq; /* PerformanceCountFreq */ \
  46. double timer; \
  47. double duration; \
  48. \
  49. QueryPerformanceFrequency(&PCFreq); \
  50. // Print("Perf Counter Resolution = %.3f ns\n\n", \
  51. // (double) 1000 * 1000 * 1000 / PCFreq.QuadPart);
  52. #define STARTPROF QueryPerformanceCounter(&PCStart);
  53. #define STOPPROF QueryPerformanceCounter(&PCStop);
  54. #define INITPROF duration = 0;
  55. #define ADDPROF timer = (double)(PCStop.QuadPart - PCStart.QuadPart) \
  56. * 1000 * 1000 * 1000 / PCFreq.QuadPart; \
  57. duration += timer; \
  58. // Print("Add : %.3f ns\n\n", timer);
  59. #define SUBPROF timer = (double)(PCStop.QuadPart - PCStart.QuadPart) \
  60. * 1000 * 1000 * 1000 / PCFreq.QuadPart; \
  61. duration -= timer; \
  62. // Print("Sub : %.3f ns\n\n", timer);
  63. #define PRINTPROF // Print("Total Time Taken To Finish : %.3f ns\n", \
  64. // duration);
  65. #endif // if PROF
  66. // Route Structures
  67. typedef ULONG IPAddr;
  68. typedef ULONG IPMask;
  69. // A Route Corr. to a Prefix
  70. typedef struct _Route Route;
  71. struct _Route
  72. {
  73. IPAddr addr; // ULONG (32 bits) representing addr
  74. IPMask mask; // ULONG (32 bits) representing mask
  75. IPAddr nexthop; // ULONG (32 bits) for next hop addr
  76. USHORT len; // Num of bits in the address route
  77. UINT metric; // A measure to compare routes with
  78. PVOID interface; // Interface on which packet is sent
  79. LOOKUP_LINKAGE backptr; // Points back to the lookup structure
  80. };
  81. // Route Macros
  82. #define DEST(_pRoute_) ((_pRoute_)->addr)
  83. #define MASK(_pRoute_) ((_pRoute_)->mask)
  84. #define NHOP(_pRoute_) ((_pRoute_)->nexthop)
  85. #define LEN(_pRoute_) ((_pRoute_)->len)
  86. #define METRIC(_pRoute_) ((_pRoute_)->metric)
  87. #define IF(_pRoute_) ((_pRoute_)->interface)
  88. #define NULL_ROUTE(_pRoute_) (_pRoute_ == NULL)
  89. // Prototypes
  90. DWORD
  91. WorkOnLookup (
  92. IN Route *InputRoutes,
  93. IN UINT NumRoutes
  94. );
  95. VOID
  96. ReadAddrAndGetRoute (
  97. IN PVOID Table
  98. );
  99. VOID
  100. EnumerateAllRoutes (
  101. IN PVOID Table
  102. );
  103. UINT ReadRoutesFromFile(
  104. IN FILE *FilePtr,
  105. IN UINT NumRoutes,
  106. OUT Route *RouteTable
  107. );
  108. INT
  109. ReadRoute (
  110. IN FILE *FilePtr,
  111. OUT Route *route
  112. );
  113. VOID
  114. PrintRoute (
  115. IN Route *route
  116. );
  117. INT
  118. ReadIPAddr (
  119. IN FILE *FilePtr,
  120. OUT ULONG *addr
  121. );
  122. VOID
  123. PrintIPAddr (
  124. IN ULONG *addr
  125. );
  126. VOID
  127. Usage (
  128. VOID
  129. );
  130. #endif // __LKUPTST_H