Commit d82cfc23 authored by Michal Wasiak's avatar Michal Wasiak Committed by Adam Wujek

snmp: add helper functions to read data from rtu

Added functions were copied from rtu_stat
Signed-off-by: 's avatarMichal Wasiak <michal.wasiak@gmail.com>
parent 0633d243
......@@ -244,3 +244,94 @@ void init_shm(void){
sleep(1);
}
}
int shmem_rtu_read_vlans(struct rtu_vlan_table_entry *vlan_tab_local)
{
unsigned ii;
unsigned retries = 0;
struct rtu_vlan_table_entry *vlan_tab_shm;
struct rtu_shmem_header *rtu_hdr;
rtu_hdr = (void *)rtud_head + rtud_head->data_off;
vlan_tab_shm = wrs_shm_follow(rtud_head, rtu_hdr->vlans);
if (!vlan_tab_shm)
return -2;
/* read data, with the sequential lock to have all data consistent */
while (1) {
ii = wrs_shm_seqbegin(rtud_head);
memcpy(vlan_tab_local, vlan_tab_shm,
NUM_VLANS * sizeof(*vlan_tab_shm));
retries++;
if (retries > 100)
return -1;
if (!wrs_shm_seqretry(rtud_head, ii))
break; /* consistent read */
usleep(1000);
}
return 0;
}
/* Read filtes from rtud's shm, convert hashtable to regular table */
int shmem_rtu_read_htab(struct rtu_filtering_entry *rtu_htab_local, int *read_entries)
{
unsigned ii;
unsigned retries = 0;
struct rtu_filtering_entry *htab_shm;
struct rtu_shmem_header *rtu_hdr;
struct rtu_filtering_entry *empty;
rtu_hdr = (void *)rtud_head + rtud_head->data_off;
htab_shm = wrs_shm_follow(rtud_head, rtu_hdr->filters);
if (!htab_shm)
return -2;
/* Read data, with the sequential lock to have all data consistent */
while (1) {
ii = wrs_shm_seqbegin(rtud_head);
memcpy(rtu_htab_local, htab_shm,
RTU_BUCKETS * HTAB_ENTRIES * sizeof(*htab_shm));
retries++;
if (retries > 100)
return -1;
if (!wrs_shm_seqretry(rtud_head, ii))
break; /* consistent read */
usleep(1000);
}
/* Convert hash table to ordered table. Table will be qsorted later,
* no need to qsort entire table */
*read_entries = 0;
empty = rtu_htab_local;
for (ii = 0; ii < RTU_BUCKETS * HTAB_ENTRIES; ii++) {
if (rtu_htab_local[ii].valid) {
memcpy(empty, &rtu_htab_local[ii], sizeof(*htab_shm));
empty++;
(*read_entries)++;
}
}
return 0;
}
/* Compare entries by by MAC */
int cmp_rtu_entries_mac(const void *p1, const void *p2)
{
const struct rtu_filtering_entry *e1 = p1;
const struct rtu_filtering_entry *e2 = p2;
return memcmp(e1->mac, e2->mac, 6);
}
/* Compare rtu entries by FID then by MAC */
int cmp_rtu_entries_fid_mac(const void *p1, const void *p2)
{
const struct rtu_filtering_entry *e1 = p1;
const struct rtu_filtering_entry *e2 = p2;
if (e1->fid > e2->fid)
return 1;
else if (e1->fid < e2->fid)
return -1;
return memcmp(e1->mac, e2->mac, 6);
}
......@@ -21,11 +21,18 @@ extern parentDS_t *ppsi_parentDS;
extern defaultDS_t *ppsi_defaultDS;
/* RTUd */
struct wrs_shm_head *rtud_head;
extern struct wrs_shm_head *rtud_head;
void init_shm();
int shmem_ready_hald(void);
int shmem_ready_ppsi(void);
int shmem_ready_rtud(void);
int shmem_rtu_read_htab(struct rtu_filtering_entry *rtu_htab_local, int *read_entries);
int shmem_rtu_read_vlans(struct rtu_vlan_table_entry *vlan_tab_local);
/* Compare entries by by MAC */
int cmp_rtu_entries_mac(const void *p1, const void *p2);
/* Compare rtu entries by FID then by MAC */
int cmp_rtu_entries_fid_mac(const void *p1, const void *p2);
#endif /* WRS_SNMP_SHMEM_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment