BUG-5137: extraroutes in router not working 62/34062/1
authorVishal Thapar <vishal.thapar@ericsson.com>
Mon, 1 Feb 2016 08:51:15 +0000 (14:21 +0530)
committerIsaku Yamahata <isaku.yamahata@gmail.com>
Thu, 4 Feb 2016 11:19:11 +0000 (11:19 +0000)
Neutron API defines extraroutes as list of destination and nexthop but in
neutron-l3.yang they're defined as list of strings. So, when these routes
are present in a router object sent by openstack we are unable to store
them in MDSAL. Fix is to change the type of routes in l3-attributes to
match with what Neutron API sends us.

Change-Id: I83519edcbdf6f4fcae34ae9650cf8ede40256296
Signed-off-by: Vishal Thapar <vishal.thapar@ericsson.com>
(cherry picked from commit 59f3919dd01797fb056fa5dcdebda2076a936954)

model/src/main/yang/neutron-L3.yang
neutron-spi/src/main/java/org/opendaylight/neutron/spi/NeutronRoute.java [new file with mode: 0644]
neutron-spi/src/main/java/org/opendaylight/neutron/spi/NeutronRouter.java
neutron-spi/src/main/java/org/opendaylight/neutron/spi/NeutronSubnet_HostRoute.java
neutron-spi/src/test/java/org/opendaylight/neutron/spi/NeutronRouterJAXBTest.java
transcriber/src/main/java/org/opendaylight/neutron/transcriber/NeutronRouterInterface.java

index 5b00ffb4e439f7144a1a274885120899f46515b7..4442c414d446db178b719cf3c40e2ab8569a2516 100644 (file)
@@ -39,9 +39,15 @@ module neutron-L3 {
             description "the port uuid holding the router's gateway address.";
             type yang:uuid;
         }
