Skip to content
This repository was archived by the owner on Apr 1, 2023. It is now read-only.

Commit 82e613d

Browse files
authored
Merge pull request #117 from zzengcs/br_77
Merak topology: create multilayer topology & add ACA command & fix ip-gen issue
2 parents 3e32c23 + 8abbf69 commit 82e613d

File tree

9 files changed

+460
-377
lines changed

9 files changed

+460
-377
lines changed

deployments/kubernetes/topo.dev.yaml

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,30 +129,48 @@ spec:
129129
role: master
130130
tier: backend
131131

132-
# RYU controller deployment
132+
# SDN controller deployment
133133
---
134134
apiVersion: apps/v1
135135
kind: Deployment
136136
metadata:
137-
name: ryu-deployment
137+
name: sdn-controller
138138
namespace: merak
139139
spec:
140140
selector:
141141
matchLabels:
142-
app: ryu
142+
app: sdn-controller
143143
replicas: 5
144144
template:
145145
metadata:
146146
labels:
147-
app: ryu
147+
app: sdn-controller
148148
spec:
149149
#hostNetwork: true
150150
containers:
151-
- name: ryu
151+
- name: sdn-controller
152152
image: osrg/ryu
153153
args:
154154
- ryu-manager
155155
- ./ryu/ryu/app/simple_switch_13.py
156156
ports:
157157
- containerPort: 6653
158158
name: openflow
159+
---
160+
apiVersion: v1
161+
kind: Service # Type of Kubernetes resource
162+
metadata:
163+
name: sdn-controller # Name of the Kubernetes resource
164+
namespace: merak
165+
labels: # Labels that will be applied to this resource
166+
app: sdn-controller
167+
role: master
168+
tier: backend
169+
spec:
170+
ports:
171+
- port: 6653 # Map incoming connections on port 55001 to the target port 55001 of the Pod
172+
targetPort: 6653
173+
selector: # Map any Pod with the specified labels to this service
174+
app: sdn-controller
175+
role: master
176+
tier: backend

services/merak-topo/database/entities.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,37 +26,36 @@ const (
2626
)
2727

2828
type Nic struct {
29+
Id string `json:"id"`
2930
Intf string `json:"intf"`
3031
Ip string `json:"ip"`
3132
Mac string `json:"mac"`
3233
}
3334

3435
type Vnode struct {
35-
Id string `json:"id"`
36-
Name string `json:"name"`
37-
Nics []Nic `json:"nics"`
38-
Flinks []map[string]interface{} `json:"flinks"`
39-
ContainerIp string `json:"containerip"`
40-
Status ServiceStatus `json:"status"`
41-
}
42-
43-
type Vport struct {
44-
Id string `json:"id"`
45-
Name string `json:"name"`
46-
Intf string `json:"nic"`
47-
Ip string `json:"ip"`
36+
Id string `json:"id"`
37+
Type string `json:"type"`
38+
Name string `json:"name"`
39+
Nics []Nic `json:"nics"`
40+
Flinks []Vlink `json:"flinks"`
41+
ContainerIp string `json:"containerip"`
42+
Status ServiceStatus `json:"status"`
4843
}
4944

5045
type Vlink struct {
51-
Id string `json:"id"`
52-
Name string `json:"name"`
53-
Src Vport `json:"src"`
54-
Dst Vport `json:"dst"`
55-
Status ServiceStatus `json:"status"`
46+
Id string `json:"id"`
47+
Name string `json:"name"`
48+
Uid int `json:"uid"`
49+
Peer_pod string `json:"peer_pod"`
50+
Local_pod string `json:"local_pod"`
51+
Local_intf string `json:"local_intf"`
52+
Local_ip string `json:"local_ip"`
53+
Peer_intf string `json:"peer_intf"`
54+
Peer_ip string `json:"peer_ip"`
55+
Status ServiceStatus `json:"status"`
5656
}
5757

5858
type TopologyData struct {
5959
Topology_id string `json:"topology_id"`
6060
Vnodes []Vnode `json:"vnodes"`
61-
Vlinks []Vlink `json:"vlinks"`
6261
}

