~james-page/ubuntu/saucy/openvswitch/1.12-snapshot

« back to all changes in this revision

Viewing changes to lib/mac-learning.h

  • Committer: James Page
  • Date: 2013-08-21 10:16:57 UTC
  • mfrom: (1.1.20)
  • Revision ID: james.page@canonical.com-20130821101657-3o0z0qeiv5zkwlzi
New upstream snapshot

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include <time.h>
21
21
#include "hmap.h"
22
22
#include "list.h"
 
23
#include "ovs-atomic.h"
 
24
#include "ovs-thread.h"
23
25
#include "packets.h"
24
26
#include "tag.h"
25
27
#include "timeval.h"
36
38
 * relearning based on a reflection from a bond slave. */
37
39
#define MAC_GRAT_ARP_LOCK_TIME 5
38
40
 
39
 
/* A MAC learning table entry. */
 
41
/* A MAC learning table entry.
 
42
 * Guarded by owning 'mac_learning''s rwlock */
40
43
struct mac_entry {
41
44
    struct hmap_node hmap_node; /* Node in a mac_learning hmap. */
42
 
    struct list lru_node;       /* Element in 'lrus' list. */
43
45
    time_t expires;             /* Expiration time. */
44
46
    time_t grat_arp_lock;       /* Gratuitous ARP lock expiration time. */
45
47
    uint8_t mac[ETH_ADDR_LEN];  /* Known MAC address. */
46
48
    uint16_t vlan;              /* VLAN tag. */
47
49
    tag_type tag;               /* Tag for this learning entry. */
48
50
 
 
51
    /* The following are marked guarded to prevent users from iterating over or
 
52
     * accessing a mac_entry without hodling the parent mac_learning rwlock. */
 
53
    struct list lru_node OVS_GUARDED; /* Element in 'lrus' list. */
 
54
 
49
55
    /* Learned port. */
50
56
    union {
51
57
        void *p;
52
 
        int i;
53
 
    } port;
 
58
        ofp_port_t ofp_port;
 
59
    } port OVS_GUARDED;
54
60
};
55
61
 
56
 
int mac_entry_age(const struct mac_learning *, const struct mac_entry *);
57
 
 
58
62
/* Returns true if mac_learning_insert() just created 'mac' and the caller has
59
63
 * not yet properly initialized it. */
60
64
static inline bool mac_entry_is_new(const struct mac_entry *mac)
79
83
/* MAC learning table. */
80
84
struct mac_learning {
81
85
    struct hmap table;          /* Learning table. */
82
 
    struct list lrus;           /* In-use entries, least recently used at the
83
 
                                   front, most recently used at the back. */
 
86
    struct list lrus OVS_GUARDED; /* In-use entries, least recently used at the
 
87
                                     front, most recently used at the back. */
84
88
    uint32_t secret;            /* Secret for randomizing hash table. */
85
89
    unsigned long *flood_vlans; /* Bitmap of learning disabled VLANs. */
86
90
    unsigned int idle_time;     /* Max age before deleting an entry. */
87
91
    size_t max_entries;         /* Max number of learned MACs. */
 
92
    struct tag_set tags;        /* Tags which have changed. */
 
93
    atomic_int ref_cnt;
 
94
    struct ovs_rwlock rwlock;
88
95
};
89
96
 
 
97
int mac_entry_age(const struct mac_learning *ml, const struct mac_entry *e)
 
98
    OVS_REQ_RDLOCK(ml->rwlock);
 
99
 
90
100
/* Basics. */
91
101
struct mac_learning *mac_learning_create(unsigned int idle_time);
92
 
void mac_learning_destroy(struct mac_learning *);
 
102
struct mac_learning *mac_learning_ref(const struct mac_learning *);
 
103
void mac_learning_unref(struct mac_learning *);
93
104
 
94
 
void mac_learning_run(struct mac_learning *, struct tag_set *);
95
 
void mac_learning_wait(struct mac_learning *);
 
105
void mac_learning_run(struct mac_learning *ml, struct tag_set *)
 
106
    OVS_REQ_WRLOCK(ml->rwlock);
 
107
void mac_learning_wait(struct mac_learning *ml)
 
108
    OVS_REQ_RDLOCK(ml->rwlock);
96
109
 
97
110
/* Configuration. */
98
 
bool mac_learning_set_flood_vlans(struct mac_learning *,
99
 
                                  const unsigned long *bitmap);
100
 
void mac_learning_set_idle_time(struct mac_learning *, unsigned int idle_time);
101
 
void mac_learning_set_max_entries(struct mac_learning *, size_t max_entries);
 
111
bool mac_learning_set_flood_vlans(struct mac_learning *ml,
 
112
                                  const unsigned long *bitmap)
 
113
    OVS_REQ_WRLOCK(ml->rwlock);
 
114
void mac_learning_set_idle_time(struct mac_learning *ml,
 
115
                                unsigned int idle_time)
 
116
    OVS_REQ_WRLOCK(ml->rwlock);
 
117
void mac_learning_set_max_entries(struct mac_learning *ml, size_t max_entries)
 
118
    OVS_REQ_WRLOCK(ml->rwlock);
102
119
 
103
120
/* Learning. */
104
 
bool mac_learning_may_learn(const struct mac_learning *,
 
121
bool mac_learning_may_learn(const struct mac_learning *ml,
105
122
                            const uint8_t src_mac[ETH_ADDR_LEN],
106
 
                            uint16_t vlan);
107
 
struct mac_entry *mac_learning_insert(struct mac_learning *,
 
123
                            uint16_t vlan)
 
124
    OVS_REQ_RDLOCK(ml->rwlock);
 
125
struct mac_entry *mac_learning_insert(struct mac_learning *ml,
108
126
                                      const uint8_t src[ETH_ADDR_LEN],
109
 
                                      uint16_t vlan);
110
 
tag_type mac_learning_changed(struct mac_learning *, struct mac_entry *);
 
127
                                      uint16_t vlan)
 
128
    OVS_REQ_WRLOCK(ml->rwlock);
 
129
void mac_learning_changed(struct mac_learning *ml, struct mac_entry *e)
 
130
    OVS_REQ_WRLOCK(ml->rwlock);
111
131
 
112
132
/* Lookup. */
113
 
struct mac_entry *mac_learning_lookup(const struct mac_learning *,
 
133
struct mac_entry *mac_learning_lookup(const struct mac_learning *ml,
114
134
                                      const uint8_t dst[ETH_ADDR_LEN],
115
 
                                      uint16_t vlan, tag_type *);
 
135
                                      uint16_t vlan, tag_type *)
 
136
    OVS_REQ_RDLOCK(ml->rwlock);
116
137
 
117
138
/* Flushing. */
118
 
void mac_learning_expire(struct mac_learning *, struct mac_entry *);
119
 
void mac_learning_flush(struct mac_learning *, struct tag_set *);
 
139
void mac_learning_expire(struct mac_learning *ml, struct mac_entry *e)
 
140
    OVS_REQ_WRLOCK(ml->rwlock);
 
141
void mac_learning_flush(struct mac_learning *ml, struct tag_set *)
 
142
    OVS_REQ_WRLOCK(ml->rwlock);
120
143
 
121
144
#endif /* mac-learning.h */