]> git.proxmox.com Git - mirror_frr.git/blobdiff - tests/bgpd/test_ecommunity.c
*: reindent
[mirror_frr.git] / tests / bgpd / test_ecommunity.c
index 564d4712961174fa65377f49f26f1c9b8793fb43..3de8a9fc72d391169e6691dc5385d71533f8f638 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
  * Copyright (C) 2007 Sun Microsystems, Inc.
  *
  * This file is part of Quagga.
@@ -36,127 +36,114 @@ struct thread_master *master = NULL;
 static int failed = 0;
 
 /* specification for a test - what the results should be */
-struct test_spec 
-{
-  const char *shouldbe; /* the string the path should parse to */
+struct test_spec {
+       const char *shouldbe; /* the string the path should parse to */
 };
 
 
 /* test segments to parse and validate, and use for other tests */
 static struct test_segment {
-  const char *name;
-  const char *desc;
-  const u_int8_t data[1024];
-  int len;
-  struct test_spec sp;
-} test_segments [] = 
-{
-  { /* 0 */
-    "ipaddr",
-    "rt 1.2.3.4:257",
-    { ECOMMUNITY_ENCODE_IP, ECOMMUNITY_ROUTE_TARGET,
-      0x1,0x2,0x3,0x4, 0x1,0x1 },
-    8,
-    { "rt 1.2.3.4:257" }
-  },
-  { /* 1 */
-    "ipaddr-so",
-    "soo 1.2.3.4:257",
-    { ECOMMUNITY_ENCODE_IP, ECOMMUNITY_SITE_ORIGIN,
-      0x1,0x2,0x3,0x4, 0x1,0x1},
-    8,
-    { "soo 1.2.3.4:257" }
-  },
-  { /* 2 */
-    "asn",
-    "rt 23456:987654321",
-    { ECOMMUNITY_ENCODE_AS, ECOMMUNITY_SITE_ORIGIN,
-      0x5b,0xa0,       0x3a,0xde,0x68,0xb1 },
-    8,
-    { "soo 23456:987654321" }
-  },
-  { /* 3 */
-    "asn4",
-    "rt 168450976:4321",
-    { ECOMMUNITY_ENCODE_AS4, ECOMMUNITY_SITE_ORIGIN,
-      0xa,0xa,0x5b,0xa0,       0x10,0xe1 },
-    8,
-    { "soo 168450976:4321" }
-  },
-  { NULL, NULL, {0}, 0, { NULL } }
-};
+       const char *name;
+       const char *desc;
+       const u_int8_t data[1024];
+       int len;
+       struct test_spec sp;
+} test_segments[] = {{/* 0 */
+                     "ipaddr",
+                     "rt 1.2.3.4:257",
+                     {ECOMMUNITY_ENCODE_IP, ECOMMUNITY_ROUTE_TARGET, 0x1, 0x2,
+                      0x3, 0x4, 0x1, 0x1},
+                     8,
+                     {"rt 1.2.3.4:257"}},
+                    {/* 1 */
+                     "ipaddr-so",
+                     "soo 1.2.3.4:257",
+                     {ECOMMUNITY_ENCODE_IP, ECOMMUNITY_SITE_ORIGIN, 0x1, 0x2,
+                      0x3, 0x4, 0x1, 0x1},
+                     8,
+                     {"soo 1.2.3.4:257"}},
+                    {/* 2 */
+                     "asn",
+                     "rt 23456:987654321",
+                     {ECOMMUNITY_ENCODE_AS, ECOMMUNITY_SITE_ORIGIN, 0x5b, 0xa0,
+                      0x3a, 0xde, 0x68, 0xb1},
+                     8,
+                     {"soo 23456:987654321"}},
+                    {/* 3 */
+                     "asn4",
+                     "rt 168450976:4321",
+                     {ECOMMUNITY_ENCODE_AS4, ECOMMUNITY_SITE_ORIGIN, 0xa, 0xa,
+                      0x5b, 0xa0, 0x10, 0xe1},
+                     8,
+                     {"soo 168450976:4321"}},
+                    {NULL, NULL, {0}, 0, {NULL}}};
 
 
 /* validate the given aspath */
