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