X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetworkconfiguration%2Fneutron%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetworkconfig%2Fneutron%2FNeutronPort.java;fp=opendaylight%2Fnetworkconfiguration%2Fneutron%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetworkconfig%2Fneutron%2FNeutronPort.java;h=7f7f712bed65c55ad8ceae7c11538435c29f7fb7;hb=e40d69673c2529d99069a8a0bafb152a1c11c41a;hp=0000000000000000000000000000000000000000;hpb=8b979410aaed68552309facf351816266efff57c;p=controller.git 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 new file mode 100644 index 0000000000..7f7f712bed --- /dev/null +++ b/opendaylight/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronPort.java @@ -0,0 +1,239 @@ +/* + * 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); + } +}