--- /dev/null
+/*
+ * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. 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.neutron.e2etest;
+
+import java.lang.Thread;
+
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import org.junit.Assert;
+
+public class NeutronBgpvpnTests {
+ String base;
+
+ public NeutronBgpvpnTests(String base) {
+ this.base = base;
+ }
+
+ public void bgpvpn_collection_get_test() {
+ String url_s = base + "/bgpvpns";
+ try {
+ int i = 0;
+ while (i < 60) {
+ URL url = new URL(url_s);
+ HttpURLConnection httpConn = ITNeutronE2E.HttpURLConnectionFactoryGet(url);
+ if (httpConn.getResponseCode() != 200) {
+ System.out.println("trial "+Integer.toString(i)+": failed with: " +
+ Integer.toString(httpConn.getResponseCode()));
+ Thread.sleep(1000);
+ i+=1;
+ } else {
+ Assert.assertEquals("BGPVPN Collection GET failed",
+ 200, httpConn.getResponseCode());
+ return;
+ }
+ }
+ Assert.assertFalse("BGPVPN Collection GET failed", true);
+ } catch (Exception e) {
+ Assert.assertFalse("E2E Tests Failed", true);
+ }
+ }
+
+ //TODO handle SB check
+ public void singleton_bgpvpn_create_test() {
+ String url = base + "/bgpvpns";
+ String content = "{ \"bgpvpn\": {" +
+ " \"status\": \"ACTIVE\", \"type\": \"l3\", " +
+ " \"name\": \"vpn1\", \"admin_state_up\": true, " +
+ " \"tenant_id\": \"9bacb3c5d39d41a79512987f338cf177\", " +
+ " \"route_targets\": \"64512:1\", " +
+ " \"networks\": \"3b80198d-4f7b-4f77-9ef5-774d54e17126\", " +
+ " \"auto_aggregate\": true, \"id\": \"4e8e5957-649f-477b-9e5b-f1f75b21c03c\" " +
+ " } } ";
+ ITNeutronE2E.test_create(url, content,"Singleton Bgpvpn Post Failed NB");
+ }
+
+ //TODO handle SB check
+ public void bulk_bgpvpn_create_test() {
+ String url = base + "/bgpvpns";
+ String content = "{ \"bgpvpns\": [ { "
+ + "\"status\": \"ACTIVE\", "
+ + "\"name\": \"sample_bgpvpn1\", "
+ + "\"admin_state_up\": true, "
+ + "\"tenant_id\": \"4fd44f30292945e481c7b8a0c8908869\", "
+ + "\"id\": \"bc1a76cb-8767-4c3a-bb95-018b822f2130\", "
+ + "\"route_targets\": \"64512:1\", "
+ + "\"auto_aggregate\": true, "
+ + "\"type\": \"l3\" }, { "
+ + "\"status\": \"ACTIVE\", "
+ + "\"name\": \"sample_bgpvpn2\", "
+ + "\"admin_state_up\": true, "
+ + "\"tenant_id\": \"4fd44f30292945e481c7b8a0c8908869\", "
+ + "\"id\": \"af374017-c9ae-4a1d-b799-ab73111476e2\", "
+ + "\"route_targets\": \"64512:2\", "
+ + "\"auto_aggregate\": false, "
+ + "\"type\": \"l3\" } ] } ";
+ ITNeutronE2E.test_create(url, content,"Bulk Bgpvpn Post Failed");
+ }
+
+ //TODO handle SB check
+ public void bgpvpn_update_test() {
+ String url = base + "/bgpvpns/bc1a76cb-8767-4c3a-bb95-018b822f2130";
+ String content = " { \"bgpvpn\": { "
+ +"\"status\": \"ACTIVE\", "
+ +"\"name\": \"sample_bgpvpn_updated\", "
+ +"\"admin_state_up\": true, "
+ +"\"tenant_id\": \"4fd44f30292945e481c7b8a0c8908869\", "
+ + "\"auto_aggregate\": true, "
+ + "\"type\": \"l3\" } } ";
+ ITNeutronE2E.test_modify(url, content,"Bgpvpn Put Failed");
+ }
+
+ public void bgpvpn_element_get_test() {
+ String url = base + "/bgpvpns/bc1a76cb-8767-4c3a-bb95-018b822f2130";
+ ITNeutronE2E.test_fetch(url, true ,"Bgpvpn Element Get Failed");
+ }
+
+ public void bgpvpn_element_negative_get_test() {
+ String url = base + "/bgpvpns/bc1a76cb-8767-4c3a-bb95-018b822f2130";
+ ITNeutronE2E.test_fetch(url, false ,"Bgpvpn Element Negative Get Failed");
+ }
+
+ public void bgpvpn_delete_test() {
+ String url = base + "/bgpvpns/bc1a76cb-8767-4c3a-bb95-018b822f2130";
+ ITNeutronE2E.test_delete(url, "bgpvpnElement Delete Failed");
+ }
+
+ public static void runTests(String base) {
+ NeutronBgpvpnTests bgpvpn_tester = new NeutronBgpvpnTests(base);
+ bgpvpn_tester.bgpvpn_collection_get_test();
+ bgpvpn_tester.singleton_bgpvpn_create_test();
+ bgpvpn_tester.bulk_bgpvpn_create_test();
+ bgpvpn_tester.bgpvpn_update_test();
+ bgpvpn_tester.bgpvpn_element_get_test();
+ bgpvpn_tester.bgpvpn_delete_test();
+ bgpvpn_tester.bgpvpn_element_negative_get_test();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others.
+ * All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+module neutron-bgpvpns {
+
+ yang-version 1;
+
+ namespace "urn:opendaylight:neutron-bgpvpns";
+
+ prefix neutron-bgpvpns;
+
+ import ietf-yang-types { prefix "yang"; }
+ import neutron-attrs { prefix "attrs"; }
+
+ organization "OpenDaylight Neutron Group";
+
+ contact "Vishal Thapar <vishal.thapar@ericsson.com>";
+
+ description "This YANG module defines Openstack Liberty Neutron BGPVPN model";
+
+ revision "2015-09-03" {
+ description
+ "Initial version of Openstack Neutron Liberty BGPVPN model.";
+ }
+
+ identity bgpvpn-type-base {
+ description
+ "Base Network type for all Bgpvpn type identifiers.";
+ }
+
+ identity bgpvpn-type-l2 {
+ base bgpvpn-type-base;
+ description
+ "L2 bgpvpn type identity.";
+ }
+ identity bgpvpn-type-l3 {
+ base bgpvpn-type-base;
+ description
+ "L3 bgpvpn type identity.";
+ }
+
+ typedef bgpvpn-type {
+ type identityref {
+ base bgpvpn-type-base;
+ }
+ description
+ "This type is used to refer to a Bgpvpn Type.";
+ }
+
+ grouping bgpvpn-attributes {
+ leaf type {
+ type bgpvpn-type;
+ description "selection of the type of VPN. e.g. l3 or l2";
+ }
+ leaf technique {
+ type string;
+ description "selection of technique used to implement VPN";
+ }
+ leaf-list route-targets {
+ type string;
+ description "route-targets";
+ }
+ leaf-list import-targets {
+ type string;
+ description "import RTs";
+ }
+ leaf-list export-targets {
+ type string;
+ description "export RTs";
+ }
+ leaf-list route-distinguishers {
+ type string;
+ description "list route-distinguishers";
+ }
+ leaf vnid {
+ type uint32;
+ description "globally assigned VxLanId";
+ }
+ leaf auto-aggregate {
+ type boolean;
+ description "auto-aggregate enabled or not";
+ default "false";
+ }
+ leaf-list networks {
+ type yang:uuid;
+ description "list of networks this vpn is associated with.";
+ }
+ leaf-list routers {
+ type yang:uuid;
+ description "list of routers this vpn is associated with.";
+ }
+ }
+
+ grouping bgpvpns-attributes {
+ container bgpvpns {
+ list bgpvpn {
+ key "uuid";
+ uses attrs:base-attributes;
+ uses attrs:admin-attributes;
+ uses bgpvpn-attributes;
+ }
+ }
+ }
+}
import neutron-provider { prefix "provider"; }
import neutron-vpnaas { prefix "vpnaas"; }
import neutron-fwaas { prefix "fwaas"; }
+ import neutron-bgpvpns { prefix "bgpvpns"; }
organization "OpenDaylight Neutron Group";
uses vpnaas:ikepolicies-attributes;
uses vpnaas:ipsecpolicies-attributes;
uses vpnaas:ipsecconnections-attributes;
+ uses bgpvpns:bgpvpns-attributes;
}
}
--- /dev/null
+/*
+ * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. 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.neutron.spi;
+
+import java.util.List;
+
+/**
+ * This interface defines the methods for CRUD of NB bgpvpn objects
+ *
+ */
+
+public interface INeutronBgpvpnCRUD extends INeutronCRUD<NeutronBgpvpn>{
+ /**
+ * Applications call this interface method to determine if a particular
+ * Bgpvpn object exists
+ *
+ * @param uuid
+ * UUID of the Bgpvpn object
+ * @return boolean
+ */
+
+ boolean bgpvpnExists(String uuid);
+
+ /**
+ * Applications call this interface method to return if a particular
+ * Bgpvpn object exists
+ *
+ * @param uuid
+ * UUID of the Bgpvpn object
+ * @return {@link org.opendaylight.neutron.spi.NeutronBgpvpn}
+ * OpenStack Bgpvpn class
+ */
+
+ NeutronBgpvpn getBgpvpn(String uuid);
+
+ /**
+ * Applications call this interface method to return all Bgpvpn objects
+ *
+ * @return List of OpenStackBgpvpn objects
+ */
+
+ List<NeutronBgpvpn> getAllBgpvpns();
+
+ /**
+ * Applications call this interface method to add a Bgpvpn object to the
+ * concurrent map
+ *
+ * @param input
+ * OpenStackBgpvpn object
+ * @return boolean on whether the object was added or not
+ */
+
+ boolean addBgpvpn(NeutronBgpvpn input);
+
+ /**
+ * Applications call this interface method to remove a Bgpvpn object to the
+ * concurrent map
+ *
+ * @param uuid
+ * identifier for the bgpvpn object
+ * @return boolean on whether the object was removed or not
+ */
+
+ boolean removeBgpvpn(String uuid);
+
+ /**
+ * Applications call this interface method to edit a Bgpvpn object
+ *
+ * @param uuid
+ * identifier of the bgpvpn object
+ * @param delta
+ * OpenStackBgpvpn object containing changes to apply
+ * @return boolean on whether the object was updated or not
+ */
+
+ boolean updateBgpvpn(String uuid, NeutronBgpvpn delta);
+
+ /**
+ * Applications call this interface method to determine if a Bgpvpn object
+ * is use
+ *
+ * @param bgpvpnUUID
+ * identifier of the bgpvpn object
+ *
+ * @return boolean on whether the bgpvpn is in use or not
+ */
+
+ boolean bgpvpnInUse(String bgpvpnUUID);
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. 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.neutron.spi;
+
+import java.io.Serializable;
+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(name = "bgpvpn")
+@XmlAccessorType(XmlAccessType.NONE)
+public class NeutronBgpvpn extends NeutronObject implements Serializable, INeutronObject {
+ // See OpenStack Network API v2.0 Reference for description of
+ // annotated attributes
+
+ private static final long serialVersionUID = 1L;
+
+ @XmlElement (name = "name")
+ String bgpvpnName;
+
+ @XmlElement (defaultValue = "true", name = "admin_state_up")
+ Boolean adminStateUp;
+
+ @XmlElement (name = "status")
+ String status;
+
+ @XmlElement (defaultValue = "l3", name = "type")
+ String type;
+
+ @XmlElement (name = "technique")
+ String technique;
+
+ @XmlElement (name = "route_targets")
+ List<String> routeTargets;
+
+ @XmlElement (name = "import_targets")
+ List<String> importTargets;
+
+ @XmlElement (name = "export_targets")
+ List<String> exportTargets;
+
+ @XmlElement (name = "route_distinguishers")
+ List<String> routeDistinguishers;
+
+ @XmlElement (name="vnid")
+ Long vnid;
+
+ @XmlElement (defaultValue="false", name="auto_aggregate")
+ Boolean autoAggregate;
+
+ @XmlElement (name = "networks")
+ List<String> networks;
+
+ @XmlElement (name = "routers")
+ List<String> routers;
+
+ /* This attribute lists the ports associated with an instance
+ * which is needed for determining if that instance can be deleted
+ */
+
+ public NeutronBgpvpn() {
+ }
+
+ public void initDefaults() {
+ if (type == null) {
+ type = "l3";
+ }
+ if (status == null) {
+ status = "ACTIVE";
+ }
+ if (adminStateUp == null) {
+ adminStateUp = true;
+ }
+ if (autoAggregate == null) {
+ autoAggregate = false;
+ }
+ }
+
+ public String getBgpvpnName() {
+ return bgpvpnName;
+ }
+
+ public void setBgpvpnName(String bgpvpnName) {
+ this.bgpvpnName = bgpvpnName;
+ }
+
+ public boolean isAdminStateUp() {
+ 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 boolean isAutoAggregate() {
+ return autoAggregate;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getTechnique() {
+ return technique;
+ }
+
+ public void setTechnique(String technique) {
+ this.technique = technique;
+ }
+
+ public List<String> getRouteTargets() {
+ return routeTargets;
+ }
+
+ public void setRouteTargets(List<String> routeTargets) {
+ this.routeTargets= routeTargets;
+ }
+
+ public void addRouteTarget(String uuid) {
+ routeTargets.add(uuid);
+ }
+
+ public void removeRouteTarget(String uuid) {
+ routeTargets.remove(uuid);
+ }
+
+ public List<String> getImportTargets() {
+ return importTargets;
+ }
+
+ public void setImportTargets(List<String> importTargets) {
+ this.importTargets = importTargets;
+ }
+
+ public void addImportTarget(String uuid) {
+ importTargets.add(uuid);
+ }
+
+ public void removeImportTarget(String uuid) {
+ importTargets.remove(uuid);
+ }
+
+ public List<String> getExportTargets() {
+ return exportTargets;
+ }
+
+ public void setExportTargets(List<String> exportTargets) {
+ this.exportTargets = exportTargets;
+ }
+
+ public void addExportTarget(String uuid) {
+ exportTargets.add(uuid);
+ }
+
+ public void removeExportTarget(String uuid) {
+ exportTargets.remove(uuid);
+ }
+
+ public List<String> getRouteDistinguishers() {
+ return routeDistinguishers;
+ }
+
+ public void setRouteDistinguishers(List<String> routeDistinguishers) {
+ this.routeDistinguishers = routeDistinguishers;
+ }
+
+ public void addRouteDistinguisher(String uuid) {
+ routeDistinguishers.add(uuid);
+ }
+
+ public void removeRouteDistinguisher(String uuid) {
+ routeDistinguishers.remove(uuid);
+ }
+
+ public Long getVnid() {
+ return vnid;
+ }
+
+ public void setVnid(Long input) {
+ vnid = input;
+ }
+
+ public Boolean getAutoAggregate() { return autoAggregate; }
+
+ public void setAutoAggregate(boolean newValue) {
+ autoAggregate = newValue;
+ }
+
+ public List<String> getNetworks() {
+ return networks;
+ }
+
+ public void setNetworks(List<String> networks) {
+ this.networks = networks;
+ }
+
+ public void addNetwork(String uuid) {
+ networks.add(uuid);
+ }
+
+ public void removeNetwork(String uuid) {
+ networks.remove(uuid);
+ }
+
+ public List<String> getRouters() {
+ return routers;
+ }
+
+ public void setRouters(List<String> routers) {
+ this.routers = routers;
+ }
+
+ public void addRouter(String uuid) {
+ routers.add(uuid);
+ }
+
+ public void removeRouter(String uuid) {
+ routers.remove(uuid);
+ }
+
+ /**
+ * 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 OpenStackNetworks object with only the selected fields
+ * populated
+ */
+
+ public NeutronBgpvpn extractFields(List<String> fields) {
+ NeutronBgpvpn ans = new NeutronBgpvpn();
+ Iterator<String> i = fields.iterator();
+ while (i.hasNext()) {
+ String s = i.next();
+ if (s.equals("id")) {
+ ans.setID(this.getID());
+ }
+ if (s.equals("name")) {
+ ans.setBgpvpnName(this.getBgpvpnName());
+ }
+ if (s.equals("admin_state_up")) {
+ ans.setAdminStateUp(adminStateUp);
+ }
+ if (s.equals("status")) {
+ ans.setStatus(this.getStatus());
+ }
+ if (s.equals("tenant_id")) {
+ ans.setTenantID(this.getTenantID());
+ }
+ if (s.equals("type")) {
+ ans.setType(this.getType());
+ }
+ if (s.equals("technique")) {
+ ans.setTechnique(this.getTechnique());
+ }
+ if (s.equals("route_targets")) {
+ ans.setRouteTargets(this.getRouteTargets());
+ }
+ if (s.equals("import_targets")) {
+ ans.setImportTargets(this.getImportTargets());
+ }
+ if (s.equals("export_targets")) {
+ ans.setExportTargets(this.getExportTargets());
+ }
+ if (s.equals("route_distinguishers")) {
+ ans.setRouteDistinguishers(this.getRouteDistinguishers());
+ }
+ if (s.equals("routers")) {
+ ans.setRouters(this.getRouters());
+ }
+ if (s.equals("networks")) {
+ ans.setNetworks(this.getNetworks());
+ }
+ if (s.equals("vnid")) {
+ ans.setVnid(this.getVnid());
+ }
+ if (s.equals("auto_aggregate")) {
+ ans.setAutoAggregate(this.getAutoAggregate());
+ }
+ }
+ return ans;
+ }
+
+ @Override
+ public String toString() {
+ return "NeutronBgpvpn [bgpvpnUUID=" + uuid + ", bgpvpnName=" + bgpvpnName + ", adminStateUp="
+ + adminStateUp + ", status=" + status + ", tenantID=" + tenantID + ", type=" + type
+ + ", technique=" + technique + ", routeTargets="
+ + routeTargets + ", importTargets=" + importTargets + ", exportTargets=" + exportTargets
+ + ", routeDistinguishers=" + routeDistinguishers + ", vnid = " + vnid
+ + ", autoAggregate = " + autoAggregate + ", networks = " + networks
+ + ", routers = " + routers + "]";
+ }
+}
+
private INeutronVPNIPSECPolicyCRUD ipsecpInterface;
private INeutronVPNServiceCRUD vpnInterface;
private INeutronVPNIPSECSiteConnectionsCRUD ipsecScInterface;
+ private INeutronBgpvpnCRUD bgpvpnInterface;
public NeutronCRUDInterfaces() {
}
return ipsecScInterface;
}
+ public INeutronBgpvpnCRUD getBgpvpnInterface() {
+ return bgpvpnInterface;
+ }
+
public NeutronCRUDInterfaces fetchINeutronNetworkCRUD(Object obj) {
networkInterface = (INeutronNetworkCRUD) getInstances(INeutronNetworkCRUD.class, obj);
return this;
return this;
}
+ public NeutronCRUDInterfaces fetchINeutronBgpvpnCRUD(Object obj) {
+ bgpvpnInterface = (INeutronBgpvpnCRUD) getInstances(INeutronBgpvpnCRUD.class, obj);
+ return this;
+ }
+
public Object getInstances(Class<?> clazz, Object bundle) {
try {
BundleContext bCtx = FrameworkUtil.getBundle(bundle.getClass()).getBundleContext();
--- /dev/null
+/*
+ * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. 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.neutron.northbound.api;
+
+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.neutron.spi.NeutronBgpvpn;
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.NONE)
+public class NeutronBgpvpnRequest implements INeutronRequest<NeutronBgpvpn> {
+ // See OpenStack Network API v2.0 Reference for description of
+ // annotated attributes
+
+ @XmlElement(name="bgpvpn")
+ NeutronBgpvpn singletonBgpvpn;
+
+ @XmlElement(name="bgpvpns")
+ List<NeutronBgpvpn> bulkRequest;
+
+
+ NeutronBgpvpnRequest() {
+ }
+
+ NeutronBgpvpnRequest(NeutronBgpvpn bgpvpn) {
+ singletonBgpvpn = bgpvpn;
+ }
+
+ NeutronBgpvpnRequest(List<NeutronBgpvpn> bulk) {
+ bulkRequest = bulk;
+ singletonBgpvpn = null;
+ }
+
+ @Override
+ public NeutronBgpvpn getSingleton() {
+ return singletonBgpvpn;
+ }
+
+ @Override
+ public boolean isSingleton() {
+ return (singletonBgpvpn != null);
+ }
+
+ @Override
+ public List<NeutronBgpvpn> getBulk() {
+ return bulkRequest;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. 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.neutron.northbound.api;
+
+import java.net.HttpURLConnection;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+
+import org.codehaus.enunciate.jaxrs.ResponseCode;
+import org.codehaus.enunciate.jaxrs.StatusCodes;
+import org.codehaus.enunciate.jaxrs.TypeHint;
+import org.opendaylight.neutron.spi.INeutronBgpvpnCRUD;
+import org.opendaylight.neutron.spi.NeutronCRUDInterfaces;
+import org.opendaylight.neutron.spi.NeutronBgpvpn;
+
+/**
+ * Neutron Northbound REST APIs for Bgpvpn.<br>
+ * This class provides REST APIs for managing neutron Bgpvpns
+ *
+ * <br>
+ * <br>
+ * Authentication scheme : <b>HTTP Basic</b><br>
+ * Authentication realm : <b>opendaylight</b><br>
+ * Transport : <b>HTTP and HTTPS</b><br>
+ * <br>
+ * HTTPS Authentication is disabled by default. Administrator can enable it in
+ * tomcat-server.xml after adding a proper keystore / SSL certificate from a
+ * trusted authority.<br>
+ * More info :
+ * http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Configuration
+ *
+ */
+
+@Path("/bgpvpns")
+public class NeutronBgpvpnsNorthbound extends AbstractNeutronNorthbound {
+
+ @Context
+ UriInfo uriInfo;
+
+ private static final String RESOURCE_NAME = "Bgpvpn";
+ private NeutronBgpvpn extractFields(NeutronBgpvpn o, List<String> fields) {
+ return o.extractFields(fields);
+ }
+
+ private NeutronCRUDInterfaces getNeutronInterfaces() {
+ NeutronCRUDInterfaces answer = new NeutronCRUDInterfaces().fetchINeutronBgpvpnCRUD(this);
+ if (answer.getBgpvpnInterface() == null) {
+ throw new ServiceUnavailableException(serviceUnavailable(RESOURCE_NAME));
+ }
+ return answer;
+ }
+
+ /**
+ * Returns a list of all Bgpvpns */
+
+ @GET
+ @Produces({ MediaType.APPLICATION_JSON })
+ //@TypeHint(OpenStackBgpvpns.class)
+ @StatusCodes({
+ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
+ @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
+ @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
+ @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
+ public Response listBgpvpns(
+ // return fields
+ @QueryParam("fields") List<String> fields,
+ // note: openstack isn't clear about filtering on lists, so we aren't handling them
+ @QueryParam("id") String queryID,
+ @QueryParam("name") String queryName,
+ @QueryParam("admin_state_up") String queryAdminStateUp,
+ @QueryParam("status") String queryStatus,
+ @QueryParam("tenant_id") String queryTenantID,
+ @QueryParam("type") String queryType,
+ @QueryParam("auto_aggregate") String queryAutoAggregate,
+ // pagination
+ @QueryParam("limit") Integer limit,
+ @QueryParam("marker") String marker,
+ @DefaultValue("false") @QueryParam("page_reverse") Boolean pageReverse
+ // sorting not supported
+ ) {
+ INeutronBgpvpnCRUD bgpvpnInterface = getNeutronInterfaces().getBgpvpnInterface();
+ List<NeutronBgpvpn> allBgpvpns = bgpvpnInterface.getAllBgpvpns();
+ List<NeutronBgpvpn> ans = new ArrayList<NeutronBgpvpn>();
+ Iterator<NeutronBgpvpn> i = allBgpvpns.iterator();
+ while (i.hasNext()) {
+ NeutronBgpvpn oSN = i.next();
+ //match filters: TODO provider extension
+ Boolean bAdminStateUp = null;
+ Boolean bAutoAggregate = null;
+ if (queryAdminStateUp != null) {
+ bAdminStateUp = Boolean.valueOf(queryAdminStateUp);
+ }
+ if (queryAutoAggregate != null) {
+ bAutoAggregate = Boolean.valueOf(queryAutoAggregate);
+ }
+ if ((queryID == null || queryID.equals(oSN.getID())) &&
+ (queryName == null || queryName.equals(oSN.getBgpvpnName())) &&
+ (bAdminStateUp == null || bAdminStateUp.booleanValue() == oSN.isAdminStateUp()) &&
+ (queryStatus == null || queryStatus.equals(oSN.getStatus())) &&
+ (bAutoAggregate == null || bAutoAggregate.booleanValue() == oSN.isAutoAggregate()) &&
+ (queryTenantID == null || queryTenantID.equals(oSN.getTenantID()))) {
+ if (fields.size() > 0) {
+ ans.add(extractFields(oSN,fields));
+ } else {
+ ans.add(oSN);
+ }
+ }
+ }
+
+ if (limit != null && ans.size() > 1) {
+ // Return a paginated request
+ NeutronBgpvpnRequest request = (NeutronBgpvpnRequest) PaginatedRequestFactory.createRequest(limit,
+ marker, pageReverse, uriInfo, ans, NeutronBgpvpn.class);
+ return Response.status(HttpURLConnection.HTTP_OK).entity(request).build();
+ }
+
+ return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronBgpvpnRequest(ans)).build();
+
+ }
+
+ /**
+ * Returns a specific Bgpvpn */
+
+ @Path("{bgpvpnUUID}")
+ @GET
+ @Produces({ MediaType.APPLICATION_JSON })
+ //@TypeHint(OpenStackBgpvpns.class)
+ @StatusCodes({
+ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
+ @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
+ @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
+ @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
+ @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
+ public Response showBgpvpn(
+ @PathParam("bgpvpnUUID") String bgpvpnUUID,
+ // return fields
+ @QueryParam("fields") List<String> fields
+ ) {
+ INeutronBgpvpnCRUD bgpvpnInterface = getNeutronInterfaces().getBgpvpnInterface();
+ if (!bgpvpnInterface.bgpvpnExists(bgpvpnUUID)) {
+ throw new ResourceNotFoundException(uuidNoExist(RESOURCE_NAME));
+ }
+ if (fields.size() > 0) {
+ NeutronBgpvpn ans = bgpvpnInterface.getBgpvpn(bgpvpnUUID);
+ return Response.status(HttpURLConnection.HTTP_OK).entity(
+ new NeutronBgpvpnRequest(extractFields(ans, fields))).build();
+ } else {
+ return Response.status(HttpURLConnection.HTTP_OK).entity(
+ new NeutronBgpvpnRequest(bgpvpnInterface.getBgpvpn(bgpvpnUUID))).build();
+ }
+ }
+
+ /**
+ * Creates new Bgpvpns */
+ @POST
+ @Produces({ MediaType.APPLICATION_JSON })
+ @Consumes({ MediaType.APPLICATION_JSON })
+ @TypeHint(NeutronBgpvpn.class)
+ @StatusCodes({
+ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
+ @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
+ public Response createBgpvpns(final NeutronBgpvpnRequest input) {
+ INeutronBgpvpnCRUD bgpvpnInterface = getNeutronInterfaces().getBgpvpnInterface();
+ if (input.isSingleton()) {
+ NeutronBgpvpn singleton = input.getSingleton();
+
+ // add bgpvpn to MDSAL
+ singleton.initDefaults();
+ bgpvpnInterface.addBgpvpn(singleton);
+ } else {
+ // add items to MDSAL
+ for (NeutronBgpvpn test : input.getBulk()) {
+ test.initDefaults();
+ bgpvpnInterface.addBgpvpn(test);
+ }
+ }
+ return Response.status(HttpURLConnection.HTTP_CREATED).entity(input).build();
+ }
+
+ /**
+ * Updates a Bgpvpn */
+ @Path("{bgpvpnUUID}")
+ @PUT
+ @Produces({ MediaType.APPLICATION_JSON })
+ @Consumes({ MediaType.APPLICATION_JSON })
+ //@TypeHint(OpenStackBgpvpns.class)
+ @StatusCodes({
+ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
+ @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
+ public Response updateBgpvpn(
+ @PathParam("bgpvpnUUID") String bgpvpnUUID, final NeutronBgpvpnRequest input
+ ) {
+ INeutronBgpvpnCRUD bgpvpnInterface = getNeutronInterfaces().getBgpvpnInterface();
+
+ NeutronBgpvpn updatedObject = input.getSingleton();
+ NeutronBgpvpn original = bgpvpnInterface.getBgpvpn(bgpvpnUUID);
+
+ /*
+ * note: what we get appears to not be a delta but
+ * rather an incomplete updated object. So we need to set
+ * the ID to complete the object and then send that down
+ * for folks to check
+ */
+
+ updatedObject.setID(bgpvpnUUID);
+ updatedObject.setTenantID(original.getTenantID());
+ //Fill in defaults if they're missing in update
+ updatedObject.initDefaults();
+
+ // update bgpvpn object
+ bgpvpnInterface.updateBgpvpn(bgpvpnUUID, updatedObject);
+
+ return Response.status(HttpURLConnection.HTTP_OK).entity(
+ new NeutronBgpvpnRequest(bgpvpnInterface.getBgpvpn(bgpvpnUUID))).build();
+ }
+
+ /**
+ * Deletes a Bgpvpn */
+
+ @Path("{bgpvpnUUID}")
+ @DELETE
+ @StatusCodes({
+ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
+ @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
+ public Response deleteBgpvpn(
+ @PathParam("bgpvpnUUID") String bgpvpnUUID) {
+ INeutronBgpvpnCRUD bgpvpnInterface = getNeutronInterfaces().getBgpvpnInterface();
+
+ if (!bgpvpnInterface.removeBgpvpn(bgpvpnUUID)) {
+ throw new InternalServerErrorException("Could not delete bgpvpn");
+ }
+ return Response.status(HttpURLConnection.HTTP_NO_CONTENT).build();
+ }
+}
classes.add(NeutronVPNIKEPoliciesNorthbound.class);
classes.add(NeutronVPNIPSECPoliciesNorthbound.class);
classes.add(NeutronVPNIPSECSiteConnectionsNorthbound.class);
+ classes.add(NeutronBgpvpnsNorthbound.class);
classes.add(MOXyJsonProvider.class);
return classes;
NeutronVPNIPSECPolicyInterface.registerNewInterface(context, providerContext, registrations);
NeutronVPNIPSECSiteConnectionsInterface.registerNewInterface(context, providerContext, registrations);
NeutronFloatingIPInterface.registerNewInterface(context, providerContext, registrations);
+ NeutronBgpvpnInterface.registerNewInterface(context, providerContext, registrations);
}
@Override
--- /dev/null
+/*
+ * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. 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.neutron.transcriber;
+
+import com.google.common.collect.ImmutableBiMap;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
+import org.opendaylight.neutron.spi.INeutronBgpvpnCRUD;
+import org.opendaylight.neutron.spi.NeutronBgpvpn;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.bgpvpns.rev150903.BgpvpnTypeBase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.bgpvpns.rev150903.BgpvpnTypeL2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.bgpvpns.rev150903.BgpvpnTypeL3;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.bgpvpns.rev150903.bgpvpns.attributes.Bgpvpns;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.bgpvpns.rev150903.bgpvpns.attributes.bgpvpns.Bgpvpn;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.bgpvpns.rev150903.bgpvpns.attributes.bgpvpns.BgpvpnBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev141002.NetworkTypeBase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150325.Neutron;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NeutronBgpvpnInterface extends AbstractNeutronInterface<Bgpvpn,NeutronBgpvpn> implements INeutronBgpvpnCRUD {
+ private static final Logger LOGGER = LoggerFactory.getLogger(NeutronBgpvpnInterface.class);
+
+ private static final ImmutableBiMap<Class<? extends BgpvpnTypeBase>,String> BGPVPN_TYPE_MAP
+ = new ImmutableBiMap.Builder<Class<? extends BgpvpnTypeBase>,String>()
+ .put(BgpvpnTypeL2.class,"l2")
+ .put(BgpvpnTypeL3.class,"l3")
+ .build();
+
+ NeutronBgpvpnInterface(ProviderContext providerContext) {
+ super(providerContext);
+ }
+
+ @Override
+ public boolean bgpvpnExists(String uuid) {
+ return exists(uuid);
+ }
+
+ @Override
+ public NeutronBgpvpn getBgpvpn(String uuid) {
+ return get(uuid);
+ }
+
+ @Override
+ public List<NeutronBgpvpn> getAll() {
+ Set<NeutronBgpvpn> allBgpvpns = new HashSet<NeutronBgpvpn>();
+ Bgpvpns bgpvpns = readMd(createInstanceIdentifier());
+ if (bgpvpns != null) {
+ for (Bgpvpn bgpvpn: bgpvpns.getBgpvpn()) {
+ allBgpvpns.add(fromMd(bgpvpn));
+ }
+ }
+ LOGGER.debug("Exiting getAllBgpvpns, Found {} OpenStackBgpvpns", allBgpvpns.size());
+ List<NeutronBgpvpn> ans = new ArrayList<NeutronBgpvpn>();
+ ans.addAll(allBgpvpns);
+ return ans;
+ }
+
+ @Override
+ public List<NeutronBgpvpn> getAllBgpvpns() {
+ return getAll();
+ }
+
+ @Override
+ public boolean addBgpvpn(NeutronBgpvpn input) {
+ return add(input);
+ }
+
+ @Override
+ public boolean removeBgpvpn(String uuid) {
+ return remove(uuid);
+ }
+
+ @Override
+ public boolean updateBgpvpn(String uuid, NeutronBgpvpn delta) {
+ return update(uuid, delta);
+ }
+
+ @Override
+ public boolean bgpvpnInUse(String bgpvpnUUID) {
+ return !exists(bgpvpnUUID);
+ }
+
+ protected NeutronBgpvpn fromMd(Bgpvpn bgpvpn) {
+ NeutronBgpvpn result = new NeutronBgpvpn();
+ result.setAdminStateUp(bgpvpn.isAdminStateUp());
+ result.setBgpvpnName(bgpvpn.getName());
+ result.setAutoAggregate(bgpvpn.isAutoAggregate());
+ result.setStatus(bgpvpn.getStatus());
+ result.setTenantID(bgpvpn.getTenantId().getValue().replace("-", ""));
+ result.setID(bgpvpn.getUuid().getValue());
+ if(bgpvpn.getVnid() != null) {
+ result.setVnid(bgpvpn.getVnid());
+ }
+ if(bgpvpn.getType() != null) {
+ result.setType(BGPVPN_TYPE_MAP.get(bgpvpn.getType()));
+ }
+ if(bgpvpn.getTechnique() != null) {
+ result.setTechnique(bgpvpn.getTechnique());
+ }
+ if (bgpvpn.getRouteTargets() != null) {
+ List<String> routeTargets = new ArrayList<String>();
+ for( String routeTarget : bgpvpn.getRouteTargets()) {
+ routeTargets.add(routeTarget);
+ }
+ result.setRouteTargets(routeTargets);
+ }
+ if (bgpvpn.getImportTargets() != null) {
+ List<String> importTargets = new ArrayList<String>();
+ for( String importTarget : bgpvpn.getImportTargets()) {
+ importTargets.add(importTarget);
+ }
+ result.setImportTargets(importTargets);
+ }
+ if (bgpvpn.getExportTargets() != null) {
+ List<String> exportTargets = new ArrayList<String>();
+ for( String exportTarget : bgpvpn.getExportTargets()) {
+ exportTargets.add(exportTarget);
+ }
+ result.setExportTargets(exportTargets);
+ }
+ if (bgpvpn.getRouteDistinguishers() != null) {
+ List<String> routeDistinguishers = new ArrayList<String>();
+ for( String routeDistinguisher : bgpvpn.getRouteDistinguishers()) {
+ routeDistinguishers.add(routeDistinguisher);
+ }
+ result.setRouteDistinguishers(routeDistinguishers);
+ }
+ if (bgpvpn.getRouters() != null) {
+ List<String> routers = new ArrayList<String>();
+ for( Uuid router : bgpvpn.getRouters()) {
+ routers.add(router.getValue());
+ }
+ result.setRouters(routers);
+ }
+ if (bgpvpn.getNetworks() != null) {
+ List<String> networks = new ArrayList<String>();
+ for( Uuid network : bgpvpn.getNetworks()) {
+ networks.add(network.getValue());
+ }
+ result.setNetworks(networks);
+ }
+ return result;
+ }
+
+ protected Bgpvpn toMd(NeutronBgpvpn bgpvpn) {
+ BgpvpnBuilder bgpvpnBuilder = new BgpvpnBuilder();
+
+ bgpvpnBuilder.setAdminStateUp(bgpvpn.getAdminStateUp());
+ if (bgpvpn.getBgpvpnName() != null) {
+ bgpvpnBuilder.setName(bgpvpn.getBgpvpnName());
+ }
+ if (bgpvpn.getAutoAggregate() != null) {
+ bgpvpnBuilder.setAutoAggregate(bgpvpn.getAutoAggregate());
+ }
+ if (bgpvpn.getStatus() != null) {
+ bgpvpnBuilder.setStatus(bgpvpn.getStatus());
+ }
+ if (bgpvpn.getVnid() != null) {
+ bgpvpnBuilder.setVnid(bgpvpn.getVnid());
+ }
+ if (bgpvpn.getType() != null) {
+ ImmutableBiMap<String, Class<? extends BgpvpnTypeBase>> mapper = BGPVPN_TYPE_MAP.inverse();
+ bgpvpnBuilder.setType(mapper.get(bgpvpn.getType()));
+ }
+ if (bgpvpn.getTechnique() != null) {
+ bgpvpnBuilder.setTechnique(bgpvpn.getTechnique());
+ }
+ if (bgpvpn.getRouteTargets() != null) {
+ List<String> routeTargets = new ArrayList<String>();
+ for( String routeTarget : bgpvpn.getRouteTargets()) {
+ routeTargets.add(routeTarget);
+ }
+ bgpvpnBuilder.setRouteTargets(routeTargets);
+ }
+ if (bgpvpn.getImportTargets() != null) {
+ List<String> importTargets = new ArrayList<String>();
+ for( String importTarget : bgpvpn.getImportTargets()) {
+ importTargets.add(importTarget);
+ }
+ bgpvpnBuilder.setImportTargets(importTargets);
+ }
+ if (bgpvpn.getExportTargets() != null) {
+ List<String> exportTargets = new ArrayList<String>();
+ for( String exportTarget : bgpvpn.getExportTargets()) {
+ exportTargets.add(exportTarget);
+ }
+ bgpvpnBuilder.setExportTargets(exportTargets);
+ }
+ if (bgpvpn.getRouteDistinguishers() != null) {
+ List<String> routeDistinguishers = new ArrayList<String>();
+ for( String routeDistinguisher : bgpvpn.getRouteDistinguishers()) {
+ routeDistinguishers.add(routeDistinguisher);
+ }
+ bgpvpnBuilder.setRouteDistinguishers(routeDistinguishers);
+ }
+ if (bgpvpn.getRouters() != null) {
+ List<Uuid> routers = new ArrayList<Uuid>();
+ for( String router : bgpvpn.getRouters()) {
+ routers.add(toUuid(router));
+ }
+ bgpvpnBuilder.setRouters(routers);
+ }
+ if (bgpvpn.getNetworks() != null) {
+ List<Uuid> networks = new ArrayList<Uuid>();
+ for( String network : bgpvpn.getNetworks()) {
+ networks.add(toUuid(network));
+ }
+ bgpvpnBuilder.setNetworks(networks);
+ }
+ if (bgpvpn.getTenantID() != null) {
+ bgpvpnBuilder.setTenantId(toUuid(bgpvpn.getTenantID()));
+ }
+ if (bgpvpn.getID() != null) {
+ bgpvpnBuilder.setUuid(toUuid(bgpvpn.getID()));
+ } else {
+ LOGGER.warn("Attempting to write neutron bgpvpn without UUID");
+ }
+ return bgpvpnBuilder.build();
+ }
+
+ protected Bgpvpn toMd(String uuid) {
+ BgpvpnBuilder bgpvpnBuilder = new BgpvpnBuilder();
+ bgpvpnBuilder.setUuid(toUuid(uuid));
+ return bgpvpnBuilder.build();
+ }
+
+ @Override
+ protected InstanceIdentifier<Bgpvpn> createInstanceIdentifier(Bgpvpn bgpvpn) {
+ return InstanceIdentifier.create(Neutron.class)
+ .child(Bgpvpns.class)
+ .child(Bgpvpn.class, bgpvpn.getKey());
+ }
+
+ protected InstanceIdentifier<Bgpvpns> createInstanceIdentifier() {
+ return InstanceIdentifier.create(Neutron.class)
+ .child(Bgpvpns.class);
+ }
+
+ public static void registerNewInterface(BundleContext context,
+ ProviderContext providerContext,
+ List<ServiceRegistration<?>> registrations) {
+ NeutronBgpvpnInterface neutronNetworkInterface = new NeutronBgpvpnInterface(providerContext);
+ ServiceRegistration<INeutronBgpvpnCRUD> neutronNetworkInterfaceRegistration = context.registerService(INeutronBgpvpnCRUD.class, neutronNetworkInterface, null);
+ if(neutronNetworkInterfaceRegistration != null) {
+ registrations.add(neutronNetworkInterfaceRegistration);
+ }
+ }
+}