Bug 6865 - Transcriber skips the uppercase protocol field 91/46791/3
authorAnil Vishnoi <vishnoianil@gmail.com>
Thu, 6 Oct 2016 02:22:17 +0000 (19:22 -0700)
committerAnil Vishnoi <vishnoianil@gmail.com>
Thu, 13 Oct 2016 18:07:04 +0000 (11:07 -0700)
Networking-sfc sends protocol string in lowercase
(e.g tcp and not TCP), but neutron spi try to find
it using the uppercase and don't find it and
eventually ignore this field. To be consistent with
other API's, flow classifier will only accept lowercase
protocol name and return 400 (Bad Request) for any other
protocol string.

Change-Id: I204f58c9cf1cf13446122c8f818ce498866a2caf
Signed-off-by: Anil Vishnoi <vishnoianil@gmail.com>
features/production/src/main/features/features.xml
integration/test/src/test/java/org/opendaylight/neutron/e2etest/ITNeutronE2E.java
integration/test/src/test/java/org/opendaylight/neutron/e2etest/NeutronSFCFlowClassifierTests.java
transcriber/pom.xml
transcriber/src/main/java/org/opendaylight/neutron/transcriber/NeutronSFCFlowClassifierInterface.java

index a4e9a7753d46f73050b9b24c7733ef1de1a5176e..bf5b81ca16b563aeb444477f7e60229f5650af9a 100644 (file)
@@ -36,6 +36,7 @@
     <bundle>mvn:com.fasterxml.jackson.core/jackson-annotations/{{VERSION}}</bundle>
   </feature>
   <feature name='odl-neutron-transcriber' version='${project.version}' description="OpenDaylight :: Neutron :: Implementation">
+    <feature version='${project.version}'>odl-neutron-northbound-api</feature>
     <feature version='${project.version}'>odl-neutron-spi</feature>
     <feature>war</feature>
     <feature version='${controller.mdsal.version}'>odl-mdsal-broker</feature>
index 9ab4cc3bf81a2f112cf08c66f86df7c0d274025d..2e8fa5815242419bfd301c7bfa02997c8aaf731b 100644 (file)
@@ -172,6 +172,16 @@ public class ITNeutronE2E {
         }
     }
 
