ipam

package module
v0.0.0-...-30b5122 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2022 License: MIT Imports: 12 Imported by: 0

README

label-ipam

This project is still on WIP

Documentation

Index

Constants

View Source
const BucketSize = (512 + 1024) * 1024

Variables

View Source
var (
	ErrInvalidLengthStorage        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowStorage          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupStorage = fmt.Errorf("proto: unexpected end of group")
)
View Source
var AddrNumPerBucket = 4096

Functions

func BigIntToIP

func BigIntToIP(ipInt *big.Int, version uint8) net.IP

func IPToBigInt

func IPToBigInt(ip net.IP) *big.Int

func IsIPv4

func IsIPv4(addr net.IP) bool

IsIPv4 return true if addr is an IPv4 address

func IsIPv6

func IsIPv6(addr net.IP) bool

IsIPv6 return true if addr is an IPv6 address

Types

type Block

type Block struct {
	Labels               map[string]string `` /* 153-byte string literal not displayed */
	Zones                []*Zone           `protobuf:"bytes,2,rep,name=zones,proto3" json:"zones,omitempty"`
	XXX_NoUnkeyedLiteral struct{}          `json:"-"`
	XXX_unrecognized     []byte            `json:"-"`
	XXX_sizecache        int32             `json:"-"`
}

func (*Block) Descriptor

func (*Block) Descriptor() ([]byte, []int)

func (*Block) GetLabels

func (m *Block) GetLabels() map[string]string

func (*Block) GetZones

func (m *Block) GetZones() []*Zone

func (*Block) Marshal

func (m *Block) Marshal() (dAtA []byte, err error)

func (*Block) MarshalTo

func (m *Block) MarshalTo(dAtA []byte) (int, error)

func (*Block) MarshalToSizedBuffer

func (m *Block) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*Block) ProtoMessage

func (*Block) ProtoMessage()

func (*Block) Reset

func (m *Block) Reset()

func (*Block) Size

func (m *Block) Size() (n int)

func (*Block) String

func (m *Block) String() string

func (*Block) Unmarshal

func (m *Block) Unmarshal(dAtA []byte) error

func (*Block) XXX_DiscardUnknown

func (m *Block) XXX_DiscardUnknown()

func (*Block) XXX_Marshal

func (m *Block) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Block) XXX_Merge

func (m *Block) XXX_Merge(src proto.Message)

func (*Block) XXX_Size

func (m *Block) XXX_Size() int

func (*Block) XXX_Unmarshal

func (m *Block) XXX_Unmarshal(b []byte) error

type Bucket

type Bucket struct {
	Used                 map[string]*Descriptor `` /* 149-byte string literal not displayed */
	XXX_NoUnkeyedLiteral struct{}               `json:"-"`
	XXX_unrecognized     []byte                 `json:"-"`
	XXX_sizecache        int32                  `json:"-"`
}

IP地址桶,用于多个IP独立存储,最大IP容量上限

func (*Bucket) Descriptor

func (*Bucket) Descriptor() ([]byte, []int)

func (*Bucket) GetUsed

func (m *Bucket) GetUsed() map[string]*Descriptor

func (*Bucket) Marshal

func (m *Bucket) Marshal() (dAtA []byte, err error)

func (*Bucket) MarshalTo

func (m *Bucket) MarshalTo(dAtA []byte) (int, error)

func (*Bucket) MarshalToSizedBuffer

func (m *Bucket) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*Bucket) ProtoMessage

func (*Bucket) ProtoMessage()

func (*Bucket) Reset

func (m *Bucket) Reset()

func (*Bucket) Size

func (m *Bucket) Size() (n int)

func (*Bucket) String

func (m *Bucket) String() string

func (*Bucket) Unmarshal

func (m *Bucket) Unmarshal(dAtA []byte) error

func (*Bucket) XXX_DiscardUnknown

func (m *Bucket) XXX_DiscardUnknown()

func (*Bucket) XXX_Marshal

func (m *Bucket) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Bucket) XXX_Merge

func (m *Bucket) XXX_Merge(src proto.Message)

func (*Bucket) XXX_Size

func (m *Bucket) XXX_Size() int

func (*Bucket) XXX_Unmarshal

func (m *Bucket) XXX_Unmarshal(b []byte) error

type Descriptor

