示例#1
0
bool OovThreadedWaitQueuePrivate::waitPopPrivate(void *item)
    {
    std::unique_lock<std::mutex> lock(mProcessQueueMutex);
    bool gotItem = false;
    LOG_PROC("pop lock", this);
    // Wait while empty
    while(isQueueEmpty() && !mQuitPopping)
        {
        // Release lock and wait for signal.
        mProviderPushedSignal.wait(lock);
        // After signaled, lock is reaquired.
        }

    // In the normal case this will not be empty.
    // If it is empty, then there was a signal, but nothing was
    // in the queue. This means that the quit function was called.
    gotItem = !isQueueEmpty();
    LOG_PROC_INT("pop got item", this, gotItem);
    if(gotItem)
        {
        getFront(item);
        }

    LOG_PROC_INT("pop unlock", this, gotItem);
    // unlock and signal to provider thread that queue is processed.
    lock.unlock();
    mConsumerPoppedSignal.notify_one();
    LOG_PROC("pop done", this);
    return gotItem;
    }
示例#2
0
void query_value(const INT1* key, INT1* value)
{
    INT4 status = 0;
    JNIEnv *jni_env = NULL;
    jstring arg_tableName;
    jstring arg_row;
    jstring out_res;

    if(0 == g_method_getonerecord)
    {
        LOG_PROC("ERROR", "Hbase client hasn't ready");
        return;
    }

    status = (*g_jvm)->AttachCurrentThread(g_jvm, (void**)&jni_env, NULL);
    if (0 != status)
    {
        LOG_PROC("ERROR", "Query value failed by key [%s], can not get jni env", key);
        return;
    }

    arg_tableName = (*jni_env)->NewStringUTF(jni_env, COMMON_TABLE);
    arg_row = (*jni_env)->NewStringUTF(jni_env, key);
    out_res = (jstring)((*jni_env)->CallStaticObjectMethod(jni_env, g_hbase_client, g_method_getonerecord, arg_tableName, arg_row));
    if (NULL != out_res)
    {
        const char *str = (*jni_env)->GetStringUTFChars(jni_env, out_res, NULL);

        //6 = strlen("VALUE|")
        strncpy(value, str + 6, TABLE_STRING_LEN);
    }

    //detach
    (*g_jvm)->DetachCurrentThread(g_jvm);
}
示例#3
0
void persist_value(const INT1* key, const INT1* value)
{
    INT4 status = 0;
    JNIEnv *jni_env = NULL;
    jstring arg_tableName;
    jstring arg_row;
    jstring arg_columnFamily;
    jstring arg_column;
    jstring arg_value;

    if(0 == g_method_addrecord)
    {
        LOG_PROC("ERROR", "Hbase client hasn't ready");
        return;
    }

    status = (*g_jvm)->AttachCurrentThread(g_jvm, (void**)&jni_env, NULL);
    if (0 != status)
    {
        LOG_PROC("ERROR", "Persist value [%s] failed by key [%s], can not get jni env", value, key);
        return;
    }

    arg_tableName = (*jni_env)->NewStringUTF(jni_env, COMMON_TABLE);
    arg_columnFamily = (*jni_env)->NewStringUTF(jni_env, COMMON_TABLE_CF);
    arg_row = (*jni_env)->NewStringUTF(jni_env, key);

    //Persist VALUE
    HBASE_ADD_RECORD("VALUE", value);

    //detach
    (*g_jvm)->DetachCurrentThread(g_jvm);
}
示例#4
0
void OovThreadedWaitQueuePrivate::quitPopsPrivate()
    {
    std::unique_lock<std::mutex> lock(mProcessQueueMutex);
    LOG_PROC("quitPops lock", this);
    mQuitPopping = true;
    // Wait to make sure all queue items were processed.
    while(!isQueueEmpty())
        {
        mConsumerPoppedSignal.wait(lock);
        }
    LOG_PROC("quitPops unlock", this);
    lock.unlock();
    mProviderPushedSignal.notify_all();
    LOG_PROC("quitPops done", this);
    }