+    static void test_create(String url_s, int responseCode, String content, String context) {
+        try {
+            URL url = new URL(url_s);
+            HttpURLConnection httpConn = httpURLConnectionFactoryPost(url, content);
+            Assert.assertEquals(context, responseCode, httpConn.getResponseCode());
+        } catch (IOException e) {
+            throw new UncheckedIOException(e);
+        }
+    }
+
     static void test_modify(String url_s, String content, String context) {
         try {
             URL url = new URL(url_s);
index 3ce484d36ae0568ea9075094121ef195e60a18b6..7c57fff0891320e0483825459b11752d612e7905 100644 (file)
@@ -24,7 +24,7 @@ public class NeutronSFCFlowClassifierTests {
         String url = base + "/sfc/flowclassifiers";
         String content = "{ \"flowclassifier\" : { \"name\": \"flowclassifier1\", "
             + "\"ethertype\": \"IPv4\", "
-            + "\"protocol\": \"UDP\", "
+            + "\"protocol\": \"udp\", "
             + "\"source_port_range_min\": 100, "
             + "\"source_port_range_max\": 200, "
             + "\"destination_port_range_min\": 100, "
@@ -67,7 +67,7 @@ public class NeutronSFCFlowClassifierTests {
         String url = base + "/sfc/flowclassifiers/4e8e5957-649f-477b-9e5b-f1f75b21c03c";
         String content = "{ \"flowclassifier\" : { \"name\": \"flowclassifier1\", "
             + "\"ethertype\": \"IPv4\", "
-            + "\"protocol\": \"UDP\", "
+            + "\"protocol\": \"udp\", "
             + "\"source_port_range_min\": 100, "
             + "\"source_port_range_max\": 200, "
             + "\"destination_port_range_min\": 100, "
@@ -96,6 +96,29 @@ public class NeutronSFCFlowClassifierTests {
         ITNeutronE2E.test_fetch(url, false, "SFC flowclassifier Element negative GET failed");
     }
 
+    public void test_bug_6865() {
+        String url = base + "/sfc/flowclassifiers";
+        String content = "{ \"flowclassifier\" : { \"name\": \"flowclassifier-bug-6865\", "
+                + "\"ethertype\": \"IPv4\", "
+                + "\"protocol\": \"TCP\", "
+                + "\"source_port_range_min\": 100, "
+                + "\"source_port_range_max\": 200, "
+                + "\"destination_port_range_min\": 100, "
+                + "\"destination_port_range_max\": 200, "
+                + "\"source_ip_prefix\": \"10.0.0.0/24\", "
+                + "\"destination_ip_prefix\": \"11.0.0.0/24\", "
+                + "\"logical_source_port\": \"5e8e5957-649f-477b-9e5b-f1f75b21c03c\", "
+                + "\"logical_destination_port\": \"6e8e5957-649f-477b-9e5b-f1f75b21c03c\", "
+                + "\"l7_parameters\": [ "
+                + "{ "
+                + "\"Key\": \"value\" "
+                + "} "
+                + "], "
+                + "\"tenant_id\": \"4969c491a3c74ee4af974e6d800c62de\", "
+                + "\"id\": \"5e8e5957-649f-477b-9e5b-f1f75b21c03c\" } }";
+        ITNeutronE2E.test_create(url, 400, content, "SFC Flowclassifier Bug 6865 regressed");
+    }
+
     public static void runTests(String base) {
         NeutronSFCFlowClassifierTests sfc_flowclassifier_tester = new NeutronSFCFlowClassifierTests(base);
         String createJsonString = sfc_flowclassifier_tester.singleton_sfc_flowclassifier_create_test();
@@ -106,5 +129,6 @@ public class NeutronSFCFlowClassifierTests {
         sfc_flowclassifier_tester.sfc_flowclassifier_modify_test();
         sfc_flowclassifier_tester.sfc_flowclassifier_delete_test();
         sfc_flowclassifier_tester.sfc_flowclassifier_element_negative_get_test();
+        sfc_flowclassifier_tester.test_bug_6865();
     }
 }
index 4c112f35e2627e8d52a1942f08a8c19011cacb40..672f91299a4dac4e18855154ab031560bbcd55a5 100644 (file)
     </plugins>
   </build>
   <dependencies>
+    <dependency>
+      <groupId>org.opendaylight.neutron</groupId>
+      <artifactId>northbound-api</artifactId>
+      <version>${project.version}</version>
+    </dependency>
     <dependency>
       <groupId>org.opendaylight.neutron</groupId>
       <artifactId>neutron-spi</artifactId>
index d48de990c75cbba17de42effce3fc0eea80f42c3..3e9f446cfc2b6088e11db61cf943e72c2524fbc8 100644 (file)
@@ -11,7 +11,9 @@ import com.google.common.collect.ImmutableBiMap;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
+
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.neutron.northbound.api.BadRequestException;
 import org.opendaylight.neutron.spi.INeutronSFCFlowClassifierCRUD;
 import org.opendaylight.neutron.spi.NeutronSFCFlowClassifier;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
@@ -49,7 +51,7 @@ public final class NeutronSFCFlowClassifierInterface
 
     private static final ImmutableBiMap<Class<? extends ProtocolBase>,
             String> PROTOCOL_MAP = new ImmutableBiMap.Builder<Class<? extends ProtocolBase>, String>()
-                    .put(ProtocolTcp.class, "TCP").put(ProtocolUdp.class, "UDP").put(ProtocolIcmp.class, "ICMP")
+                    .put(ProtocolTcp.class, "tcp").put(ProtocolUdp.class, "udp").put(ProtocolIcmp.class, "icmp")
                     .build();
 
     NeutronSFCFlowClassifierInterface(DataBroker db) {
@@ -75,7 +77,12 @@ public final class NeutronSFCFlowClassifierInterface
         }
         if (neutronClassifier.getProtocol() != null) {
             final ImmutableBiMap<String, Class<? extends ProtocolBase>> mapper = PROTOCOL_MAP.inverse();
-            result.setProtocol(mapper.get(neutronClassifier.getProtocol()));
+            Class<? extends ProtocolBase> protocol = mapper.get(neutronClassifier.getProtocol());
+            if (protocol != null) {
+                result.setProtocol(protocol);
+            } else {
+                throw new BadRequestException("Protocol {" + neutronClassifier.getProtocol() + "} is not supported");
+            }
         }
         if (neutronClassifier.getSourcePortRangeMin() != null) {
             result.setSourcePortRangeMin(neutronClassifier.getSourcePortRangeMin());