Use classifier versioning.
[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 #include "ofproto-provider.h"
28 #include "util.h"
29
30 #ifdef  __cplusplus
31 extern "C" {
32 #endif
33
34 struct ofp_bundle_entry {
35     struct ovs_list   node;
36     enum ofptype      type;  /* OFPTYPE_FLOW_MOD or OFPTYPE_PORT_MOD. */
37     union {
38         struct ofputil_flow_mod fm;   /* 'fm.ofpacts' must be malloced. */
39         struct ofputil_port_mod pm;
40     };
41
42     /* Used during commit. */
43     struct rule_collection old_rules;   /* Affected rules. */
44     struct rule_collection new_rules;   /* Affected rules. */
45
46     /* OpenFlow header and some of the message contents for error reporting. */
47     struct ofp_header ofp_msg[DIV_ROUND_UP(64, sizeof(struct ofp_header))];
48 };
49
50 enum bundle_state {
51     BS_OPEN,
52     BS_CLOSED
53 };
54
55 struct ofp_bundle {
56     struct hmap_node  node;      /* In struct ofconn's "bundles" hmap. */
57     uint32_t          id;
58     uint16_t          flags;
59     enum bundle_state state;
60
61     /* List of 'struct bundle_message's */
62     struct ovs_list   msg_list;
63 };
64
65 static inline struct ofp_bundle_entry *ofp_bundle_entry_alloc(
66     enum ofptype type, const struct ofp_header *oh);
67 static inline void ofp_bundle_entry_free(struct ofp_bundle_entry *);
68
69 enum ofperr ofp_bundle_open(struct ofconn *, uint32_t id, uint16_t flags);
70 enum ofperr ofp_bundle_close(struct ofconn *, uint32_t id, uint16_t flags);
71 enum ofperr ofp_bundle_discard(struct ofconn *, uint32_t id);
72 enum ofperr ofp_bundle_add_message(struct ofconn *, uint32_t id,
73                                    uint16_t flags, struct ofp_bundle_entry *);
74
75 void ofp_bundle_remove__(struct ofconn *, struct ofp_bundle *, bool success);
76 \f
77 static inline struct ofp_bundle_entry *
78 ofp_bundle_entry_alloc(enum ofptype type, const struct ofp_header *oh)
79 {
80     struct ofp_bundle_entry *entry = xmalloc(sizeof *entry);
81
82     entry->type = type;
83
84     /* Max 64 bytes for error reporting. */
85     memcpy(entry->ofp_msg, oh, MIN(ntohs(oh->length), sizeof entry->ofp_msg));
86
87     return entry;
88 }
89
90 static inline void
91 ofp_bundle_entry_free(struct ofp_bundle_entry *entry)
92 {
93     if (entry) {
94         if (entry->type == OFPTYPE_FLOW_MOD) {
95             free(entry->fm.ofpacts);
96         }
97         free(entry);
98     }
99 }
100
101 #ifdef  __cplusplus
102 }
103 #endif
104
105 #endif