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