4
4
#include < utility>
5
5
#include < exception>
6
6
7
+ #include " sai_serialize.h"
7
8
#include " orch.h"
8
9
#include " logger.h"
9
10
#include " swssnet.h"
10
11
#include " converter.h"
11
12
#include " mirrororch.h"
12
13
13
- #define MIRROR_SESSION_STATUS " status"
14
- #define MIRROR_SESSION_STATUS_ACTIVE " active"
15
- #define MIRROR_SESSION_STATUS_INACTIVE " inactive"
16
- #define MIRROR_SESSION_SRC_IP " src_ip"
17
- #define MIRROR_SESSION_DST_IP " dst_ip"
18
- #define MIRROR_SESSION_GRE_TYPE " gre_type"
19
- #define MIRROR_SESSION_DSCP " dscp"
20
- #define MIRROR_SESSION_TTL " ttl"
21
- #define MIRROR_SESSION_QUEUE " queue"
14
+ #define MIRROR_SESSION_STATUS " status"
15
+ #define MIRROR_SESSION_STATUS_ACTIVE " active"
16
+ #define MIRROR_SESSION_STATUS_INACTIVE " inactive"
17
+ #define MIRROR_SESSION_SRC_IP " src_ip"
18
+ #define MIRROR_SESSION_DST_IP " dst_ip"
19
+ #define MIRROR_SESSION_GRE_TYPE " gre_type"
20
+ #define MIRROR_SESSION_DSCP " dscp"
21
+ #define MIRROR_SESSION_TTL " ttl"
22
+ #define MIRROR_SESSION_QUEUE " queue"
23
+ #define MIRROR_SESSION_DST_MAC_ADDRESS " dst_mac"
24
+ #define MIRROR_SESSION_MONITOR_PORT " monitor_port"
25
+ #define MIRROR_SESSION_ROUTE_PREFIX " route_prefix"
26
+ #define MIRROR_SESSION_VLAN_HEADER_VALID " vlan_header_valid"
22
27
23
28
#define MIRROR_SESSION_DEFAULT_VLAN_PRI 0
24
29
#define MIRROR_SESSION_DEFAULT_VLAN_CFI 0
@@ -56,14 +61,14 @@ MirrorEntry::MirrorEntry(const string& platform) :
56
61
nexthopInfo.prefix = IpPrefix (" 0.0.0.0/0" );
57
62
}
58
63
59
- MirrorOrch::MirrorOrch (TableConnector appDbConnector , TableConnector confDbConnector,
64
+ MirrorOrch::MirrorOrch (TableConnector stateDbConnector , TableConnector confDbConnector,
60
65
PortsOrch *portOrch, RouteOrch *routeOrch, NeighOrch *neighOrch, FdbOrch *fdbOrch) :
61
66
Orch(confDbConnector.first, confDbConnector.second),
62
67
m_portsOrch(portOrch),
63
68
m_routeOrch(routeOrch),
64
69
m_neighOrch(neighOrch),
65
70
m_fdbOrch(fdbOrch),
66
- m_mirrorTableProducer(appDbConnector .first, appDbConnector .second)
71
+ m_mirrorTable(stateDbConnector .first, stateDbConnector .second)
67
72
{
68
73
m_portsOrch->attach (this );
69
74
m_neighOrch->attach (this );
@@ -121,7 +126,7 @@ bool MirrorOrch::sessionExists(const string& name)
121
126
return m_syncdMirrors.find (name) != m_syncdMirrors.end ();
122
127
}
123
128
124
- bool MirrorOrch::getSessionState (const string& name, bool & state)
129
+ bool MirrorOrch::getSessionStatus (const string& name, bool & state)
125
130
{
126
131
SWSS_LOG_ENTER ();
127
132
@@ -294,22 +299,45 @@ void MirrorOrch::deleteEntry(const string& name)
294
299
SWSS_LOG_NOTICE (" Removed mirror session %s" , name.c_str ());
295
300
}
296
301
297
- bool MirrorOrch::setSessionState (const string& name, MirrorEntry& session)
302
+ void MirrorOrch::setSessionState (const string& name, const MirrorEntry& session, const string& attr )
298
303
{
299
304
SWSS_LOG_ENTER ();
300
305
301
306
SWSS_LOG_INFO (" Setting mirroring sessions %s state\n " , name.c_str ());
302
307
303
308
vector<FieldValueTuple> fvVector;
309
+ string value;
310
+ if (attr.empty () || attr == MIRROR_SESSION_STATUS)
311
+ {
312
+ value = session.status ? MIRROR_SESSION_STATUS_ACTIVE : MIRROR_SESSION_STATUS_INACTIVE;
313
+ fvVector.emplace_back (MIRROR_SESSION_STATUS, value);
314
+ }
304
315
305
- string status = session.status ? MIRROR_SESSION_STATUS_ACTIVE : MIRROR_SESSION_STATUS_INACTIVE;
316
+ if (attr.empty () || attr == MIRROR_SESSION_MONITOR_PORT)
317
+ {
318
+ value = sai_serialize_object_id (session.neighborInfo .portId );
319
+ fvVector.emplace_back (MIRROR_SESSION_MONITOR_PORT, value);
320
+ }
306
321
307
- FieldValueTuple t (MIRROR_SESSION_STATUS, status);
308
- fvVector.push_back (t);
322
+ if (attr.empty () || attr == MIRROR_SESSION_DST_MAC_ADDRESS)
323
+ {
324
+ value = session.neighborInfo .mac .to_string ();
325
+ fvVector.emplace_back (MIRROR_SESSION_DST_MAC_ADDRESS, value);
326
+ }
309
327
310
- m_mirrorTableProducer.set (name, fvVector);
328
+ if (attr.empty () || attr == MIRROR_SESSION_ROUTE_PREFIX)
329
+ {
330
+ value = session.nexthopInfo .prefix .to_string ();
331
+ fvVector.emplace_back (MIRROR_SESSION_ROUTE_PREFIX, value);
332
+ }
311
333
312
- return true ;
334
+ if (attr.empty () || attr == MIRROR_SESSION_VLAN_HEADER_VALID)
335
+ {
336
+ value = to_string (session.neighborInfo .port .m_type == Port::VLAN);
337
+ fvVector.emplace_back (MIRROR_SESSION_VLAN_HEADER_VALID, value);
338
+ }
339
+
340
+ m_mirrorTable.set (name, fvVector);
313
341
}
314
342
315
343
bool MirrorOrch::getNeighborInfo (const string& name, MirrorEntry& session)
@@ -533,11 +561,7 @@ bool MirrorOrch::activateSession(const string& name, MirrorEntry& session)
533
561
}
534
562
535
563
session.status = true ;
536
-
537
- if (!setSessionState (name, session))
538
- {
539
- throw runtime_error (" Failed to test session state" );
540
- }
564
+ setSessionState (name, session);
541
565
542
566
MirrorSessionUpdate update = { name, true };
543
567
notify (SUBJECT_TYPE_MIRROR_SESSION_CHANGE, static_cast <void *>(&update));
@@ -566,10 +590,8 @@ bool MirrorOrch::deactivateSession(const string& name, MirrorEntry& session)
566
590
567
591
session.status = false ;
568
592
569
- if (!setSessionState (name, session))
570
- {
571
- throw runtime_error (" Failed to test session state" );
572
- }
593
+ // Store whole state into StateDB, since it is far from that frequent it's durable
594
+ setSessionState (name, session);
573
595
574
596
SWSS_LOG_NOTICE (" Deactive mirror session %s" , name.c_str ());
575
597
@@ -597,6 +619,8 @@ bool MirrorOrch::updateSessionDstMac(const string& name, MirrorEntry& session)
597
619
SWSS_LOG_NOTICE (" Update mirror session %s destination MAC to %s" ,
598
620
name.c_str (), session.neighborInfo .mac .to_string ().c_str ());
599
621
622
+ setSessionState (name, session, MIRROR_SESSION_DST_MAC_ADDRESS);
623
+
600
624
return true ;
601
625
}
602
626
@@ -625,6 +649,7 @@ bool MirrorOrch::updateSessionDstPort(const string& name, MirrorEntry& session)
625
649
SWSS_LOG_NOTICE (" Update mirror session %s monitor port to %s" ,
626
650
name.c_str (), port.m_alias .c_str ());
627
651
652
+ setSessionState (name, session, MIRROR_SESSION_MONITOR_PORT);
628
653
629
654
return true ;
630
655
}
@@ -682,6 +707,8 @@ bool MirrorOrch::updateSessionType(const string& name, MirrorEntry& session)
682
707
SWSS_LOG_NOTICE (" Update mirror session %s VLAN to %s" ,
683
708
name.c_str (), session.neighborInfo .port .m_alias .c_str ());
684
709
710
+ setSessionState (name, session, MIRROR_SESSION_VLAN_HEADER_VALID);
711
+
685
712
return true ;
686
713
}
687
714
@@ -705,6 +732,8 @@ void MirrorOrch::updateNextHop(const NextHopUpdate& update)
705
732
706
733
session.nexthopInfo .prefix = update.prefix ;
707
734
735
+ setSessionState (name, session, MIRROR_SESSION_ROUTE_PREFIX);
736
+
708
737
// This is the ECMP scenario that the new next hop group contains the previous
709
738
// next hop. There is no need to update this session's monitor port.
710
739
if (update.nexthopGroup != IpAddresses () &&
0 commit comments