51d668fba5f5be3077ee7b99c78c599fbcf00f89
[cascardo/ovs.git] / lib / ovs-lldp.h
1 /*
2  * Copyright (c) 2015 Nicira, Inc.
3  * Copyright (c) 2014 Wind River Systems, Inc.
4  * Copyright (c) 2015 Avaya, Inc.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 #ifndef OVS_LLDP_H
20 #define OVS_LLDP_H
21
22 #include <stdint.h>
23 #include "dp-packet.h"
24 #include "hmap.h"
25 #include "list.h"
26 #include "lldp/lldpd.h"
27 #include "ovsdb-data.h"
28 #include "ovs-thread.h"
29 #include "packets.h"
30 #include "timer.h"
31
32 /* Transmit every LLDPD_TX_INTERVAL seconds. */
33 #define LLDP_DEFAULT_TRANSMIT_INTERVAL_MS LLDPD_TX_INTERVAL * 1000
34
35 struct flow_wildcards;
36 struct flow;
37 struct netdev;
38 struct smap;
39
40 struct lldp_status {
41     /* TODO should reflect lldp stack detail */
42     char *stackdetail; /* Added because MSVC doesn't like empty structs */
43 };
44
45 /* Structure per LLDP instance (at the moment per port when enabled).
46  */
47 struct lldp {
48     struct hmap_node    hmap_node;        /* Node in all_lldps list. */
49     struct lldpd        *lldpd;
50     char                *name;            /* Name of the port. */
51     struct timer        tx_timer;         /* Send LLDP when expired. */
52     struct hmap         mappings_by_isid; /* "struct" indexed by ISID */
53     struct hmap         mappings_by_aux;  /* "struct" indexed by aux */
54     struct ovs_list     active_mapping_queue;
55     struct ovs_refcount ref_cnt;
56 };
57
58 /* Configuration specific to Auto Attach.
59  */
60 struct aa_settings {
61     char *system_description;
62     char *system_name;
63 };
64
65 /* Configuration of Auto Attach mappings.
66  */
67 struct aa_mapping_settings {
68     uint32_t isid;
69     uint16_t vlan;
70 };
71
72 enum bridge_aa_vlan_oper {
73    BRIDGE_AA_VLAN_OPER_UNDEF,
74    BRIDGE_AA_VLAN_OPER_ADD,
75    BRIDGE_AA_VLAN_OPER_REMOVE
76 };
77
78 /* Bridge Auto Attach operations.  Mostly for adding/removing VLAN on
79  * the trunk port connected to the Auto Attach server.
80  */
81 struct bridge_aa_vlan {
82     struct ovs_list list_node;
83     char *port_name;
84     uint16_t vlan;
85     enum bridge_aa_vlan_oper oper;
86 };
87
88 void lldp_init(void);
89 long long int lldp_wait(struct lldp *lldp);
90 long long int lldp_wake_time(const struct lldp *lldp);
91 void lldp_run(struct lldpd *cfg);
92 bool lldp_should_send_packet(struct lldp *cfg);
93 bool lldp_should_process_flow(const struct flow *flow);
94 bool lldp_configure(struct lldp *lldp);
95 void lldp_process_packet(struct lldp *cfg, const struct dp_packet *);
96 void lldp_put_packet(struct lldp *lldp, struct dp_packet *packet,
97                      uint8_t eth_src[ETH_ADDR_LEN]);
98 void lldpd_assign_cfg_to_protocols(struct lldpd *cfg);
99 struct lldp * lldp_create(const struct netdev *netdev, const uint32_t mtu,
100                           const struct smap *cfg);
101 struct lldp * lldp_ref(const struct lldp *lldp_);
102 void lldp_unref(struct lldp *lldp);
103
104 int aa_get_vlan_queued(struct ovs_list *list);
105 unsigned int aa_get_vlan_queue_size(void);
106 int aa_configure(const struct aa_settings *s);
107 int aa_mapping_register(void *aux, const struct aa_mapping_settings *s);
108 int aa_mapping_unregister(void *aux);
109
110 /* Used by unit tests */
111 struct lldp * lldp_create_dummy(void);
112
113 #endif /* OVS_LLDP_H */