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.
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:
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include "fail-open.h"
25 #include "ofp-actions.h"
29 #include "ofproto-provider.h"
31 #include "poll-loop.h"
38 #include "openvswitch/vconn.h"
39 #include "openvswitch/vlog.h"
43 VLOG_DEFINE_THIS_MODULE(bundles);
45 static struct ofp_bundle *
46 ofp_bundle_create(uint32_t id, uint16_t flags)
48 struct ofp_bundle *bundle;
50 bundle = xmalloc(sizeof(*bundle));
53 bundle->flags = flags;
54 bundle->state = BS_OPEN;
56 list_init(&bundle->msg_list);
62 ofp_bundle_remove__(struct ofconn *ofconn, struct ofp_bundle *bundle,
65 struct ofp_bundle_entry *msg;
67 LIST_FOR_EACH_POP (msg, node, &bundle->msg_list) {
68 if (success && msg->type == OFPTYPE_FLOW_MOD) {
69 /* Tell connmgr about successful flow mods. */
70 ofconn_report_flow_mod(ofconn, msg->ofm.fm.command);
72 ofp_bundle_entry_free(msg);
75 ofconn_remove_bundle(ofconn, bundle);
80 ofp_bundle_open(struct ofconn *ofconn, uint32_t id, uint16_t flags)
82 struct ofp_bundle *bundle;
85 bundle = ofconn_get_bundle(ofconn, id);
88 VLOG_INFO("Bundle %x already exists.", id);
89 ofp_bundle_remove__(ofconn, bundle, false);
91 return OFPERR_OFPBFC_BAD_ID;
94 bundle = ofp_bundle_create(id, flags);
95 error = ofconn_insert_bundle(ofconn, bundle);
104 ofp_bundle_close(struct ofconn *ofconn, uint32_t id, uint16_t flags)
106 struct ofp_bundle *bundle;
108 bundle = ofconn_get_bundle(ofconn, id);
111 return OFPERR_OFPBFC_BAD_ID;
114 if (bundle->state == BS_CLOSED) {
115 ofp_bundle_remove__(ofconn, bundle, false);
116 return OFPERR_OFPBFC_BUNDLE_CLOSED;
119 if (bundle->flags != flags) {
120 ofp_bundle_remove__(ofconn, bundle, false);
121 return OFPERR_OFPBFC_BAD_FLAGS;
124 bundle->state = BS_CLOSED;
129 ofp_bundle_discard(struct ofconn *ofconn, uint32_t id)
131 struct ofp_bundle *bundle;
133 bundle = ofconn_get_bundle(ofconn, id);
136 return OFPERR_OFPBFC_BAD_ID;
139 ofp_bundle_remove__(ofconn, bundle, false);
145 ofp_bundle_add_message(struct ofconn *ofconn, uint32_t id, uint16_t flags,
146 struct ofp_bundle_entry *bmsg)
148 struct ofp_bundle *bundle;
150 bundle = ofconn_get_bundle(ofconn, id);
155 bundle = ofp_bundle_create(id, flags);
156 error = ofconn_insert_bundle(ofconn, bundle);
161 } else if (bundle->state == BS_CLOSED) {
162 ofp_bundle_remove__(ofconn, bundle, false);
163 return OFPERR_OFPBFC_BUNDLE_CLOSED;
164 } else if (flags != bundle->flags) {
165 ofp_bundle_remove__(ofconn, bundle, false);
166 return OFPERR_OFPBFC_BAD_FLAGS;
169 list_push_back(&bundle->msg_list, &bmsg->node);