Initial implementation of sFlow.
[sliver-openvswitch.git] / ofproto / ofproto.h
1 /*
2  * Copyright (c) 2009 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 struct odp_actions;
28 struct ofhooks;
29 struct ofproto;
30 struct svec;
31
32 enum {
33     DP_GROUP_FLOOD = 0,
34     DP_GROUP_ALL = 1
35 };
36
37 struct ofexpired {
38     flow_t flow;
39     uint64_t packet_count;      /* Packets from subrules. */
40     uint64_t byte_count;        /* Bytes from subrules. */
41     long long int used;         /* Last-used time (0 if never used). */
42 };
43
44 struct ofproto_sflow_options {
45     struct svec targets;
46     uint32_t sampling_rate;
47     uint32_t polling_interval;
48     uint32_t header_len;
49     uint32_t sub_id;
50     char *agent_device;
51     char *control_ip;
52 };
53
54 int ofproto_create(const char *datapath, const struct ofhooks *, void *aux,
55                    struct ofproto **ofprotop);
56 void ofproto_destroy(struct ofproto *);
57 int ofproto_run(struct ofproto *);
58 int ofproto_run1(struct ofproto *);
59 int ofproto_run2(struct ofproto *, bool revalidate_all);
60 void ofproto_wait(struct ofproto *);
61 bool ofproto_is_alive(const struct ofproto *);
62
63 /* Configuration. */
64 void ofproto_set_datapath_id(struct ofproto *, uint64_t datapath_id);
65 void ofproto_set_mgmt_id(struct ofproto *, uint64_t mgmt_id);
66 void ofproto_set_probe_interval(struct ofproto *, int probe_interval);
67 void ofproto_set_max_backoff(struct ofproto *, int max_backoff);
68 void ofproto_set_desc(struct ofproto *,
69                       const char *manufacturer, const char *hardware,
70                       const char *software, const char *serial);
71 int ofproto_set_in_band(struct ofproto *, bool in_band);
72 int ofproto_set_discovery(struct ofproto *, bool discovery,
73                           const char *accept_controller_re,
74                           bool update_resolv_conf);
75 int ofproto_set_controller(struct ofproto *, const char *controller);
76 int ofproto_set_listeners(struct ofproto *, const struct svec *listeners);
77 int ofproto_set_snoops(struct ofproto *, const struct svec *snoops);
78 int ofproto_set_netflow(struct ofproto *,
79                         const struct netflow_options *nf_options);
80 void ofproto_set_sflow(struct ofproto *, const struct ofproto_sflow_options *);
81 void ofproto_set_failure(struct ofproto *, bool fail_open);
82 void ofproto_set_rate_limit(struct ofproto *, int rate_limit, int burst_limit);
83 int ofproto_set_stp(struct ofproto *, bool enable_stp);
84 int ofproto_set_remote_execution(struct ofproto *, const char *command_acl,
85                                  const char *command_dir);
86
87 /* Configuration querying. */
88 uint64_t ofproto_get_datapath_id(const struct ofproto *);
89 uint64_t ofproto_get_mgmt_id(const struct ofproto *);
90 int ofproto_get_probe_interval(const struct ofproto *);
91 int ofproto_get_max_backoff(const struct ofproto *);
92 bool ofproto_get_in_band(const struct ofproto *);
93 bool ofproto_get_discovery(const struct ofproto *);
94 const char *ofproto_get_controller(const struct ofproto *);
95 void ofproto_get_listeners(const struct ofproto *, struct svec *);
96 void ofproto_get_snoops(const struct ofproto *, struct svec *);
97 void ofproto_get_all_flows(struct ofproto *p, struct ds *);
98
99 /* Functions for use by ofproto implementation modules, not by clients. */
100 int ofproto_send_packet(struct ofproto *, const flow_t *,
101                         const union ofp_action *, size_t n_actions,
102                         const struct ofpbuf *);
103 void ofproto_add_flow(struct ofproto *, const flow_t *, uint32_t wildcards,
104                       unsigned int priority,
105                       const union ofp_action *, size_t n_actions,
106                       int idle_timeout);
107 void ofproto_delete_flow(struct ofproto *, const flow_t *, uint32_t wildcards,
108                          unsigned int priority);
109 void ofproto_flush_flows(struct ofproto *);
110
111 /* Hooks for ovs-vswitchd. */
112 struct ofhooks {
113     void (*port_changed_cb)(enum ofp_port_reason, const struct ofp_phy_port *,
114                             void *aux);
115     bool (*normal_cb)(const flow_t *, const struct ofpbuf *packet,
116                       struct odp_actions *, tag_type *,
117                       uint16_t *nf_output_iface, void *aux);
118     void (*account_flow_cb)(const flow_t *, const union odp_action *,
119                             size_t n_actions, unsigned long long int n_bytes,
120                             void *aux);
121     void (*account_checkpoint_cb)(void *aux);
122 };
123 void ofproto_revalidate(struct ofproto *, tag_type);
124 struct tag_set *ofproto_get_revalidate_set(struct ofproto *);
125
126 #endif /* ofproto.h */