2 * Copyright IBM Corporation, 2013. All rights reserved.
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
9 package org.opendaylight.controller.networkconfig.neutron;
11 import java.io.Serializable;
12 import java.util.ArrayList;
13 import java.util.Iterator;
14 import java.util.List;
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;
21 import org.opendaylight.controller.configuration.ConfigurationObject;
23 @XmlRootElement(name = "network")
24 @XmlAccessorType(XmlAccessType.NONE)
26 public class NeutronNetwork extends ConfigurationObject implements Serializable {
27 // See OpenStack Network API v2.0 Reference for description of
28 // annotated attributes
30 private static final long serialVersionUID = 1L;
32 @XmlElement (name="id")
33 String networkUUID; // network UUID
35 @XmlElement (name="name")
36 String networkName; // name
38 @XmlElement (defaultValue="true", name="admin_state_up")
39 Boolean adminStateUp; // admin state up (true/false)
41 @XmlElement (defaultValue="false", name="shared")
42 Boolean shared; // shared network or not
44 @XmlElement (name="tenant_id")
45 String tenantID; // tenant for this network
47 @XmlElement (defaultValue="false", namespace="router", name="external")
48 Boolean routerExternal; // network external or not
50 @XmlElement (defaultValue="flat", namespace="provider", name="network_type")
51 String providerNetworkType; // provider network type (flat or vlan)
53 @XmlElement (namespace="provider", name="physical_network")
54 String providerPhysicalNetwork; // provider physical network (name)
56 @XmlElement (namespace="provider", name="segmentation_id")
57 String providerSegmentationID; // provide segmentation ID (vlan ID)
59 @XmlElement (name="status")
60 String status; // status (read-only)
62 @XmlElement (name="subnets")
63 List<String> subnets; // subnets (read-only)
65 /* This attribute lists the ports associated with an instance
66 * which is needed for determining if that instance can be deleted
69 List<NeutronPort> myPorts;
71 public NeutronNetwork() {
72 myPorts = new ArrayList<NeutronPort>();
75 public void initDefaults() {
76 subnets = new ArrayList<String>();
80 if (adminStateUp == null) {
86 if (routerExternal == null) {
87 routerExternal = false;
89 if (providerNetworkType == null) {
90 providerNetworkType = "flat";
94 public String getID() { return networkUUID; }
96 public String getNetworkUUID() {
100 public void setNetworkUUID(String networkUUID) {
101 this.networkUUID = networkUUID;
104 public String getNetworkName() {
108 public void setNetworkName(String networkName) {
109 this.networkName = networkName;
112 public boolean isAdminStateUp() {
116 public Boolean getAdminStateUp() { return adminStateUp; }
118 public void setAdminStateUp(boolean newValue) {
119 adminStateUp = newValue;
122 public boolean isShared() { return shared; }
124 public Boolean getShared() { return shared; }
126 public void setShared(boolean newValue) {
130 public String getTenantID() {
134 public void setTenantID(String tenantID) {
135 this.tenantID = tenantID;
138 public boolean isRouterExternal() { return routerExternal; }
140 public Boolean getRouterExternal() { return routerExternal; }
142 public void setRouterExternal(boolean newValue) {
143 routerExternal = newValue;
146 public String getProviderNetworkType() {
147 return providerNetworkType;
150 public void setProviderNetworkType(String providerNetworkType) {
151 this.providerNetworkType = providerNetworkType;
154 public String getProviderPhysicalNetwork() {
155 return providerPhysicalNetwork;
158 public void setProviderPhysicalNetwork(String providerPhysicalNetwork) {
159 this.providerPhysicalNetwork = providerPhysicalNetwork;
162 public String getProviderSegmentationID() {
163 return providerSegmentationID;
166 public void setProviderSegmentationID(String providerSegmentationID) {
167 this.providerSegmentationID = providerSegmentationID;
170 public String getStatus() {
174 public void setStatus(String status) {
175 this.status = status;
178 public List<String> getSubnets() {
182 public void setSubnets(List<String> subnets) {
183 this.subnets = subnets;
186 public void addSubnet(String uuid) {
190 public void removeSubnet(String uuid) {
191 subnets.remove(uuid);
194 public List<NeutronPort> getPortsOnNetwork() {
198 public void addPort(NeutronPort port) {
202 public void removePort(NeutronPort port) {
203 myPorts.remove(port);
207 * This method copies selected fields from the object and returns them
208 * as a new object, suitable for marshaling.
211 * List of attributes to be extracted
212 * @return an OpenStackNetworks object with only the selected fields
216 public NeutronNetwork extractFields(List<String> fields) {
217 NeutronNetwork ans = new NeutronNetwork();
218 Iterator<String> i = fields.iterator();
219 while (i.hasNext()) {
221 if (s.equals("id")) {
222 ans.setNetworkUUID(this.getNetworkUUID());
224 if (s.equals("name")) {
225 ans.setNetworkName(this.getNetworkName());
227 if (s.equals("admin_state_up")) {
228 ans.setAdminStateUp(adminStateUp);
230 if (s.equals("status")) {
231 ans.setStatus(this.getStatus());
233 if (s.equals("subnets")) {
234 List<String> subnetList = new ArrayList<String>();
235 subnetList.addAll(this.getSubnets());
236 ans.setSubnets(subnetList);
238 if (s.equals("shared")) {
239 ans.setShared(shared);
241 if (s.equals("tenant_id")) {
242 ans.setTenantID(this.getTenantID());
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 + "]";