-static int
-api_mpls_table_add_del (vat_main_t * vam)
-{
- unformat_input_t *i = vam->input;
- vl_api_mpls_table_add_del_t *mp;
- u32 table_id = ~0;
- u8 is_add = 1;
- int ret = 0;
-
- /* Parse args required to build the message */
- while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (i, "table %d", &table_id))
- ;
- else if (unformat (i, "del"))
- is_add = 0;
- else if (unformat (i, "add"))
- is_add = 1;
- else
- {
- clib_warning ("parse error '%U'", format_unformat_error, i);
- return -99;
- }
- }
-
- if (~0 == table_id)
- {
- errmsg ("missing table-ID");
- return -99;
- }
-
- /* Construct the API message */
- M (MPLS_TABLE_ADD_DEL, mp);
-
- mp->mt_table.mt_table_id = ntohl (table_id);
- mp->mt_is_add = is_add;
-
- /* send it... */
- S (mp);
-
- /* Wait for a reply... */
- W (ret);
-
- return ret;
-}
-
-static int
-api_mpls_route_add_del (vat_main_t * vam)
-{
- u8 is_add = 1, path_count = 0, is_multipath = 0, is_eos = 0;
- mpls_label_t local_label = MPLS_LABEL_INVALID;
- unformat_input_t *i = vam->input;
- vl_api_mpls_route_add_del_t *mp;
- vl_api_fib_path_t paths[8];
- int count = 1, j;
- f64 before = 0;
-
- /* Parse args required to build the message */
- while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (i, "%d", &local_label))
- ;
- else if (unformat (i, "eos"))
- is_eos = 1;
- else if (unformat (i, "non-eos"))
- is_eos = 0;
- else if (unformat (i, "del"))
- is_add = 0;
- else if (unformat (i, "add"))
- is_add = 1;
- else if (unformat (i, "multipath"))
- is_multipath = 1;
- else if (unformat (i, "count %d", &count))
- ;
- else
- if (unformat
- (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
- {
- path_count++;
- if (8 == path_count)
- {
- errmsg ("max 8 paths");
- return -99;
- }
- }
- else
- {
- clib_warning ("parse error '%U'", format_unformat_error, i);
- return -99;
- }
- }
-
- if (!path_count)
- {
- errmsg ("specify a path; via ...");
- return -99;
- }
-
- if (MPLS_LABEL_INVALID == local_label)
- {
- errmsg ("missing label");
- return -99;
- }
-
- if (count > 1)
- {
- /* Turn on async mode */
- vam->async_mode = 1;
- vam->async_errors = 0;
- before = vat_time_now (vam);
- }
-
- for (j = 0; j < count; j++)
- {
- /* Construct the API message */
- M2 (MPLS_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
-
- mp->mr_is_add = is_add;
- mp->mr_is_multipath = is_multipath;
-
- mp->mr_route.mr_label = local_label;
- mp->mr_route.mr_eos = is_eos;
- mp->mr_route.mr_table_id = 0;
- mp->mr_route.mr_n_paths = path_count;
-
- clib_memcpy (&mp->mr_route.mr_paths, paths,
- sizeof (paths[0]) * path_count);
-
- local_label++;
-
- /* send it... */
- S (mp);
- /* If we receive SIGTERM, stop now... */
- if (vam->do_exit)
- break;
- }
-
- /* When testing multiple add/del ops, use a control-ping to sync */
- if (count > 1)
- {
- vl_api_control_ping_t *mp_ping;
- f64 after;
- f64 timeout;
-
- /* Shut off async mode */
- vam->async_mode = 0;
-
- MPING (CONTROL_PING, mp_ping);
- S (mp_ping);
-
- timeout = vat_time_now (vam) + 1.0;
- while (vat_time_now (vam) < timeout)
- if (vam->result_ready == 1)
- goto out;
- vam->retval = -99;
-
- out:
- if (vam->retval == -99)
- errmsg ("timeout");
-
- if (vam->async_errors > 0)
- {
- errmsg ("%d asynchronous errors", vam->async_errors);
- vam->retval = -98;
- }
- vam->async_errors = 0;
- after = vat_time_now (vam);
-
- /* slim chance, but we might have eaten SIGTERM on the first iteration */
- if (j > 0)
- count = j;
-
- print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
- count, after - before, count / (after - before));
- }
- else
- {
- int ret;
-
- /* Wait for a reply... */
- W (ret);
- return ret;
- }
-
- /* Return the good/bad news */
- return (vam->retval);
- return (0);
-}
-
-static int
-api_mpls_ip_bind_unbind (vat_main_t * vam)
-{
- unformat_input_t *i = vam->input;
- vl_api_mpls_ip_bind_unbind_t *mp;
- u32 ip_table_id = 0;
- u8 is_bind = 1;
- vl_api_prefix_t pfx;
- u8 prefix_set = 0;
- mpls_label_t local_label = MPLS_LABEL_INVALID;
- int ret;
-
- /* Parse args required to build the message */
- while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
- prefix_set = 1;
- else if (unformat (i, "%d", &local_label))
- ;
- else if (unformat (i, "table-id %d", &ip_table_id))
- ;
- else if (unformat (i, "unbind"))
- is_bind = 0;
- else if (unformat (i, "bind"))
- is_bind = 1;
- else
- {
- clib_warning ("parse error '%U'", format_unformat_error, i);
- return -99;
- }
- }
-
- if (!prefix_set)
- {
- errmsg ("IP prefix not set");
- return -99;
- }
-
- if (MPLS_LABEL_INVALID == local_label)
- {
- errmsg ("missing label");
- return -99;
- }
-
- /* Construct the API message */
- M (MPLS_IP_BIND_UNBIND, mp);
-
- mp->mb_is_bind = is_bind;
- mp->mb_ip_table_id = ntohl (ip_table_id);
- mp->mb_mpls_table_id = 0;
- mp->mb_label = ntohl (local_label);
- clib_memcpy (&mp->mb_prefix, &pfx, sizeof (pfx));
-
- /* send it... */
- S (mp);
-
- /* Wait for a reply... */
- W (ret);
- return ret;
- return (0);
-}
-
-static int
-api_mpls_tunnel_add_del (vat_main_t * vam)
-{
- unformat_input_t *i = vam->input;
- vl_api_mpls_tunnel_add_del_t *mp;
-
- vl_api_fib_path_t paths[8];
- u32 sw_if_index = ~0;
- u8 path_count = 0;
- u8 l2_only = 0;
- u8 is_add = 1;
- int ret;
-
- while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
- {
- if (unformat (i, "add"))
- is_add = 1;
- else
- if (unformat
- (i, "del %U", api_unformat_sw_if_index, vam, &sw_if_index))
- is_add = 0;
- else if (unformat (i, "del sw_if_index %d", &sw_if_index))
- is_add = 0;
- else if (unformat (i, "l2-only"))
- l2_only = 1;
- else
- if (unformat
- (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
- {
- path_count++;
- if (8 == path_count)
- {
- errmsg ("max 8 paths");
- return -99;
- }
- }
- else
- {
- clib_warning ("parse error '%U'", format_unformat_error, i);
- return -99;
- }
- }
-
- M2 (MPLS_TUNNEL_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
-
- mp->mt_is_add = is_add;
- mp->mt_tunnel.mt_sw_if_index = ntohl (sw_if_index);
- mp->mt_tunnel.mt_l2_only = l2_only;
- mp->mt_tunnel.mt_is_multicast = 0;
- mp->mt_tunnel.mt_n_paths = path_count;
-
- clib_memcpy (&mp->mt_tunnel.mt_paths, &paths,
- sizeof (paths[0]) * path_count);
-
- S (mp);
- W (ret);
- return ret;
-}
-