services/merak-topo/grpc/service/service.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,16 @@ func (s *Server) TopologyHandler(ctx context.Context, in *pb.InternalTopologyInf
8181
// cgw_num := in.Config.GetNumberOfGateways() /*comment gw creation function, set cgw_num=0*/
8282
cgw_num := 0
8383
topo_id := in.Config.GetTopologyId()
84+
images := in.Config.GetImages()
85+
86+
ports_per_vswitch := in.Config.GetPortsPerVswitch()
8487

8588
/*comment gw creation function*/
8689
// if data_plane_cidr == "" || aca_num == 0 || aca_per_rack == 0 || rack_num == 0 || cgw_num == 0 {
87-
if data_plane_cidr == "" || aca_num == 0 || aca_per_rack == 0 || rack_num == 0 {
90+
if data_plane_cidr == "" || aca_num == 0 || aca_per_rack == 0 || rack_num == 0 || ports_per_vswitch == 0 {
8891

8992
returnMessage.ReturnCode = pb_common.ReturnCode_FAILED
90-
returnMessage.ReturnMessage = "Must provide a valid data plane cider, aca number, aca per rack number, rack number, and control plane gateways"
93+
returnMessage.ReturnMessage = "Must provide a valid data plane cider, aca number, aca per rack number, rack number, ports per vswitch, and control plane gateways"
9194

9295
return &returnMessage, nil
9396

@@ -106,7 +109,9 @@ func (s *Server) TopologyHandler(ctx context.Context, in *pb.InternalTopologyInf
106109
//
107110
default:
108111
// pb.TopologyType_TREE
109-
err_create := handler.Create(k8client, topo_id, uint32(aca_num), uint32(rack_num), uint32(aca_per_rack), uint32(cgw_num), data_plane_cidr, &returnMessage)
112+
// err_create := handler.Create(k8client, topo_id, uint32(aca_num), uint32(rack_num), uint32(aca_per_rack), uint32(cgw_num), data_plane_cidr, &returnMessage)
113+
114+
err_create := handler.Create(k8client, topo_id, uint32(aca_num), uint32(rack_num), uint32(aca_per_rack), uint32(cgw_num), data_plane_cidr, uint32(ports_per_vswitch), images, &returnMessage)
110115

111116
if err_create != nil {
112117
returnMessage.ReturnCode = pb_common.ReturnCode_FAILED

services/merak-topo/handler/handler.go

Lines changed: 37 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -33,82 +33,33 @@ import (
3333

3434
//function CREATE
3535
/* save the part of gw creation and mac learning for future requirment, comment the related code now*/
36-
func Create(k8client *kubernetes.Clientset, topo_id string, aca_num uint32, rack_num uint32, aca_per_rack uint32, cgw_num uint32, data_plane_cidr string, returnMessage *pb.ReturnTopologyMessage) error {
36+
func Create(k8client *kubernetes.Clientset, topo_id string, aca_num uint32, rack_num uint32, aca_per_rack uint32, cgw_num uint32, data_plane_cidr string, ports_per_vswitch uint32, images []*pb.InternalTopologyImage, returnMessage *pb.ReturnTopologyMessage) error {
3737

38-
var topo database.TopologyData
39-
40-
var ovs_tor_device = []string{"core-0"}
41-
ip_num := int(aca_num) + int(cgw_num)
42-
43-
log.Println("=== parse done == ")
44-
log.Printf("Core switch is: %v \n", ovs_tor_device[0])
45-
log.Printf("Vswitch number is: %v\n", rack_num)
38+
log.Println("=== Parse gRPC message === ")
4639
log.Printf("Vhost number is: %v\n", aca_num)
40+
log.Printf("Rack number is: %v\n", rack_num)
41+
log.Printf("Vhosts per rack is: %v\n", aca_per_rack)
4742

48-
fmt.Println("======== Generate device list ==== ")
49-
rack_device := Pod_name(int(rack_num), "vswitch")
50-
aca_device := Pod_name(int(aca_num), "vhost")
51-
// ngw_device := Pod_name(int(cgw_num), "cgw") /*comment gw creation function*/
52-
53-
fmt.Printf("Vswitch_device: %v\n", rack_device)
54-
fmt.Printf("Vhost_device: %v\n", aca_device)
55-
// fmt.Printf("Cgw_device: %v\n", ngw_device) /*comment gw creation function*/
56-
57-
fmt.Println("======== Generate device nodes ==== ")
58-
rack_intf_num := int(aca_per_rack) + 1
59-
tor_intf_num := int(rack_num) + int(cgw_num)
60-
aca_intf_num := 1
61-
// ngw_intf_num := 1 /*comment gw creation function*/
43+
log.Printf("Ports per vswitch is: %v\n", ports_per_vswitch)
6244

63-
log.Println("=== Generate ip addresses == ")
45+
log.Println("=== Generate topology data === ")
6446

65-
ips := Ips_gen(topo_id, ip_num, data_plane_cidr)
66-
67-
err := database.SetValue(topo_id+":ips", ips)
68-
if err != nil {
69-
return fmt.Errorf("fail to save ips in DB %s", err)
47+
err_create, topo := Create_multiple_layers_vswitches(int(aca_num), int(rack_num), int(aca_per_rack), int(ports_per_vswitch), data_plane_cidr)
48+
if err_create != nil {
49+
return fmt.Errorf("create multiple layers vswitches error %s", err_create)
7050
}
7151

72-
fmt.Println("======== Generate topology data ==== ")
73-
7452
topo.Topology_id = topo_id
7553

76-
topo_nodes, _ := Node_port_gen(aca_intf_num, aca_device, ips, true)
77-
// nodes, _ := Node_port_gen(ngw_intf_num, ngw_device, ips_1, true) /*comment gw creation function*/
78-
// topo_nodes = append(topo_nodes, nodes...)
79-
nodes_s, _ := Node_port_gen(rack_intf_num, rack_device, ips, false)
80-
topo_nodes = append(topo_nodes, nodes_s...)
81-
nodes_t, _ := Node_port_gen(tor_intf_num, ovs_tor_device, ips, false)
82-
topo_nodes = append(topo_nodes, nodes_t...)
83-
84-
fmt.Printf("The topology nodes are : %+v. \n", topo_nodes)
85-
86-
topo.Vnodes = topo_nodes
87-
88-
fmt.Println("======== Pairing links ==== ")
89-
90-
topo_links := Links_gen(topo_nodes)
91-
92-
fmt.Printf("The topology links are : %v. \n", topo_links)
93-
94-
fmt.Printf("The topology total links are : %v. \n", len(topo_links))
95-
topo.Vlinks = topo_links
96-
97-
fmt.Println("======== Save topo to redis =====")
54+
log.Println("=== Save topology to redis ===")
9855
err1 := Topo_save(topo)
9956
if err1 != nil {
100-
return fmt.Errorf("save topo to redis error %s", err1)
57+
return fmt.Errorf("save topology to redis error %s", err1)
10158
}
10259

103-
fmt.Println("======== Topology Deployment ==== ")
104-
105-
err_deploy := Topo_deploy(k8client, topo)
60+
log.Printf("topology details: %v", topo)
10661

107-
if err_deploy != nil {
108-
return fmt.Errorf("topology deployment error %s", err_deploy)
109-
}
110-
111-
fmt.Println("========= Get k8s host nodes information after deployment=====")
62+
log.Println("=== Get k8s host nodes information ===")
11263

11364
k8s_nodes, err1 := k8client.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
11465

@@ -145,7 +96,7 @@ func Create(k8client *kubernetes.Clientset, topo_id string, aca_num uint32, rack
14596

14697
}
14798

148-
fmt.Println("========= Return deployed compute nodes information =====")
99+
log.Println("=== Return deployed compute nodes information ===")
149100

150101
for _, node := range topo.Vnodes {
151102
var cnode pb_common.InternalComputeInfo
@@ -156,26 +107,45 @@ func Create(k8client *kubernetes.Clientset, topo_id string, aca_num uint32, rack
156107
cnode.Veth = node.Nics[len(node.Nics)-1].Intf
157108
}
158109

159-
log.Printf("get compute nodes IP and Veth")
110+
log.Println("get compute nodes IP and Veth")
160111

161112
cnode.OperationType = pb_common.OperationType_CREATE
162113
cnode.Status = pb_common.Status_DEPLOYING
163114

164-
log.Printf("get compute nodes status")
115+
log.Println("get compute nodes status")
165116

166117
returnMessage.ComputeNodes = append(returnMessage.ComputeNodes, &cnode)
167118

168-
log.Printf("generate returnMessage for compute nodes")
119+
log.Println("generate returnMessage for compute nodes")
169120

170121
}
171122

172123
err_db2 := database.SetPbReturnValue(topo_id+":initialreturn", returnMessage)
173124
if err_db2 != nil {
174-
log.Printf("fail to save return msg to DB %s", err_db2.Error())
125+
175126
return fmt.Errorf("fail to save return msg to DB %s", err_db2)
176127
}
177128

129+
log.Println("=== Topology Deployment === ")
130+
var aca_image string
131+
var ovs_image string
132+
133+
for _, img := range images {
134+
if strings.Contains(img.Name, "ACA") {
135+
aca_image = img.Registry
136+
} else if strings.Contains(img.Name, "OVS") {
137+
ovs_image = img.Registry
138+
}
139+
}
140+
141+
err_deploy := Topo_deploy(k8client, aca_image, ovs_image, topo)
142+
143+
if err_deploy != nil {
144+
return fmt.Errorf("topology deployment error %s", err_deploy)
145+
}
146+
178147
return nil
148+
179149
}
180150

181151
func UpdateComputenodeInfo(client *kubernetes.Clientset, topo_id string, returnMessage *pb.ReturnTopologyMessage) error {

0 commit comments

Comments
 (0)