review of Benedikt's virtual IP device

This commit is contained in:
Stefan Lankes 2011-07-04 13:02:19 -07:00
parent 227031a41c
commit 30aaa5fda3
7 changed files with 184 additions and 155 deletions

View file

@ -1,11 +1,28 @@
/*
* Copyright 2011 Carl-Benedikt Krueger, Chair for Operating Systems,
* RWTH Aachen University
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This file is part of MetalSVM.
*/
/*
* mmnif.c --- memmory mapped interface
*
* Virutal IP Interface for the concept processor SCC
*
* virutally tested under Windows 7
*
* Carl-Benedikt Krüger 2011
* Carl-Benedikt Krueger 2011
*
*/
@ -17,6 +34,8 @@
#include <metalsvm/mailbox.h> /* mailbox_ptr_t */
#endif
#ifdef CONFIG_LWIP
#include <lwip/netif.h> /* lwip netif */
#include <lwip/stats.h> /* inteface stats */
#include <netif/etharp.h> /* ethernet arp packets */
@ -49,7 +68,6 @@ extern HANDLE hProc;
#include <metalsvm/semaphore.h>
#include <asm/RCCE_lib.h>
#include <asm/RCCE.h>
#include <asm/RCCE_lib.h>
#include <asm/iRCCE.h>
@ -214,7 +232,7 @@ typedef struct mmnif
#ifdef WIN32
__inline int get_my_core_no(void)
__inline int RCCE_ue(void)
{
#ifndef RECV
return 1;
@ -223,28 +241,8 @@ __inline int get_my_core_no(void)
#endif
}
#else
__inline int get_my_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(local_crb + RCK_TILEID);
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;
}
#endif
/*
* memory maped interface helper functions
*/
@ -922,7 +920,7 @@ err_t mmnif_init(struct netif* netif)
/* Generate MAC address */
mmnif_dev->hwaddr[0] = 0x11;mmnif_dev->hwaddr[1] = 0x22;mmnif_dev->hwaddr[2] = 0x33;
mmnif_dev->hwaddr[3] = 0x44;mmnif_dev->hwaddr[4] = 0x55;mmnif_dev->hwaddr[5] = get_my_core_no()*0x11 +0x66;
mmnif_dev->hwaddr[3] = 0x44;mmnif_dev->hwaddr[4] = 0x55;mmnif_dev->hwaddr[5] = RCCE_ue()*0x11 +0x66;
/*
* Initialize the snmp variables and counters inside the struct netif.
@ -932,7 +930,7 @@ err_t mmnif_init(struct netif* netif)
NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, speed);
/* administrative details */
netif->name[0] = 'e';
netif->name[0] = 'm';
netif->name[1] = 'n';
netif->num = num;
num++;
@ -1214,7 +1212,7 @@ int mmnif_poll(void* e)
/* mmnif_irqhandler(): handles incoming interrupts
* its just a local wrapper for mmnif_rx()
*/
void mmnif_irqhandler()
void mmnif_irqhandler(void)
{
mmnif_t* mmnif;
/* return if mmnif_dev is not yet initialized*/
@ -1233,7 +1231,7 @@ void mmnif_irqhandler()
/*
* Open the interface should be called by kernel to use this network interface
*/
int mmnif_open()
int mmnif_open(void)
{
struct ip_addr ipaddr;
struct ip_addr netmask;
@ -1243,10 +1241,10 @@ int mmnif_open()
* Note: core 1 is the router core
*/
IP4_ADDR(&gw, 0,0,0,0);
IP4_ADDR(&ipaddr, 192,168,0,get_my_core_no() +1);
IP4_ADDR(&netmask, 255,0,0,0);
IP4_ADDR(&ipaddr, 192,168,0,RCCE_ue()+1);
IP4_ADDR(&netmask, 255,255,255,0);
own_ip_address+= get_my_core_no() +1;
own_ip_address += RCCE_ue()+1;
#ifdef WIN32
mmnif_dev = malloc(sizeof(struct netif));
@ -1271,7 +1269,7 @@ int mmnif_open()
}
/* set our network interface to the default interface for lwip*/
netif_set_default(mmnif_dev);
//netif_set_default(mmnif_dev);
/* tell lwip all initialization is done and we want to set it ab*/
netif_set_up(mmnif_dev);
@ -1308,7 +1306,7 @@ int mmnif_open()
* close the interface should be called by kernel to close this interface and release resources
* Note: it's temporarly empty. Support will be added.
*/
int mmnif_close()
int mmnif_close(void)
{
mmnif_t* mmnif;
@ -1336,3 +1334,5 @@ int mmnif_close()
#endif
return NULL;
}
#endif

View file

@ -1,3 +1,22 @@
/*
* Copyright 2011 Carl-Benedikt Krueger, Chair for Operating Systems,
* RWTH Aachen University
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This file is part of MetalSVM.
*/
#ifndef __MMNIF_H__
#define __MMNIF_H__
@ -21,12 +40,12 @@ typedef int int32_t;
/*
* Initialize the network driver for mmn
*/
int mmnif_open();
int mmnif_close();
int mmnif_open(void);
int mmnif_close(void);
int mmnif_poll(void* e);
int mmnif_worker(void* e);
void mmnif_irqhandler();
void mmnif_irqhandler(void);
#endif

View file

@ -1,3 +1,22 @@
/*
* Copyright 2011 Carl-Benedikt Krueger, Chair for Operating Systems,
* RWTH Aachen University
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This file is part of MetalSVM.
*/
#include "util.h"
@ -10,7 +29,8 @@ __inline int isprint(char e)
// hex_dumb display network packets in a good way
void hex_dump(unsigned n, const unsigned char* buf)
{
int on_this_line = 0;
int on_this_line = 0;
while (n-- > 0)
{
kprintf("%02X ", *buf++);

View file

@ -1,9 +1,26 @@
/*
* Copyright 2011 Carl-Benedikt Krueger, Chair for Operating Systems,
* RWTH Aachen University
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This file is part of MetalSVM.
*/
#ifndef __UTIL__
#define __UTIL__
// hex_dumb display network packets in a good way
void hex_dump(unsigned n, const unsigned char* buf);
#endif
#endif

View file

@ -39,6 +39,7 @@
#endif
#include <net/rtl8139.h>
#include <net/rckemac.h>
#include <net/mmnif.h>
#ifdef CONFIG_ROCKCREEK
#include <asm/RCCE.h>
#include <asm/RCCE_lib.h>
@ -113,6 +114,8 @@ int STDCALL network_task(void* arg)
rtl8139if_wait(&netif, 1);
udelay(500000);
}
#else
mmnif_open();
#endif
// start echo and ping server
@ -138,6 +141,8 @@ int STDCALL network_task(void* arg)
int network_shutdown(void)
{
mmnif_close();
done = 1;
return 0;
@ -150,13 +155,7 @@ static void tcp_init_ok(void* e)
int network_init(void)
{
tcpip_init(tcp_init_ok, NULL);
kprintf("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
mmnif_open();
kprintf("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
return 0;
#if 0
int ret = 0;
#if defined(CONFIG_LWIP)
// Initialize lwIP modules
@ -164,9 +163,8 @@ int network_init(void)
#endif
#if defined(CONFIG_LWIP) && (defined(CONFIG_PCI) || defined(CONFIG_ROCKCREEK))
return create_kernel_task(&netid, network_task, NULL);
#else
return 0;
#endif
ret = create_kernel_task(&netid, network_task, NULL);
#endif
return ret;
}

View file

@ -110,8 +110,8 @@ int main(void)
kprintf("Current allocated memory: %u KBytes\n", atomic_int32_read(&total_allocated_pages)*(PAGE_SIZE/1024));
kprintf("Current available memory: %u MBytes\n", atomic_int32_read(&total_available_pages)/((1024*1024)/PAGE_SIZE));
// sleep(5);
// list_root();
sleep(5);
list_root();
test_init();
per_core(current_task)->status = TASK_IDLE;
reschedule();

View file

@ -26,7 +26,6 @@
#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>
@ -125,116 +124,93 @@ static int STDCALL join_test(void* arg)
return 0;
}
#ifdef CONFIG_LWIP
void ping_send_now();
#endif
__inline int get_core_no(void)
#if defined(CONFIG_LWIP) && defined(CONFIG_ROCKCREEK)
static int STDCALL server_task(void* e)
{
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;
}
int sockfd, newsockfd, portno, clilen;
char buffer[256];
struct sockaddr_in serv_addr, cli_addr;
int n;
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, IPPROTO_TCP);
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);
/* First call to socket() function */
sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sockfd < 0)
{
kprintf("ERROR opening socket");
return -1;
}
/* 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;
}
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 -1;
}
/* 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);
/* 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);
/* Accept actual connection from the client */
kprintf("accepting");
newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr, &clilen);
if (newsockfd < 0)
{
kprintf("ERROR on accept");
return -1;
}
/* 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 -1;
}
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;
/* 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 -1;
}
return 0;
}
void* client_task(void* e)
static int STDCALL client_task(void* e)
{
char dir[256];
int sd;
struct sockaddr_in sin;
struct sockaddr_in pin;
struct hostent *hp;
sleep(1);
/* 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.2");
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, IPPROTO_TCP)) == -1) {
kprintf("socketfail");
return;
return -1;
}
kprintf("connecting with socket nr : %d",sd);
@ -242,19 +218,19 @@ void* client_task(void* e)
if (connect(sd,(struct sockaddr *) &pin, sizeof(pin)) == -1) {
kprintf("connectfail");
return;
return -1;
}
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;
return -1;
}
kprintf("recieving");
/* wait for a message to come back from the server */
if (recv(sd, dir, 256, 0) == -1) {
kprintf("recvfail");
return;
return -1;
}
/* spew-out the results and bail out of here! */
@ -262,25 +238,25 @@ void* client_task(void* e)
close(sd);
return NULL;
return 0;
}
#endif
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);
sem_init(&consuming, 0);
mailbox_int32_init(&mbox);
#if defined(CONFIG_LWIP) && defined(CONFIG_ROCKCREEK)
if (!RCCE_ue())
create_kernel_task(NULL,server_task,NULL);
else
create_kernel_task(NULL,client_task,NULL);
#endif
create_kernel_task(NULL, foo, "Hello from foo1\n");
//create_kernel_task(NULL, join_test, NULL);
//create_kernel_task(NULL, producer, NULL);
@ -290,7 +266,6 @@ int test_init(void)
create_user_task(NULL, "/bin/tests", argv);
//create_user_task(NULL, "/bin/jacobi", argv);
//create_user_task(NULL, "/bin/jacobi", argv);
#endif
return 0;
}