diff --git a/poc-cb-net/README.KR.md b/poc-cb-net/README.KR.md index b276ae0..070ef18 100644 --- a/poc-cb-net/README.KR.md +++ b/poc-cb-net/README.KR.md @@ -161,6 +161,9 @@ git checkout tags/v3.5.0 -b v3.5.0 server_port: "8053" gateway_port: "8052" + # A config for the demo-client as follows: + service_call_method: "grpc" # i.e., "rest" / "grpc" + ``` ##### log_conf.yaml @@ -241,6 +244,9 @@ sudo ./controller server_port: "8053" gateway_port: "8052" + # A config for the demo-client as follows: + service_call_method: "grpc" # i.e., "rest" / "grpc" + ``` ##### log_conf.yaml @@ -321,6 +327,9 @@ sudo ./cladnet-service server_port: "8053" gateway_port: "8052" + # A config for the demo-client as follows: + service_call_method: "grpc" # i.e., "rest" / "grpc" + ``` ##### log_conf.yaml @@ -402,6 +411,9 @@ sudo ./admin-web server_port: "8053" gateway_port: "8052" + # A config for the demo-client as follows: + service_call_method: "grpc" # i.e., "rest" / "grpc" + ``` ##### log_conf.yaml @@ -492,6 +504,9 @@ sudo ./agent server_port: "8053" gateway_port: "8052" + # A config for the demo-client as follows: + service_call_method: "grpc" # i.e., "rest" / "grpc" + ``` #### demo-client 빌드 diff --git a/poc-cb-net/README.md b/poc-cb-net/README.md index 3a1a523..467badd 100644 --- a/poc-cb-net/README.md +++ b/poc-cb-net/README.md @@ -160,6 +160,9 @@ It was deployed and tested on the "home" directory of Ubuntu 18.04. It's possibl server_port: "8053" gateway_port: "8052" + # A config for the demo-client as follows: + service_call_method: "grpc" # i.e., "rest" / "grpc" + ``` ##### log_conf.yaml @@ -240,6 +243,9 @@ It was deployed and tested on the "home" directory of Ubuntu 18.04. It's possibl server_port: "8053" gateway_port: "8052" + # A config for the demo-client as follows: + service_call_method: "grpc" # i.e., "rest" / "grpc" + ``` ##### log_conf.yaml @@ -320,6 +326,9 @@ It was deployed and tested on the "home" directory of Ubuntu 18.04. It's possibl server_port: "8053" gateway_port: "8052" + # A config for the demo-client as follows: + service_call_method: "grpc" # i.e., "rest" / "grpc" + ``` ##### log_conf.yaml @@ -400,6 +409,9 @@ It was deployed and tested on the "home" directory of Ubuntu 18.04. It's possibl server_port: "8053" gateway_port: "8052" + # A config for the demo-client as follows: + service_call_method: "grpc" # i.e., "rest" / "grpc" + ``` ##### log_conf.yaml @@ -491,6 +503,9 @@ If it is running on another node, it is required to modify source code (related server_port: "8053" gateway_port: "8052" + # A config for the demo-client as follows: + service_call_method: "grpc" # i.e., "rest" / "grpc" + ``` #### Build the demo-client diff --git a/poc-cb-net/cmd/admin-web/admin-web.go b/poc-cb-net/cmd/admin-web/admin-web.go index 2be3c72..aadd690 100644 --- a/poc-cb-net/cmd/admin-web/admin-web.go +++ b/poc-cb-net/cmd/admin-web/admin-web.go @@ -226,11 +226,14 @@ func handleTestSpecification(etcdClient *clientv3.Client, responseText []byte) { // Get a networking rule of a cloud adaptive network keyNetworkingRule := fmt.Sprint(etcdkey.NetworkingRule + "/" + testSpecification.CLADNetID) + CBLogger.Debugf("Get - %v", keyNetworkingRule) resp, err := etcdClient.Get(context.TODO(), keyNetworkingRule, clientv3.WithPrefix()) if err != nil { CBLogger.Error(err) } + CBLogger.Tracef("Get resp: %+v", resp) + for _, kv := range resp.Kvs { var peer model.Peer @@ -275,6 +278,7 @@ func handleControlCommand(etcdClient *clientv3.Client, responseText string) { // Get a networking rule of a cloud adaptive network keyNetworkingRule := fmt.Sprint(etcdkey.NetworkingRule + "/" + cladnetID) + CBLogger.Debugf("Get - %v", keyNetworkingRule) resp, err := etcdClient.Get(context.TODO(), keyNetworkingRule, clientv3.WithPrefix()) if err != nil { CBLogger.Error(err) @@ -283,7 +287,7 @@ func handleControlCommand(etcdClient *clientv3.Client, responseText string) { for _, kv := range resp.Kvs { key := string(kv.Key) CBLogger.Tracef("Key : %v", key) - CBLogger.Tracef("The peer: %v", kv.Value) + CBLogger.Tracef("The peer: %v", string(kv.Value)) var peer model.Peer err := json.Unmarshal(kv.Value, &peer) @@ -294,6 +298,7 @@ func handleControlCommand(etcdClient *clientv3.Client, responseText string) { // Put the evaluation specification of the CLADNet to the etcd keyControlCommand := fmt.Sprint(etcdkey.ControlCommand + "/" + peer.CLADNetID + "/" + peer.HostID) + CBLogger.Debugf("Put - %v", keyControlCommand) cmdMessageBody := cmd.BuildCommandMessage(controlCommand, controlCommandOption) CBLogger.Tracef("%#v", cmdMessageBody) //spec := message.Text diff --git a/poc-cb-net/cmd/controller/controller.go b/poc-cb-net/cmd/controller/controller.go index 00600cf..c2d3c7f 100644 --- a/poc-cb-net/cmd/controller/controller.go +++ b/poc-cb-net/cmd/controller/controller.go @@ -222,9 +222,10 @@ func watchHostNetworkInformation(wg *sync.WaitGroup, etcdClient *clientv3.Client peer.PublicIPv4Address = hostNetworkInformation.PublicIP } - CBLogger.Debugf("Put \"%v\"", keyNetworkingRuleOfPeer) - doc, _ := json.Marshal(peer) + CBLogger.Debugf("Put - %v", keyNetworkingRuleOfPeer) + CBLogger.Tracef("Value: %#v", peer) + doc, _ := json.Marshal(peer) if _, err := etcdClient.Put(context.TODO(), keyNetworkingRuleOfPeer, string(doc)); err != nil { CBLogger.Error(err) } @@ -250,7 +251,7 @@ func watchHostNetworkInformation(wg *sync.WaitGroup, etcdClient *clientv3.Client func tryToAcquireWorkload(etcdClient *clientv3.Client, controllerID string, key string, revision int64) bool { CBLogger.Debugf("Start (%s) .........", controllerID) // Key to lease temporally by which each cb-network controller can distinguish each updated value - keyToLease := fmt.Sprintf("lease/%s-%d", key, revision) + keyToLease := fmt.Sprintf("lease%s-%d", key, revision) // fmt.Printf("%#v\n", keyPrefix) // Self-assign a workload by Compare-and-Swap (CAS) and Lease diff --git a/poc-cb-net/cmd/service/cladnet-service.go b/poc-cb-net/cmd/service/cladnet-service.go index cde9e6b..8f266c1 100644 --- a/poc-cb-net/cmd/service/cladnet-service.go +++ b/poc-cb-net/cmd/service/cladnet-service.go @@ -215,7 +215,7 @@ func (s *server) CreateCLADNet(ctx context.Context, cladnetSpec *pb.CLADNetSpeci } func (s *server) RecommendAvailableIPv4PrivateAddressSpaces(ctx context.Context, ipnets *pb.IPNetworks) (*pb.AvailableIPv4PrivateAddressSpaces, error) { - log.Printf("Received: %v", ipnets.IpNetworks) + log.Printf("Received: %#v", ipnets.IpNetworks) availableSpaces := nethelper.GetAvailableIPv4PrivateAddressSpaces(ipnets.IpNetworks) response := &pb.AvailableIPv4PrivateAddressSpaces{ diff --git a/poc-cb-net/cmd/test-client/config/template-config.yaml b/poc-cb-net/cmd/test-client/config/template-config.yaml index 5cb8456..a118f23 100644 --- a/poc-cb-net/cmd/test-client/config/template-config.yaml +++ b/poc-cb-net/cmd/test-client/config/template-config.yaml @@ -18,3 +18,6 @@ grpc: service_endpoint: "localhost:8053" server_port: "8053" gateway_port: "8052" + +# A config for the demo-client as follows: +service_call_method: "grpc" # i.e., "rest" / "grpc" diff --git a/poc-cb-net/cmd/test-client/demo-client.go b/poc-cb-net/cmd/test-client/demo-client.go index 8363503..7a2940f 100644 --- a/poc-cb-net/cmd/test-client/demo-client.go +++ b/poc-cb-net/cmd/test-client/demo-client.go @@ -16,6 +16,7 @@ import ( pb "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/api/gen/go/cbnetwork" model "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/cb-network/model" "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/file" + nethelper "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/network-helper" "github.com/go-resty/resty/v2" "github.com/tidwall/gjson" "google.golang.org/grpc" @@ -56,6 +57,253 @@ func init() { fmt.Println("End......... init() of test-client.go") } +func main() { + + start := time.Now() + + // Dummy data to test + gRPCServiceEndpoint := "localhost:8053" + // dummyIPNetworks := []string{"10.1.0.0/16", "10.2.0.0/16", "10.3.0.0/16", "172.16.1.0/24", "172.16.2.0/24", "172.16.3.0/24", "172.16.4.0/24", "172.16.5.0/24", "172.16.6.0/24", "192.168.1.0/28", "192.168.2.0/28", "192.168.3.0/28", "192.168.4.0/28", "192.168.5.0/28", "192.168.6.0/28", "192.168.7.0/28"} + + nsID := "ns01" + mcisID := "cbnet01" + + cladnetName := mcisID + cladnetDescription := "It's a recommended cladnet" + + client := resty.New() + client.SetBasicAuth("default", "default") + + isOn := true + + // Step 1: Health-check CB-Tumblebug + fmt.Println("\n\n##### Start ---------- Step 1: Health-check CB-Tumblebug") + pressEnterKeyToContinue(isOn) + + resp, err := client.R(). + SetHeader("Content-Type", "application/json"). + Get(fmt.Sprintf("%s/tumblebug/health", endpointTB)) + + // Output print + fmt.Printf("\nError: %v\n", err) + fmt.Printf("Time: %v\n", resp.Time()) + fmt.Printf("Body: %v\n", resp) + + fmt.Println("##### End ---------- Step 1: Health-check CB-Tumblebug") + fmt.Println("Sleep 5 sec ( _ _ )zZ") + time.Sleep(5 * time.Second) + + // Step 2: Create MCIS dynamically + // POST ​/ns​/{nsId}​/mcisDynamic Create MCIS Dynamically + fmt.Println("\n\n##### Start ---------- Step 2: Create MCIS dynamically") + pressEnterKeyToContinue(isOn) + + reqBodyHolder := `{ + "description": "Made in CB-TB", + "installMonAgent": "no", + "label": "custom tag", + "name": "%s", + "vm": [ + { + "commonImage": "ubuntu18.04", + "commonSpec": "aws-ap-northeast-2-t2-large" + }, + { + "commonImage": "ubuntu18.04", + "commonSpec": "azure-westus-standard-b2s" + }, + { + "commonImage": "ubuntu18.04", + "commonSpec": "gcp-asia-east1-e2-standard-2" + } + ] +}` + reqBody := fmt.Sprintf(reqBodyHolder, mcisID) + fmt.Printf("[mcisDynamic Body]\n%s\n", reqBody) + + resp, err = client.R(). + SetHeader("Content-Type", "application/json"). + SetHeader("Accept", "application/json"). + SetPathParams(map[string]string{ + "nsId": nsID, + }). + SetBody(reqBody). + Post(fmt.Sprintf("%s/tumblebug/ns/{nsId}/mcisDynamic", endpointTB)) + + // Output print + fmt.Printf("\nError: %v\n", err) + fmt.Printf("Time: %v\n", resp.Time()) + fmt.Printf("Body: %v\n", resp) + + mcisStatus := gjson.Get(resp.String(), "status") + fmt.Printf("=====> status: %v \n", mcisStatus) + + fmt.Println("##### End ---------- Step 2: Create MCIS dynamically") + fmt.Println("Sleep 10 sec ( _ _ )zZ") + time.Sleep(10 * time.Second) + + // Step 3: Get VM address spaces + fmt.Println("\n\n##### Start ---------- Step 3: Get VM address spaces") + pressEnterKeyToContinue(isOn) + + tbMCISInfo := resp + + vNetIDs := []string{} + + retVMID := gjson.Get(tbMCISInfo.String(), "vm.1.id") + + retVNetIDs := gjson.Get(tbMCISInfo.String(), "vm.#.vNetId") + fmt.Printf("retVNetIDs: %#v\n", retVNetIDs) + + for _, vNetID := range retVNetIDs.Array() { + vNetIDs = append(vNetIDs, vNetID.String()) + } + fmt.Printf("vNetIds: %#v\n", vNetIDs) + + ipNetsInMCIS := []string{} + + for _, v := range vNetIDs { + + // Get VNet + // curl -X GET "http://localhost:1323/tumblebug/ns/ns01/resources/vNet/ns01-systemdefault-aws-ap-northeast-2" -H "accept: application/json" + fmt.Printf("\nvNetId: %v\n", v) + resp, err = client.R(). + SetHeader("Content-Type", "application/json"). + SetHeader("Accept", "application/json"). + SetPathParams(map[string]string{ + "nsId": nsID, + "vNetId": v, + }). + Get(fmt.Sprintf("%s/tumblebug/ns/{nsId}/resources/vNet/{vNetId}", endpointTB)) + + // Output print + fmt.Printf("\nError: %v\n", err) + fmt.Printf("Time: %v\n", resp.Time()) + fmt.Printf("Body: %v\n", resp) + + retIPv4CIDR := gjson.Get(resp.String(), "subnetInfoList.0.IPv4_CIDR") + fmt.Printf("retIPv4CIDR: %#v\n", retIPv4CIDR) + ipNetsInMCIS = append(ipNetsInMCIS, retIPv4CIDR.String()) + } + + fmt.Printf("IPNetsInMCIS: %#v\n", ipNetsInMCIS) + + fmt.Println("##### End ---------- Step 3: Get VM address spaces") + fmt.Println("Sleep 3 sec ( _ _ )zZ") + time.Sleep(3 * time.Second) + + // Step 4: Create a cloud adaptive network and get an ID of it + fmt.Println("\n\n##### Start ---------- Step 4: Create a cloud adaptive network and get an ID of it") + pressEnterKeyToContinue(isOn) + + cladnetSpec, err := createProperCloudAdaptiveNetwork(gRPCServiceEndpoint, ipNetsInMCIS, cladnetName, cladnetDescription) + if err != nil { + log.Printf("Could not create a cloud adaptive network: %v\n", err) + } + + log.Printf("Struct: %#v\n", cladnetSpec) + + fmt.Println("##### End ---------- Step 4: Create a cloud adaptive network and get an ID of it") + fmt.Println("Sleep 5 sec ( _ _ )zZ") + time.Sleep(5 * time.Second) + + // Step 5: Install the cb-network agent by sending a command to specified MCIS + fmt.Println("\n\n##### Start ---------- Step 5: Install the cb-network agent by sending a command to specified MCIS") + pressEnterKeyToContinue(isOn) + + placeHolderCommand := `wget https://raw.githubusercontent.com/cloud-barista/cb-larva/develop/poc-cb-net/scripts/1.deploy-cb-network-agent.sh -O ~/1.deploy-cb-network-agent.sh; chmod +x ~/1.deploy-cb-network-agent.sh; source ~/1.deploy-cb-network-agent.sh '%s' %s` + + etcdEndpointsJSON, _ := json.Marshal(config.ETCD.Endpoints) + etcdEndpointsString := string(etcdEndpointsJSON) + //fmt.Printf("etcdEndpointsString: %#v\n", etcdEndpointsString) + additionalEncodedString := strings.Replace(etcdEndpointsString, "\"", "\\\"", -1) + //fmt.Printf("additionalEncodedString: %#v\n", additionalEncodedString) + + command := fmt.Sprintf(placeHolderCommand, additionalEncodedString, cladnetSpec.ID) + fmt.Printf("command: %#v\n", command) + + body := fmt.Sprintf(placeHolderBody, command) + //fmt.Printf("body: %#v\n", body) + + resp, err = client.R(). + SetHeader("Content-Type", "application/json"). + SetHeader("Accept", "application/json"). + SetPathParams(map[string]string{ + "nsId": nsID, + "mcisId": mcisID, + }). + SetBody(body). + Post(fmt.Sprintf("%s/tumblebug/ns/{nsId}/cmd/mcis/{mcisId}", endpointTB)) + + // Output print + fmt.Printf("\nError: %v\n", err) + fmt.Printf("Time: %v\n", resp.Time()) + fmt.Printf("Body: %v\n", resp) + + fmt.Println("##### End ---------- Step 5: Install the cb-network agent by sending a command to specified MCIS") + fmt.Println("Sleep 5 sec ( _ _ )zZ") + time.Sleep(5 * time.Second) + + // Special stage ;) + char := askYesOrNoQuestion(isOn, "Do you want to deploy a single Kubernetes cluster across multi-clouds? (y/n)") + if char == "y" { + // Deploy a single Kubernetes cluster across multi-clouds (i.e., on MCIS) + deployKubernetesCluster(nsID, mcisID, retVMID.String()) + } + + char = askYesOrNoQuestion(isOn, "Do you want to clean MCIS? (y/n)") + if char == "y" { + // Step 6: Delete MCIS + // curl -X DELETE "http://localhost:1323/tumblebug/ns/ns01/mcis/mcis01?option=terminate" -H "accept: application/json" + fmt.Println("\n\n##### Start ---------- Step 6: Delete MCIS") + pressEnterKeyToContinue(isOn) + + resp, err = client.R(). + SetHeader("Content-Type", "application/json"). + SetHeader("Accept", "application/json"). + SetPathParams(map[string]string{ + "nsId": nsID, + "mcisId": mcisID, + }). + SetQueryParams(map[string]string{ + "option": "terminate", + }). + Delete(fmt.Sprintf("%s/tumblebug/ns/{nsId}/mcis/{mcisId}", endpointTB)) + + // Output print + fmt.Printf("\nError: %v\n", err) + fmt.Printf("Time: %v\n", resp.Time()) + fmt.Printf("Body: %v\n", resp) + + fmt.Println("##### End ---------- Step 6: Delete MCIS") + fmt.Println("Sleep 5 sec ( _ _ )zZ") + time.Sleep(5 * time.Second) + + // Step 7: Delete defaultResources + // curl -X DELETE "http://localhost:1323/tumblebug/ns/ns01/defaultResources" -H "accept: application/json" + fmt.Println("\n\n##### Start ---------- Step 7: Delete defaultResources") + pressEnterKeyToContinue(isOn) + + resp, err = client.R(). + SetHeader("Content-Type", "application/json"). + SetHeader("Accept", "application/json"). + SetPathParams(map[string]string{ + "nsId": nsID, + }). + Delete(fmt.Sprintf("%s/tumblebug/ns/{nsId}/defaultResources", endpointTB)) + + // Output print + fmt.Printf("\nError: %v\n", err) + fmt.Printf("Time: %v\n", resp.Time()) + fmt.Printf("Body: %v\n", resp) + + fmt.Println("##### End ---------- Step 7: Delete defaultResources") + } + + elapsed := time.Since(start) + fmt.Printf("Elapsed time: %s\n", elapsed) +} + func pressEnterKeyToContinue(isOn bool) { if isOn { @@ -112,51 +360,119 @@ func askYesOrNoQuestion(isOn bool, question string) string { func createProperCloudAdaptiveNetwork(gRPCServiceEndpoint string, ipNetworks []string, cladnetName string, cladnetDescription string) (model.CLADNetSpecification, error) { + var cladnetSpec *pb.CLADNetSpecification ipNets := &pb.IPNetworks{IpNetworks: ipNetworks} + var spec model.CLADNetSpecification - // Connect to the gRPC server - grpcConn, err := grpc.Dial(gRPCServiceEndpoint, grpc.WithInsecure(), grpc.WithBlock()) - if err != nil { - log.Printf("Cannot connect: %v\n", err) - return model.CLADNetSpecification{}, err - } - defer grpcConn.Close() + log.Printf("Service Call Method: %s", config.ServiceCallMethod) + switch config.ServiceCallMethod { + case "grpc": - // Create a stub of Cloud AdaptiveNetwork - cladnetClient := pb.NewCloudAdaptiveNetworkServiceClient(grpcConn) + // Connect to the gRPC server + grpcConn, err := grpc.Dial(gRPCServiceEndpoint, grpc.WithInsecure(), grpc.WithBlock()) + if err != nil { + log.Printf("Cannot connect: %v\n", err) + return model.CLADNetSpecification{}, err + } + defer grpcConn.Close() - ctx, cancel := context.WithTimeout(context.Background(), time.Second) - defer cancel() + // Create a stub of Cloud AdaptiveNetwork + cladnetClient := pb.NewCloudAdaptiveNetworkServiceClient(grpcConn) - // Call rpc, RecommendAvailableIPv4PrivateAddressSpaces(ctx, ipNets) - availableIPv4PrivateAddressSpaces, err := cladnetClient.RecommendAvailableIPv4PrivateAddressSpaces(ctx, ipNets) - if err != nil { - log.Printf("Could not request: %v\n", err) - return model.CLADNetSpecification{}, err - } - log.Printf("RecommendedIpv4PrivateAddressSpace: %#v", availableIPv4PrivateAddressSpaces.RecommendedIpv4PrivateAddressSpace) + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + defer cancel() - // Call rpc, CreateCLADNet(ctx, cladnetSpec) - reqCladnetSpec := &pb.CLADNetSpecification{ - Id: "", - Name: cladnetName, - Ipv4AddressSpace: availableIPv4PrivateAddressSpaces.RecommendedIpv4PrivateAddressSpace, - Description: cladnetDescription} + // Call rpc, RecommendAvailableIPv4PrivateAddressSpaces(ctx, ipNets) + availableIPv4PrivateAddressSpaces, err := cladnetClient.RecommendAvailableIPv4PrivateAddressSpaces(ctx, ipNets) + if err != nil { + log.Printf("Could not request: %v\n", err) + return model.CLADNetSpecification{}, err + } + log.Printf("RecommendedIpv4PrivateAddressSpace: %#v", availableIPv4PrivateAddressSpaces.RecommendedIpv4PrivateAddressSpace) + + // Call rpc, CreateCLADNet(ctx, cladnetSpec) + reqCladnetSpec := &pb.CLADNetSpecification{ + Id: "", + Name: cladnetName, + Ipv4AddressSpace: availableIPv4PrivateAddressSpaces.RecommendedIpv4PrivateAddressSpace, + Description: cladnetDescription} + + cladnetSpec, err = cladnetClient.CreateCLADNet(ctx, reqCladnetSpec) + if err != nil { + log.Printf("Could not request: %v", err) + return model.CLADNetSpecification{}, err + } - cladnetSpec, err := cladnetClient.CreateCLADNet(ctx, reqCladnetSpec) - if err != nil { - log.Printf("Could not request: %v", err) - return model.CLADNetSpecification{}, err - } + log.Printf("Struct: %#v", cladnetSpec) + + spec = model.CLADNetSpecification{ + ID: cladnetSpec.Id, + Name: cladnetSpec.Name, + Ipv4AddressSpace: cladnetSpec.Ipv4AddressSpace, + Description: cladnetSpec.Description, + } + case "rest": + + ipNetworksJSON, _ := json.Marshal(ipNets) + fmt.Println(string(ipNetworksJSON)) + + client := resty.New() + // client.SetBasicAuth("default", "default") + + // Request a recommendation of available IPv4 private address spaces. + resp, err := client.R(). + SetHeader("Content-Type", "application/json"). + SetHeader("Accept", "application/json"). + SetBody(ipNetworksJSON). + Post(fmt.Sprintf("http://%s/v1/cladnet/available-ipv4-address-spaces", gRPCServiceEndpoint)) + // Output print + log.Printf("\nError: %v\n", err) + log.Printf("Time: %v\n", resp.Time()) + log.Printf("Body: %v\n", resp) + + if err != nil { + log.Printf("Could not request: %v\n", err) + return model.CLADNetSpecification{}, err + } + + var availableIPv4PrivateAddressSpaces nethelper.AvailableIPv4PrivateAddressSpaces + + json.Unmarshal(resp.Body(), &availableIPv4PrivateAddressSpaces) + log.Printf("%+v\n", availableIPv4PrivateAddressSpaces) + log.Printf("RecommendedIpv4PrivateAddressSpace: %#v", availableIPv4PrivateAddressSpaces.RecommendedIPv4PrivateAddressSpace) + + reqCladnetSpec := &pb.CLADNetSpecification{ + Id: "", + Name: cladnetName, + Ipv4AddressSpace: availableIPv4PrivateAddressSpaces.RecommendedIPv4PrivateAddressSpace, + Description: cladnetDescription} + + reqCladnetSpecJSON, _ := json.Marshal(reqCladnetSpec) + fmt.Println(string(reqCladnetSpecJSON)) - log.Printf("Struct: %#v", cladnetSpec) + // Request to create a Cloud Adaptive Network + resp, err = client.R(). + SetHeader("Content-Type", "application/json"). + SetHeader("Accept", "application/json"). + SetBody(reqCladnetSpecJSON). + Post(fmt.Sprintf("http://%s/v1/cladnet", gRPCServiceEndpoint)) + // Output print + log.Printf("\nError: %v\n", err) + log.Printf("Time: %v\n", resp.Time()) + log.Printf("Body: %v\n", resp) - spec := model.CLADNetSpecification{ - ID: cladnetSpec.Id, - Name: cladnetSpec.Name, - Ipv4AddressSpace: cladnetSpec.Ipv4AddressSpace, - Description: cladnetSpec.Description, + if err != nil { + log.Printf("Could not request: %v\n", err) + return model.CLADNetSpecification{}, err + } + + json.Unmarshal(resp.Body(), &spec) + log.Printf("%#v\n", spec) + + default: + log.Printf("Unknown service call method: %v\n", config.ServiceCallMethod) } + return spec, nil } @@ -567,248 +883,3 @@ func deployKubernetesCluster(nsID string, mcisID string, vmID string) { time.Sleep(5 * time.Second) } - -func main() { - - start := time.Now() - - // Dummy data to test - gRPCServiceEndpoint := "localhost:8053" - // dummyIPNetworks := []string{"10.1.0.0/16", "10.2.0.0/16", "10.3.0.0/16", "172.16.1.0/24", "172.16.2.0/24", "172.16.3.0/24", "172.16.4.0/24", "172.16.5.0/24", "172.16.6.0/24", "192.168.1.0/28", "192.168.2.0/28", "192.168.3.0/28", "192.168.4.0/28", "192.168.5.0/28", "192.168.6.0/28", "192.168.7.0/28"} - - cladnetName := "CLADNet01" - cladnetDescription := "Alvin's CLADNet01" - - nsID := "ns01" - mcisID := "mcis01" - - client := resty.New() - client.SetBasicAuth("default", "default") - - isOn := true - - // Step 1: Health-check CB-Tumblebug - fmt.Println("\n\n##### Start ---------- Step 1: Health-check CB-Tumblebug") - pressEnterKeyToContinue(isOn) - - resp, err := client.R(). - SetHeader("Content-Type", "application/json"). - Get(fmt.Sprintf("%s/tumblebug/health", endpointTB)) - - // Output print - fmt.Printf("\nError: %v\n", err) - fmt.Printf("Time: %v\n", resp.Time()) - fmt.Printf("Body: %v\n", resp) - - fmt.Println("##### End ---------- Step 1: Health-check CB-Tumblebug") - fmt.Println("Sleep 5 sec ( _ _ )zZ") - time.Sleep(5 * time.Second) - - // Step 2: Create MCIS dynamically - // POST ​/ns​/{nsId}​/mcisDynamic Create MCIS Dynamically - fmt.Println("\n\n##### Start ---------- Step 2: Create MCIS dynamically") - pressEnterKeyToContinue(isOn) - - reqBody := `{ - "description": "Made in CB-TB", - "installMonAgent": "no", - "label": "custom tag", - "name": "mcis01", - "vm": [ - { - "commonImage": "ubuntu18.04", - "commonSpec": "aws-ap-northeast-2-t2-large" - }, - { - "commonImage": "ubuntu18.04", - "commonSpec": "azure-westus-standard-b2s" - }, - { - "commonImage": "ubuntu18.04", - "commonSpec": "gcp-asia-east1-e2-standard-2" - } - ] -}` - - resp, err = client.R(). - SetHeader("Content-Type", "application/json"). - SetHeader("Accept", "application/json"). - SetPathParams(map[string]string{ - "nsId": nsID, - }). - SetBody(reqBody). - Post(fmt.Sprintf("%s/tumblebug/ns/{nsId}/mcisDynamic", endpointTB)) - - // Output print - fmt.Printf("\nError: %v\n", err) - fmt.Printf("Time: %v\n", resp.Time()) - fmt.Printf("Body: %v\n", resp) - - mcisStatus := gjson.Get(resp.String(), "status") - fmt.Printf("=====> status: %v \n", mcisStatus) - - fmt.Println("##### End ---------- Step 2: Create MCIS dynamically") - fmt.Println("Sleep 10 sec ( _ _ )zZ") - time.Sleep(10 * time.Second) - - // Step 3: Get VM address spaces - fmt.Println("\n\n##### Start ---------- Step 3: Get VM address spaces") - pressEnterKeyToContinue(isOn) - - tbMCISInfo := resp - - vNetIDs := []string{} - - retVMID := gjson.Get(tbMCISInfo.String(), "vm.1.id") - - retVNetIDs := gjson.Get(tbMCISInfo.String(), "vm.#.vNetId") - fmt.Printf("retVNetIDs: %#v\n", retVNetIDs) - - for _, vNetID := range retVNetIDs.Array() { - vNetIDs = append(vNetIDs, vNetID.String()) - } - fmt.Printf("vNetIds: %#v\n", vNetIDs) - - ipNetsInMCIS := []string{} - - for _, v := range vNetIDs { - - // Get VNet - // curl -X GET "http://localhost:1323/tumblebug/ns/ns01/resources/vNet/ns01-systemdefault-aws-ap-northeast-2" -H "accept: application/json" - fmt.Printf("\nvNetId: %v\n", v) - resp, err = client.R(). - SetHeader("Content-Type", "application/json"). - SetHeader("Accept", "application/json"). - SetPathParams(map[string]string{ - "nsId": nsID, - "vNetId": v, - }). - Get(fmt.Sprintf("%s/tumblebug/ns/{nsId}/resources/vNet/{vNetId}", endpointTB)) - - // Output print - fmt.Printf("\nError: %v\n", err) - fmt.Printf("Time: %v\n", resp.Time()) - fmt.Printf("Body: %v\n", resp) - - retIPv4CIDR := gjson.Get(resp.String(), "subnetInfoList.0.IPv4_CIDR") - fmt.Printf("retIPv4CIDR: %#v\n", retIPv4CIDR) - ipNetsInMCIS = append(ipNetsInMCIS, retIPv4CIDR.String()) - } - - fmt.Printf("IPNetsInMCIS: %#v\n", ipNetsInMCIS) - - fmt.Println("##### End ---------- Step 3: Get VM address spaces") - fmt.Println("Sleep 3 sec ( _ _ )zZ") - time.Sleep(3 * time.Second) - - // Step 4: Create a cloud adaptive network and get an ID of it - fmt.Println("\n\n##### Start ---------- Step 4: Create a cloud adaptive network and get an ID of it") - pressEnterKeyToContinue(isOn) - - cladnetSpec, err := createProperCloudAdaptiveNetwork(gRPCServiceEndpoint, ipNetsInMCIS, cladnetName, cladnetDescription) - if err != nil { - log.Printf("Could not create a cloud adaptive network: %v\n", err) - } - - log.Printf("Struct: %#v\n", cladnetSpec) - - fmt.Println("##### End ---------- Step 4: Create a cloud adaptive network and get an ID of it") - fmt.Println("Sleep 5 sec ( _ _ )zZ") - time.Sleep(5 * time.Second) - - // Step 5: Install the cb-network agent by sending a command to specified MCIS - fmt.Println("\n\n##### Start ---------- Step 5: Install the cb-network agent by sending a command to specified MCIS") - pressEnterKeyToContinue(isOn) - - placeHolderCommand := `wget https://raw.githubusercontent.com/cloud-barista/cb-larva/develop/poc-cb-net/scripts/1.deploy-cb-network-agent.sh -O ~/1.deploy-cb-network-agent.sh; chmod +x ~/1.deploy-cb-network-agent.sh; source ~/1.deploy-cb-network-agent.sh '%s' %s` - - etcdEndpointsJSON, _ := json.Marshal(config.ETCD.Endpoints) - etcdEndpointsString := string(etcdEndpointsJSON) - //fmt.Printf("etcdEndpointsString: %#v\n", etcdEndpointsString) - additionalEncodedString := strings.Replace(etcdEndpointsString, "\"", "\\\"", -1) - //fmt.Printf("additionalEncodedString: %#v\n", additionalEncodedString) - - command := fmt.Sprintf(placeHolderCommand, additionalEncodedString, cladnetSpec.ID) - fmt.Printf("command: %#v\n", command) - - body := fmt.Sprintf(placeHolderBody, command) - //fmt.Printf("body: %#v\n", body) - - resp, err = client.R(). - SetHeader("Content-Type", "application/json"). - SetHeader("Accept", "application/json"). - SetPathParams(map[string]string{ - "nsId": nsID, - "mcisId": mcisID, - }). - SetBody(body). - Post(fmt.Sprintf("%s/tumblebug/ns/{nsId}/cmd/mcis/{mcisId}", endpointTB)) - - // Output print - fmt.Printf("\nError: %v\n", err) - fmt.Printf("Time: %v\n", resp.Time()) - fmt.Printf("Body: %v\n", resp) - - fmt.Println("##### End ---------- Step 5: Install the cb-network agent by sending a command to specified MCIS") - fmt.Println("Sleep 5 sec ( _ _ )zZ") - time.Sleep(5 * time.Second) - - // Special stage ;) - char := askYesOrNoQuestion(isOn, "Do you want to deploy a single Kubernetes cluster across multi-clouds? (y/n)") - if char == "y" { - // Deploy a single Kubernetes cluster across multi-clouds (i.e., on MCIS) - deployKubernetesCluster(nsID, mcisID, retVMID.String()) - } - - char = askYesOrNoQuestion(isOn, "Do you want to clean MCIS? (y/n)") - if char == "y" { - // Step 6: Delete MCIS - // curl -X DELETE "http://localhost:1323/tumblebug/ns/ns01/mcis/mcis01?option=terminate" -H "accept: application/json" - fmt.Println("\n\n##### Start ---------- Step 6: Delete MCIS") - pressEnterKeyToContinue(isOn) - - resp, err = client.R(). - SetHeader("Content-Type", "application/json"). - SetHeader("Accept", "application/json"). - SetPathParams(map[string]string{ - "nsId": nsID, - "mcisId": mcisID, - }). - SetQueryParams(map[string]string{ - "option": "terminate", - }). - Delete(fmt.Sprintf("%s/tumblebug/ns/{nsId}/mcis/{mcisId}", endpointTB)) - - // Output print - fmt.Printf("\nError: %v\n", err) - fmt.Printf("Time: %v\n", resp.Time()) - fmt.Printf("Body: %v\n", resp) - - fmt.Println("##### End ---------- Step 6: Delete MCIS") - fmt.Println("Sleep 5 sec ( _ _ )zZ") - time.Sleep(5 * time.Second) - - // Step 7: Delete defaultResources - // curl -X DELETE "http://localhost:1323/tumblebug/ns/ns01/defaultResources" -H "accept: application/json" - fmt.Println("\n\n##### Start ---------- Step 7: Delete defaultResources") - pressEnterKeyToContinue(isOn) - - resp, err = client.R(). - SetHeader("Content-Type", "application/json"). - SetHeader("Accept", "application/json"). - SetPathParams(map[string]string{ - "nsId": nsID, - }). - Delete(fmt.Sprintf("%s/tumblebug/ns/{nsId}/defaultResources", endpointTB)) - - // Output print - fmt.Printf("\nError: %v\n", err) - fmt.Printf("Time: %v\n", resp.Time()) - fmt.Printf("Body: %v\n", resp) - - fmt.Println("##### End ---------- Step 7: Delete defaultResources") - } - - elapsed := time.Since(start) - fmt.Printf("Elapsed time: %s\n", elapsed) -} diff --git a/poc-cb-net/cmd/test-client/test-rest-call/test-rest-call.go b/poc-cb-net/cmd/test-client/test-rest-call/test-rest-call.go new file mode 100644 index 0000000..41eb205 --- /dev/null +++ b/poc-cb-net/cmd/test-client/test-rest-call/test-rest-call.go @@ -0,0 +1,50 @@ +package main + +import ( + "encoding/json" + "fmt" + + pb "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/api/gen/go/cbnetwork" + nethelper "github.com/cloud-barista/cb-larva/poc-cb-net/pkg/network-helper" + "github.com/go-resty/resty/v2" +) + +func main() { + // var placeHolder = `{"ipNetworks": %s }` + var ipNetworks = []string{ + "192.168.0.0/24", + "192.168.0.0/25", + "192.168.0.0/26", + "192.168.0.0/27", + "172.16.0.0/16", + "172.16.0.0/16", + "10.0.0.0/16", + "10.0.0.0/10", + } + + ipNets := &pb.IPNetworks{IpNetworks: ipNetworks} + + ipNetworksJSON, _ := json.Marshal(ipNets) + fmt.Println(string(ipNetworksJSON)) + // Set request body + // body := fmt.Sprintf(placeHolder, ipNetworksJson) + // fmt.Printf("body: %#v\n", body) + + client := resty.New() + // client.SetBasicAuth("default", "default") + resp, err := client.R(). + SetHeader("Content-Type", "application/json"). + SetHeader("Accept", "application/json"). + SetBody(ipNetworksJSON). + Post(fmt.Sprintf("%s/v1/cladnet/available-ipv4-address-spaces", "http://localhost:8053")) + // Output print + fmt.Printf("\nError: %v\n", err) + fmt.Printf("Time: %v\n", resp.Time()) + fmt.Printf("Body: %v\n", resp) + + var availableIPv4PrivateAddressSpaces nethelper.AvailableIPv4PrivateAddressSpaces + + json.Unmarshal(resp.Body(), &availableIPv4PrivateAddressSpaces) + + fmt.Printf("%#v\n", availableIPv4PrivateAddressSpaces) +} diff --git a/poc-cb-net/config/template-config.yaml b/poc-cb-net/config/template-config.yaml index 02ea54b..f8b0146 100644 --- a/poc-cb-net/config/template-config.yaml +++ b/poc-cb-net/config/template-config.yaml @@ -1,6 +1,6 @@ # A config for an etcd cluster (required for all cb-netwwork components): etcd_cluster: - endpoints: [ "xxx.xxx.xxx.xxx:xxx", "xxx.xxx.xxx.xxx:xxx", "xxx.xxx.xxx.xxx:xxx" ] + endpoints: [ "xxx.xxx.xxx.xxx:2379", "xxx.xxx.xxx.xxx:2379", "xxx.xxx.xxx.xxx:2379" ] # e.g., "123.123.123.123:2379" # A config for the cb-network admin-web as follows: admin_web: @@ -18,3 +18,6 @@ grpc: service_endpoint: "xxx.xxx.xxx.xxx:8053" # e.g., "localhost:8053" server_port: "8053" gateway_port: "8052" + +# A config for the demo-client as follows: +service_call_method: "grpc" # i.e., "rest" / "grpc" diff --git a/poc-cb-net/pkg/api/Makefile b/poc-cb-net/pkg/api/Makefile index 9e88d1c..efc6acf 100644 --- a/poc-cb-net/pkg/api/Makefile +++ b/poc-cb-net/pkg/api/Makefile @@ -1,3 +1,7 @@ +default: stub reverse_proxy + +all: stub reverse_proxy doc + stub: protoc -I ./proto \ --go_out ./gen/go --go_opt paths=source_relative \ diff --git a/poc-cb-net/pkg/api/gen/go/cbnetwork/cloud_adaptive_network.pb.go b/poc-cb-net/pkg/api/gen/go/cbnetwork/cloud_adaptive_network.pb.go index c311248..9a071c6 100644 --- a/poc-cb-net/pkg/api/gen/go/cbnetwork/cloud_adaptive_network.pb.go +++ b/poc-cb-net/pkg/api/gen/go/cbnetwork/cloud_adaptive_network.pb.go @@ -8,7 +8,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.27.1 +// protoc-gen-go v1.28.0 // protoc v3.17.3 // source: cbnetwork/cloud_adaptive_network.proto @@ -448,7 +448,7 @@ var file_cbnetwork_cloud_adaptive_network_proto_rawDesc = []byte{ 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x63, 0x62, 0x6e, 0x65, 0x74, 0x2e, 0x43, 0x4c, 0x41, 0x44, 0x4e, 0x65, 0x74, 0x53, 0x70, 0x65, 0x63, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x14, 0x63, 0x6c, 0x61, 0x64, 0x6e, 0x65, 0x74, 0x53, 0x70, 0x65, 0x63, 0x69, 0x66, - 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x32, 0xda, 0x05, 0x0a, 0x1b, 0x43, 0x6c, 0x6f, 0x75, + 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x32, 0xdd, 0x05, 0x0a, 0x1b, 0x43, 0x6c, 0x6f, 0x75, 0x64, 0x41, 0x64, 0x61, 0x70, 0x74, 0x69, 0x76, 0x65, 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x50, 0x0a, 0x08, 0x73, 0x61, 0x79, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, @@ -473,31 +473,31 @@ var file_cbnetwork_cloud_adaptive_network_proto_rawDesc = []byte{ 0x2e, 0x63, 0x62, 0x6e, 0x65, 0x74, 0x2e, 0x43, 0x4c, 0x41, 0x44, 0x4e, 0x65, 0x74, 0x53, 0x70, 0x65, 0x63, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x16, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x10, 0x22, 0x0b, 0x2f, 0x76, 0x31, 0x2f, 0x63, 0x6c, 0x61, 0x64, 0x6e, 0x65, 0x74, - 0x3a, 0x01, 0x2a, 0x12, 0x9c, 0x01, 0x0a, 0x2a, 0x72, 0x65, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, + 0x3a, 0x01, 0x2a, 0x12, 0x9f, 0x01, 0x0a, 0x2a, 0x72, 0x65, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x64, 0x41, 0x76, 0x61, 0x69, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x49, 0x50, 0x76, 0x34, 0x50, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x53, 0x70, 0x61, 0x63, 0x65, 0x73, 0x12, 0x11, 0x2e, 0x63, 0x62, 0x6e, 0x65, 0x74, 0x2e, 0x49, 0x50, 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x73, 0x1a, 0x28, 0x2e, 0x63, 0x62, 0x6e, 0x65, 0x74, 0x2e, 0x41, 0x76, 0x61, 0x69, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x49, 0x50, 0x76, 0x34, 0x50, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x53, 0x70, 0x61, 0x63, 0x65, 0x73, 0x22, - 0x31, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x2b, 0x12, 0x29, 0x2f, 0x76, 0x31, 0x2f, 0x63, 0x6c, 0x61, + 0x34, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x2e, 0x22, 0x29, 0x2f, 0x76, 0x31, 0x2f, 0x63, 0x6c, 0x61, 0x64, 0x6e, 0x65, 0x74, 0x2f, 0x61, 0x76, 0x61, 0x69, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x2d, 0x69, 0x70, 0x76, 0x34, 0x2d, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x2d, 0x73, 0x70, 0x61, 0x63, - 0x65, 0x73, 0x12, 0x4d, 0x0a, 0x0d, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x43, 0x4c, 0x41, 0x44, - 0x4e, 0x65, 0x74, 0x12, 0x10, 0x2e, 0x63, 0x62, 0x6e, 0x65, 0x74, 0x2e, 0x43, 0x4c, 0x41, 0x44, - 0x4e, 0x65, 0x74, 0x49, 0x44, 0x1a, 0x15, 0x2e, 0x63, 0x62, 0x6e, 0x65, 0x74, 0x2e, 0x44, 0x65, - 0x6c, 0x65, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x13, 0x82, 0xd3, - 0xe4, 0x93, 0x02, 0x0d, 0x2a, 0x0b, 0x2f, 0x76, 0x31, 0x2f, 0x63, 0x6c, 0x61, 0x64, 0x6e, 0x65, - 0x74, 0x12, 0x61, 0x0a, 0x0d, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x43, 0x4c, 0x41, 0x44, 0x4e, - 0x65, 0x74, 0x12, 0x1b, 0x2e, 0x63, 0x62, 0x6e, 0x65, 0x74, 0x2e, 0x43, 0x4c, 0x41, 0x44, 0x4e, - 0x65, 0x74, 0x53, 0x70, 0x65, 0x63, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x1a, - 0x1b, 0x2e, 0x63, 0x62, 0x6e, 0x65, 0x74, 0x2e, 0x43, 0x4c, 0x41, 0x44, 0x4e, 0x65, 0x74, 0x53, - 0x70, 0x65, 0x63, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x16, 0x82, 0xd3, - 0xe4, 0x93, 0x02, 0x10, 0x1a, 0x0b, 0x2f, 0x76, 0x31, 0x2f, 0x63, 0x6c, 0x61, 0x64, 0x6e, 0x65, - 0x74, 0x3a, 0x01, 0x2a, 0x42, 0x23, 0x5a, 0x21, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, - 0x6f, 0x6d, 0x2f, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x2d, 0x62, 0x61, 0x72, 0x69, 0x73, 0x74, 0x61, - 0x2f, 0x63, 0x62, 0x2d, 0x6c, 0x61, 0x72, 0x76, 0x61, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, + 0x65, 0x73, 0x3a, 0x01, 0x2a, 0x12, 0x4d, 0x0a, 0x0d, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x43, + 0x4c, 0x41, 0x44, 0x4e, 0x65, 0x74, 0x12, 0x10, 0x2e, 0x63, 0x62, 0x6e, 0x65, 0x74, 0x2e, 0x43, + 0x4c, 0x41, 0x44, 0x4e, 0x65, 0x74, 0x49, 0x44, 0x1a, 0x15, 0x2e, 0x63, 0x62, 0x6e, 0x65, 0x74, + 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, + 0x13, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0d, 0x2a, 0x0b, 0x2f, 0x76, 0x31, 0x2f, 0x63, 0x6c, 0x61, + 0x64, 0x6e, 0x65, 0x74, 0x12, 0x61, 0x0a, 0x0d, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x43, 0x4c, + 0x41, 0x44, 0x4e, 0x65, 0x74, 0x12, 0x1b, 0x2e, 0x63, 0x62, 0x6e, 0x65, 0x74, 0x2e, 0x43, 0x4c, + 0x41, 0x44, 0x4e, 0x65, 0x74, 0x53, 0x70, 0x65, 0x63, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x1a, 0x1b, 0x2e, 0x63, 0x62, 0x6e, 0x65, 0x74, 0x2e, 0x43, 0x4c, 0x41, 0x44, 0x4e, + 0x65, 0x74, 0x53, 0x70, 0x65, 0x63, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, + 0x16, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x10, 0x1a, 0x0b, 0x2f, 0x76, 0x31, 0x2f, 0x63, 0x6c, 0x61, + 0x64, 0x6e, 0x65, 0x74, 0x3a, 0x01, 0x2a, 0x42, 0x23, 0x5a, 0x21, 0x67, 0x69, 0x74, 0x68, 0x75, + 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x2d, 0x62, 0x61, 0x72, 0x69, + 0x73, 0x74, 0x61, 0x2f, 0x63, 0x62, 0x2d, 0x6c, 0x61, 0x72, 0x76, 0x61, 0x62, 0x06, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/poc-cb-net/pkg/api/gen/go/cbnetwork/cloud_adaptive_network.pb.gw.go b/poc-cb-net/pkg/api/gen/go/cbnetwork/cloud_adaptive_network.pb.gw.go index 7dee8ed..a2e8497 100644 --- a/poc-cb-net/pkg/api/gen/go/cbnetwork/cloud_adaptive_network.pb.gw.go +++ b/poc-cb-net/pkg/api/gen/go/cbnetwork/cloud_adaptive_network.pb.gw.go @@ -154,18 +154,15 @@ func local_request_CloudAdaptiveNetworkService_CreateCLADNet_0(ctx context.Conte } -var ( - filter_CloudAdaptiveNetworkService_RecommendAvailableIPv4PrivateAddressSpaces_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} -) - func request_CloudAdaptiveNetworkService_RecommendAvailableIPv4PrivateAddressSpaces_0(ctx context.Context, marshaler runtime.Marshaler, client CloudAdaptiveNetworkServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq IPNetworks var metadata runtime.ServerMetadata - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_CloudAdaptiveNetworkService_RecommendAvailableIPv4PrivateAddressSpaces_0); err != nil { + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } @@ -178,10 +175,11 @@ func local_request_CloudAdaptiveNetworkService_RecommendAvailableIPv4PrivateAddr var protoReq IPNetworks var metadata runtime.ServerMetadata - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_CloudAdaptiveNetworkService_RecommendAvailableIPv4PrivateAddressSpaces_0); err != nil { + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } @@ -272,12 +270,13 @@ func RegisterCloudAdaptiveNetworkServiceHandlerServer(ctx context.Context, mux * var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/cbnet.CloudAdaptiveNetworkService/SayHello", runtime.WithHTTPPathPattern("/hello")) + var err error + ctx, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/cbnet.CloudAdaptiveNetworkService/SayHello", runtime.WithHTTPPathPattern("/hello")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_CloudAdaptiveNetworkService_SayHello_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_CloudAdaptiveNetworkService_SayHello_0(ctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { @@ -295,12 +294,13 @@ func RegisterCloudAdaptiveNetworkServiceHandlerServer(ctx context.Context, mux * var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/cbnet.CloudAdaptiveNetworkService/GetCLADNet", runtime.WithHTTPPathPattern("/v1/cladnet/{value}")) + var err error + ctx, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/cbnet.CloudAdaptiveNetworkService/GetCLADNet", runtime.WithHTTPPathPattern("/v1/cladnet/{value}")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_CloudAdaptiveNetworkService_GetCLADNet_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_CloudAdaptiveNetworkService_GetCLADNet_0(ctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { @@ -318,12 +318,13 @@ func RegisterCloudAdaptiveNetworkServiceHandlerServer(ctx context.Context, mux * var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/cbnet.CloudAdaptiveNetworkService/GetCLADNetList", runtime.WithHTTPPathPattern("/v1/cladnet")) + var err error + ctx, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/cbnet.CloudAdaptiveNetworkService/GetCLADNetList", runtime.WithHTTPPathPattern("/v1/cladnet")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_CloudAdaptiveNetworkService_GetCLADNetList_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_CloudAdaptiveNetworkService_GetCLADNetList_0(ctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { @@ -341,12 +342,13 @@ func RegisterCloudAdaptiveNetworkServiceHandlerServer(ctx context.Context, mux * var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/cbnet.CloudAdaptiveNetworkService/CreateCLADNet", runtime.WithHTTPPathPattern("/v1/cladnet")) + var err error + ctx, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/cbnet.CloudAdaptiveNetworkService/CreateCLADNet", runtime.WithHTTPPathPattern("/v1/cladnet")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_CloudAdaptiveNetworkService_CreateCLADNet_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_CloudAdaptiveNetworkService_CreateCLADNet_0(ctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { @@ -358,18 +360,19 @@ func RegisterCloudAdaptiveNetworkServiceHandlerServer(ctx context.Context, mux * }) - mux.Handle("GET", pattern_CloudAdaptiveNetworkService_RecommendAvailableIPv4PrivateAddressSpaces_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("POST", pattern_CloudAdaptiveNetworkService_RecommendAvailableIPv4PrivateAddressSpaces_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/cbnet.CloudAdaptiveNetworkService/RecommendAvailableIPv4PrivateAddressSpaces", runtime.WithHTTPPathPattern("/v1/cladnet/available-ipv4-address-spaces")) + var err error + ctx, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/cbnet.CloudAdaptiveNetworkService/RecommendAvailableIPv4PrivateAddressSpaces", runtime.WithHTTPPathPattern("/v1/cladnet/available-ipv4-address-spaces")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_CloudAdaptiveNetworkService_RecommendAvailableIPv4PrivateAddressSpaces_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_CloudAdaptiveNetworkService_RecommendAvailableIPv4PrivateAddressSpaces_0(ctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { @@ -387,12 +390,13 @@ func RegisterCloudAdaptiveNetworkServiceHandlerServer(ctx context.Context, mux * var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/cbnet.CloudAdaptiveNetworkService/DeleteCLADNet", runtime.WithHTTPPathPattern("/v1/cladnet")) + var err error + ctx, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/cbnet.CloudAdaptiveNetworkService/DeleteCLADNet", runtime.WithHTTPPathPattern("/v1/cladnet")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_CloudAdaptiveNetworkService_DeleteCLADNet_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_CloudAdaptiveNetworkService_DeleteCLADNet_0(ctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { @@ -410,12 +414,13 @@ func RegisterCloudAdaptiveNetworkServiceHandlerServer(ctx context.Context, mux * var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/cbnet.CloudAdaptiveNetworkService/UpdateCLADNet", runtime.WithHTTPPathPattern("/v1/cladnet")) + var err error + ctx, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/cbnet.CloudAdaptiveNetworkService/UpdateCLADNet", runtime.WithHTTPPathPattern("/v1/cladnet")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_CloudAdaptiveNetworkService_UpdateCLADNet_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_CloudAdaptiveNetworkService_UpdateCLADNet_0(ctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { @@ -472,12 +477,13 @@ func RegisterCloudAdaptiveNetworkServiceHandlerClient(ctx context.Context, mux * ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req, "/cbnet.CloudAdaptiveNetworkService/SayHello", runtime.WithHTTPPathPattern("/hello")) + var err error + ctx, err = runtime.AnnotateContext(ctx, mux, req, "/cbnet.CloudAdaptiveNetworkService/SayHello", runtime.WithHTTPPathPattern("/hello")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_CloudAdaptiveNetworkService_SayHello_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_CloudAdaptiveNetworkService_SayHello_0(ctx, inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -492,12 +498,13 @@ func RegisterCloudAdaptiveNetworkServiceHandlerClient(ctx context.Context, mux * ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req, "/cbnet.CloudAdaptiveNetworkService/GetCLADNet", runtime.WithHTTPPathPattern("/v1/cladnet/{value}")) + var err error + ctx, err = runtime.AnnotateContext(ctx, mux, req, "/cbnet.CloudAdaptiveNetworkService/GetCLADNet", runtime.WithHTTPPathPattern("/v1/cladnet/{value}")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_CloudAdaptiveNetworkService_GetCLADNet_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_CloudAdaptiveNetworkService_GetCLADNet_0(ctx, inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -512,12 +519,13 @@ func RegisterCloudAdaptiveNetworkServiceHandlerClient(ctx context.Context, mux * ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req, "/cbnet.CloudAdaptiveNetworkService/GetCLADNetList", runtime.WithHTTPPathPattern("/v1/cladnet")) + var err error + ctx, err = runtime.AnnotateContext(ctx, mux, req, "/cbnet.CloudAdaptiveNetworkService/GetCLADNetList", runtime.WithHTTPPathPattern("/v1/cladnet")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_CloudAdaptiveNetworkService_GetCLADNetList_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_CloudAdaptiveNetworkService_GetCLADNetList_0(ctx, inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -532,12 +540,13 @@ func RegisterCloudAdaptiveNetworkServiceHandlerClient(ctx context.Context, mux * ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req, "/cbnet.CloudAdaptiveNetworkService/CreateCLADNet", runtime.WithHTTPPathPattern("/v1/cladnet")) + var err error + ctx, err = runtime.AnnotateContext(ctx, mux, req, "/cbnet.CloudAdaptiveNetworkService/CreateCLADNet", runtime.WithHTTPPathPattern("/v1/cladnet")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_CloudAdaptiveNetworkService_CreateCLADNet_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_CloudAdaptiveNetworkService_CreateCLADNet_0(ctx, inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -548,16 +557,17 @@ func RegisterCloudAdaptiveNetworkServiceHandlerClient(ctx context.Context, mux * }) - mux.Handle("GET", pattern_CloudAdaptiveNetworkService_RecommendAvailableIPv4PrivateAddressSpaces_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("POST", pattern_CloudAdaptiveNetworkService_RecommendAvailableIPv4PrivateAddressSpaces_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req, "/cbnet.CloudAdaptiveNetworkService/RecommendAvailableIPv4PrivateAddressSpaces", runtime.WithHTTPPathPattern("/v1/cladnet/available-ipv4-address-spaces")) + var err error + ctx, err = runtime.AnnotateContext(ctx, mux, req, "/cbnet.CloudAdaptiveNetworkService/RecommendAvailableIPv4PrivateAddressSpaces", runtime.WithHTTPPathPattern("/v1/cladnet/available-ipv4-address-spaces")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_CloudAdaptiveNetworkService_RecommendAvailableIPv4PrivateAddressSpaces_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_CloudAdaptiveNetworkService_RecommendAvailableIPv4PrivateAddressSpaces_0(ctx, inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -572,12 +582,13 @@ func RegisterCloudAdaptiveNetworkServiceHandlerClient(ctx context.Context, mux * ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req, "/cbnet.CloudAdaptiveNetworkService/DeleteCLADNet", runtime.WithHTTPPathPattern("/v1/cladnet")) + var err error + ctx, err = runtime.AnnotateContext(ctx, mux, req, "/cbnet.CloudAdaptiveNetworkService/DeleteCLADNet", runtime.WithHTTPPathPattern("/v1/cladnet")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_CloudAdaptiveNetworkService_DeleteCLADNet_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_CloudAdaptiveNetworkService_DeleteCLADNet_0(ctx, inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -592,12 +603,13 @@ func RegisterCloudAdaptiveNetworkServiceHandlerClient(ctx context.Context, mux * ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req, "/cbnet.CloudAdaptiveNetworkService/UpdateCLADNet", runtime.WithHTTPPathPattern("/v1/cladnet")) + var err error + ctx, err = runtime.AnnotateContext(ctx, mux, req, "/cbnet.CloudAdaptiveNetworkService/UpdateCLADNet", runtime.WithHTTPPathPattern("/v1/cladnet")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_CloudAdaptiveNetworkService_UpdateCLADNet_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_CloudAdaptiveNetworkService_UpdateCLADNet_0(ctx, inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) diff --git a/poc-cb-net/pkg/api/gen/go/cbnetwork/cloud_adaptive_network_grpc.pb.go b/poc-cb-net/pkg/api/gen/go/cbnetwork/cloud_adaptive_network_grpc.pb.go index 503a813..432766c 100644 --- a/poc-cb-net/pkg/api/gen/go/cbnetwork/cloud_adaptive_network_grpc.pb.go +++ b/poc-cb-net/pkg/api/gen/go/cbnetwork/cloud_adaptive_network_grpc.pb.go @@ -1,4 +1,8 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.2.0 +// - protoc v3.17.3 +// source: cbnetwork/cloud_adaptive_network.proto package cb_larva diff --git a/poc-cb-net/pkg/api/proto/cbnetwork/cloud_adaptive_network.proto b/poc-cb-net/pkg/api/proto/cbnetwork/cloud_adaptive_network.proto index 0055952..981cc51 100644 --- a/poc-cb-net/pkg/api/proto/cbnetwork/cloud_adaptive_network.proto +++ b/poc-cb-net/pkg/api/proto/cbnetwork/cloud_adaptive_network.proto @@ -116,7 +116,8 @@ service CloudAdaptiveNetworkService { // return available IPv4 private address spaces rpc recommendAvailableIPv4PrivateAddressSpaces(IPNetworks) returns (AvailableIPv4PrivateAddressSpaces){ option (google.api.http) = { - get: "/v1/cladnet/available-ipv4-address-spaces" + post: "/v1/cladnet/available-ipv4-address-spaces" + body: "*" }; } diff --git a/poc-cb-net/pkg/cb-network/cb-network.go b/poc-cb-net/pkg/cb-network/cb-network.go index 07d6c5d..cdec949 100644 --- a/poc-cb-net/pkg/cb-network/cb-network.go +++ b/poc-cb-net/pkg/cb-network/cb-network.go @@ -497,10 +497,11 @@ func (cbnetwork *CBNetwork) encapsulate(wg *sync.WaitGroup) error { } bufToWrite = ciphertext + plen = len(ciphertext) } // Send packet - nWriteToUDP, errWriteToUDP := cbnetwork.listenConnection.WriteToUDP(bufToWrite, remoteAddr) + nWriteToUDP, errWriteToUDP := cbnetwork.listenConnection.WriteToUDP(bufToWrite[:plen], remoteAddr) if errWriteToUDP != nil || nWriteToUDP == 0 { CBLogger.Errorf("Error(%d len): %s", nWriteToUDP, errWriteToUDP) } @@ -525,6 +526,9 @@ func (cbnetwork *CBNetwork) decapsulate(wg *sync.WaitGroup) error { CBLogger.Tracef("[Decapsulation] Received %d bytes from %v", n, addr) bufToWrite := buf[:n] + // if n < BUFFERSIZE-1 { + // buf[n+1] = '\n' + // } if cbnetwork.isEncryptionEnabled { // Decrypt ciphertext by private key @@ -540,6 +544,7 @@ func (cbnetwork *CBNetwork) decapsulate(wg *sync.WaitGroup) error { continue } bufToWrite = plaintext + n = len(plaintext) } // Parse header @@ -551,7 +556,7 @@ func (cbnetwork *CBNetwork) decapsulate(wg *sync.WaitGroup) error { // To be determined. // Write to TUN interface - nWrite, errWrite := cbnetwork.Interface.Write(bufToWrite) + nWrite, errWrite := cbnetwork.Interface.Write(bufToWrite[:n]) if errWrite != nil || nWrite == 0 { CBLogger.Errorf("Error(%d len): %s", nWrite, errWrite) } diff --git a/poc-cb-net/pkg/cb-network/model/config.go b/poc-cb-net/pkg/cb-network/model/config.go index 26288f5..a1d9c67 100644 --- a/poc-cb-net/pkg/cb-network/model/config.go +++ b/poc-cb-net/pkg/cb-network/model/config.go @@ -42,10 +42,11 @@ type GRPCConfig struct { // Config represents the configuration information for cb-network type Config struct { - ETCD ETCDConfig `yaml:"etcd_cluster"` - AdminWeb AdminWebConfig `yaml:"admin_web"` - CBNetwork CBNetworkConfig `yaml:"cb_network"` - GRPC GRPCConfig `yaml:"grpc"` + ETCD ETCDConfig `yaml:"etcd_cluster"` + AdminWeb AdminWebConfig `yaml:"admin_web"` + CBNetwork CBNetworkConfig `yaml:"cb_network"` + GRPC GRPCConfig `yaml:"grpc"` + ServiceCallMethod string `yaml:"service_call_method"` } // LoadConfig represents a function to read the configuration information from a file diff --git a/poc-cb-net/scripts/1.deploy-cb-network-agent.sh b/poc-cb-net/scripts/1.deploy-cb-network-agent.sh index 15f7af7..3ae7a44 100644 --- a/poc-cb-net/scripts/1.deploy-cb-network-agent.sh +++ b/poc-cb-net/scripts/1.deploy-cb-network-agent.sh @@ -70,6 +70,9 @@ grpc: server_port: "8053" gateway_port: "8052" +# A config for the demo-client as follows: +service_call_method: "grpc" # i.e., "rest" / "grpc" + EOF diff --git a/poc-cb-net/scripts/2.re-deploy-cb-network-agent.sh b/poc-cb-net/scripts/2.re-deploy-cb-network-agent.sh index b048cbc..2b7a22a 100644 --- a/poc-cb-net/scripts/2.re-deploy-cb-network-agent.sh +++ b/poc-cb-net/scripts/2.re-deploy-cb-network-agent.sh @@ -77,6 +77,9 @@ grpc: server_port: "8053" gateway_port: "8052" +# A config for the demo-client as follows: +service_call_method: "grpc" # i.e., "rest" / "grpc" + EOF diff --git a/poc-cb-net/scripts/build-and-run-agent-in-the-background.sh b/poc-cb-net/scripts/build-and-run-agent-in-the-background.sh index 977743c..83e329f 100644 --- a/poc-cb-net/scripts/build-and-run-agent-in-the-background.sh +++ b/poc-cb-net/scripts/build-and-run-agent-in-the-background.sh @@ -119,6 +119,9 @@ grpc: server_port: "8053" gateway_port: "8052" +# A config for the demo-client as follows: +service_call_method: "grpc" # i.e., "rest" / "grpc" + EOF diff --git a/poc-cb-net/scripts/build-and-run-agent.sh b/poc-cb-net/scripts/build-and-run-agent.sh index f28ef11..d8bd13e 100644 --- a/poc-cb-net/scripts/build-and-run-agent.sh +++ b/poc-cb-net/scripts/build-and-run-agent.sh @@ -119,6 +119,9 @@ grpc: server_port: "8053" gateway_port: "8052" +# A config for the demo-client as follows: +service_call_method: "grpc" # i.e., "rest" / "grpc" + EOF diff --git a/poc-cb-net/scripts/get-and-run-agent.sh b/poc-cb-net/scripts/get-and-run-agent.sh index 942d637..3a29348 100644 --- a/poc-cb-net/scripts/get-and-run-agent.sh +++ b/poc-cb-net/scripts/get-and-run-agent.sh @@ -69,6 +69,9 @@ grpc: server_port: "8053" gateway_port: "8052" +# A config for the demo-client as follows: +service_call_method: "grpc" # i.e., "rest" / "grpc" + EOF