-        leaf-list routes {
+        list routes {
             description "list of routes for this router.";
-            type string;
+            leaf destination {
+                description "Specifies a destination in CIDR format";
+                type inet:ip-prefix;
+            }
+            leaf nexthop {
+                type inet:ip-address;
+            }
         }
         leaf router-status {
             description "Contains the Router status.";
diff --git a/neutron-spi/src/main/java/org/opendaylight/neutron/spi/NeutronRoute.java b/neutron-spi/src/main/java/org/opendaylight/neutron/spi/NeutronRoute.java
new file mode 100644 (file)
index 0000000..7c80560
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2013, 2015 IBM Corporation 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 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 NeutronRoute implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    // See OpenStack Network API v2.0 Reference for description of
+    // annotated attributes
+
+    @XmlElement(name = "destination")
+    String destination;
+
+    @XmlElement(name = "nexthop")
+    String nextHop;
+
+    /**
+     *  HostRoute constructor
+     */
+    public NeutronRoute() { }
+
+    public String getDestination() {
+        return destination;
+    }
+
+    public void setDestination(String destination) {
+        this.destination = destination;
+    }
+
+    public String getNextHop() {
+        return nextHop;
+    }
+
+    public void setNextHop(String nextHop) {
+        this.nextHop = nextHop;
+    }
+
+    @Override
+    public String toString() {
+        return "NeutronRoute [" +
+            "destination=" + destination +
+            ", nextHop=" + nextHop + "]";
+    }
+
+}
index 50c4532638903ab95fc2cecfd6bc95117f1f24b1..6c296204a2f6e5233dc4dad63da2455cdd963033 100644 (file)
@@ -46,7 +46,7 @@ public class NeutronRouter extends NeutronObject implements Serializable, INeutr
     String gatewayPortId;
 
     @XmlElement (name = "routes")
-    List<String> routes;
+    List<NeutronRoute> routes;
 
     /* Holds a map of OpenStackRouterInterfaces by subnet UUID
      * used for internal mapping to DOVE
@@ -120,11 +120,11 @@ public class NeutronRouter extends NeutronObject implements Serializable, INeutr
         this.gatewayPortId = gatewayPortId;
     }
 
-    public List<String> getRoutes() {
+    public List<NeutronRoute> getRoutes() {
         return routes;
     }
 
-    public void setRoutes(List<String> routes) {
+    public void setRoutes(List<NeutronRoute> routes) {
         this.routes = routes;
     }
 
index 70bf1027ebff531aada22fd1ace6b8642c691144..73a812e5de86d4dc268b20282961bcfe22c8e0f3 100644 (file)
@@ -17,6 +17,7 @@ import javax.xml.bind.annotation.XmlRootElement;
 
 @XmlRootElement
 @XmlAccessorType(XmlAccessType.NONE)
+@Deprecated
 public class NeutronSubnet_HostRoute implements Serializable {
     private static final long serialVersionUID = 1L;
 
index 014fe971ae75662224bc6ff179284882870efde9..1447c2d06ade3850edcd3a1a7a3c70a63f8326ba 100644 (file)
@@ -24,7 +24,7 @@ public class NeutronRouterJAXBTest {
         "\"external_gateway_info\": {\"network_id\": \"e9330b1f-a2ef-4160-a991-169e56ab17f6\" }, " +
         "\"distributed\": false , " +
         "\"gw_port_id\": \"3b80198d-4f7b-4f77-9ef5-774d54e17127\", " +
-        "\"routes\": [ \"3b80198d-4f7b-4f77-9ef5-774d54e17126\" ] }";
+        "\"routes\": [ { \"destination\":\"10.0.0.0/24\",\"nexthop\":\"1.1.1.1\" } ] }";
 
     @Test
     public void test_NeutronRouter_JAXB() {
@@ -34,7 +34,7 @@ public class NeutronRouterJAXBTest {
                     NeutronRouter_sourceJson);
 
             NeutronRouter_NetworkReference external_gateway_info = testObject.getExternalGatewayInfo();
-            List<String> routes = testObject.getRoutes();
+            List<NeutronRoute> routes = testObject.getRoutes();
 
             Assert.assertEquals("NeutronRouter JAXB Test 1: Testing router_uuid failed",
                     "e9330b1f-a2ef-4160-a991-169e56ab17f5", testObject.getID());
@@ -61,7 +61,7 @@ public class NeutronRouterJAXBTest {
             Assert.assertEquals("NeutronRouter JAXB Test 9.1: Testing routes failed", 1, routes.size());
 
             Assert.assertEquals("NeutronRouter JAXB Test 9.2: Testing routes failed",
-                    "3b80198d-4f7b-4f77-9ef5-774d54e17126", routes.get(0));
+                    "10.0.0.0/24", routes.get(0).getDestination());
 
         } catch (Exception e) {
             Assert.fail("Tests failed");
index b4fa09bdf0257fcd2749c55091928122420aec41..1f71e1a1e7d1bde86968fc97e3b06d8600459b77 100644 (file)
@@ -18,11 +18,15 @@ import java.util.Set;
 
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.neutron.spi.INeutronRouterCRUD;
+import org.opendaylight.neutron.spi.NeutronRoute;
 import org.opendaylight.neutron.spi.Neutron_IPs;
 import org.opendaylight.neutron.spi.NeutronRouter;
 import org.opendaylight.neutron.spi.NeutronRouter_Interface;
 import org.opendaylight.neutron.spi.NeutronRouter_NetworkReference;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.l3.attributes.Routes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.l3.attributes.RoutesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.Routers;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.RouterBuilder;
@@ -117,9 +121,12 @@ public class NeutronRouterInterface extends AbstractNeutronInterface<Router, Rou
         routerBuilder.setAdminStateUp(router.getAdminStateUp());
         routerBuilder.setDistributed(router.getDistributed());
         if (router.getRoutes() != null) {
-            List<String> routes = new ArrayList<String>();
-            for (String route : router.getRoutes()) {
-                routes.add(route);
+            List<Routes> routes = new ArrayList<Routes>();
+            for (NeutronRoute route : router.getRoutes()) {
+                RoutesBuilder routeBuilder = new RoutesBuilder();
+                routeBuilder.setDestination(new IpPrefix(route.getDestination().toCharArray()));
+                routeBuilder.setNexthop(new IpAddress(route.getNextHop().toCharArray()));
+                routes.add(routeBuilder.build());
             }
             routerBuilder.setRoutes(routes);
         }
@@ -202,9 +209,12 @@ public class NeutronRouterInterface extends AbstractNeutronInterface<Router, Rou
             result.setGatewayPortId(String.valueOf(router.getGatewayPortId().getValue()));
         }
         if (router.getRoutes() != null) {
-            List<String> routes = new ArrayList<String>();
-            for (String route : router.getRoutes()) {
-                routes.add(route);
+            List<NeutronRoute> routes = new ArrayList<NeutronRoute>();
+            for (Routes route : router.getRoutes()) {
+                NeutronRoute routerRoute = new NeutronRoute();
+                routerRoute.setDestination(String.valueOf(route.getDestination().getValue()));
+                routerRoute.setNextHop(String.valueOf(route.getNexthop().getValue()));
+                routes.add(routerRoute);
             }
             result.setRoutes(routes);
         }