当前位置: 首页>>代码示例>>Golang>>正文


Golang bitseq.NewHandle函数代码示例

本文整理汇总了Golang中github.com/docker/libnetwork/bitseq.NewHandle函数的典型用法代码示例。如果您正苦于以下问题:Golang NewHandle函数的具体用法?Golang NewHandle怎么用?Golang NewHandle使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewHandle函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: insertBitMask

func (a *Allocator) insertBitMask(key SubnetKey, pool *net.IPNet) error {
	//logrus.Debugf("Inserting bitmask (%s, %s)", key.String(), pool.String())

	store := a.getStore(key.AddressSpace)
	ipVer := getAddressVersion(pool.IP)
	ones, bits := pool.Mask.Size()
	numAddresses := uint64(1 << uint(bits-ones))

	// Allow /64 subnet
	if ipVer == v6 && numAddresses == 0 {
		numAddresses--
	}

	// Generate the new address masks. AddressMask content may come from datastore
	h, err := bitseq.NewHandle(dsDataKey, store, key.String(), numAddresses)
	if err != nil {
		return err
	}

	// Do not let network identifier address be reserved
	// Do the same for IPv6 so that bridge ip starts with XXXX...::1
	h.Set(0)

	// Do not let broadcast address be reserved
	if ipVer == v4 {
		h.Set(numAddresses - 1)
	}

	a.Lock()
	a.addresses[key] = h
	a.Unlock()
	return nil
}
开发者ID:docker,项目名称:docker,代码行数:33,代码来源:allocator.go

示例2: insertBitMask

func (a *Allocator) insertBitMask(key SubnetKey, pool *net.IPNet) error {
	log.Debugf("Inserting bitmask (%s, %s)", key.String(), pool.String())

	store := a.getStore(key.AddressSpace)
	if store == nil {
		return fmt.Errorf("could not find store for address space %s while inserting bit mask", key.AddressSpace)
	}

	ipVer := getAddressVersion(pool.IP)
	ones, bits := pool.Mask.Size()
	numAddresses := uint32(1 << uint(bits-ones))

	if ipVer == v4 {
		// Do not let broadcast address be reserved
		numAddresses--
	}

	// Generate the new address masks. AddressMask content may come from datastore
	h, err := bitseq.NewHandle(dsDataKey, store, key.String(), numAddresses)
	if err != nil {
		return err
	}

	if ipVer == v4 {
		// Do not let network identifier address be reserved
		h.Set(0)
	}

	a.Lock()
	a.addresses[key] = h
	a.Unlock()
	return nil
}
开发者ID:dhiltgen,项目名称:libnetwork,代码行数:33,代码来源:allocator.go

示例3: insertAddressMasks

// Create and insert the internal subnet(s) addresses masks into the address database. Mask data may come from the bitseq datastore.
func (a *Allocator) insertAddressMasks(parentKey subnetKey, internalSubnetList []*net.IPNet) error {
	ipVer := getAddressVersion(internalSubnetList[0].IP)
	num := len(internalSubnetList)
	ones, bits := internalSubnetList[0].Mask.Size()
	numAddresses := 1 << uint(bits-ones)

	for i := 0; i < num; i++ {
		smallKey := subnetKey{parentKey.addressSpace, parentKey.subnet, internalSubnetList[i].String()}
		limit := uint32(numAddresses)

		if ipVer == v4 && i == num-1 {
			// Do not let broadcast address be reserved
			limit--
		}

		// Generate the new address masks. AddressMask content may come from datastore
		h, err := bitseq.NewHandle(dsDataKey, a.getStore(), smallKey.String(), limit)
		if err != nil {
			return err
		}

		if ipVer == v4 && i == 0 {
			// Do not let network identifier address be reserved
			h.Set(0)
		}

		a.Lock()
		a.addresses[smallKey] = h
		a.Unlock()
	}
	return nil
}
开发者ID:nkwilson,项目名称:libnetwork,代码行数:33,代码来源:allocator.go

示例4: New

// New returns an instance of id manager for a set of [start-end] numerical ids
func New(ds datastore.DataStore, id string, start, end uint64) (*Idm, error) {
	if id == "" {
		return nil, fmt.Errorf("Invalid id")
	}
	if end <= start {
		return nil, fmt.Errorf("Invalid set range: [%d, %d]", start, end)
	}

	h, err := bitseq.NewHandle("idm", ds, id, 1+end-start)
	if err != nil {
		return nil, fmt.Errorf("failed to initialize bit sequence handler: %s", err.Error())
	}

	return &Idm{start: start, end: end, handle: h}, nil
}
开发者ID:CadeLaRen,项目名称:docker-3,代码行数:16,代码来源:idm.go

示例5: insertAddressMasks

// Create and insert the internal subnet(s) addresses masks into the address database. Mask data may come from the bitseq datastore.
func (a *Allocator) insertAddressMasks(parentKey subnetKey, internalSubnetList []*net.IPNet) error {
	for _, intSub := range internalSubnetList {
		var err error
		ones, bits := intSub.Mask.Size()
		numAddresses := 1 << uint(bits-ones)
		smallKey := subnetKey{parentKey.addressSpace, parentKey.subnet, intSub.String()}

		// Insert the new address masks. AddressMask content may come from datastore
		a.Lock()
		a.addresses[smallKey], err = bitseq.NewHandle(dsDataKey, a.store, smallKey.String(), uint32(numAddresses))
		a.Unlock()
		if err != nil {
			return err
		}
	}
	return nil
}
开发者ID:hariharan16s,项目名称:libnetwork,代码行数:18,代码来源:allocator.go

示例6: assertGetAddress

func assertGetAddress(t *testing.T, subnet string) {
	var (
		err       error
		printTime = false
		a         = &Allocator{}
	)

	_, sub, _ := net.ParseCIDR(subnet)
	ones, bits := sub.Mask.Size()
	zeroes := bits - ones
	numAddresses := 1 << uint(zeroes)

	bm, err := bitseq.NewHandle("ipam_test", nil, "default/"+subnet, uint32(numAddresses))
	if err != nil {
		t.Fatal(err)
	}

	start := time.Now()
	run := 0
	for err != ipamapi.ErrNoAvailableIPs {
		_, err = a.getAddress(sub, bm, nil, nil)
		run++
	}
	if printTime {
		fmt.Printf("\nTaken %v, to allocate all addresses on %s. (nemAddresses: %d. Runs: %d)", time.Since(start), subnet, numAddresses, run)
	}
	if bm.Unselected() != 0 {
		t.Fatalf("Unexpected free count after reserving all addresses: %d", bm.Unselected())
	}
	/*
		if bm.Head.Block != expectedMax || bm.Head.Count != numBlocks {
			t.Fatalf("Failed to effectively reserve all addresses on %s. Expected (0x%x, %d) as first sequence. Found (0x%x,%d)",
				subnet, expectedMax, numBlocks, bm.Head.Block, bm.Head.Count)
		}
	*/
}
开发者ID:c0b,项目名称:libnetwork,代码行数:36,代码来源:allocator_test.go


注:本文中的github.com/docker/libnetwork/bitseq.NewHandle函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。