Skip to content

Commit

Permalink
ofp-util, ofp-parse: Break up into many separate modules.
Browse files Browse the repository at this point in the history
ofp-util had been far too large and monolithic for a long time.  This
commit breaks it up into units that make some logical sense.  It also
moves the pieces of ofp-parse that were specific to each unit into the
relevant unit.

Most of this commit is just moving code around.

Signed-off-by: Ben Pfaff <[email protected]>
Reviewed-by: Yifeng Sun <[email protected]>
  • Loading branch information
blp committed Feb 13, 2018
1 parent 3129269 commit 0d71302
Show file tree
Hide file tree
Showing 89 changed files with 15,816 additions and 14,805 deletions.
2 changes: 1 addition & 1 deletion Documentation/topics/openflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ The primary approach to compatibility is to abstract most of the details of the
differences from the core code, by adding a protocol layer that translates
between OF1.x and a slightly higher-level abstract representation. The core of
this approach is the many ``struct ofputil_*`` structures in
``include/openvswitch/ofp-util.h``.
``include/openvswitch/ofp-*.h``.

As a consequence of this approach, OVS cannot use OpenFlow protocol definitions
that closely resemble those in the OpenFlow specification, because
Expand Down
15 changes: 15 additions & 0 deletions include/openvswitch/automake.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,29 @@ openvswitchinclude_HEADERS = \
include/openvswitch/netdev.h \
include/openvswitch/match.h \
include/openvswitch/meta-flow.h \
include/openvswitch/namemap.h \
include/openvswitch/ofpbuf.h \
include/openvswitch/ofp-actions.h \
include/openvswitch/ofp-bundle.h \
include/openvswitch/ofp-connection.h \
include/openvswitch/ofp-ed-props.h \
include/openvswitch/ofp-errors.h \
include/openvswitch/ofp-flow.h \
include/openvswitch/ofp-group.h \
include/openvswitch/ofp-ipfix.h \
include/openvswitch/ofp-match.h \
include/openvswitch/ofp-meter.h \
include/openvswitch/ofp-monitor.h \
include/openvswitch/ofp-msgs.h \
include/openvswitch/ofp-packet.h \
include/openvswitch/ofp-parse.h \
include/openvswitch/ofp-port.h \
include/openvswitch/ofp-print.h \
include/openvswitch/ofp-prop.h \
include/openvswitch/ofp-protocol.h \
include/openvswitch/ofp-queue.h \
include/openvswitch/ofp-switch.h \
include/openvswitch/ofp-table.h \
include/openvswitch/ofp-util.h \
include/openvswitch/packets.h \
include/openvswitch/poll-loop.h \
Expand Down
13 changes: 5 additions & 8 deletions include/openvswitch/meta-flow.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <netinet/ip6.h>
#include "openvswitch/flow.h"
#include "openvswitch/ofp-errors.h"
#include "openvswitch/ofp-protocol.h"
#include "openvswitch/packets.h"
#include "openvswitch/util.h"

