This commit is contained in:
Carl-Benedikt Krüger 2011-06-27 12:31:06 +02:00
parent c78b0e9f56
commit 40da25fd3e
2 changed files with 161 additions and 0 deletions

View file

@ -144,6 +144,14 @@ int network_shutdown(void)
int network_init(void)
{
tcpip_init(tcp_init_ok,NULL);
kprintf("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
mmnif_open();
kprintf("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
return 0;
#if 0
#if defined(CONFIG_LWIP)
// Initialize lwIP modules
lwip_init();
@ -154,4 +162,5 @@ int network_init(void)
#else
return 0;
#endif
#endif
}

View file

@ -26,6 +26,14 @@
#include <metalsvm/syscall.h>
#ifdef CONFIG_ROCKCREEK
#include <asm/icc.h>
#include <asm/RCCE_lib.h>
#include <asm/RCCE.h>
#include <asm/RCCE_lib.h>
#include <asm/iRCCE.h>
#include <asm/iRCCE_lib.h>
#include <asm/SCC_API.h>
#include <lwip/sockets.h>
#endif
static sem_t consuming, producing;
@ -119,8 +127,151 @@ static int STDCALL join_test(void* arg)
void ping_send_now();
__inline int get_core_no(void)
{
unsigned int tmp;
unsigned int pid;
unsigned int x,y,z;
/* Determine the local IP address from the core number in the
* tile ID register
*/
tmp = ReadConfigReg(0xF8000000 + 0x100);
x = (tmp>>3) & 0x0f; /* bits 06:03 */
y = (tmp>>7) & 0x0f; /* bits 10:07 */
z = (tmp ) & 0x07; /* bits 02:00 */
pid = 12*y + 2*x + z;
/* Add 1 to the processor ID to avoid *.*.*.0 IP addresses */
return pid;
}s
void* server_task(void* e)
{
int sockfd, newsockfd, portno, clilen;
char buffer[256];
struct sockaddr_in serv_addr, cli_addr;
int n;
/* First call to socket() function */
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
{
kprintf("ERROR opening socket");
return;
}
/* Initialize socket structure */
memset((char *) &serv_addr,0, sizeof(serv_addr));
portno = 5001;
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = INADDR_ANY;
serv_addr.sin_port = htons(portno);
kprintf("binding");
/* Now bind the host address using bind() call.*/
if (bind(sockfd, (struct sockaddr *) &serv_addr,
sizeof(serv_addr)) < 0)
{
kprintf("ERROR on binding");
return;
}
/* Now start listening for the clients, here process will
* go in sleep mode and will wait for the incoming connection
*/
kprintf("listening");
listen(sockfd,5);
clilen = sizeof(cli_addr);
/* Accept actual connection from the client */
kprintf("accepting");
newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr,
&clilen);
if (newsockfd < 0)
{
kprintf("ERROR on accept");
return;
}
/* If connection is established then start communicating */
memset(buffer,0,256);
kprintf("recieving");
n = read( newsockfd,buffer,255 );
if (n < 0)
{
kprintf("ERROR reading from socket");
return;
}
kprintf("Here is the message: %s\n",buffer);
/* Write a response to the client */
kprintf("writing");
n = write(newsockfd,"I got your message",18);
if (n < 0)
{
kprintf("ERROR writing to socket");
return;
}
return 0;
}
void* client_task(void* e)
{
char dir[256];
int sd;
struct sockaddr_in sin;
struct sockaddr_in pin;
struct hostent *hp;
/* fill in the socket structure with host information */
memset(&pin, 0, sizeof(pin));
pin.sin_family = AF_INET;
pin.sin_addr.s_addr = inet_addr("192.168.0.1");
pin.sin_port = htons(5001);
/* grab an Internet domain socket */
if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
kprintf("socketfail");
return;
}
kprintf("connecting");
/* connect to PORT on HOST */
if (connect(sd,(struct sockaddr *) &pin, sizeof(pin)) == -1) {
kprintf("connectfail");
return;
}
kprintf("sending");
/* send a message to the server PORT on machine HOST */
if (send(sd, "HELLO THERE", strlen("HELLO THERE"), 0) == -1) {
kprintf("sendfail");
return;
}
kprintf("recieving");
/* wait for a message to come back from the server */
if (recv(sd, dir, 256, 0) == -1) {
kprintf("recvfail");
return;
}
/* spew-out the results and bail out of here! */
kprintf("%s\n", dir);
close(sd);
return NULL;
}
int test_init(void)
{
if (!get_core_no())
create_kernel_task(NULL,server_task,NULL);
else
create_kernel_task(NULL,client_task,NULL);
#if 0
char* argv[] = {"/bin/tests", NULL};
sem_init(&producing, 1);
@ -137,5 +288,6 @@ int test_init(void)
//create_user_task(NULL, "/bin/jacobi", argv);
//create_user_task(NULL, "/bin/jacobi", argv);
#endif
return 0;
}