@@ -1054,7 +1054,7 @@ bool AclTable::validate()
1054
1054
// Control plane ACLs are handled by a separate process
1055
1055
if (type == ACL_TABLE_UNKNOWN || type == ACL_TABLE_CTRLPLANE) return false ;
1056
1056
if (stage == ACL_STAGE_UNKNOWN) return false ;
1057
- if (portSet.empty ()) return false ;
1057
+ if (portSet.empty () && pendingPortSet. empty () ) return false ;
1058
1058
1059
1059
return true ;
1060
1060
}
@@ -1177,6 +1177,50 @@ bool AclTable::create()
1177
1177
return status == SAI_STATUS_SUCCESS;
1178
1178
}
1179
1179
1180
+ void AclTable::update (SubjectType type, void *cntx)
1181
+ {
1182
+ SWSS_LOG_ENTER ();
1183
+
1184
+ // Only interested in port change
1185
+ if (type != SUBJECT_TYPE_PORT_CHANGE)
1186
+ {
1187
+ return ;
1188
+ }
1189
+
1190
+ PortUpdate *update = static_cast <PortUpdate *>(cntx);
1191
+
1192
+ Port &port = update->port ;
1193
+ if (update->add )
1194
+ {
1195
+ if (pendingPortSet.find (port.m_alias ) != pendingPortSet.end ())
1196
+ {
1197
+ sai_object_id_t bind_port_id;
1198
+ if (gPortsOrch ->getAclBindPortId (port.m_alias , bind_port_id))
1199
+ {
1200
+ link (bind_port_id);
1201
+ bind (bind_port_id);
1202
+
1203
+ pendingPortSet.erase (port.m_alias );
1204
+ portSet.emplace (port.m_alias );
1205
+
1206
+ SWSS_LOG_NOTICE (" Bound port %s to ACL table %s" ,
1207
+ port.m_alias .c_str (), id.c_str ());
1208
+ }
1209
+ else
1210
+ {
1211
+ SWSS_LOG_ERROR (" Failed to get port %s bind port ID" ,
1212
+ port.m_alias .c_str ());
1213
+ return ;
1214
+ }
1215
+ }
1216
+ }
1217
+ else
1218
+ {
1219
+ // TODO: deal with port removal scenario
1220
+ }
1221
+ }
1222
+
1223
+ // TODO: make bind/unbind symmetric
1180
1224
bool AclTable::bind (sai_object_id_t portOid)
1181
1225
{
1182
1226
SWSS_LOG_ENTER ();
@@ -1737,7 +1781,9 @@ void AclOrch::init(vector<TableConnector>& connectors, PortsOrch *portOrch, Mirr
1737
1781
throw " AclOrch initialization failure" ;
1738
1782
}
1739
1783
1784
+ // Attach observers
1740
1785
m_mirrorOrch->attach (this );
1786
+ gPortsOrch ->attach (this );
1741
1787
1742
1788
// Should be initialized last to guaranty that object is
1743
1789
// initialized before thread start.
@@ -1798,18 +1844,30 @@ void AclOrch::update(SubjectType type, void *cntx)
1798
1844
{
1799
1845
SWSS_LOG_ENTER ();
1800
1846
1801
- if (type != SUBJECT_TYPE_MIRROR_SESSION_CHANGE && type != SUBJECT_TYPE_INT_SESSION_CHANGE)
1847
+ if (type != SUBJECT_TYPE_MIRROR_SESSION_CHANGE &&
1848
+ type != SUBJECT_TYPE_INT_SESSION_CHANGE &&
1849
+ type != SUBJECT_TYPE_PORT_CHANGE)
1802
1850
{
1851
+ SWSS_LOG_WARN (" Received unwanted change update %d" , type);
1803
1852
return ;
1804
1853
}
1805
1854
1806
1855
unique_lock<mutex> lock (m_countersMutex);
1807
1856
1808
- for (const auto & table : m_AclTables)
1857
+ // ACL table deals with port change
1858
+ // ACL rule deals with mirror session change and int session change
1859
+ for (auto & table : m_AclTables)
1809
1860
{
1810
- for ( auto & rule : table. second . rules )
1861
+ if (type == SUBJECT_TYPE_PORT_CHANGE )
1811
1862
{
1812
- rule.second ->update (type, cntx);
1863
+ table.second .update (type, cntx);
1864
+ }
1865
+ else
1866
+ {
1867
+ for (auto & rule : table.second .rules )
1868
+ {
1869
+ rule.second ->update (type, cntx);
1870
+ }
1813
1871
}
1814
1872
}
1815
1873
}
@@ -1835,11 +1893,6 @@ void AclOrch::doTask(Consumer &consumer)
1835
1893
unique_lock<mutex> lock (m_countersMutex);
1836
1894
doAclRuleTask (consumer);
1837
1895
}
1838
- else if (table_name == STATE_LAG_TABLE_NAME)
1839
- {
1840
- unique_lock<mutex> lock (m_countersMutex);
1841
- doAclTablePortUpdateTask (consumer);
1842
- }
1843
1896
else
1844
1897
{
1845
1898
SWSS_LOG_ERROR (" Invalid table %s" , table_name.c_str ());
@@ -1857,20 +1910,22 @@ bool AclOrch::addAclTable(AclTable &newTable, string table_id)
1857
1910
/* If ACL table exists, remove the table first.*/
1858
1911
if (!removeAclTable (table_id))
1859
1912
{
1860
- SWSS_LOG_ERROR (" Fail to remove the exsiting ACL table %s when try to add the new one." , table_id.c_str ());
1913
+ SWSS_LOG_ERROR (" Failed to remove exsiting ACL table %s before adding the new one" ,
1914
+ table_id.c_str ());
1861
1915
return false ;
1862
1916
}
1863
1917
}
1864
1918
1865
1919
if (createBindAclTable (newTable, table_oid))
1866
1920
{
1867
1921
m_AclTables[table_oid] = newTable;
1868
- SWSS_LOG_NOTICE (" Successfully created ACL table %s, oid: %lX" , newTable.description .c_str (), table_oid);
1922
+ SWSS_LOG_NOTICE (" Created ACL table %s oid:%lx" ,
1923
+ newTable.id .c_str (), table_oid);
1869
1924
return true ;
1870
1925
}
1871
1926
else
1872
1927
{
1873
- SWSS_LOG_ERROR (" Failed to create table %s" , table_id.c_str ());
1928
+ SWSS_LOG_ERROR (" Failed to create ACL table %s" , table_id.c_str ());
1874
1929
return false ;
1875
1930
}
1876
1931
}
@@ -1968,20 +2023,18 @@ void AclOrch::doAclTableTask(Consumer &consumer)
1968
2023
{
1969
2024
if (!processAclTableType (attr_value, newTable.type ))
1970
2025
{
1971
- SWSS_LOG_ERROR (" Failed to process table type for table %s" , table_id.c_str ());
2026
+ SWSS_LOG_ERROR (" Failed to process ACL table %s type" ,
2027
+ table_id.c_str ());
1972
2028
bAllAttributesOk = false ;
1973
2029
break ;
1974
2030
}
1975
2031
}
1976
2032
else if (attr_name == TABLE_PORTS)
1977
2033
{
1978
- bool suc = processPorts (newTable, attr_value, [&](sai_object_id_t portOid) {
1979
- newTable.link (portOid);
1980
- });
1981
-
1982
- if (!suc)
2034
+ if (!processAclTablePorts (attr_value, newTable))
1983
2035
{
1984
- SWSS_LOG_ERROR (" Failed to process table ports for table %s" , table_id.c_str ());
2036
+ SWSS_LOG_ERROR (" Failed to process ACL table %s ports" ,
2037
+ table_id.c_str ());
1985
2038
bAllAttributesOk = false ;
1986
2039
break ;
1987
2040
}
@@ -1990,7 +2043,8 @@ void AclOrch::doAclTableTask(Consumer &consumer)
1990
2043
{
1991
2044
if (!processAclTableStage (attr_value, newTable.stage ))
1992
2045
{
1993
- SWSS_LOG_ERROR (" Failed to process table stage for table %s" , table_id.c_str ());
2046
+ SWSS_LOG_ERROR (" Failed to process ACL table %s stage" ,
2047
+ table_id.c_str ());
1994
2048
bAllAttributesOk = false ;
1995
2049
break ;
1996
2050
}
@@ -2013,7 +2067,8 @@ void AclOrch::doAclTableTask(Consumer &consumer)
2013
2067
else
2014
2068
{
2015
2069
it = consumer.m_toSync .erase (it);
2016
- SWSS_LOG_ERROR (" Failed to create ACL table. Table configuration is invalid" );
2070
+ SWSS_LOG_ERROR (" Failed to create ACL table %s, invalid configuration" ,
2071
+ table_id.c_str ());
2017
2072
}
2018
2073
}
2019
2074
else if (op == DEL_COMMAND)
@@ -2120,140 +2175,41 @@ void AclOrch::doAclRuleTask(Consumer &consumer)
2120
2175
}
2121
2176
}
2122
2177
2123
- void AclOrch::doAclTablePortUpdateTask (Consumer &consumer )
2178
+ bool AclOrch::processAclTablePorts (string portList, AclTable &aclTable )
2124
2179
{
2125
2180
SWSS_LOG_ENTER ();
2126
2181
2127
- auto it = consumer.m_toSync .begin ();
2128
- while (it != consumer.m_toSync .end ())
2129
- {
2130
- KeyOpFieldsValuesTuple t = it->second ;
2131
- string key = kfvKey (t);
2132
- size_t found = key.find (consumer.getConsumerTable ()->getTableNameSeparator ().c_str ());
2133
- string port_alias = key.substr (0 , found);
2134
- string op = kfvOp (t);
2135
-
2136
- SWSS_LOG_INFO (" doAclTablePortUpdateTask: OP: %s, port_alias: %s" , op.c_str (), port_alias.c_str ());
2137
-
2138
- if (op == SET_COMMAND)
2139
- {
2140
- for (auto itmap : m_AclTables)
2141
- {
2142
- auto table = itmap.second ;
2143
- if (table.pendingPortSet .find (port_alias) != table.pendingPortSet .end ())
2144
- {
2145
- 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 ());
2146
-
2147
- bool suc = processPendingPort (table, port_alias, [&](sai_object_id_t portOid) {
2148
- table.link (portOid);
2149
- });
2182
+ auto port_list = tokenize (portList, ' ,' );
2183
+ set<string> ports (port_list.begin (), port_list.end ());
2150
2184
2151
- if (!suc)
2152
- {
2153
- SWSS_LOG_ERROR (" Failed to bind the ACL table: %s to port: %s" , table.description .c_str (), port_alias.c_str ());
2154
- }
2155
- else
2156
- {
2157
- table.pendingPortSet .erase (port_alias);
2158
- SWSS_LOG_DEBUG (" port: %s bound to ACL table table: %s, remove it from pending list" , port_alias.c_str (), table.description .c_str ());
2159
- }
2160
- }
2161
- }
2162
- }
2163
- else if (op == DEL_COMMAND)
2164
- {
2165
- for (auto itmap : m_AclTables)
2166
- {
2167
- auto table = itmap.second ;
2168
- if (table.portSet .find (port_alias) != table.portSet .end ())
2169
- {
2170
- /* TODO: update the ACL table after port/lag deleted*/
2171
- table.pendingPortSet .emplace (port_alias);
2172
- SWSS_LOG_INFO (" Add deleted port: %s to the pending list of ACL table: %s" , port_alias.c_str (), table.description .c_str ());
2173
- }
2174
- }
2175
- }
2176
- else
2177
- {
2178
- SWSS_LOG_ERROR (" Unknown operation type %s" , op.c_str ());
2179
- }
2180
- it = consumer.m_toSync .erase (it);
2181
- }
2182
- }
2183
-
2184
- bool AclOrch::processPorts (AclTable &aclTable, string portsList, std::function<void (sai_object_id_t )> inserter)
2185
- {
2186
- SWSS_LOG_ENTER ();
2187
-
2188
- vector<string> strList;
2189
-
2190
- SWSS_LOG_DEBUG (" Processing ACL table port list %s" , portsList.c_str ());
2191
-
2192
- split (portsList, strList, ' ,' );
2193
-
2194
- set<string> strSet (strList.begin (), strList.end ());
2195
- aclTable.portSet = strSet;
2196
-
2197
- if (strList.size () != strSet.size ())
2198
- {
2199
- SWSS_LOG_ERROR (" Failed to process port list. Duplicate port entry" );
2200
- return false ;
2201
- }
2202
-
2203
- if (strList.empty ())
2185
+ // TODO: Support adding ports afterwards
2186
+ if (ports.empty ())
2204
2187
{
2205
- SWSS_LOG_ERROR (" Failed to process port list. List is empty " );
2188
+ SWSS_LOG_ERROR (" Failed to process empty port list" );
2206
2189
return false ;
2207
2190
}
2208
2191
2209
- for (const auto & alias : strList )
2192
+ for (auto alias : ports )
2210
2193
{
2211
- sai_object_id_t port_id;
2212
2194
Port port;
2213
2195
if (!gPortsOrch ->getPort (alias, port))
2214
2196
{
2215
- SWSS_LOG_INFO (" Port %s not configured yet, add it to ACL table %s pending list" , alias.c_str (), aclTable.description .c_str ());
2197
+ SWSS_LOG_INFO (" Add unready port %s to pending list for ACL table %s" ,
2198
+ alias.c_str (), aclTable.id .c_str ());
2216
2199
aclTable.pendingPortSet .emplace (alias);
2217
2200
continue ;
2218
2201
}
2219
2202
2220
- if (gPortsOrch ->getAclBindPortId (alias, port_id))
2203
+ sai_object_id_t bind_port_id;
2204
+ if (!gPortsOrch ->getAclBindPortId (alias, bind_port_id))
2221
2205
{
2222
- inserter (port_id);
2223
- }
2224
- else
2225
- {
2226
- return false ;
2206
+ SWSS_LOG_ERROR (" Failed to get port %s bind port ID for ACL table %s" ,
2207
+ alias.c_str (), aclTable.id .c_str ());
2208
+ continue ;
2227
2209
}
2228
- }
2229
-
2230
- return true ;
2231
- }
2232
-
2233
- bool AclOrch::processPendingPort (AclTable &aclTable, string portAlias, std::function<void (sai_object_id_t )> inserter)
2234
- {
2235
- SWSS_LOG_ENTER ();
2236
-
2237
- SWSS_LOG_DEBUG (" Processing ACL table port %s" , portAlias.c_str ());
2238
2210
2239
- sai_object_id_t port_id;
2240
-
2241
- Port port;
2242
- if (!gPortsOrch ->getPort (portAlias, port))
2243
- {
2244
- SWSS_LOG_INFO (" Port %s not configured yet, add it to ACL table %s pending list" , portAlias.c_str (), aclTable.description .c_str ());
2245
- aclTable.pendingPortSet .insert (portAlias);
2246
- return true ;
2247
- }
2248
-
2249
- if (gPortsOrch ->getAclBindPortId (portAlias, port_id))
2250
- {
2251
- inserter (port_id);
2252
- aclTable.bind (port_id);
2253
- }
2254
- else
2255
- {
2256
- return false ;
2211
+ aclTable.link (bind_port_id);
2212
+ aclTable.portSet .emplace (alias);
2257
2213
}
2258
2214
2259
2215
return true ;
@@ -2292,8 +2248,6 @@ bool AclOrch::processAclTableStage(string stage, acl_stage_type_t &acl_stage)
2292
2248
return true ;
2293
2249
}
2294
2250
2295
-
2296
-
2297
2251
sai_object_id_t AclOrch::getTableById (string table_id)
2298
2252
{
2299
2253
SWSS_LOG_ENTER ();
@@ -2320,7 +2274,8 @@ bool AclOrch::createBindAclTable(AclTable &aclTable, sai_object_id_t &table_oid)
2320
2274
sai_status_t status = bindAclTable (table_oid, aclTable);
2321
2275
if (status != SAI_STATUS_SUCCESS)
2322
2276
{
2323
- SWSS_LOG_ERROR (" Failed to bind table %s to ports" , aclTable.description .c_str ());
2277
+ SWSS_LOG_ERROR (" Failed to bind table %s to ports" ,
2278
+ aclTable.id .c_str ());
2324
2279
return false ;
2325
2280
}
2326
2281
return true ;
@@ -2333,7 +2288,8 @@ sai_status_t AclOrch::deleteUnbindAclTable(sai_object_id_t table_oid)
2333
2288
2334
2289
if ((status = bindAclTable (table_oid, m_AclTables[table_oid], false )) != SAI_STATUS_SUCCESS)
2335
2290
{
2336
- SWSS_LOG_ERROR (" Failed to unbind table %s" , m_AclTables[table_oid].description .c_str ());
2291
+ SWSS_LOG_ERROR (" Failed to unbind table %s" ,
2292
+ m_AclTables[table_oid].id .c_str ());
2337
2293
return status;
2338
2294
}
2339
2295
0 commit comments