-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from lumbrjx/release
Release
- Loading branch information
Showing
17 changed files
with
348 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
TARGET = tc.o | ||
INTERFACE = enp1s0 | ||
US_DIR = user_space | ||
CFLAGS = -I/usr/include -I/usr/include/x86_64-linux-gnu -I/usr/include/x86_64-linux-gnu/bits -I/usr/include/x86_64-linux-gnu/sys -I/usr/include/bpf | ||
|
||
.PHONY: install-deps | ||
install-deps: | ||
sudo apt update | ||
sudo apt install -y clang llvm libelf-dev linux-headers-$$(uname -r) build-essential | ||
cd $(US_DIR) && go mod tidy | ||
|
||
# Compile the eBPF program | ||
$(TARGET): main.c | ||
clang $(CFLAGS) -O2 -g -target bpf -c tc.c -o $(TARGET) | ||
|
||
# Load the eBPF program manually | ||
.PHONY: load | ||
load: $(TARGET) | ||
sudo tc qdisc add dev $(INTERFACE) clsact | ||
sudo tc filter add dev $(INTERFACE) ingress bpf da obj $(TARGET) sec tc | ||
sudo tc filter add dev $(INTERFACE) egress bpf da obj $(TARGET) sec tc | ||
|
||
# View bpf_printk output | ||
.PHONY: view-manual | ||
view: | ||
sudo cat /sys/kernel/debug/tracing/trace_pipe | ||
|
||
.PHONY: view-tcp-manual | ||
view-tcp: | ||
sudo cat /sys/kernel/debug/tracing/trace_pipe | grep TCP | ||
|
||
.PHONY: view-udp-manual | ||
view-udp: | ||
sudo cat /sys/kernel/debug/tracing/trace_pipe | grep UDP | ||
|
||
|
||
# build user space program | ||
.PHONY: build-US | ||
build-US: | ||
cd user_space && go build -o tc_US tc.go | ||
|
||
# start user space program | ||
.PHONY: start-US | ||
start-US: | ||
sudo ./user_space/tc_US $(INTERFACE) | ||
|
||
# Remove the filters and qdisc when done manually | ||
.PHONY: clean | ||
clean: | ||
sudo tc filter del dev $(INTERFACE) ingress | ||
sudo tc filter del dev $(INTERFACE) egress | ||
sudo tc qdisc del dev $(INTERFACE) clsact | ||
rm -f $(TARGET) | ||
rm -f user_space/tc_US | ||
|
||
# All | ||
.PHONY: all | ||
all: install-deps $(TARGET) build-US start-US |
File renamed without changes.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package controller | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"obzev0/common/proto/latency" | ||
"time" | ||
|
||
pb "obzev0/common/proto/latency" | ||
tca "obzev0/common/proto/tcAnalyser" | ||
v "obzev0/controller/api/v1" | ||
|
||
"google.golang.org/grpc" | ||
) | ||
|
||
type GrpcServiceConfig struct { | ||
LatencyConfig v.TcpConfig | ||
TcAConfig v.TcAnalyserConfig | ||
|
||
// Add more fields as needed | ||
} | ||
|
||
func callGrpcServices( | ||
conn *grpc.ClientConn, | ||
config GrpcServiceConfig, | ||
) error { | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) | ||
defer cancel() | ||
|
||
// Handle LatencyService gRPC call | ||
client := pb.NewLatencyServiceClient(conn) | ||
response, err := client.StartTcpServer( | ||
ctx, | ||
&pb.RequestForTcp{Config: &latency.TcpConfig{ | ||
ReqDelay: config.LatencyConfig.ReqDelay, | ||
ResDelay: config.LatencyConfig.ResDelay, | ||
Server: config.LatencyConfig.Server, | ||
Client: config.LatencyConfig.Client, | ||
}}, | ||
) | ||
if err != nil { | ||
return fmt.Errorf("error calling StartTcpServer: %w", err) | ||
} | ||
fmt.Printf("Response from LatencyService gRPC server: %s\n", response.Message) | ||
|
||
// Handle TcAnalyserService gRPC call | ||
client2 := tca.NewTcAnalyserServiceClient(conn) | ||
rsp, err := client2.StartUserSpace( | ||
ctx, | ||
&tca.RequestForUserSpace{Config: &tca.TcConfig{ | ||
Interface: config.TcAConfig.NetIFace, | ||
}}, | ||
) | ||
if err != nil { | ||
return fmt.Errorf("error calling StartUserSpace: %w", err) | ||
} | ||
fmt.Printf("Response from TcAnalyserService gRPC server: %s\n", rsp.Message) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package controller | ||
|
||
import ( | ||
"context" | ||
"log" | ||
v1 "obzev0/controller/api/v1" | ||
|
||
"google.golang.org/grpc" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes" | ||
"k8s.io/klog/v2" | ||
) | ||
|
||
func processCustomResource(obz *v1.Obzev0Resource, conn *grpc.ClientConn) { | ||
name := obz.GetName() | ||
namespace := obz.GetNamespace() | ||
latencyConfig := obz.Spec.LatencyServiceConfig | ||
tcAConfig := obz.Spec.TcAnalyserServiceConfig | ||
|
||
klog.Infof("Custom Resource processed: %s/%s", namespace, name) | ||
klog.Infof("TCP Server Configuration: %+v", latencyConfig) | ||
klog.Infof("Tc Analyser Configuration: %+v", tcAConfig) | ||
|
||
svcConfig := GrpcServiceConfig{ | ||
LatencyConfig: latencyConfig, | ||
TcAConfig: tcAConfig, | ||
} | ||
|
||
err := callGrpcServices(conn, svcConfig) | ||
if err != nil { | ||
log.Printf("Error calling gRPC services: %v\n", err) | ||
} | ||
|
||
defer conn.Close() | ||
} | ||
|
||
func handleAdd(obj interface{}, conn *grpc.ClientConn) { | ||
obz, ok := obj.(*v1.Obzev0Resource) | ||
if !ok { | ||
klog.Errorf("Error converting object to Obzev0Resource: %v", obj) | ||
return | ||
} | ||
|
||
processCustomResource(obz, conn) | ||
} | ||
|
||
func handleUpdate(newObj interface{}, conn *grpc.ClientConn) { | ||
obz, ok := newObj.(*v1.Obzev0Resource) | ||
if !ok { | ||
klog.Errorf("Error converting object to Obzev0Resource: %v", newObj) | ||
return | ||
} | ||
|
||
processCustomResource(obz, conn) | ||
} | ||
|
||
func handleDelete(obj interface{}) { | ||
obz, ok := obj.(*v1.Obzev0Resource) | ||
if !ok { | ||
klog.Errorf("Error converting object to Obzev0Resource: %v", obj) | ||
return | ||
} | ||
|
||
name := obz.GetName() | ||
namespace := obz.GetNamespace() | ||
|
||
klog.Infof("Custom Resource deleted: %s/%s", namespace, name) | ||
} | ||
func listNodes(clientset *kubernetes.Clientset) { | ||
nodes, err := clientset.CoreV1(). | ||
Nodes(). | ||
List(context.TODO(), metav1.ListOptions{}) | ||
if err != nil { | ||
klog.Fatalf("Error listing nodes: %v", err) | ||
} | ||
|
||
klog.Info("Listing all nodes in the cluster:") | ||
for _, node := range nodes.Items { | ||
klog.Infof("Node Name: %s", node.Name) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.