示例#5
0
openstack_security_p update_openstack_security_group(char* security_group)
{
	openstack_security_p security_p = g_openstack_security_list;

	while (security_p) {
		if (0 == strcmp(security_p->security_group, security_group)) {
			return security_p;
		}
		security_p = security_p->next;
	}

	// create
	security_p = (openstack_security_p)mem_get(g_openstack_security_group_id);
	if (NULL != security_p) {
		memset(security_p->security_group, 0, OPENSTACK_SECURITY_GROUP_LEN);
		memcpy(security_p->security_group, security_group, OPENSTACK_SECURITY_GROUP_LEN);
		security_p->next = g_openstack_security_list;
		g_openstack_security_list = security_p;
	}
	else {
		LOG_PROC("INFO", "Security: Get memeory fail!");
	}

	return security_p;
}
示例#6
0
openstack_subnet_p create_openstack_host_subnet(
		char* tenant_id,
		char* network_id,
		//char* subnet_name,
		char* subnet_id,
		UINT4 gateway_ip,
		UINT4 start_ip,
		UINT4 end_ip){
	openstack_subnet_p ret = NULL;
	ret = (openstack_subnet_p)mem_get(g_openstack_host_subnet_id);
	if (NULL != ret) {
		memset(ret,0,sizeof(openstack_subnet));

		strcpy(ret->tenant_id,tenant_id);
		strcpy(ret->network_id,network_id);
		//strcpy(ret->subnet_name,subnet_name);
		strcpy(ret->subnet_id, subnet_id);
		ret->gateway_ip = gateway_ip;
		ret->start_ip = start_ip;
		ret->end_ip = end_ip;
	}
	else {
		LOG_PROC("ERROR", "Openstack Subnet: Create failed, Can't get memory.");
	}

	return ret;
};
示例#7
0
void OovThreadedWaitQueuePrivate::waitPushPrivate(void const *item)
    {
    std::unique_lock<std::mutex> lock(mProcessQueueMutex);
    LOG_PROC("push lock", this);
    // Wait while not empty
    while(!isQueueEmpty())
        {
        // Release lock and wait for signal.
        mConsumerPoppedSignal.wait(lock);
        // After signaled, lock is reaquired.
        }
    LOG_PROC("push", this);
    pushBack(item);

    LOG_PROC("push unlock", this);
    lock.unlock();
    // Signal to waitPop that data is ready.
    mProviderPushedSignal.notify_one();
    }
