Browse code

IPAM driver doc

Signed-off-by: Alessandro Boch <aboch@docker.com>

Alessandro Boch authored on 2015/10/13 05:39:38
Showing 3 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,232 @@
0
+# Ipam Driver
1
+
2
+During the Network and Endpoints lifecyle the CNM model controls the ip address assignment for network and endpoint interfaces via the IPAM driver(s).
3
+Libnetwork has a default, built-in ipam driver and allows third party ipam drivers to be dinamically plugged. On network creation user can specify which ipam driver libnetwork needs to use for the network's ip address management. Current document explains the APIs with which IPAM driver needs to comply and the corresponding HTTPS request/response body relevant for remote drivers.
4
+
5
+
6
+## Remote Ipam driver
7
+
8
+On the same line of remote network driver registration (see [remote.md] for more details), Libnetwork initializes the `ipams.remote` package with the `Init()` function, it passes a `ipamapi.Callback` as a parameter, which implements `RegisterOpamDriver()`. The remote driver package uses this interface to register remote drivers with Libnetwork's `NetworkController`, by supplying it in a `plugins.Handle` callback.  The remote drivers register and communicate with libnetwork via the Docker plugin package. The `ipams.remote` provides the proxy for the remote driver processes.
9
+
10
+
11
+## Protocol
12
+
13
+Communication protocol is same as remote network driver.
14
+
15
+## Handshake
16
+
17
+During driver registration, libnetwork will query the remote driver about the default local and global address spaces strings.
18
+More detailed information can be found in the respective section in this document.
19
+
20
+## Datastore Requirements
21
+
22
+It is remote driver responsibility to manage its database. 
23
+
24
+## Ipam Contract
25
+
26
+The ipam driver (internal or remote) has to comply with the contract specified in `ipamapi.contract.go`:
27
+
28
+
29
+	// Ipam represents the interface the IPAM service plugins must implement
30
+	// in order to allow injection/modification of IPAM database.
31
+	type Ipam interface {
32
+		// GetDefaultAddressSpaces returns the default local and global address spaces for this ipam
33
+		GetDefaultAddressSpaces() (string, string, error)
34
+		// RequestPool returns an address pool along with its unique id. Address space is a mandatory field
35
+		// which denotes a set of non-overlapping pools. pool describes the pool of addresses in CIDR notation.
36
+		// subpool indicates a smaller range of addresses from the pool, for now it is specified in CIDR notation.
37
+		// Both pool and subpool are non mandatory fields. When they are not specified, Ipam driver may choose to
38
+		// return a self chosen pool for this request. In such case the v6 flag needs to be set appropriately so
39
+		// that the driver would return the expected ip version pool.
40
+		RequestPool(addressSpace, pool, subPool string, options map[string]string, v6 bool) (string, *net.IPNet, map[string]string, error)
41
+		// ReleasePool releases the address pool identified by the passed id
42
+		ReleasePool(poolID string) error
43
+		// Request address from the specified pool ID. Input options or preferred IP can be passed.
44
+		RequestAddress(string, net.IP, map[string]string) (*net.IPNet, map[string]string, error)
45
+		// Release the address from the specified pool ID
46
+		ReleaseAddress(string, net.IP) error
47
+	}
48
+
49
+The following sections explain the each of the above API's semantic, when they are called during network/endpoint lyfecyle and the correspondent payload for remote driver HTTP request/responses.
50
+
51
+
52
+## Ipam Configuration and flow
53
+
54
+Libnetwork user can provide ipam related configuration when creating a network, via the `NetworkOptionIpam` setter function. 
55
+
56
+`func NetworkOptionIpam(ipamDriver string, addrSpace string, ipV4 []*IpamConf, ipV6 []*IpamConf) NetworkOption`
57
+
58
+Caller has to provide the ipam driver name and may provide the address space and a list of `IpamConf` structures for ipv4 and a list for ipv6. The ipam driver name is the only mandatory field. If not provided, network creation will fail.
59
+
60
+In the list of configurations, each element has the following form:
61
+
62
+
63
+	// IpamConf contains all the ipam related configurations for a network
64
+	type IpamConf struct {
65
+		// The master address pool for containers and network interfaces
66
+		PreferredPool string
67
+		// A subset of the master pool. If specified,
68
+		// this becomes the container pool
69
+		SubPool string
70
+		// Input options for IPAM Driver (optional)
71
+		Options map[string]string
72
+		// Preferred Network Gateway address (optional)
73
+		Gateway string
74
+		// Auxiliary addresses for network driver. Must be within the master pool.
75
+		// libnetwork will reserve them if they fall into the container pool
76
+		AuxAddresses map[string]string
77
+	}
78
+
79
+
80
+On network creation, libnetwork will iterate the list and perform the following requests to ipam driver:
81
+1) Request the address pool and pass the options along via `RequestPool()`.
82
+2) Request the network gateway address if specified. Otherwise request any address from the pool to be used as network gateway. This is done via `RequestAddress()`.
83
+3) Request each of the specified auxiliary addresses via `RequestAddress()`.
84
+
85
+If the list of ipv4 configurations is empty, libnetwork will automatically add one empty `IpamConf` structure. This will cause libnetwork to request ipam driver an ipv4 address pool of the driver choice on the configured address space, if specified, or on the ipam driver default address space otherwise. If the ipam driver is not able to provide an address pool, network creation will fail.
86
+If the list of ipv6 configurations is empty, libnetwork will not take any action.
87
+The data retrieved from the ipam driver during the execution of point 1) to 3) will be stored in the network structure as a list of `IpamInfo` structures for IPv6 and for IPv6.
88
+
89
+On endpoint creation, libnetwork will iterate over the list of configs and perform the following operation:
90
+1) Request an IPv4 address from the ipv4 pool and assign it to the endpoint interface ipv4 address. If successful, stop iterating.
91
+2) Request an IPv6 address from the ipv6 pool (if exists) and assign it to the endpoint interface ipv6 address. If successful, stop iterating.
92
+
93
+Endpoint creation will fail if any of the above operation does not succeed
94
+
95
+On endpoint deletion, libnetwork will perform the following operations:
96
+1) Release the endpoint interface IPv4 address
97
+2) Release the endpoint interface IPv6 address if present
98
+
99
+On Network deletion libnetwork will iterate the list of `IpamData` structures and perform the following requests to ipam driver:
100
+1) Release the network gateway address via `ReleaseAddress()`
101
+2) Release each of the auxiliary addresses via `ReleaseAddress()`
102
+3) Release the pool via `ReleasePool()`
103
+
104
+### GetDefaultAddressSpaces
105
+
106
+GetDefaultAddressSpaces returns the default local and global address space names for this ipam. An address space is a set of non-overlapping address pools isolated from other address spaces' pools. In other words, same pool can exist on N different address spaces. An address space naturally maps to a tenant name. 
107
+In libnetwork the meaning associated to `local` or `global` address space is that a local address space doesn't need to get synchronized across the
108
+cluster where as the global address spaces does. Unless specified otherwise in the ipam configuration, libnetwork will request address pools from the default local or default global address space based on the scope of the network being created. For example, if not specified otherwise in the configuration, libnetwork will request address pool from the default local address space for a bridge network, whereas from the default global address space for an overlay network.
109
+
110
+During registration, the remote driver will receive a POST message to the URL `/IpamDriver.GetDefaultAddressSpaces` with no payload. The driver's response should have the form:
111
+
112
+
113
+	{
114
+		"LocalDefaultAddressSpace": string
115
+		"GlobalDefaultAddressSpace": string
116
+	}
117
+
118
+
119
+
120
+### RequestPool
121
+
122
+This API is for registering a address pool with the ipam driver. Multiple identical calls must return the same result.
123
+it is ipam driver responsibility to keep a reference count for the pool.
124
+
125
+`RequestPool(addressSpace, pool, subPool string, options map[string]string, v6 bool) (string, *net.IPNet, map[string]string, error)`
126
+
127
+
128
+For this API, the remote driver will receive a POST message to the URL `/IpamDriver.RequestPool` with the following payload:
129
+
130
+    {
131
+		"AddressSpace": string
132
+		"Pool":         string 
133
+		"SubPool":      string 
134
+		"Options":      map[string]string 
135
+		"V6":           bool 
136
+    }
137
+
138
+    
139
+Where:
140
+    * `AddressSpace` the ip address space
141
+    * `Pool` The IPv4 or IPv6 address pool in CIDR format
142
+    * `SubPool` An optional subset of the address pool, an ip range in CIDR format
143
+    * `Options` A map of ipam driver specific options
144
+    * `V6` Whether a ipam self chosen pool should be IPv6
145
+    
146
+Address space is the only mandatory field. If no `Pool` is specified ipam driver may return a self chosen address pool. In such case, `V6` flag must be set if caller wants an ipam chosen IPv6 pool. A request with empty `Pool` and non-empty `SubPool` should be rejected as invalid.
147
+If a Pool is not specified IPAM will allocate one of the default pools. When the Pool is not specified V6 flag should be set if the network needs IPv6 addresses to be allocated.
148
+
149
+A successful response is in the form:
150
+
151
+
152
+	{
153
+		"PoolID": string
154
+		"Pool":   string
155
+		"Data":   map[string]string
156
+	}
157
+
158
+
159
+Where:
160
+* `PoolID` is an identifier for this pool. Same pools must have same pool id.
161
+* `Pool` is the pool in CIDR format
162
+* `Data` is the ipam driver supplied metadata for this pool
163
+
164
+
165
+### ReleasePool
166
+
167
+This API is for releasing a previously registered address pool.
168
+
169
+`ReleasePool(poolID string) error`
170
+
171
+For this API, the remote driver will receive a POST message to the URL `/IpamDriver.ReleasePool` with the following payload:
172
+
173
+	{
174
+		"PoolID": string
175
+	}
176
+
177
+Where:
178
+* `PoolID` is the pool identifier
179
+
180
+A successful response is empty:
181
+
182
+    {}
183
+    
184
+### RequestAddress
185
+
186
+This API is for reserving an ip address.
187
+
188
+`RequestAddress(string, net.IP, map[string]string) (*net.IPNet, map[string]string, error)`
189
+
190
+For this API, the remote driver will receive a POST message to the URL `/IpamDriver.RequestAddress` with the following payload:
191
+
192
+    {
193
+		"PoolID":  string
194
+		"Address": string
195
+		"Options": map[string]string
196
+    }
197
+    
198
+Where:
199
+* `PoolID` is the pool identifier
200
+* `Address` is the preferred address in regular IP form (A.B.C.D). If empty, the ipam driver chooses any available address on the pool
201
+* `Options` are ipam driver specific options
202
+
203
+
204
+A successful response is in the form:
205
+
206
+
207
+	{
208
+		Address: string
209
+		Data:    map[string]string
210
+	}
211
+
212
+
213
+Where:
214
+* `Address` is the allocated address in CIDR format (A.B.C.D/MM)
215
+* `Data` is some ipam driver specific metadata
216
+
217
+### ReleaseAddress
218
+
219
+This API is for releasing an IP address.
220
+
221
+For this API, the remote driver will receive a POST message to the URL `/IpamDriver.RleaseAddress` with the following payload:
222
+
223
+    {
224
+		"PoolID": string
225
+		"Address: string
226
+    }
227
+    
228
+Where:
229
+* `PoolID` is the pool identifier
230
+* `Address` is the ip address to release
231
+
... ...
@@ -14,7 +14,7 @@ const (
14 14
 	// DefaultIPAM is the name of the built-in default ipam driver
15 15
 	DefaultIPAM = "default"
16 16
 	// PluginEndpointType represents the Endpoint Type used by Plugin system
17
-	PluginEndpointType = "IPAM"
17
+	PluginEndpointType = "IpamDriver"
18 18
 )
