Lorenz Brun | 52f7f29 | 2020-06-24 16:42:02 +0200 | [diff] [blame] | 1 | // Copyright 2020 The Monogon Project Authors. |
| 2 | // |
| 3 | // SPDX-License-Identifier: Apache-2.0 |
| 4 | // |
| 5 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | // you may not use this file except in compliance with the License. |
| 7 | // You may obtain a copy of the License at |
| 8 | // |
| 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | // |
| 11 | // Unless required by applicable law or agreed to in writing, software |
| 12 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | // See the License for the specific language governing permissions and |
| 15 | // limitations under the License. |
| 16 | |
| 17 | package main |
| 18 | |
| 19 | import ( |
| 20 | "context" |
| 21 | "log" |
| 22 | "os" |
| 23 | "os/signal" |
| 24 | "syscall" |
| 25 | "time" |
| 26 | |
| 27 | grpcretry "github.com/grpc-ecosystem/go-grpc-middleware/retry" |
| 28 | "google.golang.org/grpc" |
| 29 | |
Lorenz Brun | 52f7f29 | 2020-06-24 16:42:02 +0200 | [diff] [blame] | 30 | "git.monogon.dev/source/nexantic.git/core/internal/common" |
| 31 | "git.monogon.dev/source/nexantic.git/core/internal/launch" |
Lorenz Brun | 52f7f29 | 2020-06-24 16:42:02 +0200 | [diff] [blame] | 32 | ) |
| 33 | |
| 34 | func main() { |
| 35 | sigs := make(chan os.Signal, 1) |
| 36 | signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) |
| 37 | ctx, cancel := context.WithCancel(context.Background()) |
| 38 | go func() { |
| 39 | <-sigs |
| 40 | cancel() |
| 41 | }() |
| 42 | sw0, vm0, err := launch.NewSocketPair() |
| 43 | if err != nil { |
| 44 | log.Fatalf("Failed to create network pipe: %v\n", err) |
| 45 | } |
| 46 | sw1, vm1, err := launch.NewSocketPair() |
| 47 | if err != nil { |
| 48 | log.Fatalf("Failed to create network pipe: %v\n", err) |
| 49 | } |
| 50 | |
| 51 | go func() { |
| 52 | if err := launch.Launch(ctx, launch.Options{ConnectToSocket: vm0, SerialPort: os.Stdout}); err != nil { |
| 53 | log.Fatalf("Failed to launch vm0: %v", err) |
| 54 | } |
| 55 | }() |
| 56 | nanoswitchPortMap := make(launch.PortMap) |
| 57 | identityPorts := []uint16{ |
| 58 | common.ExternalServicePort, |
| 59 | common.DebugServicePort, |
| 60 | common.KubernetesAPIPort, |
| 61 | } |
| 62 | for _, port := range identityPorts { |
| 63 | nanoswitchPortMap[port] = port |
| 64 | } |
| 65 | go func() { |
| 66 | opts := []grpcretry.CallOption{ |
| 67 | grpcretry.WithBackoff(grpcretry.BackoffExponential(100 * time.Millisecond)), |
| 68 | } |
| 69 | conn, err := nanoswitchPortMap.DialGRPC(common.ExternalServicePort, grpc.WithInsecure(), |
| 70 | grpc.WithUnaryInterceptor(grpcretry.UnaryClientInterceptor(opts...))) |
| 71 | if err != nil { |
| 72 | panic(err) |
| 73 | } |
| 74 | defer conn.Close() |
Serge Bazanski | 1ebd1e1 | 2020-07-13 19:17:16 +0200 | [diff] [blame^] | 75 | // TODO(D591): this gets implemented there. |
| 76 | _ = vm1 |
| 77 | panic("unimplemented") |
Lorenz Brun | 52f7f29 | 2020-06-24 16:42:02 +0200 | [diff] [blame] | 78 | }() |
| 79 | if err := launch.RunMicroVM(ctx, &launch.MicroVMOptions{ |
| 80 | SerialPort: os.Stdout, |
| 81 | KernelPath: "core/tools/ktest/linux-testing.elf", |
| 82 | InitramfsPath: "core/cmd/nanoswitch/initramfs.lz4", |
| 83 | ExtraNetworkInterfaces: []*os.File{sw0, sw1}, |
| 84 | PortMap: nanoswitchPortMap, |
| 85 | }); err != nil { |
| 86 | log.Fatalf("Failed to launch nanoswitch: %v", err) |
| 87 | } |
| 88 | } |