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, 2016 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.
23 #include "fail-open.h"
26 #include "ofproto-provider.h"
27 #include "openvswitch/ofp-actions.h"
28 #include "openvswitch/ofp-msgs.h"
29 #include "openvswitch/ofpbuf.h"
30 #include "openvswitch/vconn.h"
31 #include "openvswitch/vlog.h"
33 #include "openvswitch/poll-loop.h"
34 #include "openvswitch/rconn.h"
35 #include "openvswitch/shash.h"
40 VLOG_DEFINE_THIS_MODULE(bundles
);
42 static struct ofp_bundle
*
43 ofp_bundle_create(uint32_t id
, uint16_t flags
, const struct ofp_header
*oh
)
45 struct ofp_bundle
*bundle
;
47 bundle
= xmalloc(sizeof(*bundle
));
49 bundle
->used
= time_msec();
51 bundle
->flags
= flags
;
52 bundle
->state
= BS_OPEN
;
53 bundle
->msg
= xmemdup(oh
, ntohs(oh
->length
));
55 ovs_list_init(&bundle
->msg_list
);
61 ofp_bundle_remove__(struct ofconn
*ofconn
, struct ofp_bundle
*bundle
)
63 struct ofp_bundle_entry
*msg
;
65 LIST_FOR_EACH_POP (msg
, node
, &bundle
->msg_list
) {
66 ofp_bundle_entry_free(msg
);
69 ofconn_remove_bundle(ofconn
, bundle
);
75 ofp_bundle_open(struct ofconn
*ofconn
, uint32_t id
, uint16_t flags
,
76 const struct ofp_header
*oh
)
78 struct ofp_bundle
*bundle
;
80 bundle
= ofconn_get_bundle(ofconn
, id
);
83 VLOG_INFO("Bundle %x already exists.", id
);
84 ofp_bundle_remove__(ofconn
, bundle
);
86 return OFPERR_OFPBFC_BAD_ID
;
89 bundle
= ofp_bundle_create(id
, flags
, oh
);
90 ofconn_insert_bundle(ofconn
, bundle
);
96 ofp_bundle_close(struct ofconn
*ofconn
, uint32_t id
, uint16_t flags
)
98 struct ofp_bundle
*bundle
;
100 bundle
= ofconn_get_bundle(ofconn
, id
);
103 return OFPERR_OFPBFC_BAD_ID
;
106 if (bundle
->state
== BS_CLOSED
) {
107 ofp_bundle_remove__(ofconn
, bundle
);
108 return OFPERR_OFPBFC_BUNDLE_CLOSED
;
111 if (bundle
->flags
!= flags
) {
112 ofp_bundle_remove__(ofconn
, bundle
);
113 return OFPERR_OFPBFC_BAD_FLAGS
;
116 bundle
->used
= time_msec();
117 bundle
->state
= BS_CLOSED
;
122 ofp_bundle_discard(struct ofconn
*ofconn
, uint32_t id
)
124 struct ofp_bundle
*bundle
;
126 bundle
= ofconn_get_bundle(ofconn
, id
);
129 return OFPERR_OFPBFC_BAD_ID
;
132 ofp_bundle_remove__(ofconn
, bundle
);
137 ofp_bundle_add_message(struct ofconn
*ofconn
, uint32_t id
, uint16_t flags
,
138 struct ofp_bundle_entry
*bmsg
,
139 const struct ofp_header
*oh
)
141 struct ofp_bundle
*bundle
;
143 bundle
= ofconn_get_bundle(ofconn
, id
);
146 bundle
= ofp_bundle_create(id
, flags
, oh
);
147 ofconn_insert_bundle(ofconn
, bundle
);
148 } else if (bundle
->state
== BS_CLOSED
) {
149 ofp_bundle_remove__(ofconn
, bundle
);
150 return OFPERR_OFPBFC_BUNDLE_CLOSED
;
151 } else if (flags
!= bundle
->flags
) {
152 ofp_bundle_remove__(ofconn
, bundle
);
153 return OFPERR_OFPBFC_BAD_FLAGS
;
156 bundle
->used
= time_msec();
157 ovs_list_push_back(&bundle
->msg_list
, &bmsg
->node
);