Пример #1
0
/*
 * Class:     be_ac_ucl_ingi_cbgp_net_Node
 * Method:    getDomain
 * Signature: ()Lbe/ac/ucl/ingi/cbgp/net/IGPDomain;
 */
JNIEXPORT jobject JNICALL Java_be_ac_ucl_ingi_cbgp_net_Node_getDomain
  (JNIEnv * jEnv, jobject joNode)
{
  net_node_t * node;
  igp_domain_t * domain= NULL;
  jobject joDomain= NULL;

  jni_lock(jEnv);

  /* Get the node */
  node= (net_node_t*) jni_proxy_lookup(jEnv, joNode);
  if (node == NULL)
    return_jni_unlock(jEnv, NULL);

  /* Get the domain */
  if ((node->domains != NULL) &&
      (uint16_array_size(node->domains) > 0)) {
    domain= network_find_igp_domain(node->network,
				    node->domains->data[0]);
    joDomain= cbgp_jni_new_net_IGPDomain(jEnv, NULL, domain);
  }

  jni_unlock(jEnv);
  return joDomain;
}
Пример #2
0
/*
 * Class:     be_ac_ucl_ingi_cbgp_bgp_Peer
 * Method:    recv
 * Signature: (Ljava/lang/String;)V
 */
JNIEXPORT void JNICALL Java_be_ac_ucl_ingi_cbgp_bgp_Peer_recv
  (JNIEnv * jEnv, jobject joPeer, jstring jsMesg)
{
  bgp_peer_t * peer;
  const char * cMesg;
  bgp_msg_t * msg;
  int result;

  jni_lock(jEnv);

  peer= (bgp_peer_t *) jni_proxy_lookup(jEnv, joPeer);
  if (peer == NULL)
    return_jni_unlock2(jEnv);

  /* Check that the peer is virtual */
  if (!bgp_peer_flag_get(peer, PEER_FLAG_VIRTUAL)) {
    throw_CBGPException(jEnv, "only virtual peers can do that");
    return_jni_unlock2(jEnv);
  }

  /* Build a message from the MRT-record */
  cMesg= (*jEnv)->GetStringUTFChars(jEnv, jsMesg, NULL);
  result= mrtd_msg_from_line(peer->router, peer, cMesg,
			     &msg);
  (*jEnv)->ReleaseStringUTFChars(jEnv, jsMesg, cMesg);

  if (result >= 0) {
    if (bgp_peer_handle_message(peer, msg) != 0)
      throw_CBGPException(jEnv, "could not handle message");
  } else
    throw_CBGPException(jEnv, "could not understand MRT message (%s)",
			mrtd_strerror(result));

  jni_unlock(jEnv);
}
Пример #3
0
/*
 * Class:     be_ac_ucl_ingi_cbgp_net_Node
 * Method:    loadTraffic
 * Signature: (Ljava/lang/String;)V
 */
JNIEXPORT void JNICALL Java_be_ac_ucl_ingi_cbgp_net_Node_loadTraffic
  (JNIEnv * jEnv, jobject joNode, jstring jsFileName)
{
  net_node_t * node;
  const char * filename;
  uint8_t options= 0;
  int result;

  jni_lock(jEnv);

  // Get the node
  node= (net_node_t*) jni_proxy_lookup(jEnv, joNode);
  if (node == NULL)
    return_jni_unlock2(jEnv);

  // Load Netflow from file
  filename= (char *) (*jEnv)->GetStringUTFChars(jEnv, jsFileName, NULL);
  result= node_load_netflow(node, filename, options, NULL);
  (*jEnv)->ReleaseStringUTFChars(jEnv, jsFileName, filename);
  if (result != ESUCCESS) {
    throw_CBGPException(jEnv, "could not load Netflow");
    return_jni_unlock2(jEnv);
  }

  jni_unlock(jEnv);
}
Пример #4
0
/*
 * Class:     be_ac_ucl_ingi_cbgp_net_Node
 * Method:    addRoute
 * Signature: (Ljava/lang/String;Ljava/lang/String;I)I
 */