19 19
 
20 20
 // Callback provides a Callback interface for registering an IPAM instance into LibNetwork
... ...
@@ -57,7 +57,7 @@ type Ipam interface {
57 57
 	// GetDefaultAddressSpaces returns the default local and global address spaces for this ipam
58 58
 	GetDefaultAddressSpaces() (string, string, error)
59 59
 	// RequestPool returns an address pool along with its unique id. Address space is a mandatory field
60
-	// which denotes a set of non-overlapping pools. pool describes the pool of addrresses in CIDR notation.
60
+	// which denotes a set of non-overlapping pools. pool describes the pool of addresses in CIDR notation.
61 61
 	// subpool indicates a smaller range of addresses from the pool, for now it is specified in CIDR notation.
62 62
 	// Both pool and subpool are non mandatory fields. When they are not specified, Ipam driver may choose to
63 63
 	// return a self chosen pool for this request. In such case the v6 flag needs to be set appropriately so
... ...
@@ -70,7 +70,7 @@ type svcMap map[string]net.IP
70 70
 
71 71
 // IpamConf contains all the ipam related configurations for a network
72 72
 type IpamConf struct {
73
-	// The master address pool for containers and network iterfaces
73
+	// The master address pool for containers and network interfaces
74 74
 	PreferredPool string
75 75
 	// A subset of the master pool. If specified,
76 76
 	// this becomes the container pool