Matteo Scandolo | a229eca | 2017-08-08 13:05:28 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
Jeffrey Townsend | fdea52c | 2013-12-10 18:20:11 -0800 | [diff] [blame] | 17 | """ |
| 18 | Platform configuration file |
| 19 | platform == bpp |
| 20 | """ |
| 21 | |
| 22 | ############################################################################### |
| 23 | # |
| 24 | # This platform assumes BPP VPI specifications on the command line. |
| 25 | # |
| 26 | ############################################################################### |
| 27 | |
| 28 | import sys |
| 29 | import os |
| 30 | import argparse |
| 31 | import subprocess |
| 32 | import dppv |
| 33 | |
| 34 | # The port specification is passed via the "--platform-args" option to OFTest. |
| 35 | # Note that we must guard against abbreviations supported by argparse |
| 36 | if not "--platform-args" in " ".join(sys.argv): |
| 37 | raise Exception("--platform-args must be specified") |
| 38 | |
| 39 | ap = argparse.ArgumentParser("bpp") |
| 40 | ap.add_argument("--platform-args") |
| 41 | (ops, rest) = ap.parse_known_args() |
| 42 | |
| 43 | if not "@" in ops.platform_args: |
| 44 | # Assume it is just a device name. Get the ports from the track database. |
| 45 | if "," in ops.platform_args: |
| 46 | (type_, d) = ops.platform_args.split(",") |
| 47 | else: |
| 48 | (type_, d) = ("udp", ops.platform_args) |
| 49 | |
| 50 | trackScript = "/usr/bin/track" |
| 51 | if not os.path.exists(trackScript): |
| 52 | raise Exception("Cannot find the track script (looked at %s" % trackScript) |
| 53 | |
| 54 | ports = eval("[" + subprocess.check_output([trackScript, "getports", d]) + "]") |
| 55 | ops.platform_args = type_ + "," + ",".join( "%s@%s:%s" % (p, d, p) for p in ports) |
| 56 | |
| 57 | print "new platform_args: ", ops.platform_args |
| 58 | exit; |
| 59 | # |
| 60 | ############################################################################### |
| 61 | |
| 62 | vpi_port_map = {} |
| 63 | ports = ops.platform_args.split(",") |
| 64 | bpptype = "udp" |
| 65 | if ports[0] == "udp" or ports[0] == "tcp": |
| 66 | bpptype = ports.pop(0) |
| 67 | |
| 68 | for ps in ports: |
| 69 | (p, vpi) = ps.split("@") |
| 70 | vpi_port_map[int(p)] = "bpp|%s|%s" % (bpptype, vpi) |
| 71 | |
| 72 | print vpi_port_map; |
| 73 | |
| 74 | def platform_config_update(config): |
| 75 | """ |
| 76 | Update configuration for the remote platform |
| 77 | |
| 78 | @param config The configuration dictionary to use/update |
| 79 | This routine defines the port map used for this configuration |
| 80 | """ |
| 81 | |
| 82 | global vpi_port_map |
| 83 | config["port_map"] = vpi_port_map.copy() |
| 84 | config["caps_table_idx"] = 0 |
| 85 | # |
| 86 | # The class for DataPlanePorts must be specified here: |
| 87 | # |
| 88 | config['dataplane'] = { 'portclass': dppv.DataPlanePortVPI } |
| 89 | config['allow_user'] = True |