Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
padmanarayana committed Jun 18, 2020
1 parent f1123c4 commit 4033024
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions dockers/docker-sflow/port_index_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@
import signal
import traceback
from pyroute2 import IPDB
from pyroute2.iproute import RTM_NEWLINK, RTM_DELLINK
from swsssdk import SonicV2Connector, port_util

RTM_NEWLINK = 16
RTM_DELLINK = 17

PORT_INDEX_TABLE_NAME = 'PORT_INDEX_TABLE'
SYSLOG_IDENTIFIER = 'port_index_mapper'

ipdb = None
state_db = None

def set_port_index_table_entry(key, index, ifindex):
state_db.set(state_db.STATE_DB, key, 'index', index)
state_db.set(state_db.STATE_DB, key, 'ifindex', ifindex)

def interface_callback(ipdb, nlmsg, action):
global state_db

Expand Down Expand Up @@ -54,8 +56,7 @@ def interface_callback(ipdb, nlmsg, action):
_hash = '{}|{}'.format(PORT_INDEX_TABLE_NAME, ifname)

if msgtype == RTM_NEWLINK:
state_db.set(state_db.STATE_DB, _hash, 'index', str(index))
state_db.set(state_db.STATE_DB, _hash, 'ifindex', nlmsg['index'])
set_port_index_table_entry(_hash, str(index), nlmsg['index'])
elif msgtype == RTM_DELLINK:
state_db.delete(state_db.STATE_DB, _hash)

Expand All @@ -80,8 +81,7 @@ def main():
continue
ifindex = ipdb.interfaces[ifname]['index']
_hash = '{}|{}'.format(PORT_INDEX_TABLE_NAME, ifname)
state_db.set(state_db.STATE_DB, _hash, 'index', str(index))
state_db.set(state_db.STATE_DB, _hash, 'ifindex', str(ifindex))
set_port_index_table_entry(_hash, str(index), str(ifindex))

ipdb.register_callback(interface_callback)

Expand Down

0 comments on commit 4033024

Please sign in to comment.