Skip to content

Commit

Permalink
LRU caching for flood rule priority.
Browse files Browse the repository at this point in the history
  • Loading branch information
anarkiwi committed Feb 2, 2020
1 parent b74a390 commit 0d78839
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions faucet/valve_flood.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import functools
from collections import defaultdict

from faucet import valve_of
Expand Down Expand Up @@ -85,6 +86,7 @@ def floods_to_root(self, _dp_obj):
"""Return True if the given dp floods (only) to root switch"""
return False

@functools.lru_cache(maxsize=1024)
def _mask_flood_priority(self, eth_dst_mask):
return self.flood_priority + valve_packet.mac_mask_bits(eth_dst_mask)

Expand Down Expand Up @@ -127,6 +129,7 @@ def _build_flood_rule(self, match, command, flood_acts, flood_priority):
inst=[valve_of.apply_actions(flood_acts)],
priority=flood_priority)

@functools.lru_cache(maxsize=1024)
def _vlan_flood_priority(self, eth_type, eth_dst_mask):
priority = self._mask_flood_priority(eth_dst_mask)
if eth_type:
Expand Down
2 changes: 2 additions & 0 deletions faucet/valve_packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
MAC_MASK_BITMAP = {(2**EUI_BITS - 2**i): (EUI_BITS - i) for i in range(0, EUI_BITS + 1)}


@functools.lru_cache(maxsize=1024)
def mac_mask_bits(mac_mask):
"""Return number of bits in MAC mask or 0."""
if mac_mask is not None:
Expand Down Expand Up @@ -377,6 +378,7 @@ def lacp_actor_up(lacp_pkt):
return 0


@functools.lru_cache(maxsize=1024)
def lacp_reqreply(eth_src,
actor_system, actor_key, actor_port,
actor_state_synchronization=0,
Expand Down

0 comments on commit 0d78839

Please sign in to comment.