]>
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> | |
7ac27a04 | 4 | * Copyright (c) 2014, 2015 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" |
7ac27a04 | 25 | #include "ofp-msgs.h" |
777af88d | 26 | #include "ofp-util.h" |
1f42be1c JR |
27 | #include "ofproto-provider.h" |
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; | |
7ac27a04 | 36 | enum ofptype type; /* OFPTYPE_FLOW_MOD or OFPTYPE_PORT_MOD. */ |
1c38055d JR |
37 | long long version; /* Version in which the changes take |
38 | * effect. */ | |
7ac27a04 JR |
39 | union { |
40 | struct ofputil_flow_mod fm; /* 'fm.ofpacts' must be malloced. */ | |
41 | struct ofputil_port_mod pm; | |
42 | }; | |
1f42be1c JR |
43 | |
44 | /* Used during commit. */ | |
1c38055d | 45 | struct ofport *port; /* Affected port. */ |
39c94593 | 46 | struct rule_collection old_rules; /* Affected rules. */ |
1c38055d | 47 | struct rule_collection new_rules; /* Replacement rules. */ |
1f42be1c JR |
48 | |
49 | /* OpenFlow header and some of the message contents for error reporting. */ | |
50 | struct ofp_header ofp_msg[DIV_ROUND_UP(64, sizeof(struct ofp_header))]; | |
7ac27a04 | 51 | }; |
777af88d | 52 | |
ff09bc08 JR |
53 | enum bundle_state { |
54 | BS_OPEN, | |
55 | BS_CLOSED | |
56 | }; | |
57 | ||
58 | struct ofp_bundle { | |
59 | struct hmap_node node; /* In struct ofconn's "bundles" hmap. */ | |
60 | uint32_t id; | |
61 | uint16_t flags; | |
62 | enum bundle_state state; | |
63 | ||
64 | /* List of 'struct bundle_message's */ | |
65 | struct ovs_list msg_list; | |
66 | }; | |
67 | ||
7ac27a04 | 68 | static inline struct ofp_bundle_entry *ofp_bundle_entry_alloc( |
1f42be1c | 69 | enum ofptype type, const struct ofp_header *oh); |
7ac27a04 | 70 | static inline void ofp_bundle_entry_free(struct ofp_bundle_entry *); |
777af88d | 71 | |
7ac27a04 JR |
72 | enum ofperr ofp_bundle_open(struct ofconn *, uint32_t id, uint16_t flags); |
73 | enum ofperr ofp_bundle_close(struct ofconn *, uint32_t id, uint16_t flags); | |
7ac27a04 JR |
74 | enum ofperr ofp_bundle_discard(struct ofconn *, uint32_t id); |
75 | enum ofperr ofp_bundle_add_message(struct ofconn *, uint32_t id, | |
76 | uint16_t flags, struct ofp_bundle_entry *); | |
ff09bc08 | 77 | |
1f42be1c | 78 | void ofp_bundle_remove__(struct ofconn *, struct ofp_bundle *, bool success); |
7ac27a04 JR |
79 | \f |
80 | static inline struct ofp_bundle_entry * | |
1f42be1c | 81 | ofp_bundle_entry_alloc(enum ofptype type, const struct ofp_header *oh) |
7ac27a04 JR |
82 | { |
83 | struct ofp_bundle_entry *entry = xmalloc(sizeof *entry); | |
777af88d | 84 | |
7ac27a04 | 85 | entry->type = type; |
1c38055d | 86 | entry->version = 0; |
777af88d | 87 | |
1f42be1c JR |
88 | /* Max 64 bytes for error reporting. */ |
89 | memcpy(entry->ofp_msg, oh, MIN(ntohs(oh->length), sizeof entry->ofp_msg)); | |
90 | ||
7ac27a04 JR |
91 | return entry; |
92 | } | |
777af88d | 93 | |
1f42be1c JR |
94 | static inline void |
95 | ofp_bundle_entry_free(struct ofp_bundle_entry *entry) | |
7ac27a04 JR |
96 | { |
97 | if (entry) { | |
98 | if (entry->type == OFPTYPE_FLOW_MOD) { | |
99 | free(entry->fm.ofpacts); | |
100 | } | |
101 | free(entry); | |
102 | } | |
103 | } | |
777af88d AC |
104 | |
105 | #ifdef __cplusplus | |
106 | } | |
107 | #endif | |
108 | ||
109 | #endif |