lport: Persist lport_index and mcgroup_index structures.
[cascardo/ovs.git] / ovn / controller / lport.h
1 /* Copyright (c) 2015, 2016 Nicira, Inc.
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #ifndef OVN_LPORT_H
17 #define OVN_LPORT_H 1
18
19 #include <stdint.h>
20 #include "hmap.h"
21 #include "uuid.h"
22
23 struct ovsdb_idl;
24 struct sbrec_datapath_binding;
25
26 /* Logical port and multicast group indexes
27  * ========================================
28  *
29  * This data structure holds multiple indexes over logical ports, to allow for
30  * efficient searching for logical ports by name or number.
31  */
32
33 struct lport_index {
34     struct hmap by_name;
35     struct hmap by_key;
36     struct hmap by_uuid;
37 };
38
39 void lport_index_reset(void);
40 void lport_index_init(struct lport_index *);
41 void lport_index_fill(struct lport_index *, struct ovsdb_idl *);
42 void lport_index_remove(struct lport_index *, const struct uuid *);
43 void lport_index_clear(struct lport_index *);
44 void lport_index_destroy(struct lport_index *);
45
46 const struct sbrec_port_binding *lport_lookup_by_name(
47     const struct lport_index *, const char *name);
48 const struct sbrec_port_binding *lport_lookup_by_key(
49     const struct lport_index *, uint32_t dp_key, uint16_t port_key);
50
51 const struct lport *lport_lookup_by_uuid(
52     const struct lport_index *, const struct uuid *uuid);
53
54 \f
55 /* Multicast group index
56  * =====================
57  *
58  * This is separate from the logical port index because of namespace issues:
59  * logical port names are globally unique, but multicast group names are only
60  * unique within the scope of a logical datapath.
61  *
62  * Multicast groups could be indexed by number also, but so far the clients do
63  * not need this index. */
64
65 struct mcgroup_index {
66     struct hmap by_dp_name;
67     struct hmap by_uuid;
68 };
69
70 void mcgroup_index_reset(void);
71 void mcgroup_index_init(struct mcgroup_index *);
72 void mcgroup_index_fill(struct mcgroup_index *, struct ovsdb_idl *);
73 void mcgroup_index_remove(struct mcgroup_index *, const struct uuid *);
74 void mcgroup_index_clear(struct mcgroup_index *);
75 void mcgroup_index_destroy(struct mcgroup_index *);
76
77 const struct sbrec_multicast_group *mcgroup_lookup_by_dp_name(
78     const struct mcgroup_index *,
79     const struct sbrec_datapath_binding *,
80     const char *name);
81
82 const struct mcgroup *mcgroup_lookup_by_uuid(
83     const struct mcgroup_index *, const struct uuid *uuid);
84
85 #endif /* ovn/lport.h */