5b35dc2b34ff73519e4350fa7070ec06cf60801d
[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 {
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 String getNetworkUUID() {
97         return networkUUID;
98     }
99
100     public void setNetworkUUID(String networkUUID) {
101         this.networkUUID = networkUUID;
102     }
103
104     public String getNetworkName() {
105         return networkName;
106     }
107
108     public void setNetworkName(String networkName) {
109         this.networkName = networkName;
110     }
111
112     public boolean isAdminStateUp() {
113         return adminStateUp;
114     }
115
116     public Boolean getAdminStateUp() { return adminStateUp; }
117
118     public void setAdminStateUp(boolean newValue) {
119         adminStateUp = newValue;
120     }
121
122     public boolean isShared() { return shared; }
123
124     public Boolean getShared() { return shared; }
125
126     public void setShared(boolean newValue) {
127         shared = newValue;
128     }
129
130     public String getTenantID() {
131         return tenantID;
132     }
133
134     public void setTenantID(String tenantID) {
135         this.tenantID = tenantID;
136     }
137
138     public boolean isRouterExternal() { return routerExternal; }
139
140     public Boolean getRouterExternal() { return routerExternal; }
141
142     public void setRouterExternal(boolean newValue) {
143         routerExternal = newValue;
144     }
145
146     public String getProviderNetworkType() {
147         return providerNetworkType;
148     }
149
150     public void setProviderNetworkType(String providerNetworkType) {
151         this.providerNetworkType = providerNetworkType;
152     }
153
154     public String getProviderPhysicalNetwork() {
155         return providerPhysicalNetwork;
156     }
157
158     public void setProviderPhysicalNetwork(String providerPhysicalNetwork) {
159         this.providerPhysicalNetwork = providerPhysicalNetwork;
160     }
161
162     public String getProviderSegmentationID() {
163         return providerSegmentationID;
164     }
165
166     public void setProviderSegmentationID(String providerSegmentationID) {
167         this.providerSegmentationID = providerSegmentationID;
168     }
169
170     public String getStatus() {
171         return status;
172     }
173
174     public void setStatus(String status) {
175         this.status = status;
176     }
177
178     public List<String> getSubnets() {
179         return subnets;
180     }
181
182     public void setSubnets(List<String> subnets) {
183         this.subnets = subnets;
184     }
185
186     public void addSubnet(String uuid) {
187         subnets.add(uuid);
188     }
189
190     public void removeSubnet(String uuid) {
191         subnets.remove(uuid);
192     }
193
194     public List<NeutronPort> getPortsOnNetwork() {
195         return myPorts;
196     }
197
198     public void addPort(NeutronPort port) {
199         myPorts.add(port);
200     }
201
202     public void removePort(NeutronPort port) {
203         myPorts.remove(port);
204     }
205
206     /**
207      * This method copies selected fields from the object and returns them
208      * as a new object, suitable for marshaling.
209      *
210      * @param fields
211      *            List of attributes to be extracted
212      * @return an OpenStackNetworks object with only the selected fields
213      * populated
214      */
215
216     public NeutronNetwork extractFields(List<String> fields) {
217         NeutronNetwork ans = new NeutronNetwork();
218         Iterator<String> i = fields.iterator();
219         while (i.hasNext()) {
220             String s = i.next();
221             if (s.equals("id")) {
222                 ans.setNetworkUUID(this.getNetworkUUID());
223             }
224             if (s.equals("name")) {
225                 ans.setNetworkName(this.getNetworkName());
226             }
227             if (s.equals("admin_state_up")) {
228                 ans.setAdminStateUp(adminStateUp);
229             }
230             if (s.equals("status")) {
231                 ans.setStatus(this.getStatus());
232             }
233             if (s.equals("subnets")) {
234                 List<String> subnetList = new ArrayList<String>();
235                 subnetList.addAll(this.getSubnets());
236                 ans.setSubnets(subnetList);
237             }
238             if (s.equals("shared")) {
239                 ans.setShared(shared);
240             }
241             if (s.equals("tenant_id")) {
242                 ans.setTenantID(this.getTenantID());
243             }
244         }
245         return ans;
246     }
247
248     @Override
249     public String toString() {
250         return "NeutronNetwork [networkUUID=" + networkUUID + ", networkName=" + networkName + ", adminStateUp="
251                 + adminStateUp + ", shared=" + shared + ", tenantID=" + tenantID + ", routerExternal=" + routerExternal
252                 + ", providerNetworkType=" + providerNetworkType + ", providerPhysicalNetwork="
253                 + providerPhysicalNetwork + ", providerSegmentationID=" + providerSegmentationID + ", status=" + status
254                 + ", subnets=" + subnets + ", myPorts=" + myPorts + "]";
255     }
256 }
257