type Descriptor struct {
	Labels               map[string]string `` /* 153-byte string literal not displayed */
	RefCount             uint32            `protobuf:"varint,2,opt,name=ref_count,json=refCount,proto3" json:"ref_count,omitempty"`
	XXX_NoUnkeyedLiteral struct{}          `json:"-"`
	XXX_unrecognized     []byte            `json:"-"`
	XXX_sizecache        int32             `json:"-"`
}

IP地址描述符

func (*Descriptor) Descriptor

func (*Descriptor) Descriptor() ([]byte, []int)

func (*Descriptor) GetLabels

func (m *Descriptor) GetLabels() map[string]string

func (*Descriptor) GetRefCount

func (m *Descriptor) GetRefCount() uint32

func (*Descriptor) Marshal

func (m *Descriptor) Marshal() (dAtA []byte, err error)

func (*Descriptor) MarshalTo

func (m *Descriptor) MarshalTo(dAtA []byte) (int, error)

func (*Descriptor) MarshalToSizedBuffer

func (m *Descriptor) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*Descriptor) ProtoMessage

func (*Descriptor) ProtoMessage()

func (*Descriptor) Reset

func (m *Descriptor) Reset()

func (*Descriptor) Size

func (m *Descriptor) Size() (n int)

func (*Descriptor) String

func (m *Descriptor) String() string

func (*Descriptor) Unmarshal

func (m *Descriptor) Unmarshal(dAtA []byte) error

func (*Descriptor) XXX_DiscardUnknown

func (m *Descriptor) XXX_DiscardUnknown()

func (*Descriptor) XXX_Marshal

func (m *Descriptor) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Descriptor) XXX_Merge

func (m *Descriptor) XXX_Merge(src proto.Message)

func (*Descriptor) XXX_Size

func (m *Descriptor) XXX_Size() int

func (*Descriptor) XXX_Unmarshal

func (m *Descriptor) XXX_Unmarshal(b []byte) error

type IPAM

type IPAM interface {
	// 设置IPAM自己的标签
	SetLabel(ctx context.Context, key, value string)
	// 移除IPAM的标签,返回被移除的key的value与key是否存在,若key不存在则默认value为空字符串
	RemoveLabel(ctx context.Context, key string) (string, bool)
	// 列出指定IPAM的所有标签
	Labels(ctx context.Context) LabelMap

	// 添加Zone,即IP地址段
	//
	// literal支持以下几种IP地址格式:
	//
	// 1. 单个IPv4/IPv6地址(如192.168.0.1,或FE80::12)
	//
	// 2. 连字符(闭)区间(如192.168.0.1-192.168.3.2,或FE80::12-FE80::1:12)
	//
	// 3. CIDR网络地址(如192.168.0..0/24,或FE80::/64)
	//
	// 注意:当使用CIDR网络地址时,该网络的0地址和广播地址不会被计入可用地址内,若需要使用这些地址,请使用连字符区间格式
	//
	// lazy: 目前无效
	AddZone(ctx context.Context, literal string, lazy bool) error
	// 设置Zone的标签
	SetZoneLabel(ctx context.Context, literal, key, value string) error
	// 移除由literal指定的Zone
	RemoveZone(ctx context.Context, literal string) error
	// 移除Zone的标签,返回被移除的key的value与zone/key是否存在,若zone/key不存在则默认value为空字符串
	RemoveZoneLabel(ctx context.Context, literal, key string) (string, bool)
	// 列出指定Zone的所有标签并返回Zone是否存在
	ZoneLabels(ctx context.Context, literal string) (LabelMap, bool)

	// 以string表示的当前空闲的地址数量,即`全部地址数量 - 已用地址数量 - 保留地址数量`
	IdleCount(ctx context.Context) string
	// 全部已使用的IP地址
	UsedAddrs(ctx context.Context) []string
	// 全部已保留的IP地址
	ReservedAddrs(ctx context.Context) []string
	// 分配一个指定的IP,允许指定已使用的IP(内部引用计数加1),若有标签,则一并填写(覆盖)标签
	AllocAddrSpecific(ctx context.Context, specific string, labels LabelMap) error
	// 从随机Zone的未使用IP中分配一个,若有标签,则一并填写标签
	AllocAddrNext(ctx context.Context, labels LabelMap) (net.IP, error)
	// 保留一个IP,该IP必须未分配
	ReserveAddr(ctx context.Context, specific string, labels LabelMap) error
	// 释放一个IP,该IP应当已分配或已保留,允许多次释放一个被多次申请的IP(内部引用计数减1)
	ReleaseAddr(ctx context.Context, specific string) error
	// 设置IP地址的标签,若IP格式错误或地址未分配/未保留则报错
	SetAddrLabel(ctx context.Context, specific, key, value string) error
	// 移除IP地址的标签,若IP格式错误或地址未分配/未保留则报错
	RemoveAddrLabel(ctx context.Context, specific, key string) error
	// 列出指定IP地址的所有标签,若IP格式错误或地址未分配/未保留则报错
	AddrLabels(ctx context.Context, specific string) (LabelMap, error)
	// 从IP地址查找所属Zone的literal,由于zone的literal不可能为空字符串,因此无需返回布尔值
	FindLiteral(ctx context.Context, specific string) string
	// 列出当前所有Zone的literal
	Literals(ctx context.Context) []string

	// 导出所有Zone为字节码,默认情况下不导出已分配的IP信息
	//
	// fat为true时,将会包含已分配的IP信息
	Dump(ctx context.Context, fat bool) ([]byte, error)
	// 将Zone中已分配的IP导出为分散的字节码映射
	DumpZoneAddrs(ctx context.Context, literal string, onlyKeys bool) (map[string][]byte, error)
	// 从Dump导出的字节码中加载全部Zone,IPAM中已有的同名Zone将会被覆盖
	Load(ctx context.Context, raw []byte) error
	// 从DumpZoneAddrs导出的字节码映射中加载Zone的已分配地址
	//
	// 若addrs的key不包含在该Zone中,则该key与其对应的地址将被忽略
	//
	// 若force为true,即使addrs的key在Zone中找不到,也仍会加载
	LoadZoneAddrs(ctx context.Context, literal string, addrs map[string][]byte, force bool) error
}

