moved old tests to attic, updated selftest and host config files

This commit is contained in:
Joseph Henry
2017-06-05 17:10:24 -07:00
parent 19839eeac9
commit a94979ecd0
12 changed files with 42 additions and 28 deletions

View File

@@ -1,12 +1,14 @@
nwid c7cd7c9e1b0f52a2
mode server
mode client
local_path zt2
local_path zt1
local_port 4545
local_ipv4 10.9.9.41
local_port6 4646
local_ipv4 10.9.9.50
local_ipv6 fde5:cd7a:9edc:0f12:7399:98b2:5722:9143
remote_path zt1
remote_path zt2
remote_port 4545
remote_ipv4 10.9.9.40
remote_port6 4646
remote_ipv4 10.9.9.51
remote_ipv6 fde5:cd72:9e17:0fdb:7e99:1369:4d5b:fe3f

View File

@@ -1,12 +1,14 @@
nwid c7cd7c9e1b0f52a2
mode client
mode server
local_path zt1
local_path zt2
local_port 4545
local_ipv4 10.9.9.40
local_port6 4646
local_ipv4 10.9.9.51
local_ipv6 fde5:cd72:9e17:0fdb:7e99:1369:4d5b:fe3f
remote_path zt2
remote_path zt1
remote_port 4545
remote_ipv4 10.9.9.41
remote_port6 4646
remote_ipv4 10.9.9.50
remote_ipv6 fde5:cd7a:9edc:0f12:7399:98b2:5722:9143

View File

@@ -883,16 +883,18 @@ int main(int argc , char *argv[])
return 1;
}
int err = 0;
int type = 0;
int protocol = 0;
int mode = 0;
int port = 0;
int local_port = 0;
int remote_port = 0;
int operation = 0;
int n_count = 0;
int delay = 0;
int err = 0;
int type = 0;
int protocol = 0;
int mode = 0;
int port = 0;
int local_port = 0;
int remote_port = 0;
int local_port6 = 0;
int remote_port6 = 0;
int operation = 0;
int n_count = 0;
int delay = 0;
std::string nwid, stype, path = argv[1];
std::string ipstr, ipstr6, local_ipstr, local_ipstr6, remote_ipstr, remote_ipstr6;
@@ -921,13 +923,18 @@ int main(int argc , char *argv[])
local_port = atoi(testConf["local_port"].c_str());
remote_port = atoi(testConf["remote_port"].c_str());
local_port6 = atoi(testConf["local_port6"].c_str());
remote_port6 = atoi(testConf["remote_port6"].c_str());
fprintf(stderr, "local_ipstr = %s\n", local_ipstr.c_str());
fprintf(stderr, "local_ipstr6 = %s\n", local_ipstr6.c_str());
fprintf(stderr, "remote_ipstr = %s\n", remote_ipstr.c_str());
fprintf(stderr, "remote_ipstr6 = %s\n", remote_ipstr6.c_str());
fprintf(stderr, "remote_port = %d\n", remote_port);
fprintf(stderr, "remote_port6 = %d\n", remote_port6);
fprintf(stderr, "local_port = %d\n", local_port);
fprintf(stderr, "local_port6 = %d\n", local_port6);
}
else
{
@@ -1077,16 +1084,14 @@ int main(int argc , char *argv[])
do_test(path, nwid, type, protocol, mode, ipstr, port, operation, n_count, delay);
sleep(3);
// IPV6
printf("performing COMPREHENSIVE ipv6 test\n");
/* Each host must operate as the counterpart to the other, thus, each mode
* will call the same test helper functions in different orders
* Additionally, the test will use the preset paremeters below for the test:
*/
/*
delay = 0;
n_count = 10;
type = TEST_TYPE_SIMPLE;
@@ -1095,13 +1100,13 @@ int main(int argc , char *argv[])
if(mode == TEST_MODE_SERVER) {
printf("starting comprehensive test as SERVER\n");
port = local_port;
port = local_port6;
ipstr6 = local_ipstr6;
}
else if(mode == TEST_MODE_CLIENT) {
printf("starting comprehensive test as CLIENT (waiting, giving server time to start)\n");
sleep(10); // give the server some time to come online before beginning test
port = remote_port;
port = remote_port6;
ipstr6 = remote_ipstr6;
}
@@ -1112,13 +1117,13 @@ int main(int argc , char *argv[])
// swtich modes (client/server)
if(mode == TEST_MODE_SERVER) {
printf("\nswitching from SERVER to CLIENT mode\n");
port = remote_port;
port = remote_port6;
ipstr6 = remote_ipstr6;
mode = TEST_MODE_CLIENT;
}
else if(mode == TEST_MODE_CLIENT) {
printf("switching from CLIENT to SERVER mode\n");
port = local_port;
port = local_port6;
ipstr6 = local_ipstr6;
mode = TEST_MODE_SERVER;
}
@@ -1126,7 +1131,6 @@ int main(int argc , char *argv[])
// IPV4 (second test)
do_test(path, nwid, type, protocol, mode, ipstr6, port, operation, n_count, delay);
sleep(3);
*/
}

