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.


added network server files
[palacios.git] / misc / network_servers / vtl / vtl_model.h
1 #ifndef __VTL_MODEL_H
2 #define __VTL_MODEL_H
3
4
5 #include "vtl_util.h"
6
7 #define INVALID_PKT 0
8 #define OUTBOUND_PKT 1
9 #define INBOUND_PKT 2
10
11 typedef enum tcp_state { CLOSED,
12                          LISTEN,
13                          SYN_RCVD,
14                          SYN_SENT,
15                          ESTABLISHED,
16                          CLOSE_WAIT,
17                          LAST_ACK,
18                          FIN_WAIT1,
19                          FIN_WAIT2,
20                          CLOSING,
21                          TIME_WAIT } tcp_state_t;
22
23
24 /* State Models */
25 /*#define ETHERNET_MODEL 0
26 #define IP_MODEL 1
27 #define TCP_MODEL 2
28 #define UDP_MODEL 3
29 */
30
31 typedef enum model_type{ETHERNET_MODEL, 
32                         IP_MODEL, 
33                         TCP_MODEL, 
34                         UDP_MODEL } model_type_t;
35
36 typedef struct ethernet_host_state {
37   char addr[6];
38
39 } ethernet_host_state_t;
40
41 typedef struct ethernet_model {
42   ethernet_host_state_t src;
43   ethernet_host_state_t dst;
44   unsigned short type;
45 } ethernet_model_t;
46
47 typedef struct ip_host_state {
48   unsigned short ip_id;
49   unsigned long addr;
50
51   unsigned char ttl;
52
53 } ip_host_state_t;
54
55 typedef struct ip_model {
56   ip_host_state_t src;
57   ip_host_state_t dst;
58
59   char version;
60   unsigned char proto;
61   ethernet_model_t ethernet;
62 } ip_model_t;
63
64 typedef struct tcp_host_state {
65   unsigned short port;
66   unsigned long seq_num;
67   unsigned long last_ack;
68   unsigned short win;
69
70   unsigned long ts;
71   unsigned short mss;
72
73   tcp_state_t state;
74
75 } tcp_host_state_t;
76
77 typedef struct tcp_model {
78   tcp_host_state_t src;
79   tcp_host_state_t dst;
80
81   ip_model_t ip;
82 } tcp_model_t;
83
84 typedef struct udp_host_state {
85   unsigned short port;
86 } udp_host_state_t;
87
88 typedef struct udp_model {
89   udp_host_state_t src;
90   udp_host_state_t dst;
91
92   ip_model_t ip;
93 } udp_model_t;
94
95
96 typedef struct vtl_model {
97   union model_u {
98     ethernet_model_t ethernet_model;
99     ip_model_t ip_model;
100     tcp_model_t tcp_model;
101     udp_model_t udp_model;
102   } model;
103   model_type_t type;
104 } vtl_model_t;
105
106
107
108 udp_model_t * new_udp_model();
109 tcp_model_t * new_tcp_model();
110 ip_model_t * new_ip_model();
111 ethernet_model_t * new_ethernet_model();
112 vtl_model_t * new_vtl_model(model_type_t type);
113
114 int initialize_ip_model(ip_model_t * model, RawEthernetPacket * pkt, int dir = OUTBOUND_PKT);
115 int initialize_tcp_model(tcp_model_t * model, RawEthernetPacket * pkt, int dir = OUTBOUND_PKT);
116 int initialize_udp_model(udp_model_t * model, RawEthernetPacket * pkt, int dir = OUTBOUND_PKT);
117 int initialize_model(vtl_model_t * model, RawEthernetPacket * pkt, int dir = OUTBOUND_PKT);
118
119 int sync_ip_model(ip_model_t * model, RawEthernetPacket * pkt);
120 int sync_tcp_model(tcp_model_t * model, RawEthernetPacket * pkt);
121 int sync_udp_model(udp_model_t * model, RawEthernetPacket * pkt);
122 int sync_model(vtl_model_t * model, RawEthernetPacket * pkt);
123
124 int is_udp_model_pkt(udp_model_t * model, RawEthernetPacket * pkt);
125 int is_tcp_model_pkt(tcp_model_t * model, RawEthernetPacket * pkt);
126 int is_ip_model_pkt(ip_model_t * model, RawEthernetPacket * pkt);
127 int is_ethernet_model_pkt(ethernet_model_t * model, RawEthernetPacket * pkt);
128 int is_model_pkt(vtl_model_t * model, RawEthernetPacket * pkt);
129
130
131
132 int create_empty_ethernet_pkt(ethernet_model_t * model, RawEthernetPacket * pkt, int dir = OUTBOUND_PKT);
133 int create_empty_ip_pkt(ip_model_t * model, RawEthernetPacket * pkt, int dir = OUTBOUND_PKT);
134 int create_empty_tcp_pkt(tcp_model_t * model, RawEthernetPacket * pkt, int dir = OUTBOUND_PKT);
135 int create_empty_udp_pkt(udp_model_t * model, RawEthernetPacket * pkt, int dir = OUTBOUND_PKT);
136 int create_empty_pkt(vtl_model_t * model, RawEthernetPacket * pkt, int dir = OUTBOUND_PKT);
137
138 // User must track tcp state changes
139 //tcp_state_t get_tcp_state(tcp_state_t current_state, RawEthernetPacket * pkt, int dir = OUTBOUND_PKT);
140
141
142 void dbg_dump_eth_model(ethernet_model_t * model);
143 void dbg_dump_ip_model(ip_model_t * model);
144 void dbg_dump_tcp_model(tcp_model_t * model);
145 void dbg_dump_udp_model(udp_model_t * model);
146 void dbg_dump_model(vtl_model_t * model);
147
148
149
150
151
152
153 #endif // ! __VTL_MODEL_H