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