Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Minor fix on vnet
[palacios.git] / palacios / include / palacios / vmm_vnet.h
1 /* 
2  * This file is part of the Palacios Virtual Machine Monitor developed
3  * by the V3VEE Project with funding from the United States National 
4  * Science Foundation and the Department of Energy.  
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at 
8  * http://www.v3vee.org
9  *
10  * Copyright (c) 2009, Lei Xia <lxia@northwestern.edu> 
11  * Copyright (c) 2009, Yuan Tang <ytang@northwestern.edu> 
12  * Copyright (c) 2009, Jack Lange <jarusl@cs.northwestern.edu> 
13  * Copyright (c) 2009, Peter Dinda <pdinda@northwestern.edu
14  * Copyright (c) 2009, The V3VEE Project <http://www.v3vee.org> 
15  * All rights reserved.
16  *
17  * Author: Lei Xia <lxia@northwestern.edu>
18  *                Yuan Tang <ytang@northwestern.edu>
19  *
20  * This is free software.  You are permitted to use,
21  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
22  */
23
24 #ifndef __VNET_H__
25 #define __VNET_H__
26
27 #include <palacios/vmm.h>
28 #include <palacios/vmm_string.h>
29 #include <palacios/vmm_types.h>
30 #include <palacios/vmm_queue.h>
31 #include <palacios/vmm_hashtable.h>
32 #include <palacios/vmm_sprintf.h>
33
34 #define ETHERNET_HEADER_LEN 14
35 #define ETHERNET_DATA_MIN   46
36 #define ETHERNET_DATA_MAX   1500
37 #define ETHERNET_PACKET_LEN (ETHERNET_HEADER_LEN + ETHERNET_DATA_MAX)
38
39 typedef enum {MAC_ANY, MAC_NOT, MAC_NONE, MAC_EMPTY} mac_type_t; //for 'src_mac_qual' and 'dst_mac_qual'
40 typedef enum {LINK_INTERFACE, LINK_EDGE, LINK_ANY} link_type_t; //for 'type' and 'src_type' in struct routing
41 typedef enum {TCP_TYPE, UDP_TYPE, NONE_TYPE} prot_type_t;
42
43 //routing table entry
44 struct routing_entry{
45     char src_mac[6];
46     char dest_mac[6];
47
48     int src_mac_qual;
49     int dest_mac_qual;
50
51     int link_idx; //link[dest] is the link to be used to send pkt
52     link_type_t link_type; //EDGE|INTERFACE|ANY
53  
54     int src_link_idx;
55     link_type_t src_type; //EDGE|INTERFACE|ANY
56 }__attribute__((packed));
57
58
59 struct eth_header {
60     uchar_t dest[6];
61     uchar_t src[6];
62     uint16_t type; // indicates layer 3 protocol type
63 }__attribute__((packed));
64
65 struct ip_header {
66     uint8_t version: 4;
67     uint8_t hdr_len: 4;
68     uchar_t tos;
69     uint16_t total_len;
70     uint16_t id;
71     uint8_t flags:     3;
72     uint16_t offset: 13;
73     uchar_t ttl;
74     uchar_t proto;
75     uint16_t cksum;
76     uint32_t src_addr;
77     uint32_t dst_addr;
78 }__attribute__((packed));
79
80 struct udp_header {
81     uint16_t src_port;
82     uint16_t dst_port;
83     uint16_t len;
84     uint16_t csum;//set to zero, disable the xsum
85 }__attribute__((packed));
86
87 struct udp_link_header {
88     struct eth_header eth_hdr;
89     struct ip_header ip_hdr;
90     struct udp_header udp_hdr;
91 }__attribute__((packed));
92
93 #define DEVICE_NAME_LEN 20
94 struct vnet_if_device {
95     char name[DEVICE_NAME_LEN];
96     uchar_t mac_addr[6];
97     struct vm_device *dev;
98     
99     int (*input)(uchar_t *data, uint32_t len, void *private_data);
100     
101     void *private_data;
102 }__attribute__((packed));
103
104
105 struct vnet_if_link {
106     prot_type_t pro_type; //protocal type of this link
107     unsigned long dest_ip;
108     uint16_t dest_port;
109
110     struct udp_link_header vnet_header; //header applied to the packet in/out from this link
111
112     int (*input)(uchar_t *data, uint32_t len, void *private_data);
113     
114     void *private_data;
115 }__attribute__((packed));
116
117
118 //link table entry
119 struct link_entry {
120     link_type_t type;
121   
122     union {
123         struct vnet_if_device *dst_dev;
124         struct vnet_if_link *dst_link;
125     } __attribute__((packed));
126
127     int use;
128 }__attribute__((packed));
129
130
131 int v3_vnet_send_rawpkt(uchar_t *buf, int len, void *private_data);
132 int v3_vnet_send_udppkt(uchar_t *buf, int len, void *private_data);
133 //int vnet_register_device(struct vm_device *vdev, 
134 //                       char *dev_name, 
135 //                       uchar_t mac[6], 
136 //                       int (*netif_input)(uchar_t * pkt, uint_t size, void *private_data), 
137 //                       void *data);
138 //int vnet_unregister_device(char *dev_name);
139
140 int v3_vnet_pkt_process(); 
141
142 void v3_vnet_init(struct guest_info *vm);
143
144 #endif
145
146