Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the Tofino model source code as a package in the open P4Studio #65

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ add_subdirectory(${BF_PKG_DIR}/bf-drivers)
#compiler/model
include(FindP4CModel)
add_subdirectory(${BF_PKG_DIR}/p4-compilers)
add_subdirectory(${BF_PKG_DIR}/tofino-model)

if(ASIC AND BSP)
#platform
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ sudo ${SDE_INSTALL}/bin/veth_setup.sh 128

* bridge
* libcli
* libcrafter
* thrift
* grpc

Expand Down
7 changes: 6 additions & 1 deletion p4studio/dependencies/dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ packages:
dependencies: [boost]
type: source
libcli:
attributes: {version: 1.10.4}
attributes: {url: 'https://github.com/dparrish/libcli.git', version: 1.10.4}
tags: [default, source]
type: source
pi:
Expand All @@ -354,3 +354,8 @@ packages:
tags: [default, source]
dependencies: [boost]
type: source
libcrafter:
attributes: {url: 'https://github.com/pellegre/libcrafter.git', version: master}
tags: [default, source]
dependencies: [libcli]
type: source
55 changes: 55 additions & 0 deletions p4studio/dependencies/source/install_libcrafter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright (C) 2024 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
#
# SPDX-License-Identifier: Apache-2.0

from os.path import join, exists
from pathlib import Path

from dependencies.source.source_dependency_config import SourceDependencyConfig
from utils.processes import execute

import os

def download_libcrafter(config: SourceDependencyConfig) -> None:
version = config.dependency_manager().source_dependency_attributes("libcrafter")['version']
repo_dir = config.download_dir(ensure_exists=False)
if not repo_dir.exists():
execute("git clone https://github.com/pellegre/libcrafter.git {}".format(repo_dir))
execute("git -c advice.detachedHead=false checkout {}".format(version), repo_dir)


def install_libcrafter(config: SourceDependencyConfig) -> None:
version = config.dependency_manager().source_dependency_attributes("libcrafter")['version']

if not config.force and _is_libcrafter_installed(config.install_dir, version):
return

download_libcrafter(config)
build_dir = config.build_dir(copy_download_dir=True)
build_dir = build_dir / 'libcrafter'

# Set the environment variable
env = os.environ.copy()
env['LDFLAGS'] = "-Wl,-s"

execute("./autogen.sh", build_dir)
execute("./configure --prefix={}".format(config.install_dir), build_dir)
execute('make PREFIX={} install -j{}'.format(config.install_dir, config.jobs), build_dir)
execute("sudo ldconfig")


def _is_libcrafter_installed(path: Path, version: str) -> bool:
return (path / "lib/libcrafter.so.{}".format(version)).exists()
2 changes: 2 additions & 0 deletions p4studio/dependencies/source/source_dependency_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from dependencies.source.install_bridge_utils import install_bridge_utils
from dependencies.source.install_grpc import install_grpc
from dependencies.source.install_libcli import install_libcli
from dependencies.source.install_libcrafter import install_libcrafter
from dependencies.source.install_pi import install_pi
from dependencies.source.install_thrift import install_thrift
from dependencies.source.source_dependency_config import SourceDependencyConfig
Expand All @@ -27,6 +28,7 @@

