137
151
static void bundle_del_port(struct ofport_dpif *);
138
152
static void bundle_run(struct ofbundle *);
139
153
static void bundle_wait(struct ofbundle *);
154
static void bundle_flush_macs(struct ofbundle *, bool);
155
static void bundle_move(struct ofbundle *, struct ofbundle *);
141
157
static void stp_run(struct ofproto_dpif *ofproto);
142
158
static void stp_wait(struct ofproto_dpif *ofproto);
143
159
static int set_stp_port(struct ofport *,
144
160
const struct ofproto_port_stp_settings *);
162
static void rstp_run(struct ofproto_dpif *ofproto);
163
static void set_rstp_port(struct ofport *,
164
const struct ofproto_port_rstp_settings *);
146
166
struct ofport_dpif {
147
167
struct hmap_node odp_port_node; /* In dpif_backer's "odp_to_ofport_map". */
148
168
struct ofport up;
150
170
odp_port_t odp_port;
151
171
struct ofbundle *bundle; /* Bundle that contains this port, if any. */
152
struct list bundle_node; /* In struct ofbundle's "ports" list. */
172
struct ovs_list bundle_node;/* In struct ofbundle's "ports" list. */
153
173
struct cfm *cfm; /* Connectivity Fault Management, if any. */
154
174
struct bfd *bfd; /* BFD, if any. */
175
struct lldp *lldp; /* lldp, if any. */
155
176
bool may_enable; /* May be enabled in bonds. */
156
177
bool is_tunnel; /* This port is a tunnel. */
157
178
bool is_layer3; /* This is a layer 3 port. */
227
248
enum revalidate_reason {
228
249
REV_RECONFIGURE = 1, /* Switch configuration changed. */
229
250
REV_STP, /* Spanning tree protocol port status change. */
251
REV_RSTP, /* RSTP port status change. */
230
252
REV_BOND, /* Bonding changed. */
231
253
REV_PORT_TOGGLED, /* Port enabled or disabled by CFM, LACP, ...*/
232
254
REV_FLOW_TABLE, /* Flow table changed. */
233
255
REV_MAC_LEARNING, /* Mac learning changed. */
256
REV_MCAST_SNOOPING, /* Multicast snooping changed. */
235
258
COVERAGE_DEFINE(rev_reconfigure);
236
259
COVERAGE_DEFINE(rev_stp);
260
COVERAGE_DEFINE(rev_rstp);
237
261
COVERAGE_DEFINE(rev_bond);
238
262
COVERAGE_DEFINE(rev_port_toggled);
239
263
COVERAGE_DEFINE(rev_flow_table);
240
264
COVERAGE_DEFINE(rev_mac_learning);
242
/* Stores mapping between 'recirc_id' and 'ofproto-dpif'. */
243
struct dpif_backer_recirc_node {
244
struct hmap_node hmap_node;
245
struct ofproto_dpif *ofproto;
265
COVERAGE_DEFINE(rev_mcast_snooping);
249
267
/* All datapaths of a given type share a single dpif backer instance. */
250
268
struct dpif_backer {
603
fat_rwlock_wrlock(&xlate_rwlock);
604
637
xlate_ofproto_set(ofproto, ofproto->up.name,
605
ofproto->backer->dpif, ofproto->miss_rule,
606
ofproto->no_packet_in_rule, ofproto->ml,
607
ofproto->stp, ofproto->mbridge,
608
ofproto->sflow, ofproto->ipfix,
609
ofproto->netflow, ofproto->up.frag_handling,
638
ofproto->backer->dpif, ofproto->ml,
639
ofproto->stp, ofproto->rstp, ofproto->ms,
640
ofproto->mbridge, ofproto->sflow, ofproto->ipfix,
610
642
ofproto->up.forward_bpdu,
611
643
connmgr_has_in_band(ofproto->up.connmgr),
612
ofproto->backer->enable_recirc,
613
ofproto->backer->variable_length_userdata,
614
ofproto->backer->max_mpls_depth);
644
&ofproto->backer->support);
616
646
HMAP_FOR_EACH (bundle, hmap_node, &ofproto->bundles) {
617
647
xlate_bundle_set(ofproto, bundle, bundle->name,
628
658
xlate_ofport_set(ofproto, ofport->bundle, ofport,
629
659
ofport->up.ofp_port, ofport->odp_port,
630
ofport->up.netdev, ofport->cfm,
631
ofport->bfd, ofport->peer, stp_port,
632
ofport->qdscp, ofport->n_qdscp,
633
ofport->up.pp.config, ofport->up.pp.state,
634
ofport->is_tunnel, ofport->may_enable);
660
ofport->up.netdev, ofport->cfm, ofport->bfd,
661
ofport->lldp, ofport->peer, stp_port,
662
ofport->rstp_port, ofport->qdscp,
663
ofport->n_qdscp, ofport->up.pp.config,
664
ofport->up.pp.state, ofport->is_tunnel,
636
fat_rwlock_unlock(&xlate_rwlock);
639
670
udpif_revalidate(backer->udpif);
986
1005
struct flow flow;
987
1006
struct odputil_keybuf keybuf;
988
1007
struct ofpbuf key;
990
bool enable_recirc = false;
992
1010
memset(&flow, 0, sizeof flow);
993
1011
flow.recirc_id = 1;
994
1012
flow.dp_hash = 1;
996
1014
ofpbuf_use_stack(&key, &keybuf, sizeof keybuf);
997
odp_flow_key_from_flow(&key, &flow, NULL, 0);
999
error = dpif_flow_put(backer->dpif, DPIF_FP_CREATE,
1000
ofpbuf_data(&key), ofpbuf_size(&key), NULL, 0, NULL,
1002
if (error && error != EEXIST) {
1003
if (error != EINVAL) {
1004
VLOG_WARN("%s: Reciculation flow probe failed (%s)",
1005
dpif_name(backer->dpif), ovs_strerror(error));
1010
error = dpif_flow_del(backer->dpif, ofpbuf_data(&key), ofpbuf_size(&key),
1013
VLOG_WARN("%s: failed to delete recirculation feature probe flow",
1014
dpif_name(backer->dpif));
1017
enable_recirc = true;
1015
odp_flow_key_from_flow(&key, &flow, NULL, 0, true);
1016
enable_recirc = dpif_probe_feature(backer->dpif, "recirculation", &key,
1020
1019
if (enable_recirc) {
1021
1020
VLOG_INFO("%s: Datapath supports recirculation",
1022
1021
dpif_name(backer->dpif));
1028
1027
return enable_recirc;
1030
/* Tests whether 'dpif' supports unique flow ids. We can skip serializing
1031
* some flow attributes for datapaths that support this feature.
1033
* Returns true if 'dpif' supports UFID for flow operations.
1034
* Returns false if 'dpif' does not support UFID. */
1036
check_ufid(struct dpif_backer *backer)
1039
struct odputil_keybuf keybuf;
1044
memset(&flow, 0, sizeof flow);
1045
flow.dl_type = htons(0x1234);
1047
ofpbuf_use_stack(&key, &keybuf, sizeof keybuf);
1048
odp_flow_key_from_flow(&key, &flow, NULL, 0, true);
1049
dpif_flow_hash(backer->dpif, key.data, key.size, &ufid);
1051
enable_ufid = dpif_probe_feature(backer->dpif, "UFID", &key, &ufid);
1054
VLOG_INFO("%s: Datapath supports unique flow ids",
1055
dpif_name(backer->dpif));
1057
VLOG_INFO("%s: Datapath does not support unique flow ids",
1058
dpif_name(backer->dpif));
1031
1063
/* Tests whether 'backer''s datapath supports variable-length
1032
1064
* OVS_USERSPACE_ATTR_USERDATA in OVS_ACTION_ATTR_USERSPACE actions. We need
1033
1065
* to disable some features on older datapaths that don't support this
1115
1147
for (n = 0; n < FLOW_MAX_MPLS_LABELS; n++) {
1116
1148
struct odputil_keybuf keybuf;
1117
1149
struct ofpbuf key;
1120
1151
memset(&flow, 0, sizeof flow);
1121
1152
flow.dl_type = htons(ETH_TYPE_MPLS);
1122
1153
flow_set_mpls_bos(&flow, n, 1);
1124
1155
ofpbuf_use_stack(&key, &keybuf, sizeof keybuf);
1125
odp_flow_key_from_flow(&key, &flow, NULL, 0);
1127
error = dpif_flow_put(backer->dpif, DPIF_FP_CREATE,
1128
ofpbuf_data(&key), ofpbuf_size(&key), NULL, 0, NULL, 0, NULL);
1129
if (error && error != EEXIST) {
1130
if (error != EINVAL) {
1131
VLOG_WARN("%s: MPLS stack length feature probe failed (%s)",
1132
dpif_name(backer->dpif), ovs_strerror(error));
1156
odp_flow_key_from_flow(&key, &flow, NULL, 0, false);
1157
if (!dpif_probe_feature(backer->dpif, "MPLS", &key, NULL)) {
1137
error = dpif_flow_del(backer->dpif, ofpbuf_data(&key), ofpbuf_size(&key), NULL);
1139
VLOG_WARN("%s: failed to delete MPLS feature probe flow",
1140
dpif_name(backer->dpif));
1144
1162
VLOG_INFO("%s: MPLS label stack length probed as %d",
1167
/* Tests whether 'backer''s datapath supports masked data in
1168
* OVS_ACTION_ATTR_SET actions. We need to disable some features on older
1169
* datapaths that don't support this feature. */
1171
check_masked_set_action(struct dpif_backer *backer)
1173
struct eth_header *eth;
1174
struct ofpbuf actions;
1175
struct dpif_execute execute;
1176
struct dp_packet packet;
1178
struct ovs_key_ethernet key, mask;
1180
/* Compose a set action that will cause an EINVAL error on older
1181
* datapaths that don't support masked set actions.
1182
* Avoid using a full mask, as it could be translated to a non-masked
1183
* set action instead. */
1184
ofpbuf_init(&actions, 64);
1185
memset(&key, 0x53, sizeof key);
1186
memset(&mask, 0x7f, sizeof mask);
1187
commit_masked_set_action(&actions, OVS_KEY_ATTR_ETHERNET, &key, &mask,
1190
/* Compose a dummy ethernet packet. */
1191
dp_packet_init(&packet, ETH_HEADER_LEN);
1192
eth = dp_packet_put_zeros(&packet, ETH_HEADER_LEN);
1193
eth->eth_type = htons(0x1234);
1195
/* Execute the actions. On older datapaths this fails with EINVAL, on
1196
* newer datapaths it succeeds. */
1197
execute.actions = actions.data;
1198
execute.actions_len = actions.size;
1199
execute.packet = &packet;
1200
execute.needs_help = false;
1201
execute.probe = true;
1203
error = dpif_execute(backer->dpif, &execute);
1205
dp_packet_uninit(&packet);
1206
ofpbuf_uninit(&actions);
1209
/* Masked set action is not supported. */
1210
VLOG_INFO("%s: datapath does not support masked set action feature.",
1211
dpif_name(backer->dpif));
1217
check_support(struct dpif_backer *backer)
1219
/* This feature needs to be tested after udpif threads are set. */
1220
backer->support.variable_length_userdata = false;
1222
backer->support.recirc = check_recirc(backer);
1223
backer->support.max_mpls_depth = check_max_mpls_depth(backer);
1224
backer->support.masked_set_action = check_masked_set_action(backer);
1225
backer->support.ufid = check_ufid(backer);
1226
backer->support.tnl_push_pop = dpif_supports_tnl_push_pop(backer->dpif);
1150
1230
construct(struct ofproto *ofproto_)
1324
1390
hmap_remove(&all_ofproto_dpifs, &ofproto->all_ofproto_dpifs_node);
1326
1392
OFPROTO_FOR_EACH_TABLE (table, &ofproto->up) {
1327
struct cls_cursor cursor;
1329
fat_rwlock_rdlock(&table->cls.rwlock);
1330
cls_cursor_init(&cursor, &table->cls, NULL);
1331
fat_rwlock_unlock(&table->cls.rwlock);
1332
CLS_CURSOR_FOR_EACH_SAFE (rule, next_rule, up.cr, &cursor) {
1393
CLS_FOR_EACH (rule, up.cr, &table->cls) {
1333
1394
ofproto_rule_delete(&ofproto->up, &rule->up);
1397
ofproto_group_delete_all(&ofproto->up);
1337
1399
guarded_list_pop_all(&ofproto->pins, &pins);
1338
LIST_FOR_EACH_SAFE (pin, next_pin, list_node, &pins) {
1339
list_remove(&pin->list_node);
1400
LIST_FOR_EACH_POP (pin, list_node, &pins) {
1340
1401
free(CONST_CAST(void *, pin->up.packet));
1343
1404
guarded_list_destroy(&ofproto->pins);
1345
dpif_backer_recirc_clear_ofproto(ofproto->backer, ofproto);
1406
recirc_free_ofproto(ofproto, ofproto->up.name);
1347
1408
mbridge_unref(ofproto->mbridge);
1349
1410
netflow_unref(ofproto->netflow);
1350
1411
dpif_sflow_unref(ofproto->sflow);
1412
dpif_ipfix_unref(ofproto->ipfix);
1351
1413
hmap_destroy(&ofproto->bundles);
1352
1414
mac_learning_unref(ofproto->ml);
1415
mcast_snooping_unref(ofproto->ms);
1354
1417
hmap_destroy(&ofproto->vlandev_map);
1355
1418
hmap_destroy(&ofproto->realdev_vid_map);
1533
get_features(struct ofproto *ofproto_ OVS_UNUSED,
1534
bool *arp_match_ip, enum ofputil_action_bitmap *actions)
1601
query_tables(struct ofproto *ofproto,
1602
struct ofputil_table_features *features,
1603
struct ofputil_table_stats *stats)
1536
*arp_match_ip = true;
1537
*actions = (OFPUTIL_A_OUTPUT |
1538
OFPUTIL_A_SET_VLAN_VID |
1539
OFPUTIL_A_SET_VLAN_PCP |
1540
OFPUTIL_A_STRIP_VLAN |
1541
OFPUTIL_A_SET_DL_SRC |
1542
OFPUTIL_A_SET_DL_DST |
1543
OFPUTIL_A_SET_NW_SRC |
1544
OFPUTIL_A_SET_NW_DST |
1545
OFPUTIL_A_SET_NW_TOS |
1546
OFPUTIL_A_SET_TP_SRC |
1547
OFPUTIL_A_SET_TP_DST |
1605
strcpy(features->name, "classifier");
1610
for (i = 0; i < ofproto->n_tables; i++) {
1611
unsigned long missed, matched;
1613
atomic_read_relaxed(&ofproto->tables[i].n_matched, &matched);
1614
atomic_read_relaxed(&ofproto->tables[i].n_missed, &missed);
1616
stats[i].matched_count = matched;
1617
stats[i].lookup_count = matched + missed;
1552
get_tables(struct ofproto *ofproto_, struct ofp12_table_stats *ots)
1623
set_tables_version(struct ofproto *ofproto_, cls_version_t version)
1554
1625
struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1555
struct dpif_dp_stats s;
1556
uint64_t n_miss, n_no_pkt_in, n_bytes, n_dropped_frags;
1560
strcpy(ots->name, "classifier");
1562
dpif_get_dp_stats(ofproto->backer->dpif, &s);
1563
rule_get_stats(&ofproto->miss_rule->up, &n_miss, &n_bytes, &used);
1564
rule_get_stats(&ofproto->no_packet_in_rule->up, &n_no_pkt_in, &n_bytes,
1566
rule_get_stats(&ofproto->drop_frags_rule->up, &n_dropped_frags, &n_bytes,
1568
n_lookup = s.n_hit + s.n_missed - n_dropped_frags;
1569
ots->lookup_count = htonll(n_lookup);
1570
ots->matched_count = htonll(n_lookup - n_miss - n_no_pkt_in);
1627
atomic_store_relaxed(&ofproto->tables_version, version);
1573
1631
static struct ofport *
1574
1632
port_alloc(void)
1576
struct ofport_dpif *port = xmalloc(sizeof *port);
1634
struct ofport_dpif *port = xzalloc(sizeof *port);
1577
1635
return &port->up;
1715
1797
port_modified(struct ofport *port_)
1717
1799
struct ofport_dpif *port = ofport_dpif_cast(port_);
1800
char namebuf[NETDEV_VPORT_NAME_BUFSIZE];
1801
const char *dp_port_name;
1802
struct netdev *netdev = port->up.netdev;
1719
1804
if (port->bundle && port->bundle->bond) {
1720
bond_slave_set_netdev(port->bundle->bond, port, port->up.netdev);
1805
bond_slave_set_netdev(port->bundle->bond, port, netdev);
1723
1808
if (port->cfm) {
1724
cfm_set_netdev(port->cfm, port->up.netdev);
1809
cfm_set_netdev(port->cfm, netdev);
1727
1812
if (port->bfd) {
1728
bfd_set_netdev(port->bfd, port->up.netdev);
1813
bfd_set_netdev(port->bfd, netdev);
1731
1816
ofproto_dpif_monitor_port_update(port, port->bfd, port->cfm,
1732
port->up.pp.hw_addr);
1734
if (port->is_tunnel && tnl_port_reconfigure(port, port->up.netdev,
1736
ofproto_dpif_cast(port->up.ofproto)->backer->need_revalidate =
1817
port->lldp, port->up.pp.hw_addr);
1819
dp_port_name = netdev_vport_get_dpif_port(netdev, namebuf, sizeof namebuf);
1821
if (port->is_tunnel) {
1822
struct ofproto_dpif *ofproto = ofproto_dpif_cast(port->up.ofproto);
1824
if (tnl_port_reconfigure(port, netdev, port->odp_port,
1825
ovs_native_tunneling_is_on(ofproto),
1827
ofproto->backer->need_revalidate = REV_RECONFIGURE;
1740
1831
ofport_update_peer(port);
1889
1992
ofproto->backer->need_revalidate = REV_RECONFIGURE;
1891
1994
ofproto_dpif_monitor_port_update(ofport, ofport->bfd, ofport->cfm,
1892
ofport->up.pp.hw_addr);
1995
ofport->lldp, ofport->up.pp.hw_addr);
2000
bfd_status_changed(struct ofport *ofport_)
2002
struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
2004
return ofport->bfd ? bfd_check_status_change(ofport->bfd) : true;
1897
get_bfd_status(struct ofport *ofport_, bool force, struct smap *smap)
2008
get_bfd_status(struct ofport *ofport_, struct smap *smap)
1899
2010
struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
1902
2013
if (ofport->bfd) {
1903
if (bfd_check_status_change(ofport->bfd) || force) {
1904
bfd_get_status(ofport->bfd, smap);
1906
ret = NO_STATUS_CHANGE;
2014
bfd_get_status(ofport->bfd, smap);
2023
set_lldp(struct ofport *ofport_,
2024
const struct smap *cfg)
2026
struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
2030
if (!ofport->lldp) {
2031
struct ofproto_dpif *ofproto;
2033
ofproto = ofproto_dpif_cast(ofport->up.ofproto);
2034
ofproto->backer->need_revalidate = REV_RECONFIGURE;
2035
ofport->lldp = lldp_create(ofport->up.netdev, ofport_->mtu, cfg);
2038
if (!lldp_configure(ofport->lldp, cfg)) {
2043
lldp_unref(ofport->lldp);
2044
ofport->lldp = NULL;
2047
ofproto_dpif_monitor_port_update(ofport,
2051
ofport->up.pp.hw_addr);
2056
get_lldp_status(const struct ofport *ofport_,
2057
struct lldp_status *status OVS_UNUSED)
2059
struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
2061
return ofport->lldp ? true : false;
2065
set_aa(struct ofproto *ofproto OVS_UNUSED,
2066
const struct aa_settings *s)
2068
return aa_configure(s);
2072
aa_mapping_set(struct ofproto *ofproto_ OVS_UNUSED, void *aux,
2073
const struct aa_mapping_settings *s)
2075
return aa_mapping_register(aux, s);
2079
aa_mapping_unset(struct ofproto *ofproto OVS_UNUSED, void *aux)
2081
return aa_mapping_unregister(aux);
2085
aa_vlan_get_queued(struct ofproto *ofproto OVS_UNUSED, struct ovs_list *list)
2087
return aa_get_vlan_queued(list);
2091
aa_vlan_get_queue_size(struct ofproto *ofproto OVS_UNUSED)
2093
return aa_get_vlan_queue_size();
1915
2097
/* Spanning Tree. */
1918
send_bpdu_cb(struct ofpbuf *pkt, int port_num, void *ofproto_)
2099
/* Called while rstp_mutex is held. */
2101
rstp_send_bpdu_cb(struct dp_packet *pkt, void *ofport_, void *ofproto_)
2103
struct ofproto_dpif *ofproto = ofproto_;
2104
struct ofport_dpif *ofport = ofport_;
2105
struct eth_header *eth = dp_packet_l2(pkt);
2107
netdev_get_etheraddr(ofport->up.netdev, eth->eth_src);
2108
if (eth_addr_is_zero(eth->eth_src)) {
2109
VLOG_WARN_RL(&rl, "%s port %d: cannot send RSTP BPDU on a port which "
2110
"does not have a configured source MAC address.",
2111
ofproto->up.name, ofp_to_u16(ofport->up.ofp_port));
2113
ofproto_dpif_send_packet(ofport, pkt);
2115
dp_packet_delete(pkt);
2119
send_bpdu_cb(struct dp_packet *pkt, int port_num, void *ofproto_)
1920
2121
struct ofproto_dpif *ofproto = ofproto_;
1921
2122
struct stp_port *sp = stp_get_port(ofproto->stp, port_num);
1936
2137
ofproto_dpif_send_packet(ofport, pkt);
2140
dp_packet_delete(pkt);
2143
/* Configure RSTP on 'ofproto_' using the settings defined in 's'. */
2145
set_rstp(struct ofproto *ofproto_, const struct ofproto_rstp_settings *s)
2147
struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
2149
/* Only revalidate flows if the configuration changed. */
2150
if (!s != !ofproto->rstp) {
2151
ofproto->backer->need_revalidate = REV_RECONFIGURE;
2155
if (!ofproto->rstp) {
2156
ofproto->rstp = rstp_create(ofproto_->name, s->address,
2157
rstp_send_bpdu_cb, ofproto);
2158
ofproto->rstp_last_tick = time_msec();
2160
rstp_set_bridge_address(ofproto->rstp, s->address);
2161
rstp_set_bridge_priority(ofproto->rstp, s->priority);
2162
rstp_set_bridge_ageing_time(ofproto->rstp, s->ageing_time);
2163
rstp_set_bridge_force_protocol_version(ofproto->rstp,
2164
s->force_protocol_version);
2165
rstp_set_bridge_max_age(ofproto->rstp, s->bridge_max_age);
2166
rstp_set_bridge_forward_delay(ofproto->rstp, s->bridge_forward_delay);
2167
rstp_set_bridge_transmit_hold_count(ofproto->rstp,
2168
s->transmit_hold_count);
2170
struct ofport *ofport;
2171
HMAP_FOR_EACH (ofport, hmap_node, &ofproto->up.ports) {
2172
set_rstp_port(ofport, NULL);
2174
rstp_unref(ofproto->rstp);
2175
ofproto->rstp = NULL;
2180
get_rstp_status(struct ofproto *ofproto_, struct ofproto_rstp_status *s)
2182
struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
2184
if (ofproto->rstp) {
2186
s->root_id = rstp_get_root_id(ofproto->rstp);
2187
s->bridge_id = rstp_get_bridge_id(ofproto->rstp);
2188
s->designated_id = rstp_get_designated_id(ofproto->rstp);
2189
s->root_path_cost = rstp_get_root_path_cost(ofproto->rstp);
2190
s->designated_port_id = rstp_get_designated_port_id(ofproto->rstp);
2191
s->bridge_port_id = rstp_get_bridge_port_id(ofproto->rstp);
2198
update_rstp_port_state(struct ofport_dpif *ofport)
2200
struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto);
2201
enum rstp_state state;
2203
/* Figure out new state. */
2204
state = ofport->rstp_port ? rstp_port_get_state(ofport->rstp_port)
2208
if (ofport->rstp_state != state) {
2209
enum ofputil_port_state of_state;
2212
VLOG_DBG("port %s: RSTP state changed from %s to %s",
2213
netdev_get_name(ofport->up.netdev),
2214
rstp_state_name(ofport->rstp_state),
2215
rstp_state_name(state));
2217
if (rstp_learn_in_state(ofport->rstp_state)
2218
!= rstp_learn_in_state(state)) {
2219
/* XXX: Learning action flows should also be flushed. */
2220
if (ofport->bundle) {
2221
if (!rstp_shift_root_learned_address(ofproto->rstp)
2222
|| rstp_get_old_root_aux(ofproto->rstp) != ofport) {
2223
bundle_flush_macs(ofport->bundle, false);
2227
fwd_change = rstp_forward_in_state(ofport->rstp_state)
2228
!= rstp_forward_in_state(state);
2230
ofproto->backer->need_revalidate = REV_RSTP;
2231
ofport->rstp_state = state;
2233
if (fwd_change && ofport->bundle) {
2234
bundle_update(ofport->bundle);
2237
/* Update the RSTP state bits in the OpenFlow port description. */
2238
of_state = ofport->up.pp.state & ~OFPUTIL_PS_STP_MASK;
2239
of_state |= (state == RSTP_LEARNING ? OFPUTIL_PS_STP_LEARN
2240
: state == RSTP_FORWARDING ? OFPUTIL_PS_STP_FORWARD
2241
: state == RSTP_DISCARDING ? OFPUTIL_PS_STP_LISTEN
2243
ofproto_port_set_state(&ofport->up, of_state);
2248
rstp_run(struct ofproto_dpif *ofproto)
2250
if (ofproto->rstp) {
2251
long long int now = time_msec();
2252
long long int elapsed = now - ofproto->rstp_last_tick;
2253
struct rstp_port *rp;
2254
struct ofport_dpif *ofport;
2256
/* Every second, decrease the values of the timers. */
2257
if (elapsed >= 1000) {
2258
rstp_tick_timers(ofproto->rstp);
2259
ofproto->rstp_last_tick = now;
2262
while ((ofport = rstp_get_next_changed_port_aux(ofproto->rstp, &rp))) {
2263
update_rstp_port_state(ofport);
2267
/* FIXME: This check should be done on-event (i.e., when setting
2268
* p->fdb_flush) and not periodically.
2270
while ((ofport = rstp_check_and_reset_fdb_flush(ofproto->rstp, &rp))) {
2271
if (!rstp_shift_root_learned_address(ofproto->rstp)
2272
|| rstp_get_old_root_aux(ofproto->rstp) != ofport) {
2273
bundle_flush_macs(ofport->bundle, false);
2277
if (rstp_shift_root_learned_address(ofproto->rstp)) {
2278
bundle_move(((struct ofport_dpif *)rstp_get_old_root_aux(ofproto->rstp))->bundle,
2279
((struct ofport_dpif *)rstp_get_new_root_aux(ofproto->rstp))->bundle);
2280
rstp_reset_root_changed(ofproto->rstp);
1942
2285
/* Configures STP on 'ofproto_' using the settings defined in 's'. */
2154
2503
poll_timer_wait(1000);
2507
/* Configures RSTP on 'ofport_' using the settings defined in 's'. The
2508
* caller is responsible for assigning RSTP port numbers and ensuring
2509
* there are no duplicates. */
2511
set_rstp_port(struct ofport *ofport_,
2512
const struct ofproto_port_rstp_settings *s)
2514
struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
2515
struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto);
2516
struct rstp_port *rp = ofport->rstp_port;
2518
if (!s || !s->enable) {
2520
rstp_port_unref(rp);
2521
ofport->rstp_port = NULL;
2522
update_rstp_port_state(ofport);
2527
/* Check if need to add a new port. */
2529
rp = ofport->rstp_port = rstp_add_port(ofproto->rstp);
2532
rstp_port_set(rp, s->port_num, s->priority, s->path_cost,
2533
s->admin_edge_port, s->auto_edge,
2534
s->admin_p2p_mac_state, s->admin_port_state, s->mcheck,
2536
update_rstp_port_state(ofport);
2537
/* Synchronize operational status. */
2538
rstp_port_set_mac_operational(rp, ofport->may_enable);
2542
get_rstp_port_status(struct ofport *ofport_,
2543
struct ofproto_port_rstp_status *s)
2545
struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
2546
struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto);
2547
struct rstp_port *rp = ofport->rstp_port;
2549
if (!ofproto->rstp || !rp) {
2555
rstp_port_get_status(rp, &s->port_id, &s->state, &s->role,
2556
&s->designated_bridge_id, &s->designated_port_id,
2557
&s->designated_path_cost, &s->tx_count,
2558
&s->rx_count, &s->error_count, &s->uptime);
2159
2563
set_queues(struct ofport *ofport_, const struct ofproto_port_queue *qdscp,
2564
2989
bundle_send_learning_packets(struct ofbundle *bundle)
2566
2991
struct ofproto_dpif *ofproto = bundle->ofproto;
2567
struct ofpbuf *learning_packet;
2568
2992
int error, n_packets, n_errors;
2569
2993
struct mac_entry *e;
2570
struct list packets;
2995
struct ovs_list list_node;
2996
struct ofport_dpif *port;
2997
struct dp_packet *pkt;
2999
struct ovs_list packets;
2572
3001
list_init(&packets);
2573
3002
ovs_rwlock_rdlock(&ofproto->ml->rwlock);
2574
3003
LIST_FOR_EACH (e, lru_node, &ofproto->ml->lrus) {
2575
3004
if (mac_entry_get_port(ofproto->ml, e) != bundle) {
2578
learning_packet = bond_compose_learning_packet(bundle->bond,
2581
/* Temporarily use 'frame' as a private pointer (see below). */
2582
ovs_assert(learning_packet->frame == ofpbuf_data(learning_packet));
2583
learning_packet->frame = port_void;
2584
list_push_back(&packets, &learning_packet->list_node);
3005
pkt_node = xmalloc(sizeof *pkt_node);
3006
pkt_node->pkt = bond_compose_learning_packet(bundle->bond,
3008
(void **)&pkt_node->port);
3009
list_push_back(&packets, &pkt_node->list_node);
2587
3012
ovs_rwlock_unlock(&ofproto->ml->rwlock);
2589
3014
error = n_packets = n_errors = 0;
2590
LIST_FOR_EACH (learning_packet, list_node, &packets) {
3015
LIST_FOR_EACH_POP (pkt_node, list_node, &packets) {
2592
void *port_void = learning_packet->frame;
2594
/* Restore 'frame'. */
2595
learning_packet->frame = ofpbuf_data(learning_packet);
2596
ret = ofproto_dpif_send_packet(port_void, learning_packet);
3018
ret = ofproto_dpif_send_packet(pkt_node->port, pkt_node->pkt);
3019
dp_packet_delete(pkt_node->pkt);
2603
ofpbuf_list_delete(&packets);
2605
3028
if (n_errors) {
2606
3029
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
2727
3150
mac_learning_set_max_entries(ofproto->ml, max_entries);
2728
3151
ovs_rwlock_unlock(&ofproto->ml->rwlock);
3154
/* Configures multicast snooping on 'ofport' using the settings
3155
* defined in 's'. */
3157
set_mcast_snooping(struct ofproto *ofproto_,
3158
const struct ofproto_mcast_snooping_settings *s)
3160
struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
3162
/* Only revalidate flows if the configuration changed. */
3163
if (!s != !ofproto->ms) {
3164
ofproto->backer->need_revalidate = REV_RECONFIGURE;
3169
ofproto->ms = mcast_snooping_create();
3172
ovs_rwlock_wrlock(&ofproto->ms->rwlock);
3173
mcast_snooping_set_idle_time(ofproto->ms, s->idle_time);
3174
mcast_snooping_set_max_entries(ofproto->ms, s->max_entries);
3175
if (mcast_snooping_set_flood_unreg(ofproto->ms, s->flood_unreg)) {
3176
ofproto->backer->need_revalidate = REV_RECONFIGURE;
3178
ovs_rwlock_unlock(&ofproto->ms->rwlock);
3180
mcast_snooping_unref(ofproto->ms);
3187
/* Configures multicast snooping port's flood settings on 'ofproto'. */
3189
set_mcast_snooping_port(struct ofproto *ofproto_, void *aux,
3190
const struct ofproto_mcast_snooping_port_settings *s)
3192
struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
3193
struct ofbundle *bundle = bundle_lookup(ofproto, aux);
3195
if (ofproto->ms && s) {
3196
ovs_rwlock_wrlock(&ofproto->ms->rwlock);
3197
mcast_snooping_set_port_flood(ofproto->ms, bundle, s->flood);
3198
mcast_snooping_set_port_flood_reports(ofproto->ms, bundle,
3200
ovs_rwlock_unlock(&ofproto->ms->rwlock);
2733
static struct ofport_dpif *
2734
get_ofp_port(const struct ofproto_dpif *ofproto, ofp_port_t ofp_port)
3208
struct ofport_dpif *
3209
ofp_port_to_ofport(const struct ofproto_dpif *ofproto, ofp_port_t ofp_port)
2736
3211
struct ofport *ofport = ofproto_get_port(&ofproto->up, ofp_port);
2737
3212
return ofport ? ofport_dpif_cast(ofport) : NULL;
3155
3645
rule_dpif_credit_stats(rule, &stats);
3158
xlate_in_init(&xin, ofproto, flow, rule, stats.tcp_flags, packet);
3648
xlate_in_init(&xin, ofproto, flow, flow->in_port.ofp_port, rule,
3649
stats.tcp_flags, packet);
3159
3650
xin.ofpacts = ofpacts;
3160
3651
xin.ofpacts_len = ofpacts_len;
3161
3652
xin.resubmit_stats = &stats;
3162
3653
xlate_actions(&xin, &xout);
3164
execute.actions = ofpbuf_data(&xout.odp_actions);
3165
execute.actions_len = ofpbuf_size(&xout.odp_actions);
3655
execute.actions = xout.odp_actions->data;
3656
execute.actions_len = xout.odp_actions->size;
3658
pkt_metadata_from_flow(&packet->md, flow);
3166
3659
execute.packet = packet;
3167
execute.md = pkt_metadata_from_flow(flow);
3168
3660
execute.needs_help = (xout.slow & SLOW_ACTION) != 0;
3661
execute.probe = false;
3170
3663
/* Fix up in_port. */
3171
3664
in_port = flow->in_port.ofp_port;
3172
3665
if (in_port == OFPP_NONE) {
3173
3666
in_port = OFPP_LOCAL;
3175
execute.md.in_port.odp_port = ofp_port_to_odp_port(ofproto, in_port);
3668
execute.packet->md.in_port.odp_port = ofp_port_to_odp_port(ofproto, in_port);
3177
3670
error = dpif_execute(ofproto->backer->dpif, &execute);
3206
3703
ofproto_rule_reduce_timeouts(&rule->up, idle_timeout, hard_timeout);
3209
/* Returns 'rule''s actions. The caller owns a reference on the returned
3210
* actions and must eventually release it (with rule_actions_unref()) to avoid
3706
/* Returns 'rule''s actions. The returned actions are RCU-protected, and can
3707
* be read until the calling thread quiesces. */
3212
3708
const struct rule_actions *
3213
3709
rule_dpif_get_actions(const struct rule_dpif *rule)
3215
3711
return rule_get_actions(&rule->up);
3218
/* Lookup 'flow' in table 0 of 'ofproto''s classifier.
3219
* If 'wc' is non-null, sets the fields that were relevant as part of
3220
* the lookup. Returns the table_id where a match or miss occurred.
3222
* The return value will be zero unless there was a miss and
3223
* OFPTC11_TABLE_MISS_CONTINUE is in effect for the sequence of tables
3224
* where misses occur.
3226
* The rule is returned in '*rule', which is valid at least until the next
3227
* RCU quiescent period. If the '*rule' needs to stay around longer,
3228
* a non-zero 'take_ref' must be passed in to cause a reference to be taken
3229
* on it before this returns. */
3231
rule_dpif_lookup(struct ofproto_dpif *ofproto, struct flow *flow,
3232
struct flow_wildcards *wc, struct rule_dpif **rule,
3714
/* Sets 'rule''s recirculation id. */
3716
rule_dpif_set_recirc_id(struct rule_dpif *rule, uint32_t id)
3717
OVS_REQUIRES(rule->up.mutex)
3235
enum rule_dpif_lookup_verdict verdict;
3236
enum ofputil_port_config config = 0;
3239
if (ofproto_dpif_get_enable_recirc(ofproto)) {
3240
/* Always exactly match recirc_id since datapath supports
3243
wc->masks.recirc_id = UINT32_MAX;
3245
table_id = rule_dpif_lookup_get_init_table_id(flow);
3719
ovs_assert(!rule->recirc_id || rule->recirc_id == id);
3720
if (rule->recirc_id == id) {
3721
/* Release the new reference to the same id. */
3250
verdict = rule_dpif_lookup_from_table(ofproto, flow, wc, true,
3251
&table_id, rule, take_ref);
3254
case RULE_DPIF_LOOKUP_VERDICT_MATCH:
3256
case RULE_DPIF_LOOKUP_VERDICT_CONTROLLER: {
3257
struct ofport_dpif *port;
3259
port = get_ofp_port(ofproto, flow->in_port.ofp_port);
3261
VLOG_WARN_RL(&rl, "packet-in on unknown OpenFlow port %"PRIu16,
3262
flow->in_port.ofp_port);
3264
config = port ? port->up.pp.config : 0;
3267
case RULE_DPIF_LOOKUP_VERDICT_DROP:
3268
config = OFPUTIL_PC_NO_PACKET_IN;
3270
case RULE_DPIF_LOOKUP_VERDICT_DEFAULT:
3271
if (!connmgr_wants_packet_in_on_miss(ofproto->up.connmgr)) {
3272
config = OFPUTIL_PC_NO_PACKET_IN;
3279
choose_miss_rule(config, ofproto->miss_rule,
3280
ofproto->no_packet_in_rule, rule, take_ref);
3284
/* The returned rule is valid at least until the next RCU quiescent period.
3285
* If the '*rule' needs to stay around longer, a non-zero 'take_ref' must be
3286
* passed in to cause a reference to be taken on it before this returns. */
3724
rule->recirc_id = id;
3728
/* Sets 'rule''s recirculation id. */
3730
rule_set_recirc_id(struct rule *rule_, uint32_t id)
3732
struct rule_dpif *rule = rule_dpif_cast(rule_);
3734
ovs_mutex_lock(&rule->up.mutex);
3735
rule_dpif_set_recirc_id(rule, id);
3736
ovs_mutex_unlock(&rule->up.mutex);
3740
ofproto_dpif_get_tables_version(struct ofproto_dpif *ofproto OVS_UNUSED)
3742
cls_version_t version;
3744
atomic_read_relaxed(&ofproto->tables_version, &version);
3749
/* The returned rule (if any) is valid at least until the next RCU quiescent
3750
* period. If the rule needs to stay around longer, a non-zero 'take_ref'
3751
* must be passed in to cause a reference to be taken on it.
3753
* 'flow' is non-const to allow for temporary modifications during the lookup.
3754
* Any changes are restored before returning. */
3287
3755
static struct rule_dpif *
3288
rule_dpif_lookup_in_table(struct ofproto_dpif *ofproto, uint8_t table_id,
3289
const struct flow *flow, struct flow_wildcards *wc,
3756
rule_dpif_lookup_in_table(struct ofproto_dpif *ofproto, cls_version_t version,
3757
uint8_t table_id, struct flow *flow,
3758
struct flow_wildcards *wc, bool take_ref)
3292
3760
struct classifier *cls = &ofproto->up.tables[table_id].cls;
3293
3761
const struct cls_rule *cls_rule;
3294
3762
struct rule_dpif *rule;
3296
fat_rwlock_rdlock(&cls->rwlock);
3297
if (ofproto->up.frag_handling != OFPC_FRAG_NX_MATCH) {
3299
memset(&wc->masks.dl_type, 0xff, sizeof wc->masks.dl_type);
3300
if (is_ip_any(flow)) {
3301
wc->masks.nw_frag |= FLOW_NW_FRAG_MASK;
3305
if (flow->nw_frag & FLOW_NW_FRAG_ANY) {
3306
if (ofproto->up.frag_handling == OFPC_FRAG_NORMAL) {
3307
/* We must pretend that transport ports are unavailable. */
3308
struct flow ofpc_normal_flow = *flow;
3309
ofpc_normal_flow.tp_src = htons(0);
3310
ofpc_normal_flow.tp_dst = htons(0);
3311
cls_rule = classifier_lookup(cls, &ofpc_normal_flow, wc);
3313
/* Must be OFPC_FRAG_DROP (we don't have OFPC_FRAG_REASM). */
3314
cls_rule = &ofproto->drop_frags_rule->up.cr;
3317
cls_rule = classifier_lookup(cls, flow, wc);
3320
cls_rule = classifier_lookup(cls, flow, wc);
3323
rule = rule_dpif_cast(rule_from_cls_rule(cls_rule));
3325
rule_dpif_ref(rule);
3327
fat_rwlock_unlock(&cls->rwlock);
3765
cls_rule = classifier_lookup(cls, version, flow, wc);
3767
rule = rule_dpif_cast(rule_from_cls_rule(cls_rule));
3769
/* Try again if the rule was released before we get the reference. */
3770
} while (rule && take_ref && !rule_dpif_try_ref(rule));
3332
/* Look up 'flow' in 'ofproto''s classifier starting from table '*table_id'.
3333
* Stores the rule that was found in '*rule', or NULL if none was found.
3334
* Updates 'wc', if nonnull, to reflect the fields that were used during the
3775
/* Look up 'flow' in 'ofproto''s classifier version 'version', starting from
3776
* table '*table_id'. Returns the rule that was found, which may be one of the
3777
* special rules according to packet miss hadling. If 'may_packet_in' is
3778
* false, returning of the miss_rule (which issues packet ins for the
3779
* controller) is avoided. Updates 'wc', if nonnull, to reflect the fields
3780
* that were used during the lookup.
3337
3782
* If 'honor_table_miss' is true, the first lookup occurs in '*table_id', but
3338
3783
* if none is found then the table miss configuration for that table is
3343
3788
* If 'honor_table_miss' is false, then only one table lookup occurs, in
3348
* - RULE_DPIF_LOOKUP_VERDICT_MATCH if a rule (in '*rule') was found.
3350
* - RULE_OFPTC_TABLE_MISS_CONTROLLER if no rule was found and either:
3351
* + 'honor_table_miss' is false
3352
* + a table miss configuration specified that the packet should be
3353
* sent to the controller in this case.
3355
* - RULE_DPIF_LOOKUP_VERDICT_DROP if no rule was found, 'honor_table_miss'
3356
* is true and a table miss configuration specified that the packet
3357
* should be dropped in this case.
3359
* - RULE_DPIF_LOOKUP_VERDICT_DEFAULT if no rule was found,
3360
* 'honor_table_miss' is true and a table miss configuration has
3361
* not been specified in this case.
3363
3791
* The rule is returned in '*rule', which is valid at least until the next
3364
3792
* RCU quiescent period. If the '*rule' needs to stay around longer,
3365
3793
* a non-zero 'take_ref' must be passed in to cause a reference to be taken
3366
* on it before this returns. */
3367
enum rule_dpif_lookup_verdict
3794
* on it before this returns.
3796
* 'in_port' allows the lookup to take place as if the in port had the value
3797
* 'in_port'. This is needed for resubmit action support.
3799
* 'flow' is non-const to allow for temporary modifications during the lookup.
3800
* Any changes are restored before returning. */
3368
3802
rule_dpif_lookup_from_table(struct ofproto_dpif *ofproto,
3369
const struct flow *flow,
3370
struct flow_wildcards *wc,
3371
bool honor_table_miss,
3372
uint8_t *table_id, struct rule_dpif **rule,
3803
cls_version_t version, struct flow *flow,
3804
struct flow_wildcards *wc, bool take_ref,
3805
const struct dpif_flow_stats *stats,
3806
uint8_t *table_id, ofp_port_t in_port,
3807
bool may_packet_in, bool honor_table_miss)
3809
ovs_be16 old_tp_src = flow->tp_src, old_tp_dst = flow->tp_dst;
3810
ofp_port_t old_in_port = flow->in_port.ofp_port;
3811
enum ofputil_table_miss miss_config;
3812
struct rule_dpif *rule;
3375
3813
uint8_t next_id;
3815
/* We always unwildcard nw_frag (for IP), so they
3816
* need not be unwildcarded here. */
3817
if (flow->nw_frag & FLOW_NW_FRAG_ANY
3818
&& ofproto->up.frag_handling != OFPC_FRAG_NX_MATCH) {
3819
if (ofproto->up.frag_handling == OFPC_FRAG_NORMAL) {
3820
/* We must pretend that transport ports are unavailable. */
3821
flow->tp_src = htons(0);
3822
flow->tp_dst = htons(0);
3824
/* Must be OFPC_FRAG_DROP (we don't have OFPC_FRAG_REASM).
3825
* Use the drop_frags_rule (which cannot disappear). */
3826
rule = ofproto->drop_frags_rule;
3828
rule_dpif_ref(rule);
3831
struct oftable *tbl = &ofproto->up.tables[*table_id];
3834
atomic_add_relaxed(&tbl->n_matched, stats->n_packets, &orig);
3840
/* Look up a flow with 'in_port' as the input port. Then restore the
3841
* original input port (otherwise OFPP_NORMAL and OFPP_IN_PORT will
3842
* have surprising behavior). */
3843
flow->in_port.ofp_port = in_port;
3845
/* Our current implementation depends on n_tables == N_TABLES, and
3846
* TBL_INTERNAL being the last table. */
3847
BUILD_ASSERT_DECL(N_TABLES == TBL_INTERNAL + 1);
3849
miss_config = OFPUTIL_TABLE_MISS_CONTINUE;
3377
3851
for (next_id = *table_id;
3378
3852
next_id < ofproto->up.n_tables;
3379
3853
next_id++, next_id += (next_id == TBL_INTERNAL))
3381
3855
*table_id = next_id;
3382
*rule = rule_dpif_lookup_in_table(ofproto, *table_id, flow, wc,
3385
return RULE_DPIF_LOOKUP_VERDICT_MATCH;
3386
} else if (!honor_table_miss) {
3387
return RULE_DPIF_LOOKUP_VERDICT_CONTROLLER;
3389
switch (ofproto_table_get_config(&ofproto->up, *table_id)) {
3390
case OFPROTO_TABLE_MISS_CONTINUE:
3393
case OFPROTO_TABLE_MISS_CONTROLLER:
3394
return RULE_DPIF_LOOKUP_VERDICT_CONTROLLER;
3396
case OFPROTO_TABLE_MISS_DROP:
3397
return RULE_DPIF_LOOKUP_VERDICT_DROP;
3399
case OFPROTO_TABLE_MISS_DEFAULT:
3400
return RULE_DPIF_LOOKUP_VERDICT_DEFAULT;
3405
return RULE_DPIF_LOOKUP_VERDICT_CONTROLLER;
3408
/* Given a port configuration (specified as zero if there's no port), chooses
3409
* which of 'miss_rule' and 'no_packet_in_rule' should be used in case of a
3412
* The rule is returned in '*rule', which is valid at least until the next
3413
* RCU quiescent period. If the '*rule' needs to stay around longer,
3414
* a reference must be taken on it (rule_dpif_ref()).
3417
choose_miss_rule(enum ofputil_port_config config, struct rule_dpif *miss_rule,
3418
struct rule_dpif *no_packet_in_rule, struct rule_dpif **rule,
3421
*rule = config & OFPUTIL_PC_NO_PACKET_IN ? no_packet_in_rule : miss_rule;
3856
rule = rule_dpif_lookup_in_table(ofproto, version, next_id, flow, wc,
3859
struct oftable *tbl = &ofproto->up.tables[next_id];
3862
atomic_add_relaxed(rule ? &tbl->n_matched : &tbl->n_missed,
3863
stats->n_packets, &orig);
3866
goto out; /* Match. */
3868
if (honor_table_miss) {
3869
miss_config = ofproto_table_get_miss_config(&ofproto->up,
3871
if (miss_config == OFPUTIL_TABLE_MISS_CONTINUE) {
3878
rule = ofproto->no_packet_in_rule;
3879
if (may_packet_in) {
3880
if (miss_config == OFPUTIL_TABLE_MISS_CONTINUE
3881
|| miss_config == OFPUTIL_TABLE_MISS_CONTROLLER) {
3882
struct ofport_dpif *port;
3884
port = ofp_port_to_ofport(ofproto, old_in_port);
3886
VLOG_WARN_RL(&rl, "packet-in on unknown OpenFlow port %"PRIu16,
3888
} else if (!(port->up.pp.config & OFPUTIL_PC_NO_PACKET_IN)) {
3889
rule = ofproto->miss_rule;
3891
} else if (miss_config == OFPUTIL_TABLE_MISS_DEFAULT &&
3892
connmgr_wants_packet_in_on_miss(ofproto->up.connmgr)) {
3893
rule = ofproto->miss_rule;
3422
3896
if (take_ref) {
3423
rule_dpif_ref(*rule);
3897
rule_dpif_ref(rule);
3900
/* Restore port numbers, as they may have been modified above. */
3901
flow->tp_src = old_tp_src;
3902
flow->tp_dst = old_tp_dst;
3903
/* Restore the old in port. */
3904
flow->in_port.ofp_port = old_in_port;
3558
4057
group_construct_stats(struct group_dpif *group)
3559
4058
OVS_REQUIRES(group->stats_mutex)
4060
struct ofputil_bucket *bucket;
4061
const struct ovs_list *buckets;
3561
4063
group->packet_count = 0;
3562
4064
group->byte_count = 0;
3563
if (!group->bucket_stats) {
3564
group->bucket_stats = xcalloc(group->up.n_buckets,
3565
sizeof *group->bucket_stats);
3567
memset(group->bucket_stats, 0, group->up.n_buckets *
3568
sizeof *group->bucket_stats);
4066
group_dpif_get_buckets(group, &buckets);
4067
LIST_FOR_EACH (bucket, list_node, buckets) {
4068
bucket->stats.packet_count = 0;
4069
bucket->stats.byte_count = 0;
4074
group_dpif_credit_stats(struct group_dpif *group,
4075
struct ofputil_bucket *bucket,
4076
const struct dpif_flow_stats *stats)
4078
ovs_mutex_lock(&group->stats_mutex);
4079
group->packet_count += stats->n_packets;
4080
group->byte_count += stats->n_bytes;
4082
bucket->stats.packet_count += stats->n_packets;
4083
bucket->stats.byte_count += stats->n_bytes;
4084
} else { /* Credit to all buckets */
4085
const struct ovs_list *buckets;
4087
group_dpif_get_buckets(group, &buckets);
4088
LIST_FOR_EACH (bucket, list_node, buckets) {
4089
bucket->stats.packet_count += stats->n_packets;
4090
bucket->stats.byte_count += stats->n_bytes;
4093
ovs_mutex_unlock(&group->stats_mutex);
3572
4096
static enum ofperr
3635
4139
group_get_stats(const struct ofgroup *group_, struct ofputil_group_stats *ogs)
3637
4141
struct group_dpif *group = group_dpif_cast(group_);
4142
struct ofputil_bucket *bucket;
4143
const struct ovs_list *buckets;
4144
struct bucket_counter *bucket_stats;
3639
4146
ovs_mutex_lock(&group->stats_mutex);
3640
4147
ogs->packet_count = group->packet_count;
3641
4148
ogs->byte_count = group->byte_count;
3642
memcpy(ogs->bucket_stats, group->bucket_stats,
3643
group->up.n_buckets * sizeof *group->bucket_stats);
4150
group_dpif_get_buckets(group, &buckets);
4151
bucket_stats = ogs->bucket_stats;
4152
LIST_FOR_EACH (bucket, list_node, buckets) {
4153
bucket_stats->packet_count = bucket->stats.packet_count;
4154
bucket_stats->byte_count = bucket->stats.byte_count;
3644
4157
ovs_mutex_unlock(&group->stats_mutex);
4162
/* If the group exists, this function increments the groups's reference count.
4164
* Make sure to call group_dpif_unref() after no longer needing to maintain
4165
* a reference to the group. */
3650
4167
group_dpif_lookup(struct ofproto_dpif *ofproto, uint32_t group_id,
3651
4168
struct group_dpif **group)
3652
OVS_TRY_RDLOCK(true, (*group)->up.rwlock)
3654
4170
struct ofgroup *ofgroup;
3658
4173
found = ofproto_group_lookup(&ofproto->up, group_id, &ofgroup);
3659
4174
*group = found ? group_dpif_cast(ofgroup) : NULL;
3834
4401
ds_destroy(&ds);
4405
ofproto_unixctl_mcast_snooping_show(struct unixctl_conn *conn,
4406
int argc OVS_UNUSED,
4408
void *aux OVS_UNUSED)
4410
struct ds ds = DS_EMPTY_INITIALIZER;
4411
const struct ofproto_dpif *ofproto;
4412
const struct ofbundle *bundle;
4413
const struct mcast_group *grp;
4414
struct mcast_group_bundle *b;
4415
struct mcast_mrouter_bundle *mrouter;
4417
ofproto = ofproto_dpif_lookup(argv[1]);
4419
unixctl_command_reply_error(conn, "no such bridge");
4423
if (!mcast_snooping_enabled(ofproto->ms)) {
4424
unixctl_command_reply_error(conn, "multicast snooping is disabled");
4428
ds_put_cstr(&ds, " port VLAN GROUP Age\n");
4429
ovs_rwlock_rdlock(&ofproto->ms->rwlock);
4430
LIST_FOR_EACH (grp, group_node, &ofproto->ms->group_lru) {
4431
LIST_FOR_EACH(b, bundle_node, &grp->bundle_lru) {
4432
char name[OFP_MAX_PORT_NAME_LEN];
4435
ofputil_port_to_string(ofbundle_get_a_port(bundle)->up.ofp_port,
4437
ds_put_format(&ds, "%5s %4d "IP_FMT" %3d\n",
4438
name, grp->vlan, IP_ARGS(grp->ip4),
4439
mcast_bundle_age(ofproto->ms, b));
4443
/* ports connected to multicast routers */
4444
LIST_FOR_EACH(mrouter, mrouter_node, &ofproto->ms->mrouter_lru) {
4445
char name[OFP_MAX_PORT_NAME_LEN];
4447
bundle = mrouter->port;
4448
ofputil_port_to_string(ofbundle_get_a_port(bundle)->up.ofp_port,
4450
ds_put_format(&ds, "%5s %4d querier %3d\n",
4451
name, mrouter->vlan,
4452
mcast_mrouter_age(ofproto->ms, mrouter));
4454
ovs_rwlock_unlock(&ofproto->ms->rwlock);
4455
unixctl_command_reply(conn, ds_cstr(&ds));
3837
4459
struct trace_ctx {
3838
4460
struct xlate_out xout;
3839
4461
struct xlate_in xin;
3930
4551
ds_put_char(result, '\n');
4554
static void trace_report(struct xlate_in *xin, const char *s, int recurse);
3934
4557
trace_resubmit(struct xlate_in *xin, struct rule_dpif *rule, int recurse)
3936
4559
struct trace_ctx *trace = CONTAINER_OF(xin, struct trace_ctx, xin);
3937
4560
struct ds *result = trace->result;
4563
if (rule == xin->ofproto->miss_rule) {
4564
trace_report(xin, "No match, flow generates \"packet in\"s.",
4566
} else if (rule == xin->ofproto->no_packet_in_rule) {
4567
trace_report(xin, "No match, packets dropped because "
4568
"OFPPC_NO_PACKET_IN is set on in_port.", recurse);
4569
} else if (rule == xin->ofproto->drop_frags_rule) {
4570
trace_report(xin, "Packets dropped because they are IP "
4571
"fragments and the fragment handling mode is "
4572
"\"drop\".", recurse);
3939
4576
ds_put_char(result, '\n');
3940
trace_format_flow(result, recurse + 1, "Resubmitted flow", trace);
3941
trace_format_regs(result, recurse + 1, "Resubmitted regs", trace);
3942
trace_format_odp(result, recurse + 1, "Resubmitted odp", trace);
3943
trace_format_megaflow(result, recurse + 1, "Resubmitted megaflow", trace);
3944
trace_format_rule(result, recurse + 1, rule);
4578
trace_format_flow(result, recurse, "Resubmitted flow", trace);
4579
trace_format_regs(result, recurse, "Resubmitted regs", trace);
4580
trace_format_odp(result, recurse, "Resubmitted odp", trace);
4581
trace_format_megaflow(result, recurse, "Resubmitted megaflow", trace);
4583
trace_format_rule(result, recurse, rule);
4228
4873
ds_put_char(ds, '\n');
4230
4875
flow_wildcards_init_catchall(&trace.wc);
4234
rule_dpif_lookup(ofproto, flow, &trace.wc, &rule, false);
4236
trace_format_rule(ds, 0, rule);
4237
if (rule == ofproto->miss_rule) {
4238
ds_put_cstr(ds, "\nNo match, flow generates \"packet in\"s.\n");
4239
} else if (rule == ofproto->no_packet_in_rule) {
4240
ds_put_cstr(ds, "\nNo match, packets dropped because "
4241
"OFPPC_NO_PACKET_IN is set on in_port.\n");
4242
} else if (rule == ofproto->drop_frags_rule) {
4243
ds_put_cstr(ds, "\nPackets dropped because they are IP fragments "
4244
"and the fragment handling mode is \"drop\".\n");
4248
if (rule || ofpacts) {
4250
trace.key = flow; /* Original flow key, used for megaflow. */
4251
trace.flow = *flow; /* May be modified by actions. */
4252
xlate_in_init(&trace.xin, ofproto, flow, rule, ntohs(flow->tcp_flags),
4255
trace.xin.ofpacts = ofpacts;
4256
trace.xin.ofpacts_len = ofpacts_len;
4258
trace.xin.resubmit_hook = trace_resubmit;
4259
trace.xin.report_hook = trace_report;
4261
xlate_actions(&trace.xin, &trace.xout);
4263
ds_put_char(ds, '\n');
4264
trace_format_flow(ds, 0, "Final flow", &trace);
4265
trace_format_megaflow(ds, 0, "Megaflow", &trace);
4267
ds_put_cstr(ds, "Datapath actions: ");
4268
format_odp_actions(ds, ofpbuf_data(&trace.xout.odp_actions),
4269
ofpbuf_size(&trace.xout.odp_actions));
4271
if (trace.xout.slow) {
4272
enum slow_path_reason slow;
4274
ds_put_cstr(ds, "\nThis flow is handled by the userspace "
4275
"slow path because it:");
4277
slow = trace.xout.slow;
4279
enum slow_path_reason bit = rightmost_1bit(slow);
4281
ds_put_format(ds, "\n\t- %s.",
4282
slow_path_reason_to_explanation(bit));
4288
xlate_out_uninit(&trace.xout);
4878
trace.key = flow; /* Original flow key, used for megaflow. */
4879
trace.flow = *flow; /* May be modified by actions. */
4880
xlate_in_init(&trace.xin, ofproto, flow, flow->in_port.ofp_port, NULL,
4881
ntohs(flow->tcp_flags), packet);
4882
trace.xin.ofpacts = ofpacts;
4883
trace.xin.ofpacts_len = ofpacts_len;
4884
trace.xin.resubmit_hook = trace_resubmit;
4885
trace.xin.report_hook = trace_report;
4887
xlate_actions(&trace.xin, &trace.xout);
4889
ds_put_char(ds, '\n');
4890
trace_format_flow(ds, 0, "Final flow", &trace);
4891
trace_format_megaflow(ds, 0, "Megaflow", &trace);
4893
ds_put_cstr(ds, "Datapath actions: ");
4894
format_odp_actions(ds, trace.xout.odp_actions->data,
4895
trace.xout.odp_actions->size);
4897
if (trace.xout.slow) {
4898
enum slow_path_reason slow;
4900
ds_put_cstr(ds, "\nThis flow is handled by the userspace "
4901
"slow path because it:");
4903
slow = trace.xout.slow;
4905
enum slow_path_reason bit = rightmost_1bit(slow);
4907
ds_put_format(ds, "\n\t- %s.",
4908
slow_path_reason_to_explanation(bit));
4914
xlate_out_uninit(&trace.xout);
4292
4917
/* Store the current ofprotos in 'ofproto_shash'. Returns a sorted list
4416
5041
ds_destroy(&ds);
4420
ofproto_dpif_contains_flow(const struct ofproto_dpif *ofproto,
4421
const struct nlattr *key, size_t key_len)
4423
struct ofproto_dpif *ofp;
4426
xlate_receive(ofproto->backer, NULL, key, key_len, &flow, &ofp,
4427
NULL, NULL, NULL, NULL);
4428
return ofp == ofproto;
4432
5045
ofproto_unixctl_dpif_dump_flows(struct unixctl_conn *conn,
4433
5046
int argc OVS_UNUSED, const char *argv[],
4434
5047
void *aux OVS_UNUSED)
5049
const struct ofproto_dpif *ofproto;
4436
5051
struct ds ds = DS_EMPTY_INITIALIZER;
4437
const struct dpif_flow_stats *stats;
4438
const struct ofproto_dpif *ofproto;
4439
struct dpif_flow_dump flow_dump;
4440
const struct nlattr *actions;
4441
const struct nlattr *mask;
4442
const struct nlattr *key;
4446
5052
bool verbosity = false;
4447
5054
struct dpif_port dpif_port;
4448
5055
struct dpif_port_dump port_dump;
4449
5056
struct hmap portno_names;
5058
struct dpif_flow_dump *flow_dump;
5059
struct dpif_flow_dump_thread *flow_dump_thread;
4453
5063
ofproto = ofproto_dpif_lookup(argv[argc - 1]);
4469
error = dpif_flow_dump_start(&flow_dump, ofproto->backer->dpif);
4473
dpif_flow_dump_state_init(ofproto->backer->dpif, &state);
4474
while (dpif_flow_dump_next(&flow_dump, state, &key, &key_len,
4475
&mask, &mask_len, &actions, &actions_len,
4477
if (!ofproto_dpif_contains_flow(ofproto, key, key_len)) {
5079
flow_dump = dpif_flow_dump_create(ofproto->backer->dpif, false);
5080
flow_dump_thread = dpif_flow_dump_thread_create(flow_dump);
5081
while (dpif_flow_dump_next(flow_dump_thread, &f, 1)) {
5084
if (odp_flow_key_to_flow(f.key, f.key_len, &flow) == ODP_FIT_ERROR
5085
|| xlate_lookup_ofproto(ofproto->backer, &flow, NULL) != ofproto) {
4481
odp_flow_format(key, key_len, mask, mask_len, &portno_names, &ds,
5090
odp_format_ufid(&f.ufid, &ds);
5091
ds_put_cstr(&ds, " ");
5093
odp_flow_format(f.key, f.key_len, f.mask, f.mask_len,
5094
&portno_names, &ds, verbosity);
4483
5095
ds_put_cstr(&ds, ", ");
4484
dpif_flow_stats_format(stats, &ds);
5096
dpif_flow_stats_format(&f.stats, &ds);
4485
5097
ds_put_cstr(&ds, ", actions:");
4486
format_odp_actions(&ds, actions, actions_len);
5098
format_odp_actions(&ds, f.actions, f.actions_len);
4487
5099
ds_put_char(&ds, '\n');
4489
dpif_flow_dump_state_uninit(ofproto->backer->dpif, state);
4490
error = dpif_flow_dump_done(&flow_dump);
5101
dpif_flow_dump_thread_destroy(flow_dump_thread);
5102
error = dpif_flow_dump_destroy(flow_dump);
4495
5106
ds_put_format(&ds, "dpif/dump_flows failed: %s", ovs_strerror(errno));
4523
5163
ofproto_unixctl_fdb_flush, NULL);
4524
5164
unixctl_command_register("fdb/show", "bridge", 1, 1,
4525
5165
ofproto_unixctl_fdb_show, NULL);
5166
unixctl_command_register("mdb/flush", "[bridge]", 0, 1,
5167
ofproto_unixctl_mcast_snooping_flush, NULL);
5168
unixctl_command_register("mdb/show", "bridge", 1, 1,
5169
ofproto_unixctl_mcast_snooping_show, NULL);
4526
5170
unixctl_command_register("dpif/dump-dps", "", 0, 0,
4527
5171
ofproto_unixctl_dpif_dump_dps, NULL);
4528
5172
unixctl_command_register("dpif/show", "", 0, 0, ofproto_unixctl_dpif_show,
4530
5174
unixctl_command_register("dpif/dump-flows", "[-m] bridge", 1, 2,
4531
5175
ofproto_unixctl_dpif_dump_flows, NULL);
5177
unixctl_command_register("ofproto/tnl-push-pop", "[on]|[off]", 1, 1,
5178
disable_tnl_push_pop, NULL);
4534
5181
/* Returns true if 'table' is the table used for internal rules,
4803
struct ofproto_dpif *
4804
ofproto_dpif_recirc_get_ofproto(const struct dpif_backer *backer,
4807
struct dpif_backer_recirc_node *node;
4809
ovs_mutex_lock(&backer->recirc_mutex);
4810
node = CONTAINER_OF(hmap_first_with_hash(&backer->recirc_map, recirc_id),
4811
struct dpif_backer_recirc_node, hmap_node);
4812
ovs_mutex_unlock(&backer->recirc_mutex);
4814
return node ? node->ofproto : NULL;
4818
ofproto_dpif_alloc_recirc_id(struct ofproto_dpif *ofproto)
4820
struct dpif_backer *backer = ofproto->backer;
4821
uint32_t recirc_id = recirc_id_alloc(backer->rid_pool);
4824
struct dpif_backer_recirc_node *node = xmalloc(sizeof *node);
4826
node->recirc_id = recirc_id;
4827
node->ofproto = ofproto;
4829
ovs_mutex_lock(&backer->recirc_mutex);
4830
hmap_insert(&backer->recirc_map, &node->hmap_node, node->recirc_id);
4831
ovs_mutex_unlock(&backer->recirc_mutex);
4838
ofproto_dpif_free_recirc_id(struct ofproto_dpif *ofproto, uint32_t recirc_id)
4840
struct dpif_backer *backer = ofproto->backer;
4841
struct dpif_backer_recirc_node *node;
4843
ovs_mutex_lock(&backer->recirc_mutex);
4844
node = CONTAINER_OF(hmap_first_with_hash(&backer->recirc_map, recirc_id),
4845
struct dpif_backer_recirc_node, hmap_node);
4847
hmap_remove(&backer->recirc_map, &node->hmap_node);
4848
ovs_mutex_unlock(&backer->recirc_mutex);
4849
recirc_id_free(backer->rid_pool, node->recirc_id);
4851
if (node->ofproto != ofproto) {
4852
VLOG_ERR("recirc_id %"PRIu32", freed by incorrect ofproto (%s),"
4853
" expect ofproto (%s)", node->recirc_id, ofproto->up.name,
4854
node->ofproto->up.name);
4857
/* RCU postpone the free, since other threads may be referring
4858
* to 'node' at same time. */
4859
ovsrcu_postpone(free, node);
4861
ovs_mutex_unlock(&backer->recirc_mutex);
4866
5462
ofproto_dpif_add_internal_flow(struct ofproto_dpif *ofproto,
4867
5463
const struct match *match, int priority,
5464
uint16_t idle_timeout,
4868
5465
const struct ofpbuf *ofpacts,
4869
5466
struct rule **rulep)