View File

@@ -1,63 +0,0 @@
// TCP Client test program
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <stdlib.h>
int atoi(const char *str);
int close(int filedes);
#define MSG_SZ 128
int main(int argc , char *argv[])
{
if(argc < 3) {
printf("usage: client <addr> <port> <single|multiple> <n?>\n");
return 1;
}
int sock, port = atoi(argv[2]);
struct sockaddr_in server;
char message[MSG_SZ] , server_reply[MSG_SZ];
sock = socket(AF_INET , SOCK_STREAM , 0);
if (sock == -1) {
printf("could not create socket");
}
server.sin_addr.s_addr = inet_addr(argv[1]);
server.sin_family = AF_INET;
server.sin_port = htons( port );
printf("connecting...\n");
if (connect(sock , (struct sockaddr *)&server , sizeof(server)) < 0) {
perror("connect failed. Error");
return 1;
}
printf("connected\n");
char *msg = (char*)"welcome to the machine!";
while(1)
{
// TX
if(send(sock, msg, strlen(msg), 0) < 0) {
printf("send failed");
return 1;
}
else {
printf("TX: %s\n", msg);
printf("len = %ld\n", strlen(msg));
int bytes_read = read(sock, server_reply, MSG_SZ);
if(bytes_read < 0)
printf("\tRX: Nothing\n");
else
printf("\tRX = (%d bytes): %s\n", bytes_read, server_reply);
}
}
close(sock);
return 0;
}

View File

