From 99ee6824cd969197efb941de6d60d0a7a7dff442 Mon Sep 17 00:00:00 2001
From: Alejandro Tjaarda <alexdecb@yahoo.es>
Date: Tue, 1 Oct 2024 22:37:32 +0000
Subject: [PATCH] switch: implemented test environment

---
 src/switch/config/config.json    |  1 +
 src/switch/config/neighbors.json |  2 ++
 src/switch/test/client_test.go   | 44 ++++++++++++++++++++++++++++++++
 3 files changed, 47 insertions(+)
 create mode 100644 src/switch/config/config.json
 create mode 100644 src/switch/config/neighbors.json
 create mode 100644 src/switch/test/client_test.go

diff --git a/src/switch/config/config.json b/src/switch/config/config.json
new file mode 100644
index 0000000..1d717b7
--- /dev/null
+++ b/src/switch/config/config.json
@@ -0,0 +1 @@
+{"ConfigDir":"","ControllerIP":"192.168.122.60","NodeName":"ant-machine","NedName":"ant-machine-example-network-controller"}
diff --git a/src/switch/config/neighbors.json b/src/switch/config/neighbors.json
new file mode 100644
index 0000000..bf2730f
--- /dev/null
+++ b/src/switch/config/neighbors.json
@@ -0,0 +1,2 @@
+{"name":"ant-machine","nodeIP":"192.168.122.60","neighborNodes":["192.168.122.244"]}
+
diff --git a/src/switch/test/client_test.go b/src/switch/test/client_test.go
new file mode 100644
index 0000000..eb52772
--- /dev/null
+++ b/src/switch/test/client_test.go
@@ -0,0 +1,44 @@
+package main
+
+import (
+	"context"
+	"fmt"
+	"log"
+	"time"
+
+	"l2sm.local/ovs-switch/pkg/nedpb"
+
+	"google.golang.org/grpc"
+)
+
+func main() {
+	// Set up a connection to the gRPC server.
+	conn, err := grpc.Dial("localhost:50051", grpc.WithInsecure()) // Update with the actual server address and credentials if needed
+	if err != nil {
+		log.Fatalf("Failed to connect to gRPC server: %v", err)
+	}
+	defer conn.Close()
+
+	// Create a new client for the NedService.
+	client := nedpb.NewNedServiceClient(conn)
+
+	// Create a context with a timeout to ensure that the request doesn't hang.
+	ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
+	defer cancel()
+
+	// Prepare the request with the interface name "br10".
+	req := &nedpb.AttachInterfaceRequest{
+		InterfaceName: "br10",
+	}
+
+	// Call the AttachInterface method.
+	resp, err := client.AttachInterface(ctx, req)
+	if err != nil {
+		log.Fatalf("Error calling AttachInterface: %v", err)
+	}
+
+	// Handle and display the response.
+	fmt.Printf("Interface attached successfully:\n")
+	fmt.Printf("Interface Number: %d\n", resp.GetInterfaceNum())
+	fmt.Printf("Node Name: %s\n", resp.GetNodeName())
+}
-- 
GitLab