blob: ba4e99ab98c8ef3bdf42d0ab1d8469d961387481 [file] [log] [blame]
Matteo Scandoloa229eca2017-08-08 13:05:28 -07001
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 Townsendfdea52c2013-12-10 18:20:11 -080017"""
18Platform configuration file
19platform == bpp
20"""
21
22###############################################################################
23#
24# This platform assumes BPP VPI specifications on the command line.
25#
26###############################################################################
27
28import sys
29import os
30import argparse
31import subprocess
32import 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
36if not "--platform-args" in " ".join(sys.argv):
37 raise Exception("--platform-args must be specified")
38
39ap = argparse.ArgumentParser("bpp")
40ap.add_argument("--platform-args")
41(ops, rest) = ap.parse_known_args()
42
43if 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
62vpi_port_map = {}
63ports = ops.platform_args.split(",")
64bpptype = "udp"
65if ports[0] == "udp" or ports[0] == "tcp":
66 bpptype = ports.pop(0)
67
68for ps in ports:
69 (p, vpi) = ps.split("@")
70 vpi_port_map[int(p)] = "bpp|%s|%s" % (bpptype, vpi)
71
72print vpi_port_map;
73
74def 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