/*
* 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.
*/
#include <config.h>
#include <ctype.h>
#include <errno.h>
#include <inttypes.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netinet/icmp6.h>
#include <stdlib.h>
#include "bitmap.h"
#include "bundle.h"
#include "byte-order.h"
#include "classifier.h"
#include "learn.h"
#include "multipath.h"
#include "netdev.h"
#include "nx-match.h"
#include "id-pool.h"
#include "openflow/netronome-ext.h"
#include "openvswitch/dynamic-string.h"
#include "openvswitch/json.h"
#include "openvswitch/meta-flow.h"
#include "openvswitch/ofp-actions.h"
#include "openvswitch/ofp-errors.h"
#include "openvswitch/ofp-msgs.h"
#include "openvswitch/ofp-print.h"
#include "openvswitch/ofp-prop.h"
#include "openvswitch/ofp-util.h"
#include "openvswitch/ofpbuf.h"
#include "openvswitch/type-props.h"
#include "openvswitch/vlog.h"
#include "openflow/intel-ext.h"
#include "packets.h"
#include "random.h"
#include "tun-metadata.h"
#include "unaligned.h"
#include "util.h"
#include "uuid.h"
VLOG_DEFINE_THIS_MODULE(ofp_util);
/* Rate limit for OpenFlow message parse errors. These always indicate a bug
* in the peer and so there's not much point in showing a lot of them. */
static struct vlog_rate_limit bad_ofmsg_rl = VLOG_RATE_LIMIT_INIT(1, 5);
static enum ofputil_table_vacancy ofputil_decode_table_vacancy(
ovs_be32 config, enum ofp_version);
static enum ofputil_table_eviction ofputil_decode_table_eviction(
ovs_be32 config, enum ofp_version);
static ovs_be32 ofputil_encode_table_config(enum ofputil_table_miss,
enum ofputil_table_eviction,
enum ofputil_table_vacancy,
enum ofp_version);
/* Given the wildcard bit count in the least-significant 6 of 'wcbits', returns
* an IP netmask with a 1 in each bit that must match and a 0 in each bit that
* is wildcarded.
*
* The bits in 'wcbits' are in the format used in enum ofp_flow_wildcards: 0
* is exact match, 1 ignores the LSB, 2 ignores the 2 least-significant bits,
* ..., 32 and higher wildcard the entire field. This is the *opposite* of the
* usual convention where e.g. /24 indicates that 8 bits (not 24 bits) are
* wildcarded. */
ovs_be32
ofputil_wcbits_to_netmask(int wcbits)
{
wcbits &= 0x3f;
return wcbits < 32 ? htonl(~((1u << wcbits) - 1)) : 0;
}
/* Given the IP netmask 'netmask', returns the number of bits of the IP address
* that it wildcards, that is, the number of 0-bits in 'netmask', a number
* between 0 and 32 inclusive.
*
* If 'netmask' is not a CIDR netmask (see ip_is_cidr()), the return value will
* still be in the valid range but isn't otherwise meaningful. */
int
ofputil_netmask_to_wcbits(ovs_be32 netmask)
{
return 32 - ip_count_cidr_bits(netmask);
}
/* Converts the OpenFlow 1.0 wildcards in 'ofpfw' (OFPFW10_*) into a
* flow_wildcards in 'wc' for use in struct match. It is the caller's
* responsibility to handle the special case where the flow match's dl_vlan is
* set to OFP_VLAN_NONE. */
void
ofputil_wildcard_from_ofpfw10(uint32_t ofpfw, struct flow_wildcards *wc)
{
BUILD_ASSERT_DECL(FLOW_WC_SEQ == 40);
/* Initialize most of wc. */
flow_wildcards_init_catchall(wc);
if (!(ofpfw & OFPFW10_IN_PORT)) {
wc->masks.in_port.ofp_port = u16_to_ofp(UINT16_MAX);
}
if (!(ofpfw & OFPFW10_NW_TOS)) {
wc->masks.nw_tos |= IP_DSCP_MASK;
}
if (!(ofpfw & OFPFW10_NW_PROTO)) {
wc->masks.nw_proto = UINT8_MAX;
}
wc->masks.nw_src = ofputil_wcbits_to_netmask(ofpfw
>> OFPFW10_NW_SRC_SHIFT);
wc->masks.nw_dst = ofputil_wcbits_to_netmask(ofpfw
>> OFPFW10_NW_DST_SHIFT);
if (!(ofpfw & OFPFW10_TP_SRC)) {
wc->masks.tp_src = OVS_BE16_MAX;
}
if (!(ofpfw & OFPFW10_TP_DST)) {
wc->masks.tp_dst = OVS_BE16_MAX;
}
if (!(ofpfw & OFPFW10_DL_SRC)) {
WC_MASK_FIELD(wc, dl_src);
}
if (!(ofpfw & OFPFW10_DL_DST)) {
WC_MASK_FIELD(wc, dl_dst);
}
if (!(ofpfw & OFPFW10_DL_TYPE)) {
wc->masks.dl_type = OVS_BE16_MAX;
}
/* VLAN TCI mask. */
if (!(ofpfw & OFPFW10_DL_VLAN_PCP)) {
wc->masks.vlans[0].tci |= htons(VLAN_PCP_MASK | VLAN_CFI);
}
if (!(ofpfw & OFPFW10_DL_VLAN)) {
wc->masks.vlans[0].tci |= htons(VLAN_VID_MASK | VLAN_CFI);
}
}
/* Converts the ofp10_match in 'ofmatch' into a struct match in 'match'. */
void
ofputil_match_from_ofp10_match(const struct ofp10_match *ofmatch,
struct match *match)
{
uint32_t ofpfw = ntohl(ofmatch->wildcards) & OFPFW10_ALL;
/* Initialize match->wc. */
memset(&match->flow, 0, sizeof match->flow);
ofputil_wildcard_from_ofpfw10(ofpfw, &match->wc);
memset(&match->tun_md, 0, sizeof match->tun_md);
/* If any fields, except in_port, are matched, then we also need to match
* on the Ethernet packet_type. */
const uint32_t ofpfw_data_bits = (OFPFW10_NW_TOS | OFPFW10_NW_PROTO
| OFPFW10_TP_SRC | OFPFW10_TP_DST
| OFPFW10_DL_SRC | OFPFW10_DL_DST
| OFPFW10_DL_TYPE
| OFPFW10_DL_VLAN | OFPFW10_DL_VLAN_PCP);
if ((ofpfw & ofpfw_data_bits) != ofpfw_data_bits
|| ofputil_wcbits_to_netmask(ofpfw >> OFPFW10_NW_SRC_SHIFT)
|| ofputil_wcbits_to_netmask(ofpfw >> OFPFW10_NW_DST_SHIFT)) {
match_set_default_packet_type(match);
}
/* Initialize most of match->flow. */
match->flow.nw_src = ofmatch->nw_src;
match->flow.nw_dst = ofmatch->nw_dst;
match->flow.in_port.ofp_port = u16_to_ofp(ntohs(ofmatch->in_port));
match->flow.dl_type = ofputil_dl_type_from_openflow(ofmatch->dl_type);
match->flow.tp_src = ofmatch->tp_src;
match->flow.tp_dst = ofmatch->tp_dst;
match->flow.dl_src = ofmatch->dl_src;
match->flow.dl_dst = ofmatch->dl_dst;
match->flow.nw_tos = ofmatch->nw_tos & IP_DSCP_MASK;
match->flow.nw_proto = ofmatch->nw_proto;
/* Translate VLANs. */
if (!(ofpfw & OFPFW10_DL_VLAN) &&
ofmatch->dl_vlan == htons(OFP10_VLAN_NONE)) {
/* Match only packets without 802.1Q header.
*
* When OFPFW10_DL_VLAN_PCP is wildcarded, this is obviously correct.
*
* If OFPFW10_DL_VLAN_PCP is matched, the flow match is contradictory,
* because we can't have a specific PCP without an 802.1Q header.
* However, older versions of OVS treated this as matching packets
* withut an 802.1Q header, so we do here too. */
match->flow.vlans[0].tci = htons(0);
match->wc.masks.vlans[0].tci = htons(0xffff);
} else {
ovs_be16 vid, pcp, tci;
uint16_t hpcp;
vid = ofmatch->dl_vlan & htons(VLAN_VID_MASK);
hpcp = (ofmatch->dl_vlan_pcp << VLAN_PCP_SHIFT) & VLAN_PCP_MASK;
pcp = htons(hpcp);
tci = vid | pcp | htons(VLAN_CFI);
match->flow.vlans[0].tci = tci & match->wc.masks.vlans[0].tci;
}
/* Clean up. */
match_zero_wildcarded_fields(match);
}
/* Convert 'match' into the OpenFlow 1.0 match structure 'ofmatch'. */
void
ofputil_match_to_ofp10_match(const struct match *match,
struct ofp10
没有合适的资源?快使用搜索试试~ 我知道了~
ovs-2.8.0 源码
共1528个文件
h:449个
c:377个
rst:98个
需积分: 10 22 下载量 97 浏览量
2017-10-20
13:10:17
上传
评论 2
收藏 5.43MB ZIP 举报
温馨提示
ovs-2.8.0 源码,Open vSwitch is a production quality, multilayer virtual switch licensed under the open source Apache 2.0 license.
资源推荐
资源详情
资源评论
收起资源包目录
ovs-2.8.0 源码 (1528个子文件)
ovsdb-idlc.1 2KB
ovs-ctl.8 17KB
ovs-parse-backtrace.8 989B
configure.ac 7KB
Makefile.am 15KB
Makefile.am 2KB
ovn-nb-idl.ann 354B
ovn-sb-idl.ann 354B
vswitch-idl.ann 352B
idltest.ann 351B
vtep-idl.ann 351B
ofproto-dpif.at 480KB
ovn.at 292KB
ofproto.at 245KB
system-traffic.at 171KB
ofp-print.at 145KB
ovs-ofctl.at 137KB
ovsdb-idl.at 61KB
ovsdb-server.at 59KB
system-ovn.at 52KB
bfd.at 48KB
ovs-vsctl.at 47KB
packet-type-aware.at 47KB
ovsdb-execution.at 39KB
ovn-nbctl.at 37KB
nsh.at 37KB
learn.at 37KB
tunnel.at 33KB
ovsdb-data.at 33KB
lacp.at 28KB
ofp-actions.at 28KB
interface-reconfigure.at 27KB
pmd.at 27KB
vtep-ctl.at 26KB
ovsdb-mutation.at 25KB
odp.at 25KB
ovsdb-condition.at 25KB
reconnect.at 22KB
completion.at 22KB
system-userspace-packet-type-aware.at 22KB
stp.at 21KB
ovn-controller-vtep.at 21KB
dpif-netdev.at 19KB
tunnel-push-pop.at 19KB
cfm.at 19KB
ovsdb-monitor.at 19KB
multipath.at 18KB
vlog.at 16KB
ofproto-macros.at 16KB
ovsdb-query.at 16KB
ovsdb-rbac.at 15KB
bundle.at 15KB
json.at 14KB
classifier.at 13KB
ovsdb-tool.at 12KB
tunnel-push-pop-ipv6.at 12KB
ovsdb-row.at 12KB
daemon-py.at 11KB
system-common-macros.at 11KB
mpls-xlate.at 10KB
ofp-errors.at 10KB
ovn-controller.at 8KB
daemon.at 8KB
ovs-vswitchd.at 8KB
ovsdb-log.at 8KB
ovsdb-types.at 8KB
ovs-macros.at 7KB
rstp.at 7KB
mcast-snooping.at 7KB
library.at 7KB
unixctl-py.at 7KB
ovsdb-transaction.at 6KB
ovsdb-trigger.at 6KB
ovsdb.at 5KB
ovn-sbctl.at 5KB
ovsdb-replication.at 5KB
system-layer3-tunnels.at 4KB
ovsdb-schema.at 4KB
aes128.at 4KB
system-userspace-macros.at 4KB
system-kmod-macros.at 4KB
ovsdb-table.at 3KB
ovs-xapi-sync.at 3KB
file_name.at 3KB
ovn-northd.at 3KB
dpctl.at 3KB
ovs-router.at 3KB
testsuite.at 3KB
bridge.at 3KB
system-offloads-traffic.at 3KB
ovsdb-lock.at 2KB
ofp-util.at 2KB
lockfile.at 2KB
jsonrpc-py.at 2KB
check-structs.at 1KB
jsonrpc.at 1KB
uuid.at 1KB
system-userspace-testsuite.at 1005B
system-kmod-testsuite.at 942B
system-offloads-testsuite.at 887B
共 1528 条
- 1
- 2
- 3
- 4
- 5
- 6
- 16
资源评论
bighead_uestc
- 粉丝: 2
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功