@@ -1,72 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
void error(char *msg) {
perror(msg);
exit(0);
}
int main(int argc, char *argv[]) {
int sockfd, portno, n;
struct sockaddr_in6 serv_addr;
struct hostent *server;
char buffer[256] = "This is a string from client!";
if (argc < 3) {
printf("Usage: %s \n", argv[0]);
exit(0);
}
portno = atoi(argv[2]);
printf("\nIPv6 TCP Client Started...\n");
//Sockets Layer Call: socket()
sockfd = socket(AF_INET6, SOCK_STREAM, 0);
if (sockfd < 0)
printf("ERROR opening socket");
//Sockets Layer Call: gethostbyname2()
server = gethostbyname2(argv[1],AF_INET6);
if (server == NULL) {
printf("ERROR, no such host\n");
exit(0);
}
memset((char *) &serv_addr, 0, sizeof(serv_addr));
serv_addr.sin6_flowinfo = 0;
serv_addr.sin6_family = AF_INET6;
memmove((char *) &serv_addr.sin6_addr.s6_addr, (char *) server->h_addr, server->h_length);
serv_addr.sin6_port = htons(portno);
//Sockets Layer Call: connect()
if (connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
printf("ERROR connecting");
//Sockets Layer Call: send()
n = send(sockfd,buffer, strlen(buffer)+1, 0);
if (n < 0)
printf("ERROR writing to socket");
printf("sent %d bytes\n", n);
memset(buffer, 0, 256);
//Sockets Layer Call: recv()
printf("reading...\n");
n = recv(sockfd, buffer, 255, 0);
if (n < 0)
printf("ERROR reading from socket");
printf("Message from server: %s\n", buffer);
//Sockets Layer Call: close()
close(sockfd);
return 0;
}

View File

@@ -1,63 +0,0 @@
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <stdlib.h>
int atoi(const char *str);
int main(int argc , char *argv[])
{
if(argc < 2) {
printf("usage: tcp_server <port>\n");
return 0;
}
int comm_fd, sock, client_sock, c, read_size, port = atoi(argv[1]);
char client_message[2000];
struct sockaddr_in servaddr;
struct sockaddr_in client;
sock = socket(AF_INET, SOCK_STREAM, 0);
bzero( &servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htons(INADDR_ANY);
servaddr.sin_port = htons(port);
bind(sock, (struct sockaddr *) &servaddr, sizeof(servaddr));
printf("listening\n");
listen(sock , 3);
printf("waiting to accept\n");
c = sizeof(struct sockaddr_in);
client_sock = accept(sock, (struct sockaddr *)&client, (socklen_t*)&c);
if (client_sock < 0) {
perror("accept failed");
return 0;
}
printf("connection accepted\n reading...\n");
// RX
int msglen = 1024;
unsigned long count = 0;
while(1)
{
count++;
int bytes_read = read(client_sock, client_message, msglen);
printf("[%lu] RX = (%d): %s\n", count, bytes_read, client_message);
/*
for(int i=0; i<bytes_read; i++) {
printf("%c", client_message[i]);
}
*/
// TX
//int bytes_written = write(client_sock, "Server here!", 12);
//printf("\t\nTX = %d\n", bytes_written);
}
return 0;
}

View File

@@ -1,83 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
void error(char *msg) {
perror(msg);
exit(1);
}
int main(int argc, char *argv[]) {
int sockfd, newsockfd, portno;
socklen_t clilen;
char buffer[256];
struct sockaddr_in6 serv_addr, cli_addr;
int n;
char client_addr_ipv6[100];
if (argc < 2) {
printf("Usage: %s \n", argv[0]);
exit(0);
}
printf("\nIPv6 TCP Server Started...\n");
//Sockets Layer Call: socket()
sockfd = socket(AF_INET6, SOCK_STREAM, 0);
if (sockfd < 0)
printf("ERROR opening socket");
bzero((char *) &serv_addr, sizeof(serv_addr));
portno = atoi(argv[1]);
serv_addr.sin6_flowinfo = 0;
serv_addr.sin6_family = AF_INET6;
serv_addr.sin6_addr = in6addr_any;
serv_addr.sin6_port = htons(portno);
//Sockets Layer Call: bind()
if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
printf("ERROR on binding");
//Sockets Layer Call: listen()
listen(sockfd, 5);
clilen = sizeof(cli_addr);
//Sockets Layer Call: accept()
newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
if (newsockfd < 0)
printf("ERROR on accept");
//Sockets Layer Call: inet_ntop()
inet_ntop(AF_INET6, &(cli_addr.sin6_addr),client_addr_ipv6, 100);
printf("Incoming connection from client having IPv6 address: %s\n",client_addr_ipv6);
memset(buffer,0, 256);
//Sockets Layer Call: recv()
n = recv(newsockfd, buffer, 255, 0);
if (n < 0)
printf("ERROR reading from socket");
printf("Message from client: %s\n", buffer);
//Sockets Layer Call: send()
printf("sending...\n");
n = send(newsockfd, "Server got your message", 23+1, 0);
if (n < 0)
printf("ERROR writing to socket");
//Sockets Layer Call: close()
close(sockfd);
close(newsockfd);
return 0;
}

View File

@@ -1,88 +0,0 @@
/*
* udpclient.c - A simple UDP client
* usage: udpclient <host> <port>
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <fcntl.h>
#define BUFSIZE 1024
/*
* error - wrapper for perror
*/
void error(char *msg) {
perror(msg);
exit(0);
}
int main(int argc, char **argv) {
int sock, portno, n;
int serverlen;
struct sockaddr_in serveraddr;
struct hostent *server;
char *hostname;
char buf[BUFSIZE];
/* check command line arguments */
if (argc != 3) {
fprintf(stderr,"usage: %s <hostname> <port>\n", argv[0]);
exit(0);
}
hostname = argv[1];
portno = atoi(argv[2]);
/* socket: create the socket */
sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock < 0)
printf("ERROR opening socket");
/* gethostbyname: get the server's DNS entry */
server = gethostbyname(hostname);
if (server == NULL) {
printf("ERROR, no such host as %s\n", hostname);
exit(0);
}
/* build the server's Internet address */
bzero((char *) &serveraddr, sizeof(serveraddr));
serveraddr.sin_family = AF_INET;
bcopy((char *)server->h_addr,
(char *)&serveraddr.sin_addr.s_addr, server->h_length);
serveraddr.sin_port = htons(portno);
/* get a message from the user */
char *msg = (char*)"A message to the server!";
fcntl(sock, F_SETFL, O_NONBLOCK);
long count = 0;
while(1)
{
count++;
printf("\n\n\nTX(%lu)...\n", count);
sleep(1);
//usleep(10000);
//bzero(buf, BUFSIZE);
//printf("\nPlease enter msg: ");
//fgets(buf, BUFSIZE, stdin);
/* send the message to the server */
serverlen = sizeof(serveraddr);
n = sendto(sock, msg, strlen(msg), 0, (struct sockaddr *)&serveraddr, serverlen);
//if (n < 0)
// error("ERROR in sendto");
/* print the server's reply */
memset(buf, 0, sizeof(buf));
n = recvfrom(sock, buf, BUFSIZE, 0, (struct sockaddr *)&serveraddr, (socklen_t *)&serverlen);
//if (n < 0)
// printf("ERROR in recvfrom: %d", n);
printf("Echo from server: %s", buf);
}
return 0;
}

View File

@@ -1,43 +0,0 @@
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <string.h>
#define MAXBUF 65536
int main(int argc, char* argv[])
{
int status;
struct addrinfo sainfo, *psinfo;
struct hostent *server;
char buffer[MAXBUF];
int sock, portno, n;
struct sockaddr_in6 serv_addr;
if(argc < 2)
printf("Specify a port number\n"), exit(1);
sock = socket(PF_INET6, SOCK_DGRAM,0);
portno = atoi(argv[2]);
server = gethostbyname2(argv[1],AF_INET6);
memset((char *) &serv_addr, 0, sizeof(serv_addr));
serv_addr.sin6_flowinfo = 0;
serv_addr.sin6_family = AF_INET6;
memmove((char *) &serv_addr.sin6_addr.s6_addr, (char *) server->h_addr, server->h_length);
serv_addr.sin6_port = htons(portno);
sprintf(buffer,"Ciao");
status = sendto(sock, buffer, strlen(buffer), 0, (const struct sockaddr *)&serv_addr, sizeof(serv_addr));
printf("buffer : %s \t%d\n", buffer, status);
close(sock);
return 0;
}

View File

@@ -1,86 +0,0 @@
// UDP Server test program
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#define MAXBUF 1024*1024
void echo(int sock) {
char bufin[MAXBUF];
struct sockaddr_in remote;
int n;
socklen_t len = sizeof(remote);
long count = 0;
while (1) {
sleep(1);
//usleep(50);
count++;
// read a datagram from the socket (put result in bufin)
n=recvfrom(sock,bufin,MAXBUF,0,(struct sockaddr *)&remote,&len);
// print out the address of the sender
printf("DGRAM from %s:%d\n", inet_ntoa(remote.sin_addr), ntohs(remote.sin_port));
if (n<0) {
perror("Error receiving data");
} else {
printf("GOT %d BYTES (count = %ld)\n", n, count);
// Got something, just send it back
// sendto(sock,bufin,n,0,(struct sockaddr *)&remote,len);
printf("RX = %s\n", bufin);
}
}
}
int main(int argc, char *argv[]) {
if(argc < 2) {
printf("usage: udp_server <port>\n");
return 0;
}
int sock, port = atoi(argv[1]);
socklen_t len;
struct sockaddr_in skaddr;
struct sockaddr_in skaddr2;
// Create socket
if ((sock = socket( PF_INET, SOCK_DGRAM, 0)) < 0) {
printf("error creating socket\n");
return 0;
}
// Create address
skaddr.sin_family = AF_INET;
skaddr.sin_addr.s_addr = htonl(INADDR_ANY);
skaddr.sin_port = htons(port);
// Bind to address
if (bind(sock, (struct sockaddr *) &skaddr, sizeof(skaddr))<0) {
printf("error binding\n");
return 0;
}
// find out what port we were assigned
len = sizeof( skaddr2 );
//if (getsockname(sock, (struct sockaddr *) &skaddr2, &len)<0) {
// printf("error getsockname\n");
// return 0;
//}
// Display address:port to verify it was sent over RPC correctly
/*
port = ntohs(skaddr2.sin_port);
int ip = skaddr2.sin_addr.s_addr;
unsigned char d[4];
d[0] = ip & 0xFF;
d[1] = (ip >> 8) & 0xFF;
d[2] = (ip >> 16) & 0xFF;
d[3] = (ip >> 24) & 0xFF;
printf("bound to address: %d.%d.%d.%d : %d\n", d[0],d[1],d[2],d[3], port);
*/
// RX
echo(sock);
return(0);
}

View File

@@ -1,44 +0,0 @@
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdlib.h>
#include <string.h>
#define MAXBUF 65536
int main(int argc, char *argv[])
{
int sock;
int n;
struct sockaddr_in6 sin6;
socklen_t sin6len;
char buffer[MAXBUF];
sock = socket(PF_INET6, SOCK_DGRAM,0);
sin6len = sizeof(struct sockaddr_in6);
memset(&sin6, 0, sin6len);
sin6.sin6_port = htons(atoi(argv[1]));
sin6.sin6_family = AF_INET6;
sin6.sin6_addr = in6addr_any;
n = bind(sock, (struct sockaddr *)&sin6, sin6len);
if(-1 == n)
perror("bind"), exit(1);
//n = getsockname(sock, (struct sockaddr *)&sin6, &sin6len);
//printf("%d\n", ntohs(sin6.sin6_port));
while (1) {
sleep(1);
n = recvfrom(sock, buffer, MAXBUF, 0, (struct sockaddr *)&sin6, &sin6len);
printf("n = %d, buffer : %s\n", n, buffer);
}
shutdown(sock, 2);
close(sock);
return 0;
}