/*
 * Copyright (c) 2015 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include <vnet/vnet.h>

#define vl_api_version(n,v) static u32 vpe_api_version = (v);
#include <api/vpe.api.h>
#undef vl_api_version

#include <jni.h>
#include <japi/vppjni.h>
#include <japi/vppjni_bridge_domain.h>
#include <japi/org_openvpp_vppjapi_vppConn.h>
#include <japi/org_openvpp_vppjapi_vppApi.h>

#include <api/vpe_msg_enum.h>
#define vl_typedefs             /* define message structures */
#include <api/vpe_all_api_h.h> 
#undef vl_typedefs

#define vl_endianfun 
#include <api/vpe_all_api_h.h> 
#undef vl_endianfun

/* instantiate all the print functions we know about */
#define vl_print(handle, ...)
#define vl_printfun
#include <api/vpe_all_api_h.h>
#undef vl_printfun

#define VPPJNI_DEBUG 0

#if VPPJNI_DEBUG == 1
  #define DEBUG_LOG(...) clib_warning(__VA_ARGS__)
#else
  #define DEBUG_LOG(...)
#endif

static int connect_to_vpe(char *name);

/* 
 * The Java runtime isn't compile w/ -fstack-protector,
 * so we have to supply missing external references for the
 * regular vpp libraries. Weak reference in case folks get religion
 * at a later date...
 */
void __stack_chk_guard (void) __attribute__((weak));
void __stack_chk_guard (void) {  }

void vl_client_add_api_signatures (vl_api_memclnt_create_t *mp) 
{
    /* 
     * Send the main API signature in slot 0. This bit of code must
     * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
     */
    mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version);
}

/* Note: non-static, called once to set up the initial intfc table */
static int sw_interface_dump (vppjni_main_t * jm)
{
    vl_api_sw_interface_dump_t *mp;
    f64 timeout;
    hash_pair_t * p;
    name_sort_t * nses = 0, * ns;
    sw_interface_subif_t * sub = NULL;

    /* Toss the old name table */
    hash_foreach_pair (p, jm->sw_if_index_by_interface_name, 
    ({
        vec_add2 (nses, ns, 1);
        ns->name = (u8 *)(p->key);
        ns->value = (u32) p->value[0];
    }));

    hash_free (jm->sw_if_index_by_interface_name);

    vec_foreach (ns, nses)
        vec_free (ns->name);

    vec_free (nses);

    vec_foreach (sub, jm->sw_if_subif_table) {
        vec_free (sub->interface_name);
    }
    vec_free (jm->sw_if_subif_table);

    /* recreate the interface name hash table */
    jm->sw_if_index_by_interface_name 
      = hash_create_string (0, sizeof(uword));

    /* Get list of ethernets */
    M(SW_INTERFACE_DUMP, sw_interface_dump);
    mp->name_filter_valid = 1;
    strncpy ((char *) mp->name_filter, "Ether", sizeof(mp->name_filter-1)); 
    S;

    /* and local / loopback interfaces */
    M(SW_INTERFACE_DUMP, sw_interface_dump);
    mp->name_filter_valid = 1;
    strncpy ((char *) mp->name_filter, "lo", sizeof(mp->name_filter-1)); 
    S;

    /* and vxlan tunnel interfaces */
    M(SW_INTERFACE_DUMP, sw_interface_dump);
    mp->name_filter_valid = 1;
    strncpy ((char *) mp->name_filter, "vxlan", sizeof(mp->name_filter-1)); 
    S;

    /* and tap tunnel interfaces */
    M(SW_INTERFACE_DUMP, sw_interface_dump);
    mp->name_filter_valid = 1;
    strncpy ((char *) mp->name_filter, "tap", sizeof(mp->name_filter-1)); 
    S;

    /* and l2tpv3 tunnel interfaces */
    M(SW_INTERFACE_DUMP, sw_interface_dump);
    mp->name_filter_valid = 1;
    strncpy ((char *) mp->name_filter, "l2tpv3_tunnel", 
             sizeof(mp->name_filter-1));
    S;

    /* Use a control ping for synchronization */
    {
        vl_api_control_ping_t * mp;
        M(CONTROL_PING, control_ping);
        S;
    }
    W;
}

