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

Tests v1 #24

Merged
merged 15 commits into from
Nov 14, 2023
22 changes: 22 additions & 0 deletions .github/workflows/lint-go.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Go Checks

on:
pull_request: {}
push:
branches:
- main

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.21'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.54
25 changes: 25 additions & 0 deletions .github/workflows/test-go.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Go Tests

on:
pull_request: {}
push:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.21.x'
- name: Install dependencies
run: go mod tidy
- name: Test Go Source Code with Coverage
run: go test ./... -race -coverprofile=coverage.out -covermode=atomic
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
.DS_Store
*.swp
.vscode/

.VSCodeCounter
out
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ all: go-gen build ## Build the entire project
install-deps: ## Install development dependencies
sudo apt install -y protobuf-compiler
go install honnef.co/go/tools/cmd/staticcheck@latest
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.55.2
go install google.golang.org/protobuf/cmd/[email protected]
go install google.golang.org/grpc/cmd/[email protected]
sudo apt install clang clang-format llvm gcc libbpf-dev libelf-dev make linux-headers-$(uname -r)
Expand Down
46 changes: 24 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
# HawkWing
The wings which brings your packets to the destination

## Configuration
```yaml
---
hawkeye:
hostname: hawkeye.hawk.net
port: 1234
port: 5001
services:
wb.hawk.net:
- intent: high-bandwidth
port: 80
sid:
- fcbb:bb00:1::2
- fcbb:bb00:3::2
- intent: low-bandwidth
port: 8080
wc.hawk.net:
- intent: high-bandwidth
port: 1433
sid:
- fcbb:bb00:2::2
- fcbb:bb00:4::2
```

```
bpftool net show
bpftool prog tracelog
trace add virtio-input 10
mount --make-shared /sys/fs/bpf
service1:
domain_name: service1.hawk.net
applications:
- port: 80
intents:
- intent: sfc
functions:
- function1
- function2
sid:
- fcbb:bb00:1::2
- fcbb:bb00:3::2
service2:
domain_name: service2.hawk.net
applications:
- port: 80
intents:
- intent: low-latency
min_value: 10
max_value: 20
```

## Development Network
![Development Network](docs/network.png)
Binary file added docs/network.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions internal/test/suite.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package test

import (
"log"
"testing"

"github.com/hawkv6/hawkwing/internal/config"
)

const testConfigPath = "../../test_assets/test_config.yaml"

func SetupTestConfig(tb testing.TB) {
config.GetInstance().SetConfigFile(testConfigPath)
if err := config.Parse(); err != nil {
log.Fatalln(err)
}
}
29 changes: 29 additions & 0 deletions pkg/bpf/bpffs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package bpf

import (
"fmt"
"testing"
)

func TestMapToPath(t *testing.T) {
type args struct {
name string
}
tests := []struct {
name string
args args
want string
}{
{"basic", args{"foo"}, "/sys/fs/bpf/foo"},
{"slash", args{"/"}, "/sys/fs/bpf"},
{"empty", args{""}, "/sys/fs/bpf"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := MapToPath(tt.args.name); got != tt.want {
fmt.Println(got)
t.Errorf("MapToPath() = %v, want %v", got, tt.want)
}
})
}
}
8 changes: 4 additions & 4 deletions pkg/entities/intent.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package entities

import (
"log"
"fmt"

"github.com/hawkv6/hawkwing/internal/config"
"github.com/hawkv6/hawkwing/pkg/types"
Expand Down Expand Up @@ -51,15 +51,15 @@ type Intent struct {
IntentValues []IntentValue
}

func CreateIntentsForServiceApplication(serviceKey string, applicationPort int) []Intent {
func CreateIntentsForServiceApplication(serviceKey string, applicationPort int) ([]Intent, error) {
serviceCfg := config.Params.Services[serviceKey]
intents := make([]Intent, 0)
for _, application := range serviceCfg.Applications {
if application.Port == applicationPort {
for _, intent := range application.Intents {
intentType, err := types.ParseIntentType(intent.Intent)
if err != nil {
log.Fatalf("failed to parse intent type %s: %v", intent.Intent, err)
return nil, fmt.Errorf("failed to parse intent type %s: %v", intent.Intent, err)
}
intents = append(intents, Intent{
IntentType: intentType,
Expand All @@ -68,5 +68,5 @@ func CreateIntentsForServiceApplication(serviceKey string, applicationPort int)
}
}
}
return intents
return intents, nil
}
Loading