allocator_test.go 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245
  1. package ipam
  2. import (
  3. "encoding/json"
  4. "flag"
  5. "fmt"
  6. "io/ioutil"
  7. "math/rand"
  8. "net"
  9. "strconv"
  10. "testing"
  11. "time"
  12. "github.com/docker/libkv/store"
  13. "github.com/docker/libnetwork/bitseq"
  14. "github.com/docker/libnetwork/datastore"
  15. "github.com/docker/libnetwork/ipamapi"
  16. "github.com/docker/libnetwork/ipamutils"
  17. _ "github.com/docker/libnetwork/testutils"
  18. "github.com/docker/libnetwork/types"
  19. )
  20. const (
  21. defaultPrefix = "/tmp/libnetwork/test/ipam"
  22. )
  23. // OptionBoltdbWithRandomDBFile function returns a random dir for local store backend
  24. func randomLocalStore() (datastore.DataStore, error) {
  25. tmp, err := ioutil.TempFile("", "libnetwork-")
  26. if err != nil {
  27. return nil, fmt.Errorf("Error creating temp file: %v", err)
  28. }
  29. if err := tmp.Close(); err != nil {
  30. return nil, fmt.Errorf("Error closing temp file: %v", err)
  31. }
  32. return datastore.NewDataStore(datastore.LocalScope, &datastore.ScopeCfg{
  33. Client: datastore.ScopeClientCfg{
  34. Provider: "boltdb",
  35. Address: defaultPrefix + tmp.Name(),
  36. Config: &store.Config{
  37. Bucket: "libnetwork",
  38. ConnectionTimeout: 3 * time.Second,
  39. },
  40. },
  41. })
  42. }
  43. func getAllocator() (*Allocator, error) {
  44. ipamutils.InitNetworks()
  45. ds, err := randomLocalStore()
  46. if err != nil {
  47. return nil, err
  48. }
  49. a, err := NewAllocator(ds, nil)
  50. if err != nil {
  51. return nil, err
  52. }
  53. return a, nil
  54. }
  55. func TestInt2IP2IntConversion(t *testing.T) {
  56. for i := uint64(0); i < 256*256*256; i++ {
  57. var array [4]byte // new array at each cycle
  58. addIntToIP(array[:], i)
  59. j := ipToUint64(array[:])
  60. if j != i {
  61. t.Fatalf("Failed to convert ordinal %d to IP % x and back to ordinal. Got %d", i, array, j)
  62. }
  63. }
  64. }
  65. func TestGetAddressVersion(t *testing.T) {
  66. if v4 != getAddressVersion(net.ParseIP("172.28.30.112")) {
  67. t.Fatalf("Failed to detect IPv4 version")
  68. }
  69. if v4 != getAddressVersion(net.ParseIP("0.0.0.1")) {
  70. t.Fatalf("Failed to detect IPv4 version")
  71. }
  72. if v6 != getAddressVersion(net.ParseIP("ff01::1")) {
  73. t.Fatalf("Failed to detect IPv6 version")
  74. }
  75. if v6 != getAddressVersion(net.ParseIP("2001:db8::76:51")) {
  76. t.Fatalf("Failed to detect IPv6 version")
  77. }
  78. }
  79. func TestKeyString(t *testing.T) {
  80. k := &SubnetKey{AddressSpace: "default", Subnet: "172.27.0.0/16"}
  81. expected := "default/172.27.0.0/16"
  82. if expected != k.String() {
  83. t.Fatalf("Unexpected key string: %s", k.String())
  84. }
  85. k2 := &SubnetKey{}
  86. err := k2.FromString(expected)
  87. if err != nil {
  88. t.Fatal(err)
  89. }
  90. if k2.AddressSpace != k.AddressSpace || k2.Subnet != k.Subnet {
  91. t.Fatalf("SubnetKey.FromString() failed. Expected %v. Got %v", k, k2)
  92. }
  93. expected = fmt.Sprintf("%s/%s", expected, "172.27.3.0/24")
  94. k.ChildSubnet = "172.27.3.0/24"
  95. if expected != k.String() {
  96. t.Fatalf("Unexpected key string: %s", k.String())
  97. }
  98. err = k2.FromString(expected)
  99. if err != nil {
  100. t.Fatal(err)
  101. }
  102. if k2.AddressSpace != k.AddressSpace || k2.Subnet != k.Subnet || k2.ChildSubnet != k.ChildSubnet {
  103. t.Fatalf("SubnetKey.FromString() failed. Expected %v. Got %v", k, k2)
  104. }
  105. }
  106. func TestPoolDataMarshal(t *testing.T) {
  107. _, nw, err := net.ParseCIDR("172.28.30.1/24")
  108. if err != nil {
  109. t.Fatal(err)
  110. }
  111. p := &PoolData{
  112. ParentKey: SubnetKey{AddressSpace: "Blue", Subnet: "172.28.0.0/16"},
  113. Pool: nw,
  114. Range: &AddressRange{Sub: &net.IPNet{IP: net.IP{172, 28, 20, 0}, Mask: net.IPMask{255, 255, 255, 0}}, Start: 0, End: 255},
  115. RefCount: 4,
  116. }
  117. ba, err := json.Marshal(p)
  118. if err != nil {
  119. t.Fatal(err)
  120. }
  121. var q PoolData
  122. err = json.Unmarshal(ba, &q)
  123. if err != nil {
  124. t.Fatal(err)
  125. }
  126. if p.ParentKey != q.ParentKey || !types.CompareIPNet(p.Range.Sub, q.Range.Sub) ||
  127. p.Range.Start != q.Range.Start || p.Range.End != q.Range.End || p.RefCount != q.RefCount ||
  128. !types.CompareIPNet(p.Pool, q.Pool) {
  129. t.Fatalf("\n%#v\n%#v", p, &q)
  130. }
  131. p = &PoolData{
  132. ParentKey: SubnetKey{AddressSpace: "Blue", Subnet: "172.28.0.0/16"},
  133. Pool: nw,
  134. RefCount: 4,
  135. }
  136. ba, err = json.Marshal(p)
  137. if err != nil {
  138. t.Fatal(err)
  139. }
  140. err = json.Unmarshal(ba, &q)
  141. if err != nil {
  142. t.Fatal(err)
  143. }
  144. if q.Range != nil {
  145. t.Fatalf("Unexpected Range")
  146. }
  147. }
  148. func TestSubnetsMarshal(t *testing.T) {
  149. a, err := getAllocator()
  150. if err != nil {
  151. t.Fatal(err)
  152. }
  153. pid0, _, _, err := a.RequestPool(localAddressSpace, "192.168.0.0/16", "", nil, false)
  154. if err != nil {
  155. t.Fatal(err)
  156. }
  157. pid1, _, _, err := a.RequestPool(localAddressSpace, "192.169.0.0/16", "", nil, false)
  158. if err != nil {
  159. t.Fatal(err)
  160. }
  161. _, _, err = a.RequestAddress(pid0, nil, nil)
  162. if err != nil {
  163. t.Fatal(err)
  164. }
  165. cfg, err := a.getAddrSpace(localAddressSpace)
  166. if err != nil {
  167. t.Fatal(err)
  168. }
  169. ba := cfg.Value()
  170. if err := cfg.SetValue(ba); err != nil {
  171. t.Fatal(err)
  172. }
  173. expIP := &net.IPNet{IP: net.IP{192, 168, 0, 2}, Mask: net.IPMask{255, 255, 0, 0}}
  174. ip, _, err := a.RequestAddress(pid0, nil, nil)
  175. if err != nil {
  176. t.Fatal(err)
  177. }
  178. if !types.CompareIPNet(expIP, ip) {
  179. t.Fatalf("Got unexpected ip after pool config restore: %s", ip)
  180. }
  181. expIP = &net.IPNet{IP: net.IP{192, 169, 0, 1}, Mask: net.IPMask{255, 255, 0, 0}}
  182. ip, _, err = a.RequestAddress(pid1, nil, nil)
  183. if err != nil {
  184. t.Fatal(err)
  185. }
  186. if !types.CompareIPNet(expIP, ip) {
  187. t.Fatalf("Got unexpected ip after pool config restore: %s", ip)
  188. }
  189. }
  190. func TestAddSubnets(t *testing.T) {
  191. a, err := getAllocator()
  192. if err != nil {
  193. t.Fatal(err)
  194. }
  195. a.addrSpaces["abc"] = a.addrSpaces[localAddressSpace]
  196. pid0, _, _, err := a.RequestPool(localAddressSpace, "10.0.0.0/8", "", nil, false)
  197. if err != nil {
  198. t.Fatalf("Unexpected failure in adding subnet")
  199. }
  200. pid1, _, _, err := a.RequestPool("abc", "10.0.0.0/8", "", nil, false)
  201. if err != nil {
  202. t.Fatalf("Unexpected failure in adding overlapping subnets to different address spaces: %v", err)
  203. }
  204. if pid0 == pid1 {
  205. t.Fatalf("returned same pool id for same subnets in different namespaces")
  206. }
  207. pid, _, _, err := a.RequestPool("abc", "10.0.0.0/8", "", nil, false)
  208. if err != nil {
  209. t.Fatalf("Unexpected failure requesting existing subnet: %v", err)
  210. }
  211. if pid != pid1 {
  212. t.Fatalf("returned different pool id for same subnet requests")
  213. }
  214. _, _, _, err = a.RequestPool("abc", "10.128.0.0/9", "", nil, false)
  215. if err == nil {
  216. t.Fatalf("Expected failure on adding overlapping base subnet")
  217. }
  218. pid2, _, _, err := a.RequestPool("abc", "10.0.0.0/8", "10.128.0.0/9", nil, false)
  219. if err != nil {
  220. t.Fatalf("Unexpected failure on adding sub pool: %v", err)
  221. }
  222. pid3, _, _, err := a.RequestPool("abc", "10.0.0.0/8", "10.128.0.0/9", nil, false)
  223. if err != nil {
  224. t.Fatalf("Unexpected failure on adding overlapping sub pool: %v", err)
  225. }
  226. if pid2 != pid3 {
  227. t.Fatalf("returned different pool id for same sub pool requests")
  228. }
  229. pid, _, _, err = a.RequestPool(localAddressSpace, "10.20.2.0/24", "", nil, false)
  230. if err == nil {
  231. t.Fatalf("Failed to detect overlapping subnets")
  232. }
  233. _, _, _, err = a.RequestPool(localAddressSpace, "10.128.0.0/9", "", nil, false)
  234. if err == nil {
  235. t.Fatalf("Failed to detect overlapping subnets")
  236. }
  237. _, _, _, err = a.RequestPool(localAddressSpace, "1003:1:2:3:4:5:6::/112", "", nil, false)
  238. if err != nil {
  239. t.Fatalf("Failed to add v6 subnet: %s", err.Error())
  240. }
  241. _, _, _, err = a.RequestPool(localAddressSpace, "1003:1:2:3::/64", "", nil, false)
  242. if err == nil {
  243. t.Fatalf("Failed to detect overlapping v6 subnet")
  244. }
  245. }
  246. func TestAddReleasePoolID(t *testing.T) {
  247. var k0, k1, k2 SubnetKey
  248. a, err := getAllocator()
  249. if err != nil {
  250. t.Fatal(err)
  251. }
  252. aSpace, err := a.getAddrSpace(localAddressSpace)
  253. if err != nil {
  254. t.Fatal(err)
  255. }
  256. subnets := aSpace.subnets
  257. pid0, _, _, err := a.RequestPool(localAddressSpace, "10.0.0.0/8", "", nil, false)
  258. if err != nil {
  259. t.Fatalf("Unexpected failure in adding pool")
  260. }
  261. if err := k0.FromString(pid0); err != nil {
  262. t.Fatal(err)
  263. }
  264. aSpace, err = a.getAddrSpace(localAddressSpace)
  265. if err != nil {
  266. t.Fatal(err)
  267. }
  268. subnets = aSpace.subnets
  269. if subnets[k0].RefCount != 1 {
  270. t.Fatalf("Unexpected ref count for %s: %d", k0, subnets[k0].RefCount)
  271. }
  272. pid1, _, _, err := a.RequestPool(localAddressSpace, "10.0.0.0/8", "10.0.0.0/16", nil, false)
  273. if err != nil {
  274. t.Fatalf("Unexpected failure in adding sub pool")
  275. }
  276. if err := k1.FromString(pid1); err != nil {
  277. t.Fatal(err)
  278. }
  279. aSpace, err = a.getAddrSpace(localAddressSpace)
  280. if err != nil {
  281. t.Fatal(err)
  282. }
  283. subnets = aSpace.subnets
  284. if subnets[k1].RefCount != 1 {
  285. t.Fatalf("Unexpected ref count for %s: %d", k1, subnets[k1].RefCount)
  286. }
  287. pid2, _, _, err := a.RequestPool(localAddressSpace, "10.0.0.0/8", "10.0.0.0/16", nil, false)
  288. if err != nil {
  289. t.Fatalf("Unexpected failure in adding sub pool")
  290. }
  291. if pid0 == pid1 || pid0 == pid2 || pid1 != pid2 {
  292. t.Fatalf("Incorrect poolIDs returned %s, %s, %s", pid0, pid1, pid2)
  293. }
  294. if err := k2.FromString(pid2); err != nil {
  295. t.Fatal(err)
  296. }
  297. aSpace, err = a.getAddrSpace(localAddressSpace)
  298. if err != nil {
  299. t.Fatal(err)
  300. }
  301. subnets = aSpace.subnets
  302. if subnets[k2].RefCount != 2 {
  303. t.Fatalf("Unexpected ref count for %s: %d", k2, subnets[k2].RefCount)
  304. }
  305. if subnets[k0].RefCount != 3 {
  306. t.Fatalf("Unexpected ref count for %s: %d", k0, subnets[k0].RefCount)
  307. }
  308. if err := a.ReleasePool(pid1); err != nil {
  309. t.Fatal(err)
  310. }
  311. aSpace, err = a.getAddrSpace(localAddressSpace)
  312. if err != nil {
  313. t.Fatal(err)
  314. }
  315. subnets = aSpace.subnets
  316. if subnets[k0].RefCount != 2 {
  317. t.Fatalf("Unexpected ref count for %s: %d", k0, subnets[k0].RefCount)
  318. }
  319. if err := a.ReleasePool(pid0); err != nil {
  320. t.Fatal(err)
  321. }
  322. aSpace, err = a.getAddrSpace(localAddressSpace)
  323. if err != nil {
  324. t.Fatal(err)
  325. }
  326. subnets = aSpace.subnets
  327. if subnets[k0].RefCount != 1 {
  328. t.Fatalf("Unexpected ref count for %s: %d", k0, subnets[k0].RefCount)
  329. }
  330. pid00, _, _, err := a.RequestPool(localAddressSpace, "10.0.0.0/8", "", nil, false)
  331. if err != nil {
  332. t.Fatalf("Unexpected failure in adding pool")
  333. }
  334. if pid00 != pid0 {
  335. t.Fatalf("main pool should still exist")
  336. }
  337. aSpace, err = a.getAddrSpace(localAddressSpace)
  338. if err != nil {
  339. t.Fatal(err)
  340. }
  341. subnets = aSpace.subnets
  342. if subnets[k0].RefCount != 2 {
  343. t.Fatalf("Unexpected ref count for %s: %d", k0, subnets[k0].RefCount)
  344. }
  345. if err := a.ReleasePool(pid2); err != nil {
  346. t.Fatal(err)
  347. }
  348. aSpace, err = a.getAddrSpace(localAddressSpace)
  349. if err != nil {
  350. t.Fatal(err)
  351. }
  352. subnets = aSpace.subnets
  353. if subnets[k0].RefCount != 1 {
  354. t.Fatalf("Unexpected ref count for %s: %d", k0, subnets[k0].RefCount)
  355. }
  356. if err := a.ReleasePool(pid00); err != nil {
  357. t.Fatal(err)
  358. }
  359. aSpace, err = a.getAddrSpace(localAddressSpace)
  360. if err != nil {
  361. t.Fatal(err)
  362. }
  363. subnets = aSpace.subnets
  364. if bp, ok := subnets[k0]; ok {
  365. t.Fatalf("Base pool %s is still present: %v", k0, bp)
  366. }
  367. _, _, _, err = a.RequestPool(localAddressSpace, "10.0.0.0/8", "", nil, false)
  368. if err != nil {
  369. t.Fatalf("Unexpected failure in adding pool")
  370. }
  371. aSpace, err = a.getAddrSpace(localAddressSpace)
  372. if err != nil {
  373. t.Fatal(err)
  374. }
  375. subnets = aSpace.subnets
  376. if subnets[k0].RefCount != 1 {
  377. t.Fatalf("Unexpected ref count for %s: %d", k0, subnets[k0].RefCount)
  378. }
  379. }
  380. func TestPredefinedPool(t *testing.T) {
  381. a, err := getAllocator()
  382. if err != nil {
  383. t.Fatal(err)
  384. }
  385. if _, err := a.getPredefinedPool("blue", false); err == nil {
  386. t.Fatalf("Expected failure for non default addr space")
  387. }
  388. pid, nw, _, err := a.RequestPool(localAddressSpace, "", "", nil, false)
  389. if err != nil {
  390. t.Fatal(err)
  391. }
  392. nw2, err := a.getPredefinedPool(localAddressSpace, false)
  393. if err != nil {
  394. t.Fatal(err)
  395. }
  396. if types.CompareIPNet(nw, nw2) {
  397. t.Fatalf("Unexpected default network returned: %s = %s", nw2, nw)
  398. }
  399. if err := a.ReleasePool(pid); err != nil {
  400. t.Fatal(err)
  401. }
  402. }
  403. func TestRemoveSubnet(t *testing.T) {
  404. a, err := getAllocator()
  405. if err != nil {
  406. t.Fatal(err)
  407. }
  408. a.addrSpaces["splane"] = &addrSpace{
  409. id: dsConfigKey + "/" + "splane",
  410. ds: a.addrSpaces[localAddressSpace].ds,
  411. alloc: a.addrSpaces[localAddressSpace].alloc,
  412. scope: a.addrSpaces[localAddressSpace].scope,
  413. subnets: map[SubnetKey]*PoolData{},
  414. }
  415. input := []struct {
  416. addrSpace string
  417. subnet string
  418. v6 bool
  419. }{
  420. {localAddressSpace, "192.168.0.0/16", false},
  421. {localAddressSpace, "172.17.0.0/16", false},
  422. {localAddressSpace, "10.0.0.0/8", false},
  423. {localAddressSpace, "2001:db8:1:2:3:4:ffff::/112", false},
  424. {"splane", "172.17.0.0/16", false},
  425. {"splane", "10.0.0.0/8", false},
  426. {"splane", "2001:db8:1:2:3:4:5::/112", true},
  427. {"splane", "2001:db8:1:2:3:4:ffff::/112", true},
  428. }
  429. poolIDs := make([]string, len(input))
  430. for ind, i := range input {
  431. if poolIDs[ind], _, _, err = a.RequestPool(i.addrSpace, i.subnet, "", nil, i.v6); err != nil {
  432. t.Fatalf("Failed to apply input. Can't proceed: %s", err.Error())
  433. }
  434. }
  435. for ind, id := range poolIDs {
  436. if err := a.ReleasePool(id); err != nil {
  437. t.Fatalf("Failed to release poolID %s (%d)", id, ind)
  438. }
  439. }
  440. }
  441. func TestGetSameAddress(t *testing.T) {
  442. a, err := getAllocator()
  443. if err != nil {
  444. t.Fatal(err)
  445. }
  446. a.addrSpaces["giallo"] = &addrSpace{
  447. id: dsConfigKey + "/" + "giallo",
  448. ds: a.addrSpaces[localAddressSpace].ds,
  449. alloc: a.addrSpaces[localAddressSpace].alloc,
  450. scope: a.addrSpaces[localAddressSpace].scope,
  451. subnets: map[SubnetKey]*PoolData{},
  452. }
  453. pid, _, _, err := a.RequestPool("giallo", "192.168.100.0/24", "", nil, false)
  454. if err != nil {
  455. t.Fatal(err)
  456. }
  457. ip := net.ParseIP("192.168.100.250")
  458. _, _, err = a.RequestAddress(pid, ip, nil)
  459. if err != nil {
  460. t.Fatal(err)
  461. }
  462. _, _, err = a.RequestAddress(pid, ip, nil)
  463. if err == nil {
  464. t.Fatal(err)
  465. }
  466. }
  467. func TestGetAddressSubPoolEqualPool(t *testing.T) {
  468. a, err := getAllocator()
  469. if err != nil {
  470. t.Fatal(err)
  471. }
  472. // Requesting a subpool of same size of the master pool should not cause any problem on ip allocation
  473. pid, _, _, err := a.RequestPool(localAddressSpace, "172.18.0.0/16", "172.18.0.0/16", nil, false)
  474. if err != nil {
  475. t.Fatal(err)
  476. }
  477. _, _, err = a.RequestAddress(pid, nil, nil)
  478. if err != nil {
  479. t.Fatal(err)
  480. }
  481. }
  482. func TestRequestReleaseAddressFromSubPool(t *testing.T) {
  483. a, err := getAllocator()
  484. if err != nil {
  485. t.Fatal(err)
  486. }
  487. a.addrSpaces["rosso"] = &addrSpace{
  488. id: dsConfigKey + "/" + "rosso",
  489. ds: a.addrSpaces[localAddressSpace].ds,
  490. alloc: a.addrSpaces[localAddressSpace].alloc,
  491. scope: a.addrSpaces[localAddressSpace].scope,
  492. subnets: map[SubnetKey]*PoolData{},
  493. }
  494. poolID, _, _, err := a.RequestPool("rosso", "172.28.0.0/16", "172.28.30.0/24", nil, false)
  495. if err != nil {
  496. t.Fatal(err)
  497. }
  498. var ip *net.IPNet
  499. expected := &net.IPNet{IP: net.IP{172, 28, 30, 255}, Mask: net.IPMask{255, 255, 0, 0}}
  500. for err == nil {
  501. var c *net.IPNet
  502. if c, _, err = a.RequestAddress(poolID, nil, nil); err == nil {
  503. ip = c
  504. }
  505. }
  506. if err != ipamapi.ErrNoAvailableIPs {
  507. t.Fatal(err)
  508. }
  509. if !types.CompareIPNet(expected, ip) {
  510. t.Fatalf("Unexpected last IP from subpool. Expected: %s. Got: %v.", expected, ip)
  511. }
  512. rp := &net.IPNet{IP: net.IP{172, 28, 30, 97}, Mask: net.IPMask{255, 255, 0, 0}}
  513. if err = a.ReleaseAddress(poolID, rp.IP); err != nil {
  514. t.Fatal(err)
  515. }
  516. if ip, _, err = a.RequestAddress(poolID, nil, nil); err != nil {
  517. t.Fatal(err)
  518. }
  519. if !types.CompareIPNet(rp, ip) {
  520. t.Fatalf("Unexpected IP from subpool. Expected: %s. Got: %v.", rp, ip)
  521. }
  522. _, _, _, err = a.RequestPool("rosso", "10.0.0.0/8", "10.0.0.0/16", nil, false)
  523. if err != nil {
  524. t.Fatal(err)
  525. }
  526. poolID, _, _, err = a.RequestPool("rosso", "10.0.0.0/16", "10.0.0.0/24", nil, false)
  527. if err != nil {
  528. t.Fatal(err)
  529. }
  530. expected = &net.IPNet{IP: net.IP{10, 0, 0, 255}, Mask: net.IPMask{255, 255, 0, 0}}
  531. for err == nil {
  532. var c *net.IPNet
  533. if c, _, err = a.RequestAddress(poolID, nil, nil); err == nil {
  534. ip = c
  535. }
  536. }
  537. if err != ipamapi.ErrNoAvailableIPs {
  538. t.Fatal(err)
  539. }
  540. if !types.CompareIPNet(expected, ip) {
  541. t.Fatalf("Unexpected last IP from subpool. Expected: %s. Got: %v.", expected, ip)
  542. }
  543. rp = &net.IPNet{IP: net.IP{10, 0, 0, 79}, Mask: net.IPMask{255, 255, 0, 0}}
  544. if err = a.ReleaseAddress(poolID, rp.IP); err != nil {
  545. t.Fatal(err)
  546. }
  547. if ip, _, err = a.RequestAddress(poolID, nil, nil); err != nil {
  548. t.Fatal(err)
  549. }
  550. if !types.CompareIPNet(rp, ip) {
  551. t.Fatalf("Unexpected IP from subpool. Expected: %s. Got: %v.", rp, ip)
  552. }
  553. // Request any addresses from subpool after explicit address request
  554. unoExp, _ := types.ParseCIDR("10.2.2.0/16")
  555. dueExp, _ := types.ParseCIDR("10.2.2.2/16")
  556. treExp, _ := types.ParseCIDR("10.2.2.1/16")
  557. if poolID, _, _, err = a.RequestPool("rosso", "10.2.0.0/16", "10.2.2.0/24", nil, false); err != nil {
  558. t.Fatal(err)
  559. }
  560. tre, _, err := a.RequestAddress(poolID, treExp.IP, nil)
  561. if err != nil {
  562. t.Fatal(err)
  563. }
  564. if !types.CompareIPNet(tre, treExp) {
  565. t.Fatalf("Unexpected address: %v", tre)
  566. }
  567. uno, _, err := a.RequestAddress(poolID, nil, nil)
  568. if err != nil {
  569. t.Fatal(err)
  570. }
  571. if !types.CompareIPNet(uno, unoExp) {
  572. t.Fatalf("Unexpected address: %v", uno)
  573. }
  574. due, _, err := a.RequestAddress(poolID, nil, nil)
  575. if err != nil {
  576. t.Fatal(err)
  577. }
  578. if !types.CompareIPNet(due, dueExp) {
  579. t.Fatalf("Unexpected address: %v", due)
  580. }
  581. if err = a.ReleaseAddress(poolID, uno.IP); err != nil {
  582. t.Fatal(err)
  583. }
  584. uno, _, err = a.RequestAddress(poolID, nil, nil)
  585. if err != nil {
  586. t.Fatal(err)
  587. }
  588. if !types.CompareIPNet(uno, unoExp) {
  589. t.Fatalf("Unexpected address: %v", uno)
  590. }
  591. if err = a.ReleaseAddress(poolID, tre.IP); err != nil {
  592. t.Fatal(err)
  593. }
  594. tre, _, err = a.RequestAddress(poolID, nil, nil)
  595. if err != nil {
  596. t.Fatal(err)
  597. }
  598. if !types.CompareIPNet(tre, treExp) {
  599. t.Fatalf("Unexpected address: %v", tre)
  600. }
  601. }
  602. func TestGetAddress(t *testing.T) {
  603. input := []string{
  604. /*"10.0.0.0/8", "10.0.0.0/9", "10.0.0.0/10",*/ "10.0.0.0/11", "10.0.0.0/12", "10.0.0.0/13", "10.0.0.0/14",
  605. "10.0.0.0/15", "10.0.0.0/16", "10.0.0.0/17", "10.0.0.0/18", "10.0.0.0/19", "10.0.0.0/20", "10.0.0.0/21",
  606. "10.0.0.0/22", "10.0.0.0/23", "10.0.0.0/24", "10.0.0.0/25", "10.0.0.0/26", "10.0.0.0/27", "10.0.0.0/28",
  607. "10.0.0.0/29", "10.0.0.0/30", "10.0.0.0/31"}
  608. for _, subnet := range input {
  609. assertGetAddress(t, subnet)
  610. }
  611. }
  612. func TestRequestSyntaxCheck(t *testing.T) {
  613. var (
  614. pool = "192.168.0.0/16"
  615. subPool = "192.168.0.0/24"
  616. as = "green"
  617. err error
  618. )
  619. a, err := getAllocator()
  620. if err != nil {
  621. t.Fatal(err)
  622. }
  623. a.addrSpaces[as] = &addrSpace{
  624. id: dsConfigKey + "/" + as,
  625. ds: a.addrSpaces[localAddressSpace].ds,
  626. alloc: a.addrSpaces[localAddressSpace].alloc,
  627. scope: a.addrSpaces[localAddressSpace].scope,
  628. subnets: map[SubnetKey]*PoolData{},
  629. }
  630. _, _, _, err = a.RequestPool("", pool, "", nil, false)
  631. if err == nil {
  632. t.Fatalf("Failed to detect wrong request: empty address space")
  633. }
  634. _, _, _, err = a.RequestPool("", pool, subPool, nil, false)
  635. if err == nil {
  636. t.Fatalf("Failed to detect wrong request: empty address space")
  637. }
  638. _, _, _, err = a.RequestPool(as, "", subPool, nil, false)
  639. if err == nil {
  640. t.Fatalf("Failed to detect wrong request: subPool specified and no pool")
  641. }
  642. pid, _, _, err := a.RequestPool(as, pool, subPool, nil, false)
  643. if err != nil {
  644. t.Fatalf("Unexpected failure: %v", err)
  645. }
  646. _, _, err = a.RequestAddress("", nil, nil)
  647. if err == nil {
  648. t.Fatalf("Failed to detect wrong request: no pool id specified")
  649. }
  650. ip := net.ParseIP("172.17.0.23")
  651. _, _, err = a.RequestAddress(pid, ip, nil)
  652. if err == nil {
  653. t.Fatalf("Failed to detect wrong request: requested IP from different subnet")
  654. }
  655. ip = net.ParseIP("192.168.0.50")
  656. _, _, err = a.RequestAddress(pid, ip, nil)
  657. if err != nil {
  658. t.Fatalf("Unexpected failure: %v", err)
  659. }
  660. err = a.ReleaseAddress("", ip)
  661. if err == nil {
  662. t.Fatalf("Failed to detect wrong request: no pool id specified")
  663. }
  664. err = a.ReleaseAddress(pid, nil)
  665. if err == nil {
  666. t.Fatalf("Failed to detect wrong request: no pool id specified")
  667. }
  668. err = a.ReleaseAddress(pid, ip)
  669. if err != nil {
  670. t.Fatalf("Unexpected failure: %v: %s, %s", err, pid, ip)
  671. }
  672. }
  673. func TestRequest(t *testing.T) {
  674. // Request N addresses from different size subnets, verifying last request
  675. // returns expected address. Internal subnet host size is Allocator's default, 16
  676. input := []struct {
  677. subnet string
  678. numReq int
  679. lastIP string
  680. }{
  681. {"192.168.59.0/24", 254, "192.168.59.254"},
  682. {"192.168.240.0/20", 255, "192.168.240.255"},
  683. {"192.168.0.0/16", 255, "192.168.0.255"},
  684. {"192.168.0.0/16", 256, "192.168.1.0"},
  685. {"10.16.0.0/16", 255, "10.16.0.255"},
  686. {"10.128.0.0/12", 255, "10.128.0.255"},
  687. {"10.0.0.0/8", 256, "10.0.1.0"},
  688. {"192.168.128.0/18", 4*256 - 1, "192.168.131.255"},
  689. /*
  690. {"192.168.240.0/20", 16*256 - 2, "192.168.255.254"},
  691. {"192.168.0.0/16", 256*256 - 2, "192.168.255.254"},
  692. {"10.0.0.0/8", 2 * 256, "10.0.2.0"},
  693. {"10.0.0.0/8", 5 * 256, "10.0.5.0"},
  694. {"10.0.0.0/8", 100 * 256 * 254, "10.99.255.254"},
  695. */
  696. }
  697. for _, d := range input {
  698. assertNRequests(t, d.subnet, d.numReq, d.lastIP)
  699. }
  700. }
  701. func TestRelease(t *testing.T) {
  702. var (
  703. subnet = "192.168.0.0/23"
  704. )
  705. a, err := getAllocator()
  706. if err != nil {
  707. t.Fatal(err)
  708. }
  709. pid, _, _, err := a.RequestPool(localAddressSpace, subnet, "", nil, false)
  710. if err != nil {
  711. t.Fatal(err)
  712. }
  713. bm := a.addresses[SubnetKey{localAddressSpace, subnet, ""}]
  714. // Allocate all addresses
  715. for err != ipamapi.ErrNoAvailableIPs {
  716. _, _, err = a.RequestAddress(pid, nil, nil)
  717. }
  718. toRelease := []struct {
  719. address string
  720. }{
  721. {"192.168.0.1"},
  722. {"192.168.0.2"},
  723. {"192.168.0.3"},
  724. {"192.168.0.4"},
  725. {"192.168.0.5"},
  726. {"192.168.0.6"},
  727. {"192.168.0.7"},
  728. {"192.168.0.8"},
  729. {"192.168.0.9"},
  730. {"192.168.0.10"},
  731. {"192.168.0.30"},
  732. {"192.168.0.31"},
  733. {"192.168.1.32"},
  734. {"192.168.0.254"},
  735. {"192.168.1.1"},
  736. {"192.168.1.2"},
  737. {"192.168.1.3"},
  738. {"192.168.1.253"},
  739. {"192.168.1.254"},
  740. }
  741. // One by one, relase the address and request again. We should get the same IP
  742. for i, inp := range toRelease {
  743. ip0 := net.ParseIP(inp.address)
  744. a.ReleaseAddress(pid, ip0)
  745. bm = a.addresses[SubnetKey{localAddressSpace, subnet, ""}]
  746. if bm.Unselected() != 1 {
  747. t.Fatalf("Failed to update free address count after release. Expected %d, Found: %d", i+1, bm.Unselected())
  748. }
  749. nw, _, err := a.RequestAddress(pid, nil, nil)
  750. if err != nil {
  751. t.Fatalf("Failed to obtain the address: %s", err.Error())
  752. }
  753. ip := nw.IP
  754. if !ip0.Equal(ip) {
  755. t.Fatalf("Failed to obtain the same address. Expected: %s, Got: %s", ip0, ip)
  756. }
  757. }
  758. }
  759. func assertGetAddress(t *testing.T, subnet string) {
  760. var (
  761. err error
  762. printTime = false
  763. a = &Allocator{}
  764. )
  765. _, sub, _ := net.ParseCIDR(subnet)
  766. ones, bits := sub.Mask.Size()
  767. zeroes := bits - ones
  768. numAddresses := 1 << uint(zeroes)
  769. bm, err := bitseq.NewHandle("ipam_test", nil, "default/"+subnet, uint64(numAddresses))
  770. if err != nil {
  771. t.Fatal(err)
  772. }
  773. start := time.Now()
  774. run := 0
  775. for err != ipamapi.ErrNoAvailableIPs {
  776. _, err = a.getAddress(sub, bm, nil, nil)
  777. run++
  778. }
  779. if printTime {
  780. fmt.Printf("\nTaken %v, to allocate all addresses on %s. (nemAddresses: %d. Runs: %d)", time.Since(start), subnet, numAddresses, run)
  781. }
  782. if bm.Unselected() != 0 {
  783. t.Fatalf("Unexpected free count after reserving all addresses: %d", bm.Unselected())
  784. }
  785. /*
  786. if bm.Head.Block != expectedMax || bm.Head.Count != numBlocks {
  787. t.Fatalf("Failed to effectively reserve all addresses on %s. Expected (0x%x, %d) as first sequence. Found (0x%x,%d)",
  788. subnet, expectedMax, numBlocks, bm.Head.Block, bm.Head.Count)
  789. }
  790. */
  791. }
  792. func assertNRequests(t *testing.T, subnet string, numReq int, lastExpectedIP string) {
  793. var (
  794. nw *net.IPNet
  795. printTime = false
  796. )
  797. lastIP := net.ParseIP(lastExpectedIP)
  798. a, err := getAllocator()
  799. if err != nil {
  800. t.Fatal(err)
  801. }
  802. pid, _, _, err := a.RequestPool(localAddressSpace, subnet, "", nil, false)
  803. if err != nil {
  804. t.Fatal(err)
  805. }
  806. i := 0
  807. start := time.Now()
  808. for ; i < numReq; i++ {
  809. nw, _, err = a.RequestAddress(pid, nil, nil)
  810. }
  811. if printTime {
  812. fmt.Printf("\nTaken %v, to allocate %d addresses on %s\n", time.Since(start), numReq, subnet)
  813. }
  814. if !lastIP.Equal(nw.IP) {
  815. t.Fatalf("Wrong last IP. Expected %s. Got: %s (err: %v, ind: %d)", lastExpectedIP, nw.IP.String(), err, i)
  816. }
  817. }
  818. func benchmarkRequest(b *testing.B, a *Allocator, subnet string) {
  819. pid, _, _, err := a.RequestPool(localAddressSpace, subnet, "", nil, false)
  820. for err != ipamapi.ErrNoAvailableIPs {
  821. _, _, err = a.RequestAddress(pid, nil, nil)
  822. }
  823. }
  824. func benchMarkRequest(subnet string, b *testing.B) {
  825. a, _ := getAllocator()
  826. for n := 0; n < b.N; n++ {
  827. benchmarkRequest(b, a, subnet)
  828. }
  829. }
  830. func BenchmarkRequest_24(b *testing.B) {
  831. a, _ := getAllocator()
  832. benchmarkRequest(b, a, "10.0.0.0/24")
  833. }
  834. func BenchmarkRequest_16(b *testing.B) {
  835. a, _ := getAllocator()
  836. benchmarkRequest(b, a, "10.0.0.0/16")
  837. }
  838. func BenchmarkRequest_8(b *testing.B) {
  839. a, _ := getAllocator()
  840. benchmarkRequest(b, a, "10.0.0.0/8")
  841. }
  842. func TestAllocateRandomDeallocate(t *testing.T) {
  843. testAllocateRandomDeallocate(t, "172.25.0.0/16", "", 384)
  844. testAllocateRandomDeallocate(t, "172.25.0.0/16", "172.25.252.0/22", 384)
  845. }
  846. func testAllocateRandomDeallocate(t *testing.T, pool, subPool string, num int) {
  847. ds, err := randomLocalStore()
  848. if err != nil {
  849. t.Fatal(err)
  850. }
  851. a, err := NewAllocator(ds, nil)
  852. if err != nil {
  853. t.Fatal(err)
  854. }
  855. pid, _, _, err := a.RequestPool(localAddressSpace, pool, subPool, nil, false)
  856. if err != nil {
  857. t.Fatal(err)
  858. }
  859. // Allocate num ip addresses
  860. indices := make(map[int]*net.IPNet, num)
  861. allocated := make(map[string]bool, num)
  862. for i := 0; i < num; i++ {
  863. ip, _, err := a.RequestAddress(pid, nil, nil)
  864. if err != nil {
  865. t.Fatal(err)
  866. }
  867. ips := ip.String()
  868. if _, ok := allocated[ips]; ok {
  869. t.Fatalf("Address %s is already allocated", ips)
  870. }
  871. allocated[ips] = true
  872. indices[i] = ip
  873. }
  874. if len(indices) != len(allocated) || len(indices) != num {
  875. t.Fatalf("Unexpected number of allocated addresses: (%d,%d).", len(indices), len(allocated))
  876. }
  877. seed := time.Now().Unix()
  878. rand.Seed(seed)
  879. // Deallocate half of the allocated addresses following a random pattern
  880. pattern := rand.Perm(num)
  881. for i := 0; i < num/2; i++ {
  882. idx := pattern[i]
  883. ip := indices[idx]
  884. err := a.ReleaseAddress(pid, ip.IP)
  885. if err != nil {
  886. t.Fatalf("Unexpected failure on deallocation of %s: %v.\nSeed: %d.", ip, err, seed)
  887. }
  888. delete(indices, idx)
  889. delete(allocated, ip.String())
  890. }
  891. // Request a quarter of addresses
  892. for i := 0; i < num/2; i++ {
  893. ip, _, err := a.RequestAddress(pid, nil, nil)
  894. if err != nil {
  895. t.Fatal(err)
  896. }
  897. ips := ip.String()
  898. if _, ok := allocated[ips]; ok {
  899. t.Fatalf("\nAddress %s is already allocated.\nSeed: %d.", ips, seed)
  900. }
  901. allocated[ips] = true
  902. }
  903. if len(allocated) != num {
  904. t.Fatalf("Unexpected number of allocated addresses: %d.\nSeed: %d.", len(allocated), seed)
  905. }
  906. }
  907. func TestRetrieveFromStore(t *testing.T) {
  908. num := 200
  909. ds, err := randomLocalStore()
  910. if err != nil {
  911. t.Fatal(err)
  912. }
  913. a, err := NewAllocator(ds, nil)
  914. if err != nil {
  915. t.Fatal(err)
  916. }
  917. pid, _, _, err := a.RequestPool(localAddressSpace, "172.25.0.0/16", "", nil, false)
  918. if err != nil {
  919. t.Fatal(err)
  920. }
  921. for i := 0; i < num; i++ {
  922. if _, _, err := a.RequestAddress(pid, nil, nil); err != nil {
  923. t.Fatal(err)
  924. }
  925. }
  926. // Restore
  927. a1, err := NewAllocator(ds, nil)
  928. if err != nil {
  929. t.Fatal(err)
  930. }
  931. a1.refresh(localAddressSpace)
  932. db := a.DumpDatabase()
  933. db1 := a1.DumpDatabase()
  934. if db != db1 {
  935. t.Fatalf("Unexpected db change.\nExpected:%s\nGot:%s", db, db1)
  936. }
  937. checkDBEquality(a, a1, t)
  938. pid, _, _, err = a1.RequestPool(localAddressSpace, "172.25.0.0/16", "172.25.1.0/24", nil, false)
  939. if err != nil {
  940. t.Fatal(err)
  941. }
  942. for i := 0; i < num/2; i++ {
  943. if _, _, err := a1.RequestAddress(pid, nil, nil); err != nil {
  944. t.Fatal(err)
  945. }
  946. }
  947. // Restore
  948. a2, err := NewAllocator(ds, nil)
  949. if err != nil {
  950. t.Fatal(err)
  951. }
  952. a2.refresh(localAddressSpace)
  953. checkDBEquality(a1, a2, t)
  954. pid, _, _, err = a2.RequestPool(localAddressSpace, "172.25.0.0/16", "172.25.2.0/24", nil, false)
  955. if err != nil {
  956. t.Fatal(err)
  957. }
  958. for i := 0; i < num/2; i++ {
  959. if _, _, err := a2.RequestAddress(pid, nil, nil); err != nil {
  960. t.Fatal(err)
  961. }
  962. }
  963. // Restore
  964. a3, err := NewAllocator(ds, nil)
  965. if err != nil {
  966. t.Fatal(err)
  967. }
  968. a3.refresh(localAddressSpace)
  969. checkDBEquality(a2, a3, t)
  970. pid, _, _, err = a3.RequestPool(localAddressSpace, "172.26.0.0/16", "", nil, false)
  971. if err != nil {
  972. t.Fatal(err)
  973. }
  974. for i := 0; i < num/2; i++ {
  975. if _, _, err := a3.RequestAddress(pid, nil, nil); err != nil {
  976. t.Fatal(err)
  977. }
  978. }
  979. // Restore
  980. a4, err := NewAllocator(ds, nil)
  981. if err != nil {
  982. t.Fatal(err)
  983. }
  984. a4.refresh(localAddressSpace)
  985. checkDBEquality(a3, a4, t)
  986. }
  987. func checkDBEquality(a1, a2 *Allocator, t *testing.T) {
  988. for k, cnf1 := range a1.addrSpaces[localAddressSpace].subnets {
  989. cnf2 := a2.addrSpaces[localAddressSpace].subnets[k]
  990. if cnf1.String() != cnf2.String() {
  991. t.Fatalf("%s\n%s", cnf1, cnf2)
  992. }
  993. if cnf1.Range == nil {
  994. a2.retrieveBitmask(k, cnf1.Pool)
  995. }
  996. }
  997. for k, bm1 := range a1.addresses {
  998. bm2 := a2.addresses[k]
  999. if bm1.String() != bm2.String() {
  1000. t.Fatalf("%s\n%s", bm1, bm2)
  1001. }
  1002. }
  1003. }
  1004. const (
  1005. numInstances = 5
  1006. first = 0
  1007. last = numInstances - 1
  1008. )
  1009. var (
  1010. allocator *Allocator
  1011. start = make(chan struct{})
  1012. done = make(chan chan struct{}, numInstances-1)
  1013. pools = make([]*net.IPNet, numInstances)
  1014. )
  1015. func runParallelTests(t *testing.T, instance int) {
  1016. var err error
  1017. t.Parallel()
  1018. pTest := flag.Lookup("test.parallel")
  1019. if pTest == nil {
  1020. t.Skip("Skipped because test.parallel flag not set;")
  1021. }
  1022. numParallel, err := strconv.Atoi(pTest.Value.String())
  1023. if err != nil {
  1024. t.Fatal(err)
  1025. }
  1026. if numParallel < numInstances {
  1027. t.Skip("Skipped because t.parallel was less than ", numInstances)
  1028. }
  1029. // The first instance creates the allocator, gives the start
  1030. // and finally checks the pools each instance was assigned
  1031. if instance == first {
  1032. allocator, err = getAllocator()
  1033. if err != nil {
  1034. t.Fatal(err)
  1035. }
  1036. close(start)
  1037. }
  1038. if instance != first {
  1039. select {
  1040. case <-start:
  1041. }
  1042. instDone := make(chan struct{})
  1043. done <- instDone
  1044. defer close(instDone)
  1045. if instance == last {
  1046. defer close(done)
  1047. }
  1048. }
  1049. _, pools[instance], _, err = allocator.RequestPool(localAddressSpace, "", "", nil, false)
  1050. if err != nil {
  1051. t.Fatal(err)
  1052. }
  1053. if instance == first {
  1054. for instDone := range done {
  1055. select {
  1056. case <-instDone:
  1057. }
  1058. }
  1059. // Now check each instance got a different pool
  1060. for i := 0; i < numInstances; i++ {
  1061. for j := i + 1; j < numInstances; j++ {
  1062. if types.CompareIPNet(pools[i], pools[j]) {
  1063. t.Fatalf("Instance %d and %d were given the same predefined pool: %v", i, j, pools)
  1064. }
  1065. }
  1066. }
  1067. }
  1068. }
  1069. func TestParallelPredefinedRequest1(t *testing.T) {
  1070. runParallelTests(t, 0)
  1071. }
  1072. func TestParallelPredefinedRequest2(t *testing.T) {
  1073. runParallelTests(t, 1)
  1074. }
  1075. func TestParallelPredefinedRequest3(t *testing.T) {
  1076. runParallelTests(t, 2)
  1077. }
  1078. func TestParallelPredefinedRequest4(t *testing.T) {
  1079. runParallelTests(t, 3)
  1080. }
  1081. func TestParallelPredefinedRequest5(t *testing.T) {
  1082. runParallelTests(t, 4)
  1083. }