forked from sonic-net/sonic-swss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpfcwdorch.h
More file actions
108 lines (89 loc) · 3.05 KB
/
Copy pathpfcwdorch.h
File metadata and controls
108 lines (89 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#ifndef PFC_WATCHDOG_H
#define PFC_WATCHDOG_H
#include <mutex>
#include <condition_variable>
#include "orch.h"
#include "port.h"
#include "pfcactionhandler.h"
#include "producerstatetable.h"
#include "notificationconsumer.h"
extern "C" {
#include "sai.h"
}
enum class PfcWdAction
{
PFC_WD_ACTION_UNKNOWN,
PFC_WD_ACTION_FORWARD,
PFC_WD_ACTION_DROP,
PFC_WD_ACTION_ALERT,
};
template <typename DropHandler, typename ForwardHandler>
class PfcWdOrch: public Orch
{
public:
PfcWdOrch(DBConnector *db, vector<string> &tableNames);
virtual ~PfcWdOrch(void);
virtual void doTask(Consumer& consumer);
virtual bool startWdOnPort(const Port& port,
uint32_t detectionTime, uint32_t restorationTime, PfcWdAction action) = 0;
virtual bool stopWdOnPort(const Port& port) = 0;
shared_ptr<Table> getCountersTable(void)
{
return m_countersTable;
}
shared_ptr<DBConnector> getCountersDb(void)
{
return m_countersDb;
}
private:
static PfcWdAction deserializeAction(const string& key);
void createEntry(const string& key, const vector<FieldValueTuple>& data);
void deleteEntry(const string& name);
shared_ptr<DBConnector> m_countersDb = nullptr;
shared_ptr<Table> m_countersTable = nullptr;
};
template <typename DropHandler, typename ForwardHandler>
class PfcWdSwOrch: public PfcWdOrch<DropHandler, ForwardHandler>
{
public:
PfcWdSwOrch(
DBConnector *db,
vector<string> &tableNames,
vector<sai_port_stat_t> portStatIds,
vector<sai_queue_stat_t> queueStatIds);
virtual ~PfcWdSwOrch(void);
virtual bool startWdOnPort(const Port& port,
uint32_t detectionTime, uint32_t restorationTime, PfcWdAction action);
virtual bool stopWdOnPort(const Port& port);
//XXX Add port/queue state change event handlers
private:
struct PfcWdQueueEntry
{
PfcWdQueueEntry(
PfcWdAction action,
sai_object_id_t port,
uint8_t idx);
PfcWdAction action = PfcWdAction::PFC_WD_ACTION_UNKNOWN;
sai_object_id_t portId = SAI_NULL_OBJECT_ID;
uint8_t index = 0;
shared_ptr<PfcWdActionHandler> handler = { nullptr };
};
template <typename T>
static string counterIdsToStr(const vector<T> ids, string (*convert)(T));
void registerInWdDb(const Port& port,
uint32_t detectionTime, uint32_t restorationTime, PfcWdAction action);
void unregisterFromWdDb(const Port& port);
void handleWdNotification(swss::NotificationConsumer &wdNotification);
void pfcWatchdogThread(void);
void startWatchdogThread(void);
void endWatchdogThread(void);
map<sai_object_id_t, PfcWdQueueEntry> m_entryMap;
mutex m_pfcWdMutex;
const vector<sai_port_stat_t> c_portStatIds;
const vector<sai_queue_stat_t> c_queueStatIds;
shared_ptr<DBConnector> m_pfcWdDb = nullptr;
shared_ptr<ProducerStateTable> m_pfcWdTable = nullptr;
atomic_bool m_runPfcWdSwOrchThread = { false };
shared_ptr<thread> m_pfcWatchdogThread = nullptr;
};
#endif