From 53b9b09dc5615c6aebaef0deb43e73744987a0fe Mon Sep 17 00:00:00 2001
From: "S.H." <sebastian.heiss94@proton.me>
Date: Thu, 20 Feb 2025 14:12:40 +0100
Subject: [PATCH] venv.go: Added ApplyRoutes() to go through all links and
 create route for them (untested)

---
 applications/rtdt-manager/venv/venv.go | 32 ++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/applications/rtdt-manager/venv/venv.go b/applications/rtdt-manager/venv/venv.go
index e266ee34e..8b182cd13 100644
--- a/applications/rtdt-manager/venv/venv.go
+++ b/applications/rtdt-manager/venv/venv.go
@@ -260,6 +260,38 @@ func (v *VEnv) DeriveTopologyFromClabData() error {
 	}
 	return nil
 }
+
+func (v *VEnv) ApplyRoutes() error {
+	conn := v.auth.GetConn()
+	hostIP := int64(1)
+	for _, link := range v.topology.Links {
+		req := topoPb.AddRoutingTableRequest{
+			Timestamp: util.Now(),
+			RoutingTable: &topoPb.RoutingTable{
+				Id: uuid.NewString(),
+				Routes: []*topoPb.Route{
+					{
+						Id:            uuid.NewString(),
+						TargetIPRange: "16",
+						NextHopIP:     "192.168.178." + strconv.FormatInt(hostIP, 10),
+						PortID:        link.SourcePort.ID,
+					},
+				},
+			},
+		}
+		hostIP++
+		routeService := topoPb.NewRoutingTableServiceClient(conn)
+
+		ctx := v.auth.CreateContextWithAuthorization()
+		reply, err := routeService.AddRoutingTable(ctx, &req)
+		if err != nil {
+			return fmt.Errorf("AddRoutingTable failed: %v\n", err)
+		}
+		fmt.Println("Successfully added Link:", reply)
+	}
+	return nil
+}
+
 func (v *VEnv) UploadTopology() error {
 	conn := v.auth.GetConn()
 	topoService := topoPb.NewTopologyServiceClient(conn)
-- 
GitLab