diff options
| author | Donald Sharp <sharpd@cumulusnetworks.com> | 2015-06-12 07:59:11 -0700 | 
|---|---|---|
| committer | Donald Sharp <sharpd@cumulusnetworks.com> | 2015-06-12 07:59:11 -0700 | 
| commit | c43ed2e48af8c787a1ebc4b648f844c44032db35 (patch) | |
| tree | 24e3abff6f724033ab16418961da91ff1ddd6aee /lib/csv.h | |
| parent | f1aa5d8ac823969694430feec02594c6851e596a (diff) | |
This patch changes BGP from only listening mode for BFD status updates to interactive mode of dynamically registering/deregistering BFD enabled peers with PTM/BFD through zebra. Peer is registered with BFD when it goes into established state and de-registers when it goes out of establish state.
This patch also adds BFD multihop support for BGP. Whether a peer is multi-hop or single hop is determined internally. All IGP peers are considered as multi-hop peers. EBGP peers are considered as single hop unless configured as multi-hop.
BGP BFD command enhancement to configure BFD parameters (detect multiplier, min rx and min tx).
router bgp <as-number>
  neighbor <name/ip-address> bfd <detect mult> <min rx> <min tx>
Signed-off-by: Radhika Mahankali <radhika@cumulusnetworks.com>
Reviewed-by:   Dinesh G Dutt <ddutt@cumulusnetworks.com>
Reviewed-by:   Vipin Kumar <vipin@cumulusnetworks.com>
Reviewed-by:   Kanna Rajagopal <kanna@cumulusnetworks.com>
Diffstat (limited to 'lib/csv.h')
| -rw-r--r-- | lib/csv.h | 172 | 
1 files changed, 172 insertions, 0 deletions
diff --git a/lib/csv.h b/lib/csv.h new file mode 100644 index 0000000000..078f390873 --- /dev/null +++ b/lib/csv.h @@ -0,0 +1,172 @@ +/* Copyright 2013 Cumulus Networks, LLC.  All rights reserved. */ + +#ifndef __CSV_H__ +#define __CSV_H__ + +/* + * CSV encoding and decoding routines. + * + * Example: + * Encoding side: + * + *      csv_t *csv; + *      csv_record_t *fstrec; + *      csv_record_t *rec; + *      char  buf[BUFSIZ]; + * + *      csv = csv_init(csv, buf, BUFSIZ); + *      ... + *      fstrec = csv_encode(csv, 2, "hello", "world"); + *      rec = csv_encode(csv, 2, "foo", "bar"); + *      ... + *      fstrec = csv_encode_record(csv, fstrec, 2, "HELLO", "WORLD"); + *      ... + *      csv_clean(csv); + * + * Decoding side: + * + *      csv_t *csv; + *      csv_record_t *rec; + *      csv_field_t *fld; + *      char  *rcvdbuf; + * + *      csv = csv_init(csv, rcvdbuf, BUFSIZ); + *      ... + *      csv_decode(csv); + *      csv_dump(csv); + * + *      for (rec = csv_record_iter(csv); rec; + *           rec = csv_record_iter_next(rec)) { + *          ... + *          for (str = csv_field_iter(rec, &fld); str; + *               str = csv_field_iter_next(&fld)) { + *              ... + *          } + *      } + *      ... + *      csv_clean(csv); + */ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <stdarg.h> +#include <sys/queue.h> + +typedef struct _csv_field_t_ csv_field_t; +typedef struct _csv_record_t_ csv_record_t; +typedef struct _csv_t_ csv_t; + +/** + * Initialize the CSV structure (if necessary, allocate first). Point to + * the passed string buffer. + */ +csv_t * csv_init(csv_t *csv, char *buf, int buflen); + +/** + * Encode the variable list of arguments as CSV fields. The csv structure + * should have been initialized (with the string buffer). The fields get + * concatenated into the string. + */ +csv_record_t *csv_encode(csv_t *csv, int count, ...); + +/** + * Encode the variable list arguments into an existing record, essentially + * overwriting the record. No checking is done for consistency. The number + * of fields should be the same as what was encoded and the length of each + * field should also be the same as what was encoded before. The "rec" + * parameter should be the same as what was returned from a previous call + * to csv_encode(). + * + * Useful for message encoding/decoding that get passed around between + * processes/nodes - e.g. the message header record can be rewritten AFTER + * encoding all other records, with new information such as total length. + */ +csv_record_t *csv_encode_record(csv_t *csv, csv_record_t *rec, +				int count, ...); + +/** + * Decode a CSV formatted string. The csv structure should have been + * initialized (with the string). The function creates a LIST of records + * (csv_record_t structure) where each record is in turn a LIST of fields + * (csv_field_t structure). The record points to the string containing the + * list of fields. Similarly, the field points to the field string. + * NB: csv initialized for discrete buf , caller will pass inbuf + */ +void csv_decode(csv_t *csv, char *inbuf); + +/** + * Dump all fields of a decoded CSV to stderr + */ +void csv_dump(csv_t *csv); + +/** + * Total length of all characters encoded in the CSV. + */ +int csvlen(csv_t *csv); + +void csv_clean(csv_t *csv); +void csv_free(csv_t *csv); + +/** + * Iterate through the records and fields of an encoded/decoded CSV. + */ +csv_record_t *csv_record_iter(csv_t *csv); +csv_record_t *csv_record_iter_next(csv_record_t *rec); +char *csv_field_iter(csv_record_t *rec, csv_field_t **fld); +char *csv_field_iter_next(csv_field_t **fld); + +/** + * Return the length of field + */ +int csv_field_len(csv_field_t *fld); + +/** + * Checks to see if a record belongs to a csv + */ +int csv_is_record_valid(csv_t *csv, csv_record_t *in_rec); + +/** + * concat two records in a csv + * Returns the newly formed record which includes fields from rec1 and rec2 + * rec1 and rec2 are removed + */ +csv_record_t *csv_concat_record(csv_t *csv, csv_record_t *rec1, +                               csv_record_t *rec2); + +/** + * Remove a record from csv + * Only works when csv has discrete record bufs + */ +void csv_remove_record(csv_t *csv, csv_record_t *rec); + +/** + * Insert a record into csv + * Only works when csv has discrete record bufs + */ +void csv_insert_record(csv_t *csv, csv_record_t *rec); + +/** + * append fields to a record + * Only works when csv has discrete record bufs + */ +csv_record_t * +csv_append_record (csv_t *csv, csv_record_t *rec, int count, ...); + +/** + * Serialize contents of csv into string + * Only works when csv has discrete record bufs + */ +int csv_serialize(csv_t *csv, char *msgbuf, int msglen); + +/** + * Clone a record. + * Only works when csv has discrete record bufs + */ +void csv_clone_record (csv_t *csv, csv_record_t *in_rec, csv_record_t **out_rec); + +/** + * Return number of records + */ +int csv_num_records (csv_t *csv); + +#endif  | 
