/*
 * 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.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;

import org.opendaylight.controller.configuration.ConfigurationObject;

@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)

public class NeutronRouter extends ConfigurationObject 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 routerUUID;

    @XmlElement (name="name")
    String name;

    @XmlElement (defaultValue="true", name="admin_state_up")
    Boolean adminStateUp;

    @XmlElement (name="status")
    String status;

    @XmlElement (name="tenant_id")
    String tenantID;

    @XmlElement (name="external_gateway_info")
    NeutronRouter_NetworkReference externalGatewayInfo;

    /* Holds a map of OpenStackRouterInterfaces by subnet UUID
     * used for internal mapping to DOVE
     */
    HashMap<String, NeutronRouter_Interface> interfaces;

    public NeutronRouter() {
        interfaces = new HashMap<String, NeutronRouter_Interface>();
    }

    public String getID() { return routerUUID; }

    public void setID(String id) { this.routerUUID = id; }

    public String getRouterUUID() {
        return routerUUID;
    }

    public void setRouterUUID(String routerUUID) {
        this.routerUUID = routerUUID;
    }

    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 getTenantID() {
        return tenantID;
    }

    public void setTenantID(String tenantID) {
        this.tenantID = tenantID;
    }

    public NeutronRouter_NetworkReference getExternalGatewayInfo() {
        return externalGatewayInfo;
    }

    public void setExternalGatewayInfo(NeutronRouter_NetworkReference externalGatewayInfo) {
        this.externalGatewayInfo = externalGatewayInfo;
    }

    /**
     * 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 OpenStackRouters object with only the selected fields
     * populated
     */

    public NeutronRouter extractFields(List<String> fields) {
        NeutronRouter ans = new NeutronRouter();
        Iterator<String> i = fields.iterator();
        while (i.hasNext()) {
            String s = i.next();
            if (s.equals("id")) {
                ans.setRouterUUID(this.getRouterUUID());
            }
            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("tenant_id")) {
                ans.setTenantID(this.getTenantID());
            }
            if (s.equals("external_gateway_info")) {
                ans.setExternalGatewayInfo(this.getExternalGatewayInfo());
            }
        }
        return ans;
    }

    public HashMap<String, NeutronRouter_Interface> getInterfaces() {
        return interfaces;
    }

    public void addInterface(String s, NeutronRouter_Interface i) {
        interfaces.put(s, i);
    }

    public void removeInterface(String s) {
        interfaces.remove(s);
    }

    public void initDefaults() {
        adminStateUp = true;
    }
}

@@ -1356,18 +1356,33 @@
 ay_info%22
+, nillable=true
 )%0A
-
     Neut
@@ -1430,16 +1430,215 @@
 yInfo;%0A%0A
+    @XmlElement (name=%22distributed%22)%0A    Boolean distributed;%0A%0A    @XmlElement (name=%22gw_port_id%22, nillable=true)%0A    String gatewayPortId;%0A%0A    @XmlElement (name=%22routes%22)%0A    List%3CString%3E routes;%0A%0A
     /* H
@@ -3170,24 +3170,536 @@
 nfo;%0A    %7D%0A%0A
+    public Boolean getDistributed() %7B%0A        return distributed;%0A    %7D%0A%0A    public void setDistributed(Boolean distributed) %7B%0A        this.distributed = distributed;%0A    %7D%0A%0A    public String getGatewayPortId() %7B%0A        return gatewayPortId;%0A    %7D%0A%0A    public void setGatewayPortId(String gatewayPortId) %7B%0A        this.gatewayPortId = gatewayPortId;%0A    %7D%0A%0A    public List%3CString%3E getRoutes() %7B%0A        return routes;%0A    %7D%0A%0A    public void setRoutes(List%3CString%3E routes) %7B%0A        this.routes = routes;%0A    %7D%0A%0A
     /**%0A    
@@ -3996,17 +3996,16 @@
      */%0A
-%0A
     publ
@@ -4797,24 +4797,24 @@
 y_info%22)) %7B%0A
-
             
@@ -4882,32 +4882,367 @@
 ;%0A            %7D%0A
+            if (s.equals(%22distributed%22)) %7B%0A                ans.setDistributed(this.getDistributed());%0A            %7D%0A            if (s.equals(%22gw_port_id%22)) %7B%0A                ans.setGatewayPortId(this.getGatewayPortId());%0A            %7D%0A            if (s.equals(%22routes%22))%7B%0A                ans.setRoutes(this.getRoutes());%0A            %7D%0A
         %7D%0A      

Add additional fields to Neutron Router