Diff for /embedaddon/quagga/tests/aspath_test.c between versions 1.1.1.1 and 1.1.1.3

version 1.1.1.1, 2012/02/21 17:26:11 version 1.1.1.3, 2016/11/02 10:09:12
Line 1 Line 1
   /* 
    * Copyright (C) 2005 Sun Microsystems, Inc.
    *
    * This file is part of Quagga.
    *
    * Quagga is free software; you can redistribute it and/or modify it
    * under the terms of the GNU General Public License as published by the
    * Free Software Foundation; either version 2, or (at your option) any
    * later version.
    *
    * Quagga is distributed in the hope that it will be useful, but
    * WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    * General Public License for more details.
    *
    * You should have received a copy of the GNU General Public License
    * along with Quagga; see the file COPYING.  If not, write to the Free
    * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
    * 02111-1307, USA.  
    */
   
 #include <zebra.h>  #include <zebra.h>
   
 #include "vty.h"  #include "vty.h"
 #include "stream.h"  #include "stream.h"
 #include "privs.h"  #include "privs.h"
   #include "filter.h"
   
 #include "bgpd/bgpd.h"  #include "bgpd/bgpd.h"
 #include "bgpd/bgp_aspath.h"  #include "bgpd/bgp_aspath.h"
Line 432  static struct test_segment { Line 454  static struct test_segment {
   },  { NULL, NULL, {0}, 0, { NULL, 0, 0 } }    },  { NULL, NULL, {0}, 0, { NULL, 0, 0 } }
 };  };
   
   #define COMMON_ATTRS \
         BGP_ATTR_FLAG_TRANS, \
         BGP_ATTR_ORIGIN, \
         1, \
         BGP_ORIGIN_EGP, \
         BGP_ATTR_FLAG_TRANS, \
         BGP_ATTR_NEXT_HOP, \
         4, 192, 0, 2, 0
   #define COMMON_ATTR_SIZE 11
   
 /* */  /* */
 static struct aspath_tests {  static struct aspath_tests {
   const char *desc;    const char *desc;
Line 443  static struct aspath_tests { Line 475  static struct aspath_tests {
   const int cap;        /* capabilities to set for peer */    const int cap;        /* capabilities to set for peer */
   const char attrheader [1024];    const char attrheader [1024];
   size_t len;    size_t len;
     const struct test_segment *old_segment;
 } aspath_tests [] =  } aspath_tests [] =
 {  {
   /* 0 */    /* 0 */
Line 452  static struct aspath_tests { Line 485  static struct aspath_tests {
     "8466 3 52737 4096",      "8466 3 52737 4096",
     AS2_DATA, 0,      AS2_DATA, 0,
     0,      0,
    { BGP_ATTR_FLAG_TRANS,    { COMMON_ATTRS,
      BGP_ATTR_AS_PATH,       BGP_ATTR_FLAG_TRANS,
       BGP_ATTR_AS_PATH,
       10,        10,
     },      },
    3,    COMMON_ATTR_SIZE + 3,
   },    },
   /* 1 */    /* 1 */
   {    {
Line 465  static struct aspath_tests { Line 499  static struct aspath_tests {
     "8466 3 52737 4096",      "8466 3 52737 4096",
     AS2_DATA, -1,      AS2_DATA, -1,
     0,      0,
    { BGP_ATTR_FLAG_TRANS,    { COMMON_ATTRS,
       BGP_ATTR_FLAG_TRANS,
       BGP_ATTR_AS_PATH,         BGP_ATTR_AS_PATH, 
       8,        8,
     },      },
    3,    COMMON_ATTR_SIZE + 3,
   },    },
   /* 2 */    /* 2 */
   {    {
Line 478  static struct aspath_tests { Line 513  static struct aspath_tests {
     "8466 3 52737 4096",      "8466 3 52737 4096",
     AS2_DATA, -1,      AS2_DATA, -1,
     0,      0,
    { BGP_ATTR_FLAG_TRANS,    { COMMON_ATTRS,
       BGP_ATTR_FLAG_TRANS,
       BGP_ATTR_AS_PATH,         BGP_ATTR_AS_PATH, 
       12,        12,
     },      },
    3,    COMMON_ATTR_SIZE + 3,
   },    },
   /* 3 */    /* 3 */
   {    {
Line 491  static struct aspath_tests { Line 527  static struct aspath_tests {
     "8466 3 52737 4096",      "8466 3 52737 4096",
     AS2_DATA, -1,      AS2_DATA, -1,
     0,      0,
    { BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL,    { COMMON_ATTRS,
       BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL,
       BGP_ATTR_AS_PATH,         BGP_ATTR_AS_PATH, 
       10,        10,
     },      },
    3,    COMMON_ATTR_SIZE + 3,
   },    },
   /* 4 */    /* 4 */
   {    {
Line 504  static struct aspath_tests { Line 541  static struct aspath_tests {
     "8466 3 52737 4096",      "8466 3 52737 4096",
     AS2_DATA, -1,      AS2_DATA, -1,
     0,      0,
    { BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL,    { COMMON_ATTRS,
       BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL,
       BGP_ATTR_AS4_PATH,         BGP_ATTR_AS4_PATH, 
       10,        10,
     },      },
    3,    COMMON_ATTR_SIZE + 3,
   },    },
   /* 5 */    /* 5 */
   {    {
Line 517  static struct aspath_tests { Line 555  static struct aspath_tests {
     "8466 3 52737 4096",      "8466 3 52737 4096",
     AS4_DATA, -1,      AS4_DATA, -1,
     PEER_CAP_AS4_RCV,      PEER_CAP_AS4_RCV,
    { BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL,    { COMMON_ATTRS,
       BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL,
       BGP_ATTR_AS4_PATH,         BGP_ATTR_AS4_PATH, 
       10,        10,
     },      },
    3,    COMMON_ATTR_SIZE + 3,
   },    },
   /* 6 */    /* 6 */
   {    {
Line 530  static struct aspath_tests { Line 569  static struct aspath_tests {
     "8466 3 52737 4096",      "8466 3 52737 4096",
     AS4_DATA, 0,      AS4_DATA, 0,
     PEER_CAP_AS4_RCV|PEER_CAP_AS4_ADV,      PEER_CAP_AS4_RCV|PEER_CAP_AS4_ADV,
    { BGP_ATTR_FLAG_TRANS,    { COMMON_ATTRS,
       BGP_ATTR_FLAG_TRANS,
       BGP_ATTR_AS_PATH,         BGP_ATTR_AS_PATH, 
       18,        18,
     },      },
    3,    COMMON_ATTR_SIZE + 3,
   },    },
   /* 7 */    /* 7 */
   {    {
Line 543  static struct aspath_tests { Line 583  static struct aspath_tests {
     "8466 3 52737 4096",      "8466 3 52737 4096",
     AS4_DATA, -1,      AS4_DATA, -1,
     PEER_CAP_AS4_RCV|PEER_CAP_AS4_ADV,      PEER_CAP_AS4_RCV|PEER_CAP_AS4_ADV,
    { BGP_ATTR_FLAG_TRANS,    { COMMON_ATTRS,
       BGP_ATTR_FLAG_TRANS,
       BGP_ATTR_AS_PATH,         BGP_ATTR_AS_PATH, 
       16,        16,
     },      },
    3,    COMMON_ATTR_SIZE + 3,
   },    },
   /* 8 */    /* 8 */
   {    {
Line 556  static struct aspath_tests { Line 597  static struct aspath_tests {
     "8466 3 52737 4096",      "8466 3 52737 4096",
     AS4_DATA, -1,      AS4_DATA, -1,
     PEER_CAP_AS4_RCV|PEER_CAP_AS4_ADV,      PEER_CAP_AS4_RCV|PEER_CAP_AS4_ADV,
    { BGP_ATTR_FLAG_TRANS,    { COMMON_ATTRS,
       BGP_ATTR_FLAG_TRANS,
       BGP_ATTR_AS_PATH,         BGP_ATTR_AS_PATH, 
       20,        20,
     },      },
    3,    COMMON_ATTR_SIZE + 3,
   },    },
   /* 9 */    /* 9 */
   {    {
Line 569  static struct aspath_tests { Line 611  static struct aspath_tests {
     "8466 3 52737 4096",      "8466 3 52737 4096",
     AS4_DATA, -1,      AS4_DATA, -1,
     PEER_CAP_AS4_RCV|PEER_CAP_AS4_ADV,      PEER_CAP_AS4_RCV|PEER_CAP_AS4_ADV,
    { BGP_ATTR_FLAG_TRANS,    { COMMON_ATTRS,
       BGP_ATTR_FLAG_TRANS,
       BGP_ATTR_AS_PATH,         BGP_ATTR_AS_PATH, 
       22,        22,
     },      },
    3,    COMMON_ATTR_SIZE + 3,
   },    },
   /* 10 */    /* 10 */
   {    {
Line 582  static struct aspath_tests { Line 625  static struct aspath_tests {
     "8466 3 52737 4096",      "8466 3 52737 4096",
     AS4_DATA, -1,      AS4_DATA, -1,
     PEER_CAP_AS4_RCV|PEER_CAP_AS4_ADV,      PEER_CAP_AS4_RCV|PEER_CAP_AS4_ADV,
    { BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL,    { COMMON_ATTRS,
       BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL,
       BGP_ATTR_AS_PATH,         BGP_ATTR_AS_PATH, 
       18,        18,
     },      },
    3,    COMMON_ATTR_SIZE + 3,
   },    },
   /* 11 */    /* 11 */
   {    {
    "4b AS_PATH: confed",    "4b AS4_PATH w/o AS_PATH",
     &test_segments[6],      &test_segments[6],
    "8466 3 52737 4096",    NULL,
     AS4_DATA, -1,      AS4_DATA, -1,
     PEER_CAP_AS4_ADV,      PEER_CAP_AS4_ADV,
    { BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL,    { COMMON_ATTRS,
       BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL,
       BGP_ATTR_AS4_PATH,         BGP_ATTR_AS4_PATH, 
       14,        14,
     },      },
    3,    COMMON_ATTR_SIZE + 3,
   },    },
     /* 12 */
     {
       "4b AS4_PATH: confed",
       &test_segments[6],
       "8466 3 52737 4096 (123 456 789)",
       AS4_DATA, 0,
       PEER_CAP_AS4_ADV,
       { COMMON_ATTRS,
         BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL,
         BGP_ATTR_AS4_PATH, 
         14,
       },
       COMMON_ATTR_SIZE + 3,
       &test_segments[0],
     },
   { NULL, NULL, NULL, 0, 0, 0, { 0 }, 0 },    { NULL, NULL, NULL, 0, 0, 0, { 0 }, 0 },
 };  };
   
Line 983  validate (struct aspath *as, const struct test_spec *s Line 1043  validate (struct aspath *as, const struct test_spec *s
       printf ("private check: %d %d\n", sp->private_as,        printf ("private check: %d %d\n", sp->private_as,
               aspath_private_as_check (as));                aspath_private_as_check (as));
     }      }
  aspath_unintern (asinout);  aspath_unintern (&asinout);
  aspath_unintern (as4);  aspath_unintern (&as4);
       
   aspath_free (asconfeddel);    aspath_free (asconfeddel);
   aspath_free (asstr);    aspath_free (asstr);
Line 1030  parse_test (struct test_segment *t) Line 1090  parse_test (struct test_segment *t)
   printf ("\n");    printf ("\n");
       
   if (asp)    if (asp)
    aspath_unintern (asp);    aspath_unintern (&asp);
 }  }
   
 /* prepend testing */  /* prepend testing */
Line 1046  prepend_test (struct tests *t) Line 1106  prepend_test (struct tests *t)
   asp2 = make_aspath (t->test2->asdata, t->test2->len, 0);    asp2 = make_aspath (t->test2->asdata, t->test2->len, 0);
       
   ascratch = aspath_dup (asp2);    ascratch = aspath_dup (asp2);
  aspath_unintern (asp2);  aspath_unintern (&asp2);
       
   asp2 = aspath_prepend (asp1, ascratch);    asp2 = aspath_prepend (asp1, ascratch);
       
Line 1058  prepend_test (struct tests *t) Line 1118  prepend_test (struct tests *t)
     printf ("%s!\n", FAILED);      printf ("%s!\n", FAILED);
       
   printf ("\n");    printf ("\n");
  aspath_unintern (asp1);  aspath_unintern (&asp1);
   aspath_free (asp2);    aspath_free (asp2);
 }  }
   
Line 1074  empty_prepend_test (struct test_segment *t) Line 1134  empty_prepend_test (struct test_segment *t)
   asp2 = aspath_empty ();    asp2 = aspath_empty ();
       
   ascratch = aspath_dup (asp2);    ascratch = aspath_dup (asp2);
  aspath_unintern (asp2);  aspath_unintern (&asp2);
       
   asp2 = aspath_prepend (asp1, ascratch);    asp2 = aspath_prepend (asp1, ascratch);
       
Line 1087  empty_prepend_test (struct test_segment *t) Line 1147  empty_prepend_test (struct test_segment *t)
       
   printf ("\n");    printf ("\n");
   if (asp1)    if (asp1)
    aspath_unintern (asp1);    aspath_unintern (&asp1);
   aspath_free (asp2);    aspath_free (asp2);
 }  }
   
Line 1111  as4_reconcile_test (struct tests *t) Line 1171  as4_reconcile_test (struct tests *t)
     printf (FAILED "!\n");      printf (FAILED "!\n");
       
   printf ("\n");    printf ("\n");
  aspath_unintern (asp1);  aspath_unintern (&asp1);
  aspath_unintern (asp2);  aspath_unintern (&asp2);
   aspath_free (ascratch);    aspath_free (ascratch);
 }  }
   
Line 1137  aggregate_test (struct tests *t) Line 1197  aggregate_test (struct tests *t)
     printf (FAILED "!\n");      printf (FAILED "!\n");
       
   printf ("\n");    printf ("\n");
  aspath_unintern (asp1);  aspath_unintern (&asp1);
  aspath_unintern (asp2);  aspath_unintern (&asp2);
   aspath_free (ascratch);    aspath_free (ascratch);
 /*  aspath_unintern (ascratch);*/  /*  aspath_unintern (ascratch);*/
 }  }
Line 1185  cmp_test () Line 1245  cmp_test ()
         printf (OK "\n");          printf (OK "\n");
               
       printf ("\n");        printf ("\n");
      aspath_unintern (asp1);      aspath_unintern (&asp1);
      aspath_unintern (asp2);      aspath_unintern (&asp2);
     }      }
 }  }
   
Line 1212  handle_attr_test (struct aspath_tests *t) Line 1272  handle_attr_test (struct aspath_tests *t)
       
   stream_write (peer.ibuf, t->attrheader, t->len);    stream_write (peer.ibuf, t->attrheader, t->len);
   datalen = aspath_put (peer.ibuf, asp, t->as4 == AS4_DATA);    datalen = aspath_put (peer.ibuf, asp, t->as4 == AS4_DATA);
     if (t->old_segment)
       {
         char dummyaspath[] = { BGP_ATTR_FLAG_TRANS, BGP_ATTR_AS_PATH,
                                t->old_segment->len };
         stream_write (peer.ibuf, dummyaspath, sizeof (dummyaspath));
         stream_write (peer.ibuf, t->old_segment->asdata, t->old_segment->len);
         datalen += sizeof (dummyaspath) + t->old_segment->len;
       }
       
   ret = bgp_attr_parse (&peer, &attr, t->len + datalen, NULL, NULL);    ret = bgp_attr_parse (&peer, &attr, t->len + datalen, NULL, NULL);
       
   if (ret != t->result)    if (ret != t->result)
     {      {
       printf ("bgp_attr_parse returned %d, expected %d\n", ret, t->result);        printf ("bgp_attr_parse returned %d, expected %d\n", ret, t->result);
      printf ("datalen %d\n", datalen);      printf ("datalen %zd\n", datalen);
       failed++;        failed++;
     }      }
   if (ret != 0)    if (ret != 0)
     goto out;      goto out;
       
  if (attr.aspath == NULL)  if (t->shouldbe && attr.aspath == NULL)
     {      {
      printf ("aspath is NULL!\n");      printf ("aspath is NULL, but should be: %s\n", t->shouldbe);
       failed++;        failed++;
     }      }
  if (attr.aspath && strcmp (attr.aspath->str, t->shouldbe))  if (t->shouldbe && attr.aspath && strcmp (attr.aspath->str, t->shouldbe))
     {      {
       printf ("attr str and 'shouldbe' mismatched!\n"        printf ("attr str and 'shouldbe' mismatched!\n"
               "attr str:  %s\n"                "attr str:  %s\n"
Line 1237  handle_attr_test (struct aspath_tests *t) Line 1305  handle_attr_test (struct aspath_tests *t)
               attr.aspath->str, t->shouldbe);                attr.aspath->str, t->shouldbe);
       failed++;        failed++;
     }      }
     if (!t->shouldbe && attr.aspath)
       {
         printf ("aspath should be NULL, but is: %s\n", attr.aspath->str);
         failed++;
       }
   
 out:  out:
   if (attr.aspath)    if (attr.aspath)
    aspath_unintern (attr.aspath);    aspath_unintern (&attr.aspath);
   if (asp)    if (asp)
    aspath_unintern (asp);    aspath_unintern (&asp);
   return failed - initfail;    return failed - initfail;
 }  }
   
Line 1259  main (void) Line 1332  main (void)
   int i = 0;    int i = 0;
   bgp_master_init ();    bgp_master_init ();
   master = bm->master;    master = bm->master;
     bgp_option_set (BGP_OPT_NO_LISTEN);
   bgp_attr_init ();    bgp_attr_init ();
       
   while (test_segments[i].name)    while (test_segments[i].name)

Removed from v.1.1.1.1  
changed lines
  Added in v.1.1.1.3


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>