_DEP_TO_FUNC = {
"libcli": install_libcli,
"libcrafter": install_libcrafter,
"pi": install_pi,
"boost": install_boost,
"grpc": install_grpc,
Expand Down
2 changes: 1 addition & 1 deletion p4studio/profile/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def _set_field(self, path: str, value: object) -> None:
nested_set(self.raw, path, value)

def _calculate_source_packages(self) -> List[str]:
result = ['bridge', 'libcli']
result = ['bridge', 'libcli', 'libcrafter']

if any([
self.config_options().get('thrift-driver', True),
Expand Down
2 changes: 1 addition & 1 deletion p4studio/workspace/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def bsp_path(self) -> Optional[Path]:
pass

def package_installation_script(self, name: str) -> Path:
if name in ['boost', 'grpc', 'libcli', 'pi', 'thrift']:
if name in ['boost', 'grpc', 'libcli', 'libcrafter', 'pi', 'thrift']:
return self.p4studio_path / 'dependencies/source/install_{}.py'.format(name)
elif name == 'bridge':
return self.p4studio_path / 'dependencies/source/install_bridge_utils.py'
Expand Down
32 changes: 16 additions & 16 deletions pkgsrc/switch-p4-16/api/common/pal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1803,14 +1803,14 @@ switch_status_t speed_set(switch_object_id_t port_handle,
port_lane_list.v_set(lane_list);
status = switch_store::attribute_set(port_handle, port_lane_list);
if (status != SWITCH_STATUS_SUCCESS) {
switch_log(SWITCH_API_LEVEL_ERROR,
SWITCH_OBJECT_TYPE_PORT,
"{}.{}: lane_list failure port_handle {} speed {} status {}",
__func__,
__LINE__,
port_handle,
port_lane_list,
status);
// switch_log(SWITCH_API_LEVEL_ERROR,
// SWITCH_OBJECT_TYPE_PORT,
// "{}.{}: lane_list failure port_handle {} speed {} status {}",
// __func__,
// __LINE__,
// port_handle,
// port_lane_list,
// status);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to merge this PR with this code commented out? Or perhaps wrap them all in an #ifdef SOME_NEW_SYMBOL_NAME with the same symbol name as each other, to make them easier to grep and find later when someone wants to update all of these calls? I guess marking them all with an identical unique string in a comment works for that, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will remove these changes later. But I need them to build on Ubuntu 24.04, which is the distribution I am currently using.

The problem is that this code doesn't compile with newer version of GCC/CLang, which enforce the C++ standard correctly.

}

switch_enum_t _link_pause = {0};
Expand Down Expand Up @@ -3526,14 +3526,14 @@ switch_status_t after_port_create(const switch_object_id_t object_id,
port_lane_list.v_set(lane_list);
status = switch_store::attribute_set(object_id, port_lane_list);
if (status != SWITCH_STATUS_SUCCESS) {
switch_log(SWITCH_API_LEVEL_ERROR,
SWITCH_OBJECT_TYPE_PORT,
"{}.{}: lane_list failure port_handle {} speed {} status {}",
__func__,
__LINE__,
object_id,
port_lane_list,
status);
// switch_log(SWITCH_API_LEVEL_ERROR,
// SWITCH_OBJECT_TYPE_PORT,
// "{}.{}: lane_list failure port_handle {} speed {} status {}",
// __func__,
// __LINE__,
// object_id,
// port_lane_list,
// status);
}

status |= switch_store::v_get(device_hdl, SWITCH_DEVICE_ATTR_DEV_ID, device);
Expand Down
124 changes: 62 additions & 62 deletions pkgsrc/switch-p4-16/api/common/qos_pdfixed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3024,15 +3024,15 @@ static void update_internal_ppg(const switch_object_id_t object_id,
switch_status_t temp_status = SWITCH_STATUS_SUCCESS;
temp_status = switch_store::attribute_set(object_id, attr);
if (temp_status != SWITCH_STATUS_SUCCESS) {
switch_log(SWITCH_API_LEVEL_ERROR,
SWITCH_OBJECT_TYPE_PORT_PRIORITY_GROUP,
"{}.{}: Failure to update internal ppg {} attr {}"
"status {}",
__func__,
__LINE__,
object_id,
attr,
temp_status);
// switch_log(SWITCH_API_LEVEL_ERROR,
// SWITCH_OBJECT_TYPE_PORT_PRIORITY_GROUP,
// "{}.{}: Failure to update internal ppg {} attr {}"
// "status {}",
// __func__,
// __LINE__,
// object_id,
// attr,
// temp_status);
}
status.set_value(temp_status);
return;
Expand Down Expand Up @@ -3152,16 +3152,16 @@ switch_status_t before_ppg_create_add_internal_ports_ppg(
internal_ppg_create.join();
status = ppg_status.get();
if (status != SWITCH_STATUS_SUCCESS) {
switch_log(SWITCH_API_LEVEL_ERROR,
SWITCH_OBJECT_TYPE_PORT_PRIORITY_GROUP,
"{}:{}: Failed to add internal ppg for port {} corresponding "
"to external port {} with attrs {}",
__func__,
__LINE__,
port,
port_handle,
attrs,
status);
// switch_log(SWITCH_API_LEVEL_ERROR,
// SWITCH_OBJECT_TYPE_PORT_PRIORITY_GROUP,
// "{}:{}: Failed to add internal ppg for port {} corresponding "
// "to external port {} with attrs {}",
// __func__,
// __LINE__,
// port,
// port_handle,
// attrs,
// status);
goto cleanup;
}
switch_object_id_t internal_ppg_handle{oid.get()};
Expand Down Expand Up @@ -3236,17 +3236,17 @@ switch_status_t before_ppg_update_update_internal_ports_ppg(
if (ppg_handle.data) ppg_handles.push_back(ppg_handle);
}
if (status != SWITCH_STATUS_SUCCESS) {
switch_log(SWITCH_API_LEVEL_ERROR,
SWITCH_OBJECT_TYPE_PORT_PRIORITY_GROUP,
"{}.{}: Failure to update attr {} for internal ppgs "
"corresponding to external port {} ppg {}"
"status {}",
__func__,
__LINE__,
attr,
port_handle,
object_id,
status);
// switch_log(SWITCH_API_LEVEL_ERROR,
// SWITCH_OBJECT_TYPE_PORT_PRIORITY_GROUP,
// "{}.{}: Failure to update attr {} for internal ppgs "
// "corresponding to external port {} ppg {}"
// "status {}",
// __func__,
// __LINE__,
// attr,
// port_handle,
// object_id,
// status);
}
if (ppg_handles.empty()) return status;
// Attribute Set
Expand All @@ -3259,17 +3259,17 @@ switch_status_t before_ppg_update_update_internal_ports_ppg(
status |= update_status.get();
}
if (status != SWITCH_STATUS_SUCCESS) {
switch_log(SWITCH_API_LEVEL_ERROR,
SWITCH_OBJECT_TYPE_PORT_PRIORITY_GROUP,
"{}.{}: Failure to update attr {} for internal ppgs "
"corresponding to external port {} ppg {}"
"status {}",
__func__,
__LINE__,
attr,
port_handle,
object_id,
status);
// switch_log(SWITCH_API_LEVEL_ERROR,
// SWITCH_OBJECT_TYPE_PORT_PRIORITY_GROUP,
// "{}.{}: Failure to update attr {} for internal ppgs "
// "corresponding to external port {} ppg {}"
// "status {}",
// __func__,
// __LINE__,
// attr,
// port_handle,
// object_id,
// status);
}
return status;
}
Expand Down Expand Up @@ -3297,17 +3297,17 @@ switch_status_t after_scheduler_added_to_queue(
queue_handle);
}
if (status != SWITCH_STATUS_SUCCESS) {
switch_log(SWITCH_API_LEVEL_ERROR,
SWITCH_OBJECT_TYPE_QUEUE,
"{}.{}: Failure to update attr {} for a queue {} "
"corresponding to port {}"
"status {}",
__func__,
__LINE__,
attr,
queue_handle,
port_handle,
status);
// switch_log(SWITCH_API_LEVEL_ERROR,
// SWITCH_OBJECT_TYPE_QUEUE,
// "{}.{}: Failure to update attr {} for a queue {} "
// "corresponding to port {}"
// "status {}",
// __func__,
// __LINE__,
// attr,
// queue_handle,
// port_handle,
// status);
}
}
return status;
Expand Down Expand Up @@ -3361,16 +3361,16 @@ switch_status_t before_scheduler_removed_from_queue(
0 /* min_rate */);

if (status != SWITCH_STATUS_SUCCESS) {
switch_log(SWITCH_API_LEVEL_ERROR,
SWITCH_OBJECT_TYPE_QUEUE,
"{}.{}: Failure to detach scheduler from a queue {} "
"corresponding to port {}"
"status {}",
__func__,
__LINE__,
queue_handle,
port_handle,
status);
// switch_log(SWITCH_API_LEVEL_ERROR,
// SWITCH_OBJECT_TYPE_QUEUE,
// "{}.{}: Failure to detach scheduler from a queue {} "
// "corresponding to port {}"
// "status {}",
// __func__,
// __LINE__,
// queue_handle,
// port_handle,
// status);
}
}
}
Expand Down
32 changes: 16 additions & 16 deletions pkgsrc/switch-p4-16/s3/bf_rt_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1335,12 +1335,12 @@ switch_status_t _ActionEntry::set_arg(const bf_rt_field_id_t field_id,
return bf_rt_status_xlate(rc);
}

SWITCH_DEBUG_LOG(switch_log(
SWITCH_API_LEVEL_DEBUG,
SWITCH_OT_NONE,
"arg: {} -> {}",
dataFieldNameGetInternal(table, field_id, _action_id, indirect),
key));
// SWITCH_DEBUG_LOG(switch_log(
// SWITCH_API_LEVEL_DEBUG,
// SWITCH_OT_NONE,
// "arg: {} -> {}",
// dataFieldNameGetInternal(table, field_id, _action_id, indirect),
// key));
return status;
}

Expand Down Expand Up @@ -1412,16 +1412,16 @@ switch_status_t _ActionEntry::set_arg(const bf_rt_field_id_t field_id,

rc = table_data->setValue(field_id, key);
if (rc != BF_SUCCESS) {
switch_log(SWITCH_API_LEVEL_ERROR,
SWITCH_OT_NONE,
"{}.{}:{}: rc: {} failed setValue: \"{}.{}\" key {}",
__NS__,
__func__,
__LINE__,
bf_err_str(rc),
tableNameGetInternal(table),
dataFieldNameGetInternal(table, field_id, _action_id, indirect),
key);
// switch_log(SWITCH_API_LEVEL_ERROR,
// SWITCH_OT_NONE,
// "{}.{}:{}: rc: {} failed setValue: \"{}.{}\" key {}",
// __NS__,
// __func__,
// __LINE__,
// bf_err_str(rc),
// tableNameGetInternal(table),
// dataFieldNameGetInternal(table, field_id, _action_id, indirect),
// key);
return bf_rt_status_xlate(rc);
}
return status;
Expand Down
Loading