Skip to content

Commit

Permalink
Added more comments on logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
abdosi committed Jul 25, 2020
1 parent fbfc4a7 commit 9410398
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions files/image_config/caclmgrd/caclmgrd
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ try:
import subprocess
import sys
import syslog

import sonic_device_util
from swsscommon import swsscommon
from swsssdk import SonicDBConfig, ConfigDBConnector
Expand Down Expand Up @@ -448,28 +449,41 @@ class ControlPlaneAclManager(object):
def run(self):
# Select Time-out for 10 Seconds
SELECT_TIMEOUT_MS = 1000 * 10
# Initlaize Global config that loads all database*.json
swsscommon.SonicDBConfig.initializeGlobalConfig()
# Create the Select object
sel = swsscommon.Select()
# Map of Namespace <--> susbcriber table's object
config_db_subscriber_table_map = {}
# Loop through all asic namespaces (if present) and host (namespace='')
for namespace in self.config_db_map.keys():
# Unconditionally update control plane ACLs once at start
# Unconditionally update control plane ACLs once at start on given namespace
self.update_control_plane_acls(namespace)

# Connect to Config DB of given namespace
acl_db_connector = swsscommon.DBConnector("CONFIG_DB", 0, False, namespace)
# Subscribe to notifications when ACL tables changes
subscribe_acl_table = swsscommon.SubscriberStateTable(acl_db_connector, swsscommon.CFG_ACL_TABLE_TABLE_NAME)
# Subscribe to notifications when ACL rule tables changes
subscribe_acl_rule_table = swsscommon.SubscriberStateTable(acl_db_connector, swsscommon.CFG_ACL_RULE_TABLE_NAME)
# Add both tables to the selectable object
sel.addSelectable(subscribe_acl_table)
sel.addSelectable(subscribe_acl_rule_table)
# Update the map
config_db_subscriber_table_map[namespace] = []
config_db_subscriber_table_map[namespace].append(subscribe_acl_table)
config_db_subscriber_table_map[namespace].append(subscribe_acl_rule_table)
#Loop on select to see if any event happen on config db of any namespace
while True:
(state, c) = sel.select(SELECT_TIMEOUT_MS)
# Continue if select is timeout or selectable object is not return
if state != swsscommon.Select.OBJECT:
continue
# Get the corresponding namespace from selectable object
namespace = c.getDbNamespace()
# Pop data of both Subscriber Table object of namespace that got config db acl table event
for table in config_db_subscriber_table_map[namespace]:
table.pop()
# Update the Control Plane ACL of the namespace that got config db acl table event
self.update_control_plane_acls(namespace)

# ============================= Functions =============================
Expand Down

0 comments on commit 9410398

Please sign in to comment.