paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 1 | #include <zebra.h> |
| 2 | |
| 3 | #include "vty.h" |
| 4 | #include "stream.h" |
| 5 | #include "privs.h" |
| 6 | |
| 7 | #include "bgpd/bgpd.h" |
| 8 | #include "bgpd/bgp_aspath.h" |
| 9 | |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 10 | #define VT100_RESET "\x1b[0m" |
| 11 | #define VT100_RED "\x1b[31m" |
| 12 | #define VT100_GREEN "\x1b[32m" |
| 13 | #define VT100_YELLOW "\x1b[33m" |
| 14 | #define OK VT100_GREEN "OK" VT100_RESET |
| 15 | #define FAILED VT100_RED "failed" VT100_RESET |
| 16 | |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 17 | /* need these to link in libbgp */ |
| 18 | struct zebra_privs_t *bgpd_privs = NULL; |
| 19 | struct thread_master *master = NULL; |
| 20 | |
| 21 | static int failed = 0; |
| 22 | |
| 23 | /* specification for a test - what the results should be */ |
| 24 | struct test_spec |
| 25 | { |
| 26 | const char *shouldbe; /* the string the path should parse to */ |
| 27 | const char *shouldbe_delete_confed; /* ditto, but once confeds are deleted */ |
paul | 84771ee | 2005-10-11 03:48:28 +0000 | [diff] [blame] | 28 | const unsigned int hops; /* aspath_count_hops result */ |
| 29 | const unsigned int confeds; /* aspath_count_confeds */ |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 30 | const int private_as; /* whether the private_as check should pass or fail */ |
| 31 | #define NOT_ALL_PRIVATE 0 |
| 32 | #define ALL_PRIVATE 1 |
| 33 | const as_t does_loop; /* an ASN which should trigger loop-check */ |
| 34 | const as_t doesnt_loop; /* one which should not */ |
| 35 | const as_t first; /* the first ASN, if there is one */ |
| 36 | #define NULL_ASN 0 |
| 37 | }; |
| 38 | |
| 39 | |
| 40 | /* test segments to parse and validate, and use for other tests */ |
| 41 | static struct test_segment { |
| 42 | const char *name; |
| 43 | const char *desc; |
| 44 | const u_char asdata[1024]; |
| 45 | int len; |
| 46 | struct test_spec sp; |
| 47 | } test_segments [] = |
| 48 | { |
| 49 | { /* 0 */ |
| 50 | "seq1", |
| 51 | "seq(8466,3,52737,4096)", |
| 52 | { 0x2,0x4, 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00 }, |
| 53 | 10, |
| 54 | { "8466 3 52737 4096", |
| 55 | "8466 3 52737 4096", |
| 56 | 4, 0, NOT_ALL_PRIVATE, 4096, 4, 8466 }, |
| 57 | }, |
| 58 | { /* 1 */ |
| 59 | "seq2", |
| 60 | "seq(8722) seq(4)", |
| 61 | { 0x2,0x1, 0x22,0x12, |
| 62 | 0x2,0x1, 0x00,0x04 }, |
| 63 | 8, |
| 64 | { "8722 4", |
| 65 | "8722 4", |
| 66 | 2, 0, NOT_ALL_PRIVATE, 4, 5, 8722, }, |
| 67 | }, |
| 68 | { /* 2 */ |
| 69 | "seq3", |
| 70 | "seq(8466,3,52737,4096,8722,4)", |
| 71 | { 0x2,0x6, 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, |
| 72 | 0x22,0x12, 0x00,0x04}, |
| 73 | 14, |
| 74 | { "8466 3 52737 4096 8722 4", |
| 75 | "8466 3 52737 4096 8722 4", |
| 76 | 6, 0, NOT_ALL_PRIVATE, 3, 5, 8466 }, |
| 77 | }, |
| 78 | { /* 3 */ |
| 79 | "seqset", |
| 80 | "seq(8482,51457) set(5204)", |
| 81 | { 0x2,0x2, 0x21,0x22, 0xc9,0x01, |
| 82 | 0x1,0x1, 0x14,0x54 }, |
| 83 | 10, |
| 84 | { "8482 51457 {5204}", |
| 85 | "8482 51457 {5204}", |
Paul Jakma | 1f742f2 | 2006-08-06 15:52:11 +0000 | [diff] [blame] | 86 | 3, 0, NOT_ALL_PRIVATE, 5204, 51456, 8482}, |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 87 | }, |
| 88 | { /* 4 */ |
| 89 | "seqset2", |
| 90 | "seq(8467, 59649) set(4196,48658) set(17322,30745)", |
| 91 | { 0x2,0x2, 0x21,0x13, 0xe9,0x01, |
| 92 | 0x1,0x2, 0x10,0x64, 0xbe,0x12, |
| 93 | 0x1,0x2, 0x43,0xaa, 0x78,0x19 }, |
| 94 | 18, |
| 95 | { "8467 59649 {4196,48658} {17322,30745}", |
| 96 | "8467 59649 {4196,48658} {17322,30745}", |
| 97 | 4, 0, NOT_ALL_PRIVATE, 48658, 1, 8467}, |
| 98 | }, |
| 99 | { /* 5 */ |
| 100 | "multi", |
| 101 | "seq(6435,59408,21665) set(2457,61697,4369), seq(1842,41590,51793)", |
| 102 | { 0x2,0x3, 0x19,0x23, 0xe8,0x10, 0x54,0xa1, |
| 103 | 0x1,0x3, 0x09,0x99, 0xf1,0x01, 0x11,0x11, |
| 104 | 0x2,0x3, 0x07,0x32, 0xa2,0x76, 0xca,0x51 }, |
| 105 | 24, |
| 106 | { "6435 59408 21665 {2457,4369,61697} 1842 41590 51793", |
| 107 | "6435 59408 21665 {2457,4369,61697} 1842 41590 51793", |
| 108 | 7, 0, NOT_ALL_PRIVATE, 51793, 1, 6435 }, |
| 109 | }, |
| 110 | { /* 6 */ |
| 111 | "confed", |
| 112 | "confseq(123,456,789)", |
| 113 | { 0x3,0x3, 0x00,0x7b, 0x01,0xc8, 0x03,0x15 }, |
| 114 | 8, |
| 115 | { "(123 456 789)", |
| 116 | "", |
| 117 | 0, 3, NOT_ALL_PRIVATE, 789, 1, NULL_ASN }, |
| 118 | }, |
| 119 | { /* 7 */ |
| 120 | "confed2", |
| 121 | "confseq(123,456,789) confseq(111,222)", |
| 122 | { 0x3,0x3, 0x00,0x7b, 0x01,0xc8, 0x03,0x15, |
| 123 | 0x3,0x2, 0x00,0x6f, 0x00,0xde }, |
| 124 | 14, |
| 125 | { "(123 456 789) (111 222)", |
| 126 | "", |
| 127 | 0, 5, NOT_ALL_PRIVATE, 111, 1, NULL_ASN }, |
| 128 | }, |
| 129 | { /* 8 */ |
| 130 | "confset", |
| 131 | "confset(456,123,789)", |
| 132 | { 0x4,0x3, 0x01,0xc8, 0x00,0x7b, 0x03,0x15 }, |
| 133 | 8, |
| 134 | { "[123,456,789]", |
| 135 | "[123,456,789]", |
| 136 | 0, 1, NOT_ALL_PRIVATE, 123, 1, NULL_ASN }, |
| 137 | }, |
| 138 | { /* 9 */ |
| 139 | "confmulti", |
| 140 | "confseq(123,456,789) confset(222,111) seq(8722) set(4196,48658)", |
| 141 | { 0x3,0x3, 0x00,0x7b, 0x01,0xc8, 0x03,0x15, |
| 142 | 0x4,0x2, 0x00,0xde, 0x00,0x6f, |
| 143 | 0x2,0x1, 0x22,0x12, |
| 144 | 0x1,0x2, 0x10,0x64, 0xbe,0x12 }, |
| 145 | 24, |
| 146 | { "(123 456 789) [111,222] 8722 {4196,48658}", |
| 147 | "8722 {4196,48658}", |
| 148 | 2, 4, NOT_ALL_PRIVATE, 123, 1, NULL_ASN }, |
| 149 | }, |
| 150 | { /* 10 */ |
| 151 | "seq4", |
| 152 | "seq(8466,2,52737,4096,8722,4)", |
| 153 | { 0x2,0x6, 0x21,0x12, 0x00,0x02, 0xce,0x01, 0x10,0x00, |
| 154 | 0x22,0x12, 0x00,0x04}, |
| 155 | 14, |
| 156 | { "8466 2 52737 4096 8722 4", |
| 157 | "8466 2 52737 4096 8722 4", |
| 158 | 6, 0, NOT_ALL_PRIVATE, 4096, 1, 8466 }, |
| 159 | }, |
| 160 | { /* 11 */ |
| 161 | "tripleseq1", |
| 162 | "seq(8466,2,52737) seq(4096,8722,4) seq(8722)", |
| 163 | { 0x2,0x3, 0x21,0x12, 0x00,0x02, 0xce,0x01, |
| 164 | 0x2,0x3, 0x10,0x00, 0x22,0x12, 0x00,0x04, |
| 165 | 0x2,0x1, 0x22,0x12}, |
| 166 | 20, |
| 167 | { "8466 2 52737 4096 8722 4 8722", |
| 168 | "8466 2 52737 4096 8722 4 8722", |
| 169 | 7, 0, NOT_ALL_PRIVATE, 4096, 1, 8466 }, |
| 170 | }, |
| 171 | { /* 12 */ |
| 172 | "someprivate", |
| 173 | "seq(8466,64512,52737,65535)", |
| 174 | { 0x2,0x4, 0x21,0x12, 0xfc,0x00, 0xce,0x01, 0xff,0xff }, |
| 175 | 10, |
| 176 | { "8466 64512 52737 65535", |
| 177 | "8466 64512 52737 65535", |
| 178 | 4, 0, NOT_ALL_PRIVATE, 65535, 4, 8466 }, |
| 179 | }, |
| 180 | { /* 13 */ |
| 181 | "allprivate", |
| 182 | "seq(65534,64512,64513,65535)", |
| 183 | { 0x2,0x4, 0xff,0xfe, 0xfc,0x00, 0xfc,0x01, 0xff,0xff }, |
| 184 | 10, |
| 185 | { "65534 64512 64513 65535", |
| 186 | "65534 64512 64513 65535", |
| 187 | 4, 0, ALL_PRIVATE, 65534, 4, 65534 }, |
| 188 | }, |
| 189 | { /* 14 */ |
| 190 | "long", |
| 191 | "seq(8466,3,52737,4096,34285,<repeated 49 more times>)", |
| 192 | { 0x2,0xfa, 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 193 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 194 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 195 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 196 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 197 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 198 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 199 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 200 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 201 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 202 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 203 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 204 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 205 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 206 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 207 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 208 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 209 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 210 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 211 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 212 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 213 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 214 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 215 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 216 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 217 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 218 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 219 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 220 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 221 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 222 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 223 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 224 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 225 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 226 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 227 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 228 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 229 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 230 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 231 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 232 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 233 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 234 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 235 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 236 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 237 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 238 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 239 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 240 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, |
| 241 | 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, }, |
| 242 | 502, |
| 243 | { "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 244 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 245 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 246 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 247 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 248 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 249 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 250 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 251 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 252 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 253 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 254 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 255 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 256 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 257 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 258 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 259 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 260 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 261 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 262 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 263 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 264 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 265 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 266 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 267 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285", |
| 268 | |
| 269 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 270 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 271 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 272 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 273 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 274 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 275 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 276 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 277 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 278 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 279 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 280 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 281 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 282 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 283 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 284 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 285 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 286 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 287 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 288 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 289 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 290 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 291 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 292 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 293 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285", |
| 294 | 250, 0, NOT_ALL_PRIVATE, 4096, 4, 8466 }, |
| 295 | }, |
paul | 5906476 | 2005-11-23 02:48:14 +0000 | [diff] [blame] | 296 | { /* 15 */ |
| 297 | "seq1extra", |
| 298 | "seq(8466,3,52737,4096,3456)", |
| 299 | { 0x2,0x5, 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x0d,0x80 }, |
| 300 | 12, |
| 301 | { "8466 3 52737 4096 3456", |
| 302 | "8466 3 52737 4096 3456", |
| 303 | 5, 0, NOT_ALL_PRIVATE, 4096, 4, 8466 }, |
| 304 | }, |
| 305 | { /* 16 */ |
| 306 | "empty", |
| 307 | "<empty>", |
| 308 | {}, |
| 309 | 0, |
| 310 | { "", "", 0, 0, 0, 0, 0, 0 }, |
| 311 | }, |
Paul Jakma | 5d932f6 | 2006-03-30 13:42:50 +0000 | [diff] [blame] | 312 | { /* 17 */ |
| 313 | "redundantset", |
| 314 | "seq(8466,3,52737,4096,3456) set(7099,8153,8153,8153)", |
| 315 | { 0x2,0x5, 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x0d,0x80, |
| 316 | 0x1,0x4, 0x1b,0xbb, 0x1f,0xd9, 0x1f,0xd9, 0x1f,0xd9 }, |
| 317 | 22, |
| 318 | { |
| 319 | /* We shouldn't ever /generate/ such paths. However, we should |
| 320 | * cope with them fine. |
| 321 | */ |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 322 | "8466 3 52737 4096 3456 {7099,8153}", |
| 323 | "8466 3 52737 4096 3456 {7099,8153}", |
| 324 | 6, 0, NOT_ALL_PRIVATE, 4096, 4, 8466 }, |
| 325 | }, |
| 326 | { /* 18 */ |
| 327 | "reconcile_lead_asp", |
| 328 | "seq(6435,59408,21665) set(23456,23456,23456), seq(23456,23456,23456)", |
| 329 | { 0x2,0x3, 0x19,0x23, 0xe8,0x10, 0x54,0xa1, |
| 330 | 0x1,0x3, 0x5b,0xa0, 0x5b,0xa0, 0x5b,0xa0, |
| 331 | 0x2,0x3, 0x5b,0xa0, 0x5b,0xa0, 0x5b,0xa0 }, |
| 332 | 24, |
| 333 | { "6435 59408 21665 {23456} 23456 23456 23456", |
| 334 | "6435 59408 21665 {23456} 23456 23456 23456", |
| 335 | 7, 0, NOT_ALL_PRIVATE, 23456, 1, 6435 }, |
| 336 | }, |
| 337 | { /* 19 */ |
| 338 | "reconcile_new_asp", |
| 339 | "set(2457,61697,4369), seq(1842,41591,51793)", |
| 340 | { |
| 341 | 0x1,0x3, 0x09,0x99, 0xf1,0x01, 0x11,0x11, |
| 342 | 0x2,0x3, 0x07,0x32, 0xa2,0x77, 0xca,0x51 }, |
| 343 | 16, |
| 344 | { "{2457,4369,61697} 1842 41591 51793", |
| 345 | "{2457,4369,61697} 1842 41591 51793", |
| 346 | 4, 0, NOT_ALL_PRIVATE, 51793, 1, 2457 }, |
| 347 | }, |
| 348 | { /* 20 */ |
| 349 | "reconcile_confed", |
| 350 | "confseq(123,456,789) confset(456,124,788) seq(6435,59408,21665)" |
| 351 | " set(23456,23456,23456), seq(23456,23456,23456)", |
| 352 | { 0x3,0x3, 0x00,0x7b, 0x01,0xc8, 0x03,0x15, |
| 353 | 0x4,0x3, 0x01,0xc8, 0x00,0x7c, 0x03,0x14, |
| 354 | 0x2,0x3, 0x19,0x23, 0xe8,0x10, 0x54,0xa1, |
| 355 | 0x1,0x3, 0x5b,0xa0, 0x5b,0xa0, 0x5b,0xa0, |
| 356 | 0x2,0x3, 0x5b,0xa0, 0x5b,0xa0, 0x5b,0xa0 }, |
| 357 | 40, |
| 358 | { "(123 456 789) [124,456,788] 6435 59408 21665" |
| 359 | " {23456} 23456 23456 23456", |
| 360 | "6435 59408 21665 {23456} 23456 23456 23456", |
| 361 | 7, 4, NOT_ALL_PRIVATE, 23456, 1, 6435 }, |
| 362 | }, |
| 363 | { /* 21 */ |
| 364 | "reconcile_start_trans", |
| 365 | "seq(23456,23456,23456) seq(6435,59408,21665)", |
| 366 | { 0x2,0x3, 0x5b,0xa0, 0x5b,0xa0, 0x5b,0xa0, |
| 367 | 0x2,0x3, 0x19,0x23, 0xe8,0x10, 0x54,0xa1, }, |
| 368 | 16, |
| 369 | { "23456 23456 23456 6435 59408 21665", |
| 370 | "23456 23456 23456 6435 59408 21665", |
| 371 | 6, 0, NOT_ALL_PRIVATE, 21665, 1, 23456 }, |
| 372 | }, |
| 373 | { /* 22 */ |
| 374 | "reconcile_start_trans4", |
| 375 | "seq(1842,41591,51793) seq(6435,59408,21665)", |
| 376 | { 0x2,0x3, 0x07,0x32, 0xa2,0x77, 0xca,0x51, |
| 377 | 0x2,0x3, 0x19,0x23, 0xe8,0x10, 0x54,0xa1, }, |
| 378 | 16, |
| 379 | { "1842 41591 51793 6435 59408 21665", |
| 380 | "1842 41591 51793 6435 59408 21665", |
| 381 | 6, 0, NOT_ALL_PRIVATE, 41591, 1, 1842 }, |
| 382 | }, |
| 383 | { /* 23 */ |
| 384 | "reconcile_start_trans_error", |
| 385 | "seq(23456,23456,23456) seq(6435,59408)", |
| 386 | { 0x2,0x3, 0x5b,0xa0, 0x5b,0xa0, 0x5b,0xa0, |
| 387 | 0x2,0x2, 0x19,0x23, 0xe8,0x10, }, |
| 388 | 14, |
| 389 | { "23456 23456 23456 6435 59408", |
| 390 | "23456 23456 23456 6435 59408", |
| 391 | 5, 0, NOT_ALL_PRIVATE, 59408, 1, 23456 }, |
| 392 | }, |
| 393 | { /* 24 */ |
| 394 | "redundantset2", |
| 395 | "seq(8466,3,52737,4096,3456) set(7099,8153,8153,8153,7099)", |
| 396 | { 0x2,0x5, 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x0d,0x80, |
| 397 | 0x1,0x5, 0x1b,0xbb, 0x1f,0xd9, 0x1f,0xd9, 0x1f,0xd9, 0x1b,0xbb,}, |
| 398 | 24, |
| 399 | { |
| 400 | /* We should weed out duplicate set members. */ |
| 401 | "8466 3 52737 4096 3456 {7099,8153}", |
| 402 | "8466 3 52737 4096 3456 {7099,8153}", |
Paul Jakma | 5d932f6 | 2006-03-30 13:42:50 +0000 | [diff] [blame] | 403 | 6, 0, NOT_ALL_PRIVATE, 4096, 4, 8466 }, |
| 404 | }, |
Paul Jakma | d38e8d6 | 2008-02-23 16:57:03 +0000 | [diff] [blame] | 405 | { /* 25 */ |
| 406 | "zero-size overflow", |
| 407 | "#ASNs = 0, data = seq(8466 3 52737 4096 3456)", |
| 408 | { 0x2,0x0, 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x0d,0x80 }, |
| 409 | 12, |
| 410 | { "", "", |
| 411 | 0, 0, 0, 0, 0, 0 }, |
| 412 | }, |
| 413 | { /* 26 */ |
| 414 | "zero-size overflow + valid segment", |
| 415 | "seq(#AS=0:8466 3 52737),seq(4096 3456)", |
| 416 | { 0x2,0x0, 0x21,0x12, 0x00,0x03, 0xce,0x01, |
| 417 | 0x2,0x2, 0x10,0x00, 0x0d,0x80 }, |
| 418 | 14 |
| 419 | , |
| 420 | { "", "", |
| 421 | 0, 0, 0, 0, 0, 0 }, |
| 422 | }, |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 423 | { NULL, NULL, {0}, 0, { NULL, 0, 0 } } |
| 424 | }; |
| 425 | |
| 426 | /* prepending tests */ |
| 427 | static struct tests { |
| 428 | const struct test_segment *test1; |
| 429 | const struct test_segment *test2; |
| 430 | struct test_spec sp; |
| 431 | } prepend_tests[] = |
| 432 | { |
| 433 | { &test_segments[0], &test_segments[1], |
| 434 | { "8466 3 52737 4096 8722 4", |
| 435 | "8466 3 52737 4096 8722 4", |
| 436 | 6, 0, NOT_ALL_PRIVATE, 4096, 1, 8466 }, |
| 437 | }, |
| 438 | { &test_segments[1], &test_segments[3], |
| 439 | { "8722 4 8482 51457 {5204}", |
| 440 | "8722 4 8482 51457 {5204}", |
| 441 | 5, 0, NOT_ALL_PRIVATE, 5204, 1, 8722 } |
| 442 | }, |
| 443 | { &test_segments[3], &test_segments[4], |
| 444 | { "8482 51457 {5204} 8467 59649 {4196,48658} {17322,30745}", |
| 445 | "8482 51457 {5204} 8467 59649 {4196,48658} {17322,30745}", |
| 446 | 7, 0, NOT_ALL_PRIVATE, 5204, 1, 8482 }, |
| 447 | }, |
| 448 | { &test_segments[4], &test_segments[5], |
| 449 | { "8467 59649 {4196,48658} {17322,30745} 6435 59408 21665" |
| 450 | " {2457,4369,61697} 1842 41590 51793", |
| 451 | "8467 59649 {4196,48658} {17322,30745} 6435 59408 21665" |
| 452 | " {2457,4369,61697} 1842 41590 51793", |
| 453 | 11, 0, NOT_ALL_PRIVATE, 61697, 1, 8467 } |
| 454 | }, |
| 455 | { &test_segments[5], &test_segments[6], |
| 456 | { "6435 59408 21665 {2457,4369,61697} 1842 41590 51793 (123 456 789)", |
| 457 | "6435 59408 21665 {2457,4369,61697} 1842 41590 51793 (123 456 789)", |
| 458 | 7, 3, NOT_ALL_PRIVATE, 123, 1, 6435 }, |
| 459 | }, |
| 460 | { &test_segments[6], &test_segments[7], |
| 461 | { "(123 456 789) (123 456 789) (111 222)", |
| 462 | "", |
| 463 | 0, 8, NOT_ALL_PRIVATE, 111, 1, 0 } |
| 464 | }, |
| 465 | { &test_segments[7], &test_segments[8], |
| 466 | { "(123 456 789) (111 222) [123,456,789]", |
| 467 | "", |
| 468 | 0, 6, NOT_ALL_PRIVATE, 111, 1, 0 } |
| 469 | }, |
| 470 | { &test_segments[8], &test_segments[9], |
| 471 | { "[123,456,789] (123 456 789) [111,222] 8722 {4196,48658}", |
| 472 | "[123,456,789] (123 456 789) [111,222] 8722 {4196,48658}", |
| 473 | 2, 5, NOT_ALL_PRIVATE, 456, 1, NULL_ASN }, |
| 474 | }, |
| 475 | { &test_segments[9], &test_segments[8], |
| 476 | { "(123 456 789) [111,222] 8722 {4196,48658} [123,456,789]", |
| 477 | "8722 {4196,48658} [123,456,789]", |
| 478 | 2, 5, NOT_ALL_PRIVATE, 48658, 1, NULL_ASN }, |
| 479 | }, |
| 480 | { &test_segments[14], &test_segments[11], |
| 481 | { "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 482 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 483 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 484 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 485 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 486 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 487 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 488 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 489 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 490 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 491 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 492 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 493 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 494 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 495 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 496 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 497 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 498 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 499 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 500 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 501 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 502 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 503 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 504 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 505 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 506 | "8466 2 52737 4096 8722 4 8722", |
| 507 | |
| 508 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 509 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 510 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 511 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 512 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 513 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 514 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 515 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 516 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 517 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 518 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 519 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 520 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 521 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 522 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 523 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 524 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 525 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 526 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 527 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 528 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 529 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 530 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 531 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 532 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " |
| 533 | "8466 2 52737 4096 8722 4 8722", |
| 534 | 257, 0, NOT_ALL_PRIVATE, 4096, 1000, 8466 }, |
| 535 | }, |
| 536 | { NULL, NULL, { NULL, 0, 0, 0, 0, 0, 0, } }, |
| 537 | }; |
| 538 | |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 539 | struct tests reconcile_tests[] = |
| 540 | { |
| 541 | { &test_segments[18], &test_segments[19], |
| 542 | { "6435 59408 21665 {2457,4369,61697} 1842 41591 51793", |
| 543 | "6435 59408 21665 {2457,4369,61697} 1842 41591 51793", |
| 544 | 7, 0, NOT_ALL_PRIVATE, 51793, 1, 6435 }, |
| 545 | }, |
| 546 | { &test_segments[19], &test_segments[18], |
| 547 | /* AS_PATH (19) has more hops than NEW_AS_PATH, |
| 548 | * so just AS_PATH should be used (though, this practice |
| 549 | * is bad imho). |
| 550 | */ |
| 551 | { "{2457,4369,61697} 1842 41591 51793 6435 59408 21665 {23456} 23456 23456 23456", |
| 552 | "{2457,4369,61697} 1842 41591 51793 6435 59408 21665 {23456} 23456 23456 23456", |
| 553 | 11, 0, NOT_ALL_PRIVATE, 51793, 1, 6435 }, |
| 554 | }, |
| 555 | { &test_segments[20], &test_segments[19], |
| 556 | { "(123 456 789) [124,456,788] 6435 59408 21665" |
| 557 | " {2457,4369,61697} 1842 41591 51793", |
| 558 | "6435 59408 21665 {2457,4369,61697} 1842 41591 51793", |
| 559 | 7, 4, NOT_ALL_PRIVATE, 51793, 1, 6435 }, |
| 560 | }, |
| 561 | { &test_segments[21], &test_segments[22], |
| 562 | { "1842 41591 51793 6435 59408 21665", |
| 563 | "1842 41591 51793 6435 59408 21665", |
| 564 | 6, 0, NOT_ALL_PRIVATE, 51793, 1, 1842 }, |
| 565 | }, |
| 566 | { &test_segments[23], &test_segments[22], |
| 567 | { "23456 23456 23456 6435 59408 1842 41591 51793 6435 59408 21665", |
| 568 | "23456 23456 23456 6435 59408 1842 41591 51793 6435 59408 21665", |
| 569 | 11, 0, NOT_ALL_PRIVATE, 51793, 1, 1842 }, |
| 570 | }, |
| 571 | { NULL, NULL, { NULL, 0, 0, 0, 0, 0, 0, } }, |
| 572 | }; |
| 573 | |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 574 | struct tests aggregate_tests[] = |
| 575 | { |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 576 | { &test_segments[0], &test_segments[2], |
| 577 | { "8466 3 52737 4096 {4,8722}", |
| 578 | "8466 3 52737 4096 {4,8722}", |
| 579 | 5, 0, NOT_ALL_PRIVATE, 4, 1, 8466 }, |
| 580 | }, |
| 581 | { &test_segments[2], &test_segments[0], |
| 582 | { "8466 3 52737 4096 {4,8722}", |
| 583 | "8466 3 52737 4096 {4,8722}", |
| 584 | 5, 0, NOT_ALL_PRIVATE, 8722, 1, 8466 }, |
| 585 | }, |
| 586 | { &test_segments[2], &test_segments[10], |
| 587 | { "8466 {2,3,4,4096,8722,52737}", |
| 588 | "8466 {2,3,4,4096,8722,52737}", |
| 589 | 2, 0, NOT_ALL_PRIVATE, 8722, 5, 8466 }, |
| 590 | }, |
| 591 | { &test_segments[10], &test_segments[2], |
| 592 | { "8466 {2,3,4,4096,8722,52737}", |
| 593 | "8466 {2,3,4,4096,8722,52737}", |
| 594 | 2, 0, NOT_ALL_PRIVATE, 2, 20000, 8466 }, |
| 595 | }, |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 596 | |
| 597 | { &test_segments[5], &test_segments[18], |
| 598 | { "6435 59408 21665 {1842,2457,4369,23456,41590,51793,61697}", |
| 599 | "6435 59408 21665 {1842,2457,4369,23456,41590,51793,61697}", |
| 600 | 4, 0, NOT_ALL_PRIVATE, 41590, 1, 6435 }, |
| 601 | }, |
| 602 | |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 603 | { NULL, NULL, { NULL, 0, 0} }, |
| 604 | }; |
| 605 | |
| 606 | struct compare_tests |
| 607 | { |
| 608 | int test_index1; |
| 609 | int test_index2; |
| 610 | #define CMP_RES_YES 1 |
| 611 | #define CMP_RES_NO 0 |
| 612 | char shouldbe_cmp; |
| 613 | char shouldbe_confed; |
| 614 | } left_compare [] = |
| 615 | { |
| 616 | { 0, 1, CMP_RES_NO, CMP_RES_NO }, |
| 617 | { 0, 2, CMP_RES_YES, CMP_RES_NO }, |
| 618 | { 0, 11, CMP_RES_YES, CMP_RES_NO }, |
paul | 5906476 | 2005-11-23 02:48:14 +0000 | [diff] [blame] | 619 | { 0, 15, CMP_RES_YES, CMP_RES_NO }, |
| 620 | { 0, 16, CMP_RES_NO, CMP_RES_NO }, |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 621 | { 1, 11, CMP_RES_NO, CMP_RES_NO }, |
| 622 | { 6, 7, CMP_RES_NO, CMP_RES_YES }, |
| 623 | { 6, 8, CMP_RES_NO, CMP_RES_NO }, |
| 624 | { 7, 8, CMP_RES_NO, CMP_RES_NO }, |
| 625 | { 1, 9, CMP_RES_YES, CMP_RES_NO }, |
| 626 | { 0, 9, CMP_RES_NO, CMP_RES_NO }, |
| 627 | { 3, 9, CMP_RES_NO, CMP_RES_NO }, |
| 628 | { 0, 6, CMP_RES_NO, CMP_RES_NO }, |
| 629 | { 1, 6, CMP_RES_NO, CMP_RES_NO }, |
| 630 | { 0, 8, CMP_RES_NO, CMP_RES_NO }, |
| 631 | { 1, 8, CMP_RES_NO, CMP_RES_NO }, |
| 632 | { 11, 6, CMP_RES_NO, CMP_RES_NO }, |
| 633 | { 11, 7, CMP_RES_NO, CMP_RES_NO }, |
| 634 | { 11, 8, CMP_RES_NO, CMP_RES_NO }, |
| 635 | { 9, 6, CMP_RES_NO, CMP_RES_YES }, |
| 636 | { 9, 7, CMP_RES_NO, CMP_RES_YES }, |
| 637 | { 9, 8, CMP_RES_NO, CMP_RES_NO }, |
| 638 | }; |
| 639 | |
| 640 | /* make an aspath from a data stream */ |
| 641 | static struct aspath * |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 642 | make_aspath (const u_char *data, size_t len, int use32bit) |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 643 | { |
| 644 | struct stream *s = NULL; |
| 645 | struct aspath *as; |
| 646 | |
| 647 | if (len) |
| 648 | { |
| 649 | s = stream_new (len); |
| 650 | stream_put (s, data, len); |
| 651 | } |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 652 | as = aspath_parse (s, len, use32bit); |
paul | 5906476 | 2005-11-23 02:48:14 +0000 | [diff] [blame] | 653 | |
| 654 | if (s) |
| 655 | stream_free (s); |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 656 | |
| 657 | return as; |
| 658 | } |
| 659 | |
| 660 | static void |
| 661 | printbytes (const u_char *bytes, int len) |
| 662 | { |
| 663 | int i = 0; |
| 664 | while (i < len) |
| 665 | { |
| 666 | if (i % 2) |
| 667 | printf ("%02hhx%s", bytes[i], " "); |
| 668 | else |
| 669 | printf ("0x%02hhx", bytes[i]); |
| 670 | i++; |
| 671 | } |
| 672 | printf ("\n"); |
| 673 | } |
| 674 | |
| 675 | /* validate the given aspath */ |
| 676 | static int |
| 677 | validate (struct aspath *as, const struct test_spec *sp) |
| 678 | { |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 679 | size_t bytes, bytes4; |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 680 | int fails = 0; |
| 681 | const u_char *out; |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 682 | static struct stream *s; |
| 683 | struct aspath *asinout, *asconfeddel, *asstr, *as4; |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 684 | |
| 685 | out = aspath_snmp_pathseg (as, &bytes); |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 686 | asinout = make_aspath (out, bytes, 0); |
| 687 | |
| 688 | /* Excercise AS4 parsing a bit, with a dogfood test */ |
| 689 | if (!s) |
| 690 | s = stream_new (4096); |
| 691 | bytes4 = aspath_put (s, as, 1); |
| 692 | as4 = make_aspath (STREAM_DATA(s), bytes4, 1); |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 693 | |
| 694 | asstr = aspath_str2aspath (sp->shouldbe); |
| 695 | |
| 696 | asconfeddel = aspath_delete_confed_seq (aspath_dup (asinout)); |
| 697 | |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 698 | printf ("got: %s\n", aspath_print(as)); |
| 699 | |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 700 | /* the parsed path should match the specified 'shouldbe' string. |
| 701 | * We should pass the "eat our own dog food" test, be able to output |
| 702 | * this path and then input it again. Ie the path resulting from: |
| 703 | * |
| 704 | * aspath_parse(aspath_put(as)) |
| 705 | * |
| 706 | * should: |
| 707 | * |
| 708 | * - also match the specified 'shouldbe' value |
| 709 | * - hash to same value as original path |
| 710 | * - have same hops and confed counts as original, and as the |
| 711 | * the specified counts |
| 712 | * |
| 713 | * aspath_str2aspath() and shouldbe should match |
| 714 | * |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 715 | * We do the same for: |
| 716 | * |
| 717 | * aspath_parse(aspath_put(as,USE32BIT)) |
| 718 | * |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 719 | * Confederation related tests: |
| 720 | * - aspath_delete_confed_seq(aspath) should match shouldbe_confed |
| 721 | * - aspath_delete_confed_seq should be idempotent. |
| 722 | */ |
| 723 | if (strcmp(aspath_print (as), sp->shouldbe) |
| 724 | /* hash validation */ |
| 725 | || (aspath_key_make (as) != aspath_key_make (asinout)) |
| 726 | /* by string */ |
| 727 | || strcmp(aspath_print (asinout), sp->shouldbe) |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 728 | /* By 4-byte parsing */ |
| 729 | || strcmp(aspath_print (as4), sp->shouldbe) |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 730 | /* by various path counts */ |
| 731 | || (aspath_count_hops (as) != sp->hops) |
| 732 | || (aspath_count_confeds (as) != sp->confeds) |
| 733 | || (aspath_count_hops (asinout) != sp->hops) |
| 734 | || (aspath_count_confeds (asinout) != sp->confeds)) |
| 735 | { |
| 736 | failed++; |
| 737 | fails++; |
| 738 | printf ("shouldbe:\n%s\n", sp->shouldbe); |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 739 | printf ("as4:\n%s\n", aspath_print (as4)); |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 740 | printf ("hash keys: in: %d out->in: %d\n", |
| 741 | aspath_key_make (as), aspath_key_make (asinout)); |
| 742 | printf ("hops: %d, counted %d %d\n", sp->hops, |
| 743 | aspath_count_hops (as), |
| 744 | aspath_count_hops (asinout) ); |
| 745 | printf ("confeds: %d, counted %d %d\n", sp->confeds, |
| 746 | aspath_count_confeds (as), |
| 747 | aspath_count_confeds (asinout)); |
| 748 | printf ("out->in:\n%s\nbytes: ", aspath_print(asinout)); |
| 749 | printbytes (out, bytes); |
| 750 | } |
| 751 | /* basic confed related tests */ |
| 752 | if ((aspath_print (asconfeddel) == NULL |
| 753 | && sp->shouldbe_delete_confed != NULL) |
| 754 | || (aspath_print (asconfeddel) != NULL |
| 755 | && sp->shouldbe_delete_confed == NULL) |
| 756 | || strcmp(aspath_print (asconfeddel), sp->shouldbe_delete_confed) |
| 757 | /* delete_confed_seq should be idempotent */ |
| 758 | || (aspath_key_make (asconfeddel) |
| 759 | != aspath_key_make (aspath_delete_confed_seq (asconfeddel)))) |
| 760 | { |
| 761 | failed++; |
| 762 | fails++; |
| 763 | printf ("confed_del: %s\n", aspath_print (asconfeddel)); |
| 764 | printf ("should be: %s\n", sp->shouldbe_delete_confed); |
| 765 | } |
| 766 | /* aspath_str2aspath test */ |
| 767 | if ((aspath_print (asstr) == NULL && sp->shouldbe != NULL) |
| 768 | || (aspath_print (asstr) != NULL && sp->shouldbe == NULL) |
| 769 | || strcmp(aspath_print (asstr), sp->shouldbe)) |
| 770 | { |
| 771 | failed++; |
| 772 | fails++; |
| 773 | printf ("asstr: %s\n", aspath_print (asstr)); |
| 774 | } |
| 775 | |
| 776 | /* loop, private and first as checks */ |
Paul Jakma | 1f742f2 | 2006-08-06 15:52:11 +0000 | [diff] [blame] | 777 | if ((sp->does_loop && aspath_loop_check (as, sp->does_loop) == 0) |
| 778 | || (sp->doesnt_loop && aspath_loop_check (as, sp->doesnt_loop) != 0) |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 779 | || (aspath_private_as_check (as) != sp->private_as) |
| 780 | || (aspath_firstas_check (as,sp->first) |
| 781 | && sp->first == 0)) |
| 782 | { |
| 783 | failed++; |
| 784 | fails++; |
| 785 | printf ("firstas: %d, got %d\n", sp->first, |
| 786 | aspath_firstas_check (as,sp->first)); |
| 787 | printf ("loop does: %d %d, doesnt: %d %d\n", |
| 788 | sp->does_loop, aspath_loop_check (as, sp->does_loop), |
| 789 | sp->doesnt_loop, aspath_loop_check (as, sp->doesnt_loop)); |
| 790 | printf ("private check: %d %d\n", sp->private_as, |
| 791 | aspath_private_as_check (as)); |
| 792 | } |
| 793 | aspath_unintern (asinout); |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 794 | aspath_unintern (as4); |
| 795 | |
paul | 6726f95 | 2006-01-16 12:06:00 +0000 | [diff] [blame] | 796 | aspath_free (asconfeddel); |
| 797 | aspath_free (asstr); |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 798 | stream_reset (s); |
paul | 6726f95 | 2006-01-16 12:06:00 +0000 | [diff] [blame] | 799 | |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 800 | return fails; |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | static void |
| 804 | empty_get_test () |
| 805 | { |
| 806 | struct aspath *as = aspath_empty_get (); |
| 807 | struct test_spec sp = { "", "", 0, 0, 0, 0, 0, 0 }; |
| 808 | |
| 809 | printf ("empty_get_test, as: %s\n",aspath_print (as)); |
| 810 | if (!validate (as, &sp)) |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 811 | printf ("%s\n", OK); |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 812 | else |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 813 | printf ("%s!\n", FAILED); |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 814 | |
| 815 | printf ("\n"); |
paul | 6726f95 | 2006-01-16 12:06:00 +0000 | [diff] [blame] | 816 | |
| 817 | aspath_free (as); |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | /* basic parsing test */ |
| 821 | static void |
| 822 | parse_test (struct test_segment *t) |
| 823 | { |
| 824 | struct aspath *asp; |
| 825 | |
| 826 | printf ("%s: %s\n", t->name, t->desc); |
| 827 | |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 828 | asp = make_aspath (t->asdata, t->len, 0); |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 829 | |
| 830 | printf ("aspath: %s\nvalidating...:\n", aspath_print (asp)); |
| 831 | |
| 832 | if (!validate (asp, &t->sp)) |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 833 | printf (OK "\n"); |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 834 | else |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 835 | printf (FAILED "\n"); |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 836 | |
| 837 | printf ("\n"); |
| 838 | aspath_unintern (asp); |
| 839 | } |
| 840 | |
| 841 | /* prepend testing */ |
Paul Jakma | 5d932f6 | 2006-03-30 13:42:50 +0000 | [diff] [blame] | 842 | static void |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 843 | prepend_test (struct tests *t) |
| 844 | { |
| 845 | struct aspath *asp1, *asp2, *ascratch; |
| 846 | |
| 847 | printf ("prepend %s: %s\n", t->test1->name, t->test1->desc); |
| 848 | printf ("to %s: %s\n", t->test2->name, t->test2->desc); |
| 849 | |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 850 | asp1 = make_aspath (t->test1->asdata, t->test1->len, 0); |
| 851 | asp2 = make_aspath (t->test2->asdata, t->test2->len, 0); |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 852 | |
| 853 | ascratch = aspath_dup (asp2); |
| 854 | aspath_unintern (asp2); |
| 855 | |
| 856 | asp2 = aspath_prepend (asp1, ascratch); |
| 857 | |
| 858 | printf ("aspath: %s\n", aspath_print (asp2)); |
| 859 | |
| 860 | if (!validate (asp2, &t->sp)) |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 861 | printf ("%s\n", OK); |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 862 | else |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 863 | printf ("%s!\n", FAILED); |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 864 | |
| 865 | printf ("\n"); |
| 866 | aspath_unintern (asp1); |
| 867 | aspath_free (asp2); |
| 868 | } |
| 869 | |
| 870 | /* empty-prepend testing */ |
Paul Jakma | 5d932f6 | 2006-03-30 13:42:50 +0000 | [diff] [blame] | 871 | static void |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 872 | empty_prepend_test (struct test_segment *t) |
| 873 | { |
| 874 | struct aspath *asp1, *asp2, *ascratch; |
| 875 | |
| 876 | printf ("empty prepend %s: %s\n", t->name, t->desc); |
| 877 | |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 878 | asp1 = make_aspath (t->asdata, t->len, 0); |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 879 | asp2 = aspath_empty (); |
| 880 | |
| 881 | ascratch = aspath_dup (asp2); |
| 882 | aspath_unintern (asp2); |
| 883 | |
| 884 | asp2 = aspath_prepend (asp1, ascratch); |
| 885 | |
| 886 | printf ("aspath: %s\n", aspath_print (asp2)); |
| 887 | |
| 888 | if (!validate (asp2, &t->sp)) |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 889 | printf (OK "\n"); |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 890 | else |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 891 | printf (FAILED "!\n"); |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 892 | |
| 893 | printf ("\n"); |
| 894 | aspath_unintern (asp1); |
| 895 | aspath_free (asp2); |
| 896 | } |
| 897 | |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 898 | /* as2+as4 reconciliation testing */ |
| 899 | static void |
| 900 | as4_reconcile_test (struct tests *t) |
| 901 | { |
| 902 | struct aspath *asp1, *asp2, *ascratch; |
| 903 | |
| 904 | printf ("reconciling %s:\n %s\n", t->test1->name, t->test1->desc); |
| 905 | printf ("with %s:\n %s\n", t->test2->name, t->test2->desc); |
| 906 | |
| 907 | asp1 = make_aspath (t->test1->asdata, t->test1->len, 0); |
| 908 | asp2 = make_aspath (t->test2->asdata, t->test2->len, 0); |
| 909 | |
| 910 | ascratch = aspath_reconcile_as4 (asp1, asp2); |
| 911 | |
| 912 | if (!validate (ascratch, &t->sp)) |
| 913 | printf (OK "\n"); |
| 914 | else |
| 915 | printf (FAILED "!\n"); |
| 916 | |
| 917 | printf ("\n"); |
| 918 | aspath_unintern (asp1); |
| 919 | aspath_unintern (asp2); |
| 920 | aspath_free (ascratch); |
| 921 | } |
| 922 | |
| 923 | |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 924 | /* aggregation testing */ |
Paul Jakma | 5d932f6 | 2006-03-30 13:42:50 +0000 | [diff] [blame] | 925 | static void |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 926 | aggregate_test (struct tests *t) |
| 927 | { |
| 928 | struct aspath *asp1, *asp2, *ascratch; |
| 929 | |
| 930 | printf ("aggregate %s: %s\n", t->test1->name, t->test1->desc); |
| 931 | printf ("with %s: %s\n", t->test2->name, t->test2->desc); |
| 932 | |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 933 | asp1 = make_aspath (t->test1->asdata, t->test1->len, 0); |
| 934 | asp2 = make_aspath (t->test2->asdata, t->test2->len, 0); |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 935 | |
| 936 | ascratch = aspath_aggregate (asp1, asp2); |
| 937 | |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 938 | if (!validate (ascratch, &t->sp)) |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 939 | printf (OK "\n"); |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 940 | else |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 941 | printf (FAILED "!\n"); |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 942 | |
| 943 | printf ("\n"); |
| 944 | aspath_unintern (asp1); |
| 945 | aspath_unintern (asp2); |
| 946 | aspath_free (ascratch); |
| 947 | /* aspath_unintern (ascratch);*/ |
| 948 | } |
| 949 | |
| 950 | /* cmp_left tests */ |
| 951 | static void |
| 952 | cmp_test () |
| 953 | { |
paul | 84771ee | 2005-10-11 03:48:28 +0000 | [diff] [blame] | 954 | unsigned int i; |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 955 | #define CMP_TESTS_MAX \ |
| 956 | (sizeof(left_compare) / sizeof (struct compare_tests)) |
| 957 | |
| 958 | for (i = 0; i < CMP_TESTS_MAX; i++) |
| 959 | { |
| 960 | struct test_segment *t1 = &test_segments[left_compare[i].test_index1]; |
| 961 | struct test_segment *t2 = &test_segments[left_compare[i].test_index2]; |
| 962 | struct aspath *asp1, *asp2; |
| 963 | |
| 964 | printf ("left cmp %s: %s\n", t1->name, t1->desc); |
| 965 | printf ("and %s: %s\n", t2->name, t2->desc); |
| 966 | |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 967 | asp1 = make_aspath (t1->asdata, t1->len, 0); |
| 968 | asp2 = make_aspath (t2->asdata, t2->len, 0); |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 969 | |
| 970 | if (aspath_cmp_left (asp1, asp2) != left_compare[i].shouldbe_cmp |
| 971 | || aspath_cmp_left (asp2, asp1) != left_compare[i].shouldbe_cmp |
| 972 | || aspath_cmp_left_confed (asp1, asp2) |
| 973 | != left_compare[i].shouldbe_confed |
| 974 | || aspath_cmp_left_confed (asp2, asp1) |
| 975 | != left_compare[i].shouldbe_confed) |
| 976 | { |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 977 | failed++; |
| 978 | printf (FAILED "\n"); |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 979 | printf ("result should be: cmp: %d, confed: %d\n", |
| 980 | left_compare[i].shouldbe_cmp, |
| 981 | left_compare[i].shouldbe_confed); |
| 982 | printf ("got: cmp %d, cmp_confed: %d\n", |
| 983 | aspath_cmp_left (asp1, asp2), |
| 984 | aspath_cmp_left_confed (asp1, asp2)); |
| 985 | printf("path1: %s\npath2: %s\n", aspath_print (asp1), |
| 986 | aspath_print (asp2)); |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 987 | } |
| 988 | else |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 989 | printf (OK "\n"); |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 990 | |
| 991 | printf ("\n"); |
| 992 | aspath_unintern (asp1); |
| 993 | aspath_unintern (asp2); |
| 994 | } |
| 995 | } |
| 996 | |
| 997 | int |
| 998 | main (void) |
| 999 | { |
| 1000 | int i = 0; |
| 1001 | aspath_init(); |
| 1002 | while (test_segments[i].name) |
| 1003 | { |
| 1004 | parse_test (&test_segments[i]); |
| 1005 | empty_prepend_test (&test_segments[i++]); |
| 1006 | } |
| 1007 | |
| 1008 | i = 0; |
| 1009 | while (prepend_tests[i].test1) |
| 1010 | prepend_test (&prepend_tests[i++]); |
| 1011 | |
| 1012 | i = 0; |
| 1013 | while (aggregate_tests[i].test1) |
| 1014 | aggregate_test (&aggregate_tests[i++]); |
| 1015 | |
Paul Jakma | 0b2aa3a | 2007-10-14 22:32:21 +0000 | [diff] [blame] | 1016 | i = 0; |
| 1017 | |
| 1018 | while (reconcile_tests[i].test1) |
| 1019 | as4_reconcile_test (&reconcile_tests[i++]); |
| 1020 | |
| 1021 | i = 0; |
| 1022 | |
paul | 1f377b0 | 2005-09-10 18:00:11 +0000 | [diff] [blame] | 1023 | cmp_test(); |
| 1024 | |
| 1025 | i = 0; |
| 1026 | |
| 1027 | empty_get_test(); |
| 1028 | |
| 1029 | printf ("failures: %d\n", failed); |
| 1030 | printf ("aspath count: %ld\n", aspath_count()); |
| 1031 | |
| 1032 | return (failed + aspath_count()); |
| 1033 | } |