Filip Tehlar | 850024b | 2021-09-02 10:32:40 +0000 | [diff] [blame] | 1 | /* |
| 2 | *------------------------------------------------------------------ |
| 3 | * Copyright (c) 2021 Cisco and/or its affiliates. |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at: |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | *------------------------------------------------------------------ |
| 16 | */ |
| 17 | #include <vat/vat.h> |
| 18 | #include <vlibapi/api.h> |
| 19 | #include <vlibmemory/api.h> |
| 20 | #include <vppinfra/error.h> |
| 21 | #include <vpp/api/types.h> |
| 22 | |
| 23 | #define __plugin_msg_base sr_mpls_test_main.msg_id_base |
| 24 | #include <vlibapi/vat_helper_macros.h> |
| 25 | |
| 26 | /* Declare message IDs */ |
| 27 | #include <vnet/format_fns.h> |
| 28 | #include <vnet/srmpls/sr_mpls.api_enum.h> |
| 29 | #include <vnet/srmpls/sr_mpls.api_types.h> |
| 30 | |
| 31 | #define vl_endianfun /* define message structures */ |
| 32 | #include <vnet/srmpls/sr_mpls.api.h> |
| 33 | #undef vl_endianfun |
| 34 | |
| 35 | typedef struct |
| 36 | { |
| 37 | /* API message ID base */ |
| 38 | u16 msg_id_base; |
| 39 | u32 ping_id; |
| 40 | vat_main_t *vat_main; |
| 41 | } sr_mpls_test_main_t; |
| 42 | |
| 43 | static sr_mpls_test_main_t sr_mpls_test_main; |
| 44 | |
| 45 | static int |
| 46 | api_sr_mpls_policy_mod (vat_main_t *vam) |
| 47 | { |
| 48 | return -1; |
| 49 | } |
| 50 | |
| 51 | static int |
| 52 | api_sr_mpls_steering_add_del (vat_main_t *vam) |
| 53 | { |
| 54 | return -1; |
| 55 | } |
| 56 | |
| 57 | static int |
| 58 | api_sr_mpls_policy_assign_endpoint_color (vat_main_t *vam) |
| 59 | { |
| 60 | return -1; |
| 61 | } |
| 62 | |
| 63 | static int |
| 64 | api_sr_mpls_policy_add (vat_main_t *vam) |
| 65 | { |
| 66 | unformat_input_t *i = vam->input; |
| 67 | vl_api_sr_mpls_policy_add_t *mp; |
| 68 | u32 bsid = 0; |
| 69 | u32 weight = 1; |
| 70 | u8 type = 0; |
| 71 | u8 n_segments = 0; |
| 72 | u32 sid; |
| 73 | u32 *segments = NULL; |
| 74 | int ret; |
| 75 | |
| 76 | /* Parse args required to build the message */ |
| 77 | while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 78 | { |
| 79 | if (unformat (i, "bsid %d", &bsid)) |
| 80 | ; |
| 81 | else if (unformat (i, "weight %d", &weight)) |
| 82 | ; |
| 83 | else if (unformat (i, "spray")) |
| 84 | type = 1; |
| 85 | else if (unformat (i, "next %d", &sid)) |
| 86 | { |
| 87 | n_segments += 1; |
| 88 | vec_add1 (segments, htonl (sid)); |
| 89 | } |
| 90 | else |
| 91 | { |
| 92 | clib_warning ("parse error '%U'", format_unformat_error, i); |
| 93 | return -99; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | if (bsid == 0) |
| 98 | { |
| 99 | errmsg ("bsid not set"); |
| 100 | return -99; |
| 101 | } |
| 102 | |
| 103 | if (n_segments == 0) |
| 104 | { |
| 105 | errmsg ("no sid in segment stack"); |
| 106 | return -99; |
| 107 | } |
| 108 | |
| 109 | /* Construct the API message */ |
| 110 | M2 (SR_MPLS_POLICY_ADD, mp, sizeof (u32) * n_segments); |
| 111 | |
| 112 | mp->bsid = htonl (bsid); |
| 113 | mp->weight = htonl (weight); |
| 114 | mp->is_spray = type; |
| 115 | mp->n_segments = n_segments; |
| 116 | memcpy (mp->segments, segments, sizeof (u32) * n_segments); |
| 117 | vec_free (segments); |
| 118 | |
| 119 | /* send it... */ |
| 120 | S (mp); |
| 121 | |
| 122 | /* Wait for a reply... */ |
| 123 | W (ret); |
| 124 | return ret; |
| 125 | } |
| 126 | |
| 127 | static int |
| 128 | api_sr_mpls_policy_del (vat_main_t *vam) |
| 129 | { |
| 130 | unformat_input_t *i = vam->input; |
| 131 | vl_api_sr_mpls_policy_del_t *mp; |
| 132 | u32 bsid = 0; |
| 133 | int ret; |
| 134 | |
| 135 | /* Parse args required to build the message */ |
| 136 | while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 137 | { |
| 138 | if (unformat (i, "bsid %d", &bsid)) |
| 139 | ; |
| 140 | else |
| 141 | { |
| 142 | clib_warning ("parse error '%U'", format_unformat_error, i); |
| 143 | return -99; |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | if (bsid == 0) |
| 148 | { |
| 149 | errmsg ("bsid not set"); |
| 150 | return -99; |
| 151 | } |
| 152 | |
| 153 | /* Construct the API message */ |
| 154 | M (SR_MPLS_POLICY_DEL, mp); |
| 155 | |
| 156 | mp->bsid = htonl (bsid); |
| 157 | |
| 158 | /* send it... */ |
| 159 | S (mp); |
| 160 | |
| 161 | /* Wait for a reply... */ |
| 162 | W (ret); |
| 163 | return ret; |
| 164 | } |
| 165 | |
| 166 | #include <vnet/srmpls/sr_mpls.api_test.c> |
| 167 | |
| 168 | /* |
| 169 | * fd.io coding-style-patch-verification: ON |
| 170 | * |
| 171 | * Local Variables: |
| 172 | * eval: (c-set-style "gnu") |
| 173 | * End: |
| 174 | */ |