neutron-spi: Introduce base class for Neutron object
[neutron.git] / neutron-spi / src / main / java / org / opendaylight / neutron / spi / NeutronRouter.java
1 /*
2  * Copyright (c) 2013, 2015 IBM Corporation and others.  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.neutron.spi;
10
11 import java.io.Serializable;
12 import java.util.HashMap;
13 import java.util.Iterator;
14 import java.util.List;
15 import java.util.Map;
16
17 import javax.xml.bind.annotation.XmlAccessType;
18 import javax.xml.bind.annotation.XmlAccessorType;
19 import javax.xml.bind.annotation.XmlElement;
20 import javax.xml.bind.annotation.XmlRootElement;
21
22 @XmlRootElement
23 @XmlAccessorType(XmlAccessType.NONE)
24
25 public class NeutronRouter extends NeutronObject implements Serializable, INeutronObject {
26     private static final long serialVersionUID = 1L;
27
28     // See OpenStack Network API v2.0 Reference for description of
29     // annotated attributes
30     @XmlElement (name = "name")
31     String name;
32
33     @XmlElement (defaultValue = "true", name = "admin_state_up")
34     Boolean adminStateUp;
35
36     @XmlElement (name = "status")
37     String status;
38
39     @XmlElement (name = "external_gateway_info", nillable = true)
40     NeutronRouter_NetworkReference externalGatewayInfo;
41
42     @XmlElement (name = "distributed")
43     Boolean distributed;
44
45     @XmlElement (name = "gw_port_id", nillable = true)
46     String gatewayPortId;
47
48     @XmlElement (name = "routes")
49     List<String> routes;
50
51     /* Holds a map of OpenStackRouterInterfaces by subnet UUID
52      * used for internal mapping to DOVE
53      */
54     Map<String, NeutronRouter_Interface> interfaces;
55
56     public NeutronRouter() {
57         interfaces = new HashMap<String, NeutronRouter_Interface>();
58     }
59
60     @Deprecated
61     public String getRouterUUID() {
62         return getID();
63     }
64
65     @Deprecated
66     public void setRouterUUID(String uuid) {
67         setID(uuid);
68     }
69
70     public String getName() {
71         return name;
72     }
73
74     public void setName(String name) {
75         this.name = name;
76     }
77
78     public boolean isAdminStateUp() {
79         if (adminStateUp == null) {
80             return true;
81         }
82         return adminStateUp;
83     }
84
85     public Boolean getAdminStateUp() { return adminStateUp; }
86
87     public void setAdminStateUp(Boolean newValue) {
88         adminStateUp = newValue;
89     }
90
91     public String getStatus() {
92         return status;
93     }
94
95     public void setStatus(String status) {
96         this.status = status;
97     }
98
99     public NeutronRouter_NetworkReference getExternalGatewayInfo() {
100         return externalGatewayInfo;
101     }
102
103     public void setExternalGatewayInfo(NeutronRouter_NetworkReference externalGatewayInfo) {
104         this.externalGatewayInfo = externalGatewayInfo;
105     }
106
107     public Boolean getDistributed() {
108         return distributed;
109     }
110
111     public void setDistributed(Boolean distributed) {
112         this.distributed = distributed;
113     }
114
115     public String getGatewayPortId() {
116         return gatewayPortId;
117     }
118
119     public void setGatewayPortId(String gatewayPortId) {
120         this.gatewayPortId = gatewayPortId;
121     }
122
123     public List<String> getRoutes() {
124         return routes;
125     }
126
127     public void setRoutes(List<String> routes) {
128         this.routes = routes;
129     }
130
131     /**
132      * This method copies selected fields from the object and returns them
133      * as a new object, suitable for marshaling.
134      *
135      * @param fields
136      *            List of attributes to be extracted
137      * @return an OpenStackRouters object with only the selected fields
138      * populated
139      */
140     public NeutronRouter extractFields(List<String> fields) {
141         NeutronRouter ans = new NeutronRouter();
142         Iterator<String> i = fields.iterator();
143         while (i.hasNext()) {
144             String s = i.next();
145             if (s.equals("id")) {
146                 ans.setID(this.getID());
147             }
148             if (s.equals("name")) {
149                 ans.setName(this.getName());
150             }
151             if (s.equals("admin_state_up")) {
152                 ans.setAdminStateUp(this.getAdminStateUp());
153             }
154             if (s.equals("status")) {
155                 ans.setStatus(this.getStatus());
156             }
157             if (s.equals("tenant_id")) {
158                 ans.setTenantID(this.getTenantID());
159             }
160             if (s.equals("external_gateway_info")) {
161                 ans.setExternalGatewayInfo(this.getExternalGatewayInfo());
162             }
163             if (s.equals("distributed")) {
164                 ans.setDistributed(this.getDistributed());
165             }
166             if (s.equals("gw_port_id")) {
167                 ans.setGatewayPortId(this.getGatewayPortId());
168             }
169             if (s.equals("routes")){
170                 ans.setRoutes(this.getRoutes());
171             }
172         }
173         return ans;
174     }
175
176     public void setInterfaces(Map<String, NeutronRouter_Interface> input) {
177         interfaces = input;
178     }
179
180     public Map<String, NeutronRouter_Interface> getInterfaces() {
181         return interfaces;
182     }
183
184     public void addInterface(String s, NeutronRouter_Interface i) {
185         interfaces.put(s, i);
186     }
187
188     public void removeInterface(String s) {
189         interfaces.remove(s);
190     }
191
192     public void initDefaults() {
193         adminStateUp = true;
194     }
195
196     @Override
197     public String toString() {
198         return "NeutronRouter [" +
199             "id=" + uuid +
200             ", name=" + name +
201             ", adminStateUp=" + adminStateUp +
202             ", status=" + status +
203             ", tenantID=" + tenantID +
204             ", external_gateway_info=" + externalGatewayInfo +
205             ", distributed=" + distributed +
206             ", gw_port_id=" + gatewayPortId +
207             ", routes=" + routes +
208             ", interfaces=" + interfaces +
209             "]";
210     }
211
212 }