X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetworkconfiguration%2Fneutron%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetworkconfig%2Fneutron%2FNeutronPort.java;h=38539883533d89104f1e060081ee566d7edb707d;hp=7f7f712bed65c55ad8ceae7c11538435c29f7fb7;hb=c31509c7a6630e54a9f9749a643fed5e1a1ad380;hpb=f39735ca424bb6a64b46505c9c2b25cbe4940c24 diff --git a/opendaylight/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronPort.java b/opendaylight/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronPort.java index 7f7f712bed..3853988353 100644 --- a/opendaylight/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronPort.java +++ b/opendaylight/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronPort.java @@ -1,239 +1,313 @@ -/* - * Copyright IBM Corporation, 2013. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.networkconfig.neutron; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; - - -@XmlRootElement -@XmlAccessorType(XmlAccessType.NONE) - -public class NeutronPort { - // See OpenStack Network API v2.0 Reference for description of - // annotated attributes - - @XmlElement (name="id") - String portUUID; - - @XmlElement (name="network_id") - String networkUUID; - - @XmlElement (name="name") - String name; - - @XmlElement (defaultValue="true", name="admin_state_up") - Boolean adminStateUp; - - @XmlElement (name="status") - String status; - - @XmlElement (name="mac_address") - String macAddress; - - @XmlElement (name="fixed_ips") - List fixedIPs; - - @XmlElement (name="device_id") - String deviceID; - - @XmlElement (name="device_owner") - String deviceOwner; - - @XmlElement (name="tenant_id") - String tenantID; - - // TODO: add security groups - // @XmlElement (name="security_groups") - // List securityGroups; - - /* this attribute stores the floating IP address assigned to - * each fixed IP address - */ - - HashMap floatingIPMap; - - public NeutronPort() { - floatingIPMap = new HashMap(); - } - - public String getID() { return portUUID; } - - public String getPortUUID() { - return portUUID; - } - - public void setPortUUID(String portUUID) { - this.portUUID = portUUID; - } - - public String getNetworkUUID() { - return networkUUID; - } - - public void setNetworkUUID(String networkUUID) { - this.networkUUID = networkUUID; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public boolean isAdminStateUp() { - if (adminStateUp == null) - return true; - return adminStateUp; - } - - public Boolean getAdminStateUp() { return adminStateUp; } - - public void setAdminStateUp(Boolean newValue) { - this.adminStateUp = newValue; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - public String getMacAddress() { - return macAddress; - } - - public void setMacAddress(String macAddress) { - this.macAddress = macAddress; - } - - public List getFixedIPs() { - return fixedIPs; - } - - public void setFixedIPs(List fixedIPs) { - this.fixedIPs = fixedIPs; - } - - public String getDeviceID() { - return deviceID; - } - - public void setDeviceID(String deviceID) { - this.deviceID = deviceID; - } - - public String getDeviceOwner() { - return deviceOwner; - } - - public void setDeviceOwner(String deviceOwner) { - this.deviceOwner = deviceOwner; - } - - public String getTenantID() { - return tenantID; - } - - public void setTenantID(String tenantID) { - this.tenantID = tenantID; - } - - public NeutronFloatingIP getFloatingIP(String key) { - if (!floatingIPMap.containsKey(key)) - return null; - return floatingIPMap.get(key); - } - - public void removeFloatingIP(String key) { - floatingIPMap.remove(key); - } - - public void addFloatingIP(String key, NeutronFloatingIP floatingIP) { - if (!floatingIPMap.containsKey(key)) - floatingIPMap.put(key, floatingIP); - } - - /** - * This method copies selected fields from the object and returns them - * as a new object, suitable for marshaling. - * - * @param fields - * List of attributes to be extracted - * @return an OpenStackPorts object with only the selected fields - * populated - */ - - public NeutronPort extractFields(List fields) { - NeutronPort ans = new NeutronPort(); - Iterator i = fields.iterator(); - while (i.hasNext()) { - String s = i.next(); - if (s.equals("id")) - ans.setPortUUID(this.getPortUUID()); - if (s.equals("network_id")) - ans.setNetworkUUID(this.getNetworkUUID()); - if (s.equals("name")) - ans.setName(this.getName()); - if (s.equals("admin_state_up")) - ans.setAdminStateUp(this.getAdminStateUp()); - if (s.equals("status")) - ans.setStatus(this.getStatus()); - if (s.equals("mac_address")) - ans.setMacAddress(this.getMacAddress()); - if (s.equals("fixed_ips")) { - List fixedIPs = new ArrayList(); - fixedIPs.addAll(this.getFixedIPs()); - ans.setFixedIPs(fixedIPs); - } - if (s.equals("device_id")) { - ans.setDeviceID(this.getDeviceID()); - } - if (s.equals("device_owner")) { - ans.setDeviceOwner(this.getDeviceOwner()); - } - if (s.equals("tenant_id")) - ans.setTenantID(this.getTenantID()); - } - return ans; - } - - public void initDefaults() { - adminStateUp = true; - if (status == null) - status = "ACTIVE"; - if (fixedIPs == null) - fixedIPs = new ArrayList(); - } - - /** - * This method checks to see if the port has a floating IPv4 address - * associated with the supplied fixed IPv4 address - * - * @param fixedIP - * fixed IPv4 address in dotted decimal format - * @return a boolean indicating if there is a floating IPv4 address bound - * to the fixed IPv4 address - */ - - public boolean isBoundToFloatingIP(String fixedIP) { - return floatingIPMap.containsKey(fixedIP); - } -} +/* + * Copyright IBM Corporation, 2013. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.controller.networkconfig.neutron; + + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + + +@XmlRootElement +@XmlAccessorType(XmlAccessType.NONE) + +public class NeutronPort implements Serializable, INeutronObject { + private static final long serialVersionUID = 1L; + + // See OpenStack Network API v2.0 Reference for description of + // annotated attributes + + @XmlElement (name="id") + String portUUID; + + @XmlElement (name="network_id") + String networkUUID; + + @XmlElement (name="name") + String name; + + @XmlElement (defaultValue="true", name="admin_state_up") + Boolean adminStateUp; + + @XmlElement (name="status") + String status; + + @XmlElement (name="mac_address") + String macAddress; + + @XmlElement (name="fixed_ips") + List fixedIPs; + + @XmlElement (name="device_id") + String deviceID; + + @XmlElement (name="device_owner") + String deviceOwner; + + @XmlElement (name="tenant_id") + String tenantID; + + @XmlElement (name="security_groups") + List securityGroups; + + @XmlElement (namespace= "binding", name="host_id") + String bindinghostID; + + @XmlElement (namespace= "binding", name="vnic_type") + String bindingvnicType; + + @XmlElement (namespace= "binding", name="vif_type") + String bindingvifType; + + + /* this attribute stores the floating IP address assigned to + * each fixed IP address + */ + + HashMap floatingIPMap; + + public NeutronPort() { + floatingIPMap = new HashMap(); + } + + public String getID() { return portUUID; } + + public void setID(String id) { this.portUUID = id; } + + public String getPortUUID() { + return portUUID; + } + + public void setPortUUID(String portUUID) { + this.portUUID = portUUID; + } + + public String getNetworkUUID() { + return networkUUID; + } + + public void setNetworkUUID(String networkUUID) { + this.networkUUID = networkUUID; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public boolean isAdminStateUp() { + if (adminStateUp == null) { + return true; + } + return adminStateUp; + } + + public Boolean getAdminStateUp() { return adminStateUp; } + + public void setAdminStateUp(Boolean newValue) { + adminStateUp = newValue; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getMacAddress() { + return macAddress; + } + + public void setMacAddress(String macAddress) { + this.macAddress = macAddress; + } + + public List getFixedIPs() { + return fixedIPs; + } + + public void setFixedIPs(List fixedIPs) { + this.fixedIPs = fixedIPs; + } + + public String getDeviceID() { + return deviceID; + } + + public void setDeviceID(String deviceID) { + this.deviceID = deviceID; + } + + public String getDeviceOwner() { + return deviceOwner; + } + + public void setDeviceOwner(String deviceOwner) { + this.deviceOwner = deviceOwner; + } + + public String getTenantID() { + return tenantID; + } + + public void setTenantID(String tenantID) { + this.tenantID = tenantID; + } + + public List getSecurityGroups() { + return securityGroups; + } + + public void setSecurityGroups(List securityGroups) { + this.securityGroups = securityGroups; + } + + public String getBindinghostID() { + return bindinghostID; + } + + public void setBindinghostID(String bindinghostID) { + this.bindinghostID = bindinghostID; + } + + public String getBindingvnicType() { + return bindingvnicType; + } + + public void setBindingvnicType(String bindingvnicType) { + this.bindingvnicType = bindingvnicType; + } + + public String getBindingvifType() { + return bindingvifType; + } + + public void setBindingvifType(String bindingvifType) { + this.bindingvifType = bindingvifType; + } + + public NeutronFloatingIP getFloatingIP(String key) { + if (!floatingIPMap.containsKey(key)) { + return null; + } + return floatingIPMap.get(key); + } + + public void removeFloatingIP(String key) { + floatingIPMap.remove(key); + } + + public void addFloatingIP(String key, NeutronFloatingIP floatingIP) { + if (!floatingIPMap.containsKey(key)) { + floatingIPMap.put(key, floatingIP); + } + } + + /** + * This method copies selected fields from the object and returns them + * as a new object, suitable for marshaling. + * + * @param fields + * List of attributes to be extracted + * @return an OpenStackPorts object with only the selected fields + * populated + */ + + public NeutronPort extractFields(List fields) { + NeutronPort ans = new NeutronPort(); + Iterator i = fields.iterator(); + while (i.hasNext()) { + String s = i.next(); + if (s.equals("id")) { + ans.setPortUUID(this.getPortUUID()); + } + if (s.equals("network_id")) { + ans.setNetworkUUID(this.getNetworkUUID()); + } + if (s.equals("name")) { + ans.setName(this.getName()); + } + if (s.equals("admin_state_up")) { + ans.setAdminStateUp(this.getAdminStateUp()); + } + if (s.equals("status")) { + ans.setStatus(this.getStatus()); + } + if (s.equals("mac_address")) { + ans.setMacAddress(this.getMacAddress()); + } + if (s.equals("fixed_ips")) { + List fixedIPs = new ArrayList(); + fixedIPs.addAll(this.getFixedIPs()); + ans.setFixedIPs(fixedIPs); + } + if (s.equals("device_id")) { + ans.setDeviceID(this.getDeviceID()); + } + if (s.equals("device_owner")) { + ans.setDeviceOwner(this.getDeviceOwner()); + } + if (s.equals("tenant_id")) { + ans.setTenantID(this.getTenantID()); + } + if (s.equals("security_groups")) { + List securityGroups = new ArrayList(); + securityGroups.addAll(this.getSecurityGroups()); + ans.setSecurityGroups(securityGroups); + } + } + return ans; + } + + public void initDefaults() { + adminStateUp = true; + if (status == null) { + status = "ACTIVE"; + } + if (fixedIPs == null) { + fixedIPs = new ArrayList(); + } + } + + /** + * This method checks to see if the port has a floating IPv4 address + * associated with the supplied fixed IPv4 address + * + * @param fixedIP + * fixed IPv4 address in dotted decimal format + * @return a boolean indicating if there is a floating IPv4 address bound + * to the fixed IPv4 address + */ + + public boolean isBoundToFloatingIP(String fixedIP) { + return floatingIPMap.containsKey(fixedIP); + } + + @Override + public String toString() { + return "NeutronPort [portUUID=" + portUUID + ", networkUUID=" + networkUUID + ", name=" + name + + ", adminStateUp=" + adminStateUp + ", status=" + status + ", macAddress=" + macAddress + + ", fixedIPs=" + fixedIPs + ", deviceID=" + deviceID + ", deviceOwner=" + deviceOwner + ", tenantID=" + + tenantID + ", floatingIPMap=" + floatingIPMap + ", securityGroups=" + securityGroups + + ", bindinghostID=" + bindinghostID + ", bindingvnicType=" + bindingvnicType + + ", bindingvnicType=" + bindingvnicType + "]"; + } +}