JNIEXPORT void JNICALL Java_be_ac_ucl_ingi_cbgp_net_Node_addRoute
  (JNIEnv * jEnv, jobject joNode, jstring jsPrefix,
   jstring jsNexthop, jint jiWeight)
{
  net_node_t * node;
  ip_pfx_t prefix;
  net_addr_t next_hop;
  net_iface_id_t tIfaceID;
  int error;

  jni_lock(jEnv);

  /* Get the node */
  node= (net_node_t*) jni_proxy_lookup(jEnv, joNode);
  if (node == NULL)
    return_jni_unlock2(jEnv);

  if (ip_jstring_to_prefix(jEnv, jsPrefix, &prefix) != 0)
    return_jni_unlock2(jEnv);

  if (ip_jstring_to_address(jEnv, jsNexthop, &next_hop) != 0)
    return_jni_unlock2(jEnv);

  tIfaceID.network= next_hop;
  tIfaceID.mask= 32;
  error= node_rt_add_route(node, prefix, tIfaceID,
			   next_hop, jiWeight, NET_ROUTE_STATIC);
  if (error != ESUCCESS) {
    throw_CBGPException(jEnv, "could not add route (%s)",
			network_strerror(error));
    return_jni_unlock2(jEnv);
  }

  jni_unlock(jEnv);
}
Пример #5
0
/*
 * Class:     be_ac_ucl_ingi_cbgp_bgp_Peer
 * Method:    closeSession
 * Signature: (Z)V
 */
JNIEXPORT void JNICALL Java_be_ac_ucl_ingi_cbgp_bgp_Peer_closeSession
  (JNIEnv * jEnv, jobject joObject)
{
  bgp_peer_t * peer;

  jni_lock(jEnv);
  
  peer= (bgp_peer_t *) jni_proxy_lookup(jEnv, joObject);
  if (peer == NULL)
    return_jni_unlock2(jEnv);

  bgp_peer_close_session(peer);

  jni_unlock(jEnv);
}
Пример #6
0
/*
 * Class:     be_ac_ucl_ingi_cbgp_net_Iface
 * Method:    setState
 * Signature: (Z)V
 */
JNIEXPORT void JNICALL Java_be_ac_ucl_ingi_cbgp_net_Interface_setState
  (JNIEnv * jEnv, jobject joIface, jboolean bState)
{
  net_iface_t * pIface;

  jni_lock(jEnv);

  pIface= (net_iface_t *) jni_proxy_lookup(jEnv, joIface);
  if (pIface == NULL)
    return_jni_unlock2(jEnv);
    
  net_iface_set_enabled(pIface, (bState == JNI_TRUE)?1:0);

  jni_unlock(jEnv);
}
Пример #7
0
JNIEXPORT void JNICALL Java_be_ac_ucl_ingi_cbgp_net_Node_setLongitude
(JNIEnv * jEnv, jobject joNode, jfloat jfLongitude)
{
  net_node_t * node;

  jni_lock(jEnv);

  /* Get the node */
  node= (net_node_t*) jni_proxy_lookup(jEnv, joNode);
  if (node == NULL)
    return_jni_unlock2(jEnv);

  node->coord.longitude= jfLongitude;

  jni_unlock(jEnv);
}
Пример #8
0
/*
 * Class:     be_ac_ucl_ingi_cbgp_bgp_Peer
 * Method:    setNextHopSelf
 * Signature: (Z)V
 */
JNIEXPORT void JNICALL Java_be_ac_ucl_ingi_cbgp_bgp_Peer_setNextHopSelf
  (JNIEnv * jEnv, jobject joPeer, jboolean state)
{
  bgp_peer_t * peer;

  jni_lock(jEnv);

  peer= (bgp_peer_t *) jni_proxy_lookup(jEnv, joPeer);
  if (peer == NULL)
    return_jni_unlock2(jEnv);

  bgp_peer_flag_set(peer, PEER_FLAG_NEXT_HOP_SELF,
		    (state==JNI_TRUE)?1:0);

  jni_unlock(jEnv);
}
Пример #9
0
/*
 * Class:     bgp.Peer
 * Method:    setVirtual
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_be_ac_ucl_ingi_cbgp_bgp_Peer_setVirtual
  (JNIEnv * jEnv, jobject joPeer)
{
  bgp_peer_t * peer;

  jni_lock(jEnv);

  peer= (bgp_peer_t *) jni_proxy_lookup(jEnv, joPeer);
  if (peer == NULL)
    return_jni_unlock2(jEnv);

  bgp_peer_flag_set(peer, PEER_FLAG_VIRTUAL, 1);
  bgp_peer_flag_set(peer, PEER_FLAG_SOFT_RESTART, 1);

  jni_unlock(jEnv);
}
Пример #10
0
/*
 * Class:     bgp.Peer
 * Method:    setReflectorClient
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_be_ac_ucl_ingi_cbgp_bgp_Peer_setReflectorClient
  (JNIEnv * jEnv, jobject joPeer)
{
  bgp_peer_t * peer;

  jni_lock(jEnv);

  peer= (bgp_peer_t *) jni_proxy_lookup(jEnv, joPeer);
  if (peer == NULL)
    return_jni_unlock2(jEnv);

  peer->router->reflector= 1;
  bgp_peer_flag_set(peer, PEER_FLAG_RR_CLIENT, 1);

  jni_unlock(jEnv);
}
Пример #11
0
/**
 * Class:     be_ac_ucl_ingi_cbgp_net_Iface
 * Method:    setWeight
 * Signature: (J)V
 */
