@@ -936,7 +936,7 @@ bool AclTable::validate()
936
936
{
937
937
// Control plane ACLs are handled by a separate process
938
938
if (type == ACL_TABLE_UNKNOWN || type == ACL_TABLE_CTRLPLANE) return false ;
939
- if (ports .empty ()) return false ;
939
+ if (portSet .empty ()) return false ;
940
940
return true ;
941
941
}
942
942
@@ -1361,8 +1361,8 @@ bool AclRange::remove()
1361
1361
return true ;
1362
1362
}
1363
1363
1364
- AclOrch::AclOrch (DBConnector *db, vector<string> tableNames , PortsOrch *portOrch, MirrorOrch *mirrorOrch, NeighOrch *neighOrch, RouteOrch *routeOrch) :
1365
- Orch(db, tableNames ),
1364
+ AclOrch::AclOrch (vector<TableConnector>& connectors , PortsOrch *portOrch, MirrorOrch *mirrorOrch, NeighOrch *neighOrch, RouteOrch *routeOrch) :
1365
+ Orch(connectors ),
1366
1366
m_mirrorOrch(mirrorOrch),
1367
1367
m_neighOrch(neighOrch),
1368
1368
m_routeOrch(routeOrch)
@@ -1445,6 +1445,11 @@ void AclOrch::doTask(Consumer &consumer)
1445
1445
unique_lock<mutex> lock (m_countersMutex);
1446
1446
doAclRuleTask (consumer);
1447
1447
}
1448
+ else if (table_name == STATE_LAG_TABLE_NAME)
1449
+ {
1450
+ unique_lock<mutex> lock (m_countersMutex);
1451
+ doAclTablePortUpdateTask (consumer);
1452
+ }
1448
1453
else
1449
1454
{
1450
1455
SWSS_LOG_ERROR (" Invalid table %s" , table_name.c_str ());
@@ -1545,7 +1550,7 @@ void AclOrch::doAclTableTask(Consumer &consumer)
1545
1550
{
1546
1551
KeyOpFieldsValuesTuple t = it->second ;
1547
1552
string key = kfvKey (t);
1548
- size_t found = key.find (' | ' );
1553
+ size_t found = key.find (consumer. getConsumerTable ()-> getTableNameSeparator (). c_str () );
1549
1554
string table_id = key.substr (0 , found);
1550
1555
string op = kfvOp (t);
1551
1556
@@ -1580,7 +1585,7 @@ void AclOrch::doAclTableTask(Consumer &consumer)
1580
1585
}
1581
1586
else if (attr_name == TABLE_PORTS)
1582
1587
{
1583
- bool suc = processPorts (attr_value, [&](sai_object_id_t portOid) {
1588
+ bool suc = processPorts (newTable, attr_value, [&](sai_object_id_t portOid) {
1584
1589
newTable.link (portOid);
1585
1590
});
1586
1591
@@ -1645,7 +1650,7 @@ void AclOrch::doAclRuleTask(Consumer &consumer)
1645
1650
{
1646
1651
KeyOpFieldsValuesTuple t = it->second ;
1647
1652
string key = kfvKey (t);
1648
- size_t found = key.find (' | ' );
1653
+ size_t found = key.find (consumer. getConsumerTable ()-> getTableNameSeparator (). c_str () );
1649
1654
string table_id = key.substr (0 , found);
1650
1655
string rule_id = key.substr (found + 1 );
1651
1656
string op = kfvOp (t);
@@ -1725,17 +1730,79 @@ void AclOrch::doAclRuleTask(Consumer &consumer)
1725
1730
}
1726
1731
}
1727
1732
1728
- bool AclOrch::processPorts (string portsList, std::function<void (sai_object_id_t )> inserter)
1733
+ void AclOrch::doAclTablePortUpdateTask (Consumer &consumer)
1734
+ {
1735
+ SWSS_LOG_ENTER ();
1736
+
1737
+ auto it = consumer.m_toSync .begin ();
1738
+ while (it != consumer.m_toSync .end ())
1739
+ {
1740
+ KeyOpFieldsValuesTuple t = it->second ;
1741
+ string key = kfvKey (t);
1742
+ size_t found = key.find (consumer.getConsumerTable ()->getTableNameSeparator ().c_str ());
1743
+ string port_alias = key.substr (0 , found);
1744
+ string op = kfvOp (t);
1745
+
1746
+ SWSS_LOG_INFO (" doAclTablePortUpdateTask: OP: %s, port_alias: %s" , op.c_str (), port_alias.c_str ());
1747
+
1748
+ if (op == SET_COMMAND)
1749
+ {
1750
+ for (auto itmap : m_AclTables)
1751
+ {
1752
+ auto table = itmap.second ;
1753
+ if (table.pendingPortSet .find (port_alias) != table.pendingPortSet .end ())
1754
+ {
1755
+ SWSS_LOG_INFO (" found the port: %s in ACL table: %s pending port list, bind it to ACL table." , port_alias.c_str (), table.description .c_str ());
1756
+
1757
+ bool suc = processPendingPort (table, port_alias, [&](sai_object_id_t portOid) {
1758
+ table.link (portOid);
1759
+ });
1760
+
1761
+ if (!suc)
1762
+ {
1763
+ SWSS_LOG_ERROR (" Failed to bind the ACL table: %s to port: %s" , table.description .c_str (), port_alias.c_str ());
1764
+ }
1765
+ else
1766
+ {
1767
+ table.pendingPortSet .erase (port_alias);
1768
+ SWSS_LOG_DEBUG (" port: %s bound to ACL table table: %s, remove it from pending list" , port_alias.c_str (), table.description .c_str ());
1769
+ }
1770
+ }
1771
+ }
1772
+ }
1773
+ else if (op == DEL_COMMAND)
1774
+ {
1775
+ for (auto itmap : m_AclTables)
1776
+ {
1777
+ auto table = itmap.second ;
1778
+ if (table.portSet .find (port_alias) != table.portSet .end ())
1779
+ {
1780
+ /* TODO: update the ACL table after port/lag deleted*/
1781
+ table.pendingPortSet .emplace (port_alias);
1782
+ SWSS_LOG_INFO (" Add deleted port: %s to the pending list of ACL table: %s" , port_alias.c_str (), table.description .c_str ());
1783
+ }
1784
+ }
1785
+ }
1786
+ else
1787
+ {
1788
+ SWSS_LOG_ERROR (" Unknown operation type %s" , op.c_str ());
1789
+ }
1790
+ it = consumer.m_toSync .erase (it);
1791
+ }
1792
+ }
1793
+
1794
+ bool AclOrch::processPorts (AclTable &aclTable, string portsList, std::function<void (sai_object_id_t )> inserter)
1729
1795
{
1730
1796
SWSS_LOG_ENTER ();
1731
1797
1732
1798
vector<string> strList;
1733
1799
1734
- SWSS_LOG_INFO (" Processing ACL table port list %s" , portsList.c_str ());
1800
+ SWSS_LOG_DEBUG (" Processing ACL table port list %s" , portsList.c_str ());
1735
1801
1736
1802
split (portsList, strList, ' ,' );
1737
1803
1738
1804
set<string> strSet (strList.begin (), strList.end ());
1805
+ aclTable.portSet = strSet;
1739
1806
1740
1807
if (strList.size () != strSet.size ())
1741
1808
{
@@ -1751,33 +1818,52 @@ bool AclOrch::processPorts(string portsList, std::function<void (sai_object_id_t
1751
1818
1752
1819
for (const auto & alias : strList)
1753
1820
{
1821
+ sai_object_id_t port_id;
1754
1822
Port port;
1755
1823
if (!gPortsOrch ->getPort (alias, port))
1756
1824
{
1757
- SWSS_LOG_ERROR (" Failed to process port. Port %s doesn't exist" , alias.c_str ());
1758
- return false ;
1825
+ SWSS_LOG_INFO (" Port %s not configured yet, add it to ACL table %s pending list" , alias.c_str (), aclTable.description .c_str ());
1826
+ aclTable.pendingPortSet .emplace (alias);
1827
+ continue ;
1759
1828
}
1760
1829
1761
- switch (port. m_type )
1830
+ if ( gPortsOrch -> getAclBindPortId (alias, port_id) )
1762
1831
{
1763
- case Port::PHY:
1764
- if (port.m_lag_member_id != SAI_NULL_OBJECT_ID)
1765
- {
1766
- SWSS_LOG_ERROR (" Failed to process port. Bind table to LAG member %s is not allowed" , alias.c_str ());
1767
- return false ;
1768
- }
1769
- inserter (port.m_port_id );
1770
- break ;
1771
- case Port::LAG:
1772
- inserter (port.m_lag_id );
1773
- break ;
1774
- case Port::VLAN:
1775
- inserter (port.m_vlan_info .vlan_oid );
1776
- break ;
1777
- default :
1778
- SWSS_LOG_ERROR (" Failed to process port. Incorrect port %s type %d" , alias.c_str (), port.m_type );
1779
- return false ;
1780
- }
1832
+ inserter (port_id);
1833
+ }
1834
+ else
1835
+ {
1836
+ return false ;
1837
+ }
1838
+ }
1839
+
1840
+ return true ;
1841
+ }
1842
+
1843
+ bool AclOrch::processPendingPort (AclTable &aclTable, string portAlias, std::function<void (sai_object_id_t )> inserter)
1844
+ {
1845
+ SWSS_LOG_ENTER ();
1846
+
1847
+ SWSS_LOG_DEBUG (" Processing ACL table port %s" , portAlias.c_str ());
1848
+
1849
+ sai_object_id_t port_id;
1850
+
1851
+ Port port;
1852
+ if (!gPortsOrch ->getPort (portAlias, port))
1853
+ {
1854
+ SWSS_LOG_INFO (" Port %s not configured yet, add it to ACL table %s pending list" , portAlias.c_str (), aclTable.description .c_str ());
1855
+ aclTable.pendingPortSet .insert (portAlias);
1856
+ return true ;
1857
+ }
1858
+
1859
+ if (gPortsOrch ->getAclBindPortId (portAlias, port_id))
1860
+ {
1861
+ inserter (port_id);
1862
+ aclTable.bind (port_id);
1863
+ }
1864
+ else
1865
+ {
1866
+ return false ;
1781
1867
}
1782
1868
1783
1869
return true ;
@@ -1894,18 +1980,14 @@ sai_status_t AclOrch::bindAclTable(sai_object_id_t table_oid, AclTable &aclTable
1894
1980
sai_status_t status = SAI_STATUS_SUCCESS;
1895
1981
1896
1982
SWSS_LOG_INFO (" %s table %s to ports" , bind ? " Bind" : " Unbind" , aclTable.id .c_str ());
1897
-
1983
+
1898
1984
if (aclTable.ports .empty ())
1899
1985
{
1900
1986
if (bind)
1901
1987
{
1902
- SWSS_LOG_ERROR (" Port list is not configured for %s table" , aclTable.id .c_str ());
1903
- return SAI_STATUS_FAILURE;
1904
- }
1905
- else
1906
- {
1907
- return SAI_STATUS_SUCCESS;
1988
+ SWSS_LOG_WARN (" Binding port list is empty for %s table" , aclTable.id .c_str ());
1908
1989
}
1990
+ return SAI_STATUS_SUCCESS;
1909
1991
}
1910
1992
1911
1993
if (bind)
0 commit comments