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