|
17 | 17 | from .sff8436 import sff8436InterfaceId # Dot module supports both Python 2 and Python 3 using explicit relative import methods |
18 | 18 | from .sff8436 import sff8436Dom # Dot module supports both Python 2 and Python 3 using explicit relative import methods |
19 | 19 | from .inf8628 import inf8628InterfaceId # Dot module supports both Python 2 and Python 3 using explicit relative import methods |
| 20 | + from portconfig import get_port_config |
| 21 | + from collections import OrderedDict |
| 22 | + from natsort import natsorted |
| 23 | + from sonic_daemon_base.daemon_base import DaemonBase |
| 24 | + import sys |
20 | 25 | except ImportError as e: |
21 | 26 | raise ImportError("%s - required module not found" % str(e)) |
22 | 27 |
|
| 28 | +# Global Variable |
| 29 | +PLATFORM_JSON = 'platform.json' |
| 30 | +PORT_CONFIG_INI = 'portconfig.ini' |
| 31 | + |
23 | 32 | # definitions of the offset and width for values in XCVR info eeprom |
24 | 33 | XCVR_INTFACE_BULK_OFFSET = 0 |
25 | 34 | XCVR_INTFACE_BULK_WIDTH_QSFP = 20 |
@@ -370,14 +379,59 @@ def read_porttab_mappings(self, porttabfile): |
370 | 379 | first = 1 |
371 | 380 | port_pos_in_file = 0 |
372 | 381 | parse_fmt_port_config_ini = False |
| 382 | + parse_fmt_platform_json = False |
| 383 | + |
| 384 | + parse_fmt_port_config_ini = (os.path.basename(porttabfile) == PORT_CONFIG_INI) |
| 385 | + parse_fmt_platform_json = (os.path.basename(porttabfile) == PLATFORM_JSON) |
| 386 | + |
| 387 | + (platform, hwsku) = DaemonBase().get_platform_and_hwsku() |
| 388 | + if(parse_fmt_platform_json): |
| 389 | + ports, _ = get_port_config(hwsku, platform) |
| 390 | + if not ports: |
| 391 | + print('Failed to get port config', file=sys.stderr) |
| 392 | + sys.exit(1) |
| 393 | + else: |
| 394 | + logical_list = [] |
| 395 | + for intf in ports.keys(): |
| 396 | + logical_list.append(intf) |
| 397 | + |
| 398 | + logical = natsorted(logical_list, key=lambda y: y.lower()) |
| 399 | + logical_to_bcm, logical_to_physical, physical_to_logical = OrderedDict(), OrderedDict(), OrderedDict() |
| 400 | + |
| 401 | + for intf_name in logical: |
| 402 | + bcm_port = str(port_pos_in_file) |
| 403 | + logical_to_bcm[intf_name] = "xe"+ bcm_port |
| 404 | + |
| 405 | + if 'index' in ports[intf_name].keys(): |
| 406 | + fp_port_index = ports[intf_name]['index'] |
| 407 | + logical_to_physical[intf_name] = [fp_port_index] |
| 408 | + |
| 409 | + if physical_to_logical.get(fp_port_index) is None: |
| 410 | + physical_to_logical[fp_port_index] = [intf_name] |
| 411 | + else: |
| 412 | + physical_to_logical[fp_port_index].append(intf_name) |
| 413 | + |
| 414 | + port_pos_in_file +=1 |
| 415 | + |
| 416 | + self.logical = logical |
| 417 | + self.logical_to_bcm = logical_to_bcm |
| 418 | + self.logical_to_physical = logical_to_physical |
| 419 | + self.physical_to_logical = physical_to_logical |
| 420 | + |
| 421 | + """ |
| 422 | + print("logical: {}".format(self.logical)) |
| 423 | + print("logical to bcm: {}".format(self.logical_to_bcm)) |
| 424 | + print("logical to physical: {}".format(self.logical_to_physical)) |
| 425 | + print("physical to logical: {}".format( self.physical_to_logical)) |
| 426 | + """ |
| 427 | + return None |
| 428 | + |
373 | 429 |
|
374 | 430 | try: |
375 | 431 | f = open(porttabfile) |
376 | 432 | except: |
377 | 433 | raise |
378 | 434 |
|
379 | | - parse_fmt_port_config_ini = (os.path.basename(porttabfile) == "port_config.ini") |
380 | | - |
381 | 435 | # Read the porttab file and generate dicts |
382 | 436 | # with mapping for future reference. |
383 | 437 | # |
@@ -432,8 +486,7 @@ def read_porttab_mappings(self, porttabfile): |
432 | 486 | if physical_to_logical.get(fp_port_index) is None: |
433 | 487 | physical_to_logical[fp_port_index] = [portname] |
434 | 488 | else: |
435 | | - physical_to_logical[fp_port_index].append( |
436 | | - portname) |
| 489 | + physical_to_logical[fp_port_index].append(portname) |
437 | 490 |
|
438 | 491 | last_fp_port_index = fp_port_index |
439 | 492 | last_portname = portname |
|
0 commit comments