支持IPv4与IPv6的地址管理与持久化

func New

func New(prefix string, labels LabelMap) IPAM

type LabelMap

type LabelMap map[string]string

func (LabelMap) Copy

func (lm LabelMap) Copy() LabelMap

type Zone

type Zone struct {
	Literal string            `protobuf:"bytes,1,opt,name=literal,proto3" json:"literal,omitempty"`
	Labels  map[string]string `` /* 153-byte string literal not displayed */
	// bucket的索引映射,其中key为bucket的索引
	Buckets              map[string]*Bucket     `` /* 155-byte string literal not displayed */
	Reserved             map[string]*Descriptor `` /* 157-byte string literal not displayed */
	XXX_NoUnkeyedLiteral struct{}               `json:"-"`
	XXX_unrecognized     []byte                 `json:"-"`
	XXX_sizecache        int32                  `json:"-"`
}

func (*Zone) Descriptor

func (*Zone) Descriptor() ([]byte, []int)

func (*Zone) GetBuckets

func (m *Zone) GetBuckets() map[string]*Bucket

func (*Zone) GetLabels

func (m *Zone) GetLabels() map[string]string

func (*Zone) GetLiteral

func (m *Zone) GetLiteral() string

func (*Zone) GetReserved

func (m *Zone) GetReserved() map[string]*Descriptor

func (*Zone) Marshal

func (m *Zone) Marshal() (dAtA []byte, err error)

func (*Zone) MarshalTo

func (m *Zone) MarshalTo(dAtA []byte) (int, error)

func (*Zone) MarshalToSizedBuffer

func (m *Zone) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*Zone) ProtoMessage

func (*Zone) ProtoMessage()

func (*Zone) Reset

func (m *Zone) Reset()

func (*Zone) Size

func (m *Zone) Size() (n int)

func (*Zone) String

func (m *Zone) String() string

func (*Zone) Unmarshal

func (m *Zone) Unmarshal(dAtA []byte) error

func (*Zone) XXX_DiscardUnknown

func (m *Zone) XXX_DiscardUnknown()

func (*Zone) XXX_Marshal

func (m *Zone) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Zone) XXX_Merge

func (m *Zone) XXX_Merge(src proto.Message)

func (*Zone) XXX_Size

func (m *Zone) XXX_Size() int

func (*Zone) XXX_Unmarshal

func (m *Zone) XXX_Unmarshal(b []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL