예제 #1
0
int main(int argc, char *argv[])
{

  CHECK_INIT_RETURN(itti_init(TASK_MAX, THREAD_MAX, MESSAGES_ID_MAX,
                              tasks_info, messages_info, messages_definition_xml,
                              mme_config.itti_config.log_file));
  /* Parse the command line for options and set the mme_config accordingly. */
  CHECK_INIT_RETURN(config_parse_opt_line(argc, argv, &mme_config) < 0);
  MSC_INIT(MSC_MME_GW, THREAD_MAX+TASK_MAX);

  /* Calling each layer init function */
  CHECK_INIT_RETURN(log_init(&mme_config, oai_epc_log_specific));
  CHECK_INIT_RETURN(nas_init(&mme_config));
  CHECK_INIT_RETURN(sctp_init(&mme_config));
  CHECK_INIT_RETURN(udp_init(&mme_config));
  CHECK_INIT_RETURN(gtpv1u_init(&mme_config));
  CHECK_INIT_RETURN(s1ap_mme_init(&mme_config));
  CHECK_INIT_RETURN(mme_app_init(&mme_config));
  CHECK_INIT_RETURN(s6a_init(&mme_config));
  CHECK_INIT_RETURN(sgw_lite_init(mme_config.config_file));
  /* Handle signals here */
  itti_wait_tasks_end();

  return 0;
}
예제 #2
0
파일: sctp.c 프로젝트: iHaD/openss7
/*
 *  =========================================================================
 *
 *  Kernel Module Initialization
 *
 *  =========================================================================
 */
int
init_module(void)
{
	cmn_err(CE_NOTE, SCTP_BANNER);	/* console splash */
	sctp_init();
	sctp_n_init();
	sctp_t_init();
	return (0);
}
int main(int argc, char *argv[])
{

	pthread_t tid;
	struct socket *sock;
	unsigned int i;
	struct sockaddr_in addr;
	char buffer[BUFFER_SIZE];

	sctp_init();

	pthread_create(&tid, NULL, &discard_server, (void *)NULL);
	sleep(1);
	
	memset((void *)buffer, 'A', BUFFER_SIZE);
	
	if ((sock = userspace_socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP)) == NULL) {
		perror("userspace_socket");
	}

	memset((void *)&addr, 0, sizeof(struct sockaddr_in));
#ifdef HAVE_SIN_LEN
	addr.sin_len         = sizeof(struct sockaddr_in);
#endif
	addr.sin_family      = AF_INET;
	addr.sin_port        = htons(0);
	addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
	if (userspace_bind(sock, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) < 0) {
		perror("userspace_bind");
	}

	memset((void *)&addr, 0, sizeof(struct sockaddr_in));
#ifdef HAVE_SIN_LEN
	addr.sin_len         = sizeof(struct sockaddr_in);
#endif
	addr.sin_family      = AF_INET;
	addr.sin_port        = htons(DISCARD_PORT);
	addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);

	if (userspace_connect(sock, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) < 0)
		perror("userspace_connect");

	for (i = 0; i <  NUMBER_OF_MESSAGES; i++) {
		if (userspace_sctp_sendmsg(sock, (const void *)buffer, BUFFER_SIZE, (struct sockaddr *)&addr, sizeof(struct sockaddr_in), htonl(3), 0, 2, 0, 0) < 0) {
			perror("userspace_sctp_sendmsg");
		}
	}
	userspace_close(sock);
	sleep(1);
	return(0);
}
예제 #4
0
extern void #MARK_init(void);
void init_extensions(void) {
	ah_init();
	addrtype_init();
	comment_init();
	2connmark_init();
	conntrack_init();
	2dscp_init();
	2ecn_init();
	esp_init();
	hashlimit_init();
	helper_init();
	icmp_init();
	iprange_init();
	length_init();
	limit_init();
	mac_init();
	multiport_init();
	#2mark_init();
	owner_init();
	physdev_init();
	pkttype_init();
	policy_init();
	realm_init();
	sctp_init();
	standard_init();
	state_init();
	tcp_init();
	2tcpmss_init();
	2tos_init();
	2ttl_init();
	udp_init();
	unclean_init();
	CLASSIFY_init();
	CONNMARK_init();
	DNAT_init();
	LOG_init();
	#DSCP_init();
	ECN_init();
	MASQUERADE_init();
	MIRROR_init();
	NETMAP_init();
	NFQUEUE_init();
	NOTRACK_init();
	REDIRECT_init();
	REJECT_init();
	#MARK_init();
}
예제 #5
0
파일: net.c 프로젝트: dolfly/nmdb
void net_loop(void)
{
	int tipc_fd = -1;
	int tcp_fd = -1;
	int udp_fd = -1;
	int sctp_fd = -1;
	struct event tipc_evt, tcp_evt, udp_evt, sctp_evt,
		     sigterm_evt, sigint_evt,
		     sighup_evt, sigusr1_evt, sigusr2_evt;

	event_init();

	/* ENABLE_* are preprocessor constants defined on the command line by
	 * make. */

	if (ENABLE_TIPC) {
		tipc_fd = tipc_init();
		if (tipc_fd < 0) {
			errlog("Error initializing TIPC");
			exit(1);
		}

		event_set(&tipc_evt, tipc_fd, EV_READ | EV_PERSIST, tipc_recv,
				&tipc_evt);
		event_add(&tipc_evt, NULL);
	}

	if (ENABLE_TCP) {
		tcp_fd = tcp_init();
		if (tcp_fd < 0) {
			errlog("Error initializing TCP");
			exit(1);
		}

		event_set(&tcp_evt, tcp_fd, EV_READ | EV_PERSIST,
				tcp_newconnection, &tcp_evt);
		event_add(&tcp_evt, NULL);
	}

	if (ENABLE_UDP) {
		udp_fd = udp_init();
		if (udp_fd < 0) {
			errlog("Error initializing UDP");
			exit(1);
		}

		event_set(&udp_evt, udp_fd, EV_READ | EV_PERSIST, udp_recv,
				&udp_evt);
		event_add(&udp_evt, NULL);
	}

	if (ENABLE_SCTP) {
		sctp_fd = sctp_init();
		if (sctp_fd < 0) {
			errlog("Error initializing SCTP");
			exit(1);
		}

		event_set(&sctp_evt, sctp_fd, EV_READ | EV_PERSIST, sctp_recv,
				&sctp_evt);
		event_add(&sctp_evt, NULL);
	}

	signal_set(&sigterm_evt, SIGTERM, exit_sighandler, &sigterm_evt);
	signal_add(&sigterm_evt, NULL);
	signal_set(&sigint_evt, SIGINT, exit_sighandler, &sigint_evt);
	signal_add(&sigint_evt, NULL);
	signal_set(&sighup_evt, SIGHUP, logfd_reopen_sighandler,
			&sighup_evt);
	signal_add(&sighup_evt, NULL);
	signal_set(&sigusr1_evt, SIGUSR1, enable_read_only_sighandler,
			&sigusr1_evt);
	signal_add(&sigusr1_evt, NULL);
	signal_set(&sigusr2_evt, SIGUSR2, passive_to_active_sighandler,
			&sigusr2_evt);
	signal_add(&sigusr2_evt, NULL);

	event_dispatch();

	if (ENABLE_TIPC)
		event_del(&tipc_evt);
	if (ENABLE_TCP)
		event_del(&tcp_evt);
	if (ENABLE_UDP)
		event_del(&udp_evt);
	if (ENABLE_SCTP)
		event_del(&sctp_evt);

	signal_del(&sigterm_evt);
	signal_del(&sigint_evt);
	signal_del(&sigusr1_evt);
	signal_del(&sigusr2_evt);

	tipc_close(tipc_fd);
	tcp_close(tcp_fd);
	udp_close(udp_fd);
	sctp_close(sctp_fd);
}
int main(int argc, char **argv) {
    int i, j;
    int size, align_size;
    char *s_buf, *r_buf;
    double t_start = 0.0, t_end = 0.0, t = 0.0;


    struct sockaddr_in *dest = malloc(sizeof(struct sockaddr_in));
    struct sctp_sndrcvinfo sri;
    struct sockaddr_in cli;
    socklen_t s = sizeof(struct sockaddr_in);
    int msg_flags = 0;
    int n=-1;
    char mode[15];


    struct timeval start, end;
    struct dp datapoints[DATAPOINTS];
    int num_dp = 0;
    FILE *file;
    char filename[PRINTARRAY];
    char ascii_size[PRINTARRAY];
    int name[] = {CTL_KERN, KERN_OSTYPE};
    int namelen = 2;
    char oldval[15];
    size_t len = sizeof(oldval);
    int  error;    


    if (argc < 3) {
	printf("Usage: %s dst-ip dest-port\n", argv[0]);
	exit(1);
    }
    
#if defined(SCTP_USERMODE)
    uint32_t optval=1;
    struct socket *psock = NULL;
    strcpy(mode, "Userspace");
#else //kernel mode
    int sock_fd;
    strcpy(mode, "Kernel");
#endif


    align_size = getpagesize();
    assert(align_size <= MAX_ALIGNMENT);

    s_buf =
        (char *) (((unsigned long) s_buf1 + (align_size - 1)) /
                  align_size * align_size);
    r_buf =
        (char *) (((unsigned long) r_buf1 + (align_size - 1)) /
                  align_size * align_size);

    
    error = sysctl (name, namelen,
                    (void *)oldval, &len, NULL
                    /* newval */, 0 /* newlen */);
    if (error) {
        printf("sysctl() error\n");
        exit(1);
    }

    strcpy(filename, "BWbenchmark");
    sprintf(ascii_size,"%s%smode",oldval,mode);
    strcat(filename, ascii_size);
    strcat(filename,".txt");

    
#if defined(SCTP_USERMODE)
    sctp_init(); 
    SCTP_BASE_SYSCTL(sctp_udp_tunneling_for_client_enable)=1; 
    
    if( !(psock = userspace_socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP)) ){
        printf("user_socket() returned NULL\n");
        exit(1);
    }
