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

feat: Add command to generate skeleton for Barq strategy #15

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions barq-common/create_strategy.sh
Copy link
Collaborator

Choose a reason for hiding this comment

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

This change is missing an inclusion line in lib.rs, causing it to fail to compile.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe we should also include some usage instructions, at least mentioning it in the README.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This script doesn't add the strategy to barq-plugin crate for routing, so it remains unused.

Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash

capitalize() {
echo "$1" | awk '{print toupper(substr($0,1,1)) tolower(substr($0,2))}'
}

script_dir=$(dirname "$(realpath "$0")")

mkdir -p "$script_dir/src/algorithms"

read -p "Enter the name of your strategy: " script_name

capitalized_script_name=$(capitalize "$script_name")

if [ -f "$script_dir/src/algorithms/${script_name}.rs" ]; then
echo "Error: $script_dir/src/algorithms/${script_name}.rs already exists."
exit 1
fi

cat <<EOL > "$script_dir/src/algorithms/${script_name}.rs"
use anyhow::Result;

use crate::strategy::{RouteHop, RouteInput, RouteOutput, Strategy};

const DEFAULT_DELAY: u64 = 9;

pub struct $capitalized_script_name;

impl $capitalized_script_name {
pub fn new() -> Self {
$capitalized_script_name
}
}

impl Default for $capitalized_script_name {
fn default() -> Self {
$capitalized_script_name::new()
}
}

impl Strategy for $capitalized_script_name {
fn can_apply(&self, input: &RouteInput) -> Result<bool> {
// TODO: implement logic which checks if this strategy can be applied to given network graph
Copy link
Collaborator

Choose a reason for hiding this comment

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

These will cause compilation errors. The function returns Result<bool>, so we need to return Ok(true) in the template.

}

fn route(&self, input: &RouteInput) -> Result<RouteOutput> {
// TODO: implement routing algorithm
}
Comment on lines +46 to +48
Copy link
Collaborator

Choose a reason for hiding this comment

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

same here

}

#[cfg(test)]
mod tests {
use super::*;
use crate::{
graph::{Edge, NetworkGraph, Node},
strategy::Router,
};

#[test]
fn test_direct_routing() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you should modify this too?

// TODO: write tests for $capitalized_script_name strategy
}
}
EOL

echo "Strategy ${script_name} created in $script_dir/src/algorithms/${script_name}.rs"
Loading