ofproto: Split delete_flow*().
[cascardo/ovs.git] / ofproto / bundles.h
1 /*
2  * Copyright (c) 2013, 2014 Alexandru Copot <alex.mihai.c@gmail.com>, with support from IXIA.
3  * Copyright (c) 2013, 2014 Daniel Baluta <dbaluta@ixiacom.com>
4  * Copyright (c) 2014, 2015 Nicira, 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 BUNDLES_H
20 #define BUNDLES_H 1
21
22 #include <sys/types.h>
23
24 #include "connmgr.h"
25 #include "ofp-msgs.h"
26 #include "ofp-util.h"
27
28 #ifdef  __cplusplus
29 extern "C" {
30 #endif
31
32 struct ofp_bundle_entry {
33     struct ovs_list   node;
34     ovs_be32          xid;   /* For error returns. */
35     enum ofptype      type;  /* OFPTYPE_FLOW_MOD or OFPTYPE_PORT_MOD. */
36     union {
37         struct ofputil_flow_mod fm;   /* 'fm.ofpacts' must be malloced. */
38         struct ofputil_port_mod pm;
39     };
40 };
41
42 enum bundle_state {
43     BS_OPEN,
44     BS_CLOSED
45 };
46
47 struct ofp_bundle {
48     struct hmap_node  node;      /* In struct ofconn's "bundles" hmap. */
49     uint32_t          id;
50     uint16_t          flags;
51     enum bundle_state state;
52
53     /* List of 'struct bundle_message's */
54     struct ovs_list   msg_list;
55 };
56
57 static inline struct ofp_bundle_entry *ofp_bundle_entry_alloc(
58     enum ofptype type, ovs_be32 xid);
59 static inline void ofp_bundle_entry_free(struct ofp_bundle_entry *);
60
61 enum ofperr ofp_bundle_open(struct ofconn *, uint32_t id, uint16_t flags);
62 enum ofperr ofp_bundle_close(struct ofconn *, uint32_t id, uint16_t flags);
63 enum ofperr ofp_bundle_commit(struct ofconn *, uint32_t id, uint16_t flags);
64 enum ofperr ofp_bundle_discard(struct ofconn *, uint32_t id);
65 enum ofperr ofp_bundle_add_message(struct ofconn *, uint32_t id,
66                                    uint16_t flags, struct ofp_bundle_entry *);
67
68 void ofp_bundle_remove__(struct ofconn *ofconn, struct ofp_bundle *bundle);
69 \f
70 static inline struct ofp_bundle_entry *
71 ofp_bundle_entry_alloc(enum ofptype type, ovs_be32 xid)
72 {
73     struct ofp_bundle_entry *entry = xmalloc(sizeof *entry);
74
75     entry->xid = xid;
76     entry->type = type;
77
78     return entry;
79 }
80
81 static inline void ofp_bundle_entry_free(struct ofp_bundle_entry *entry)
82 {
83     if (entry) {
84         if (entry->type == OFPTYPE_FLOW_MOD) {
85             free(entry->fm.ofpacts);
86         }
87         free(entry);
88     }
89 }
90
91 #ifdef  __cplusplus
92 }
93 #endif
94
95 #endif