示例#8
0
//UINT4 find_openstack_host_ports_by_subnet_id(char* subnet_id,openstack_port_p* host_list){
//	UINT4 ret = 0;
//	openstack_port_p port = NULL;
//	openstack_node_p node_p = NULL;
//	node_p = g_openstack_host_port_list;
//
//	while(node_p != NULL){
//		port = (openstack_port_p)(node_p->data);
//		if(strcmp(port->subnet_id,subnet_id) == 0){
//			host_list[ret] = port;
//			ret++;
//		}
//		node_p = node_p->next;
//	}
//	return ret;
//};
//
//void delete_openstack_host_port_by_tenant_id(char* tenant_id){
//	openstack_port_p port = NULL;
//	openstack_node node;
//	openstack_node_p node_p = &node,temp_p = NULL;
//	node_p->next = g_openstack_host_port_list;
//
//	while(node_p->next != NULL){
//		port = (openstack_port_p)(node_p->next->data);
//		if(strcmp(port->tenant_id,tenant_id) == 0){
//			temp_p = node_p->next;
//			node_p->next = temp_p->next;
//			destory_openstack_host_node(temp_p);
//			destory_openstack_host_port(port);
//		}else{
//			node_p = node_p->next;
//		}
//	}
//	g_openstack_host_port_list = node.next;
//	return;
//};
//void delete_openstack_host_port_by_network_id(char* network_id){
//	openstack_port_p port = NULL;
//	openstack_node node;
//	openstack_node_p node_p = &node,temp_p = NULL;
//	node_p->next = g_openstack_host_port_list;
//
//	while(node_p->next != NULL){
//		port = (openstack_port_p)(node_p->next->data);
//		if(strcmp(port->network_id,network_id) == 0){
//			temp_p = node_p->next;
//			node_p->next = temp_p->next;
//			destory_openstack_host_node(temp_p);
//			destory_openstack_host_port(port);
//		}else{
//			node_p = node_p->next;
//		}
//	}
//	g_openstack_host_port_list = node.next;
//	return;
//};
//void delete_openstack_host_port_by_subnet_id(char* subnet_id){
//	openstack_port_p port = NULL;
//	openstack_node node;
//	openstack_node_p node_p = &node,temp_p = NULL;
//	node_p->next = g_openstack_host_port_list;
//
//	while(node_p->next != NULL){
//		port = (openstack_port_p)(node_p->next->data);
//		if(strcmp(port->subnet_id,subnet_id) == 0){
//			temp_p = node_p->next;
//			node_p->next = temp_p->next;
//			destory_openstack_host_node(temp_p);
//			destory_openstack_host_port(port);
//		}else{
//			node_p = node_p->next;
//		}
//	}
//	g_openstack_host_port_list = node.next;
//	return;
//};
//void delete_openstack_host_port_by_port_id(char* port_id){
//	openstack_port_p port = NULL;
//	port = remove_openstack_host_port_by_port_id(port_id);
//	if(port != NULL){
//		destory_openstack_host_port(port);
//	}
//	return;
//};
////////////////////////////////////////////////////////////////////////
openstack_node_p create_openstack_host_node(UINT1* data){
	openstack_node_p ret = NULL;
	ret = (openstack_node_p)mem_get(g_openstack_host_node_id);
	if (NULL != ret) {
		memset(ret,0,sizeof(openstack_node));
		ret->data = data;
	}
	else {
		LOG_PROC("ERROR", "Create openstack host node: Create fail, can't get memory.");
	}
	return ret;
};
示例#9
0
void* create_openstack_host_port(
		gn_switch_t* sw,
		UINT4 port,
		UINT4 ip,
		UINT1* mac,
		char* tenant_id,
		char* network_id,
		char* subnet_id,
		char* port_id,
		UINT2 security_num,
		UINT1* security_data){
	UINT8 dpid = 0;
	p_fabric_host_node node = NULL;
	openstack_port_p ret = NULL;
	ret = (openstack_port_p)mem_get(g_openstack_host_port_id);
	if (NULL != ret) {
		memset(ret,0,sizeof(openstack_port));

		if (NULL != tenant_id)
			strcpy(ret->tenant_id,tenant_id);
		if (NULL != network_id)
			strcpy(ret->network_id,network_id);
		if (NULL != port_id)
			strcpy(ret->port_id,port_id);
		if (NULL != subnet_id)
			strcpy(ret->subnet_id, subnet_id);
	//	ret->ip = ip;
	//	ret->sw = sw;
	//	if(sw != NULL)
	//		ret->dpid = sw->dpid;
	//	ret->port = port;
	//	memcpy(ret->mac, mac, 6);
		if (NULL != sw) {
			dpid = sw->dpid;
		}
		ret->security_num = security_num;
		if (NULL != security_data)
			ret->security_data = security_data;

		node = insert_fabric_host_into_list_paras(sw, dpid, port, mac, ip);
		if (NULL != node) {
			node->data = (void*)ret;
		}
		else {
			mem_free(ret, g_openstack_host_port_id);
		}
	}
	else {
		LOG_PROC("ERROR", "Create openstack host port: Can't get memory.");
	}
	return (void*)node;
};
示例#10
0
文件: l3.c 项目: China863SDN/DCFabric
INT4 create_l3_subnet(INT1 *name, INT1 *masked_ip)
{
    net_mask_t net_mask;
    UINT1 i;

    masked_ip_parser(masked_ip, &net_mask);
    if((0 == net_mask.prefix) || (0 == net_mask.ip))
    {
		//by:yhy add 201701051305
		LOG_PROC("ERROR", "create_l3_subnet -- (0 == net_mask.prefix) || (0 == net_mask.ip) return GN_ERR");
        return GN_ERR;
    }

    if(search_l3_subnet(net_mask.ip))
    {
		//by:yhy add 201701051305
		LOG_PROC("ERROR", "create_l3_subnet -- search_l3_subnet(net_mask.ip) return GN_ERR");
        return GN_ERR;
    }

    for(i = 0; i < MAX_L3_SUBNET; i++)
    {
        if(g_subnet_info[i].is_using == FALSE)
        {
            strncpy(g_subnet_info[i].name, name, 64 - 1);
            strncpy(g_subnet_info[i].netmask, masked_ip, 16 - 1);
            g_subnet_info[i].gw_ip = net_mask.ip;
            g_subnet_info[i].gw_prefix = net_mask.prefix;
            g_subnet_info[i].gw_minip = net_mask.minip;
            g_subnet_info[i].gw_maxip = net_mask.maxip;
            g_subnet_info[i].is_using = TRUE;
            return GN_OK;
        }
    }

    return GN_ERR;
}
示例#11
0
void delete_record(const INT1 *table_name, const INT1 *row_key)
{
    INT4 status = 0;
    JNIEnv *jni_env = NULL;
    jstring arg_tableName;
    jstring arg_row;

    if(0 == g_method_deleterecord)
    {
        LOG_PROC("ERROR", "Hbase client hasn't ready!\n");
        return;
    }

    status = (*g_jvm)->AttachCurrentThread(g_jvm, (void**)&jni_env, NULL);
    if (0 != status)
    {
        LOG_PROC("ERROR", "Delete record, can not get jni env! --RowKey: %s\n", row_key);
        return;
    }

    arg_tableName = (*jni_env)->NewStringUTF(jni_env, table_name);
    arg_row = (*jni_env)->NewStringUTF(jni_env, row_key);
    (*jni_env)->CallStaticObjectMethod(jni_env, g_hbase_client, g_method_deleterecord, arg_tableName, arg_row);
}
示例#12
0
openstack_network_p create_openstack_host_network(
		char* tenant_id,
		//char* network_name,
		char* network_id,
		UINT1 shared){
	openstack_network_p ret = NULL;
	ret = (openstack_network_p)mem_get(g_openstack_host_network_id);
	if (NULL != ret) {
		memset(ret,0,sizeof(openstack_network));
		strcpy(ret->tenant_id,tenant_id);
		//strcpy(ret->network_name,network_name);
		strcpy(ret->network_id,network_id);
		ret->shared = shared;
	}
	else {
		LOG_PROC("ERROR", "Create openstack host network: Can't get memory.");
	}
	return ret;
};
示例#13
0
void fini_hbase_client()
{
    JNIEnv *jni_env = (JNIEnv *)NULL;
    INT4 status = 0;

    //Get jni env for current thread
    status = (*g_jvm)->AttachCurrentThread(g_jvm, (void**)&jni_env, NULL);
    if (0 != status)
    {
        LOG_PROC("ERROR", "Fini hbase client, can not get jni env");
        return;
    }

    (*jni_env)->DeleteGlobalRef(jni_env, (jobject)g_method_addrecord);
    (*jni_env)->DeleteGlobalRef(jni_env, (jobject)g_method_getonerecord);
    (*jni_env)->DeleteGlobalRef(jni_env, (jobject)g_method_getrecordsbyfilter);
    (*jni_env)->DeleteGlobalRef(jni_env, g_hbase_client);
    (*g_jvm)->DetachCurrentThread(g_jvm);
    (*g_jvm)->DestroyJavaVM(g_jvm);
}
示例#14
0
INT4 init_restful_svr()
{
    UINT4 i;
    INT1 *value = get_value(g_controller_configure, "[controller]", "restful_service_port");
    g_restful_port = (NULL == value ? 8081 : atoi(value));

    for(i = 0; i < REST_CAPACITY; i++)
    {
        g_restful_get_handles[i].used = 0;
        g_restful_post_handles[i].used = 0;
        g_restful_delete_handles[i].used = 0;
    }

    init_json_server();
    if (pthread_create(&g_restful_pid, NULL, start_httpd_service, NULL))
    {
        LOG_PROC("ERROR", "Restful service state failed");
        return GN_ERR;
    }
    return GN_OK;
}
示例#15
0
static int answer_to_connection(void *cls, struct MHD_Connection *connection,
        const INT1 *url, const char *method, const INT1 *version,
        const INT1 *upload_data, size_t *upload_data_size, void **con_cls)
{
    INT4 ret = 0;
    UINT4 idx = 0;

    if (NULL == *con_cls)
    {
        struct connection_info *conn_info = (struct connection_info *)gn_malloc(sizeof(struct connection_info));
        if(NULL == conn_info)
        {
            return MHD_NO;
        }

        conn_info->connection_time = g_cur_sys_time.tv_sec;
        *con_cls = (void *)conn_info;
        return MHD_YES;
    }

    if (0 == strcmp(method, "GET"))
    {
        LOG_PROC("INFO", "Restful[%s]: [%s]", method, url);
        g_rest_reply = proc_rest_msg(method, url, upload_data);
        //todo ÅпÕ
        ret = send_page(connection, g_rest_reply, MHD_HTTP_OK);     //»Ø¸´ÏûÏ¢
        memset((char *) upload_data, 0x0, *upload_data_size);    //Çå¿Õ»º³åÇø
        *upload_data_size = 0;
        upload_data = NULL;

        free(g_rest_reply);
        return ret;
    }

    if (0 == strcmp(method, "POST") || 0 == strcmp(method, "DELETE")
            || 0 == strcmp(method, "PUT") || 0 == strcmp(method, "PATCH")
            || 0 == strcmp(method, "HEAD"))
    {
        struct connection_info *conn_info = *con_cls;
        conn_info->connection_type = HTTP_POST;

        if (*upload_data_size)
        {
            if(is_json(upload_data, *upload_data_size))
            {
                INT1 *tmp = (char*) upload_data;
                for (idx = *upload_data_size; idx > 0; --idx)
                {
                    if ('}' == tmp[idx])
                    {
                        tmp[idx + 1] = '\0';
                        break;
                    }
                }

                LOG_PROC("INFO", "Restful[%s]: [%s] %s\n", method, url, upload_data);
                g_rest_reply = proc_rest_msg(method, url, upload_data);

                memset((char *) upload_data, 0x0, *upload_data_size);    //Çå¿Õ»º³åÇø
                *upload_data_size = 0;
            }
            else
            {
                if(conn_info->connection_time - g_cur_sys_time.tv_sec > HTTP_TIMEOUT)
                {
                    memset((char *) upload_data, 0x0, *upload_data_size);    //Çå¿Õ»º³åÇø
                    *upload_data_size = 0;
                    return MHD_NO;
                }
            }

            return MHD_YES;
        }
        else
        {
            ret = send_page(connection, g_rest_reply, MHD_HTTP_OK);
            memset((char *) upload_data, 0x0, *upload_data_size);    //Çå¿Õ»º³åÇø
            *upload_data_size = 0;
            upload_data = NULL;

            gn_free((void **)&g_rest_reply);
            return ret;
        }
    }

    return ret;
}
示例#16
0
void query_topology()
{
    INT4 status = 0;
    JNIEnv *jni_env = NULL;
    jstring arg_tableName;
    jstring arg_row;
    jstring arg_columnFamily;
    jstring arg_column;
    jstring arg_value;

    jarray data;
    UINT4 src_port = 0;
    UINT4 dst_port = 0;
    unsigned long long int src_dpid = 0;
    unsigned long long int dst_dpid = 0;
    gn_switch_t *src_sw;

    if(0 == g_method_addrecord)
    {
        LOG_PROC("ERROR", "Hbase client hasn't ready");
        return;
    }

    //Get jni env for current thread
    status = (*g_jvm)->AttachCurrentThread(g_jvm, (void**)&jni_env, NULL);
    if (0 != status)
    {
        LOG_PROC("ERROR", "Update topology, can not get jni env");
        return;
    }

    arg_value = (*jni_env)->NewStringUTF(jni_env, "0");
    arg_tableName = (*jni_env)->NewStringUTF(jni_env, COMMON_TABLE);
    arg_row = (*jni_env)->NewStringUTF(jni_env, TOPO_VER);
    data = (jstring)((*jni_env)->CallStaticObjectMethod(jni_env, g_hbase_client, g_method_getonerecord, arg_tableName, arg_row));
    if (NULL != data)
    {
        const char *str = (*jni_env)->GetStringUTFChars(jni_env, data, NULL);
        arg_value = (*jni_env)->NewStringUTF(jni_env, str + 6);
    }
    arg_tableName = (*jni_env)->NewStringUTF(jni_env, TOPO_TABLE);
    arg_columnFamily = (*jni_env)->NewStringUTF(jni_env, TOPO_TABLE_CF);
    arg_column = (*jni_env)->NewStringUTF(jni_env, "VERSION");
    data = (*jni_env)->CallStaticObjectMethod(jni_env, g_hbase_client, g_method_getrecordsbyfilter, arg_tableName, arg_columnFamily, arg_column, arg_value);
    if (NULL != data)
    {
        const jsize length = (*jni_env)->GetArrayLength(jni_env, data);
        jsize index = length;
        while(index--)
        {
            jstring element = (jstring)((*jni_env)->GetObjectArrayElement(jni_env, data, index));
            char const* nativeString = (*jni_env)->GetStringUTFChars(jni_env, element, 0);

            char *p_next = NULL;
            char *value = NULL;
            char *str_cpy = strdup(nativeString);
            char *column = strcut(str_cpy, '|', &p_next);
            while(column)
            {
                value = strcut(NULL, '|', &p_next);
                if (0 == strcmp(column, "SRC_DPID"))
                {
                    src_dpid = strtoull(value, NULL, 16);
                }
                else if(0 == strcmp(column, "SRC_PORT"))
                {
                    src_port = atoi(value);
                }
                else if(0 == strcmp(column, "DST_DPID"))
                {
                    dst_dpid = strtoull(value, NULL, 16);
                }
                else if(0 == strcmp(column, "DST_PORT"))
                {
                    dst_port = atoi(value);
                }

                if (!p_next)
                {
                    break;
                }
                column = strcut(NULL, '|', &p_next);
            }

            free(str_cpy);
            (*jni_env)->ReleaseStringUTFChars(jni_env, element, nativeString);

            src_sw = find_sw_from_dpid(src_dpid);
            if(src_sw)
            {
                LOG_PROC("DEBUG", "----======>>>>> Mapping a new neighbor: src- %016llx.%d, dst: %016llx.%d", src_dpid, src_port, dst_dpid, dst_port);
                mapping_new_neighbor(src_sw, src_port, dst_dpid, dst_port);
            }
            else
            {
                LOG_PROC("DEBUG", "----======>>>>> Mapping a new neighbor failed, can not find src sw: src- %016llx.%d, dst: %016llx.%d", src_dpid, src_port, dst_dpid, dst_port);
            }
        }
    }

    //detach
    (*g_jvm)->DetachCurrentThread(g_jvm);
}
示例#17
0
INT4 init_hbase_client()
{
    JNIEnv *jni_env = (JNIEnv *)NULL;
    jclass cls = 0;
    JavaVMInitArgs vm_args;
    JavaVMOption   options[1];
    jmethodID mid = 0;

    INT1 value[TABLE_STRING_LEN] = {0};
    INT1 *conf_value = NULL;
    conf_value = get_value(g_controller_configure, "[controller]", "hbase_ip");
    NULL == conf_value ? strncpy(g_hbase_ip, "127.0.0.1", 16 - 1) : strncpy(g_hbase_ip, conf_value, 300 - 1);

    conf_value = get_value(g_controller_configure, "[controller]", "hbase_port");
    NULL == conf_value ? strncpy(g_hbase_port, "60000", 6 - 1) : strncpy(g_hbase_port, conf_value, 300 - 1);


//    int jarCount = 0;
//    struct dirent **jar_files;
//    char option_str[10240] = {0};
//    strcat(option_str, "-Djava.class.path=");
//    strcat(option_str, g_hbase_client_file_path);
//    if ((jarCount = scandir(g_hbase_lib_path, &jar_files, filter_jar, alphasort)) > 0)
//    {
//        while (jarCount--)
//        {
//            strcat(option_str, ":");
//            strcat(option_str, g_hbase_lib_path);
//            strcat(option_str, "/");
//            strcat(option_str, jar_files[jarCount]->d_name);
//
//            free(jar_files[jarCount]);
//        }
//
//        free(jar_files);
//    }
//    else
//    {
//        printf("No libs found in the given hbase lib path.");
//    }
//
//    options[0].optionString = option_str;
//    printf("Option string: %s\n", option_str);

    options[0].optionString = "-Djava.class.path=../hbase/hbase_client.jar:../hbase/hbase_lib.jar";
    vm_args.version  = JNI_VERSION_1_6;
    vm_args.nOptions = 1;
    vm_args.options  = options;


    //Create java vm
    if(JNI_CreateJavaVM(&g_jvm, (void **)&jni_env, &vm_args) != JNI_OK)
    {
        LOG_PROC("ERROR", "Create JVM failed");
        return GN_ERR;
    }

    //Find class "hbase_client"
     cls = (*jni_env)->FindClass(jni_env, "hbase_client");
     g_hbase_client = (jclass)((*jni_env)->NewGlobalRef(jni_env, cls));
    if(0 == g_hbase_client)
    {
        LOG_PROC("ERROR", "Jni can not find class named \"hbase_client\"");
        return GN_ERR;
    }

    //Init env conf
    mid = (*jni_env)->GetStaticMethodID(jni_env, g_hbase_client, "Init_conf", "(Ljava/lang/String;Ljava/lang/String;)V");
    if(0 != mid)
    {
        jstring arg_ip = (*jni_env)->NewStringUTF(jni_env, g_hbase_ip);
        jstring arg_port = (*jni_env)->NewStringUTF(jni_env, g_hbase_port);
        (*jni_env)->CallStaticObjectMethod(jni_env, g_hbase_client, mid, arg_ip, arg_port);
    }
    else
    {
        LOG_PROC("ERROR", "Call method \"Init_conf\" failed");
        return GN_ERR;
    }

    //Get method: add record
    mid = (*jni_env)->GetStaticMethodID(jni_env, g_hbase_client, "addRecord", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
    if(0 == mid)
    {
        LOG_PROC("ERROR", "Jni can not find method named \"addRecord\"");
        return GN_ERR;
    }
    g_method_addrecord = (jmethodID)((*jni_env)->NewGlobalRef(jni_env, (jobject)mid));

    //Get method: delete records by row key
    mid = (*jni_env)->GetStaticMethodID(jni_env, g_hbase_client, "deleteRecord", "(Ljava/lang/String;Ljava/lang/String;)V");
    if(0 == mid)
    {
        LOG_PROC("ERROR", "Jni can not find method named \"deleteRecord\"");
        return GN_ERR;
    }
    g_method_deleterecord = (jmethodID)((*jni_env)->NewGlobalRef(jni_env, (jobject)mid));

    //Get method: get records by filter
    mid = (*jni_env)->GetStaticMethodID(jni_env, g_hbase_client, "getRecordsByFilter", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)[Ljava/lang/String;");
    if(0 == mid)
    {
        LOG_PROC("ERROR", "Jni can not find method named \"getRecordsByFilter\"");
        return GN_ERR;
    }
    g_method_getrecordsbyfilter = (jmethodID)((*jni_env)->NewGlobalRef(jni_env, (jobject)mid));

    //Get method: get all records
    mid = (*jni_env)->GetStaticMethodID(jni_env, g_hbase_client, "getAllRecords", "(Ljava/lang/String;Ljava/lang/String;)[Ljava/lang/String;");
    if(0 == mid)
    {
        LOG_PROC("ERROR", "Jni can not find method named \"getAllRecords\"");
        return GN_ERR;
    }
    g_method_getallrecords = (jmethodID)((*jni_env)->NewGlobalRef(jni_env, (jobject)mid));

    //Get method: get one record
    mid = (*jni_env)->GetStaticMethodID(jni_env, g_hbase_client, "getOneRecord", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;");
    if(0 == mid)
    {
        LOG_PROC("ERROR", "Jni can not find method named \"getOneRecord\"");
        return GN_ERR;
    }
    g_method_getonerecord = (jmethodID)((*jni_env)->NewGlobalRef(jni_env, (jobject)mid));

    //Get the latest version of topology
    query_value(TOPO_VER, value);
    g_topology_version = atoi(value);
    LOG_PROC("INFO", "Topology version: %d", g_topology_version);

    //Get the latest master of topology
    query_value(MASTER_ID, value);
    g_master_id = strtoul(value, 0, 10);
    LOG_PROC("INFO", "User specified master is: %llu", g_master_id);

    return GN_OK;
}
示例#18
0
/*
INT4 add_flow_entry(gn_switch_t *sw, gn_flow_t *flow)
{
    uuid_t uuid_gen;
    if(sw->conn_state == INITSTATE)
    {
        return GN_ERR;
    }

    pthread_mutex_lock(&sw->flow_entry_mutex);
    if(NULL == find_flow_entry(sw, flow))
    {
        uuid_generate_random(uuid_gen);
        uuid_unparse(uuid_gen, flow->uuid);

        if(sw->flow_entries)
        {
            gn_flow_t *p_flow = sw->flow_entries;
            while(p_flow->next)
            {
                p_flow = p_flow->next;
            };

            p_flow->next = flow;
        }
        else
        {
            flow->prev = NULL;
            flow->next = NULL;
            sw->flow_entries = flow;
        }
    }
    else
    {
        pthread_mutex_unlock(&sw->flow_entry_mutex);
        return GN_ERR;
    }

    flow->status = ENTRY_DISABLED;
    pthread_mutex_unlock(&sw->flow_entry_mutex);
    return GN_OK;
}
*/
gn_flow_t* copy_flow_entry(gn_flow_t *src)
{
	gn_instruction_t *p_ins_src,*p_ins_dst;
	gn_instruction_t *p_ins_src_next;
	gn_instruction_t *p_ins_dst_next;
    gn_action_t *p_act_src = NULL, *p_act_src_next = NULL;
    gn_action_t *p_act_dst = NULL, *p_act_dst_next = NULL;
    gn_instruction_actions_t* p_inact_src,* p_inact_dst;
    gn_flow_t *dest = NULL;

	
	dest =(gn_flow_t *)mem_get(g_gnflow_mempool_id);
	
	//addedby:yhy
	if(NULL == dest)
	{
		LOG_PROC("ERROR", "%s -- mem_get(g_gnflow_mempool_id) Fail",FN);
		return NULL;
	}
	
	dest->prev = NULL;
	dest->next = NULL;
	memcpy(dest->uuid,src->uuid,sizeof(src->uuid));
	memcpy(dest->creater,src->creater,sizeof(src->creater));
	dest->create_time = src->create_time;
	dest->table_id = src->table_id;
	dest->status = src->status;
	dest->idle_timeout = src->idle_timeout;
	dest->hard_timeout = src->hard_timeout;
	dest->priority = src->priority;
	memcpy(&dest->stats,&src->stats,sizeof(src->stats));
	memcpy(&dest->match,&src->match,sizeof(src->match));
	
	if(src->instructions == NULL)
	{
		dest->instructions = NULL;
		return dest;
	}
	
	p_ins_src = src->instructions;

    while(p_ins_src)
    {
        p_ins_dst_next = mem_get(g_gninstruction_mempool_id);
		
		//addedby:yhy
		if(NULL == p_ins_dst_next)
		{
			LOG_PROC("ERROR", "%s -- mem_get(g_gninstruction_mempool_id) Fail",FN);
			return NULL;
		}
		
        p_ins_dst_next->type = p_ins_src->type;   
        if((p_ins_src->type == OFPIT_APPLY_ACTIONS) || (p_ins_src->type == OFPIT_WRITE_ACTIONS))
        {
        	p_inact_src = (gn_instruction_actions_t *)p_ins_src;
        	p_inact_dst = (gn_instruction_actions_t *)p_ins_dst_next;
            p_act_src = p_inact_src->actions;
           
            while(p_act_src)
            {
            	p_act_dst_next = mem_get(g_gnaction_mempool_id);
				
				//addedby:yhy
				if(NULL == p_act_dst_next)
				{
					LOG_PROC("ERROR", "%s -- mem_get(g_gnaction_mempool_id) Fail",FN);
					return NULL;
				}
				
            	memcpy(p_act_dst_next,p_act_src,sizeof(gn_action_t));
            	p_act_dst_next->next = NULL;
            	
            	if(p_inact_dst->actions == NULL)
            	{
            		p_inact_dst->actions = p_act_dst_next;
            	}
            	else
            	{
            		p_act_dst = p_inact_dst->actions;
            		while(p_act_dst->next)
            		{
            			p_act_dst = p_act_dst->next;
            		}
            		p_act_dst->next = p_act_dst_next;
            	}
                p_act_src_next = p_act_src->next; 
                p_act_src = p_act_src_next;
            }
        }

        if(dest->instructions == NULL)
        {
        	dest->instructions = p_ins_dst_next;
        	dest->instructions->next = NULL;
        }
        else
        {
			p_ins_dst = dest->instructions;
        	while(p_ins_dst->next)
    		{
    			p_ins_dst = p_ins_dst->next;
    		}
        	p_ins_dst->next = p_ins_dst_next;
        }
        
        p_ins_src_next = p_ins_src->next;        
        p_ins_src = p_ins_src_next;
    }

    return dest;
}
示例#19
0
文件: l3.c 项目: China863SDN/DCFabric
static INT4 l3_install_flow(gn_switch_t *sw, UINT4 gw_ip, UINT4 inport, ether_t *ether)
{
    flow_mod_req_info_t flow_mod_req;
    gn_flow_t *flow = NULL;
    gn_instruction_actions_t *instruction = NULL;
    gn_action_output_t *action_outport = NULL;
    INT4 ret = 0;
    UINT4 src_ip = 0;
    UINT4 dst_ip = 0;

    if(ether->proto == htons(ETHER_ARP))
    {
        arp_t *p_arp = (arp_t *)(ether);
        src_ip = ntohl(p_arp->sendip);
        dst_ip = ntohl(p_arp->targetip);
    }
    else if(ether->proto == htons(ETHER_IP))
    {
        ip_t *p_ip = (ip_t *)(ether);
        src_ip = ntohl(p_ip->src);
        dst_ip = ntohl(p_ip->dest);
    }
    else
    {
		//by:yhy add 201701051305
		LOG_PROC("ERROR", "l3_install_flow -- ether->proto return GN_ERR");
        return GN_ERR;
    }

    memset(&sw->flowmod_helper, 0, sizeof(gn_flowmod_helper_t));
//    flow = (gn_flow_t *)gn_malloc(sizeof(gn_flow_t));
    flow = &sw->flowmod_helper.flow;
    strncpy(flow->creater, FLOW_L3_CREATER, sizeof(FLOW_L3_CREATER));
    flow->create_time = g_cur_sys_time.tv_sec;
    flow->table_id = 0;
    flow->idle_timeout = g_l3_flow_entry_idle_time;
    flow->hard_timeout = g_l3_flow_entry_hard_time;
    flow->priority = 1;
    flow->match.type = OFPMT_OXM;

    flow->match.oxm_fields.ipv4_dst = src_ip;
    flow->match.oxm_fields.mask |= (1 << OFPXMT_OFB_IPV4_DST);

    flow->match.oxm_fields.eth_type = ETHER_IP;
    flow->match.oxm_fields.mask |= (1 << OFPXMT_OFB_ETH_TYPE);

//    instruction = (gn_instruction_actions_t *)gn_malloc(sizeof(gn_instruction_actions_t));
    instruction = &sw->flowmod_helper.instruction;
    instruction->type = OFPIT_APPLY_ACTIONS;
    instruction->next = flow->instructions;
    flow->instructions = (gn_instruction_t *)instruction;

//    action_outport = (gn_action_output_t *)gn_malloc(sizeof(gn_action_output_t));
    action_outport = &sw->flowmod_helper.action_output;
    action_outport->port = inport;
    action_outport->next = instruction->actions;
    instruction->actions = (gn_action_t *)action_outport;

    flow_mod_req.xid = 0;
    flow_mod_req.buffer_id = 0xffffffff;
    flow_mod_req.out_port = 0xffffffff;
    flow_mod_req.out_group = 0xffffffff;
    flow_mod_req.command = OFPFC_ADD;
    flow_mod_req.flags = OFPFF13_SEND_FLOW_REM;
    flow_mod_req.flow = flow;

//    add_flow_entry(sw, flow);
    if(sw->ofp_version == OFP10_VERSION)
    {
        ret = sw->msg_driver.msg_handler[OFPT_FLOW_MOD](sw, (UINT1 *)&flow_mod_req);
    }
    else
    {
        ret = sw->msg_driver.msg_handler[OFPT13_FLOW_MOD](sw, (UINT1 *)&flow_mod_req);
    }

    //arp查找目的IP
    if(gw_ip)
    {
        UINT4 port_idx = 0;

        for(port_idx = 0; port_idx < sw->n_ports; port_idx++)
        {
           //if(!(sw->neighbor[port_idx]))            //从非SW互联端口寻找
           if(!(sw->neighbor[port_idx]->bValid))            //从非SW互联端口寻找
           {
               arp_request(sw, ntohl(gw_ip), dst_ip, sw->ports[port_idx].port_no);
           }
        }
    }

    return ret;
}