summaryrefslogtreecommitdiff
path: root/lib/learning-switch.c
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2011-03-22 09:47:02 -0700
committerBen Pfaff <blp@nicira.com>2011-03-22 09:47:02 -0700
commitdb8077c315f12fd523ace965cc22778ed8d5939a (patch)
treef2d7acc0a062154bf3b1716921b4c9d8314a8d89 /lib/learning-switch.c
parent83db796889bf98f8699fbd7305ffe920a0b527a1 (diff)
downloadopenvswitch-db8077c315f12fd523ace965cc22778ed8d5939a.tar.gz
mac-learning: Refactor to increase generality.
In an upcoming commit I want to store a pointer in MAC learning entries in the bridge, instead of an integer port number. The MAC learning library has other clients, and the others do not gracefully fit this new model, so in fact the data will have to become a union. However, this does not fit well with the current mac_learning API, since mac_learning_learn() currently initializes and compares the data. It seems better to break up the API so that only the client has to know the data's format and how to initialize it or compare it. This commit makes this possible. This commit doesn't change the type of the data stored in a MAC learning entry yet. As a side effect this commit has the benefit that clients that don't need gratuitous ARP locking don't have to specify any policy for it at all.
Diffstat (limited to 'lib/learning-switch.c')
-rw-r--r--lib/learning-switch.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/learning-switch.c b/lib/learning-switch.c
index ca970540e..5fa3a53b0 100644
--- a/lib/learning-switch.c
+++ b/lib/learning-switch.c
@@ -324,12 +324,15 @@ lswitch_choose_destination(struct lswitch *sw, const struct flow *flow)
uint16_t out_port;
/* Learn the source MAC. */
- if (sw->ml) {
- if (mac_learning_learn(sw->ml, flow->dl_src, 0, flow->in_port,
- GRAT_ARP_LOCK_NONE)) {
+ if (mac_learning_may_learn(sw->ml, flow->dl_src, 0)) {
+ struct mac_entry *mac = mac_learning_insert(sw->ml, flow->dl_src, 0);
+ if (mac_entry_is_new(mac) || mac->port != flow->in_port) {
VLOG_DBG_RL(&rl, "%016llx: learned that "ETH_ADDR_FMT" is on "
"port %"PRIu16, sw->datapath_id,
ETH_ADDR_ARGS(flow->dl_src), flow->in_port);
+
+ mac->port = flow->in_port;
+ mac_learning_changed(sw->ml, mac);
}
}
@@ -340,9 +343,11 @@ lswitch_choose_destination(struct lswitch *sw, const struct flow *flow)
out_port = OFPP_FLOOD;
if (sw->ml) {
- int learned_port = mac_learning_lookup(sw->ml, flow->dl_dst, 0, NULL);
- if (learned_port >= 0) {
- out_port = learned_port;
+ struct mac_entry *mac;
+
+ mac = mac_learning_lookup(sw->ml, flow->dl_dst, 0, NULL);
+ if (mac) {
+ out_port = mac->port;
if (out_port == flow->in_port) {
/* Don't send a packet back out its input port. */
return OFPP_NONE;