JNIEXPORT jobject JNICALL Java_org_openvpp_vppjapi_vppConn_getVppVersion
  (JNIEnv *env, jobject obj)
{
  vppjni_main_t * jm = &vppjni_main;
  jmethodID constr;
  // TODO: cache this
  jclass cls = (*env)->FindClass(env, "org/openvpp/vppjapi/vppVersion");
  if ((*env)->ExceptionCheck(env)) {
      (*env)->ExceptionDescribe(env);
      return NULL;
  }

  constr = (*env)->GetMethodID(env, cls, "<init>", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
  if ((*env)->ExceptionCheck(env)) {
      (*env)->ExceptionDescribe(env);
      return NULL;
  }

  vppjni_lock (jm, 11);
  jstring progName = (*env)->NewStringUTF(env, (char *)jm->program_name);
  jstring buildDir = (*env)->NewStringUTF(env, (char *)jm->build_directory);
  jstring version = (*env)->NewStringUTF(env, (char *)jm->version);
  jstring buildDate = (*env)->NewStringUTF(env, (char *)jm->build_date);
  vppjni_unlock (jm);

  return (*env)->NewObject(env, cls, constr, progName, buildDir, version, buildDate);
}

static int jm_show_version (vppjni_main_t *jm)
{
  int rv;
  vl_api_show_version_t *mp;
  f64 timeout;

  vppjni_lock (jm, 10);
  M(SHOW_VERSION, show_version);

  S;
  vppjni_unlock (jm);
  WNR;
  return rv;
}

static int jm_stats_enable_disable (vppjni_main_t *jm, u8 enable)
{
  vl_api_want_stats_t * mp;
  f64 timeout;
  int rv;

  vppjni_lock (jm, 13);

  M(WANT_STATS, want_stats);

  mp->enable_disable = enable;

  S;
  vppjni_unlock (jm);
  WNR;

  // already subscribed / already disabled (it's ok)
  if (rv == -2 || rv == -3)
      rv = 0;
  return rv;
}

JNIEXPORT jint JNICALL Java_org_openvpp_vppjapi_vppConn_setInterfaceDescription
  (JNIEnv *env, jobject obj, jstring ifName, jstring ifDesc)
{
    int rv = 0;
    vppjni_main_t * jm = &vppjni_main;
    uword * p;
    u32 sw_if_index = ~0;
    sw_if_config_t *cfg;

    const char *if_name_str = (*env)->GetStringUTFChars (env, ifName, 0);
    const char *if_desc_str = (*env)->GetStringUTFChars (env, ifDesc, 0);

    vppjni_lock (jm, 23);

    p = hash_get_mem (jm->sw_if_index_by_interface_name, if_name_str);
    if (p == 0) {
        rv = -1;
        goto out;
    }
    sw_if_index = (jint) p[0];

    u8 *if_desc = 0;
    vec_validate_init_c_string (if_desc, if_desc_str, strlen(if_desc_str));
    (*env)->ReleaseStringUTFChars (env, ifDesc, if_desc_str);

    p = hash_get (jm->sw_if_config_by_sw_if_index, sw_if_index);
    if (p != 0) {
        cfg = (sw_if_config_t *) (p[0]);
        if (cfg->desc)
            vec_free(cfg->desc);
    }
    else {
        cfg = (sw_if_config_t *) clib_mem_alloc(sizeof(sw_if_config_t));
        hash_set (jm->sw_if_config_by_sw_if_index, sw_if_index, cfg);
    }

    cfg->desc = if_desc;

out:
    (*env)->ReleaseStringUTFChars (env, ifName, if_name_str);
    vppjni_unlock (jm);
    return rv;
}

JNIEXPORT jstring JNICALL Java_org_openvpp_vppjapi_vppConn_getInterfaceDescription
(JNIEnv * env, jobject obj, jstring ifName)
{
    vppjni_main_t * jm = &vppjni_main;
    u32 sw_if_index = ~0;
    uword * p;
    const char *if_name_str = (*env)->GetStringUTFChars (env, ifName, 0);
    jstring ifDesc = NULL;

    vppjni_lock (jm, 24);
    p = hash_get_mem (jm->sw_if_index_by_interface_name, if_name_str);
    if (p == 0)
        goto out;

    sw_if_index = (jint) p[0];

    p = hash_get (jm->sw_if_config_by_sw_if_index, sw_if_index);
    if (p == 0)
        goto out;

    sw_if_config_t *cfg = (sw_if_config_t *) (p[0]);
    u8 * s = format (0, "%s%c", cfg->desc, 0);
    ifDesc = (*env)->NewStringUTF(env, (char *)s);

out:
    vppjni_unlock (jm);

    return ifDesc;
}

JNIEXPORT jint JNICALL Java_org_openvpp_vppjapi_vppConn_clientConnect
  (JNIEnv *env, jobject obj, jstring clientName)
{
  int rv;
  const char *client_name;
  void vl_msg_reply_handler_hookup(void);
  vppjni_main_t * jm = &vppjni_main;
  api_main_t * am = &api_main;
  u8 * heap;
  mheap_t * h; 
  f64 timeout;
      
  /* 
   * Bail out now if we're not running as root
   */
  if (geteuid() != 0)
    return -1;

  if (jm->is_connected)
      return -2;

  if (jm->heap == 0)
    clib_mem_init (0, 128<<20);

  heap = clib_mem_get_per_cpu_heap();
  h = mheap_header (heap);

  client_name = (*env)->GetStringUTFChars (env, clientName, 0);

  clib_time_init (&jm->clib_time);

  rv = connect_to_vpe ((char *) client_name);

  if (rv < 0)
    clib_warning ("connection failed, rv %d", rv);

  (*env)->ReleaseStringUTFChars (env, clientName, client_name);

  if (rv == 0)
    {
      vl_msg_reply_handler_hookup ();
      jm->is_connected = 1;
      /* make the main heap thread-safe */
      h->flags |= MHEAP_FLAG_THREAD_SAFE;

      jm->reply_hash = hash_create (0, sizeof (uword));
      //jm->callback_hash = hash_create (0, sizeof (uword));
      //jm->ping_hash = hash_create (0, sizeof (uword));
      jm->api_main = am;
      vjbd_main_init(&jm->vjbd_main);
      jm->sw_if_index_by_interface_name = 
        hash_create_string (0, sizeof (uword));
      jm->sw_if_config_by_sw_if_index =
        hash_create (0, sizeof (uword));

      {
        // call control ping first to attach rx thread to java thread
        vl_api_control_ping_t * mp;
        M(CONTROL_PING, control_ping);
        S;
        WNR;

        if (rv != 0) {
            clib_warning ("first control ping failed: %d", rv);
        }
      }
      rv = jm_show_version(jm);
      if (rv != 0)
          clib_warning ("unable to retrieve vpp version (rv: %d)", rv);
      rv = sw_interface_dump(jm);
      if (rv != 0)
          clib_warning ("unable to retrieve interface list (rv: %d)", rv);
      rv = jm_stats_enable_disable(jm, 1);
      if (rv != 0)
          clib_warning ("unable to subscribe to stats (rv: %d)", rv);
    }
  DEBUG_LOG ("clientConnect result: %d", rv);

  return rv;
}

JNIEXPORT void JNICALL Java_org_openvpp_vppjapi_vppConn_clientDisconnect
  (JNIEnv *env, jobject obj)
{
  u8 *save_heap;
  vppjni_main_t * jm = &vppjni_main;
  vl_client_disconnect_from_vlib();
  
  save_heap = jm->heap;
  memset (jm, 0, sizeof (*jm));
  jm->heap = save_heap;
}

void vl_api_generic_reply_handler (vl_api_generic_reply_t *mp)
{
  api_main_t * am = &api_main;
  u16 msg_id = clib_net_to_host_u16 (mp->_vl_msg_id);
  trace_cfg_t *cfgp;
  i32 retval = clib_net_to_host_u32 (mp->retval);
  int total_bytes = sizeof(mp);
  vppjni_main_t * jm = &vppjni_main;
  u8 * saved_reply = 0;
  u32 context = clib_host_to_net_u32 (mp->context);
    
  cfgp = am->api_trace_cfg + msg_id;

  if (!cfgp) 
    clib_warning ("msg id %d: no trace configuration\n", msg_id);
  else
    total_bytes = cfgp->size;

  jm->context_id_received = context;

  DEBUG_LOG ("Received generic reply for msg id %d", msg_id);

  /* A generic reply, successful, we're done */
  if (retval >= 0 && total_bytes == sizeof(*mp))
    return;

  /* Save the reply */
  vec_validate (saved_reply, total_bytes - 1);
  memcpy (saved_reply, mp, total_bytes);

  vppjni_lock (jm, 2);
  hash_set (jm->reply_hash, context, saved_reply);
  jm->saved_reply_count ++;
  vppjni_unlock (jm);
}

JNIEXPORT jint JNICALL Java_org_openvpp_vppjapi_vppConn_getRetval
(JNIEnv * env, jobject obj, jint context, jint release)
{
  vppjni_main_t * jm = &vppjni_main;
  vl_api_generic_reply_t * mp;
  uword * p;
  int rv = 0;

  /* Dunno yet? */
  if (context > jm->context_id_received)
    return (VNET_API_ERROR_RESPONSE_NOT_READY);

  vppjni_lock (jm, 1);
  p = hash_get (jm->reply_hash, context);

  /* 
   * Two cases: a generic "yes" reply - won't be in the hash table
   * or "no", or "more data" which will be in the table.
   */
  if (p == 0)
    goto out;
      
  mp = (vl_api_generic_reply_t *) (p[0]);
  rv = clib_net_to_host_u32 (mp->retval);

  if (release)
    {
      u8 * free_me = (u8 *) mp;
      vec_free (free_me);
      hash_unset (jm->reply_hash, context);
      jm->saved_reply_count --;
    }

out:
  vppjni_unlock (jm);
  return (rv);
}

static int
name_sort_cmp (void * a1, void * a2)
{
  name_sort_t * n1 = a1;
  name_sort_t * n2 = a2;

  return strcmp ((char *)n1->name, (char *)n2->name);
}

JNIEXPORT jstring JNICALL Java_org_openvpp_vppjapi_vppConn_getInterfaceList
  (JNIEnv * env, jobject obj, jstring name_filter)
{
  vppjni_main_t * jm = &vppjni_main;
  jstring rv;
  hash_pair_t * p;
  name_sort_t * nses = 0, * ns;
  const char *this_name;
  const char * nf = (*env)->GetStringUTFChars (env, name_filter, NULL);
  u8 * s = 0;
  char *strcasestr (const char *, const char *);

  vppjni_lock (jm, 4);
  
  hash_foreach_pair (p, jm->sw_if_index_by_interface_name, 
    ({
      this_name = (const char *)(p->key);
      if (strlen (nf) == 0 || strcasestr (this_name, nf))
        {
          vec_add2 (nses, ns, 1);
          ns->name = (u8 *)(p->key);
          ns->value = (u32) p->value[0];
        }
    }));

  vec_sort_with_function (nses, name_sort_cmp);

  vec_foreach (ns, nses)
    s = format (s, "%s: %d, ", ns->name, ns->value);

  _vec_len (s) = vec_len (s) - 2;
  vec_terminate_c_string (s);
  vppjni_unlock (jm);

  vec_free (nses);

  (*env)->ReleaseStringUTFChars (env, name_filter, nf);

  rv = (*env)->NewStringUTF (env, (char *) s);
  vec_free (s);
  
  return rv;
}

JNIEXPORT jint JNICALL Java_org_openvpp_vppjapi_vppConn_swIfIndexFromName
  (JNIEnv * env, jobject obj, jstring interfaceName)
{
  vppjni_main_t * jm = &vppjni_main;
  jint rv = -1;
  const char * if_name = (*env)->GetStringUTFChars (env, interfaceName, NULL);
  uword * p;

  vppjni_lock (jm, 5);

  p = hash_get_mem (jm->sw_if_index_by_interface_name, if_name);

  if (p != 0)
      rv = (jint) p[0];

  vppjni_unlock (jm);
  
  (*env)->ReleaseStringUTFChars (env, interfaceName, if_name);

  return rv;
}

JNIEXPORT jobject JNICALL Java_org_openvpp_vppjapi_vppConn_getInterfaceCounters
(JNIEnv * env, jobject obj, jint swIfIndex)
{
    vppjni_main_t * jm = &vppjni_main;
    sw_interface_stats_t *s;
    u32 sw_if_index = swIfIndex;
    jmethodID constr;
    jobject result = NULL;

    // TODO: cache this
    jclass cls = (*env)->FindClass(env, "org/openvpp/vppjapi/vppInterfaceCounters");
    if ((*env)->ExceptionCheck(env)) {
        (*env)->ExceptionDescribe(env);
        return NULL;
    }

    constr = (*env)->GetMethodID(env, cls, "<init>", "(JJJJJJJJJJJJJJJJJJJJJJ)V");
    if ((*env)->ExceptionCheck(env)) {
        (*env)->ExceptionDescribe(env);
        return NULL;
    }

    vppjni_lock (jm, 16);

    if (sw_if_index >= vec_len(jm->sw_if_stats_by_sw_if_index)) {
        goto out;
    }
    s = &jm->sw_if_stats_by_sw_if_index[sw_if_index];
    if (!s->valid) {
        goto out;
    }

    result = (*env)->NewObject(env, cls, constr,
            s->rx.octets, s->rx.pkts.ip4, s->rx.pkts.ip6, s->rx.pkts.unicast,
            s->rx.pkts.multicast, s->rx.pkts.broadcast, s->rx.pkts.discard,
            s->rx.pkts.fifo_full, s->rx.pkts.error, s->rx.pkts.unknown_proto,
            s->rx.pkts.miss,
            s->tx.octets, s->tx.pkts.ip4, s->tx.pkts.ip6, s->tx.pkts.unicast,
            s->tx.pkts.multicast, s->tx.pkts.broadcast, s->tx.pkts.discard,
            s->tx.pkts.fifo_full, s->tx.pkts.error, s->tx.pkts.unknown_proto,
            s->tx.pkts.miss);

out:
    vppjni_unlock (jm);
    return result;
}

JNIEXPORT jstring JNICALL Java_org_openvpp_vppjapi_vppConn_interfaceNameFromSwIfIndex
(JNIEnv * env, jobject obj, jint swIfIndex)
{
    vppjni_main_t * jm = &vppjni_main;
    sw_interface_details_t *sw_if_details;
    u32 sw_if_index;
    jstring ifname = NULL;

    vppjni_lock (jm, 8);

    sw_if_index = swIfIndex;

    if (sw_if_index >= vec_len(jm->sw_if_table)) {
        goto out;
    }
    sw_if_details = &jm->sw_if_table[sw_if_index];
    if (!sw_if_details->valid) {
        goto out;
    }

    u8 * s = format (0, "%s%c", sw_if_details->interface_name, 0);
    ifname = (*env)->NewStringUTF(env, (char *)s);

out:
    vppjni_unlock (jm);

    return ifname;
}

JNIEXPORT void JNICALL Java_org_openvpp_vppjapi_vppConn_clearInterfaceTable
(JNIEnv * env, jobject obj)
{
    vppjni_main_t * jm = &vppjni_main;

    vppjni_lock (jm, 21);

    vec_reset_length(jm->sw_if_table);

    vppjni_unlock (jm);
}

static jobjectArray sw_if_dump_get_interfaces ();

JNIEXPORT jobjectArray JNICALL Java_org_openvpp_vppjapi_vppConn_swInterfaceDump
(JNIEnv * env, jobject obj, jbyte name_filter_valid, jbyteArray name_filter)
{
    vppjni_main_t *jm = &vppjni_main;
    f64 timeout;
    vl_api_sw_interface_dump_t * mp;
    u32 my_context_id;
    int rv;
    rv = vppjni_sanity_check (jm);
    if (rv) {
        clib_warning("swInterfaceDump sanity_check rv = %d", rv);
        return NULL;
    }

    vppjni_lock (jm, 7);
    my_context_id = vppjni_get_context_id (jm);
    jbyte * name_filterP = (*env)->GetByteArrayElements (env, name_filter, NULL);
    int cnt = (*env)->GetArrayLength (env, name_filter);

    M(SW_INTERFACE_DUMP, sw_interface_dump);
    mp->context = clib_host_to_net_u32 (my_context_id);
    mp->name_filter_valid = name_filter_valid;

    if (cnt > sizeof(mp->name_filter))
        cnt = sizeof(mp->name_filter);

    memcpy ((char *) mp->name_filter, name_filterP, cnt);
    (*env)->ReleaseByteArrayElements (env, name_filter, name_filterP, 0);

    DEBUG_LOG ("interface filter (%d, %s, len: %d)", mp->name_filter_valid, (char *)mp->name_filter, cnt);

    jm->collect_indices = 1;

    S;
    {
        // now send control ping so we know when it ends
        vl_api_control_ping_t * mp;
        M(CONTROL_PING, control_ping);
        mp->context = clib_host_to_net_u32 (my_context_id);

        S;
    }
    vppjni_unlock (jm);
    WNR;

    vppjni_lock (jm, 7);
    jobjectArray result = sw_if_dump_get_interfaces(env);
    vppjni_unlock (jm);
    return result;
}

static jobjectArray sw_if_dump_get_interfaces (JNIEnv * env)
{
    vppjni_main_t * jm = &vppjni_main;
    sw_interface_details_t *sw_if_details;
    u32 i;

    int len = vec_len(jm->sw_if_dump_if_indices);
    jmethodID jmtdIfDetails = jm->jmtdIfDetails;

    jobjectArray ifArray = (*env)->NewObjectArray(env, len, jm->jcls, NULL);

    for (i = 0; i < len; i++) {
        u32 sw_if_index = jm->sw_if_dump_if_indices[i];
        ASSERT(sw_if_index < vec_len(jm->sw_if_table));
        sw_if_details = &jm->sw_if_table[sw_if_index];
        ASSERT(sw_if_details->valid);

        u8 * s = format (0, "%s%c", sw_if_details->interface_name, 0);

        jstring ifname = (*env)->NewStringUTF(env, (char *)s);
        jint ifIndex = sw_if_details->sw_if_index;
        jint supIfIndex = sw_if_details->sup_sw_if_index;
        jbyteArray physAddr = (*env)->NewByteArray(env,
                sw_if_details->l2_address_length);
        (*env)->SetByteArrayRegion(env, physAddr, 0,
                sw_if_details->l2_address_length,
                (signed char*)sw_if_details->l2_address);
        jint subId = sw_if_details->sub_id;
        jint subOuterVlanId = sw_if_details->sub_outer_vlan_id;
        jint subInnerVlanId = sw_if_details->sub_inner_vlan_id;
        jint vtrOp = sw_if_details->vtr_op;
        jint vtrPushDot1q = sw_if_details->vtr_push_dot1q;
        jint vtrTag1 = sw_if_details->vtr_tag1;
        jint vtrTag2 = sw_if_details->vtr_tag2;

        jbyte adminUpDown = sw_if_details->admin_up_down;
        jbyte linkUpDown = sw_if_details->link_up_down;
        jbyte linkDuplex = sw_if_details->link_duplex;
        jbyte linkSpeed = sw_if_details->link_speed;
        jbyte subDot1ad = sw_if_details->sub_dot1ad;
        jbyte subNumberOfTags = sw_if_details->sub_number_of_tags;
        jbyte subExactMatch = sw_if_details->sub_exact_match;
        jbyte subDefault = sw_if_details->sub_default;
        jbyte subOuterVlanIdAny = sw_if_details->sub_outer_vlan_id_any;
        jbyte subInnerVlanIdAny = sw_if_details->sub_inner_vlan_id_any;

        jobject ifObj = (*env)->NewObject(env, jm->jcls, jmtdIfDetails,
                ifIndex, ifname,
                supIfIndex, physAddr, adminUpDown, linkUpDown,
                linkDuplex, linkSpeed, subId, subDot1ad,
                subNumberOfTags, subOuterVlanId, subInnerVlanId,
                subExactMatch, subDefault, subOuterVlanIdAny,
                subInnerVlanIdAny, vtrOp, vtrPushDot1q, vtrTag1, vtrTag2);
        (*env)->SetObjectArrayElement(env, ifArray, i, ifObj);
    }

    jm->collect_indices = 0;
    vec_reset_length(jm->sw_if_dump_if_indices);
    return ifArray;
}

JNIEXPORT jint JNICALL Java_org_openvpp_vppjapi_vppConn_findOrAddBridgeDomainId
  (JNIEnv * env, jobject obj, jstring bridgeDomain)
{
  vppjni_main_t * jm = &vppjni_main;
  static u8 * bd_name = 0;
  jint rv = -1;
  const char * bdName = (*env)->GetStringUTFChars (env, bridgeDomain, NULL);

  vec_validate_init_c_string (bd_name, bdName, strlen(bdName));
  (*env)->ReleaseStringUTFChars (env, bridgeDomain, bdName);

  vppjni_lock (jm, 6);
  rv = (jint)vjbd_find_or_add_bd (&jm->vjbd_main, bd_name);
  vppjni_unlock (jm);
  
  _vec_len(bd_name) = 0;
  return rv;
}

JNIEXPORT jint JNICALL Java_org_openvpp_vppjapi_vppConn_bridgeDomainIdFromName
  (JNIEnv * env, jobject obj, jstring bridgeDomain)
{
  vppjni_main_t * jm = &vppjni_main;
  static u8 * bd_name = 0;
  jint rv = -1;
  const char * bdName = (*env)->GetStringUTFChars (env, bridgeDomain, NULL);

  vec_validate_init_c_string (bd_name, bdName, strlen(bdName));
  (*env)->ReleaseStringUTFChars (env, bridgeDomain, bdName);

  vppjni_lock (jm, 20);
  rv = (jint)vjbd_id_from_name(&jm->vjbd_main, (u8 *)bd_name);
  vppjni_unlock (jm);

  _vec_len(bd_name) = 0;

  return rv;
}

JNIEXPORT jint JNICALL Java_org_openvpp_vppjapi_vppConn_bridgeDomainIdFromInterfaceName
  (JNIEnv * env, jobject obj, jstring interfaceName)
{
  vppjni_main_t * jm = &vppjni_main;
  vjbd_main_t * bdm = &jm->vjbd_main;
  u32 sw_if_index;
  jint rv = -1;
  const char * if_name;
  uword * p;

  if_name = (*env)->GetStringUTFChars (env, interfaceName, NULL);

  vppjni_lock (jm, 14);

  p = hash_get_mem (jm->sw_if_index_by_interface_name, if_name);

  if (p != 0) {
      sw_if_index = (jint) p[0];
      p = hash_get (bdm->bd_id_by_sw_if_index, sw_if_index);
      if (p != 0) {
          rv = (jint) p[0];
      }
  }

  vppjni_unlock (jm);

  (*env)->ReleaseStringUTFChars (env, interfaceName, if_name);

  return rv;
}

/* 
 * Special-case: build the interface table, maintain
 * the next loopback sw_if_index vbl.
 */
static void vl_api_sw_interface_details_t_handler
(vl_api_sw_interface_details_t * mp)
{
  vppjni_main_t * jm = &vppjni_main;
  static sw_interface_details_t empty_sw_if_details = {0,};
  sw_interface_details_t *sw_if_details;
  u32 sw_if_index;

  vppjni_lock (jm, 1);

  sw_if_index = ntohl (mp->sw_if_index);

  u8 * s = format (0, "%s%c", mp->interface_name, 0);

  if (jm->collect_indices) {
      u32 pos = vec_len(jm->sw_if_dump_if_indices);
      vec_validate(jm->sw_if_dump_if_indices, pos);
      jm->sw_if_dump_if_indices[pos] = sw_if_index;
  }

  vec_validate_init_empty(jm->sw_if_table, sw_if_index, empty_sw_if_details);
  sw_if_details = &jm->sw_if_table[sw_if_index];
  sw_if_details->valid = 1;

  snprintf((char *)sw_if_details->interface_name,
          sizeof(sw_if_details->interface_name), "%s", (char *)s);
  sw_if_details->sw_if_index = sw_if_index;
  sw_if_details->sup_sw_if_index = ntohl(mp->sup_sw_if_index);
  sw_if_details->l2_address_length = ntohl (mp->l2_address_length);
  ASSERT(sw_if_details->l2_address_length <= sizeof(sw_if_details->l2_address));
  memcpy(sw_if_details->l2_address, mp->l2_address,
          sw_if_details->l2_address_length);
  sw_if_details->sub_id = ntohl (mp->sub_id);
  sw_if_details->sub_outer_vlan_id = ntohl (mp->sub_outer_vlan_id);
  sw_if_details->sub_inner_vlan_id = ntohl (mp->sub_inner_vlan_id);
  sw_if_details->vtr_op = ntohl (mp->vtr_op);
  sw_if_details->vtr_push_dot1q = ntohl (mp->vtr_push_dot1q);
  sw_if_details->vtr_tag1 = ntohl (mp->vtr_tag1);
  sw_if_details->vtr_tag2 = ntohl (mp->vtr_tag2);

  sw_if_details->admin_up_down = mp->admin_up_down;
  sw_if_details->link_up_down = mp->link_up_down;
  sw_if_details->link_duplex = mp->link_duplex;
  sw_if_details->link_speed = mp->link_speed;
  sw_if_details->sub_dot1ad = mp->sub_dot1ad;
  sw_if_details->sub_number_of_tags = mp->sub_number_of_tags;
  sw_if_details->sub_exact_match = mp->sub_exact_match;
  sw_if_details->sub_default = mp->sub_default;
  sw_if_details->sub_outer_vlan_id_any = mp->sub_outer_vlan_id_any;
  sw_if_details->sub_inner_vlan_id_any = mp->sub_inner_vlan_id_any;

  hash_set_mem (jm->sw_if_index_by_interface_name, s, sw_if_index);
  DEBUG_LOG ("Got interface %s", (char *)s);

  /* In sub interface case, fill the sub interface table entry */
  if (mp->sw_if_index != mp->sup_sw_if_index) {
    sw_interface_subif_t * sub = NULL;

    vec_add2(jm->sw_if_subif_table, sub, 1);

    vec_validate(sub->interface_name, strlen((char *)s) + 1);
    strncpy((char *)sub->interface_name, (char *)s,
            vec_len(sub->interface_name));
    sub->sw_if_index = ntohl(mp->sw_if_index);
    sub->sub_id = ntohl(mp->sub_id);

    sub->sub_dot1ad = mp->sub_dot1ad;
    sub->sub_number_of_tags = mp->sub_number_of_tags;
    sub->sub_outer_vlan_id = ntohs(mp->sub_outer_vlan_id);
    sub->sub_inner_vlan_id = ntohs(mp->sub_inner_vlan_id);
    sub->sub_exact_match = mp->sub_exact_match;
    sub->sub_default = mp->sub_default;
    sub->sub_outer_vlan_id_any = mp->sub_outer_vlan_id_any;
    sub->sub_inner_vlan_id_any = mp->sub_inner_vlan_id_any;

    /* vlan tag rewrite */
    sub->vtr_op = ntohl(mp->vtr_op);
    sub->vtr_push_dot1q = ntohl(mp->vtr_push_dot1q);
    sub->vtr_tag1 = ntohl(mp->vtr_tag1);
    sub->vtr_tag2 = ntohl(mp->vtr_tag2);
  }
  vppjni_unlock (jm);
}

static void vl_api_sw_interface_set_flags_t_handler
(vl_api_sw_interface_set_flags_t * mp)
{
  /* $$$ nothing for the moment */
}

static jintArray create_array_of_bd_ids(JNIEnv * env, jint bd_id)
{
    vppjni_main_t *jm = &vppjni_main;
    vjbd_main_t * bdm = &jm->vjbd_main;
    u32 *buf = NULL;
    u32 i;

    if (bd_id != ~0) {
        vec_add1(buf, bd_id);
    } else {
        for (i = 0; i < vec_len(bdm->bd_oper); i++) {
            u32 bd_id = bdm->bd_oper[i].bd_id;
            vec_add1(buf, bd_id);
        }
    }

    jintArray bdidArray = (*env)->NewIntArray(env, vec_len(buf));

    (*env)->SetIntArrayRegion(env, bdidArray, 0, vec_len(buf), (int*)buf);

    return bdidArray;
}

static void bridge_domain_oper_free(void)
{
    vppjni_main_t *jm = &vppjni_main;
    vjbd_main_t *bdm = &jm->vjbd_main;
    u32 i;

    for (i = 0; i < vec_len(bdm->bd_oper); i++) {
        vec_free(bdm->bd_oper->l2fib_oper);
    }
    vec_reset_length(bdm->bd_oper);
    hash_free(bdm->bd_id_by_sw_if_index);
    hash_free(bdm->oper_bd_index_by_bd_id);
}

JNIEXPORT jintArray JNICALL Java_org_openvpp_vppjapi_vppConn_bridgeDomainDump
(JNIEnv * env, jobject obj, jint bd_id)
{
    vppjni_main_t *jm = &vppjni_main;
    vl_api_bridge_domain_dump_t * mp;
    u32 my_context_id;
    f64 timeout;
    int rv;
    rv = vppjni_sanity_check (jm);
    if (rv) return NULL;

    vppjni_lock (jm, 15);

    if (~0 == bd_id) {
        bridge_domain_oper_free();
    }

    my_context_id = vppjni_get_context_id (jm);
    M(BRIDGE_DOMAIN_DUMP, bridge_domain_dump);
    mp->context = clib_host_to_net_u32 (my_context_id);
    mp->bd_id = clib_host_to_net_u32(bd_id);
    S;

    /* Use a control ping for synchronization */
    {
        vl_api_control_ping_t * mp;
        M(CONTROL_PING, control_ping);
        S;
    }

    WNR;
    if (0 != rv) {
        return NULL;
    }

    jintArray ret = create_array_of_bd_ids(env, bd_id);

    vppjni_unlock (jm);

    return ret;
}

static void
vl_api_bridge_domain_details_t_handler (vl_api_bridge_domain_details_t * mp)
{
  vppjni_main_t *jm = &vppjni_main;
  vjbd_main_t * bdm = &jm->vjbd_main;
  vjbd_oper_t * bd_oper;
  u32 bd_id, bd_index;

  bd_id = ntohl (mp->bd_id);

  bd_index = vec_len(bdm->bd_oper);
  vec_validate (bdm->bd_oper, bd_index);
  bd_oper = vec_elt_at_index(bdm->bd_oper, bd_index);

  hash_set(bdm->oper_bd_index_by_bd_id, bd_id, bd_index);

  bd_oper->bd_id = bd_id;
  bd_oper->flood = mp->flood != 0;
  bd_oper->forward = mp->forward != 0;
  bd_oper->learn =  mp->learn != 0;
  bd_oper->uu_flood = mp->uu_flood != 0;
  bd_oper->arp_term = mp->arp_term != 0;
  bd_oper->bvi_sw_if_index = ntohl (mp->bvi_sw_if_index);
  bd_oper->n_sw_ifs = ntohl (mp->n_sw_ifs);

  bd_oper->bd_sw_if_oper = 0;
}

static void
vl_api_bridge_domain_sw_if_details_t_handler
(vl_api_bridge_domain_sw_if_details_t * mp)
{
  vppjni_main_t *jm = &vppjni_main;
  vjbd_main_t * bdm = &jm->vjbd_main;
  bd_sw_if_oper_t * bd_sw_if_oper;
  u32 bd_id, sw_if_index;

  bd_id = ntohl (mp->bd_id);
  sw_if_index = ntohl (mp->sw_if_index);

  uword *p;
  p = hash_get (bdm->oper_bd_index_by_bd_id, bd_id);
  if (p == 0) {
      clib_warning("Invalid bd_id %d in bridge_domain_sw_if_details_t_handler", bd_id);
      return;
  }
  u32 oper_bd_index = (jint) p[0];
  vjbd_oper_t *bd_oper = vec_elt_at_index(bdm->bd_oper, oper_bd_index);

  u32 len = vec_len(bd_oper->bd_sw_if_oper);
  vec_validate(bd_oper->bd_sw_if_oper, len);
  bd_sw_if_oper = &bd_oper->bd_sw_if_oper[len];
  bd_sw_if_oper->bd_id = bd_id;
  bd_sw_if_oper->sw_if_index = sw_if_index;
  bd_sw_if_oper->shg = mp->shg;

  hash_set(bdm->bd_id_by_sw_if_index, sw_if_index, bd_id);
}

static const char* interface_name_from_sw_if_index(u32 sw_if_index)
{
    vppjni_main_t *jm = &vppjni_main;

    if (sw_if_index >= vec_len(jm->sw_if_table)) {
        return NULL;
    }
    if (!jm->sw_if_table[sw_if_index].valid) {
        return NULL;
    }
    return (const char*)jm->sw_if_table[sw_if_index].interface_name;
}

JNIEXPORT jobject JNICALL Java_org_openvpp_vppjapi_vppConn_getBridgeDomainDetails
(JNIEnv * env, jobject obj, jint bdId)
{
    vppjni_main_t *jm = &vppjni_main;
    vjbd_main_t * bdm = &jm->vjbd_main;
    u32 oper_bd_index;
    u32 bd_id = bdId;
    jobject rv = NULL;
    uword *p;

    vppjni_lock (jm, 16);

    p = hash_get (bdm->oper_bd_index_by_bd_id, bd_id);
    if (p == 0) {
        rv = NULL;
        goto out;
    }
    oper_bd_index = (jint) p[0];

    vjbd_oper_t *bd_oper = vec_elt_at_index(bdm->bd_oper, oper_bd_index);


    /* setting BridgeDomainDetails */

    jclass bddClass = (*env)->FindClass(env, "org/openvpp/vppjapi/vppBridgeDomainDetails");
    if ((*env)->ExceptionCheck(env)) {
        (*env)->ExceptionDescribe(env);
        rv = NULL;
        goto out;
    }

    jmethodID midInit = (*env)->GetMethodID(env, bddClass, "<init>", "()V");
    if ((*env)->ExceptionCheck(env)) {
        (*env)->ExceptionDescribe(env);
        rv = NULL;
        goto out;
    }
    jobject bddObj = (*env)->NewObject(env, bddClass, midInit);

    u8 *vec_bd_name = vjbd_oper_name_from_id(bdm, bd_id);
    if (NULL == vec_bd_name) {
        rv = NULL;
        goto out;
    }
    char *str_bd_name = (char*)format (0, "%s%c", vec_bd_name, 0);
    vec_free(vec_bd_name);
    jstring bdName = (*env)->NewStringUTF(env, str_bd_name);
    vec_free(str_bd_name);
    if (NULL == bdName) {
        rv = NULL;
        goto out;
    }
    jfieldID fidName = (*env)->GetFieldID(env, bddClass, "name", "Ljava/lang/String;");
    if ((*env)->ExceptionCheck(env)) {
        (*env)->ExceptionDescribe(env);
        rv = NULL;
        goto out;
    }
    (*env)->SetObjectField(env, bddObj, fidName, bdName);

    jfieldID fidBdId = (*env)->GetFieldID(env, bddClass, "bdId", "I");
    if ((*env)->ExceptionCheck(env)) {
        (*env)->ExceptionDescribe(env);
        rv = NULL;
        goto out;
    }
    (*env)->SetIntField(env, bddObj, fidBdId, bdId);

    jboolean flood = bd_oper->flood;
    jfieldID fidFlood = (*env)->GetFieldID(env, bddClass, "flood", "Z");
    if ((*env)->ExceptionCheck(env)) {
        (*env)->ExceptionDescribe(env);
        rv = NULL;
        goto out;
    }
    (*env)->SetBooleanField(env, bddObj, fidFlood, flood);

    jboolean uuFlood = bd_oper->uu_flood;
    jfieldID fidUuFlood = (*env)->GetFieldID(env, bddClass, "uuFlood", "Z");
    if ((*env)->ExceptionCheck(env)) {
        (*env)->ExceptionDescribe(env);
        rv = NULL;
        goto out;
    }
    (*env)->SetBooleanField(env, bddObj, fidUuFlood, uuFlood);

    jboolean forward = bd_oper->forward;
    jfieldID fidForward = (*env)->GetFieldID(env, bddClass, "forward", "Z");
    if ((*env)->ExceptionCheck(env)) {
        (*env)->ExceptionDescribe(env);
        rv = NULL;
        goto out;
    }
    (*env)->SetBooleanField(env, bddObj, fidForward, forward);

    jboolean learn = bd_oper->learn;
    jfieldID fidLearn = (*env)->GetFieldID(env, bddClass, "learn", "Z");
    if ((*env)->ExceptionCheck(env)) {
        (*env)->ExceptionDescribe(env);
        rv = NULL;
        goto out;
    }
    (*env)->SetBooleanField(env, bddObj, fidLearn, learn);

    jboolean arpTerm = bd_oper->arp_term;
    jfieldID fidArpTerm = (*env)->GetFieldID(env, bddClass, "arpTerm", "Z");
    if ((*env)->ExceptionCheck(env)) {
        (*env)->ExceptionDescribe(env);
        rv = NULL;
        goto out;
    }
    (*env)->SetBooleanField(env, bddObj, fidArpTerm, arpTerm);

    jstring bviInterfaceName = NULL;
    if (~0 != bd_oper->bvi_sw_if_index) {
        const char *str_if_name = interface_name_from_sw_if_index(bd_oper->bvi_sw_if_index);
        if (NULL == str_if_name) {
            clib_warning("Could not get interface name for sw_if_index %d", bd_oper->bvi_sw_if_index);
            rv = NULL;
            goto out;
        }
        bviInterfaceName = (*env)->NewStringUTF(env, str_if_name);
        if (NULL == bviInterfaceName) {
            rv = NULL;
            goto out;
        }
    }
    jfieldID fidBviInterfaceName = (*env)->GetFieldID(env, bddClass, "bviInterfaceName", "Ljava/lang/String;");
    if ((*env)->ExceptionCheck(env)) {
        (*env)->ExceptionDescribe(env);
        rv = NULL;
        goto out;
    }
    (*env)->SetObjectField(env, bddObj, fidBviInterfaceName, bviInterfaceName);


    /* setting BridgeDomainInterfaceDetails */

    jclass bdidClass = (*env)->FindClass(env, "org/openvpp/vppjapi/vppBridgeDomainInterfaceDetails");
    if ((*env)->ExceptionCheck(env)) {
        (*env)->ExceptionDescribe(env);
        rv = NULL;
        goto out;
    }

    jfieldID fidInterfaceName = (*env)->GetFieldID(env, bdidClass, "interfaceName", "Ljava/lang/String;");
    if ((*env)->ExceptionCheck(env)) {
        (*env)->ExceptionDescribe(env);
        rv = NULL;
        goto out;
    }

    jfieldID fidSHG = (*env)->GetFieldID(env, bdidClass, "splitHorizonGroup", "B");
    if ((*env)->ExceptionCheck(env)) {
        (*env)->ExceptionDescribe(env);
        rv = NULL;
        goto out;
    }

    u32 len = vec_len(bd_oper->bd_sw_if_oper);
    ASSERT(len == bd_oper->n_sw_ifs);

    jobjectArray bdidArray = (*env)->NewObjectArray(env, len, bdidClass, NULL);

    u32 i;
    for (i = 0; i < len; i++) {
        bd_sw_if_oper_t *sw_if_oper = &bd_oper->bd_sw_if_oper[i];

        jmethodID midBdidInit = (*env)->GetMethodID(env, bdidClass, "<init>", "()V");
        if ((*env)->ExceptionCheck(env)) {
            (*env)->ExceptionDescribe(env);
            rv = NULL;
            goto out;
        }
        jobject bdidObj = (*env)->NewObject(env, bdidClass, midBdidInit);
        (*env)->SetObjectArrayElement(env, bdidArray, i, bdidObj);

        u32 sw_if_index = sw_if_oper->sw_if_index;
        const char *str_if_name = interface_name_from_sw_if_index(sw_if_index);
        if (NULL == str_if_name) {
            rv = NULL;
            goto out;
        }
        jstring interfaceName = (*env)->NewStringUTF(env, str_if_name);
        if (NULL == interfaceName) {
            rv = NULL;
            goto out;
        }
        (*env)->SetObjectField(env, bdidObj, fidInterfaceName, interfaceName);

        jbyte shg = sw_if_oper->shg;
        (*env)->SetByteField(env, bdidObj, fidSHG, shg);
    }

    jfieldID fidInterfaces = (*env)->GetFieldID(env, bddClass, "interfaces",
            "[Lorg/openvpp/vppjapi/vppBridgeDomainInterfaceDetails;");
    if ((*env)->ExceptionCheck(env)) {
        (*env)->ExceptionDescribe(env);
        rv = NULL;
        goto out;
    }
    (*env)->SetObjectField(env, bddObj, fidInterfaces, bdidArray);

    rv = bddObj;

out:

    vppjni_unlock (jm);

    return rv;
}

static jobject l2_fib_create_object(JNIEnv *env, bd_l2fib_oper_t *l2_fib)
{
    jclass l2FibClass = (*env)->FindClass(env, "org/openvpp/vppjapi/vppL2Fib");
    if ((*env)->ExceptionCheck(env)) {
        (*env)->ExceptionDescribe(env);
        return NULL;
    }

    jmethodID midL2FIbInit = (*env)->GetMethodID(env, l2FibClass, "<init>", "([BZLjava/lang/String;ZZ)V");
    if ((*env)->ExceptionCheck(env)) {
        (*env)->ExceptionDescribe(env);
        return NULL;
    }

    u32 sw_if_index = l2_fib->sw_if_index;
    const char *str_if_name = interface_name_from_sw_if_index(sw_if_index);
    if (NULL == str_if_name) {
        return NULL;
    }
    jstring interfaceName = (*env)->NewStringUTF(env, str_if_name);
    if (NULL == interfaceName) {
        return NULL;
    }

    jbyteArray physAddr = (*env)->NewByteArray(env, 6);
    (*env)->SetByteArrayRegion(env, physAddr, 0, 6,
            (signed char*)l2_fib->mac_addr.fields.mac);
    jboolean staticConfig = !l2_fib->learned;
    jstring outgoingInterface = interfaceName;
    jboolean filter = l2_fib->filter;
    jboolean bridgedVirtualInterface = l2_fib->bvi;

    jobject l2FibObj = (*env)->NewObject(env, l2FibClass, midL2FIbInit,
            physAddr, staticConfig, outgoingInterface, filter,
            bridgedVirtualInterface);

    return l2FibObj;
}

JNIEXPORT jobjectArray JNICALL Java_org_openvpp_vppjapi_vppConn_l2FibTableDump
(JNIEnv * env, jobject obj, jint bd_id)
{
  vppjni_main_t *jm = &vppjni_main;
  vjbd_main_t * bdm = &jm->vjbd_main;
  vl_api_l2_fib_table_dump_t *mp;
  jobjectArray l2FibArray = NULL;
  vjbd_oper_t *bd_oper;
  u32 oper_bd_index;
  uword *p;
  f64 timeout;
  int rv;
  u32 i;

  vppjni_lock (jm, 17);

  //vjbd_l2fib_oper_reset (bdm);

  p = hash_get (bdm->oper_bd_index_by_bd_id, bd_id);
  if (p == 0) {
      goto done;
  }
  oper_bd_index = p[0];
  bd_oper = vec_elt_at_index(bdm->bd_oper, oper_bd_index);
  vec_reset_length (bd_oper->l2fib_oper);

  /* Get list of l2 fib table entries */
  M(L2_FIB_TABLE_DUMP, l2_fib_table_dump);
  mp->bd_id = ntohl(bd_id);
  S;

  /* Use a control ping for synchronization */
  {
    vl_api_control_ping_t * mp;
    M(CONTROL_PING, control_ping);
    S;
  }

  WNR;
  if (0 != rv) {
      goto done;
  }

  u32 count = vec_len(bd_oper->l2fib_oper);
  bd_l2fib_oper_t *l2fib_oper = bd_oper->l2fib_oper;

  jclass l2FibClass = (*env)->FindClass(env, "org/openvpp/vppjapi/vppL2Fib");
  if ((*env)->ExceptionCheck(env)) {
      (*env)->ExceptionDescribe(env);
      goto done;
  }

  l2FibArray = (*env)->NewObjectArray(env, count, l2FibClass, NULL);

  for (i = 0; i < count; i++) {
      bd_l2fib_oper_t *l2_fib = &l2fib_oper[i];
      jobject l2FibObj = l2_fib_create_object(env, l2_fib);
      (*env)->SetObjectArrayElement(env, l2FibArray, i, l2FibObj);
  }

done:
  vppjni_unlock (jm);

  return l2FibArray;
}

static void
vl_api_l2_fib_table_entry_t_handler (vl_api_l2_fib_table_entry_t * mp)
{
  //static u8 * mac_addr;
  vppjni_main_t *jm = &vppjni_main;
  vjbd_main_t * bdm = &jm->vjbd_main;
  vjbd_oper_t * bd_oper;
  u32 bd_id, oper_bd_index;
  //uword mhash_val_l2fi;
  bd_l2fib_oper_t * l2fib_oper;
  l2fib_u64_mac_t * l2fe_u64_mac = (l2fib_u64_mac_t *)&mp->mac;

  bd_id = ntohl (mp->bd_id);

  uword *p = hash_get (bdm->oper_bd_index_by_bd_id, bd_id);
  if (p == 0) {
      return;
  }
  oper_bd_index = (jint) p[0];
  bd_oper = vec_elt_at_index(bdm->bd_oper, oper_bd_index);

#if 0
  vec_validate (mac_addr, MAC_ADDRESS_SIZE);
  memcpy (mac_addr, l2fe_u64_mac->fields.mac, MAC_ADDRESS_SIZE);
  mhash_val_l2fi = vec_len (bd_oper->l2fib_oper);
  if (mhash_elts (&bd_oper->l2fib_index_by_mac) == 0)
    mhash_init (&bd_oper->l2fib_index_by_mac, sizeof (u32), MAC_ADDRESS_SIZE);
  mhash_set_mem (&bd_oper->l2fib_index_by_mac, mac_addr, &mhash_val_l2fi, 0);
#endif

  vec_add2 (bd_oper->l2fib_oper, l2fib_oper, 1);

  l2fib_oper->bd_id = bd_id;
  l2fib_oper->mac_addr.raw = l2fib_mac_to_u64 (l2fe_u64_mac->fields.mac);
  l2fib_oper->sw_if_index = ntohl (mp->sw_if_index);
  l2fib_oper->learned = !mp->static_mac;
  l2fib_oper->filter = mp->filter_mac;
  l2fib_oper->bvi = mp->bvi_mac;
}

static int ipAddressDump
(JNIEnv * env, jobject obj, jstring interfaceName, jboolean isIPv6)
{
    vppjni_main_t *jm = &vppjni_main;
    vl_api_ip_address_dump_t * mp;
    const char *if_name;
    u32 my_context_id;
    u32 sw_if_index;
    f64 timeout;
    uword *p;
    int rv = 0;

    if (NULL == interfaceName) {
        return -1;
    }

    if_name = (*env)->GetStringUTFChars (env, interfaceName, NULL);
    p = hash_get_mem (jm->sw_if_index_by_interface_name, if_name);
    (*env)->ReleaseStringUTFChars (env, interfaceName, if_name);
    if (p == 0) {
        return -1;
    }
    sw_if_index = (u32) p[0];

    rv = vppjni_sanity_check (jm);
    if (0 != rv) {
        return rv;
    }

    my_context_id = vppjni_get_context_id (jm);
    M(IP_ADDRESS_DUMP, ip_address_dump);
    mp->context = clib_host_to_net_u32 (my_context_id);
    mp->sw_if_index = clib_host_to_net_u32(sw_if_index);
    mp->is_ipv6 = isIPv6;
    jm->is_ipv6 = isIPv6;
    S;

    /* Use a control ping for synchronization */
    {
      vl_api_control_ping_t * mp;
      M(CONTROL_PING, control_ping);
      S;
    }

    WNR;

    return rv;
}

JNIEXPORT jobjectArray JNICALL Java_org_openvpp_vppjapi_vppConn_ipv4AddressDump
(JNIEnv * env, jobject obj, jstring interfaceName)
{
    vppjni_main_t *jm = &vppjni_main;
    jobject returnArray = NULL;
    int i;

    vppjni_lock (jm, 18);

    vec_reset_length(jm->ipv4_addresses);

    if (0 != ipAddressDump(env, obj, interfaceName, 0)) {
        goto done;
    }

    u32 count = vec_len(jm->ipv4_addresses);
    ipv4_address_t *ipv4_address = jm->ipv4_addresses;

    jclass IPv4AddressClass = (*env)->FindClass(env, "org/openvpp/vppjapi/vppIPv4Address");
    if ((*env)->ExceptionCheck(env)) {
        (*env)->ExceptionDescribe(env);
        goto done;
    }

    jmethodID midIPv4AddressInit = (*env)->GetMethodID(env, IPv4AddressClass, "<init>", "(IB)V");
    if ((*env)->ExceptionCheck(env)) {
        (*env)->ExceptionDescribe(env);
        goto done;
    }

    jobjectArray ipv4AddressArray = (*env)->NewObjectArray(env, count, IPv4AddressClass, NULL);

    for (i = 0; i < count; i++) {
        ipv4_address_t *address = &ipv4_address[i];

        jint ip = address->ip;
        jbyte prefixLength = address->prefix_length;

        jobject ipv4AddressObj = (*env)->NewObject(env, IPv4AddressClass, midIPv4AddressInit,
                ip, prefixLength);

        (*env)->SetObjectArrayElement(env, ipv4AddressArray, i, ipv4AddressObj);
    }

    returnArray = ipv4AddressArray;

done:
    vppjni_unlock (jm);
    return returnArray;
}

JNIEXPORT jobjectArray JNICALL Java_org_openvpp_vppjapi_vppConn_ipv6AddressDump
(JNIEnv * env, jobject obj, jstring interfaceName)
{
    vppjni_main_t *jm = &vppjni_main;
    jobject returnArray = NULL;
    int i;

    vppjni_lock (jm, 19);

    vec_reset_length(jm->ipv6_addresses);

    if (0 != ipAddressDump(env, obj, interfaceName, 1)) {
        goto done;
    }

    u32 count = vec_len(jm->ipv6_addresses);
    ipv6_address_t *ipv6_address = jm->ipv6_addresses;

    jclass IPv6AddressClass = (*env)->FindClass(env, "org/openvpp/vppjapi/vppIPv6Address");
    if ((*env)->ExceptionCheck(env)) {
        (*env)->ExceptionDescribe(env);
        goto done;
    }

    jmethodID midIPv6AddressInit = (*env)->GetMethodID(env, IPv6AddressClass, "<init>", "([BB)V");
    if ((*env)->ExceptionCheck(env)) {
        (*env)->ExceptionDescribe(env);
        goto done;
    }

    jobjectArray ipv6AddressArray = (*env)->NewObjectArray(env, count, IPv6AddressClass, NULL);

    for (i = 0; i < count; i++) {
        ipv6_address_t *address = &ipv6_address[i];

        jbyteArray ip = (*env)->NewByteArray(env, 16);
        (*env)->SetByteArrayRegion(env, ip, 0, 16,
                (signed char*)address->ip);

        jbyte prefixLength = address->prefix_length;

        jobject ipv6AddressObj = (*env)->NewObject(env, IPv6AddressClass, midIPv6AddressInit,
                ip, prefixLength);

        (*env)->SetObjectArrayElement(env, ipv6AddressArray, i, ipv6AddressObj);
    }

    returnArray = ipv6AddressArray;

done:
    vppjni_unlock (jm);
    return returnArray;
}

static void vl_api_ip_address_details_t_handler (vl_api_ip_address_details_t * mp)
{
    vppjni_main_t * jm = &vppjni_main;

    if (!jm->is_ipv6) {
        ipv4_address_t *address = 0;
        vec_add2(jm->ipv4_addresses, address, 1);
        memcpy(&address->ip, mp->ip, 4);
        address->prefix_length = mp->prefix_length;
    } else {
        ipv6_address_t *address = 0;
        vec_add2(jm->ipv6_addresses, address, 1);
        memcpy(address->ip, mp->ip, 16);
        address->prefix_length = mp->prefix_length;
    }
}

#define VXLAN_TUNNEL_INTERFACE_NAME_PREFIX "vxlan_tunnel"

JNIEXPORT jobjectArray JNICALL Java_org_openvpp_vppjapi_vppConn_vxlanTunnelDump
(JNIEnv * env, jobject obj, jint swIfIndex)
{
    vppjni_main_t *jm = &vppjni_main;
    vl_api_vxlan_tunnel_dump_t * mp;
    jobjectArray returnArray = NULL;
    u32 my_context_id;
    f64 timeout;
    int rv = 0;
    int i;

    vppjni_lock (jm, 22);

    vec_reset_length(jm->vxlan_tunnel_details);

    my_context_id = vppjni_get_context_id (jm);
    M(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump);
    mp->context = clib_host_to_net_u32 (my_context_id);
    mp->sw_if_index = clib_host_to_net_u32 (swIfIndex);
    S;

    /* Use a control ping for synchronization */
    {
      vl_api_control_ping_t * mp;
      M(CONTROL_PING, control_ping);
      S;
    }

    WNR;
    if (0 != rv) {
        goto done;
    }

    u32 count = vec_len(jm->vxlan_tunnel_details);

    jclass VxlanTunnelDetailsClass = (*env)->FindClass(env,
            "org/openvpp/vppjapi/vppVxlanTunnelDetails");
    if ((*env)->ExceptionCheck(env)) {
        (*env)->ExceptionDescribe(env);
        goto done;
    }

    jmethodID midVxlanTunnelDetailsInit = (*env)->GetMethodID(env,
            VxlanTunnelDetailsClass, "<init>", "(IIIII)V");
    if ((*env)->ExceptionCheck(env)) {
        (*env)->ExceptionDescribe(env);
        goto done;
    }

    jobjectArray vxlanTunnelDetailsArray = (*env)->NewObjectArray(env, count,
            VxlanTunnelDetailsClass, NULL);

    for (i = 0; i < count; i++) {
        vxlan_tunnel_details_t *details = &jm->vxlan_tunnel_details[i];

        jint src_address = details->src_address;
        jint dst_address = details->dst_address;
        jint encap_vrf_id = details->encap_vrf_id;
        jint vni = details->vni;
        jint decap_next_index = details->decap_next_index;

        jobject vxlanTunnelDetailsObj = (*env)->NewObject(env,
                VxlanTunnelDetailsClass, midVxlanTunnelDetailsInit,
                src_address, dst_address, encap_vrf_id, vni, decap_next_index);

        (*env)->SetObjectArrayElement(env, vxlanTunnelDetailsArray, i,
                vxlanTunnelDetailsObj);
    }

    returnArray = vxlanTunnelDetailsArray;

done:
    vppjni_unlock (jm);
    return returnArray;
}

static void vl_api_vxlan_tunnel_details_t_handler
(vl_api_vxlan_tunnel_details_t * mp)
{
    vppjni_main_t * jm = &vppjni_main;
    vxlan_tunnel_details_t *tunnel_details;

    vec_add2(jm->vxlan_tunnel_details, tunnel_details, 1);
    tunnel_details->src_address = ntohl(mp->src_address);
    tunnel_details->dst_address = ntohl(mp->dst_address);
    tunnel_details->encap_vrf_id = ntohl(mp->encap_vrf_id);
    tunnel_details->vni = ntohl(mp->vni);
    tunnel_details->decap_next_index = ntohl(mp->decap_next_index);
}

/* cleanup handler for RX thread */
void cleanup_rx_thread(void *arg)
{
  vppjni_main_t * jm = &vppjni_main;

  vppjni_lock (jm, 99);

  int getEnvStat = (*jm->jvm)->GetEnv(jm->jvm, (void **)&(jm->jenv), JNI_VERSION_1_6);
  if (getEnvStat == JNI_EVERSION) {
    clib_warning ("Unsupported JNI version\n");
    jm->retval = -999;
    goto out;
  } else if (getEnvStat != JNI_EDETACHED) {
    (*jm->jvm)->DetachCurrentThread(jm->jvm);
  }
out:
  vppjni_unlock (jm);
}

static void
vl_api_show_version_reply_t_handler (vl_api_show_version_reply_t * mp)
{
  vppjni_main_t * jm = &vppjni_main;
  i32 retval = ntohl(mp->retval);

  if (retval >= 0) {
    DEBUG_LOG ("show version request succeeded(%d)");
    strncpy((char*)jm->program_name, (const char*)mp->program,
            sizeof(jm->program_name)-1);
    jm->program_name[sizeof(jm->program_name)-1] = 0;

    strncpy((char*)jm->build_directory, (const char*)mp->build_directory,
            sizeof(jm->build_directory)-1);
    jm->build_directory[sizeof(jm->build_directory)-1] = 0;

    strncpy((char*)jm->version, (const char*)mp->version,
            sizeof(jm->version)-1);
    jm->version[sizeof(jm->version)-1] = 0;

    strncpy((char*)jm->build_date, (const char*)mp->build_date,
            sizeof(jm->build_date)-1);
    jm->build_date[sizeof(jm->build_date)-1] = 0;
  } else {
    clib_error ("show version request failed(%d)", retval);
  }
  jm->retval = retval;
  jm->result_ready = 1;
}

static void vl_api_want_stats_reply_t_handler (vl_api_want_stats_reply_t * mp)
{
  vppjni_main_t * jm = &vppjni_main;
  jm->retval = mp->retval; // FIXME: vpp api does not do ntohl on this retval
  jm->result_ready = 1;
}

// control ping needs to be very first thing called
// to attach rx thread to java thread
static void vl_api_control_ping_reply_t_handler
(vl_api_control_ping_reply_t * mp)
{
  vppjni_main_t * jm = &vppjni_main;
  i32 retval = ntohl(mp->retval);
  jm->retval = retval;

  // attach to java thread if not attached
  int getEnvStat = (*jm->jvm)->GetEnv(jm->jvm, (void **)&(jm->jenv), JNI_VERSION_1_6);
  if (getEnvStat == JNI_EDETACHED) {
    if ((*jm->jvm)->AttachCurrentThread(jm->jvm, (void **)&(jm->jenv), NULL) != 0) {
      clib_warning("Failed to attach thread\n");
      jm->retval = -999;
      goto out;
    }

    // workaround as we can't use pthread_cleanup_push
    pthread_key_create(&jm->cleanup_rx_thread_key, cleanup_rx_thread);
    // destructor is only called if the value of key is non null
    pthread_setspecific(jm->cleanup_rx_thread_key, (void *)1);
  } else if (getEnvStat == JNI_EVERSION) {
    clib_warning ("Unsupported JNI version\n");
    jm->retval = -999;
    goto out;
  }
  // jm->jenv is now stable global reference that can be reused (only within RX thread)

#if 0
  // ! callback system removed for now
  //
  // get issuer msg-id
  p = hash_get (jm->ping_hash, context);
  if (p != 0) { // ping marks end of some dump call
    JNIEnv *env = jm->jenv;
    u16 msg_id = (u16)p[0];

    // we will no longer need this
    hash_unset (jm->ping_hash, context);

    // get original caller obj
    p = hash_get (jm->callback_hash, context);

    if (p == 0) // don't have callback stored
      goto out;

    jobject obj = (jobject)p[0]; // object that called original call

    switch (msg_id) {
      case VL_API_SW_INTERFACE_DUMP:
        if (0 != sw_if_dump_call_all_callbacks(obj)) {
          goto out2;
        }
        break;
      default:
        clib_warning("Unhandled control ping issuer msg-id: %d", msg_id);
        goto out2;
        break;
    }
  out2:
    // free the saved obj
    hash_unset (jm->callback_hash, context);
    // delete global reference
    (*env)->DeleteGlobalRef(env, obj);
  }
#endif

out:
  jm->result_ready = 1;
}

#define VPPJNI_DEBUG_COUNTERS 0

static void vl_api_vnet_interface_counters_t_handler
(vl_api_vnet_interface_counters_t *mp)
{
  vppjni_main_t *jm = &vppjni_main;
  CLIB_UNUSED(char *counter_name);
  u32 count, sw_if_index;
  int i;
  static sw_interface_stats_t empty_stats = {0, };

  vppjni_lock (jm, 12);
  count = ntohl (mp->count);
  sw_if_index = ntohl (mp->first_sw_if_index);
  if (mp->is_combined == 0) {
    u64 * vp, v;
    vp = (u64 *) mp->data;

    for (i = 0; i < count; i++) {
      sw_interface_details_t *sw_if = NULL;

      v = clib_mem_unaligned (vp, u64);
      v = clib_net_to_host_u64 (v);
      vp++;

      if (sw_if_index < vec_len(jm->sw_if_table))
        sw_if = vec_elt_at_index(jm->sw_if_table, sw_if_index);

      if (sw_if /* && (sw_if->admin_up_down == 1)*/ && sw_if->interface_name[0] != 0)
        {
          vec_validate_init_empty(jm->sw_if_stats_by_sw_if_index, sw_if_index, empty_stats);
          sw_interface_stats_t * s = vec_elt_at_index(jm->sw_if_stats_by_sw_if_index, sw_if_index);

          s->sw_if_index = sw_if_index;
          s->valid = 1;

          switch (mp->vnet_counter_type) {
          case  VNET_INTERFACE_COUNTER_DROP:
            counter_name = "drop";
            s->rx.pkts.discard = v;
            break;
          case  VNET_INTERFACE_COUNTER_PUNT:
            counter_name = "punt";
            s->rx.pkts.unknown_proto = v;
            break;
          case  VNET_INTERFACE_COUNTER_IP4:
            counter_name = "ip4";
            s->rx.pkts.ip4 = v;
            break;
          case  VNET_INTERFACE_COUNTER_IP6:
            counter_name = "ip6";
            s->rx.pkts.ip6 = v;
            break;
          case  VNET_INTERFACE_COUNTER_RX_NO_BUF:
            counter_name = "rx-no-buf";
            s->rx.pkts.fifo_full = v;
            break;
          case  VNET_INTERFACE_COUNTER_RX_MISS:
            counter_name = "rx-miss";
            s->rx.pkts.miss = v;
            break;
          case  VNET_INTERFACE_COUNTER_RX_ERROR:
            counter_name = "rx-error";
            s->rx.pkts.error = v;
            break;
          case  VNET_INTERFACE_COUNTER_TX_ERROR:
            counter_name = "tx-error (fifo-full)";
            s->tx.pkts.fifo_full = v;
            break;
          default:
            counter_name = "bogus";
            break;
          }

#if VPPJNI_DEBUG_COUNTERS == 1
          clib_warning ("%s (%d): %s (%lld)\n", sw_if->interface_name, s->sw_if_index,
                        counter_name, v);
#endif
        }
      sw_if_index++;
    }
  } else {
    vlib_counter_t *vp;
    u64 packets, bytes;
    vp = (vlib_counter_t *) mp->data;

    for (i = 0; i < count; i++) {
      sw_interface_details_t *sw_if = NULL;

      packets = clib_mem_unaligned (&vp->packets, u64);
      packets = clib_net_to_host_u64 (packets);
      bytes = clib_mem_unaligned (&vp->bytes, u64);
      bytes = clib_net_to_host_u64 (bytes);
      vp++;

      if (sw_if_index < vec_len(jm->sw_if_table))
        sw_if = vec_elt_at_index(jm->sw_if_table, sw_if_index);

      if (sw_if /* && (sw_if->admin_up_down == 1) */ && sw_if->interface_name[0] != 0)
        {
          vec_validate_init_empty(jm->sw_if_stats_by_sw_if_index, sw_if_index, empty_stats);
          sw_interface_stats_t * s = vec_elt_at_index(jm->sw_if_stats_by_sw_if_index, sw_if_index);

          s->valid = 1;
          s->sw_if_index = sw_if_index;

          switch (mp->vnet_counter_type) {
          case  VNET_INTERFACE_COUNTER_RX:
            s->rx.pkts.unicast = packets;
            s->rx.octets = bytes;
            counter_name = "rx";
            break;

          case  VNET_INTERFACE_COUNTER_TX:
            s->tx.pkts.unicast = packets;
            s->tx.octets = bytes;
            counter_name = "tx";
            break;

          default:
            counter_name = "bogus";
            break;
          }

#if VPPJNI_DEBUG_COUNTERS == 1
          clib_warning ("%s (%d): %s.packets %lld\n", 
                   sw_if->interface_name,
                   sw_if_index, counter_name, packets);
          clib_warning ("%s (%d): %s.bytes %lld\n", 
                   sw_if->interface_name,
                   sw_if_index, counter_name, bytes);
#endif
        }
      sw_if_index++;
    }
  }
  vppjni_unlock (jm);
}

jint JNI_OnLoad(JavaVM *vm, void *reserved) {
  vppjni_main_t * jm = &vppjni_main;
  JNIEnv* env;
  if ((*vm)->GetEnv(vm, (void**) &env, JNI_VERSION_1_6) != JNI_OK) {
    return JNI_ERR;
  }

  jclass cls = (*env)->FindClass(env, "org/openvpp/vppjapi/vppInterfaceDetails");
  if ((*env)->ExceptionCheck(env)) {
      (*env)->ExceptionDescribe(env);
      return JNI_ERR;
  }

  jm->jmtdIfDetails = 
      (*env)->GetMethodID(env, cls, "<init>", "(ILjava/lang/String;I[BBBBBIBBIIBBBBIIII)V");
  if ((*env)->ExceptionCheck(env)) {
      (*env)->ExceptionDescribe(env);
      return JNI_ERR;
  }

  // methods are not local references they stay forever
  // jclass is local reference let's hold global ref to it
  jm->jcls = (*env)->NewGlobalRef(env, cls);

  jm->jvm = vm;
  return JNI_VERSION_1_6;
}

void JNI_OnUnload(JavaVM *vm, void *reserved) {
  vppjni_main_t * jm = &vppjni_main;
  JNIEnv* env;
  if ((*vm)->GetEnv(vm, (void**) &env, JNI_VERSION_1_6) != JNI_OK) {
    return;
  }

  if (jm->jcls != NULL) {
    (*env)->DeleteGlobalRef(env, jm->jcls);
    jm->jcls = NULL;
  }

  jm->jenv = NULL;
  jm->jvm = NULL;
}

#define foreach_vpe_api_msg                             \
_(CONTROL_PING_REPLY, control_ping_reply)               \
_(SW_INTERFACE_DETAILS, sw_interface_details)           \
_(SHOW_VERSION_REPLY, show_version_reply)               \
_(WANT_STATS_REPLY, want_stats_reply)                   \
_(VNET_INTERFACE_COUNTERS, vnet_interface_counters)     \
_(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags)       \
_(BRIDGE_DOMAIN_DETAILS, bridge_domain_details)         \
_(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
_(L2_FIB_TABLE_ENTRY, l2_fib_table_entry)               \
_(IP_ADDRESS_DETAILS, ip_address_details)               \
_(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details)

static int connect_to_vpe(char *name)
{
  vppjni_main_t * jm = &vppjni_main;
  api_main_t * am = &api_main;

  if (vl_client_connect_to_vlib("/vpe-api", name, 32) < 0)
    return -1;

  jm->my_client_index = am->my_client_index;
  jm->vl_input_queue = am->shmem_hdr->vl_input_queue;

#define _(N,n)                                                  \
    vl_msg_api_set_handlers(VL_API_##N, #n,                     \
                           vl_api_##n##_t_handler,	        \
                           vl_noop_handler,                     \
                           vl_api_##n##_t_endian,               \
                           vl_api_##n##_t_print,                \
                           sizeof(vl_api_##n##_t), 1); 
    foreach_vpe_api_msg;
#undef _
  

  return 0;
}

/* Format an IP6 address. */
u8 * format_ip6_address (u8 * s, va_list * args)
{
  ip6_address_t * a = va_arg (*args, ip6_address_t *);
  u32 max_zero_run = 0, this_zero_run = 0;
  int max_zero_run_index = -1, this_zero_run_index=0;
  int in_zero_run = 0, i;
  int last_double_colon = 0;

  /* Ugh, this is a pain. Scan forward looking for runs of 0's */
  for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
    {
      if (a->as_u16[i] == 0)
        {
          if (in_zero_run)
            this_zero_run++;
          else
            {
              in_zero_run = 1;
              this_zero_run =1;
              this_zero_run_index = i;
            }
        }
      else
        {
          if (in_zero_run)
            {
              /* offer to compress the biggest run of > 1 zero */
              if (this_zero_run > max_zero_run && this_zero_run > 1)
                {
                  max_zero_run_index = this_zero_run_index;
                  max_zero_run = this_zero_run;
                }
            }
          in_zero_run = 0;
          this_zero_run = 0;
        }
    }

  if (in_zero_run)
    {
      if (this_zero_run > max_zero_run && this_zero_run > 1)
        {
          max_zero_run_index = this_zero_run_index;
          max_zero_run = this_zero_run;
        }
    }
  
  for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
    {
      if (i == max_zero_run_index)
        {
	  s = format (s, "::");
          i += max_zero_run - 1;
          last_double_colon = 1;
        }
      else
	{
	  s = format (s, "%s%x",
		      (last_double_colon || i == 0) ? "" : ":",
		      clib_net_to_host_u16 (a->as_u16[i]));
	  last_double_colon = 0;
	}
    }

  return s;
}

/* Format an IP4 address. */
u8 * format_ip4_address (u8 * s, va_list * args)
{
  u8 * a = va_arg (*args, u8 *);
  return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
}


