Merge "Fixed for bug : 1171 - issue while creating subnet"
[controller.git] / opendaylight / networkconfiguration / neutron / src / main / java / org / opendaylight / controller / networkconfig / neutron / NeutronNetwork.java
1 /*
2  * Copyright IBM Corporation, 2013.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.networkconfig.neutron;
10
11 import java.io.Serializable;
12 import java.util.ArrayList;
13 import java.util.Iterator;
14 import java.util.List;
15
16 import javax.xml.bind.annotation.XmlAccessType;
17 import javax.xml.bind.annotation.XmlAccessorType;
18 import javax.xml.bind.annotation.XmlElement;
19 import javax.xml.bind.annotation.XmlRootElement;
20
21 import org.opendaylight.controller.configuration.ConfigurationObject;
22
23 @XmlRootElement(name = "network")
24 @XmlAccessorType(XmlAccessType.NONE)
25
26 public class NeutronNetwork extends ConfigurationObject implements Serializable, INeutronObject {
27     // See OpenStack Network API v2.0 Reference for description of
28     // annotated attributes
29
30     private static final long serialVersionUID = 1L;
31
32     @XmlElement (name="id")
33     String networkUUID;              // network UUID
34
35     @XmlElement (name="name")
36     String networkName;              // name
37
38     @XmlElement (defaultValue="true", name="admin_state_up")
39     Boolean adminStateUp;             // admin state up (true/false)
40
41     @XmlElement (defaultValue="false", name="shared")
42     Boolean shared;                   // shared network or not
43
44     @XmlElement (name="tenant_id")
45     String tenantID;                 // tenant for this network
46
47     @XmlElement (defaultValue="false", namespace="router", name="external")
48     Boolean routerExternal;           // network external or not
49
50     @XmlElement (defaultValue="flat", namespace="provider", name="network_type")
51     String providerNetworkType;      // provider network type (flat or vlan)
52
53     @XmlElement (namespace="provider", name="physical_network")
54     String providerPhysicalNetwork;  // provider physical network (name)
55
56     @XmlElement (namespace="provider", name="segmentation_id")
57     String providerSegmentationID;   // provide segmentation ID (vlan ID)
58
59     @XmlElement (name="status")
60     String status;                   // status (read-only)
61
62     @XmlElement (name="subnets")
63     List<String> subnets;            // subnets (read-only)
64
65     /* This attribute lists the ports associated with an instance
66      * which is needed for determining if that instance can be deleted
67      */
68
69     List<NeutronPort> myPorts;
70
71     public NeutronNetwork() {
72         myPorts = new ArrayList<NeutronPort>();
73     }
74
75     public void initDefaults() {
76         subnets = new ArrayList<String>();
77         if (status == null) {
78             status = "ACTIVE";
79         }
80         if (adminStateUp == null) {
81             adminStateUp = true;
82         }
83         if (shared == null) {
84             shared = false;
85         }
86         if (routerExternal == null) {
87             routerExternal = false;
88         }
89         if (providerNetworkType == null) {
90             providerNetworkType = "flat";
91         }
92     }
93
94     public String getID() { return networkUUID; }
95
96     public void setID(String id) { this.networkUUID = id; }
97
98     public String getNetworkUUID() {
99         return networkUUID;
100     }
101
102     public void setNetworkUUID(String networkUUID) {
103         this.networkUUID = networkUUID;
104     }
105
106     public String getNetworkName() {
107         return networkName;
108     }
109
110     public void setNetworkName(String networkName) {
111         this.networkName = networkName;
112     }
113
114     public boolean isAdminStateUp() {
115         return adminStateUp;
116     }
117
118     public Boolean getAdminStateUp() { return adminStateUp; }
119
120     public void setAdminStateUp(boolean newValue) {
121         adminStateUp = newValue;
122     }
123
124     public boolean isShared() { return shared; }
125
126     public Boolean getShared() { return shared; }
127
128     public void setShared(boolean newValue) {
129         shared = newValue;
130     }
131
132     public String getTenantID() {
133         return tenantID;
134     }
135
136     public void setTenantID(String tenantID) {
137         this.tenantID = tenantID;
138     }
139
140     public boolean isRouterExternal() { return routerExternal; }
141
142     public Boolean getRouterExternal() { return routerExternal; }
143
144     public void setRouterExternal(boolean newValue) {
145         routerExternal = newValue;
146     }
147
148     public String getProviderNetworkType() {
149         return providerNetworkType;
150     }
151
152     public void setProviderNetworkType(String providerNetworkType) {
153         this.providerNetworkType = providerNetworkType;
154     }
155
156     public String getProviderPhysicalNetwork() {
157         return providerPhysicalNetwork;
158     }
159
160     public void setProviderPhysicalNetwork(String providerPhysicalNetwork) {
161         this.providerPhysicalNetwork = providerPhysicalNetwork;
162     }
163
164     public String getProviderSegmentationID() {
165         return providerSegmentationID;
166     }
167
168     public void setProviderSegmentationID(String providerSegmentationID) {
169         this.providerSegmentationID = providerSegmentationID;
170     }
171
172     public String getStatus() {
173         return status;
174     }
175
176     public void setStatus(String status) {
177         this.status = status;
178     }
179
180     public List<String> getSubnets() {
181         return subnets;
182     }
183
184     public void setSubnets(List<String> subnets) {
185         this.subnets = subnets;
186     }
187
188     public void addSubnet(String uuid) {
189         subnets.add(uuid);
190     }
191
192     public void removeSubnet(String uuid) {
193         subnets.remove(uuid);
194     }
195
196     public List<NeutronPort> getPortsOnNetwork() {
197         return myPorts;
198     }
199
200     public void addPort(NeutronPort port) {
201         myPorts.add(port);
202     }
203
204     public void removePort(NeutronPort port) {
205         myPorts.remove(port);
206     }
207
208     /**
209      * This method copies selected fields from the object and returns them
210      * as a new object, suitable for marshaling.
211      *
212      * @param fields
213      *            List of attributes to be extracted
214      * @return an OpenStackNetworks object with only the selected fields
215      * populated
216      */
217
218     public NeutronNetwork extractFields(List<String> fields) {
219         NeutronNetwork ans = new NeutronNetwork();
220         Iterator<String> i = fields.iterator();
221         while (i.hasNext()) {
222             String s = i.next();
223             if (s.equals("id")) {
224                 ans.setNetworkUUID(this.getNetworkUUID());
225             }
226             if (s.equals("name")) {
227                 ans.setNetworkName(this.getNetworkName());
228             }
229             if (s.equals("admin_state_up")) {
230                 ans.setAdminStateUp(adminStateUp);
231             }
232             if (s.equals("status")) {
233                 ans.setStatus(this.getStatus());
234             }
235             if (s.equals("subnets")) {
236                 List<String> subnetList = new ArrayList<String>();
237                 subnetList.addAll(this.getSubnets());
238                 ans.setSubnets(subnetList);
239             }
240             if (s.equals("shared")) {
241                 ans.setShared(shared);
242             }
243             if (s.equals("tenant_id")) {
244                 ans.setTenantID(this.getTenantID());
245             }
246         }
247         return ans;
248     }
249
250     @Override
251     public String toString() {
252         return "NeutronNetwork [networkUUID=" + networkUUID + ", networkName=" + networkName + ", adminStateUp="
253                 + adminStateUp + ", shared=" + shared + ", tenantID=" + tenantID + ", routerExternal=" + routerExternal
254                 + ", providerNetworkType=" + providerNetworkType + ", providerPhysicalNetwork="
255                 + providerPhysicalNetwork + ", providerSegmentationID=" + providerSegmentationID + ", status=" + status
256                 + ", subnets=" + subnets + ", myPorts=" + myPorts + "]";
257     }
258 }
259