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.


254fbf55c0329d2bf053eceb11b39d0cd554a86a
[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) 2010, Lei Xia <lxia@northwestern.edu> 
11  * Copyright (c) 2009, Yuan Tang <ytang@northwestern.edu> 
12  * Copyright (c) 2010, The V3VEE Project <http://www.v3vee.org> 
13  * All rights reserved.
14  *
15  * Author: Lei Xia <lxia@northwestern.edu>
16  *                Yuan Tang <ytang@northwestern.edu>
17  *
18  * This is free software.  You are permitted to use,
19  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
20  */
21
22 #ifndef __VNET_H__
23 #define __VNET_H__
24
25 #ifdef __V3VEE__
26
27 #include <palacios/vmm.h>
28
29
30 #define V3_VNET_POLLING_VECTOR  50
31
32 typedef enum {MAC_ANY=0, MAC_NOT, MAC_NONE, MAC_ADDR} mac_type_t; //for 'src_mac_qual' and 'dst_mac_qual'
33 typedef enum {LINK_INTERFACE=0, LINK_EDGE, LINK_ANY} link_type_t; //for 'type' and 'src_type' in struct routing
34
35
36 #define VNET_HASH_SIZE 17
37 #define ETHERNET_HEADER_LEN 14
38 #define ETHERNET_MTU   1500
39 #define ETHERNET_PACKET_LEN (ETHERNET_HEADER_LEN + ETHERNET_MTU)
40
41 //routing table entry
42 struct v3_vnet_route {
43     uint8_t src_mac[6];
44     uint8_t dst_mac[6];
45
46     uint8_t src_mac_qual;
47     uint8_t dst_mac_qual;
48
49     uint32_t dst_id; //link[dest] is the link to be used to send pkt
50     uint8_t dst_type; //EDGE|INTERFACE|ANY
51  
52     uint32_t src_id;
53     uint8_t src_type; //EDGE|INTERFACE|ANY
54 } __attribute__((packed));
55
56
57 struct v3_vnet_pkt {
58     uint32_t size; 
59     
60     uint8_t dst_type;
61     uint32_t dst_id;
62
63     /*
64      * IMPORTANT The next three fields must be grouped and packed together
65      *  They are used to generate a hash value 
66      */
67     union {
68         uint8_t hash_buf[VNET_HASH_SIZE];
69         struct {
70             uint8_t src_type;
71             uint32_t src_id;
72             uint8_t header[ETHERNET_HEADER_LEN];
73             uint8_t *data;
74         } __attribute__((packed));
75     } __attribute__((packed));
76 } __attribute__((packed));
77
78
79 #ifdef CONFIG_VNET_PROFILE
80 struct v3_vnet_profile{
81     uint64_t  time_copy_from_guest;
82     uint64_t  time_route_lookup;
83     uint64_t  time_mallocfree;
84     uint64_t  time_copy_to_guest;
85     uint64_t  total_handle_time;
86     uint64_t  memcpy_time;
87
88     uint64_t  total_exit_time;
89     bool print;
90
91     uint64_t virtio_handle_start;
92 };
93 #endif
94
95
96 struct v3_vnet_bridge_xcall_args{
97     struct v3_vm_info * vm;
98     struct v3_vnet_pkt *vnet_pkts; 
99     uint16_t pkt_num;
100     void * private_data;
101 };
102
103 struct v3_vnet_dev_xcall_args{
104     struct v3_vm_info * vm;
105     void * private_data;
106 };
107
108 struct v3_vnet_dev_ops {
109     int (*input)(struct v3_vm_info * vm, struct v3_vnet_pkt * pkt, void * dev_data);
110     void (*poll) (struct v3_vm_info *vm, void *dev_data);
111     void (*poll_xcall)(void *arg);
112
113     void (*start_tx)(void * dev_data);
114     void (*stop_tx)(void * dev_data);
115 };
116
117 struct v3_vnet_bridge_ops {
118     int (*input)(struct v3_vm_info * vm, struct v3_vnet_pkt pkt[], uint16_t pkt_num, void * private_data);
119     int (*xcall_input)(void *data);
120     void (*polling_pkt)(struct v3_vm_info * vm,  void *private_data);
121 };
122         
123
124 int v3_vnet_send_pkt(struct v3_vnet_pkt * pkt, void *private_data);
125
126 int v3_vnet_add_route(struct v3_vnet_route route);
127
128 int v3_init_vnet();
129
130 int v3_vnet_add_bridge(struct v3_vm_info * vm,
131                 /*int (*input)(struct v3_vm_info * vm, struct v3_vnet_pkt pkt[], uint16_t pkt_num, void * private_data),
132                 void (*xcall_input)(void *data),
133                 int (*poll_pkt)(struct v3_vm_info * vm, void * private_data),*/
134                 struct v3_vnet_bridge_ops *ops,
135                 void * priv_data);
136
137 int v3_vnet_add_dev(struct v3_vm_info *info, uint8_t mac[6], 
138                     struct v3_vnet_dev_ops *ops,
139                     void * priv_data);
140
141 void v3_vnet_poll(struct v3_vm_info *vm);
142
143 /* enable a vnet device, tell VNET can send pkts to it */
144 int v3_vnet_enable_device(int dev_id);
145
146 /* tell VNET stop sending pkts to it */
147 int v3_vnet_disable_device(int dev_id);
148
149 #endif
150
151 #endif
152
153