Allow controller to set MAC address to use in ARP responses for SNAT IPs.
[sliver-openvswitch.git] / include / openflow / nicira-ext.h
1 /*
2  * Distributed under the terms of the GNU GPL version 2.
3  * Copyright (c) 2008 Nicira Networks
4  */
5
6 #ifndef OPENFLOW_NICIRA_EXT_H
7 #define OPENFLOW_NICIRA_EXT_H 1
8
9 #include "openflow/openflow.h"
10
11 #define NICIRA_OUI_STR "002320"
12
13 /* The following vendor extensions, proposed by Nicira Networks, are not yet
14  * ready for standardization (and may never be), so they are not included in
15  * openflow.h. */
16
17 #define NX_VENDOR_ID 0x00002320
18
19 enum nicira_type {
20     /* Switch status request.  The request body is an ASCII string that
21      * specifies a prefix of the key names to include in the output; if it is
22      * the null string, then all key-value pairs are included. */
23     NXT_STATUS_REQUEST,
24
25     /* Switch status reply.  The reply body is an ASCII string of key-value
26      * pairs in the form "key=value\n". */
27     NXT_STATUS_REPLY,
28
29     /* Configure an action.  Most actions do not require configuration
30      * beyond that supplied in the actual action call. */
31     NXT_ACT_SET_CONFIG,
32
33     /* Get configuration of action. */
34     NXT_ACT_GET_CONFIG,
35
36     /* Remote command execution.  The request body is a sequence of strings
37      * delimited by null bytes.  The first string is a command name.
38      * Subsequent strings are command arguments. */
39     NXT_COMMAND_REQUEST,
40
41     /* Remote command execution reply, sent when the command's execution
42      * completes.  The reply body is struct nx_command_reply. */
43     NXT_COMMAND_REPLY,
44
45     /* Configure whether Flow End messages should be sent. */
46     NXT_FLOW_END_CONFIG,
47
48     /* Sent by switch when a flow ends.  These messages are turned into
49      * ofp_flow_expired and NetFlow messages in user-space. */
50     NXT_FLOW_END
51 };
52
53 struct nicira_header {
54     struct ofp_header header;
55     uint32_t vendor;            /* NX_VENDOR_ID. */
56     uint32_t subtype;           /* One of NXT_* above. */
57 };
58 OFP_ASSERT(sizeof(struct nicira_header) == sizeof(struct ofp_vendor_header) + 4);
59
60
61 enum nx_snat_command {
62     NXSC_ADD,
63     NXSC_DELETE
64 };
65
66 /* Configuration for source-NATing */
67 struct nx_snat_config {
68     uint8_t command;        /* One of NXSC_*. */
69     uint8_t pad[3];
70     uint16_t port;          /* Physical switch port. */
71     uint16_t mac_timeout;   /* Time to cache MAC addresses of SNAT'd hosts
72                                in seconds.  0 uses the default value. */
73
74     /* Range of IP addresses to impersonate.  Set both values to the
75      * same to support a single address.  */
76     uint32_t ip_addr_start; 
77     uint32_t ip_addr_end;
78
79     /* Range of transport ports that should be used as new source port.  A
80      * value of zero, let's the switch choose.*/
81     uint16_t tcp_start;
82     uint16_t tcp_end;
83     uint16_t udp_start;
84     uint16_t udp_end;
85
86     /* MAC address to use for ARP requests for a SNAT IP address that 
87      * comes in on a different interface than 'port'.  A value of all 
88      * zeros silently drops those ARP requests.  Requests that arrive 
89      * on 'port' get a response with the mac address of the datapath 
90      * device. */
91     uint8_t mac_addr[OFP_ETH_ALEN];
92     uint8_t pad2[2];
93 };
94 OFP_ASSERT(sizeof(struct nx_snat_config) == 32);
95
96 /* Action configuration.  Not all actions require separate configuration. */
97 struct nx_act_config {
98     struct nicira_header header;
99     uint16_t type;          /* One of OFPAT_* */
100     uint8_t pad[2];
101     union {
102         struct nx_snat_config snat[0];
103     };                      /* Array of action configurations.  The number 
104                                is inferred from the length field in the 
105                                header. */
106 };
107 OFP_ASSERT(sizeof(struct nx_act_config) == 20);
108
109
110 enum nx_action_subtype {
111     NXAST_SNAT                      /* Source-NAT */
112 };
113
114 /* Action structure for NXAST_SNAT. */
115 struct nx_action_snat {
116     uint16_t type;                  /* OFPAT_VENDOR. */
117     uint16_t len;                   /* Length is 8. */
118     uint32_t vendor;                /* NX_VENDOR_ID. */
119     uint16_t subtype;               /* NXAST_SNAT. */
120     uint16_t port;                  /* Output port--it must be previously 
121                                        configured. */
122     uint8_t pad[4];
123 };
124 OFP_ASSERT(sizeof(struct nx_action_snat) == 16);
125
126 /* Header for Nicira-defined actions. */
127 struct nx_action_header {
128     uint16_t type;                  /* OFPAT_VENDOR. */
129     uint16_t len;                   /* Length is 8. */
130     uint32_t vendor;                /* NX_VENDOR_ID. */
131     uint16_t subtype;               /* NXAST_*. */
132     uint8_t pad[6];
133 };
134 OFP_ASSERT(sizeof(struct nx_action_header) == 16);
135
136 /* Status bits for NXT_COMMAND_REPLY. */
137 enum {
138     NXT_STATUS_EXITED = 1 << 31,   /* Exited normally. */
139     NXT_STATUS_SIGNALED = 1 << 30, /* Exited due to signal. */
140     NXT_STATUS_UNKNOWN = 1 << 29,  /* Exited for unknown reason. */
141     NXT_STATUS_COREDUMP = 1 << 28, /* Exited with core dump. */
142     NXT_STATUS_ERROR = 1 << 27,    /* Command could not be executed. */
143     NXT_STATUS_STARTED = 1 << 26,  /* Command was started. */
144     NXT_STATUS_EXITSTATUS = 0xff,  /* Exit code mask if NXT_STATUS_EXITED. */
145     NXT_STATUS_TERMSIG = 0xff,     /* Signal number if NXT_STATUS_SIGNALED. */
146 };
147
148 /* NXT_COMMAND_REPLY. */
149 struct nx_command_reply {
150     struct nicira_header nxh;
151     uint32_t status;            /* Status bits defined above. */
152     /* Followed by any number of bytes of process output. */
153 };
154 OFP_ASSERT(sizeof(struct nx_command_reply) == 20);
155
156 enum nx_flow_end_reason {
157     NXFER_IDLE_TIMEOUT,         /* Flow idle time exceeded idle_timeout. */
158     NXFER_HARD_TIMEOUT,         /* Time exceeded hard_timeout. */
159     NXFER_DELETE,               /* Flow was removed by delete command. */
160     NXFER_EJECT                 /* Flow was ejected. */
161 };
162
163 struct nx_flow_end_config {
164     struct nicira_header header;
165     uint8_t enable;           /* Set to 1 to enable Flow End message
166                                  generation.  0 to disable.  */
167     uint8_t pad[3];
168 };
169 OFP_ASSERT(sizeof(struct nx_flow_end_config) == 20);
170
171 struct nx_flow_end {
172     struct nicira_header header;
173     struct ofp_match match;   /* Description of fields. */
174
175     uint16_t priority;        /* Priority level of flow entry. */
176     uint8_t reason;           /* One of NXFER_*. */
177
178     uint8_t tcp_flags;        /* Union of seen TCP flags. */
179     uint8_t ip_tos;           /* IP TOS value. */
180
181     uint8_t pad[7];           /* Align to 64-bits. */
182
183     uint64_t init_time;       /* Time flow started in milliseconds. */
184     uint64_t used_time;       /* Time entry was last used in milliseconds. */
185     uint64_t end_time;        /* Time flow ended in milliseconds. */
186
187     uint64_t packet_count;    
188     uint64_t byte_count;
189 };
190 OFP_ASSERT(sizeof(struct nx_flow_end) == 104);
191
192 #endif /* openflow/nicira-ext.h */