-static int
-validate (struct ecommunity *ecom, const struct test_spec *sp)
+static int validate(struct ecommunity *ecom, const struct test_spec *sp)
 {
-  int fails = 0;
-  struct ecommunity *etmp;
-  char *str1, *str2;
-    
-  printf ("got:\n  %s\n", ecommunity_str (ecom));
-  str1 = ecommunity_ecom2str (ecom, ECOMMUNITY_FORMAT_COMMUNITY_LIST, 0);
-  etmp = ecommunity_str2com (str1, 0, 1);
-  if (etmp)
-    str2 = ecommunity_ecom2str (etmp, ECOMMUNITY_FORMAT_COMMUNITY_LIST, 0);
-  else
-    str2 = NULL;
-  
-  if (strcmp (sp->shouldbe, str1))
-    {
-      failed++;
-      fails++;
-      printf ("shouldbe: %s\n%s\n", str1, sp->shouldbe);
-    }
-  if (!etmp || strcmp (str1, str2))
-    {
-      failed++;
-      fails++;
-      printf ("dogfood: in %s\n"
-              "    in->out %s\n",
-              str1, 
-              (etmp && str2) ? str2 : "NULL");
-    }
-  ecommunity_free (&etmp);
-  XFREE (MTYPE_ECOMMUNITY_STR, str1);
-  XFREE (MTYPE_ECOMMUNITY_STR, str2);
-  
-  return fails;
+       int fails = 0;
+       struct ecommunity *etmp;
+       char *str1, *str2;
+
+       printf("got:\n  %s\n", ecommunity_str(ecom));
+       str1 = ecommunity_ecom2str(ecom, ECOMMUNITY_FORMAT_COMMUNITY_LIST, 0);
+       etmp = ecommunity_str2com(str1, 0, 1);
+       if (etmp)
+               str2 = ecommunity_ecom2str(etmp,
+                                          ECOMMUNITY_FORMAT_COMMUNITY_LIST, 0);
+       else
+               str2 = NULL;
+
+       if (strcmp(sp->shouldbe, str1)) {
+               failed++;
+               fails++;
+               printf("shouldbe: %s\n%s\n", str1, sp->shouldbe);
+       }
+       if (!etmp || strcmp(str1, str2)) {
+               failed++;
+               fails++;
+               printf("dogfood: in %s\n"
+                      "    in->out %s\n",
+                      str1, (etmp && str2) ? str2 : "NULL");
+       }
+       ecommunity_free(&etmp);
+       XFREE(MTYPE_ECOMMUNITY_STR, str1);
+       XFREE(MTYPE_ECOMMUNITY_STR, str2);
+
+       return fails;
 }
 
 /* basic parsing test */
-static void
-parse_test (struct test_segment *t)
+static void parse_test(struct test_segment *t)
 {
-  struct ecommunity *ecom;
-  
-  printf ("%s: %s\n", t->name, t->desc);
+       struct ecommunity *ecom;
+
+       printf("%s: %s\n", t->name, t->desc);
+
+       ecom = ecommunity_parse((u_int8_t *)t->data, t->len);
 
-  ecom = ecommunity_parse ((u_int8_t *)t->data, t->len);
+       printf("ecom: %s\nvalidating...:\n", ecommunity_str(ecom));
 
-  printf ("ecom: %s\nvalidating...:\n", ecommunity_str (ecom));
+       if (!validate(ecom, &t->sp))
+               printf("OK\n");
+       else
+               printf("failed\n");
 
-  if (!validate (ecom, &t->sp))
-    printf ("OK\n");
-  else
-    printf ("failed\n");
-  
-  printf ("\n");
-  ecommunity_unintern (&ecom);
+       printf("\n");
+       ecommunity_unintern(&ecom);
 }
 
-     
-int
-main (void)
+
+int main(void)
 {
-  int i = 0;
-  ecommunity_init();
-  while (test_segments[i].name)
-    parse_test (&test_segments[i++]);
-  
-  printf ("failures: %d\n", failed);
-  //printf ("aspath count: %ld\n", aspath_count());
-  return failed;
-  //return (failed + aspath_count());
+       int i = 0;
+       ecommunity_init();
+       while (test_segments[i].name)
+               parse_test(&test_segments[i++]);
+
+       printf("failures: %d\n", failed);
+       // printf ("aspath count: %ld\n", aspath_count());
+       return failed;
+       // return (failed + aspath_count());
 }