Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
Robert Varga | 40223da | 2016-02-10 15:57:23 +0100 | [diff] [blame] | 15 | #define _GNU_SOURCE /* for strcasestr(3) */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 16 | #include <vnet/vnet.h> |
| 17 | |
| 18 | #define vl_api_version(n,v) static u32 vpe_api_version = (v); |
| 19 | #include <api/vpe.api.h> |
| 20 | #undef vl_api_version |
| 21 | |
| 22 | #include <jni.h> |
| 23 | #include <japi/vppjni.h> |
| 24 | #include <japi/vppjni_bridge_domain.h> |
Robert Varga | 81d99ac | 2016-01-30 18:30:36 +0100 | [diff] [blame] | 25 | #include <japi/vppjni_env.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 26 | #include <japi/org_openvpp_vppjapi_vppConn.h> |
| 27 | #include <japi/org_openvpp_vppjapi_vppApi.h> |
| 28 | |
| 29 | #include <api/vpe_msg_enum.h> |
| 30 | #define vl_typedefs /* define message structures */ |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 31 | #include <api/vpe_all_api_h.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 32 | #undef vl_typedefs |
| 33 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 34 | #define vl_endianfun |
| 35 | #include <api/vpe_all_api_h.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 36 | #undef vl_endianfun |
| 37 | |
| 38 | /* instantiate all the print functions we know about */ |
| 39 | #define vl_print(handle, ...) |
| 40 | #define vl_printfun |
| 41 | #include <api/vpe_all_api_h.h> |
| 42 | #undef vl_printfun |
| 43 | |
Dave Wallace | bf8c15e | 2015-12-17 20:54:54 -0500 | [diff] [blame] | 44 | #define VPPJNI_DEBUG 0 |
| 45 | |
| 46 | #if VPPJNI_DEBUG == 1 |
| 47 | #define DEBUG_LOG(...) clib_warning(__VA_ARGS__) |
| 48 | #else |
| 49 | #define DEBUG_LOG(...) |
| 50 | #endif |
| 51 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 52 | static int connect_to_vpe(char *name); |
| 53 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 54 | /* |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 55 | * The Java runtime isn't compile w/ -fstack-protector, |
| 56 | * so we have to supply missing external references for the |
| 57 | * regular vpp libraries. Weak reference in case folks get religion |
| 58 | * at a later date... |
| 59 | */ |
| 60 | void __stack_chk_guard (void) __attribute__((weak)); |
| 61 | void __stack_chk_guard (void) { } |
| 62 | |
Robert Varga | 81d99ac | 2016-01-30 18:30:36 +0100 | [diff] [blame] | 63 | BIND_JAPI_CLASS(vppBridgeDomainDetails, "()V"); |
| 64 | BIND_JAPI_BOOL_FIELD(vppBridgeDomainDetails, arpTerm); |
| 65 | BIND_JAPI_BOOL_FIELD(vppBridgeDomainDetails, flood); |
| 66 | BIND_JAPI_BOOL_FIELD(vppBridgeDomainDetails, forward); |
| 67 | BIND_JAPI_BOOL_FIELD(vppBridgeDomainDetails, learn); |
| 68 | BIND_JAPI_BOOL_FIELD(vppBridgeDomainDetails, uuFlood); |
| 69 | BIND_JAPI_INT_FIELD(vppBridgeDomainDetails, bdId); |
| 70 | BIND_JAPI_STRING_FIELD(vppBridgeDomainDetails, name); |
| 71 | BIND_JAPI_STRING_FIELD(vppBridgeDomainDetails, bviInterfaceName); |
| 72 | BIND_JAPI_OBJ_FIELD(vppBridgeDomainDetails, interfaces, "[Lorg/openvpp/vppjapi/vppBridgeDomainInterfaceDetails;"); |
| 73 | |
| 74 | BIND_JAPI_CLASS(vppBridgeDomainInterfaceDetails, "()V"); |
| 75 | BIND_JAPI_BYTE_FIELD(vppBridgeDomainInterfaceDetails, splitHorizonGroup); |
| 76 | BIND_JAPI_STRING_FIELD(vppBridgeDomainInterfaceDetails, interfaceName); |
| 77 | |
| 78 | BIND_JAPI_CLASS(vppInterfaceCounters, "(JJJJJJJJJJJJJJJJJJJJJJ)V"); |
| 79 | BIND_JAPI_CLASS(vppInterfaceDetails, "(ILjava/lang/String;I[BBBBBIBBIIBBBBIIII)V"); |
| 80 | BIND_JAPI_CLASS(vppIPv4Address, "(IB)V"); |
| 81 | BIND_JAPI_CLASS(vppIPv6Address, "([BB)V"); |
| 82 | BIND_JAPI_CLASS(vppL2Fib, "([BZLjava/lang/String;ZZ)V"); |
| 83 | BIND_JAPI_CLASS(vppVersion, "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); |
| 84 | BIND_JAPI_CLASS(vppVxlanTunnelDetails, "(IIIII)V"); |
| 85 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 86 | void vl_client_add_api_signatures (vl_api_memclnt_create_t *mp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 87 | { |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 88 | /* |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 89 | * Send the main API signature in slot 0. This bit of code must |
| 90 | * match the checks in ../vpe/api/api.c: vl_msg_api_version_check(). |
| 91 | */ |
| 92 | mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version); |
| 93 | } |
| 94 | |
| 95 | /* Note: non-static, called once to set up the initial intfc table */ |
| 96 | static int sw_interface_dump (vppjni_main_t * jm) |
| 97 | { |
| 98 | vl_api_sw_interface_dump_t *mp; |
| 99 | f64 timeout; |
| 100 | hash_pair_t * p; |
| 101 | name_sort_t * nses = 0, * ns; |
| 102 | sw_interface_subif_t * sub = NULL; |
| 103 | |
| 104 | /* Toss the old name table */ |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 105 | hash_foreach_pair (p, jm->sw_if_index_by_interface_name, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 106 | ({ |
| 107 | vec_add2 (nses, ns, 1); |
| 108 | ns->name = (u8 *)(p->key); |
| 109 | ns->value = (u32) p->value[0]; |
| 110 | })); |
| 111 | |
| 112 | hash_free (jm->sw_if_index_by_interface_name); |
| 113 | |
| 114 | vec_foreach (ns, nses) |
| 115 | vec_free (ns->name); |
| 116 | |
| 117 | vec_free (nses); |
| 118 | |
| 119 | vec_foreach (sub, jm->sw_if_subif_table) { |
| 120 | vec_free (sub->interface_name); |
| 121 | } |
| 122 | vec_free (jm->sw_if_subif_table); |
| 123 | |
| 124 | /* recreate the interface name hash table */ |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 125 | jm->sw_if_index_by_interface_name |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 126 | = hash_create_string (0, sizeof(uword)); |
| 127 | |
| 128 | /* Get list of ethernets */ |
| 129 | M(SW_INTERFACE_DUMP, sw_interface_dump); |
| 130 | mp->name_filter_valid = 1; |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 131 | strncpy ((char *) mp->name_filter, "Ether", sizeof(mp->name_filter-1)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 132 | S; |
| 133 | |
| 134 | /* and local / loopback interfaces */ |
| 135 | M(SW_INTERFACE_DUMP, sw_interface_dump); |
| 136 | mp->name_filter_valid = 1; |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 137 | strncpy ((char *) mp->name_filter, "lo", sizeof(mp->name_filter-1)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 138 | S; |
| 139 | |
| 140 | /* and vxlan tunnel interfaces */ |
| 141 | M(SW_INTERFACE_DUMP, sw_interface_dump); |
| 142 | mp->name_filter_valid = 1; |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 143 | strncpy ((char *) mp->name_filter, "vxlan", sizeof(mp->name_filter-1)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 144 | S; |
| 145 | |
| 146 | /* and tap tunnel interfaces */ |
| 147 | M(SW_INTERFACE_DUMP, sw_interface_dump); |
| 148 | mp->name_filter_valid = 1; |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 149 | strncpy ((char *) mp->name_filter, "tap", sizeof(mp->name_filter-1)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 150 | S; |
| 151 | |
| 152 | /* and l2tpv3 tunnel interfaces */ |
| 153 | M(SW_INTERFACE_DUMP, sw_interface_dump); |
| 154 | mp->name_filter_valid = 1; |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 155 | strncpy ((char *) mp->name_filter, "l2tpv3_tunnel", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 156 | sizeof(mp->name_filter-1)); |
| 157 | S; |
| 158 | |
| 159 | /* Use a control ping for synchronization */ |
| 160 | { |
| 161 | vl_api_control_ping_t * mp; |
| 162 | M(CONTROL_PING, control_ping); |
| 163 | S; |
| 164 | } |
| 165 | W; |
| 166 | } |
| 167 | |
Dave Wallace | ba474a2 | 2016-02-09 23:09:41 -0500 | [diff] [blame] | 168 | JNIEXPORT jobject JNICALL Java_org_openvpp_vppjapi_vppConn_getVppVersion0 |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 169 | (JNIEnv *env, jobject obj) |
| 170 | { |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 171 | vppjni_main_t * jm = &vppjni_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 172 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 173 | vppjni_lock (jm, 11); |
| 174 | jstring progName = (*env)->NewStringUTF(env, (char *)jm->program_name); |
| 175 | jstring buildDir = (*env)->NewStringUTF(env, (char *)jm->build_directory); |
| 176 | jstring version = (*env)->NewStringUTF(env, (char *)jm->version); |
| 177 | jstring buildDate = (*env)->NewStringUTF(env, (char *)jm->build_date); |
| 178 | vppjni_unlock (jm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 179 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 180 | return vppVersionObject(env, progName, buildDir, version, buildDate); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | static int jm_show_version (vppjni_main_t *jm) |
| 184 | { |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 185 | int rv; |
| 186 | vl_api_show_version_t *mp; |
| 187 | f64 timeout; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 188 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 189 | vppjni_lock (jm, 10); |
| 190 | M(SHOW_VERSION, show_version); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 191 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 192 | S; |
| 193 | vppjni_unlock (jm); |
| 194 | WNR; |
| 195 | return rv; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | static int jm_stats_enable_disable (vppjni_main_t *jm, u8 enable) |
| 199 | { |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 200 | vl_api_want_stats_t * mp; |
| 201 | f64 timeout; |
| 202 | int rv; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 203 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 204 | vppjni_lock (jm, 13); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 205 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 206 | M(WANT_STATS, want_stats); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 207 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 208 | mp->enable_disable = enable; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 209 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 210 | S; |
| 211 | vppjni_unlock (jm); |
| 212 | WNR; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 213 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 214 | // already subscribed / already disabled (it's ok) |
| 215 | if (rv == -2 || rv == -3) |
| 216 | rv = 0; |
| 217 | return rv; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Dave Wallace | ba474a2 | 2016-02-09 23:09:41 -0500 | [diff] [blame] | 220 | JNIEXPORT jint JNICALL Java_org_openvpp_vppjapi_vppConn_setInterfaceDescription0 |
Dave Wallace | bf8c15e | 2015-12-17 20:54:54 -0500 | [diff] [blame] | 221 | (JNIEnv *env, jobject obj, jstring ifName, jstring ifDesc) |
| 222 | { |
| 223 | int rv = 0; |
| 224 | vppjni_main_t * jm = &vppjni_main; |
| 225 | uword * p; |
| 226 | u32 sw_if_index = ~0; |
| 227 | sw_if_config_t *cfg; |
| 228 | |
| 229 | const char *if_name_str = (*env)->GetStringUTFChars (env, ifName, 0); |
| 230 | const char *if_desc_str = (*env)->GetStringUTFChars (env, ifDesc, 0); |
| 231 | |
| 232 | vppjni_lock (jm, 23); |
| 233 | |
| 234 | p = hash_get_mem (jm->sw_if_index_by_interface_name, if_name_str); |
| 235 | if (p == 0) { |
| 236 | rv = -1; |
| 237 | goto out; |
| 238 | } |
| 239 | sw_if_index = (jint) p[0]; |
| 240 | |
| 241 | u8 *if_desc = 0; |
| 242 | vec_validate_init_c_string (if_desc, if_desc_str, strlen(if_desc_str)); |
| 243 | (*env)->ReleaseStringUTFChars (env, ifDesc, if_desc_str); |
| 244 | |
| 245 | p = hash_get (jm->sw_if_config_by_sw_if_index, sw_if_index); |
| 246 | if (p != 0) { |
| 247 | cfg = (sw_if_config_t *) (p[0]); |
| 248 | if (cfg->desc) |
| 249 | vec_free(cfg->desc); |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 250 | } else { |
Dave Wallace | bf8c15e | 2015-12-17 20:54:54 -0500 | [diff] [blame] | 251 | cfg = (sw_if_config_t *) clib_mem_alloc(sizeof(sw_if_config_t)); |
| 252 | hash_set (jm->sw_if_config_by_sw_if_index, sw_if_index, cfg); |
| 253 | } |
| 254 | |
| 255 | cfg->desc = if_desc; |
| 256 | |
| 257 | out: |
| 258 | (*env)->ReleaseStringUTFChars (env, ifName, if_name_str); |
| 259 | vppjni_unlock (jm); |
| 260 | return rv; |
| 261 | } |
| 262 | |
Dave Wallace | ba474a2 | 2016-02-09 23:09:41 -0500 | [diff] [blame] | 263 | JNIEXPORT jstring JNICALL Java_org_openvpp_vppjapi_vppConn_getInterfaceDescription0 |
Dave Wallace | bf8c15e | 2015-12-17 20:54:54 -0500 | [diff] [blame] | 264 | (JNIEnv * env, jobject obj, jstring ifName) |
| 265 | { |
| 266 | vppjni_main_t * jm = &vppjni_main; |
| 267 | u32 sw_if_index = ~0; |
| 268 | uword * p; |
Dave Wallace | bf8c15e | 2015-12-17 20:54:54 -0500 | [diff] [blame] | 269 | jstring ifDesc = NULL; |
Robert Varga | f0f54d8 | 2016-02-10 16:01:58 +0100 | [diff] [blame] | 270 | const char *if_name_str = (*env)->GetStringUTFChars (env, ifName, 0); |
| 271 | if (!if_name_str) |
| 272 | return NULL; |
Dave Wallace | bf8c15e | 2015-12-17 20:54:54 -0500 | [diff] [blame] | 273 | |
| 274 | vppjni_lock (jm, 24); |
| 275 | p = hash_get_mem (jm->sw_if_index_by_interface_name, if_name_str); |
| 276 | if (p == 0) |
| 277 | goto out; |
| 278 | |
| 279 | sw_if_index = (jint) p[0]; |
| 280 | |
| 281 | p = hash_get (jm->sw_if_config_by_sw_if_index, sw_if_index); |
| 282 | if (p == 0) |
| 283 | goto out; |
| 284 | |
| 285 | sw_if_config_t *cfg = (sw_if_config_t *) (p[0]); |
| 286 | u8 * s = format (0, "%s%c", cfg->desc, 0); |
| 287 | ifDesc = (*env)->NewStringUTF(env, (char *)s); |
| 288 | |
| 289 | out: |
| 290 | vppjni_unlock (jm); |
| 291 | |
| 292 | return ifDesc; |
| 293 | } |
| 294 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 295 | JNIEXPORT jint JNICALL Java_org_openvpp_vppjapi_vppConn_clientConnect |
| 296 | (JNIEnv *env, jobject obj, jstring clientName) |
| 297 | { |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 298 | int rv; |
| 299 | const char *client_name; |
| 300 | void vl_msg_reply_handler_hookup(void); |
| 301 | vppjni_main_t * jm = &vppjni_main; |
| 302 | api_main_t * am = &api_main; |
| 303 | u8 * heap; |
| 304 | mheap_t * h; |
| 305 | f64 timeout; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 306 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 307 | /* |
| 308 | * Bail out now if we're not running as root |
| 309 | */ |
| 310 | if (geteuid() != 0) |
| 311 | return -1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 312 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 313 | if (jm->is_connected) |
| 314 | return -2; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 315 | |
Robert Varga | f0f54d8 | 2016-02-10 16:01:58 +0100 | [diff] [blame] | 316 | client_name = (*env)->GetStringUTFChars(env, clientName, 0); |
| 317 | if (!client_name) |
| 318 | return -3; |
| 319 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 320 | if (jm->heap == 0) |
| 321 | clib_mem_init (0, 128<<20); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 322 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 323 | heap = clib_mem_get_per_cpu_heap(); |
| 324 | h = mheap_header (heap); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 325 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 326 | clib_time_init (&jm->clib_time); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 327 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 328 | rv = connect_to_vpe ((char *) client_name); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 329 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 330 | if (rv < 0) |
| 331 | clib_warning ("connection failed, rv %d", rv); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 332 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 333 | (*env)->ReleaseStringUTFChars (env, clientName, client_name); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 334 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 335 | if (rv == 0) { |
| 336 | vl_msg_reply_handler_hookup (); |
| 337 | jm->is_connected = 1; |
| 338 | /* make the main heap thread-safe */ |
| 339 | h->flags |= MHEAP_FLAG_THREAD_SAFE; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 340 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 341 | jm->reply_hash = hash_create (0, sizeof (uword)); |
| 342 | //jm->callback_hash = hash_create (0, sizeof (uword)); |
| 343 | //jm->ping_hash = hash_create (0, sizeof (uword)); |
| 344 | jm->api_main = am; |
| 345 | vjbd_main_init(&jm->vjbd_main); |
| 346 | jm->sw_if_index_by_interface_name = |
| 347 | hash_create_string (0, sizeof (uword)); |
| 348 | jm->sw_if_config_by_sw_if_index = |
| 349 | hash_create (0, sizeof (uword)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 350 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 351 | { |
| 352 | // call control ping first to attach rx thread to java thread |
| 353 | vl_api_control_ping_t * mp; |
| 354 | M(CONTROL_PING, control_ping); |
| 355 | S; |
| 356 | WNR; |
| 357 | |
| 358 | if (rv != 0) { |
| 359 | clib_warning ("first control ping failed: %d", rv); |
| 360 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 361 | } |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 362 | rv = jm_show_version(jm); |
| 363 | if (rv != 0) |
| 364 | clib_warning ("unable to retrieve vpp version (rv: %d)", rv); |
| 365 | rv = sw_interface_dump(jm); |
| 366 | if (rv != 0) |
| 367 | clib_warning ("unable to retrieve interface list (rv: %d)", rv); |
| 368 | rv = jm_stats_enable_disable(jm, 1); |
| 369 | if (rv != 0) |
| 370 | clib_warning ("unable to subscribe to stats (rv: %d)", rv); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 371 | } |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 372 | DEBUG_LOG ("clientConnect result: %d", rv); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 373 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 374 | return rv; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | JNIEXPORT void JNICALL Java_org_openvpp_vppjapi_vppConn_clientDisconnect |
| 378 | (JNIEnv *env, jobject obj) |
| 379 | { |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 380 | u8 *save_heap; |
| 381 | vppjni_main_t * jm = &vppjni_main; |
| 382 | vl_client_disconnect_from_vlib(); |
| 383 | |
| 384 | save_heap = jm->heap; |
| 385 | memset (jm, 0, sizeof (*jm)); |
| 386 | jm->heap = save_heap; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | void vl_api_generic_reply_handler (vl_api_generic_reply_t *mp) |
| 390 | { |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 391 | api_main_t * am = &api_main; |
| 392 | u16 msg_id = clib_net_to_host_u16 (mp->_vl_msg_id); |
| 393 | trace_cfg_t *cfgp; |
| 394 | i32 retval = clib_net_to_host_u32 (mp->retval); |
| 395 | int total_bytes = sizeof(mp); |
| 396 | vppjni_main_t * jm = &vppjni_main; |
| 397 | u8 * saved_reply = 0; |
| 398 | u32 context = clib_host_to_net_u32 (mp->context); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 399 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 400 | cfgp = am->api_trace_cfg + msg_id; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 401 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 402 | if (!cfgp) |
| 403 | clib_warning ("msg id %d: no trace configuration\n", msg_id); |
| 404 | else |
| 405 | total_bytes = cfgp->size; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 406 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 407 | jm->context_id_received = context; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 408 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 409 | DEBUG_LOG ("Received generic reply for msg id %d", msg_id); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 410 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 411 | /* A generic reply, successful, we're done */ |
| 412 | if (retval >= 0 && total_bytes == sizeof(*mp)) |
| 413 | return; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 414 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 415 | /* Save the reply */ |
| 416 | vec_validate (saved_reply, total_bytes - 1); |
| 417 | memcpy (saved_reply, mp, total_bytes); |
| 418 | |
| 419 | vppjni_lock (jm, 2); |
| 420 | hash_set (jm->reply_hash, context, saved_reply); |
| 421 | jm->saved_reply_count ++; |
| 422 | vppjni_unlock (jm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 423 | } |
| 424 | |
Dave Wallace | ba474a2 | 2016-02-09 23:09:41 -0500 | [diff] [blame] | 425 | JNIEXPORT jint JNICALL Java_org_openvpp_vppjapi_vppConn_getRetval0 |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 426 | (JNIEnv * env, jobject obj, jint context, jint release) |
| 427 | { |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 428 | vppjni_main_t * jm = &vppjni_main; |
| 429 | vl_api_generic_reply_t * mp; |
| 430 | uword * p; |
| 431 | int rv = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 432 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 433 | /* Dunno yet? */ |
| 434 | if (context > jm->context_id_received) |
| 435 | return (VNET_API_ERROR_RESPONSE_NOT_READY); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 436 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 437 | vppjni_lock (jm, 1); |
| 438 | p = hash_get (jm->reply_hash, context); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 439 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 440 | /* |
| 441 | * Two cases: a generic "yes" reply - won't be in the hash table |
| 442 | * or "no", or "more data" which will be in the table. |
| 443 | */ |
| 444 | if (p == 0) |
| 445 | goto out; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 446 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 447 | mp = (vl_api_generic_reply_t *) (p[0]); |
| 448 | rv = clib_net_to_host_u32 (mp->retval); |
| 449 | |
| 450 | if (release) { |
| 451 | u8 * free_me = (u8 *) mp; |
| 452 | vec_free (free_me); |
| 453 | hash_unset (jm->reply_hash, context); |
| 454 | jm->saved_reply_count --; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | out: |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 458 | vppjni_unlock (jm); |
| 459 | return (rv); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 460 | } |
| 461 | |
Matus Fabian | d2dc3df | 2015-12-14 10:31:33 -0500 | [diff] [blame] | 462 | static int |
| 463 | name_sort_cmp (void * a1, void * a2) |
| 464 | { |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 465 | name_sort_t * n1 = a1; |
| 466 | name_sort_t * n2 = a2; |
Matus Fabian | d2dc3df | 2015-12-14 10:31:33 -0500 | [diff] [blame] | 467 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 468 | return strcmp ((char *)n1->name, (char *)n2->name); |
Matus Fabian | d2dc3df | 2015-12-14 10:31:33 -0500 | [diff] [blame] | 469 | } |
| 470 | |
Dave Wallace | ba474a2 | 2016-02-09 23:09:41 -0500 | [diff] [blame] | 471 | JNIEXPORT jstring JNICALL Java_org_openvpp_vppjapi_vppConn_getInterfaceList0 |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 472 | (JNIEnv * env, jobject obj, jstring name_filter) |
| 473 | { |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 474 | vppjni_main_t * jm = &vppjni_main; |
| 475 | jstring rv; |
| 476 | hash_pair_t * p; |
| 477 | name_sort_t * nses = 0, * ns; |
| 478 | const char *this_name; |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 479 | u8 * s = 0; |
Robert Varga | f0f54d8 | 2016-02-10 16:01:58 +0100 | [diff] [blame] | 480 | const char * nf = (*env)->GetStringUTFChars (env, name_filter, NULL); |
| 481 | if (!nf) |
| 482 | return NULL; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 483 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 484 | vppjni_lock (jm, 4); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 485 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 486 | hash_foreach_pair (p, jm->sw_if_index_by_interface_name, |
| 487 | ({ |
| 488 | this_name = (const char *)(p->key); |
| 489 | if (strlen (nf) == 0 || strcasestr (this_name, nf)) { |
| 490 | vec_add2 (nses, ns, 1); |
| 491 | ns->name = (u8 *)(p->key); |
| 492 | ns->value = (u32) p->value[0]; |
| 493 | } |
| 494 | })); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 495 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 496 | vec_sort_with_function (nses, name_sort_cmp); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 497 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 498 | vec_foreach (ns, nses) |
| 499 | s = format (s, "%s: %d, ", ns->name, ns->value); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 500 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 501 | _vec_len (s) = vec_len (s) - 2; |
| 502 | vec_terminate_c_string (s); |
| 503 | vppjni_unlock (jm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 504 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 505 | vec_free (nses); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 506 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 507 | (*env)->ReleaseStringUTFChars (env, name_filter, nf); |
| 508 | |
| 509 | rv = (*env)->NewStringUTF (env, (char *) s); |
| 510 | vec_free (s); |
| 511 | |
| 512 | return rv; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 513 | } |
| 514 | |
Dave Wallace | ba474a2 | 2016-02-09 23:09:41 -0500 | [diff] [blame] | 515 | JNIEXPORT jint JNICALL Java_org_openvpp_vppjapi_vppConn_swIfIndexFromName0 |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 516 | (JNIEnv * env, jobject obj, jstring interfaceName) |
| 517 | { |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 518 | vppjni_main_t * jm = &vppjni_main; |
| 519 | jint rv = -1; |
| 520 | const char * if_name = (*env)->GetStringUTFChars (env, interfaceName, NULL); |
Robert Varga | f0f54d8 | 2016-02-10 16:01:58 +0100 | [diff] [blame] | 521 | if (if_name) { |
| 522 | uword * p; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 523 | |
Robert Varga | f0f54d8 | 2016-02-10 16:01:58 +0100 | [diff] [blame] | 524 | vppjni_lock (jm, 5); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 525 | |
Robert Varga | f0f54d8 | 2016-02-10 16:01:58 +0100 | [diff] [blame] | 526 | p = hash_get_mem (jm->sw_if_index_by_interface_name, if_name); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 527 | |
Robert Varga | f0f54d8 | 2016-02-10 16:01:58 +0100 | [diff] [blame] | 528 | if (p != 0) |
| 529 | rv = (jint) p[0]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 530 | |
Robert Varga | f0f54d8 | 2016-02-10 16:01:58 +0100 | [diff] [blame] | 531 | vppjni_unlock (jm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 532 | |
Robert Varga | f0f54d8 | 2016-02-10 16:01:58 +0100 | [diff] [blame] | 533 | (*env)->ReleaseStringUTFChars (env, interfaceName, if_name); |
| 534 | } |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 535 | |
| 536 | return rv; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 537 | } |
| 538 | |
Dave Wallace | ba474a2 | 2016-02-09 23:09:41 -0500 | [diff] [blame] | 539 | JNIEXPORT jobject JNICALL Java_org_openvpp_vppjapi_vppConn_getInterfaceCounters0 |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 540 | (JNIEnv * env, jobject obj, jint swIfIndex) |
| 541 | { |
| 542 | vppjni_main_t * jm = &vppjni_main; |
| 543 | sw_interface_stats_t *s; |
| 544 | u32 sw_if_index = swIfIndex; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 545 | jobject result = NULL; |
| 546 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 547 | vppjni_lock (jm, 16); |
| 548 | |
| 549 | if (sw_if_index >= vec_len(jm->sw_if_stats_by_sw_if_index)) { |
| 550 | goto out; |
| 551 | } |
| 552 | s = &jm->sw_if_stats_by_sw_if_index[sw_if_index]; |
| 553 | if (!s->valid) { |
| 554 | goto out; |
| 555 | } |
| 556 | |
Robert Varga | 81d99ac | 2016-01-30 18:30:36 +0100 | [diff] [blame] | 557 | result = vppInterfaceCountersObject(env, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 558 | s->rx.octets, s->rx.pkts.ip4, s->rx.pkts.ip6, s->rx.pkts.unicast, |
| 559 | s->rx.pkts.multicast, s->rx.pkts.broadcast, s->rx.pkts.discard, |
| 560 | s->rx.pkts.fifo_full, s->rx.pkts.error, s->rx.pkts.unknown_proto, |
| 561 | s->rx.pkts.miss, |
| 562 | s->tx.octets, s->tx.pkts.ip4, s->tx.pkts.ip6, s->tx.pkts.unicast, |
| 563 | s->tx.pkts.multicast, s->tx.pkts.broadcast, s->tx.pkts.discard, |
| 564 | s->tx.pkts.fifo_full, s->tx.pkts.error, s->tx.pkts.unknown_proto, |
| 565 | s->tx.pkts.miss); |
| 566 | |
| 567 | out: |
| 568 | vppjni_unlock (jm); |
| 569 | return result; |
| 570 | } |
| 571 | |
Dave Wallace | ba474a2 | 2016-02-09 23:09:41 -0500 | [diff] [blame] | 572 | JNIEXPORT jstring JNICALL Java_org_openvpp_vppjapi_vppConn_interfaceNameFromSwIfIndex0 |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 573 | (JNIEnv * env, jobject obj, jint swIfIndex) |
| 574 | { |
| 575 | vppjni_main_t * jm = &vppjni_main; |
| 576 | sw_interface_details_t *sw_if_details; |
| 577 | u32 sw_if_index; |
| 578 | jstring ifname = NULL; |
| 579 | |
| 580 | vppjni_lock (jm, 8); |
| 581 | |
| 582 | sw_if_index = swIfIndex; |
| 583 | |
| 584 | if (sw_if_index >= vec_len(jm->sw_if_table)) { |
| 585 | goto out; |
| 586 | } |
| 587 | sw_if_details = &jm->sw_if_table[sw_if_index]; |
| 588 | if (!sw_if_details->valid) { |
| 589 | goto out; |
| 590 | } |
| 591 | |
| 592 | u8 * s = format (0, "%s%c", sw_if_details->interface_name, 0); |
| 593 | ifname = (*env)->NewStringUTF(env, (char *)s); |
| 594 | |
| 595 | out: |
| 596 | vppjni_unlock (jm); |
| 597 | |
| 598 | return ifname; |
| 599 | } |
| 600 | |
Dave Wallace | ba474a2 | 2016-02-09 23:09:41 -0500 | [diff] [blame] | 601 | JNIEXPORT void JNICALL Java_org_openvpp_vppjapi_vppConn_clearInterfaceTable0 |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 602 | (JNIEnv * env, jobject obj) |
| 603 | { |
| 604 | vppjni_main_t * jm = &vppjni_main; |
| 605 | |
Dave Wallace | bf8c15e | 2015-12-17 20:54:54 -0500 | [diff] [blame] | 606 | vppjni_lock (jm, 21); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 607 | |
| 608 | vec_reset_length(jm->sw_if_table); |
| 609 | |
| 610 | vppjni_unlock (jm); |
| 611 | } |
| 612 | |
Dave Wallace | bf8c15e | 2015-12-17 20:54:54 -0500 | [diff] [blame] | 613 | static jobjectArray sw_if_dump_get_interfaces (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 614 | |
Dave Wallace | ba474a2 | 2016-02-09 23:09:41 -0500 | [diff] [blame] | 615 | JNIEXPORT jobjectArray JNICALL Java_org_openvpp_vppjapi_vppConn_swInterfaceDump0 |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 616 | (JNIEnv * env, jobject obj, jbyte name_filter_valid, jbyteArray name_filter) |
| 617 | { |
| 618 | vppjni_main_t *jm = &vppjni_main; |
| 619 | f64 timeout; |
| 620 | vl_api_sw_interface_dump_t * mp; |
| 621 | u32 my_context_id; |
| 622 | int rv; |
| 623 | rv = vppjni_sanity_check (jm); |
Dave Wallace | bf8c15e | 2015-12-17 20:54:54 -0500 | [diff] [blame] | 624 | if (rv) { |
| 625 | clib_warning("swInterfaceDump sanity_check rv = %d", rv); |
| 626 | return NULL; |
| 627 | } |
| 628 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 629 | vppjni_lock (jm, 7); |
| 630 | my_context_id = vppjni_get_context_id (jm); |
Robert Varga | 427ce22 | 2016-02-01 18:12:18 +0100 | [diff] [blame] | 631 | jsize cnt = (*env)->GetArrayLength (env, name_filter); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 632 | |
| 633 | M(SW_INTERFACE_DUMP, sw_interface_dump); |
| 634 | mp->context = clib_host_to_net_u32 (my_context_id); |
| 635 | mp->name_filter_valid = name_filter_valid; |
| 636 | |
| 637 | if (cnt > sizeof(mp->name_filter)) |
| 638 | cnt = sizeof(mp->name_filter); |
| 639 | |
Robert Varga | 427ce22 | 2016-02-01 18:12:18 +0100 | [diff] [blame] | 640 | (*env)->GetByteArrayRegion(env, name_filter, 0, cnt, (jbyte *)mp->name_filter); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 641 | |
Dave Wallace | bf8c15e | 2015-12-17 20:54:54 -0500 | [diff] [blame] | 642 | DEBUG_LOG ("interface filter (%d, %s, len: %d)", mp->name_filter_valid, (char *)mp->name_filter, cnt); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 643 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 644 | jm->collect_indices = 1; |
| 645 | |
| 646 | S; |
| 647 | { |
| 648 | // now send control ping so we know when it ends |
| 649 | vl_api_control_ping_t * mp; |
| 650 | M(CONTROL_PING, control_ping); |
| 651 | mp->context = clib_host_to_net_u32 (my_context_id); |
| 652 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 653 | S; |
| 654 | } |
| 655 | vppjni_unlock (jm); |
| 656 | WNR; |
Dave Wallace | bf8c15e | 2015-12-17 20:54:54 -0500 | [diff] [blame] | 657 | |
| 658 | vppjni_lock (jm, 7); |
| 659 | jobjectArray result = sw_if_dump_get_interfaces(env); |
| 660 | vppjni_unlock (jm); |
| 661 | return result; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 662 | } |
| 663 | |
Dave Wallace | bf8c15e | 2015-12-17 20:54:54 -0500 | [diff] [blame] | 664 | static jobjectArray sw_if_dump_get_interfaces (JNIEnv * env) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 665 | { |
| 666 | vppjni_main_t * jm = &vppjni_main; |
| 667 | sw_interface_details_t *sw_if_details; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 668 | u32 i; |
| 669 | |
Dave Wallace | bf8c15e | 2015-12-17 20:54:54 -0500 | [diff] [blame] | 670 | int len = vec_len(jm->sw_if_dump_if_indices); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 671 | |
Robert Varga | 81d99ac | 2016-01-30 18:30:36 +0100 | [diff] [blame] | 672 | jobjectArray ifArray = vppInterfaceDetailsArray(env, len); |
Dave Wallace | bf8c15e | 2015-12-17 20:54:54 -0500 | [diff] [blame] | 673 | |
| 674 | for (i = 0; i < len; i++) { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 675 | u32 sw_if_index = jm->sw_if_dump_if_indices[i]; |
| 676 | ASSERT(sw_if_index < vec_len(jm->sw_if_table)); |
| 677 | sw_if_details = &jm->sw_if_table[sw_if_index]; |
| 678 | ASSERT(sw_if_details->valid); |
| 679 | |
| 680 | u8 * s = format (0, "%s%c", sw_if_details->interface_name, 0); |
| 681 | |
| 682 | jstring ifname = (*env)->NewStringUTF(env, (char *)s); |
| 683 | jint ifIndex = sw_if_details->sw_if_index; |
| 684 | jint supIfIndex = sw_if_details->sup_sw_if_index; |
| 685 | jbyteArray physAddr = (*env)->NewByteArray(env, |
| 686 | sw_if_details->l2_address_length); |
| 687 | (*env)->SetByteArrayRegion(env, physAddr, 0, |
| 688 | sw_if_details->l2_address_length, |
| 689 | (signed char*)sw_if_details->l2_address); |
| 690 | jint subId = sw_if_details->sub_id; |
| 691 | jint subOuterVlanId = sw_if_details->sub_outer_vlan_id; |
| 692 | jint subInnerVlanId = sw_if_details->sub_inner_vlan_id; |
| 693 | jint vtrOp = sw_if_details->vtr_op; |
| 694 | jint vtrPushDot1q = sw_if_details->vtr_push_dot1q; |
| 695 | jint vtrTag1 = sw_if_details->vtr_tag1; |
| 696 | jint vtrTag2 = sw_if_details->vtr_tag2; |
| 697 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 698 | jbyte adminUpDown = sw_if_details->admin_up_down; |
| 699 | jbyte linkUpDown = sw_if_details->link_up_down; |
| 700 | jbyte linkDuplex = sw_if_details->link_duplex; |
| 701 | jbyte linkSpeed = sw_if_details->link_speed; |
| 702 | jbyte subDot1ad = sw_if_details->sub_dot1ad; |
| 703 | jbyte subNumberOfTags = sw_if_details->sub_number_of_tags; |
| 704 | jbyte subExactMatch = sw_if_details->sub_exact_match; |
| 705 | jbyte subDefault = sw_if_details->sub_default; |
| 706 | jbyte subOuterVlanIdAny = sw_if_details->sub_outer_vlan_id_any; |
| 707 | jbyte subInnerVlanIdAny = sw_if_details->sub_inner_vlan_id_any; |
| 708 | |
Robert Varga | 81d99ac | 2016-01-30 18:30:36 +0100 | [diff] [blame] | 709 | jobject ifObj = vppInterfaceDetailsObject(env, |
Dave Wallace | bf8c15e | 2015-12-17 20:54:54 -0500 | [diff] [blame] | 710 | ifIndex, ifname, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 711 | supIfIndex, physAddr, adminUpDown, linkUpDown, |
| 712 | linkDuplex, linkSpeed, subId, subDot1ad, |
| 713 | subNumberOfTags, subOuterVlanId, subInnerVlanId, |
| 714 | subExactMatch, subDefault, subOuterVlanIdAny, |
| 715 | subInnerVlanIdAny, vtrOp, vtrPushDot1q, vtrTag1, vtrTag2); |
Dave Wallace | bf8c15e | 2015-12-17 20:54:54 -0500 | [diff] [blame] | 716 | (*env)->SetObjectArrayElement(env, ifArray, i, ifObj); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 717 | } |
| 718 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 719 | jm->collect_indices = 0; |
| 720 | vec_reset_length(jm->sw_if_dump_if_indices); |
Dave Wallace | bf8c15e | 2015-12-17 20:54:54 -0500 | [diff] [blame] | 721 | return ifArray; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 722 | } |
| 723 | |
Dave Wallace | ba474a2 | 2016-02-09 23:09:41 -0500 | [diff] [blame] | 724 | JNIEXPORT jint JNICALL Java_org_openvpp_vppjapi_vppConn_findOrAddBridgeDomainId0 |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 725 | (JNIEnv * env, jobject obj, jstring bridgeDomain) |
| 726 | { |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 727 | vppjni_main_t * jm = &vppjni_main; |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 728 | jint rv = -1; |
| 729 | const char * bdName = (*env)->GetStringUTFChars (env, bridgeDomain, NULL); |
Robert Varga | f0f54d8 | 2016-02-10 16:01:58 +0100 | [diff] [blame] | 730 | if (bdName) { |
| 731 | static u8 * bd_name = 0; |
Dave Wallace | bf8c15e | 2015-12-17 20:54:54 -0500 | [diff] [blame] | 732 | |
Robert Varga | f0f54d8 | 2016-02-10 16:01:58 +0100 | [diff] [blame] | 733 | vec_validate_init_c_string (bd_name, bdName, strlen(bdName)); |
| 734 | (*env)->ReleaseStringUTFChars (env, bridgeDomain, bdName); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 735 | |
Robert Varga | f0f54d8 | 2016-02-10 16:01:58 +0100 | [diff] [blame] | 736 | vppjni_lock (jm, 6); |
| 737 | rv = (jint)vjbd_find_or_add_bd (&jm->vjbd_main, bd_name); |
| 738 | vppjni_unlock (jm); |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 739 | |
Robert Varga | f0f54d8 | 2016-02-10 16:01:58 +0100 | [diff] [blame] | 740 | _vec_len(bd_name) = 0; |
| 741 | } |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 742 | return rv; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 743 | } |
| 744 | |
Dave Wallace | ba474a2 | 2016-02-09 23:09:41 -0500 | [diff] [blame] | 745 | JNIEXPORT jint JNICALL Java_org_openvpp_vppjapi_vppConn_bridgeDomainIdFromName0 |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 746 | (JNIEnv * env, jobject obj, jstring bridgeDomain) |
| 747 | { |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 748 | vppjni_main_t * jm = &vppjni_main; |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 749 | jint rv = -1; |
| 750 | const char * bdName = (*env)->GetStringUTFChars (env, bridgeDomain, NULL); |
Robert Varga | f0f54d8 | 2016-02-10 16:01:58 +0100 | [diff] [blame] | 751 | if (bdName) { |
| 752 | static u8 * bd_name = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 753 | |
Robert Varga | f0f54d8 | 2016-02-10 16:01:58 +0100 | [diff] [blame] | 754 | vec_validate_init_c_string (bd_name, bdName, strlen(bdName)); |
| 755 | (*env)->ReleaseStringUTFChars (env, bridgeDomain, bdName); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 756 | |
Robert Varga | f0f54d8 | 2016-02-10 16:01:58 +0100 | [diff] [blame] | 757 | vppjni_lock (jm, 20); |
| 758 | rv = (jint)vjbd_id_from_name(&jm->vjbd_main, (u8 *)bd_name); |
| 759 | vppjni_unlock (jm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 760 | |
Robert Varga | f0f54d8 | 2016-02-10 16:01:58 +0100 | [diff] [blame] | 761 | _vec_len(bd_name) = 0; |
| 762 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 763 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 764 | return rv; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 765 | } |
| 766 | |
Dave Wallace | ba474a2 | 2016-02-09 23:09:41 -0500 | [diff] [blame] | 767 | JNIEXPORT jint JNICALL Java_org_openvpp_vppjapi_vppConn_bridgeDomainIdFromInterfaceName0 |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 768 | (JNIEnv * env, jobject obj, jstring interfaceName) |
| 769 | { |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 770 | vppjni_main_t * jm = &vppjni_main; |
| 771 | vjbd_main_t * bdm = &jm->vjbd_main; |
| 772 | u32 sw_if_index; |
| 773 | jint rv = -1; |
| 774 | const char * if_name; |
| 775 | uword * p; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 776 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 777 | if_name = (*env)->GetStringUTFChars (env, interfaceName, NULL); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 778 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 779 | vppjni_lock (jm, 14); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 780 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 781 | p = hash_get_mem (jm->sw_if_index_by_interface_name, if_name); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 782 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 783 | if (p != 0) { |
| 784 | sw_if_index = (jint) p[0]; |
| 785 | p = hash_get (bdm->bd_id_by_sw_if_index, sw_if_index); |
| 786 | if (p != 0) { |
| 787 | rv = (jint) p[0]; |
| 788 | } |
| 789 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 790 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 791 | vppjni_unlock (jm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 792 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 793 | (*env)->ReleaseStringUTFChars (env, interfaceName, if_name); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 794 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 795 | return rv; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 796 | } |
| 797 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 798 | /* |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 799 | * Special-case: build the interface table, maintain |
| 800 | * the next loopback sw_if_index vbl. |
| 801 | */ |
| 802 | static void vl_api_sw_interface_details_t_handler |
| 803 | (vl_api_sw_interface_details_t * mp) |
| 804 | { |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 805 | vppjni_main_t * jm = &vppjni_main; |
| 806 | static sw_interface_details_t empty_sw_if_details = {0,}; |
| 807 | sw_interface_details_t *sw_if_details; |
| 808 | u32 sw_if_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 809 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 810 | vppjni_lock (jm, 1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 811 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 812 | sw_if_index = ntohl (mp->sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 813 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 814 | u8 * s = format (0, "%s%c", mp->interface_name, 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 815 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 816 | if (jm->collect_indices) { |
| 817 | u32 pos = vec_len(jm->sw_if_dump_if_indices); |
| 818 | vec_validate(jm->sw_if_dump_if_indices, pos); |
| 819 | jm->sw_if_dump_if_indices[pos] = sw_if_index; |
| 820 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 821 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 822 | vec_validate_init_empty(jm->sw_if_table, sw_if_index, empty_sw_if_details); |
| 823 | sw_if_details = &jm->sw_if_table[sw_if_index]; |
| 824 | sw_if_details->valid = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 825 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 826 | snprintf((char *)sw_if_details->interface_name, |
| 827 | sizeof(sw_if_details->interface_name), "%s", (char *)s); |
| 828 | sw_if_details->sw_if_index = sw_if_index; |
| 829 | sw_if_details->sup_sw_if_index = ntohl(mp->sup_sw_if_index); |
| 830 | sw_if_details->l2_address_length = ntohl (mp->l2_address_length); |
| 831 | ASSERT(sw_if_details->l2_address_length <= sizeof(sw_if_details->l2_address)); |
| 832 | memcpy(sw_if_details->l2_address, mp->l2_address, |
| 833 | sw_if_details->l2_address_length); |
| 834 | sw_if_details->sub_id = ntohl (mp->sub_id); |
| 835 | sw_if_details->sub_outer_vlan_id = ntohl (mp->sub_outer_vlan_id); |
| 836 | sw_if_details->sub_inner_vlan_id = ntohl (mp->sub_inner_vlan_id); |
| 837 | sw_if_details->vtr_op = ntohl (mp->vtr_op); |
| 838 | sw_if_details->vtr_push_dot1q = ntohl (mp->vtr_push_dot1q); |
| 839 | sw_if_details->vtr_tag1 = ntohl (mp->vtr_tag1); |
| 840 | sw_if_details->vtr_tag2 = ntohl (mp->vtr_tag2); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 841 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 842 | sw_if_details->admin_up_down = mp->admin_up_down; |
| 843 | sw_if_details->link_up_down = mp->link_up_down; |
| 844 | sw_if_details->link_duplex = mp->link_duplex; |
| 845 | sw_if_details->link_speed = mp->link_speed; |
| 846 | sw_if_details->sub_dot1ad = mp->sub_dot1ad; |
| 847 | sw_if_details->sub_number_of_tags = mp->sub_number_of_tags; |
| 848 | sw_if_details->sub_exact_match = mp->sub_exact_match; |
| 849 | sw_if_details->sub_default = mp->sub_default; |
| 850 | sw_if_details->sub_outer_vlan_id_any = mp->sub_outer_vlan_id_any; |
| 851 | sw_if_details->sub_inner_vlan_id_any = mp->sub_inner_vlan_id_any; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 852 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 853 | hash_set_mem (jm->sw_if_index_by_interface_name, s, sw_if_index); |
| 854 | DEBUG_LOG ("Got interface %s", (char *)s); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 855 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 856 | /* In sub interface case, fill the sub interface table entry */ |
| 857 | if (mp->sw_if_index != mp->sup_sw_if_index) { |
| 858 | sw_interface_subif_t * sub = NULL; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 859 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 860 | vec_add2(jm->sw_if_subif_table, sub, 1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 861 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 862 | vec_validate(sub->interface_name, strlen((char *)s) + 1); |
| 863 | strncpy((char *)sub->interface_name, (char *)s, |
| 864 | vec_len(sub->interface_name)); |
| 865 | sub->sw_if_index = ntohl(mp->sw_if_index); |
| 866 | sub->sub_id = ntohl(mp->sub_id); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 867 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 868 | sub->sub_dot1ad = mp->sub_dot1ad; |
| 869 | sub->sub_number_of_tags = mp->sub_number_of_tags; |
| 870 | sub->sub_outer_vlan_id = ntohs(mp->sub_outer_vlan_id); |
| 871 | sub->sub_inner_vlan_id = ntohs(mp->sub_inner_vlan_id); |
| 872 | sub->sub_exact_match = mp->sub_exact_match; |
| 873 | sub->sub_default = mp->sub_default; |
| 874 | sub->sub_outer_vlan_id_any = mp->sub_outer_vlan_id_any; |
| 875 | sub->sub_inner_vlan_id_any = mp->sub_inner_vlan_id_any; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 876 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 877 | /* vlan tag rewrite */ |
| 878 | sub->vtr_op = ntohl(mp->vtr_op); |
| 879 | sub->vtr_push_dot1q = ntohl(mp->vtr_push_dot1q); |
| 880 | sub->vtr_tag1 = ntohl(mp->vtr_tag1); |
| 881 | sub->vtr_tag2 = ntohl(mp->vtr_tag2); |
| 882 | } |
| 883 | vppjni_unlock (jm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | static void vl_api_sw_interface_set_flags_t_handler |
| 887 | (vl_api_sw_interface_set_flags_t * mp) |
| 888 | { |
| 889 | /* $$$ nothing for the moment */ |
| 890 | } |
| 891 | |
| 892 | static jintArray create_array_of_bd_ids(JNIEnv * env, jint bd_id) |
| 893 | { |
| 894 | vppjni_main_t *jm = &vppjni_main; |
| 895 | vjbd_main_t * bdm = &jm->vjbd_main; |
| 896 | u32 *buf = NULL; |
| 897 | u32 i; |
| 898 | |
| 899 | if (bd_id != ~0) { |
| 900 | vec_add1(buf, bd_id); |
| 901 | } else { |
| 902 | for (i = 0; i < vec_len(bdm->bd_oper); i++) { |
| 903 | u32 bd_id = bdm->bd_oper[i].bd_id; |
| 904 | vec_add1(buf, bd_id); |
| 905 | } |
| 906 | } |
| 907 | |
| 908 | jintArray bdidArray = (*env)->NewIntArray(env, vec_len(buf)); |
Robert Varga | ec3034c | 2016-02-10 16:00:16 +0100 | [diff] [blame] | 909 | if (!bdidArray) { |
| 910 | goto out; |
| 911 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 912 | |
| 913 | (*env)->SetIntArrayRegion(env, bdidArray, 0, vec_len(buf), (int*)buf); |
| 914 | |
Robert Varga | ec3034c | 2016-02-10 16:00:16 +0100 | [diff] [blame] | 915 | out: |
Robert Varga | 7a224a0 | 2016-02-01 18:33:38 +0100 | [diff] [blame] | 916 | vec_free(buf); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 917 | return bdidArray; |
| 918 | } |
| 919 | |
| 920 | static void bridge_domain_oper_free(void) |
| 921 | { |
| 922 | vppjni_main_t *jm = &vppjni_main; |
| 923 | vjbd_main_t *bdm = &jm->vjbd_main; |
| 924 | u32 i; |
| 925 | |
| 926 | for (i = 0; i < vec_len(bdm->bd_oper); i++) { |
| 927 | vec_free(bdm->bd_oper->l2fib_oper); |
| 928 | } |
| 929 | vec_reset_length(bdm->bd_oper); |
| 930 | hash_free(bdm->bd_id_by_sw_if_index); |
| 931 | hash_free(bdm->oper_bd_index_by_bd_id); |
| 932 | } |
| 933 | |
Dave Wallace | ba474a2 | 2016-02-09 23:09:41 -0500 | [diff] [blame] | 934 | JNIEXPORT jintArray JNICALL Java_org_openvpp_vppjapi_vppConn_bridgeDomainDump0 |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 935 | (JNIEnv * env, jobject obj, jint bd_id) |
| 936 | { |
| 937 | vppjni_main_t *jm = &vppjni_main; |
| 938 | vl_api_bridge_domain_dump_t * mp; |
| 939 | u32 my_context_id; |
| 940 | f64 timeout; |
| 941 | int rv; |
| 942 | rv = vppjni_sanity_check (jm); |
| 943 | if (rv) return NULL; |
| 944 | |
| 945 | vppjni_lock (jm, 15); |
| 946 | |
| 947 | if (~0 == bd_id) { |
| 948 | bridge_domain_oper_free(); |
| 949 | } |
| 950 | |
| 951 | my_context_id = vppjni_get_context_id (jm); |
| 952 | M(BRIDGE_DOMAIN_DUMP, bridge_domain_dump); |
| 953 | mp->context = clib_host_to_net_u32 (my_context_id); |
| 954 | mp->bd_id = clib_host_to_net_u32(bd_id); |
| 955 | S; |
| 956 | |
| 957 | /* Use a control ping for synchronization */ |
| 958 | { |
| 959 | vl_api_control_ping_t * mp; |
| 960 | M(CONTROL_PING, control_ping); |
| 961 | S; |
| 962 | } |
| 963 | |
| 964 | WNR; |
| 965 | if (0 != rv) { |
| 966 | return NULL; |
| 967 | } |
| 968 | |
| 969 | jintArray ret = create_array_of_bd_ids(env, bd_id); |
| 970 | |
| 971 | vppjni_unlock (jm); |
| 972 | |
| 973 | return ret; |
| 974 | } |
| 975 | |
| 976 | static void |
| 977 | vl_api_bridge_domain_details_t_handler (vl_api_bridge_domain_details_t * mp) |
| 978 | { |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 979 | vppjni_main_t *jm = &vppjni_main; |
| 980 | vjbd_main_t * bdm = &jm->vjbd_main; |
| 981 | vjbd_oper_t * bd_oper; |
| 982 | u32 bd_id, bd_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 983 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 984 | bd_id = ntohl (mp->bd_id); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 985 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 986 | bd_index = vec_len(bdm->bd_oper); |
| 987 | vec_validate (bdm->bd_oper, bd_index); |
| 988 | bd_oper = vec_elt_at_index(bdm->bd_oper, bd_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 989 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 990 | hash_set(bdm->oper_bd_index_by_bd_id, bd_id, bd_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 991 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 992 | bd_oper->bd_id = bd_id; |
| 993 | bd_oper->flood = mp->flood != 0; |
| 994 | bd_oper->forward = mp->forward != 0; |
| 995 | bd_oper->learn = mp->learn != 0; |
| 996 | bd_oper->uu_flood = mp->uu_flood != 0; |
| 997 | bd_oper->arp_term = mp->arp_term != 0; |
| 998 | bd_oper->bvi_sw_if_index = ntohl (mp->bvi_sw_if_index); |
| 999 | bd_oper->n_sw_ifs = ntohl (mp->n_sw_ifs); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1000 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1001 | bd_oper->bd_sw_if_oper = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | static void |
| 1005 | vl_api_bridge_domain_sw_if_details_t_handler |
| 1006 | (vl_api_bridge_domain_sw_if_details_t * mp) |
| 1007 | { |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1008 | vppjni_main_t *jm = &vppjni_main; |
| 1009 | vjbd_main_t * bdm = &jm->vjbd_main; |
| 1010 | bd_sw_if_oper_t * bd_sw_if_oper; |
| 1011 | u32 bd_id, sw_if_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1012 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1013 | bd_id = ntohl (mp->bd_id); |
| 1014 | sw_if_index = ntohl (mp->sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1015 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1016 | uword *p; |
| 1017 | p = hash_get (bdm->oper_bd_index_by_bd_id, bd_id); |
| 1018 | if (p == 0) { |
| 1019 | clib_warning("Invalid bd_id %d in bridge_domain_sw_if_details_t_handler", bd_id); |
| 1020 | return; |
| 1021 | } |
| 1022 | u32 oper_bd_index = (jint) p[0]; |
| 1023 | vjbd_oper_t *bd_oper = vec_elt_at_index(bdm->bd_oper, oper_bd_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1024 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1025 | u32 len = vec_len(bd_oper->bd_sw_if_oper); |
| 1026 | vec_validate(bd_oper->bd_sw_if_oper, len); |
| 1027 | bd_sw_if_oper = &bd_oper->bd_sw_if_oper[len]; |
| 1028 | bd_sw_if_oper->bd_id = bd_id; |
| 1029 | bd_sw_if_oper->sw_if_index = sw_if_index; |
| 1030 | bd_sw_if_oper->shg = mp->shg; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1031 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1032 | hash_set(bdm->bd_id_by_sw_if_index, sw_if_index, bd_id); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | static const char* interface_name_from_sw_if_index(u32 sw_if_index) |
| 1036 | { |
| 1037 | vppjni_main_t *jm = &vppjni_main; |
| 1038 | |
| 1039 | if (sw_if_index >= vec_len(jm->sw_if_table)) { |
| 1040 | return NULL; |
| 1041 | } |
| 1042 | if (!jm->sw_if_table[sw_if_index].valid) { |
| 1043 | return NULL; |
| 1044 | } |
| 1045 | return (const char*)jm->sw_if_table[sw_if_index].interface_name; |
| 1046 | } |
| 1047 | |
Dave Wallace | ba474a2 | 2016-02-09 23:09:41 -0500 | [diff] [blame] | 1048 | JNIEXPORT jobject JNICALL Java_org_openvpp_vppjapi_vppConn_getBridgeDomainDetails0 |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1049 | (JNIEnv * env, jobject obj, jint bdId) |
| 1050 | { |
| 1051 | vppjni_main_t *jm = &vppjni_main; |
| 1052 | vjbd_main_t * bdm = &jm->vjbd_main; |
| 1053 | u32 oper_bd_index; |
| 1054 | u32 bd_id = bdId; |
| 1055 | jobject rv = NULL; |
| 1056 | uword *p; |
| 1057 | |
| 1058 | vppjni_lock (jm, 16); |
| 1059 | |
| 1060 | p = hash_get (bdm->oper_bd_index_by_bd_id, bd_id); |
| 1061 | if (p == 0) { |
| 1062 | rv = NULL; |
| 1063 | goto out; |
| 1064 | } |
| 1065 | oper_bd_index = (jint) p[0]; |
| 1066 | |
| 1067 | vjbd_oper_t *bd_oper = vec_elt_at_index(bdm->bd_oper, oper_bd_index); |
| 1068 | |
| 1069 | |
| 1070 | /* setting BridgeDomainDetails */ |
| 1071 | |
Robert Varga | 81d99ac | 2016-01-30 18:30:36 +0100 | [diff] [blame] | 1072 | jobject bddObj = vppBridgeDomainDetailsObject(env); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1073 | |
| 1074 | u8 *vec_bd_name = vjbd_oper_name_from_id(bdm, bd_id); |
| 1075 | if (NULL == vec_bd_name) { |
| 1076 | rv = NULL; |
| 1077 | goto out; |
| 1078 | } |
| 1079 | char *str_bd_name = (char*)format (0, "%s%c", vec_bd_name, 0); |
| 1080 | vec_free(vec_bd_name); |
| 1081 | jstring bdName = (*env)->NewStringUTF(env, str_bd_name); |
| 1082 | vec_free(str_bd_name); |
| 1083 | if (NULL == bdName) { |
| 1084 | rv = NULL; |
| 1085 | goto out; |
| 1086 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1087 | |
Robert Varga | 81d99ac | 2016-01-30 18:30:36 +0100 | [diff] [blame] | 1088 | set_vppBridgeDomainDetails_name(env, bddObj, bdName); |
| 1089 | set_vppBridgeDomainDetails_bdId(env, bddObj, bdId); |
| 1090 | set_vppBridgeDomainDetails_flood(env, bddObj, (jboolean)bd_oper->flood); |
| 1091 | set_vppBridgeDomainDetails_uuFlood(env, bddObj, (jboolean)bd_oper->uu_flood); |
| 1092 | set_vppBridgeDomainDetails_forward(env, bddObj, (jboolean)bd_oper->forward); |
| 1093 | set_vppBridgeDomainDetails_learn(env, bddObj, (jboolean)bd_oper->learn); |
| 1094 | set_vppBridgeDomainDetails_arpTerm(env, bddObj, (jboolean)bd_oper->arp_term); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1095 | |
| 1096 | jstring bviInterfaceName = NULL; |
| 1097 | if (~0 != bd_oper->bvi_sw_if_index) { |
| 1098 | const char *str_if_name = interface_name_from_sw_if_index(bd_oper->bvi_sw_if_index); |
| 1099 | if (NULL == str_if_name) { |
| 1100 | clib_warning("Could not get interface name for sw_if_index %d", bd_oper->bvi_sw_if_index); |
| 1101 | rv = NULL; |
| 1102 | goto out; |
| 1103 | } |
| 1104 | bviInterfaceName = (*env)->NewStringUTF(env, str_if_name); |
| 1105 | if (NULL == bviInterfaceName) { |
| 1106 | rv = NULL; |
| 1107 | goto out; |
| 1108 | } |
| 1109 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1110 | |
Robert Varga | 81d99ac | 2016-01-30 18:30:36 +0100 | [diff] [blame] | 1111 | set_vppBridgeDomainDetails_bviInterfaceName(env, bddObj, bviInterfaceName); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1112 | |
| 1113 | /* setting BridgeDomainInterfaceDetails */ |
| 1114 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1115 | u32 len = vec_len(bd_oper->bd_sw_if_oper); |
| 1116 | ASSERT(len == bd_oper->n_sw_ifs); |
| 1117 | |
Robert Varga | 81d99ac | 2016-01-30 18:30:36 +0100 | [diff] [blame] | 1118 | jobjectArray bdidArray = vppBridgeDomainInterfaceDetailsArray(env, len); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1119 | |
| 1120 | u32 i; |
| 1121 | for (i = 0; i < len; i++) { |
| 1122 | bd_sw_if_oper_t *sw_if_oper = &bd_oper->bd_sw_if_oper[i]; |
| 1123 | |
Robert Varga | 81d99ac | 2016-01-30 18:30:36 +0100 | [diff] [blame] | 1124 | jobject bdidObj = vppBridgeDomainInterfaceDetailsObject(env); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1125 | (*env)->SetObjectArrayElement(env, bdidArray, i, bdidObj); |
| 1126 | |
| 1127 | u32 sw_if_index = sw_if_oper->sw_if_index; |
| 1128 | const char *str_if_name = interface_name_from_sw_if_index(sw_if_index); |
| 1129 | if (NULL == str_if_name) { |
| 1130 | rv = NULL; |
| 1131 | goto out; |
| 1132 | } |
| 1133 | jstring interfaceName = (*env)->NewStringUTF(env, str_if_name); |
| 1134 | if (NULL == interfaceName) { |
| 1135 | rv = NULL; |
| 1136 | goto out; |
| 1137 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1138 | |
Robert Varga | 81d99ac | 2016-01-30 18:30:36 +0100 | [diff] [blame] | 1139 | set_vppBridgeDomainInterfaceDetails_interfaceName(env, bdidObj, interfaceName); |
| 1140 | set_vppBridgeDomainInterfaceDetails_splitHorizonGroup(env, bdidObj, (jbyte)sw_if_oper->shg); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1141 | } |
| 1142 | |
Robert Varga | 81d99ac | 2016-01-30 18:30:36 +0100 | [diff] [blame] | 1143 | set_vppBridgeDomainDetails_interfaces(env, bddObj, bdidArray); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1144 | |
| 1145 | rv = bddObj; |
| 1146 | |
| 1147 | out: |
| 1148 | |
| 1149 | vppjni_unlock (jm); |
| 1150 | |
| 1151 | return rv; |
| 1152 | } |
| 1153 | |
| 1154 | static jobject l2_fib_create_object(JNIEnv *env, bd_l2fib_oper_t *l2_fib) |
| 1155 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1156 | u32 sw_if_index = l2_fib->sw_if_index; |
| 1157 | const char *str_if_name = interface_name_from_sw_if_index(sw_if_index); |
| 1158 | if (NULL == str_if_name) { |
| 1159 | return NULL; |
| 1160 | } |
| 1161 | jstring interfaceName = (*env)->NewStringUTF(env, str_if_name); |
| 1162 | if (NULL == interfaceName) { |
| 1163 | return NULL; |
| 1164 | } |
| 1165 | |
| 1166 | jbyteArray physAddr = (*env)->NewByteArray(env, 6); |
| 1167 | (*env)->SetByteArrayRegion(env, physAddr, 0, 6, |
| 1168 | (signed char*)l2_fib->mac_addr.fields.mac); |
| 1169 | jboolean staticConfig = !l2_fib->learned; |
| 1170 | jstring outgoingInterface = interfaceName; |
| 1171 | jboolean filter = l2_fib->filter; |
| 1172 | jboolean bridgedVirtualInterface = l2_fib->bvi; |
| 1173 | |
Robert Varga | 81d99ac | 2016-01-30 18:30:36 +0100 | [diff] [blame] | 1174 | return vppL2FibObject(env, physAddr, staticConfig, outgoingInterface, filter, bridgedVirtualInterface); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1175 | } |
| 1176 | |
Dave Wallace | ba474a2 | 2016-02-09 23:09:41 -0500 | [diff] [blame] | 1177 | JNIEXPORT jobjectArray JNICALL Java_org_openvpp_vppjapi_vppConn_l2FibTableDump0 |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1178 | (JNIEnv * env, jobject obj, jint bd_id) |
| 1179 | { |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1180 | vppjni_main_t *jm = &vppjni_main; |
| 1181 | vjbd_main_t * bdm = &jm->vjbd_main; |
| 1182 | vl_api_l2_fib_table_dump_t *mp; |
| 1183 | jobjectArray l2FibArray = NULL; |
| 1184 | vjbd_oper_t *bd_oper; |
| 1185 | u32 oper_bd_index; |
| 1186 | uword *p; |
| 1187 | f64 timeout; |
| 1188 | int rv; |
| 1189 | u32 i; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1190 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1191 | vppjni_lock (jm, 17); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1192 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1193 | //vjbd_l2fib_oper_reset (bdm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1194 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1195 | p = hash_get (bdm->oper_bd_index_by_bd_id, bd_id); |
| 1196 | if (p == 0) { |
| 1197 | goto done; |
| 1198 | } |
| 1199 | oper_bd_index = p[0]; |
| 1200 | bd_oper = vec_elt_at_index(bdm->bd_oper, oper_bd_index); |
| 1201 | vec_reset_length (bd_oper->l2fib_oper); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1202 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1203 | /* Get list of l2 fib table entries */ |
| 1204 | M(L2_FIB_TABLE_DUMP, l2_fib_table_dump); |
| 1205 | mp->bd_id = ntohl(bd_id); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1206 | S; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1207 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1208 | /* Use a control ping for synchronization */ |
| 1209 | { |
| 1210 | vl_api_control_ping_t * mp; |
| 1211 | M(CONTROL_PING, control_ping); |
| 1212 | S; |
| 1213 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1214 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1215 | WNR; |
| 1216 | if (0 != rv) { |
| 1217 | goto done; |
| 1218 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1219 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1220 | u32 count = vec_len(bd_oper->l2fib_oper); |
| 1221 | bd_l2fib_oper_t *l2fib_oper = bd_oper->l2fib_oper; |
| 1222 | |
| 1223 | l2FibArray = vppL2FibArray(env, count); |
| 1224 | for (i = 0; i < count; i++) { |
| 1225 | bd_l2fib_oper_t *l2_fib = &l2fib_oper[i]; |
| 1226 | jobject l2FibObj = l2_fib_create_object(env, l2_fib); |
| 1227 | (*env)->SetObjectArrayElement(env, l2FibArray, i, l2FibObj); |
| 1228 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1229 | |
| 1230 | done: |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1231 | vppjni_unlock (jm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1232 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1233 | return l2FibArray; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1234 | } |
| 1235 | |
| 1236 | static void |
| 1237 | vl_api_l2_fib_table_entry_t_handler (vl_api_l2_fib_table_entry_t * mp) |
| 1238 | { |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1239 | //static u8 * mac_addr; |
| 1240 | vppjni_main_t *jm = &vppjni_main; |
| 1241 | vjbd_main_t * bdm = &jm->vjbd_main; |
| 1242 | vjbd_oper_t * bd_oper; |
| 1243 | u32 bd_id, oper_bd_index; |
| 1244 | //uword mhash_val_l2fi; |
| 1245 | bd_l2fib_oper_t * l2fib_oper; |
| 1246 | l2fib_u64_mac_t * l2fe_u64_mac = (l2fib_u64_mac_t *)&mp->mac; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1247 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1248 | bd_id = ntohl (mp->bd_id); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1249 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1250 | uword *p = hash_get (bdm->oper_bd_index_by_bd_id, bd_id); |
| 1251 | if (p == 0) { |
| 1252 | return; |
| 1253 | } |
| 1254 | oper_bd_index = (jint) p[0]; |
| 1255 | bd_oper = vec_elt_at_index(bdm->bd_oper, oper_bd_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1256 | |
| 1257 | #if 0 |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1258 | vec_validate (mac_addr, MAC_ADDRESS_SIZE); |
| 1259 | memcpy (mac_addr, l2fe_u64_mac->fields.mac, MAC_ADDRESS_SIZE); |
| 1260 | mhash_val_l2fi = vec_len (bd_oper->l2fib_oper); |
| 1261 | if (mhash_elts (&bd_oper->l2fib_index_by_mac) == 0) |
| 1262 | mhash_init (&bd_oper->l2fib_index_by_mac, sizeof (u32), MAC_ADDRESS_SIZE); |
| 1263 | mhash_set_mem (&bd_oper->l2fib_index_by_mac, mac_addr, &mhash_val_l2fi, 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1264 | #endif |
| 1265 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1266 | vec_add2 (bd_oper->l2fib_oper, l2fib_oper, 1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1267 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1268 | l2fib_oper->bd_id = bd_id; |
| 1269 | l2fib_oper->mac_addr.raw = l2fib_mac_to_u64 (l2fe_u64_mac->fields.mac); |
| 1270 | l2fib_oper->sw_if_index = ntohl (mp->sw_if_index); |
| 1271 | l2fib_oper->learned = !mp->static_mac; |
| 1272 | l2fib_oper->filter = mp->filter_mac; |
| 1273 | l2fib_oper->bvi = mp->bvi_mac; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1274 | } |
| 1275 | |
Dave Wallace | bf8c15e | 2015-12-17 20:54:54 -0500 | [diff] [blame] | 1276 | static int ipAddressDump |
| 1277 | (JNIEnv * env, jobject obj, jstring interfaceName, jboolean isIPv6) |
| 1278 | { |
| 1279 | vppjni_main_t *jm = &vppjni_main; |
| 1280 | vl_api_ip_address_dump_t * mp; |
| 1281 | const char *if_name; |
| 1282 | u32 my_context_id; |
| 1283 | u32 sw_if_index; |
| 1284 | f64 timeout; |
| 1285 | uword *p; |
| 1286 | int rv = 0; |
| 1287 | |
| 1288 | if (NULL == interfaceName) { |
| 1289 | return -1; |
| 1290 | } |
| 1291 | |
| 1292 | if_name = (*env)->GetStringUTFChars (env, interfaceName, NULL); |
Robert Varga | f0f54d8 | 2016-02-10 16:01:58 +0100 | [diff] [blame] | 1293 | if (!if_name) { |
| 1294 | return -1; |
| 1295 | } |
| 1296 | |
Dave Wallace | bf8c15e | 2015-12-17 20:54:54 -0500 | [diff] [blame] | 1297 | p = hash_get_mem (jm->sw_if_index_by_interface_name, if_name); |
| 1298 | (*env)->ReleaseStringUTFChars (env, interfaceName, if_name); |
| 1299 | if (p == 0) { |
| 1300 | return -1; |
| 1301 | } |
| 1302 | sw_if_index = (u32) p[0]; |
| 1303 | |
| 1304 | rv = vppjni_sanity_check (jm); |
| 1305 | if (0 != rv) { |
| 1306 | return rv; |
| 1307 | } |
| 1308 | |
| 1309 | my_context_id = vppjni_get_context_id (jm); |
| 1310 | M(IP_ADDRESS_DUMP, ip_address_dump); |
| 1311 | mp->context = clib_host_to_net_u32 (my_context_id); |
| 1312 | mp->sw_if_index = clib_host_to_net_u32(sw_if_index); |
| 1313 | mp->is_ipv6 = isIPv6; |
| 1314 | jm->is_ipv6 = isIPv6; |
| 1315 | S; |
| 1316 | |
| 1317 | /* Use a control ping for synchronization */ |
| 1318 | { |
| 1319 | vl_api_control_ping_t * mp; |
| 1320 | M(CONTROL_PING, control_ping); |
| 1321 | S; |
| 1322 | } |
| 1323 | |
| 1324 | WNR; |
| 1325 | |
| 1326 | return rv; |
| 1327 | } |
| 1328 | |
Dave Wallace | ba474a2 | 2016-02-09 23:09:41 -0500 | [diff] [blame] | 1329 | JNIEXPORT jobjectArray JNICALL Java_org_openvpp_vppjapi_vppConn_ipv4AddressDump0 |
Dave Wallace | bf8c15e | 2015-12-17 20:54:54 -0500 | [diff] [blame] | 1330 | (JNIEnv * env, jobject obj, jstring interfaceName) |
| 1331 | { |
| 1332 | vppjni_main_t *jm = &vppjni_main; |
| 1333 | jobject returnArray = NULL; |
| 1334 | int i; |
| 1335 | |
| 1336 | vppjni_lock (jm, 18); |
| 1337 | |
| 1338 | vec_reset_length(jm->ipv4_addresses); |
| 1339 | |
| 1340 | if (0 != ipAddressDump(env, obj, interfaceName, 0)) { |
| 1341 | goto done; |
| 1342 | } |
| 1343 | |
| 1344 | u32 count = vec_len(jm->ipv4_addresses); |
| 1345 | ipv4_address_t *ipv4_address = jm->ipv4_addresses; |
| 1346 | |
Robert Varga | 81d99ac | 2016-01-30 18:30:36 +0100 | [diff] [blame] | 1347 | jobjectArray ipv4AddressArray = vppIPv4AddressArray(env, count); |
Dave Wallace | bf8c15e | 2015-12-17 20:54:54 -0500 | [diff] [blame] | 1348 | |
| 1349 | for (i = 0; i < count; i++) { |
| 1350 | ipv4_address_t *address = &ipv4_address[i]; |
| 1351 | |
| 1352 | jint ip = address->ip; |
| 1353 | jbyte prefixLength = address->prefix_length; |
| 1354 | |
Robert Varga | 81d99ac | 2016-01-30 18:30:36 +0100 | [diff] [blame] | 1355 | jobject ipv4AddressObj = vppIPv4AddressObject(env, ip, prefixLength); |
Dave Wallace | bf8c15e | 2015-12-17 20:54:54 -0500 | [diff] [blame] | 1356 | |
| 1357 | (*env)->SetObjectArrayElement(env, ipv4AddressArray, i, ipv4AddressObj); |
| 1358 | } |
| 1359 | |
| 1360 | returnArray = ipv4AddressArray; |
| 1361 | |
| 1362 | done: |
| 1363 | vppjni_unlock (jm); |
| 1364 | return returnArray; |
| 1365 | } |
| 1366 | |
Dave Wallace | ba474a2 | 2016-02-09 23:09:41 -0500 | [diff] [blame] | 1367 | JNIEXPORT jobjectArray JNICALL Java_org_openvpp_vppjapi_vppConn_ipv6AddressDump0 |
Dave Wallace | bf8c15e | 2015-12-17 20:54:54 -0500 | [diff] [blame] | 1368 | (JNIEnv * env, jobject obj, jstring interfaceName) |
| 1369 | { |
| 1370 | vppjni_main_t *jm = &vppjni_main; |
| 1371 | jobject returnArray = NULL; |
| 1372 | int i; |
| 1373 | |
| 1374 | vppjni_lock (jm, 19); |
| 1375 | |
| 1376 | vec_reset_length(jm->ipv6_addresses); |
| 1377 | |
| 1378 | if (0 != ipAddressDump(env, obj, interfaceName, 1)) { |
| 1379 | goto done; |
| 1380 | } |
| 1381 | |
| 1382 | u32 count = vec_len(jm->ipv6_addresses); |
| 1383 | ipv6_address_t *ipv6_address = jm->ipv6_addresses; |
| 1384 | |
Robert Varga | 81d99ac | 2016-01-30 18:30:36 +0100 | [diff] [blame] | 1385 | jobjectArray ipv6AddressArray = vppIPv6AddressArray(env, count); |
Dave Wallace | bf8c15e | 2015-12-17 20:54:54 -0500 | [diff] [blame] | 1386 | |
| 1387 | for (i = 0; i < count; i++) { |
| 1388 | ipv6_address_t *address = &ipv6_address[i]; |
| 1389 | |
| 1390 | jbyteArray ip = (*env)->NewByteArray(env, 16); |
| 1391 | (*env)->SetByteArrayRegion(env, ip, 0, 16, |
| 1392 | (signed char*)address->ip); |
| 1393 | |
| 1394 | jbyte prefixLength = address->prefix_length; |
| 1395 | |
Robert Varga | 81d99ac | 2016-01-30 18:30:36 +0100 | [diff] [blame] | 1396 | jobject ipv6AddressObj = vppIPv6AddressObject(env, ip, prefixLength); |
Dave Wallace | bf8c15e | 2015-12-17 20:54:54 -0500 | [diff] [blame] | 1397 | |
| 1398 | (*env)->SetObjectArrayElement(env, ipv6AddressArray, i, ipv6AddressObj); |
| 1399 | } |
| 1400 | |
| 1401 | returnArray = ipv6AddressArray; |
| 1402 | |
| 1403 | done: |
| 1404 | vppjni_unlock (jm); |
| 1405 | return returnArray; |
| 1406 | } |
| 1407 | |
| 1408 | static void vl_api_ip_address_details_t_handler (vl_api_ip_address_details_t * mp) |
| 1409 | { |
| 1410 | vppjni_main_t * jm = &vppjni_main; |
| 1411 | |
| 1412 | if (!jm->is_ipv6) { |
| 1413 | ipv4_address_t *address = 0; |
| 1414 | vec_add2(jm->ipv4_addresses, address, 1); |
Dave Wallace | 4afb281 | 2016-01-04 22:14:40 -0500 | [diff] [blame] | 1415 | memcpy(&address->ip, mp->ip, 4); |
Dave Wallace | bf8c15e | 2015-12-17 20:54:54 -0500 | [diff] [blame] | 1416 | address->prefix_length = mp->prefix_length; |
| 1417 | } else { |
| 1418 | ipv6_address_t *address = 0; |
| 1419 | vec_add2(jm->ipv6_addresses, address, 1); |
| 1420 | memcpy(address->ip, mp->ip, 16); |
| 1421 | address->prefix_length = mp->prefix_length; |
| 1422 | } |
| 1423 | } |
| 1424 | |
| 1425 | #define VXLAN_TUNNEL_INTERFACE_NAME_PREFIX "vxlan_tunnel" |
| 1426 | |
Dave Wallace | ba474a2 | 2016-02-09 23:09:41 -0500 | [diff] [blame] | 1427 | JNIEXPORT jobjectArray JNICALL Java_org_openvpp_vppjapi_vppConn_vxlanTunnelDump0 |
Dave Wallace | bf8c15e | 2015-12-17 20:54:54 -0500 | [diff] [blame] | 1428 | (JNIEnv * env, jobject obj, jint swIfIndex) |
| 1429 | { |
| 1430 | vppjni_main_t *jm = &vppjni_main; |
| 1431 | vl_api_vxlan_tunnel_dump_t * mp; |
| 1432 | jobjectArray returnArray = NULL; |
| 1433 | u32 my_context_id; |
| 1434 | f64 timeout; |
| 1435 | int rv = 0; |
| 1436 | int i; |
| 1437 | |
| 1438 | vppjni_lock (jm, 22); |
| 1439 | |
| 1440 | vec_reset_length(jm->vxlan_tunnel_details); |
| 1441 | |
| 1442 | my_context_id = vppjni_get_context_id (jm); |
| 1443 | M(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump); |
| 1444 | mp->context = clib_host_to_net_u32 (my_context_id); |
| 1445 | mp->sw_if_index = clib_host_to_net_u32 (swIfIndex); |
| 1446 | S; |
| 1447 | |
| 1448 | /* Use a control ping for synchronization */ |
| 1449 | { |
| 1450 | vl_api_control_ping_t * mp; |
| 1451 | M(CONTROL_PING, control_ping); |
| 1452 | S; |
| 1453 | } |
| 1454 | |
| 1455 | WNR; |
| 1456 | if (0 != rv) { |
| 1457 | goto done; |
| 1458 | } |
| 1459 | |
| 1460 | u32 count = vec_len(jm->vxlan_tunnel_details); |
| 1461 | |
Robert Varga | 81d99ac | 2016-01-30 18:30:36 +0100 | [diff] [blame] | 1462 | jobjectArray vxlanTunnelDetailsArray = vppVxlanTunnelDetailsArray(env, count); |
Dave Wallace | bf8c15e | 2015-12-17 20:54:54 -0500 | [diff] [blame] | 1463 | |
| 1464 | for (i = 0; i < count; i++) { |
| 1465 | vxlan_tunnel_details_t *details = &jm->vxlan_tunnel_details[i]; |
| 1466 | |
| 1467 | jint src_address = details->src_address; |
| 1468 | jint dst_address = details->dst_address; |
| 1469 | jint encap_vrf_id = details->encap_vrf_id; |
| 1470 | jint vni = details->vni; |
| 1471 | jint decap_next_index = details->decap_next_index; |
| 1472 | |
Robert Varga | 81d99ac | 2016-01-30 18:30:36 +0100 | [diff] [blame] | 1473 | jobject vxlanTunnelDetailsObj = vppVxlanTunnelDetailsObject(env, |
Dave Wallace | bf8c15e | 2015-12-17 20:54:54 -0500 | [diff] [blame] | 1474 | src_address, dst_address, encap_vrf_id, vni, decap_next_index); |
| 1475 | |
| 1476 | (*env)->SetObjectArrayElement(env, vxlanTunnelDetailsArray, i, |
| 1477 | vxlanTunnelDetailsObj); |
| 1478 | } |
| 1479 | |
| 1480 | returnArray = vxlanTunnelDetailsArray; |
| 1481 | |
| 1482 | done: |
| 1483 | vppjni_unlock (jm); |
| 1484 | return returnArray; |
| 1485 | } |
| 1486 | |
| 1487 | static void vl_api_vxlan_tunnel_details_t_handler |
| 1488 | (vl_api_vxlan_tunnel_details_t * mp) |
| 1489 | { |
| 1490 | vppjni_main_t * jm = &vppjni_main; |
| 1491 | vxlan_tunnel_details_t *tunnel_details; |
| 1492 | |
| 1493 | vec_add2(jm->vxlan_tunnel_details, tunnel_details, 1); |
| 1494 | tunnel_details->src_address = ntohl(mp->src_address); |
| 1495 | tunnel_details->dst_address = ntohl(mp->dst_address); |
| 1496 | tunnel_details->encap_vrf_id = ntohl(mp->encap_vrf_id); |
| 1497 | tunnel_details->vni = ntohl(mp->vni); |
| 1498 | tunnel_details->decap_next_index = ntohl(mp->decap_next_index); |
| 1499 | } |
| 1500 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1501 | /* cleanup handler for RX thread */ |
Robert Varga | 190efbc | 2016-02-09 17:16:36 +0100 | [diff] [blame] | 1502 | static void cleanup_rx_thread(void *arg) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1503 | { |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1504 | vppjni_main_t * jm = &vppjni_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1505 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1506 | vppjni_lock (jm, 99); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1507 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1508 | int getEnvStat = (*jm->jvm)->GetEnv(jm->jvm, (void **)&(jm->jenv), JNI_VERSION_1_6); |
| 1509 | if (getEnvStat == JNI_EVERSION) { |
| 1510 | clib_warning ("Unsupported JNI version\n"); |
| 1511 | jm->retval = -999; |
| 1512 | goto out; |
| 1513 | } else if (getEnvStat != JNI_EDETACHED) { |
| 1514 | (*jm->jvm)->DetachCurrentThread(jm->jvm); |
| 1515 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1516 | out: |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1517 | vppjni_unlock (jm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1518 | } |
| 1519 | |
| 1520 | static void |
| 1521 | vl_api_show_version_reply_t_handler (vl_api_show_version_reply_t * mp) |
| 1522 | { |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1523 | vppjni_main_t * jm = &vppjni_main; |
| 1524 | i32 retval = ntohl(mp->retval); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1525 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1526 | if (retval >= 0) { |
| 1527 | DEBUG_LOG ("show version request succeeded(%d)"); |
| 1528 | strncpy((char*)jm->program_name, (const char*)mp->program, |
| 1529 | sizeof(jm->program_name)-1); |
| 1530 | jm->program_name[sizeof(jm->program_name)-1] = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1531 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1532 | strncpy((char*)jm->build_directory, (const char*)mp->build_directory, |
| 1533 | sizeof(jm->build_directory)-1); |
| 1534 | jm->build_directory[sizeof(jm->build_directory)-1] = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1535 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1536 | strncpy((char*)jm->version, (const char*)mp->version, |
| 1537 | sizeof(jm->version)-1); |
| 1538 | jm->version[sizeof(jm->version)-1] = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1539 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1540 | strncpy((char*)jm->build_date, (const char*)mp->build_date, |
| 1541 | sizeof(jm->build_date)-1); |
| 1542 | jm->build_date[sizeof(jm->build_date)-1] = 0; |
| 1543 | } else { |
| 1544 | clib_error ("show version request failed(%d)", retval); |
| 1545 | } |
| 1546 | jm->retval = retval; |
| 1547 | jm->result_ready = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1548 | } |
| 1549 | |
| 1550 | static void vl_api_want_stats_reply_t_handler (vl_api_want_stats_reply_t * mp) |
| 1551 | { |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1552 | vppjni_main_t * jm = &vppjni_main; |
| 1553 | jm->retval = mp->retval; // FIXME: vpp api does not do ntohl on this retval |
| 1554 | jm->result_ready = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1555 | } |
| 1556 | |
| 1557 | // control ping needs to be very first thing called |
| 1558 | // to attach rx thread to java thread |
| 1559 | static void vl_api_control_ping_reply_t_handler |
| 1560 | (vl_api_control_ping_reply_t * mp) |
| 1561 | { |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1562 | vppjni_main_t * jm = &vppjni_main; |
| 1563 | i32 retval = ntohl(mp->retval); |
| 1564 | jm->retval = retval; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1565 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1566 | // attach to java thread if not attached |
| 1567 | int getEnvStat = (*jm->jvm)->GetEnv(jm->jvm, (void **)&(jm->jenv), JNI_VERSION_1_6); |
| 1568 | if (getEnvStat == JNI_EDETACHED) { |
| 1569 | if ((*jm->jvm)->AttachCurrentThread(jm->jvm, (void **)&(jm->jenv), NULL) != 0) { |
| 1570 | clib_warning("Failed to attach thread\n"); |
| 1571 | jm->retval = -999; |
| 1572 | goto out; |
| 1573 | } |
| 1574 | |
| 1575 | // workaround as we can't use pthread_cleanup_push |
| 1576 | pthread_key_create(&jm->cleanup_rx_thread_key, cleanup_rx_thread); |
| 1577 | // destructor is only called if the value of key is non null |
| 1578 | pthread_setspecific(jm->cleanup_rx_thread_key, (void *)1); |
| 1579 | } else if (getEnvStat == JNI_EVERSION) { |
| 1580 | clib_warning ("Unsupported JNI version\n"); |
| 1581 | jm->retval = -999; |
| 1582 | goto out; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1583 | } |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1584 | // jm->jenv is now stable global reference that can be reused (only within RX thread) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1585 | |
Dave Wallace | bf8c15e | 2015-12-17 20:54:54 -0500 | [diff] [blame] | 1586 | #if 0 |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1587 | // ! callback system removed for now |
| 1588 | // |
| 1589 | // get issuer msg-id |
| 1590 | p = hash_get (jm->ping_hash, context); |
| 1591 | if (p != 0) { // ping marks end of some dump call |
| 1592 | JNIEnv *env = jm->jenv; |
| 1593 | u16 msg_id = (u16)p[0]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1594 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1595 | // we will no longer need this |
| 1596 | hash_unset (jm->ping_hash, context); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1597 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1598 | // get original caller obj |
| 1599 | p = hash_get (jm->callback_hash, context); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1600 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1601 | if (p == 0) // don't have callback stored |
| 1602 | goto out; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1603 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1604 | jobject obj = (jobject)p[0]; // object that called original call |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1605 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1606 | switch (msg_id) { |
| 1607 | case VL_API_SW_INTERFACE_DUMP: |
| 1608 | if (0 != sw_if_dump_call_all_callbacks(obj)) { |
| 1609 | goto out2; |
| 1610 | } |
| 1611 | break; |
| 1612 | default: |
| 1613 | clib_warning("Unhandled control ping issuer msg-id: %d", msg_id); |
| 1614 | goto out2; |
| 1615 | break; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1616 | } |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1617 | out2: |
| 1618 | // free the saved obj |
| 1619 | hash_unset (jm->callback_hash, context); |
| 1620 | // delete global reference |
| 1621 | (*env)->DeleteGlobalRef(env, obj); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1622 | } |
Dave Wallace | bf8c15e | 2015-12-17 20:54:54 -0500 | [diff] [blame] | 1623 | #endif |
| 1624 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1625 | out: |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1626 | jm->result_ready = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1627 | } |
| 1628 | |
| 1629 | #define VPPJNI_DEBUG_COUNTERS 0 |
| 1630 | |
| 1631 | static void vl_api_vnet_interface_counters_t_handler |
| 1632 | (vl_api_vnet_interface_counters_t *mp) |
| 1633 | { |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1634 | vppjni_main_t *jm = &vppjni_main; |
| 1635 | CLIB_UNUSED(char *counter_name); |
| 1636 | u32 count, sw_if_index; |
| 1637 | int i; |
| 1638 | static sw_interface_stats_t empty_stats = {0, }; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1639 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1640 | vppjni_lock (jm, 12); |
| 1641 | count = ntohl (mp->count); |
| 1642 | sw_if_index = ntohl (mp->first_sw_if_index); |
| 1643 | if (mp->is_combined == 0) { |
| 1644 | u64 * vp, v; |
| 1645 | vp = (u64 *) mp->data; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1646 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1647 | for (i = 0; i < count; i++) { |
| 1648 | sw_interface_details_t *sw_if = NULL; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1649 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1650 | v = clib_mem_unaligned (vp, u64); |
| 1651 | v = clib_net_to_host_u64 (v); |
| 1652 | vp++; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1653 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1654 | if (sw_if_index < vec_len(jm->sw_if_table)) |
| 1655 | sw_if = vec_elt_at_index(jm->sw_if_table, sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1656 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1657 | if (sw_if /* && (sw_if->admin_up_down == 1)*/ && sw_if->interface_name[0] != 0) { |
| 1658 | vec_validate_init_empty(jm->sw_if_stats_by_sw_if_index, sw_if_index, empty_stats); |
| 1659 | sw_interface_stats_t * s = vec_elt_at_index(jm->sw_if_stats_by_sw_if_index, sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1660 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1661 | s->sw_if_index = sw_if_index; |
| 1662 | s->valid = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1663 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1664 | switch (mp->vnet_counter_type) { |
| 1665 | case VNET_INTERFACE_COUNTER_DROP: |
| 1666 | counter_name = "drop"; |
| 1667 | s->rx.pkts.discard = v; |
| 1668 | break; |
| 1669 | case VNET_INTERFACE_COUNTER_PUNT: |
| 1670 | counter_name = "punt"; |
| 1671 | s->rx.pkts.unknown_proto = v; |
| 1672 | break; |
| 1673 | case VNET_INTERFACE_COUNTER_IP4: |
| 1674 | counter_name = "ip4"; |
| 1675 | s->rx.pkts.ip4 = v; |
| 1676 | break; |
| 1677 | case VNET_INTERFACE_COUNTER_IP6: |
| 1678 | counter_name = "ip6"; |
| 1679 | s->rx.pkts.ip6 = v; |
| 1680 | break; |
| 1681 | case VNET_INTERFACE_COUNTER_RX_NO_BUF: |
| 1682 | counter_name = "rx-no-buf"; |
| 1683 | s->rx.pkts.fifo_full = v; |
| 1684 | break; |
| 1685 | case VNET_INTERFACE_COUNTER_RX_MISS: |
| 1686 | counter_name = "rx-miss"; |
| 1687 | s->rx.pkts.miss = v; |
| 1688 | break; |
| 1689 | case VNET_INTERFACE_COUNTER_RX_ERROR: |
| 1690 | counter_name = "rx-error"; |
| 1691 | s->rx.pkts.error = v; |
| 1692 | break; |
| 1693 | case VNET_INTERFACE_COUNTER_TX_ERROR: |
| 1694 | counter_name = "tx-error (fifo-full)"; |
| 1695 | s->tx.pkts.fifo_full = v; |
| 1696 | break; |
| 1697 | default: |
| 1698 | counter_name = "bogus"; |
| 1699 | break; |
| 1700 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1701 | |
| 1702 | #if VPPJNI_DEBUG_COUNTERS == 1 |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1703 | clib_warning ("%s (%d): %s (%lld)\n", sw_if->interface_name, s->sw_if_index, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1704 | counter_name, v); |
| 1705 | #endif |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1706 | } |
| 1707 | sw_if_index++; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1708 | } |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1709 | } else { |
| 1710 | vlib_counter_t *vp; |
| 1711 | u64 packets, bytes; |
| 1712 | vp = (vlib_counter_t *) mp->data; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1713 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1714 | for (i = 0; i < count; i++) { |
| 1715 | sw_interface_details_t *sw_if = NULL; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1716 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1717 | packets = clib_mem_unaligned (&vp->packets, u64); |
| 1718 | packets = clib_net_to_host_u64 (packets); |
| 1719 | bytes = clib_mem_unaligned (&vp->bytes, u64); |
| 1720 | bytes = clib_net_to_host_u64 (bytes); |
| 1721 | vp++; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1722 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1723 | if (sw_if_index < vec_len(jm->sw_if_table)) |
| 1724 | sw_if = vec_elt_at_index(jm->sw_if_table, sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1725 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1726 | if (sw_if /* && (sw_if->admin_up_down == 1) */ && sw_if->interface_name[0] != 0) { |
| 1727 | vec_validate_init_empty(jm->sw_if_stats_by_sw_if_index, sw_if_index, empty_stats); |
| 1728 | sw_interface_stats_t * s = vec_elt_at_index(jm->sw_if_stats_by_sw_if_index, sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1729 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1730 | s->valid = 1; |
| 1731 | s->sw_if_index = sw_if_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1732 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1733 | switch (mp->vnet_counter_type) { |
| 1734 | case VNET_INTERFACE_COUNTER_RX: |
| 1735 | s->rx.pkts.unicast = packets; |
| 1736 | s->rx.octets = bytes; |
| 1737 | counter_name = "rx"; |
| 1738 | break; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1739 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1740 | case VNET_INTERFACE_COUNTER_TX: |
| 1741 | s->tx.pkts.unicast = packets; |
| 1742 | s->tx.octets = bytes; |
| 1743 | counter_name = "tx"; |
| 1744 | break; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1745 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1746 | default: |
| 1747 | counter_name = "bogus"; |
| 1748 | break; |
| 1749 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1750 | |
| 1751 | #if VPPJNI_DEBUG_COUNTERS == 1 |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1752 | clib_warning ("%s (%d): %s.packets %lld\n", |
| 1753 | sw_if->interface_name, |
| 1754 | sw_if_index, counter_name, packets); |
| 1755 | clib_warning ("%s (%d): %s.bytes %lld\n", |
| 1756 | sw_if->interface_name, |
| 1757 | sw_if_index, counter_name, bytes); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1758 | #endif |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1759 | } |
| 1760 | sw_if_index++; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1761 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1762 | } |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1763 | vppjni_unlock (jm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1764 | } |
| 1765 | |
| 1766 | jint JNI_OnLoad(JavaVM *vm, void *reserved) { |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1767 | vppjni_main_t * jm = &vppjni_main; |
| 1768 | JNIEnv* env; |
| 1769 | if ((*vm)->GetEnv(vm, (void**) &env, JNI_VERSION_1_6) != JNI_OK) { |
| 1770 | return JNI_ERR; |
| 1771 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1772 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1773 | if (vppjni_init(env) != 0) { |
| 1774 | return JNI_ERR; |
| 1775 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1776 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1777 | jm->jvm = vm; |
| 1778 | return JNI_VERSION_1_6; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | void JNI_OnUnload(JavaVM *vm, void *reserved) { |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1782 | vppjni_main_t * jm = &vppjni_main; |
| 1783 | JNIEnv* env; |
| 1784 | if ((*vm)->GetEnv(vm, (void**) &env, JNI_VERSION_1_6) != JNI_OK) { |
| 1785 | return; |
| 1786 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1787 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1788 | vppjni_uninit(env); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1789 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1790 | jm->jenv = NULL; |
| 1791 | jm->jvm = NULL; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1792 | } |
| 1793 | |
| 1794 | #define foreach_vpe_api_msg \ |
| 1795 | _(CONTROL_PING_REPLY, control_ping_reply) \ |
| 1796 | _(SW_INTERFACE_DETAILS, sw_interface_details) \ |
| 1797 | _(SHOW_VERSION_REPLY, show_version_reply) \ |
| 1798 | _(WANT_STATS_REPLY, want_stats_reply) \ |
| 1799 | _(VNET_INTERFACE_COUNTERS, vnet_interface_counters) \ |
| 1800 | _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \ |
| 1801 | _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \ |
| 1802 | _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \ |
Dave Wallace | bf8c15e | 2015-12-17 20:54:54 -0500 | [diff] [blame] | 1803 | _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \ |
| 1804 | _(IP_ADDRESS_DETAILS, ip_address_details) \ |
| 1805 | _(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1806 | |
| 1807 | static int connect_to_vpe(char *name) |
| 1808 | { |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1809 | vppjni_main_t * jm = &vppjni_main; |
| 1810 | api_main_t * am = &api_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1811 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1812 | if (vl_client_connect_to_vlib("/vpe-api", name, 32) < 0) |
| 1813 | return -1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1814 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1815 | jm->my_client_index = am->my_client_index; |
| 1816 | jm->vl_input_queue = am->shmem_hdr->vl_input_queue; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1817 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1818 | #define _(N,n) \ |
| 1819 | vl_msg_api_set_handlers(VL_API_##N, #n, \ |
| 1820 | vl_api_##n##_t_handler, \ |
| 1821 | vl_noop_handler, \ |
| 1822 | vl_api_##n##_t_endian, \ |
| 1823 | vl_api_##n##_t_print, \ |
| 1824 | sizeof(vl_api_##n##_t), 1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1825 | foreach_vpe_api_msg; |
| 1826 | #undef _ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1827 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1828 | return 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1829 | } |
| 1830 | |
| 1831 | /* Format an IP6 address. */ |
| 1832 | u8 * format_ip6_address (u8 * s, va_list * args) |
| 1833 | { |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1834 | ip6_address_t * a = va_arg (*args, ip6_address_t *); |
| 1835 | u32 max_zero_run = 0, this_zero_run = 0; |
| 1836 | int max_zero_run_index = -1, this_zero_run_index=0; |
| 1837 | int in_zero_run = 0, i; |
| 1838 | int last_double_colon = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1839 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1840 | /* Ugh, this is a pain. Scan forward looking for runs of 0's */ |
| 1841 | for (i = 0; i < ARRAY_LEN (a->as_u16); i++) { |
| 1842 | if (a->as_u16[i] == 0) { |
| 1843 | if (in_zero_run) { |
| 1844 | this_zero_run++; |
| 1845 | } else { |
| 1846 | in_zero_run = 1; |
| 1847 | this_zero_run =1; |
| 1848 | this_zero_run_index = i; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1849 | } |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1850 | } else { |
| 1851 | if (in_zero_run) { |
| 1852 | /* offer to compress the biggest run of > 1 zero */ |
| 1853 | if (this_zero_run > max_zero_run && this_zero_run > 1) { |
| 1854 | max_zero_run_index = this_zero_run_index; |
| 1855 | max_zero_run = this_zero_run; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1856 | } |
| 1857 | } |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1858 | in_zero_run = 0; |
| 1859 | this_zero_run = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1860 | } |
| 1861 | } |
| 1862 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1863 | if (in_zero_run) { |
| 1864 | if (this_zero_run > max_zero_run && this_zero_run > 1) { |
| 1865 | max_zero_run_index = this_zero_run_index; |
| 1866 | max_zero_run = this_zero_run; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1867 | } |
| 1868 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1869 | |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1870 | for (i = 0; i < ARRAY_LEN (a->as_u16); i++) { |
| 1871 | if (i == max_zero_run_index) { |
| 1872 | s = format (s, "::"); |
| 1873 | i += max_zero_run - 1; |
| 1874 | last_double_colon = 1; |
| 1875 | } else { |
| 1876 | s = format (s, "%s%x", |
| 1877 | (last_double_colon || i == 0) ? "" : ":", |
| 1878 | clib_net_to_host_u16 (a->as_u16[i])); |
| 1879 | last_double_colon = 0; |
| 1880 | } |
| 1881 | } |
| 1882 | |
| 1883 | return s; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1884 | } |
| 1885 | |
| 1886 | /* Format an IP4 address. */ |
| 1887 | u8 * format_ip4_address (u8 * s, va_list * args) |
| 1888 | { |
Robert Varga | d0f9209 | 2016-02-10 14:39:57 +0100 | [diff] [blame] | 1889 | u8 * a = va_arg (*args, u8 *); |
| 1890 | return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1891 | } |
| 1892 | |
| 1893 | |