@@ -248,10 +248,10 @@ def convert_ipv4(self, table_name, rule_idx, rule):
248248 rule_props ["IP_PROTOCOL" ] = rule .ip .config .protocol
249249
250250 if rule .ip .config .source_ip_address :
251- rule_props ["SRC_IP" ] = rule .ip .config .source_ip_address
251+ rule_props ["SRC_IP" ] = rule .ip .config .source_ip_address . encode ( "ascii" )
252252
253253 if rule .ip .config .destination_ip_address :
254- rule_props ["DST_IP" ] = rule .ip .config .destination_ip_address
254+ rule_props ["DST_IP" ] = rule .ip .config .destination_ip_address . encode ( "ascii" )
255255
256256 # NOTE: DSCP is available only for MIRROR table
257257 if self .is_table_mirror (table_name ):
@@ -321,7 +321,7 @@ def convert_rule_to_db_schema(self, table_name, rule):
321321 rule_props = {}
322322 rule_data = {(table_name , "RULE_" + str (rule_idx )): rule_props }
323323
324- rule_props ["PRIORITY" ] = self .max_priority - rule_idx
324+ rule_props ["PRIORITY" ] = str ( self .max_priority - rule_idx )
325325
326326 deep_update (rule_props , self .convert_action (table_name , rule_idx , rule ))
327327 deep_update (rule_props , self .convert_l2 (table_name , rule_idx , rule ))
@@ -338,8 +338,8 @@ def deny_rule(self, table_name):
338338 """
339339 rule_props = {}
340340 rule_data = {(table_name , "DEFAULT_RULE" ): rule_props }
341- rule_props ["PRIORITY" ] = self .min_priority
342- rule_props ["ETHER_TYPE" ] = self .ethertype_map ["ETHERTYPE_IPV4" ]
341+ rule_props ["PRIORITY" ] = str ( self .min_priority )
342+ rule_props ["ETHER_TYPE" ] = str ( self .ethertype_map ["ETHERTYPE_IPV4" ])
343343 rule_props ["PACKET_ACTION" ] = "DROP"
344344 return rule_data
345345
@@ -349,7 +349,7 @@ def convert_rules(self):
349349 :return:
350350 """
351351 for acl_set_name in self .yang_acl .acl .acl_sets .acl_set :
352- table_name = acl_set_name .replace (" " , "_" ).replace ("-" , "_" ).upper ()
352+ table_name = acl_set_name .replace (" " , "_" ).replace ("-" , "_" ).upper (). encode ( 'ascii' )
353353 acl_set = self .yang_acl .acl .acl_sets .acl_set [acl_set_name ]
354354
355355 if not self .is_table_valid (table_name ):
@@ -385,23 +385,54 @@ def incremental_update(self):
385385 modifications.
386386 :return:
387387 """
388+
389+ # TODO: Until we test ASIC behavior, we cannot assume that we can insert
390+ # dataplane ACLs and shift existing ACLs. Therefore, we perform a full
391+ # update on dataplane ACLs, and only perform an incremental update on
392+ # control plane ACLs.
393+
388394 new_rules = set (self .rules_info .iterkeys ())
395+ new_dataplane_rules = set ()
396+ new_controlplane_rules = set ()
389397 current_rules = set (self .rules_db_info .iterkeys ())
398+ current_dataplane_rules = set ()
399+ current_controlplane_rules = set ()
390400
391- added_rules = new_rules .difference (current_rules )
392- removed_rules = current_rules .difference (new_rules )
393- existing_rules = new_rules .intersection (current_rules )
401+ for key in new_rules :
402+ table_name = key [0 ]
403+ if self .tables_db_info [table_name ]['type' ].upper () == self .ACL_TABLE_TYPE_CTRLPLANE :
404+ new_controlplane_rules .add (key )
405+ else :
406+ new_dataplane_rules .add (key )
407+
408+ for key in current_rules :
409+ table_name = key [0 ]
410+ if self .tables_db_info [table_name ]['type' ].upper () == self .ACL_TABLE_TYPE_CTRLPLANE :
411+ current_controlplane_rules .add (key )
412+ else :
413+ current_dataplane_rules .add (key )
394414
395- for key in removed_rules :
415+ # Remove all existing dataplane rules
416+ for key in current_dataplane_rules :
396417 self .configdb .mod_entry (self .ACL_RULE , key , None )
397418
398- for key in added_rules :
419+ # Add all new dataplane rules
420+ for key in new_dataplane_rules :
399421 self .configdb .mod_entry (self .ACL_RULE , key , self .rules_info [key ])
400422
401- for key in existing_rules :
402- if cmp (self .rules_info [key ], self .rules_db_info [key ]):
403- self .configdb .mod_entry (self .ACL_RULE , key , None )
404- self .configdb .mod_entry (self .ACL_RULE , key , self .rules_info [key ])
423+ added_controlplane_rules = new_controlplane_rules .difference (current_controlplane_rules )
424+ removed_controlplane_rules = current_controlplane_rules .difference (new_controlplane_rules )
425+ existing_controlplane_rules = new_rules .intersection (current_controlplane_rules )
426+
427+ for key in added_controlplane_rules :
428+ self .configdb .mod_entry (self .ACL_RULE , key , self .rules_info [key ])
429+
430+ for key in removed_controlplane_rules :
431+ self .configdb .mod_entry (self .ACL_RULE , key , None )
432+
433+ for key in existing_controlplane_rules :
434+ if cmp (self .rules_info [key ], self .rules_db_info [key ]) != 0 :
435+ self .configdb .set_entry (self .ACL_RULE , key , self .rules_info [key ])
405436
406437
407438 def delete (self , table = None , rule = None ):
0 commit comments