Merge "citrix" branch into "master".
[sliver-openvswitch.git] / ofproto / ofproto.h
1 /*
2  * Copyright (c) 2009, 2010 Nicira Networks.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef OFPROTO_H
18 #define OFPROTO_H 1
19
20 #include <stdbool.h>
21 #include <stddef.h>
22 #include <stdint.h>
23 #include "flow.h"
24 #include "netflow.h"
25 #include "tag.h"
26
27 #ifdef  __cplusplus
28 extern "C" {
29 #endif
30
31 struct odp_actions;
32 struct ofhooks;
33 struct ofproto;
34 struct svec;
35
36 enum {
37     DP_GROUP_FLOOD = 0,
38     DP_GROUP_ALL = 1
39 };
40
41 struct ofexpired {
42     flow_t flow;
43     uint64_t packet_count;      /* Packets from subrules. */
44     uint64_t byte_count;        /* Bytes from subrules. */
45     long long int used;         /* Last-used time (0 if never used). */
46 };
47
48 struct ofproto_sflow_options {
49     struct svec targets;
50     uint32_t sampling_rate;
51     uint32_t polling_interval;
52     uint32_t header_len;
53     uint32_t sub_id;
54     char *agent_device;
55     char *control_ip;
56 };
57
58 #define DEFAULT_MFR_DESC "Nicira Networks, Inc."
59 #define DEFAULT_HW_DESC "Open vSwitch"
60 #define DEFAULT_SW_DESC VERSION BUILDNR
61 #define DEFAULT_SERIAL_DESC "None"
62 #define DEFAULT_DP_DESC "None"
63
64 int ofproto_create(const char *datapath, const char *datapath_type,
65                    const struct ofhooks *, void *aux,
66                    struct ofproto **ofprotop);
67 void ofproto_destroy(struct ofproto *);
68 int ofproto_run(struct ofproto *);
69 int ofproto_run1(struct ofproto *);
70 int ofproto_run2(struct ofproto *, bool revalidate_all);
71 void ofproto_wait(struct ofproto *);
72 bool ofproto_is_alive(const struct ofproto *);
73
74 /* Configuration. */
75 void ofproto_set_datapath_id(struct ofproto *, uint64_t datapath_id);
76 void ofproto_set_probe_interval(struct ofproto *, int probe_interval);
77 void ofproto_set_max_backoff(struct ofproto *, int max_backoff);
78 void ofproto_set_desc(struct ofproto *,
79                       const char *mfr_desc, const char *hw_desc,
80                       const char *sw_desc, const char *serial_desc,
81                       const char *dp_desc);
82 int ofproto_set_in_band(struct ofproto *, bool in_band);
83 int ofproto_set_discovery(struct ofproto *, bool discovery,
84                           const char *accept_controller_re,
85                           bool update_resolv_conf);
86 int ofproto_set_controller(struct ofproto *, const char *controller);
87 int ofproto_set_listeners(struct ofproto *, const struct svec *listeners);
88 int ofproto_set_snoops(struct ofproto *, const struct svec *snoops);
89 int ofproto_set_netflow(struct ofproto *,
90                         const struct netflow_options *nf_options);
91 void ofproto_set_sflow(struct ofproto *, const struct ofproto_sflow_options *);
92 void ofproto_set_failure(struct ofproto *, bool fail_open);
93 void ofproto_set_rate_limit(struct ofproto *, int rate_limit, int burst_limit);
94 int ofproto_set_stp(struct ofproto *, bool enable_stp);
95
96 /* Configuration querying. */
97 uint64_t ofproto_get_datapath_id(const struct ofproto *);
98 int ofproto_get_probe_interval(const struct ofproto *);
99 int ofproto_get_max_backoff(const struct ofproto *);
100 bool ofproto_get_in_band(const struct ofproto *);
101 bool ofproto_get_discovery(const struct ofproto *);
102 const char *ofproto_get_controller(const struct ofproto *);
103 void ofproto_get_listeners(const struct ofproto *, struct svec *);
104 void ofproto_get_snoops(const struct ofproto *, struct svec *);
105 void ofproto_get_all_flows(struct ofproto *p, struct ds *);
106
107 /* Functions for use by ofproto implementation modules, not by clients. */
108 int ofproto_send_packet(struct ofproto *, const flow_t *,
109                         const union ofp_action *, size_t n_actions,
110                         const struct ofpbuf *);
111 void ofproto_add_flow(struct ofproto *, const flow_t *, uint32_t wildcards,
112                       unsigned int priority,
113                       const union ofp_action *, size_t n_actions,
114                       int idle_timeout);
115 void ofproto_delete_flow(struct ofproto *, const flow_t *, uint32_t wildcards,
116                          unsigned int priority);
117 void ofproto_flush_flows(struct ofproto *);
118
119 /* Hooks for ovs-vswitchd. */
120 struct ofhooks {
121     void (*port_changed_cb)(enum ofp_port_reason, const struct ofp_phy_port *,
122                             void *aux);
123     bool (*normal_cb)(const flow_t *, const struct ofpbuf *packet,
124                       struct odp_actions *, tag_type *,
125                       uint16_t *nf_output_iface, void *aux);
126     void (*account_flow_cb)(const flow_t *, const union odp_action *,
127                             size_t n_actions, unsigned long long int n_bytes,
128                             void *aux);
129     void (*account_checkpoint_cb)(void *aux);
130 };
131 void ofproto_revalidate(struct ofproto *, tag_type);
132 struct tag_set *ofproto_get_revalidate_set(struct ofproto *);
133
134 #ifdef  __cplusplus
135 }
136 #endif
137
138 #endif /* ofproto.h */