]>
Commit | Line | Data |
---|---|---|
777af88d AC |
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> | |
25070e04 | 4 | * Copyright (c) 2014, 2015, 2016 Nicira, Inc. |
777af88d AC |
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 | ||
777af88d | 24 | #include "connmgr.h" |
1f42be1c | 25 | #include "ofproto-provider.h" |
d271907f BW |
26 | #include "openvswitch/ofp-msgs.h" |
27 | #include "openvswitch/ofp-util.h" | |
1f42be1c | 28 | #include "util.h" |
777af88d AC |
29 | |
30 | #ifdef __cplusplus | |
31 | extern "C" { | |
32 | #endif | |
33 | ||
7ac27a04 JR |
34 | struct ofp_bundle_entry { |
35 | struct ovs_list node; | |
25070e04 JR |
36 | enum ofptype type; /* OFPTYPE_FLOW_MOD, OFPTYPE_PORT_MOD, or |
37 | * OFPTYPE_GROUP_MOD. */ | |
7ac27a04 | 38 | union { |
5bacd5cd | 39 | struct ofproto_flow_mod ofm; |
8be00367 | 40 | struct ofproto_port_mod opm; |
25070e04 | 41 | struct ofproto_group_mod ogm; |
7ac27a04 | 42 | }; |
1f42be1c | 43 | |
1f42be1c JR |
44 | /* OpenFlow header and some of the message contents for error reporting. */ |
45 | struct ofp_header ofp_msg[DIV_ROUND_UP(64, sizeof(struct ofp_header))]; | |
7ac27a04 | 46 | }; |
777af88d | 47 | |
ff09bc08 JR |
48 | enum bundle_state { |
49 | BS_OPEN, | |
50 | BS_CLOSED | |
51 | }; | |
52 | ||
53 | struct ofp_bundle { | |
54 | struct hmap_node node; /* In struct ofconn's "bundles" hmap. */ | |
55 | uint32_t id; | |
56 | uint16_t flags; | |
57 | enum bundle_state state; | |
58 | ||
59 | /* List of 'struct bundle_message's */ | |
60 | struct ovs_list msg_list; | |
61 | }; | |
62 | ||
7ac27a04 | 63 | static inline struct ofp_bundle_entry *ofp_bundle_entry_alloc( |
1f42be1c | 64 | enum ofptype type, const struct ofp_header *oh); |
7ac27a04 | 65 | static inline void ofp_bundle_entry_free(struct ofp_bundle_entry *); |
777af88d | 66 | |
7ac27a04 JR |
67 | enum ofperr ofp_bundle_open(struct ofconn *, uint32_t id, uint16_t flags); |
68 | enum ofperr ofp_bundle_close(struct ofconn *, uint32_t id, uint16_t flags); | |
7ac27a04 JR |
69 | enum ofperr ofp_bundle_discard(struct ofconn *, uint32_t id); |
70 | enum ofperr ofp_bundle_add_message(struct ofconn *, uint32_t id, | |
71 | uint16_t flags, struct ofp_bundle_entry *); | |
ff09bc08 | 72 | |
1f42be1c | 73 | void ofp_bundle_remove__(struct ofconn *, struct ofp_bundle *, bool success); |
7ac27a04 JR |
74 | \f |
75 | static inline struct ofp_bundle_entry * | |
1f42be1c | 76 | ofp_bundle_entry_alloc(enum ofptype type, const struct ofp_header *oh) |
7ac27a04 JR |
77 | { |
78 | struct ofp_bundle_entry *entry = xmalloc(sizeof *entry); | |
777af88d | 79 | |
7ac27a04 | 80 | entry->type = type; |
777af88d | 81 | |
1f42be1c JR |
82 | /* Max 64 bytes for error reporting. */ |
83 | memcpy(entry->ofp_msg, oh, MIN(ntohs(oh->length), sizeof entry->ofp_msg)); | |
84 | ||
7ac27a04 JR |
85 | return entry; |
86 | } | |
777af88d | 87 | |
1f42be1c JR |
88 | static inline void |
89 | ofp_bundle_entry_free(struct ofp_bundle_entry *entry) | |
7ac27a04 JR |
90 | { |
91 | if (entry) { | |
92 | if (entry->type == OFPTYPE_FLOW_MOD) { | |
5bacd5cd | 93 | ofproto_flow_mod_uninit(&entry->ofm); |
25070e04 JR |
94 | } else if (entry->type == OFPTYPE_GROUP_MOD) { |
95 | ofputil_uninit_group_mod(&entry->ogm.gm); | |
7ac27a04 JR |
96 | } |
97 | free(entry); | |
98 | } | |
99 | } | |
777af88d AC |
100 | |
101 | #ifdef __cplusplus | |
102 | } | |
103 | #endif | |
104 | ||
105 | #endif |