JNIEXPORT void JNICALL Java_be_ac_ucl_ingi_cbgp_net_Interface_setWeight
  (JNIEnv * jEnv, jobject joIface, jlong jlWeight)
{
  net_iface_t * pIface;
  int iResult;

  jni_lock(jEnv);

  pIface= (net_iface_t *) jni_proxy_lookup(jEnv, joIface);
  if (pIface == NULL)
    return_jni_unlock2(jEnv);

  iResult= net_iface_set_metric(pIface, 0, (uint32_t) jlWeight, 0);
  if (iResult != ESUCCESS)
    throw_CBGPException(jEnv, "could not set weight (%s)",
			network_strerror(iResult));

  jni_unlock(jEnv);
}
Пример #12
0
/*
 * Class:     be_ac_ucl_ingi_cbgp_net_Node
 * Method:    getName
 * Signature: ()Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_be_ac_ucl_ingi_cbgp_net_Node_getName
  (JNIEnv * jEnv, jobject joNode)
{
  net_node_t * node;
  jstring jsName= NULL;

  jni_lock(jEnv);

  /* Get the node */
  node= (net_node_t*) jni_proxy_lookup(jEnv, joNode);
  if (node == NULL)
    return_jni_unlock(jEnv, NULL);

  /* Get the name */
  if (node->name != NULL)
    jsName= cbgp_jni_new_String(jEnv, node->name);

  jni_unlock(jEnv);
  return jsName;
}
Пример #13
0
/*
 * Class:     be_ac_ucl_ingi_cbgp_net_Iface
 * Method:    setCapacity
 * Signature: (J)V
 */
JNIEXPORT void JNICALL Java_be_ac_ucl_ingi_cbgp_net_Interface_setCapacity
  (JNIEnv * jEnv, jobject joIface, jlong jlCapacity)
{
  net_iface_t * pIface;
  int iResult;

  jni_lock(jEnv);

  /* Get interface */
  pIface= (net_iface_t *) jni_proxy_lookup(jEnv, joIface);
  if (pIface == NULL)
    return_jni_unlock2(jEnv);

  iResult= net_iface_set_capacity(pIface, jlCapacity, 0);
  if (iResult != ESUCCESS)
    throw_CBGPException(jEnv, "could not set capacity (%s)",
			network_strerror(iResult));

  jni_unlock(jEnv);
}
Пример #14
0
void GC_locker::jni_unlock_slow() {
  MutexLocker mu(JNICritical_lock);
  jni_unlock();
  if (needs_gc() && !is_jni_active()) {
    // We're the last thread out. Cause a GC to occur.
    // GC will also check is_active, so this check is not
    // strictly needed. It's added here to make it clear that
    // the GC will NOT be performed if any other caller
    // of GC_locker::lock() still needs GC locked.
    if (!is_active()) {
      _doing_gc = true;
      {
        // Must give up the lock while at a safepoint
        MutexUnlocker munlock(JNICritical_lock);
        Universe::heap()->collect(GCCause::_gc_locker);
      }
      _doing_gc = false;
    }
    clear_needs_gc();
    JNICritical_lock->notify_all();
  }
}
Пример #15
0
/*
 * Class:     be_ac_ucl_ingi_cbgp_net_Node
 * Method:    setName
 * Signature: (Ljava/lang/String;)V
 */
JNIEXPORT void JNICALL Java_be_ac_ucl_ingi_cbgp_net_Node_setName
  (JNIEnv * jEnv, jobject joNode, jstring jsName)
{
  net_node_t * node;
  const char * name;

  jni_lock(jEnv);

  /* Get the node */
  node= (net_node_t*) jni_proxy_lookup(jEnv, joNode);
  if (node == NULL)
    return_jni_unlock2(jEnv);

  /* Set the name */
  if (jsName != NULL) {
    name= (*jEnv)->GetStringUTFChars(jEnv, jsName, NULL);
    node_set_name(node, name);
    (*jEnv)->ReleaseStringUTFChars(jEnv, jsName, name);
  } else
    node_set_name(node, NULL);

  jni_unlock(jEnv);
}