#else //Kernel mode
    if((sock_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP)) == -1) {
        printf("socket error\n");
        exit(1);
    }
#endif
    
    /* prepare destination adddress */
    bzero(dest, sizeof(struct sockaddr_in));
    dest->sin_family = AF_INET;
    dest->sin_addr.s_addr = inet_addr(argv[1]);
    dest->sin_port = htons((unsigned short) atoi(argv[2]));
#if defined(__Userspace_os_FreeBSD)
    dest->sin_len = sizeof(struct sockaddr);
#endif

#if defined(SCTP_USERMODE)
    /* call userspace_connect which eventually calls sctp_send_initiate */
    if( userspace_connect(psock, (struct sockaddr *) dest, sizeof(struct sockaddr_in)) == -1 ) {
        printf("userspace_connect failed.  exiting...\n");
        exit(1);        
    }

    sctp_setopt(psock, SCTP_NODELAY, &optval, sizeof(uint32_t), NULL);

#else //Kernel mode
    if((connect(sock_fd, (struct sockaddr *) dest, sizeof(struct sockaddr_in))) == -1) {
        perror("connect error\n");
        exit(1);
    }
    /* Setting the send and receive socket buffer sizes */
    const int maxbufsize = 65536 * 3;
    int sndrcvbufsize = maxbufsize;
    int sndrcvbufsize_len;
    int rc;
    sndrcvbufsize_len = sizeof(sndrcvbufsize);
    rc = setsockopt(sock_fd, SOL_SOCKET, SO_SNDBUF, &sndrcvbufsize, sndrcvbufsize_len);
    
    if (rc == -1) {
        perror("can't set the socket send size to requested one");
        exit(1);
    }
    
    rc = setsockopt(sock_fd, SOL_SOCKET, SO_RCVBUF, &sndrcvbufsize, sndrcvbufsize_len);
    
    if (rc == -1) {
        perror("can't set the socket receive size to requested one");
        exit(1);
    }
    
    /* turning nagle off */
    int no_nagle = 1;
    if (setsockopt(sock_fd, IPPROTO_SCTP,
                   SCTP_NODELAY, (char *) &no_nagle, sizeof(no_nagle)) < 0){
        perror("can't setsockopt to no_nagle\n");
        exit(1);
    }