Expand Down Expand Up @@ -2031,14 +2032,10 @@ struct mf_field {
* the OpenFlow protocol version the field was introduced in.
* Also, some field types are tranparently mapped to each other via the
* struct flow (like vlan and dscp/tos fields), so each variant supports
* all protocols.
*
* These are combinations of OFPUTIL_P_*. (They are not declared as type
* enum ofputil_protocol because that would give meta-flow.h and ofp-util.h
* a circular dependency.) */
uint32_t usable_protocols_exact; /* Matching or setting whole field. */
uint32_t usable_protocols_cidr; /* Matching a CIDR mask in field. */
uint32_t usable_protocols_bitwise; /* Matching arbitrary bits in field. */
* all protocols. */
enum ofputil_protocol usable_protocols_exact; /* Match/set whole field. */
enum ofputil_protocol usable_protocols_cidr; /* Match CIDR mask. */
enum ofputil_protocol usable_protocols_bitwise; /* Match arbitrary bits. */

int flow_be32ofs; /* Field's be32 offset in "struct flow", if prefix tree
* lookup is supported for the field, or -1. */
Expand Down
78 changes: 78 additions & 0 deletions include/openvswitch/namemap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright (c) 2008-2017 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef OPENVSWITCH_NAMEMAP_H
#define OPENVSWITCH_NAMEMAP_H 1

#include "openvswitch/hmap.h"

struct ds;

#ifdef __cplusplus
extern "C" {
#endif

/* Name-number mapping.
*
* This data structure tracks and manages a mapping between names and 32-bit
* unsigned integers, with provision for detecting names that are used more
* than once.
*
* This structure is suitable for tracking mappings between OpenFlow port names
* and numbers. OpenFlow doesn't require either these kinds of names to be
* unique, and in OVS it's possible for two ports to appear to have the same
* name if their names are longer than the maximum length supported by a given
* version of OpenFlow.
*
* OpenFlow does require port numbers to be unique. We check for duplicate
* ports numbers just in case a switch has a bug.
*
* This structure is also suitable for tracking mappings between OpenFlow table
* names and number. OpenFlow doesn't require table names to be unique and
* Open vSwitch doesn't try to make them unique. */
struct namemap_node {
struct hmap_node name_node;
struct hmap_node number_node;

uint32_t number;
char *name;

bool duplicate;
};

struct namemap {
struct hmap by_name;
struct hmap by_number;
};
#define NAMEMAP_INITIALIZER(MAP) \
{ HMAP_INITIALIZER(&(MAP)->by_name), HMAP_INITIALIZER(&(MAP)->by_number) }

void namemap_init(struct namemap *);
struct namemap_node *namemap_find_by_name(const struct namemap *,
const char *);
struct namemap_node *namemap_find_by_number(const struct namemap *, uint32_t);
void namemap_put(struct namemap *, uint32_t, const char *);
void namemap_destroy(struct namemap *);

void namemap_put_name(const char *, struct ds *);

#ifdef __cplusplus
}
#endif

#endif /* namemap.h */


2 changes: 1 addition & 1 deletion include/openvswitch/ofp-actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#include "openflow/openflow.h"
#include "openflow/nicira-ext.h"
#include "openvswitch/meta-flow.h"
#include "openvswitch/ofp-util.h"
#include "openvswitch/ofp-errors.h"
#include "openvswitch/ofp-protocol.h"
#include "openvswitch/types.h"
#include "openvswitch/ofp-ed-props.h"

Expand Down
83 changes: 83 additions & 0 deletions include/openvswitch/ofp-bundle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright (c) 2008-2017 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef OPENVSWITCH_OFP_BUNDLE_H
#define OPENVSWITCH_OFP_BUNDLE_H 1

#include "openflow/openflow.h"
#include "openvswitch/ofp-flow.h"
#include "openvswitch/ofp-group.h"
#include "openvswitch/ofp-packet.h"
#include "openvswitch/ofp-msgs.h"

#ifdef __cplusplus
extern "C" {
#endif

struct ofputil_bundle_ctrl_msg {
uint32_t bundle_id;
uint16_t type;
uint16_t flags;
};

struct ofputil_bundle_add_msg {
uint32_t bundle_id;
uint16_t flags;
const struct ofp_header *msg;
};

enum ofperr ofputil_decode_bundle_ctrl(const struct ofp_header *,
struct ofputil_bundle_ctrl_msg *);

struct ofpbuf *ofputil_encode_bundle_ctrl_request(
enum ofp_version, struct ofputil_bundle_ctrl_msg *);
struct ofpbuf *ofputil_encode_bundle_ctrl_reply(
const struct ofp_header *, struct ofputil_bundle_ctrl_msg *);

struct ofpbuf *ofputil_encode_bundle_add(enum ofp_version,
struct ofputil_bundle_add_msg *);

enum ofperr ofputil_decode_bundle_add(const struct ofp_header *,
struct ofputil_bundle_add_msg *,
enum ofptype *);

/* Bundle message as produced by ofp-parse. */
struct ofputil_bundle_msg {
enum ofptype type;
union {
struct ofputil_flow_mod fm;
struct ofputil_group_mod gm;
struct ofputil_packet_out po;
};
};

void ofputil_encode_bundle_msgs(const struct ofputil_bundle_msg *, size_t n,
struct ovs_list *requests,
enum ofputil_protocol);
void ofputil_free_bundle_msgs(struct ofputil_bundle_msg *, size_t n);

char *parse_ofp_bundle_file(const char *file_name,
const struct ofputil_port_map *,
const struct ofputil_table_map *,
struct ofputil_bundle_msg **, size_t *n_bms,
enum ofputil_protocol *)
OVS_WARN_UNUSED_RESULT;

#ifdef __cplusplus
}
#endif

#endif /* ofp-bundle.h */
89 changes: 89 additions & 0 deletions include/openvswitch/ofp-connection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright (c) 2008-2017 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef OPENVSWITCH_OFP_CONNECTION_H
#define OPENVSWITCH_OFP_CONNECTION_H 1

#include "openflow/openflow.h"
#include "openvswitch/ofp-protocol.h"

#ifdef __cplusplus
extern "C" {
#endif

/* Abstract ofp_role_request and reply. */
struct ofputil_role_request {
enum ofp12_controller_role role;
bool have_generation_id;
uint64_t generation_id;
};

struct ofputil_role_status {
enum ofp12_controller_role role;
enum ofp14_controller_role_reason reason;
uint64_t generation_id;
};

enum ofperr ofputil_decode_role_message(const struct ofp_header *,
struct ofputil_role_request *);
struct ofpbuf *ofputil_encode_role_reply(const struct ofp_header *,
const struct ofputil_role_request *);

struct ofpbuf *ofputil_encode_role_status(const struct ofputil_role_status *,
enum ofputil_protocol);

enum ofperr ofputil_decode_role_status(const struct ofp_header *,
struct ofputil_role_status *);

enum ofputil_async_msg_type {
/* Standard asynchronous messages. */
OAM_PACKET_IN, /* OFPT_PACKET_IN or NXT_PACKET_IN. */
OAM_PORT_STATUS, /* OFPT_PORT_STATUS. */
OAM_FLOW_REMOVED, /* OFPT_FLOW_REMOVED or NXT_FLOW_REMOVED. */
OAM_ROLE_STATUS, /* OFPT_ROLE_STATUS. */
OAM_TABLE_STATUS, /* OFPT_TABLE_STATUS. */
OAM_REQUESTFORWARD, /* OFPT_REQUESTFORWARD. */

/* Extension asynchronous messages (none yet--coming soon!). */
#define OAM_EXTENSIONS 0 /* Bitmap of all extensions. */

OAM_N_TYPES
};
const char *ofputil_async_msg_type_to_string(enum ofputil_async_msg_type);

struct ofputil_async_cfg {
uint32_t master[OAM_N_TYPES];
uint32_t slave[OAM_N_TYPES];
};
#define OFPUTIL_ASYNC_CFG_INIT (struct ofputil_async_cfg) { .master[0] = 0 }

enum ofperr ofputil_decode_set_async_config(const struct ofp_header *,
bool loose,
const struct ofputil_async_cfg *,
struct ofputil_async_cfg *);

struct ofpbuf *ofputil_encode_get_async_reply(
const struct ofp_header *, const struct ofputil_async_cfg *);
struct ofpbuf *ofputil_encode_set_async_config(
const struct ofputil_async_cfg *, uint32_t oams, enum ofp_version);

struct ofputil_async_cfg ofputil_async_cfg_default(enum ofp_version);

#ifdef __cplusplus
}
#endif

#endif /* ofp-connection.h */
Loading

0 comments on commit 0d71302

Please sign in to comment.