(t *testing.T, numClients, numRouters int, fullyConnected bool)
| 9 | ) |
| 10 | |
| 11 | func SampleNetwork(t *testing.T, numClients, numRouters int, fullyConnected bool) (CentralCfg, map[string]NyPrivateKey) { |
| 12 | t.Helper() |
| 13 | keyStore := make(map[string]NyPrivateKey) |
| 14 | keyStore["dist"] = GenerateKey() |
| 15 | cfg := CentralCfg{ |
| 16 | Dist: &DistributionCfg{ |
| 17 | Key: keyStore["dist"].Pubkey(), |
| 18 | Repos: []string{ |
| 19 | "https://example.com", |
| 20 | "file:example.conf", |
| 21 | }, |
| 22 | }, |
| 23 | } |
| 24 | |
| 25 | clients := make([]string, numClients) |
| 26 | |
| 27 | for idx := range numClients { |
| 28 | client := fmt.Sprintf("client-%d", idx) |
| 29 | clients[idx] = client |
| 30 | keyStore[client] = GenerateKey() |
| 31 | cfg.Clients = append(cfg.Clients, ClientCfg{NodeCfg{ |
| 32 | Id: NodeId(client), |
| 33 | PubKey: keyStore[client].Pubkey(), |
| 34 | Prefixes: []PrefixHealthWrapper{ |
| 35 | { |
| 36 | &StaticPrefixHealth{ |
| 37 | Prefix: netip.MustParsePrefix(fmt.Sprintf("10.1.0.%d/32", idx)), |
| 38 | Metric: 0, |
| 39 | }, |
| 40 | }, |
| 41 | }, |
| 42 | }}) |
| 43 | } |
| 44 | |
| 45 | routers := make([]string, numRouters) |
| 46 | |
| 47 | for idx := range numRouters { |
| 48 | router := fmt.Sprintf("router-%d", idx) |
| 49 | routers[idx] = router |
| 50 | keyStore[router] = GenerateKey() |
| 51 | cfg.Routers = append(cfg.Routers, RouterCfg{ |
| 52 | NodeCfg: NodeCfg{ |
| 53 | Id: NodeId(router), |
| 54 | PubKey: keyStore[router].Pubkey(), |
| 55 | Prefixes: []PrefixHealthWrapper{ |
| 56 | { |
| 57 | &StaticPrefixHealth{ |
| 58 | Prefix: netip.MustParsePrefix(fmt.Sprintf("10.1.0.%d/32", idx)), |
| 59 | Metric: 0, |
| 60 | }, |
| 61 | }, |
| 62 | }, |
| 63 | }, |
| 64 | Endpoints: []*DynamicEndpoint{ |
| 65 | NewDynamicEndpoint(fmt.Sprintf("192.168.0.%d:25565", idx)), |
| 66 | }, |
| 67 | }) |
| 68 | } |
no test coverage detected