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 Code Cleaned
[palacios.git] / palacios / include / devices / 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  *                Jack Lange <jarusl@cs.northwestern.edu> 
20  *                Peter Dinda <pdinda@northwestern.edu
21  *
22  * This is free software.  You are permitted to use,
23  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
24  */
25
26 #ifndef __VNET_H__
27 #define __VNET_H__
28
29 #include <palacios/vmm.h>
30 #include <palacios/vmm_string.h>
31 #include <palacios/vmm_types.h>
32 #include <palacios/vmm_queue.h>
33 #include <palacios/vmm_socket.h>
34 #include <palacios/vmm_hashtable.h>
35
36
37 #define ETHERNET_HEADER_LEN 14
38 #define ETHERNET_DATA_MIN   46
39 #define ETHERNET_DATA_MAX   1500
40 #define ETHERNET_PACKET_LEN (ETHERNET_HEADER_LEN+ETHERNET_DATA_MAX)
41
42 struct ethAddr{
43   char addr[6];
44 };
45
46 #define SOCK int
47
48 #define TCP_TYPE 0
49 #define UDP_TYPE 1
50
51 #define TCP_STR "TCP"
52 #define UDP_STR "UDP"
53
54 /*   
55 #define HANDLER_ERROR -1
56 #define HANDLER_SUCCESS 0
57 */
58
59 #define ANY "any"
60 #define NOT "not"
61 #define NONE "none"
62 #define EMPTY "empty"
63
64 #define ANY_TYPE 0
65 #define NOT_TYPE 1
66 #define NONE_TYPE 2
67 #define EMPTY_TYPE 3
68
69 #define INTERFACE "INTERFACE"
70 #define EDGE "EDGE"
71 #define ANY_SRC "ANY"
72
73 #define INTERFACE_TYPE 0
74 #define EDGE_TYPE 1
75 #define ANY_SRC_TYPE 2
76
77 //the routing entry
78 struct routing {
79   char src_mac[6];
80   char dest_mac[6];
81
82   int src_mac_qual;
83   int dest_mac_qual;
84
85   int dest;
86   int type; //EDGE_TYPE|INTERFACE_TYPE
87  
88   int src;
89   int src_type;
90
91   int use;
92
93   int next;
94   int prev;
95 };
96
97  //This is the structure that stores the topology 
98 struct topology {
99   SOCK link_sock;
100
101   unsigned long dest;
102
103   // Port for UDP
104   unsigned short remote_port;
105
106   // LINK OR GATEWAY
107   // int link_class;
108
109   int use;
110   int type; //TCP=0, UDP=1,VTP=2, can be extended so on
111
112   int next;
113   int prev;
114 };
115
116 struct sock_list {
117   SOCK sock;
118
119   int next;
120   int prev;
121 };
122
123
124 #define GENERAL_NIC 0
125
126 struct vnet_if_device{
127         char name[50];
128         struct ethAddr device_addr;
129
130         int (*input)(uchar_t * pkt, uint_t size);
131
132         void *data;
133 };
134
135
136 struct device_list {
137   struct vnet_if_device *device;
138
139   int use;
140   int type;
141
142   int next;
143   int prev;
144 };
145
146 // 14 (ethernet frame) + 20 bytes
147 struct HEADERS {
148   char ethernetdest[6];
149   char ethernetsrc[6];
150   unsigned char ethernettype[2]; // indicates layer 3 protocol type
151   char ip[20];
152 };
153
154 #define FOREACH(iter, list, start) for (iter = start; iter != -1; iter = list[iter].next)
155 #define FOREACH_SOCK(iter, socks, start) FOREACH(iter, socks, start)
156 #define FOREACH_LINK(iter, links, start) FOREACH(iter, links, start)
157 #define FOREACH_ROUTE(iter, routes, start) FOREACH(iter, routes, start)
158 #define FOREACH_DEVICE(iter, devices, start) FOREACH(iter, devices, start)
159
160
161 int V3_Send_pkt(uchar_t *buf, int length);
162 int V3_Register_pkt_event(int (*netif_input)(uchar_t * pkt, uint_t size));
163
164
165 int vnet_send_pkt(char *buf, int length);
166 int vnet_register_pkt_event(char *dev_name, int (*netif_input)(uchar_t * pkt, uint_t size), void *data);
167
168 int vnet_pkt_process();
169
170 void vnet_init();
171
172 #endif
173
174