|
1 | 1 | /** |
2 | | - * Copyright (C) 2010 Cloud.com, Inc. All rights reserved. |
3 | | - * |
4 | | - * This software is licensed under the GNU General Public License v3 or later. |
5 | | - * |
6 | | - * It is free software: you can redistribute it and/or modify |
7 | | - * it under the terms of the GNU General Public License as published by |
8 | | - * the Free Software Foundation, either version 3 of the License, or any later version. |
9 | | - * This program is distributed in the hope that it will be useful, |
10 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | | - * GNU General Public License for more details. |
13 | | - * |
14 | | - * You should have received a copy of the GNU General Public License |
15 | | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 2 | * |
17 | 3 | */ |
18 | 4 | package com.cloud.network; |
19 | 5 |
|
20 | 6 | import java.net.URI; |
21 | | -import java.net.URISyntaxException; |
| 7 | +import java.util.List; |
| 8 | +import java.util.Set; |
22 | 9 |
|
23 | | -import com.cloud.utils.exception.CloudRuntimeException; |
| 10 | +import com.cloud.acl.ControlledEntity; |
| 11 | +import com.cloud.network.Networks.BroadcastDomainType; |
| 12 | +import com.cloud.network.Networks.Mode; |
| 13 | +import com.cloud.network.Networks.TrafficType; |
| 14 | +import com.cloud.offering.NetworkOffering.GuestIpType; |
| 15 | +import com.cloud.utils.fsm.FiniteState; |
| 16 | +import com.cloud.utils.fsm.StateMachine; |
24 | 17 |
|
25 | 18 | /** |
26 | | - * Network includes all of the enums used within networking. |
27 | | - * |
| 19 | + * A NetworkProfile defines the specifics of a network |
| 20 | + * owned by an account. |
28 | 21 | */ |
29 | | -public class Network { |
30 | | - /** |
31 | | - * Different ways to assign ip address to this network. |
32 | | - */ |
33 | | - public enum Mode { |
34 | | - None, |
35 | | - Static, |
36 | | - Dhcp, |
37 | | - ExternalDhcp; |
38 | | - }; |
39 | | - |
40 | | - public enum AddressFormat { |
41 | | - Ip4, |
42 | | - Ip6, |
43 | | - Mixed |
| 22 | +public interface Network extends ControlledEntity { |
| 23 | + enum Event { |
| 24 | + ImplementNetwork, |
| 25 | + DestroyNetwork, |
| 26 | + OperationSucceeded, |
| 27 | + OperationFailed; |
44 | 28 | } |
| 29 | + |
| 30 | + enum State implements FiniteState<State, Event> { |
| 31 | + Allocated("Indicates the network configuration is in allocated but not setup"), |
| 32 | + Setup("Indicates the network configuration is setup"), |
| 33 | + Implementing("Indicates the network configuration is being implemented"), |
| 34 | + Implemented("Indicates the network configuration is in use"), |
| 35 | + Destroying("Indicates the network configuration is being destroyed"); |
45 | 36 |
|
46 | | - /** |
47 | | - * Different types of broadcast domains. |
48 | | - */ |
49 | | - public enum BroadcastDomainType { |
50 | | - Native(null, null), |
51 | | - Vlan("vlan", Integer.class), |
52 | | - Vswitch("vs", String.class), |
53 | | - LinkLocal(null, null), |
54 | | - Vnet("vnet", Long.class), |
55 | | - UnDecided(null, null); |
56 | | - |
57 | | - private String scheme; |
58 | | - private Class<?> type; |
59 | | - |
60 | | - private BroadcastDomainType(String scheme, Class<?> type) { |
61 | | - this.scheme = scheme; |
62 | | - this.type = type; |
| 37 | + @Override |
| 38 | + public StateMachine<State, Event> getStateMachine() { |
| 39 | + return s_fsm; |
63 | 40 | } |
64 | | - |
65 | | - /** |
66 | | - * @return scheme to be used in broadcast uri. Null indicates that this type does not have broadcast tags. |
67 | | - */ |
68 | | - public String scheme() { |
69 | | - return scheme; |
| 41 | + |
| 42 | + @Override |
| 43 | + public State getNextState(Event event) { |
| 44 | + return s_fsm.getNextState(this, event); |
70 | 45 | } |
71 | | - |
72 | | - /** |
73 | | - * @return type of the value in the broadcast uri. Null indicates that this type does not have broadcast tags. |
74 | | - */ |
75 | | - public Class<?> type() { |
76 | | - return type; |
| 46 | + |
| 47 | + @Override |
| 48 | + public List<State> getFromStates(Event event) { |
| 49 | + return s_fsm.getFromStates(this, event); |
77 | 50 | } |
78 | | - |
79 | | - public <T> URI toUri(T value) { |
80 | | - try { |
81 | | - return new URI(scheme + "://" + value); |
82 | | - } catch (URISyntaxException e) { |
83 | | - throw new CloudRuntimeException("Unable to convert to broadcast URI: " + value); |
84 | | - } |
| 51 | + |
| 52 | + @Override |
| 53 | + public Set<Event> getPossibleEvents() { |
| 54 | + return s_fsm.getPossibleEvents(this); |
85 | 55 | } |
86 | | - }; |
87 | | - |
88 | | - /** |
89 | | - * Different types of network traffic in the data center. |
90 | | - */ |
91 | | - public enum TrafficType { |
92 | | - Public, |
93 | | - Guest, |
94 | | - Storage, |
95 | | - Management, |
96 | | - Control, |
97 | | - Vpn |
98 | | - }; |
99 | | - |
100 | | - public enum IsolationType { |
101 | | - None(null, null), |
102 | | - Ec2("ec2", String.class), |
103 | | - Vlan("vlan", Integer.class), |
104 | | - Vswitch("vs", String.class), |
105 | | - Undecided(null, null), |
106 | | - Vnet("vnet", Long.class); |
107 | 56 |
|
108 | | - private final String scheme; |
109 | | - private final Class<?> type; |
| 57 | + String _description; |
110 | 58 |
|
111 | | - private IsolationType(String scheme, Class<?> type) { |
112 | | - this.scheme = scheme; |
113 | | - this.type = type; |
114 | | - } |
115 | | - |
116 | | - public String scheme() { |
117 | | - return scheme; |
| 59 | + @Override |
| 60 | + public String getDescription() { |
| 61 | + return _description; |
118 | 62 | } |
119 | 63 |
|
120 | | - public Class<?> type() { |
121 | | - return type; |
| 64 | + private State(String description) { |
| 65 | + _description = description; |
122 | 66 | } |
123 | 67 |
|
124 | | - public <T> URI toUri(T value) { |
125 | | - try { |
126 | | - return new URI(scheme + "://" + value.toString()); |
127 | | - } catch (URISyntaxException e) { |
128 | | - throw new CloudRuntimeException("Unable to convert to isolation type URI: " + value); |
129 | | - } |
| 68 | + private static StateMachine<State, Event> s_fsm = new StateMachine<State, Event>(); |
| 69 | + static { |
| 70 | + s_fsm.addTransition(State.Allocated, Event.ImplementNetwork, State.Implementing); |
| 71 | + s_fsm.addTransition(State.Implementing, Event.OperationSucceeded, State.Implemented); |
| 72 | + s_fsm.addTransition(State.Implementing, Event.OperationFailed, State.Destroying); |
| 73 | + s_fsm.addTransition(State.Implemented, Event.DestroyNetwork, State.Destroying); |
| 74 | + s_fsm.addTransition(State.Destroying, Event.OperationSucceeded, State.Allocated); |
| 75 | + s_fsm.addTransition(State.Destroying, Event.OperationFailed, State.Implemented); |
130 | 76 | } |
131 | 77 | } |
132 | 78 |
|
133 | | - public enum BroadcastScheme { |
134 | | - Vlan("vlan"), |
135 | | - VSwitch("vswitch"); |
136 | | - |
137 | | - private String scheme; |
138 | | - |
139 | | - private BroadcastScheme(String scheme) { |
140 | | - this.scheme = scheme; |
141 | | - } |
142 | | - |
143 | | - @Override |
144 | | - public String toString() { |
145 | | - return scheme; |
146 | | - } |
147 | | - } |
| 79 | + /** |
| 80 | + * @return id of the network profile. Null means the network profile is not from the database. |
| 81 | + */ |
| 82 | + long getId(); |
| 83 | + |
| 84 | + Mode getMode(); |
| 85 | + |
| 86 | + BroadcastDomainType getBroadcastDomainType(); |
| 87 | + |
| 88 | + TrafficType getTrafficType(); |
| 89 | + |
| 90 | + String getGateway(); |
| 91 | + |
| 92 | + String getCidr(); |
| 93 | + |
| 94 | + long getDataCenterId(); |
| 95 | + |
| 96 | + long getNetworkOfferingId(); |
| 97 | + |
| 98 | + State getState(); |
| 99 | + |
| 100 | + long getRelated(); |
| 101 | + |
| 102 | + URI getBroadcastUri(); |
| 103 | + |
| 104 | + String getDns1(); |
| 105 | + |
| 106 | + String getDns2(); |
| 107 | + |
| 108 | + GuestIpType getGuestType(); |
148 | 109 | } |
0 commit comments