From: Jack Lange Date: Wed, 4 Mar 2009 20:45:25 +0000 (-0600) Subject: adding paravirtualized network device X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=commitdiff_plain;h=a5347db03b69dc64ce283e67b624f63baa0c364e adding paravirtualized network device --- diff --git a/palacios/include/devices/para_net.h b/palacios/include/devices/para_net.h new file mode 100644 index 0000000..8e6c7fb --- /dev/null +++ b/palacios/include/devices/para_net.h @@ -0,0 +1,32 @@ +/* + * This file is part of the Palacios Virtual Machine Monitor developed + * by the V3VEE Project with funding from the United States National + * Science Foundation and the Department of Energy. + * + * The V3VEE Project is a joint project between Northwestern University + * and the University of New Mexico. You can find out more at + * http://www.v3vee.org + * + * Copyright (c) 2008, Jack Lange + * Copyright (c) 2008, The V3VEE Project + * All rights reserved. + * + * Author: Jack Lange + * + * This is free software. You are permitted to use, + * redistribute, and modify it as specified in the file "V3VEE_LICENSE". + */ + +#ifndef __DEVICES_PARA_NET_H__ +#define __DEVICES_PARA_NET_H__ + +#ifdef __V3VEE__ + +#include + +struct vm_device * v3_create_para_net(); + + +#endif // ! __V3VEE__ + +#endif diff --git a/palacios/include/devices/vnet.h b/palacios/include/devices/vnet.h new file mode 100644 index 0000000..2984519 --- /dev/null +++ b/palacios/include/devices/vnet.h @@ -0,0 +1,42 @@ +/* + * This file is part of the Palacios Virtual Machine Monitor developed + * by the V3VEE Project with funding from the United States National + * Science Foundation and the Department of Energy. + * + * The V3VEE Project is a joint project between Northwestern University + * and the University of New Mexico. You can find out more at + * http://www.v3vee.org + * + * Copyright (c) 2008, Jack Lange + * Copyright (c) 2008, The V3VEE Project + * All rights reserved. + * + * Author: Jack Lange + * + * This is free software. You are permitted to use, + * redistribute, and modify it as specified in the file "V3VEE_LICENSE". + */ + + +#ifndef __DEVICES_VNET_H__ +#define __DEVICES_VNET_H__ + +#ifdef __V3VEE__ + +#include + +struct v3_vnet { + int vnet_sock; + void * private_data; +}; + +int v3_init_vnet(struct v3_vnet * vnet, + int (*rx_pkt)(), //Fix this... + uint32_t ip, uint16_t port, + void * private_data); + +int v3_send_vnet_pkt(struct v3_vnet * vnet, uchar_t * pkt, uint_t pkt_len); + +#endif + +#endif diff --git a/palacios/src/devices/para_net.c b/palacios/src/devices/para_net.c new file mode 100644 index 0000000..405b9c6 --- /dev/null +++ b/palacios/src/devices/para_net.c @@ -0,0 +1,127 @@ +/* + * This file is part of the Palacios Virtual Machine Monitor developed + * by the V3VEE Project with funding from the United States National + * Science Foundation and the Department of Energy. + * + * The V3VEE Project is a joint project between Northwestern University + * and the University of New Mexico. You can find out more at + * http://www.v3vee.org + * + * Copyright (c) 2008, Jack Lange + * Copyright (c) 2008, The V3VEE Project + * All rights reserved. + * + * Author: Jack Lange + * + * This is free software. You are permitted to use, + * redistribute, and modify it as specified in the file "V3VEE_LICENSE". + */ + +#include +#include +#include +#include + +#define TX_HYPERCALL 0x300 +#define RX_HYPERCALL 0x301 +#define MACADDR_HYPERCALL 0x302 + + +struct nic_state { + uchar_t mac_addr[6]; +}; + + + +static int tx_call(struct guest_info * info, uint_t call_no, void * priv_data) { + // struct nic_state * nic = (struct nic_state *)priv_data; + addr_t pkt_gpa = info->vm_regs.rbx; + int pkt_len = info->vm_regs.rcx; + uchar_t * pkt = V3_Malloc(pkt_len); + + PrintDebug("Transmitting Packet\n"); + + if (read_guest_pa_memory(info, pkt_gpa, pkt_len, pkt) != -1) { + return -1; + } + + + return -1; +} + + +static int rx_call(struct guest_info * info, uint_t call_no, void * priv_data) { + // struct nic_state * nic = (struct nic_state *)priv_data; + addr_t pkt_gpa = info->vm_regs.rbx; + uint_t pkt_len = 0; + uchar_t * pkt = NULL; + + PrintDebug("Receiving Packet\n"); + return -1; + + if (write_guest_pa_memory(info, pkt_gpa, pkt_len, pkt) != -1) { + return -1; + } + + return -1; +} + + +static int macaddr_call(struct guest_info * info, uint_t call_no, void * priv_data) { + struct nic_state * nic = (struct nic_state *)priv_data; + addr_t mac_gpa = info->vm_regs.rbx; + + + PrintDebug("Returning MAC ADDR\n"); + + if (write_guest_pa_memory(info, mac_gpa, 6, nic->mac_addr) != 6) { + PrintError("Could not write mac address\n"); + return -1; + } + + return 0; +} + +static int net_init(struct vm_device * dev) { + struct nic_state * nic = (struct nic_state *)dev->private_data; + + v3_register_hypercall(dev->vm, TX_HYPERCALL, tx_call, nic); + v3_register_hypercall(dev->vm, RX_HYPERCALL, rx_call, nic); + v3_register_hypercall(dev->vm, MACADDR_HYPERCALL, macaddr_call, nic); + + nic->mac_addr[0] = 0x52; + nic->mac_addr[1] = 0x54; + nic->mac_addr[2] = 0x00; + nic->mac_addr[3] = 0x12; + nic->mac_addr[4] = 0x34; + nic->mac_addr[5] = 0x56; + + return 0; +} + +static int net_deinit(struct vm_device * dev) { + + return 0; +} + + +static struct vm_device_ops dev_ops = { + .init = net_init, + .deinit = net_deinit, + .reset = NULL, + .start = NULL, + .stop = NULL, +}; + + +struct vm_device * v3_create_para_net() { + struct nic_state * state = NULL; + + state = (struct nic_state *)V3_Malloc(sizeof(struct nic_state)); + + PrintDebug("Creating VMNet Device\n"); + + struct vm_device * device = v3_create_device("VMNET", &dev_ops, state); + + return device; +} diff --git a/palacios/src/devices/vnet.c b/palacios/src/devices/vnet.c new file mode 100644 index 0000000..6b71b3f --- /dev/null +++ b/palacios/src/devices/vnet.c @@ -0,0 +1,42 @@ +/* + * This file is part of the Palacios Virtual Machine Monitor developed + * by the V3VEE Project with funding from the United States National + * Science Foundation and the Department of Energy. + * + * The V3VEE Project is a joint project between Northwestern University + * and the University of New Mexico. You can find out more at + * http://www.v3vee.org + * + * Copyright (c) 2008, Jack Lange + * Copyright (c) 2008, The V3VEE Project + * All rights reserved. + * + * Author: Jack Lange + * + * This is free software. You are permitted to use, + * redistribute, and modify it as specified in the file "V3VEE_LICENSE". + */ + +#include +#include + +static int vnet_server(void * arg) { + // select loop +} + +int v3_init_vnet(struct v3_vnet * vnet, + int (*rx_pkt)(), // fix this... + uint32_t ip, uint16_t port, + void * private_data) { + // connect + + // setup listener + V3_CREATE_THREAD(vnet_server, NULL, "VNET Server"); + + return -1; +} + +int v3_send_vnet_pkt(struct v3_vnet * vnet, uchar_t * pkt, uint_t pkt_len) { + + return -1; +}