Jeffrey Townsend | fdea52c | 2013-12-10 18:20:11 -0800 | [diff] [blame] | 1 | """ |
| 2 | Platform configuration file |
| 3 | platform == bpp |
| 4 | """ |
| 5 | |
| 6 | ############################################################################### |
| 7 | # |
| 8 | # This platform assumes BPP VPI specifications on the command line. |
| 9 | # |
| 10 | ############################################################################### |
| 11 | |
| 12 | import sys |
| 13 | import os |
| 14 | import argparse |
| 15 | import subprocess |
| 16 | import dppv |
| 17 | |
| 18 | # The port specification is passed via the "--platform-args" option to OFTest. |
| 19 | # Note that we must guard against abbreviations supported by argparse |
| 20 | if not "--platform-args" in " ".join(sys.argv): |
| 21 | raise Exception("--platform-args must be specified") |
| 22 | |
| 23 | ap = argparse.ArgumentParser("bpp") |
| 24 | ap.add_argument("--platform-args") |
| 25 | (ops, rest) = ap.parse_known_args() |
| 26 | |
| 27 | if not "@" in ops.platform_args: |
| 28 | # Assume it is just a device name. Get the ports from the track database. |
| 29 | if "," in ops.platform_args: |
| 30 | (type_, d) = ops.platform_args.split(",") |
| 31 | else: |
| 32 | (type_, d) = ("udp", ops.platform_args) |
| 33 | |
| 34 | trackScript = "/usr/bin/track" |
| 35 | if not os.path.exists(trackScript): |
| 36 | raise Exception("Cannot find the track script (looked at %s" % trackScript) |
| 37 | |
| 38 | ports = eval("[" + subprocess.check_output([trackScript, "getports", d]) + "]") |
| 39 | ops.platform_args = type_ + "," + ",".join( "%s@%s:%s" % (p, d, p) for p in ports) |
| 40 | |
| 41 | print "new platform_args: ", ops.platform_args |
| 42 | exit; |
| 43 | # |
| 44 | ############################################################################### |
| 45 | |
| 46 | vpi_port_map = {} |
| 47 | ports = ops.platform_args.split(",") |
| 48 | bpptype = "udp" |
| 49 | if ports[0] == "udp" or ports[0] == "tcp": |
| 50 | bpptype = ports.pop(0) |
| 51 | |
| 52 | for ps in ports: |
| 53 | (p, vpi) = ps.split("@") |
| 54 | vpi_port_map[int(p)] = "bpp|%s|%s" % (bpptype, vpi) |
| 55 | |
| 56 | print vpi_port_map; |
| 57 | |
| 58 | def platform_config_update(config): |
| 59 | """ |
| 60 | Update configuration for the remote platform |
| 61 | |
| 62 | @param config The configuration dictionary to use/update |
| 63 | This routine defines the port map used for this configuration |
| 64 | """ |
| 65 | |
| 66 | global vpi_port_map |
| 67 | config["port_map"] = vpi_port_map.copy() |
| 68 | config["caps_table_idx"] = 0 |
| 69 | # |
| 70 | # The class for DataPlanePorts must be specified here: |
| 71 | # |
| 72 | config['dataplane'] = { 'portclass': dppv.DataPlanePortVPI } |
| 73 | config['allow_user'] = True |