forked from apache/cloudstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetworkManager.java
More file actions
executable file
·483 lines (358 loc) · 17.5 KB
/
NetworkManager.java
File metadata and controls
executable file
·483 lines (358 loc) · 17.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.cloud.acl.ControlledEntity.ACLType;
import com.cloud.dc.DataCenter;
import com.cloud.dc.Vlan;
import com.cloud.dc.Vlan.VlanType;
import com.cloud.deploy.DataCenterDeployment;
import com.cloud.deploy.DeployDestination;
import com.cloud.deploy.DeploymentPlan;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.network.Network.Capability;
import com.cloud.network.Network.Provider;
import com.cloud.network.Network.Service;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.addr.PublicIp;
import com.cloud.network.element.NetworkElement;
import com.cloud.network.element.RemoteAccessVPNServiceProvider;
import com.cloud.network.element.Site2SiteVpnServiceProvider;
import com.cloud.network.element.UserDataServiceProvider;
import com.cloud.network.guru.NetworkGuru;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.StaticNat;
import com.cloud.offering.NetworkOffering;
import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.user.Account;
import com.cloud.utils.Pair;
import com.cloud.vm.Nic;
import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.VirtualMachineProfileImpl;
/**
* NetworkManager manages the network for the different end users.
*
*/
public interface NetworkManager extends NetworkService {
/**
* Assigns a new public ip address.
*
* @param dcId
* @param podId
* TODO
* @param owner
* @param type
* @param networkId
* @param requestedIp
* TODO
* @param allocatedBy
* TODO
* @return
* @throws InsufficientAddressCapacityException
*/
PublicIp assignPublicIpAddress(long dcId, Long podId, Account owner, VlanType type, Long networkId, String requestedIp,
boolean isSystem) throws InsufficientAddressCapacityException;
/**
* Do all of the work of releasing public ip addresses. Note that if this method fails, there can be side effects.
*
* @param userId
* @param caller
* TODO
* @param IpAddress
* @return true if it did; false if it didn't
*/
public boolean disassociatePublicIpAddress(long id, long userId, Account caller);
/**
* Lists IP addresses that belong to VirtualNetwork VLANs
*
* @param accountId
* - account that the IP address should belong to
* @param associatedNetworkId
* TODO
* @param sourceNat
* - (optional) true if the IP address should be a source NAT address
* @return - list of IP addresses
*/
List<IPAddressVO> listPublicIpsAssignedToGuestNtwk(long accountId, long associatedNetworkId, Boolean sourceNat);
List<NetworkVO> setupNetwork(Account owner, NetworkOfferingVO offering, DeploymentPlan plan, String name, String displayText, boolean isDefault)
throws ConcurrentOperationException;
List<NetworkVO> setupNetwork(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan, String name, String displayText, boolean errorIfAlreadySetup, Long domainId,
ACLType aclType, Boolean subdomainAccess, Long vpcId) throws ConcurrentOperationException;
List<NetworkOfferingVO> getSystemAccountNetworkOfferings(String... offeringNames);
void allocate(VirtualMachineProfile<? extends VMInstanceVO> vm, List<Pair<NetworkVO, NicProfile>> networks) throws InsufficientCapacityException, ConcurrentOperationException;
void prepare(VirtualMachineProfile<? extends VMInstanceVO> profile, DeployDestination dest, ReservationContext context) throws InsufficientCapacityException, ConcurrentOperationException,
ResourceUnavailableException;
void release(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, boolean forced) throws
ConcurrentOperationException, ResourceUnavailableException;
void cleanupNics(VirtualMachineProfile<? extends VMInstanceVO> vm);
void expungeNics(VirtualMachineProfile<? extends VMInstanceVO> vm);
List<? extends Nic> getNics(long vmId);
List<NicProfile> getNicProfiles(VirtualMachine vm);
String getNextAvailableMacAddressInNetwork(long networkConfigurationId) throws InsufficientAddressCapacityException;
boolean applyRules(List<? extends FirewallRule> rules, boolean continueOnError) throws ResourceUnavailableException;
public boolean validateRule(FirewallRule rule);
List<? extends RemoteAccessVPNServiceProvider> getRemoteAccessVpnElements();
List<? extends Site2SiteVpnServiceProvider> getSite2SiteVpnElements();
PublicIpAddress getPublicIpAddress(long ipAddressId);
List<? extends Vlan> listPodVlans(long podId);
Pair<NetworkGuru, NetworkVO> implementNetwork(long networkId, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException,
InsufficientCapacityException;
List<NetworkVO> listNetworksUsedByVm(long vmId, boolean isSystem);
<T extends VMInstanceVO> void prepareNicForMigration(VirtualMachineProfile<T> vm, DeployDestination dest);
boolean shutdownNetwork(long networkId, ReservationContext context, boolean cleanupElements);
boolean destroyNetwork(long networkId, ReservationContext context);
Network createGuestNetwork(long networkOfferingId, String name, String displayText, String gateway, String cidr,
String vlanId, String networkDomain, Account owner, Long domainId, PhysicalNetwork physicalNetwork,
long zoneId, ACLType aclType, Boolean subdomainAccess, Long vpcId)
throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException;
/**
* @throws ResourceAllocationException TODO
* @throws InsufficientCapacityException
* Associates an ip address list to an account. The list of ip addresses are all addresses associated
* with the
* given vlan id.
* @param userId
* @param accountId
* @param zoneId
* @param vlanId
* @throws InsufficientAddressCapacityException
* @throws
*/
boolean associateIpAddressListToAccount(long userId, long accountId, long zoneId, Long vlanId, Network guestNetwork) throws InsufficientCapacityException, ConcurrentOperationException,
ResourceUnavailableException, ResourceAllocationException;
Nic getNicInNetwork(long vmId, long networkId);
List<? extends Nic> getNicsForTraffic(long vmId, TrafficType type);
Network getDefaultNetworkForVm(long vmId);
Nic getDefaultNic(long vmId);
UserDataServiceProvider getPasswordResetProvider(Network network);
boolean networkIsConfiguredForExternalNetworking(long zoneId, long networkId);
Map<Capability, String> getNetworkServiceCapabilities(long networkId, Service service);
boolean applyIpAssociations(Network network, boolean continueOnError) throws ResourceUnavailableException;
boolean areServicesSupportedByNetworkOffering(long networkOfferingId, Service... services);
NetworkVO getNetworkWithSecurityGroupEnabled(Long zoneId);
boolean startNetwork(long networkId, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException;
String getIpOfNetworkElementInVirtualNetwork(long accountId, long dataCenterId);
List<NetworkVO> listNetworksForAccount(long accountId, long zoneId, Network.GuestType type);
List<NetworkVO> listAllNetworksInAllZonesByType(Network.GuestType type);
IPAddressVO markIpAsUnavailable(long addrId);
public String acquireGuestIpAddress(Network network, String requestedIp);
String getGlobalGuestDomainSuffix();
String getStartIpAddress(long networkId);
boolean applyStaticNats(List<? extends StaticNat> staticNats, boolean continueOnError) throws ResourceUnavailableException;
String getIpInNetwork(long vmId, long networkId);
String getIpInNetworkIncludingRemoved(long vmId, long networkId);
Long getPodIdForVlan(long vlanDbId);
List<Long> listNetworkOfferingsForUpgrade(long networkId);
boolean isSecurityGroupSupportedInNetwork(Network network);
boolean isProviderSupportServiceInNetwork(long networkId, Service service, Provider provider);
boolean isProviderEnabledInPhysicalNetwork(long physicalNetowrkId, String providerName);
String getNetworkTag(HypervisorType hType, Network network);
List<Service> getElementServices(Provider provider);
boolean canElementEnableIndividualServices(Provider provider);
boolean areServicesSupportedInNetwork(long networkId, Service... services);
boolean isNetworkSystem(Network network);
boolean reallocate(VirtualMachineProfile<? extends VMInstanceVO> vm,
DataCenterDeployment dest) throws InsufficientCapacityException, ConcurrentOperationException;
Map<Capability, String> getNetworkOfferingServiceCapabilities(NetworkOffering offering, Service service);
Long getPhysicalNetworkId(Network network);
boolean getAllowSubdomainAccessGlobal();
boolean isProviderForNetwork(Provider provider, long networkId);
boolean isProviderForNetworkOffering(Provider provider, long networkOfferingId);
void canProviderSupportServices(Map<Provider, Set<Service>> providersMap);
List<PhysicalNetworkSetupInfo> getPhysicalNetworkInfo(long dcId,
HypervisorType hypervisorType);
boolean canAddDefaultSecurityGroup();
List<Service> listNetworkOfferingServices(long networkOfferingId);
boolean areServicesEnabledInZone(long zoneId, NetworkOffering offering, List<Service> services);
public Map<PublicIp, Set<Service>> getIpToServices(List<PublicIp> publicIps, boolean rulesRevoked, boolean includingFirewall);
public Map<Provider, ArrayList<PublicIp>> getProviderToIpList(Network network, Map<PublicIp, Set<Service>> ipToServices);
public boolean checkIpForService(IPAddressVO ip, Service service, Long networkId);
void checkCapabilityForProvider(Set<Provider> providers, Service service,
Capability cap, String capValue);
Provider getDefaultUniqueProviderForService(String serviceName);
IpAddress assignSystemIp(long networkId, Account owner,
boolean forElasticLb, boolean forElasticIp)
throws InsufficientAddressCapacityException;
boolean handleSystemIpRelease(IpAddress ip);
void checkNetworkPermissions(Account owner, Network network);
void allocateDirectIp(NicProfile nic, DataCenter dc,
VirtualMachineProfile<? extends VirtualMachine> vm,
Network network, String requestedIp)
throws InsufficientVirtualNetworkCapcityException,
InsufficientAddressCapacityException;
String getDefaultManagementTrafficLabel(long zoneId, HypervisorType hypervisorType);
String getDefaultStorageTrafficLabel(long zoneId, HypervisorType hypervisorType);
String getDefaultPublicTrafficLabel(long dcId, HypervisorType vmware);
String getDefaultGuestTrafficLabel(long dcId, HypervisorType vmware);
/**
* @param providerName
* @return
*/
NetworkElement getElementImplementingProvider(String providerName);
/**
* @param owner
* @param guestNetwork
* @return
* @throws ConcurrentOperationException
* @throws InsufficientAddressCapacityException
*/
PublicIp assignSourceNatIpAddressToGuestNetwork(Account owner, Network guestNetwork) throws InsufficientAddressCapacityException, ConcurrentOperationException;
/**
* @param accountId
* @param zoneId
* @return
*/
String getAccountNetworkDomain(long accountId, long zoneId);
/**
* @return
*/
String getDefaultNetworkDomain();
/**
* @param ntwkOffId
* @return
*/
List<Provider> getNtwkOffDistinctProviders(long ntwkOffId);
/**
* @param requested
* @param network
* @param isDefaultNic
* @param deviceId
* @param vm
* @return
* @throws InsufficientVirtualNetworkCapcityException
* @throws InsufficientAddressCapacityException
* @throws ConcurrentOperationException
*/
Pair<NicProfile,Integer> allocateNic(NicProfile requested, Network network, Boolean isDefaultNic, int deviceId,
VirtualMachineProfile<? extends VMInstanceVO> vm) throws InsufficientVirtualNetworkCapcityException,
InsufficientAddressCapacityException, ConcurrentOperationException;
/**
* @param vmProfile
* @param dest
* @param context
* @param nicId
* @param network
* @return
* @throws InsufficientVirtualNetworkCapcityException
* @throws InsufficientAddressCapacityException
* @throws ConcurrentOperationException
* @throws InsufficientCapacityException
* @throws ResourceUnavailableException
*/
NicProfile prepareNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, DeployDestination dest,
ReservationContext context, long nicId, NetworkVO network) throws InsufficientVirtualNetworkCapcityException,
InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException;
/**
* @param vm
* @param nic TODO
*/
void removeNic(VirtualMachineProfile<? extends VMInstanceVO> vm, Nic nic);
/**
* @param accountId
* @param dcId
* @param sourceNat
* @return
*/
List<IPAddressVO> listPublicIpsAssignedToAccount(long accountId, long dcId, Boolean sourceNat);
/**
* @param ipAddrId
* @param networkId
* @param releaseOnFailure TODO
*/
IPAddressVO associateIPToGuestNetwork(long ipAddrId, long networkId, boolean releaseOnFailure) throws ResourceAllocationException, ResourceUnavailableException,
InsufficientAddressCapacityException, ConcurrentOperationException;
/**
* @param vm
* @param networkId
* @param broadcastUri TODO
* @return
*/
NicProfile getNicProfile(VirtualMachine vm, long networkId, String broadcastUri);
/**
* @param network
* @param provider
* @return
*/
boolean setupDns(Network network, Provider provider);
/**
* @param vmProfile
* @param nic TODO
* @throws ConcurrentOperationException
* @throws ResourceUnavailableException
*/
void releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, Nic nic)
throws ConcurrentOperationException, ResourceUnavailableException;
/**
* @param zoneId
* @param trafficType
* @return
*/
List<? extends PhysicalNetwork> getPhysicalNtwksSupportingTrafficType(long zoneId, TrafficType trafficType);
/**
* @param guestNic
* @return
*/
boolean isPrivateGateway(Nic guestNic);
/**
* @param network
* @param requested
* @param context
* @param vmProfile
* @param prepare TODO
* @return
* @throws InsufficientVirtualNetworkCapcityException
* @throws InsufficientAddressCapacityException
* @throws ConcurrentOperationException
* @throws InsufficientCapacityException
* @throws ResourceUnavailableException
*/
NicProfile createNicForVm(Network network, NicProfile requested, ReservationContext context, VirtualMachineProfileImpl<VMInstanceVO> vmProfile, boolean prepare) throws InsufficientVirtualNetworkCapcityException,
InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException;
PublicIp assignVpnGatewayIpAddress(long dcId, Account owner, long vpcId) throws InsufficientAddressCapacityException, ConcurrentOperationException;
/**
* @param addr
*/
void markPublicIpAsAllocated(IPAddressVO addr);
/**
* @param owner
* @param guestNtwkId
* @param vpcId
* @param dcId
* @param isSourceNat
* @return
* @throws ConcurrentOperationException
* @throws InsufficientAddressCapacityException
*/
PublicIp assignDedicateIpAddress(Account owner, Long guestNtwkId, Long vpcId, long dcId, boolean isSourceNat) throws ConcurrentOperationException, InsufficientAddressCapacityException;
/**
* @return
*/
int getNetworkLockTimeout();
}