]> git.proxmox.com Git - mirror_ovs.git/blame - ofproto/bundles.h
Move lib/ofp-util.h to include/openvswitch directory
[mirror_ovs.git] / ofproto / bundles.h
CommitLineData
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"
f4248336 26#include "openvswitch/ofp-util.h"
1f42be1c
JR
27#include "ofproto-provider.h"
28#include "util.h"
777af88d
AC
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
7ac27a04
JR
34struct ofp_bundle_entry {
35 struct ovs_list node;
7ac27a04
JR
36 enum ofptype type; /* OFPTYPE_FLOW_MOD or OFPTYPE_PORT_MOD. */
37 union {
8be00367
JR
38 struct ofproto_flow_mod ofm; /* ofm.fm.ofpacts must be malloced. */
39 struct ofproto_port_mod opm;
7ac27a04 40 };
1f42be1c 41
1f42be1c
JR
42 /* OpenFlow header and some of the message contents for error reporting. */
43 struct ofp_header ofp_msg[DIV_ROUND_UP(64, sizeof(struct ofp_header))];
7ac27a04 44};
777af88d 45
ff09bc08
JR
46enum bundle_state {
47 BS_OPEN,
48 BS_CLOSED
49};
50
51struct ofp_bundle {
52 struct hmap_node node; /* In struct ofconn's "bundles" hmap. */
53 uint32_t id;
54 uint16_t flags;
55 enum bundle_state state;
56
57 /* List of 'struct bundle_message's */
58 struct ovs_list msg_list;
59};
60
7ac27a04 61static inline struct ofp_bundle_entry *ofp_bundle_entry_alloc(
1f42be1c 62 enum ofptype type, const struct ofp_header *oh);
7ac27a04 63static inline void ofp_bundle_entry_free(struct ofp_bundle_entry *);
777af88d 64
7ac27a04
JR
65enum ofperr ofp_bundle_open(struct ofconn *, uint32_t id, uint16_t flags);
66enum ofperr ofp_bundle_close(struct ofconn *, uint32_t id, uint16_t flags);
7ac27a04
JR
67enum ofperr ofp_bundle_discard(struct ofconn *, uint32_t id);
68enum ofperr ofp_bundle_add_message(struct ofconn *, uint32_t id,
69 uint16_t flags, struct ofp_bundle_entry *);
ff09bc08 70
1f42be1c 71void ofp_bundle_remove__(struct ofconn *, struct ofp_bundle *, bool success);
7ac27a04
JR
72\f
73static inline struct ofp_bundle_entry *
1f42be1c 74ofp_bundle_entry_alloc(enum ofptype type, const struct ofp_header *oh)
7ac27a04
JR
75{
76 struct ofp_bundle_entry *entry = xmalloc(sizeof *entry);
777af88d 77
7ac27a04 78 entry->type = type;
777af88d 79
1f42be1c
JR
80 /* Max 64 bytes for error reporting. */
81 memcpy(entry->ofp_msg, oh, MIN(ntohs(oh->length), sizeof entry->ofp_msg));
82
7ac27a04
JR
83 return entry;
84}
777af88d 85
1f42be1c
JR
86static inline void
87ofp_bundle_entry_free(struct ofp_bundle_entry *entry)
7ac27a04
JR
88{
89 if (entry) {
90 if (entry->type == OFPTYPE_FLOW_MOD) {
8be00367 91 free(entry->ofm.fm.ofpacts);
7ac27a04
JR
92 }
93 free(entry);
94 }
95}
777af88d
AC
96
97#ifdef __cplusplus
98}
99#endif
100
101#endif