2
0
mirror of https://github.com/openvswitch/ovs synced 2025-10-19 14:37:21 +00:00

mac-learning: New function mac_entry_age().

This function will be used as part of printing the MAC learning table at
user request.
This commit is contained in:
Ben Pfaff
2009-07-15 11:02:24 -07:00
parent eaa7133434
commit 321943f790
2 changed files with 14 additions and 1 deletions

View File

@@ -32,6 +32,14 @@
#define THIS_MODULE VLM_mac_learning #define THIS_MODULE VLM_mac_learning
#include "vlog.h" #include "vlog.h"
/* Returns the number of seconds since 'e' was last learned. */
int
mac_entry_age(const struct mac_entry *e)
{
time_t remaining = e->expires - time_now();
return MAC_ENTRY_IDLE_TIME - remaining;
}
static uint32_t static uint32_t
mac_table_hash(const uint8_t mac[ETH_ADDR_LEN], uint16_t vlan) mac_table_hash(const uint8_t mac[ETH_ADDR_LEN], uint16_t vlan)
{ {
@@ -174,7 +182,7 @@ mac_learning_learn(struct mac_learning *ml,
/* Make the entry most-recently-used. */ /* Make the entry most-recently-used. */
list_remove(&e->lru_node); list_remove(&e->lru_node);
list_push_back(&ml->lrus, &e->lru_node); list_push_back(&ml->lrus, &e->lru_node);
e->expires = time_now() + 60; e->expires = time_now() + MAC_ENTRY_IDLE_TIME;
/* Did we learn something? */ /* Did we learn something? */
if (e->port != src_port) { if (e->port != src_port) {

View File

@@ -28,6 +28,9 @@
#define MAC_MAX 1024 #define MAC_MAX 1024
/* Time, in seconds, before expiring a mac_entry due to inactivity. */
#define MAC_ENTRY_IDLE_TIME 60
/* A MAC learning table entry. */ /* A MAC learning table entry. */
struct mac_entry { struct mac_entry {
struct list hash_node; /* Element in a mac_learning 'table' list. */ struct list hash_node; /* Element in a mac_learning 'table' list. */
@@ -39,6 +42,8 @@ struct mac_entry {
tag_type tag; /* Tag for this learning entry. */ tag_type tag; /* Tag for this learning entry. */
}; };
int mac_entry_age(const struct mac_entry *);
/* MAC learning table. */ /* MAC learning table. */
struct mac_learning { struct mac_learning {
struct list free; /* Not-in-use entries. */ struct list free; /* Not-in-use entries. */