#endif



    num_dp = 0;
    int retval = 0;

    printf("\nRunning in %s mode\nStoring results in file %s\n\n", mode, filename);

    fprintf(stdout, "# %s %s\n", mode, "Mode: Bandwidth Benchmark Similar to OSU");
    fprintf(stdout, "%-*s%*s\n", 10, "# Size", FIELD_WIDTH,
            "Bandwidth (MB/s)");
    fflush(stdout);


    /* Bandwidth test */
    for(size = 1; size <= MAX_MSG_SIZE; size *= 2) {
        /* touch the data */
        for(i = 0; i < size; i++) {
            s_buf[i] = 'a';
            r_buf[i] = 'b';
        }
        
        if(size > large_message_size) {
            loop = loop_large;
            skip = skip_large;
            window_size = window_size_large;
        }
        

        for(i = 0; i < loop + skip; i++) {
            if(i == skip) {
                gettimeofday(&start, NULL);
                t_start = (double) start.tv_sec + .000001 * (double) start.tv_usec;
            }
            
            for(j = 0; j < window_size; j++) {
#if defined(SCTP_USERMODE)
                if((retval = userspace_sctp_sendmsg(psock /* struct socket *so */,
                                                    s_buf /* const void *data */,
                                                    size /* size_t len */,
                                                    (struct sockaddr *)dest /* const struct sockaddr *to */,
                                                    sizeof(struct sockaddr_in) /* socklen_t tolen */,
                                                    0 /* u_int32_t ppid */,
                                                    0 /* u_int32_t flags */,
                                                    3 /* u_int16_t stream_no */,
                                                    0 /* u_int32_t timetolive */,
                                                    0 /* u_int32_t context */))<=0)
                    {
                        printf("userspace_sctp_sendmsg returned retval=%d errno=%d\n", retval, errno);
                        exit(1);
                        
                    }
#else //Kernel mode
                
                if ((retval = sctp_sendmsg(sock_fd, (void *)s_buf, (size_t)size, NULL, 0, 0, 0, 3, 0, 0)) <=0 )
                    {
                        printf("sctp_sendmsg returned retval=%d errno=%d\n", retval, errno);
                        exit(1);
                    }
#endif        
                
                
            }


#if defined(SCTP_USERMODE)
            if ((n = userspace_sctp_recvmsg(psock, r_buf, 4, (struct sockaddr *) &cli, &s, &sri, &msg_flags)) <=0 )
                {
                    printf(".....userspace_sctp_recvmsg returned n=%d errno=%d\n", n, errno);
                    break;
                }
#else  //Kernel mode
            if ((n = sctp_recvmsg(sock_fd, r_buf, 4, (struct sockaddr *) &cli, &s, &sri, &msg_flags)) <=0 )
                {
                    printf("sctp_recvmsg returned n=%d errno=%d\n", n, errno);
                    break;
                }
#endif
            
        }
        
        gettimeofday(&end, NULL);
        t_end = (double) end.tv_sec + .000001 * (double) end.tv_usec;
        
        t = t_end - t_start;
        
        double tmp = size / 1e6 * loop * window_size;
        
        fprintf(stdout, "%-*d%*.*f\n", 10, size, FIELD_WIDTH,
                FLOAT_PRECISION, tmp / t);
        fflush(stdout);
        datapoints[num_dp].msg_size = size;
        datapoints[num_dp].tottime = t;
        datapoints[num_dp].bw = tmp/t;
        num_dp++;
        
    }
    
    
    printf("Client closing socket...errno=%d\n", errno);
    free(dest);
#if defined(SCTP_USERMODE)
    userspace_close(psock);
#else
    close(sock_fd);
#endif
    
    printf("Sleeping for 60 secs\n");
    sleep(60);
    
    file = fopen(filename, "w+");
    if(file == NULL) {
        perror("could not open results file");
    } else {        
        for (j=0; j<num_dp; j++)
        {
            fprintf(file,"%d , %.2f , %.2f\n",datapoints[j].msg_size, datapoints[j].tottime, datapoints[j].bw); /*write datapoints to file*/
        }
        fclose(file);
    }


#if defined(SCTP_USERMODE)
    sctp_finish();
    //    pthread_exit(NULL);
#endif

    return 0;
        
}