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.


VNET Hypercall interface, implemented as a new stub device
[palacios.git] / palacios / include / vnet / vnet.h
1
2 /* 
3  * This file is part of the Palacios Virtual Machine Monitor developed
4  * by the V3VEE Project with funding from the United States National 
5  * Science Foundation and the Department of Energy.  
6  *
7  * The V3VEE Project is a joint project between Northwestern University
8  * and the University of New Mexico.  You can find out more at 
9  * http://www.v3vee.org
10  *
11  * Copyright (c) 2010, Lei Xia <lxia@northwestern.edu> 
12  * Copyright (c) 2009, Yuan Tang <ytang@northwestern.edu> 
13  * Copyright (c) 2010, The V3VEE Project <http://www.v3vee.org> 
14  * All rights reserved.
15  *
16  * Author: Lei Xia <lxia@northwestern.edu>
17  *                Yuan Tang <ytang@northwestern.edu>
18  *
19  * This is free software.  You are permitted to use,
20  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
21  */
22
23 #ifndef __VNET_H__
24 #define __VNET_H__
25
26 #include <palacios/vmm_ethernet.h>
27 #include <vnet/vnet_base.h>
28 #include <vnet/vnet_host.h>
29 #include <vnet/vnet_vmm.h>
30
31 #define MAC_NOSET       0
32 #define MAC_ANY         11
33 #define MAC_NOT         12
34 #define MAC_NONE        13 
35 #define MAC_ADDR        14
36
37 #define LINK_NOSET      0
38 #define LINK_INTERFACE  11
39 #define LINK_EDGE       12 
40 #define LINK_ANY        13
41
42 #define VNET_HASH_SIZE  17
43
44 #define VNET_MAX_HEADER_LEN 128
45
46 /*
47   A VNET header is the data that needs to be
48   prefaced to an outgoing packet for a specific
49   MAC pair and qualifiers
50 */
51 struct v3_vnet_header {
52     // this header is for data that match
53     uint8_t src_mac[ETH_ALEN];
54     uint8_t dst_mac[ETH_ALEN];
55
56     uint8_t src_mac_qual;
57     uint8_t dst_mac_qual;
58     
59 #define VNET_HEADER_NOMATCH 0 // Could not find a header
60 #define VNET_HEADER_NONE  1   // There is no header, send/receive without change
61 #define VNET_HEADER_RAW   2   // Prepend the following data on a send, remove this much data on a receive
62 #define VNET_HEADER_UDP   3   // Prepend this UDP header and then send this as a UDP packet / dual on receive
63 #define VNET_HEADER_TCP   4   // Prepend this TCP header and then send this as a TCP segment / dual on receive
64 #define VNET_HEADER_VXLAN 5   // Prepend this UDP header + VXLAN ID / dual on receive
65
66     uint32_t header_type;
67
68     uint32_t header_len;
69     uint8_t  header_data[VNET_MAX_HEADER_LEN];
70
71
72 } __attribute__((packed));
73
74
75 struct v3_vnet_route {
76     uint8_t src_mac[ETH_ALEN];
77     uint8_t dst_mac[ETH_ALEN];
78
79     uint8_t src_mac_qual;
80     uint8_t dst_mac_qual;
81
82     int dst_id;
83     uint8_t dst_type;
84  
85     int src_id;
86     uint8_t src_type;
87
88 } __attribute__((packed));
89
90
91 struct v3_vnet_pkt {
92     uint32_t size; 
93     
94     uint8_t dst_type;
95     uint32_t dst_id;
96
97     /*
98      * IMPORTANT The next three fields must be grouped and packed together
99      *  They are used to generate a hash value 
100      */
101     union {
102         uint8_t hash_buf[VNET_HASH_SIZE];
103         struct {
104             uint8_t src_type;
105             uint32_t src_id;
106             uint8_t header[ETHERNET_HEADER_LEN];
107             uint8_t * data;
108         } __attribute__((packed));
109     } __attribute__((packed));
110 } __attribute__((packed));
111
112
113 struct vnet_stat{
114     uint64_t tx_bytes;
115     uint32_t tx_pkts;
116     uint64_t rx_bytes;
117     uint32_t rx_pkts;
118 };
119
120
121 struct v3_vnet_bridge_ops {
122     int (*input)(struct v3_vm_info * vm, 
123                  struct v3_vnet_pkt * pkt,
124                  void * private_data);
125     void (*poll)(struct v3_vm_info * vm,  
126                  void * private_data);
127 };
128
129 #define HOST_LNX_BRIDGE 1
130 #define CTL_VM_BRIDGE   2
131
132 int v3_vnet_add_bridge(struct v3_vm_info * vm,
133                        struct v3_vnet_bridge_ops * ops,
134                        uint8_t type,
135                        void * priv_data);
136
137 void v3_vnet_del_bridge(uint8_t type);
138
139 int v3_vnet_add_route(struct v3_vnet_route route);
140 void v3_vnet_del_route(uint32_t route_idx);
141
142 int v3_vnet_send_pkt(struct v3_vnet_pkt * pkt, void * private_data);
143 int v3_vnet_find_dev(uint8_t  * mac);
144 int v3_vnet_stat(struct vnet_stat * stats);
145
146 #ifdef __V3VEE__
147
148 struct v3_vnet_dev_ops {
149     int (*input)(struct v3_vm_info * vm, 
150                  struct v3_vnet_pkt * pkt, 
151                  void * dev_data);
152
153     /* return >0 means there are more pkts in the queue to be sent */
154     int (*poll)(struct v3_vm_info * vm,
155                 int quote,
156                 void * dev_data);
157 };
158
159 int v3_init_vnet(void); 
160 void v3_deinit_vnet(void);
161
162 int v3_vnet_add_dev(struct v3_vm_info * info, uint8_t * mac, 
163                     struct v3_vnet_dev_ops * ops, int quote, int poll_state,
164                     void * priv_data);
165 int v3_vnet_del_dev(int dev_id);
166
167 int v3_vnet_query_header(uint8_t src_mac[6], 
168                          uint8_t dest_mac[6],
169                          int     recv,
170                          struct v3_vnet_header *header);
171
172
173 #endif
174
175 #endif
176
177