datapath-windows: Rename hyper-v switch port and nic handlers
[cascardo/ovs.git] / ofproto / bond.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2014 Nicira, Inc.
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 BOND_H
18 #define BOND_H 1
19
20 #include <stdbool.h>
21 #include <stdint.h>
22 #include "ofproto-provider.h"
23 #include "packets.h"
24
25 struct flow;
26 struct netdev;
27 struct ofpbuf;
28 struct ofproto_dpif;
29 enum lacp_status;
30
31 /* How flows are balanced among bond slaves. */
32 enum bond_mode {
33     BM_TCP, /* Transport Layer Load Balance. */
34     BM_SLB, /* Source Load Balance. */
35     BM_AB   /* Active Backup. */
36 };
37
38 bool bond_mode_from_string(enum bond_mode *, const char *);
39 const char *bond_mode_to_string(enum bond_mode);
40
41 /* Configuration for a bond as a whole. */
42 struct bond_settings {
43     char *name;                 /* Bond's name, for log messages. */
44     uint32_t basis;             /* Flow hashing basis. */
45
46     /* Balancing configuration. */
47     enum bond_mode balance;
48     int rebalance_interval;     /* Milliseconds between rebalances.
49                                    Zero to disable rebalancing. */
50
51     /* Link status detection. */
52     int up_delay;               /* ms before enabling an up slave. */
53     int down_delay;             /* ms before disabling a down slave. */
54
55     bool lacp_fallback_ab_cfg;  /* Fallback to active-backup on LACP failure. */
56
57     uint8_t active_slave_mac[6];/* The MAC address of the interface
58                                    that was active during the last
59                                    ovs run. */
60 };
61
62 /* Program startup. */
63 void bond_init(void);
64
65 /* Basics. */
66 struct bond *bond_create(const struct bond_settings *,
67                          struct ofproto_dpif *ofproto);
68 void bond_unref(struct bond *);
69 struct bond *bond_ref(const struct bond *);
70
71 bool bond_reconfigure(struct bond *, const struct bond_settings *);
72 void bond_slave_register(struct bond *, void *slave_, ofp_port_t ofport, struct netdev *);
73 void bond_slave_set_netdev(struct bond *, void *slave_, struct netdev *);
74 void bond_slave_unregister(struct bond *, const void *slave);
75
76 bool bond_run(struct bond *, enum lacp_status);
77 void bond_wait(struct bond *);
78
79 void bond_slave_set_may_enable(struct bond *, void *slave_, bool may_enable);
80
81 /* Special MAC learning support for SLB bonding. */
82 bool bond_should_send_learning_packets(struct bond *);
83 struct ofpbuf *bond_compose_learning_packet(struct bond *,
84                                             const uint8_t eth_src[ETH_ADDR_LEN],
85                                             uint16_t vlan, void **port_aux);
86 bool bond_get_changed_active_slave(const char *name, uint8_t mac[6],
87                                         bool force);
88
89 /* Packet processing. */
90 enum bond_verdict {
91     BV_ACCEPT,                  /* Accept this packet. */
92     BV_DROP,                    /* Drop this packet. */
93     BV_DROP_IF_MOVED            /* Drop if we've learned a different port. */
94 };
95 enum bond_verdict bond_check_admissibility(struct bond *, const void *slave_,
96                                            const uint8_t dst[ETH_ADDR_LEN]);
97 void *bond_choose_output_slave(struct bond *, const struct flow *,
98                                struct flow_wildcards *, uint16_t vlan);
99
100 /* Rebalancing. */
101 void bond_account(struct bond *, const struct flow *, uint16_t vlan,
102                   uint64_t n_bytes);
103 void bond_rebalance(struct bond *);
104
105 /* Recirculation
106  *
107  * Only balance_tcp mode uses recirculation.
108  *
109  * When recirculation is used, each bond port is assigned with a unique
110  * recirc_id. The output action to the bond port will be replaced by
111  * a Hash action, followed by a RECIRC action.
112  *
113  *   ... actions= ... HASH(hash(L4)), RECIRC(recirc_id) ....
114  *
115  * On handling first output packet, 256 post recirculation flows are installed:
116  *
117  *  recirc_id=<bond_recirc_id>, dp_hash=<[0..255]>/0xff, actions: output<slave>
118  *
119  * Bond module pulls stats from those post recirculation rules. If rebalancing
120  * is needed, those rules are updated with new output actions.
121 */
122 void bond_update_post_recirc_rules(struct bond *, const bool force);
123 bool bond_may_recirc(const struct bond *, uint32_t *recirc_id,
124                      uint32_t *hash_bias);
125 #endif /* bond.h */