Merge "Refactoring SubnetConfig: -Use NetUtils IP validation methods instead of own...
authorAlessandro Boch <aboch@cisco.com>
Fri, 29 Mar 2013 20:53:19 +0000 (20:53 +0000)
committerGerrit Code Review <gerrit@daylight1.linux-foundation.org>
Fri, 29 Mar 2013 20:53:19 +0000 (20:53 +0000)
opendaylight/distribution/opendaylight/src/main/resources/configuration/config.ini
opendaylight/northbound/commons/src/test/java/org/opendaylight/controller/northbound/commons/CommonsNorthboundTest.java [new file with mode: 0644]
opendaylight/northbound/commons/src/test/java/org/opendaylight/controller/northbound/commons/exception/CommonsNorthboundExceptionTest.java [new file with mode: 0644]
opendaylight/northbound/statistics/src/test/java/org/opendaylight/controller/statistics/northbound/StatisticsNorthboundTest.java [new file with mode: 0644]
opendaylight/northbound/topology/src/test/java/org/opendaylight/controller/topology/northbound/TopologyTest.java [new file with mode: 0644]
opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/ControllerIO.java
opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/SwitchHandler.java

index 1b3d1ec..3f373e9 100644 (file)
@@ -39,3 +39,9 @@ logback.configurationFile=configuration/logback.xml
 
 # Embedded Tomcat configuration File
 org.eclipse.gemini.web.tomcat.config.path=configuration/tomcat-server.xml
+
+# Open Flow related system parameters
+# TCP port on which the controller is listening (default 6633)
+# of.listenPort=6633
+# The time (in milliseconds) the controller will wait for a response after sending a Barrier Request or a Statistic Request message (default 2000 msec)
+# of.messageResponseTimer=2000
diff --git a/opendaylight/northbound/commons/src/test/java/org/opendaylight/controller/northbound/commons/CommonsNorthboundTest.java b/opendaylight/northbound/commons/src/test/java/org/opendaylight/controller/northbound/commons/CommonsNorthboundTest.java
new file mode 100644 (file)
index 0000000..9dba530
--- /dev/null
@@ -0,0 +1,19 @@
+package org.opendaylight.controller.northbound.commons;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import junit.framework.TestCase;
+
+public class CommonsNorthboundTest extends TestCase {
+
+    @Test
+    public void testRestMessages() {
+        Assert.assertTrue(RestMessages.SUCCESS.toString().equals("Success"));
+        Assert.assertTrue(RestMessages.INTERNALERROR.toString().equals(
+                "Internal Error"));
+        Assert.assertTrue(RestMessages.INVALIDDATA.toString().equals(
+                "Data is invalid or conflicts with URI"));
+    }
+
+}
diff --git a/opendaylight/northbound/commons/src/test/java/org/opendaylight/controller/northbound/commons/exception/CommonsNorthboundExceptionTest.java b/opendaylight/northbound/commons/src/test/java/org/opendaylight/controller/northbound/commons/exception/CommonsNorthboundExceptionTest.java
new file mode 100644 (file)
index 0000000..65790ad
--- /dev/null
@@ -0,0 +1,133 @@
+package org.opendaylight.controller.northbound.commons.exception;
+
+import javax.ws.rs.core.Response;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import junit.framework.TestCase;
+
+public class CommonsNorthboundExceptionTest extends TestCase {
+
+    @Test
+    public void testMethodNotAllowed() {
+        MethodNotAllowed mna = new MethodNotAllowed();
+        Assert.assertTrue(mna.getStatusCode() == 405);
+        Assert.assertTrue(mna.getReasonPhrase().equals("Method Not Allowed"));
+        Assert.assertTrue(mna.getFamily().equals(
+                Response.Status.Family.CLIENT_ERROR));
+    }
+
+    @Test
+    public void testInternalServerErrorException() {
+        try {
+            throw new InternalServerErrorException("Internal Server Exception");
+        } catch (InternalServerErrorException e) {
+            Assert.assertTrue(e instanceof InternalServerErrorException);
+            Assert.assertTrue(e.getResponse().getEntity()
+                    .equals("Internal Server Exception"));
+        }
+    }
+
+    @Test
+    public void testMethodNotAllowedException() {
+        try {
+            throw new MethodNotAllowedException("Method Not Allowed Exception");
+        } catch (MethodNotAllowedException e) {
+            Assert.assertTrue(e instanceof MethodNotAllowedException);
+            Assert.assertTrue(e.getResponse().getEntity()
+                    .equals("Method Not Allowed Exception"));
+        }
+    }
+
+    @Test
+    public void testNotAcceptableException() {
+        try {
+            throw new NotAcceptableException("Not Acceptable Exception");
+        } catch (NotAcceptableException e) {
+            Assert.assertTrue(e instanceof NotAcceptableException);
+            Assert.assertTrue(e.getResponse().getEntity()
+                    .equals("Not Acceptable Exception"));
+        }
+    }
+
+    @Test
+    public void testResourceConflictException() {
+        try {
+            throw new ResourceConflictException("Resource Conflict Exception");
+        } catch (ResourceConflictException e) {
+            Assert.assertTrue(e instanceof ResourceConflictException);
+            Assert.assertTrue(e.getResponse().getEntity()
+                    .equals("Resource Conflict Exception"));
+        }
+    }
+
+    @Test
+    public void testResourceForbiddenException() {
+        try {
+            throw new ResourceForbiddenException("Resource Forbidden Exception");
+        } catch (ResourceForbiddenException e) {
+            Assert.assertTrue(e instanceof ResourceForbiddenException);
+            Assert.assertTrue(e.getResponse().getEntity()
+                    .equals("Resource Forbidden Exception"));
+        }
+    }
+
+    @Test
+    public void testResourceGoneException() {
+        try {
+            throw new ResourceGoneException("Resource Gone Exception");
+        } catch (ResourceGoneException e) {
+            Assert.assertTrue(e instanceof ResourceGoneException);
+            Assert.assertTrue(e.getResponse().getEntity()
+                    .equals("Resource Gone Exception"));
+        }
+    }
+
+    @Test
+    public void testResourceNotFoundException() {
+        try {
+            throw new ResourceNotFoundException("Resource Not Found Exception");
+        } catch (ResourceNotFoundException e) {
+            Assert.assertTrue(e instanceof ResourceNotFoundException);
+            Assert.assertTrue(e.getResponse().getEntity()
+                    .equals("Resource Not Found Exception"));
+        }
+    }
+
+    @Test
+    public void testServiceUnavailableException() {
+        try {
+            throw new ServiceUnavailableException(
+                    "Service Unavailable Exception");
+        } catch (ServiceUnavailableException e) {
+            Assert.assertTrue(e instanceof ServiceUnavailableException);
+            Assert.assertTrue(e.getResponse().getEntity()
+                    .equals("Service Unavailable Exception"));
+        }
+    }
+
+    @Test
+    public void testUnauthorizedException() {
+        try {
+            throw new UnauthorizedException("Unauthorized Exception");
+        } catch (UnauthorizedException e) {
+            Assert.assertTrue(e instanceof UnauthorizedException);
+            Assert.assertTrue(e.getResponse().getEntity()
+                    .equals("Unauthorized Exception"));
+        }
+    }
+
+    @Test
+    public void testUnsupportedMediaTypeException() {
+        try {
+            throw new UnsupportedMediaTypeException(
+                    "Unsupported Media Type Exception");
+        } catch (UnsupportedMediaTypeException e) {
+            Assert.assertTrue(e instanceof UnsupportedMediaTypeException);
+            Assert.assertTrue(e.getResponse().getEntity()
+                    .equals("Unsupported Media Type Exception"));
+        }
+    }
+
+}
diff --git a/opendaylight/northbound/statistics/src/test/java/org/opendaylight/controller/statistics/northbound/StatisticsNorthboundTest.java b/opendaylight/northbound/statistics/src/test/java/org/opendaylight/controller/statistics/northbound/StatisticsNorthboundTest.java
new file mode 100644 (file)
index 0000000..3790ae8
--- /dev/null
@@ -0,0 +1,67 @@
+package org.opendaylight.controller.statistics.northbound;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.controller.sal.reader.FlowOnNode;
+import org.opendaylight.controller.sal.reader.NodeConnectorStatistics;
+import org.opendaylight.controller.sal.utils.NodeCreator;
+
+import junit.framework.TestCase;
+
+public class StatisticsNorthboundTest extends TestCase {
+
+    @Test
+    public void testFlowStatistics() {
+        List<FlowOnNode> fon = new ArrayList<FlowOnNode>();
+        Node node = NodeCreator.createOFNode(1L);
+        FlowStatistics fs = new FlowStatistics(node, fon);
+        Assert.assertTrue(fs.getNode().equals(node));
+        Assert.assertTrue(fs.getFlowStats().equals(fon));
+
+        Node node2 = NodeCreator.createOFNode(2L);
+        fs.setNode(node2);
+        Assert.assertTrue(fs.getNode().equals(node2));
+        fs.setNode(node2);
+        Assert.assertTrue(fs.getNode().equals(node2));
+        fs.setFlowStats(null);
+        Assert.assertTrue(fs.getFlowStats() == null);
+    }
+
+    @Test
+    public void testAllFlowStatistics() {
+        List<FlowStatistics> fs = new ArrayList<FlowStatistics>();
+        AllFlowStatistics afs = new AllFlowStatistics(fs);
+        Assert.assertTrue(afs.getFlowStatistics().equals(fs));
+        afs.setFlowStatistics(null);
+        Assert.assertTrue(afs.getFlowStatistics() == null);
+    }
+
+    @Test
+    public void testPortStatistics() {
+        List<NodeConnectorStatistics> ncs = new ArrayList<NodeConnectorStatistics>();
+        Node node = NodeCreator.createOFNode(1L);
+        PortStatistics ps = new PortStatistics(node, ncs);
+
+        Assert.assertTrue(ps.getNode().equals(node));
+        Assert.assertTrue(ps.getPortStats().equals(ncs));
+        Node node2 = NodeCreator.createOFNode(2L);
+        ps.setNode(node2);
+        Assert.assertTrue(ps.getNode().equals(node2));
+        ps.setFlowStats(null);
+        Assert.assertTrue(ps.getPortStats() == null);
+    }
+
+    @Test
+    public void testAllPortStatistics() {
+        List<PortStatistics> ps = new ArrayList<PortStatistics>();
+        AllPortStatistics aps = new AllPortStatistics(ps);
+        Assert.assertTrue(aps.getPortStatistics().equals(ps));
+        aps.setPortStatistics(null);
+        Assert.assertTrue(aps.getPortStatistics() == null);
+    }
+
+}
diff --git a/opendaylight/northbound/topology/src/test/java/org/opendaylight/controller/topology/northbound/TopologyTest.java b/opendaylight/northbound/topology/src/test/java/org/opendaylight/controller/topology/northbound/TopologyTest.java
new file mode 100644 (file)
index 0000000..13b6e5f
--- /dev/null
@@ -0,0 +1,114 @@
+package org.opendaylight.controller.topology.northbound;
+
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.junit.Test;
+import org.opendaylight.controller.sal.core.Bandwidth;
+import org.opendaylight.controller.sal.core.ConstructionException;
+import org.opendaylight.controller.sal.core.Edge;
+import org.opendaylight.controller.sal.core.Latency;
+import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.controller.sal.core.NodeConnector;
+import org.opendaylight.controller.sal.core.Property;
+import org.opendaylight.controller.sal.core.State;
+import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
+import org.opendaylight.controller.sal.utils.NodeCreator;
+
+public class TopologyTest {
+
+    @Test
+    public void edgePropertiesTopologyTest() {
+
+        //Create 3 nodes and edges between them
+        Node n1 = NodeCreator.createOFNode((long)1);
+        Node n2 = NodeCreator.createOFNode((long)2);
+        Node n3 = NodeCreator.createOFNode((long)3);
+
+        NodeConnector nc11 = NodeConnectorCreator.createOFNodeConnector((short) 1, n1);
+        NodeConnector nc12 = NodeConnectorCreator.createOFNodeConnector((short) 2, n1);
+        NodeConnector nc21 = NodeConnectorCreator.createOFNodeConnector((short) 1, n2);
+        NodeConnector nc22 = NodeConnectorCreator.createOFNodeConnector((short) 2, n2);
+        NodeConnector nc23 = NodeConnectorCreator.createOFNodeConnector((short) 2, n3);
+        NodeConnector nc32 = NodeConnectorCreator.createOFNodeConnector((short) 3, n2);
+        NodeConnector nc33 = NodeConnectorCreator.createOFNodeConnector((short) 3, n3);
+
+        Edge e12 = null;
+        Edge e23 = null;
+
+        try {
+            e12 = new Edge(nc12, nc21);
+        } catch (ConstructionException e) {
+            e.printStackTrace();
+            assertTrue(false);
+        }
+        try {
+            e23 = new Edge(nc23, nc32);
+        } catch (ConstructionException e) {
+            e.printStackTrace();
+            assertTrue(false);
+        }
+
+        Set<Property> props = new HashSet<Property>();
+        State state = new State(State.EDGE_UP);
+        Bandwidth bw = new Bandwidth(Bandwidth.BW100Gbps);
+        Latency l = new Latency(Latency.LATENCY100ns);
+        props.add(state);
+        props.add(bw);
+        props.add(l);
+
+        //Check get methods for edge and properties
+        EdgeProperties edgeProp = new EdgeProperties(e12, props);
+
+        Edge getEdge = edgeProp.getEdge();
+        assertEquals(e12, getEdge);
+        assertEquals(nc12, getEdge.getTailNodeConnector());
+        assertEquals(n1, getEdge.getTailNodeConnector().getNode());
+        assertEquals((long)1, getEdge.getTailNodeConnector().getNode().getID());
+        assertEquals(nc21, getEdge.getHeadNodeConnector());
+        assertEquals(n2, getEdge.getHeadNodeConnector().getNode());
+        assertEquals((long)2, getEdge.getHeadNodeConnector().getNode().getID());
+
+        Set<Property> getProp = edgeProp.getProperties();
+        assertEquals(props, getProp);
+        assertEquals(props.size(), getProp.size());
+
+        //Use set methods
+        edgeProp.setEdge(e23);
+        getEdge = edgeProp.getEdge();
+        assertEquals(e23, getEdge);
+        assertEquals(nc23, getEdge.getTailNodeConnector());
+        assertEquals(nc32, getEdge.getHeadNodeConnector());
+
+        props.remove(state);
+        edgeProp.setProperties(props);
+        assertEquals(props, getProp);
+        assertEquals(props.size(), getProp.size());
+
+
+        //Create and check topology
+        List<EdgeProperties> edgePropList= new ArrayList<EdgeProperties>();
+        edgePropList.add(edgeProp);
+
+        Topology t = new Topology(edgePropList);
+
+        List<EdgeProperties> getEdgePropList = t.getEdgeProperties();
+        assertEquals(edgePropList, getEdgePropList);
+        assertEquals(1, getEdgePropList.size());
+
+        EdgeProperties edgeProp2 = new EdgeProperties(e23, props);
+        edgePropList.add(edgeProp2);
+        t.setEdgeProperties(edgePropList);
+
+        getEdgePropList = t.getEdgeProperties();
+        assertEquals(edgePropList, getEdgePropList);
+        assertEquals(2, getEdgePropList.size());
+
+    }
+       
+
+}
index 3e39ab2..a4b7584 100644 (file)
@@ -35,7 +35,7 @@ public class ControllerIO {
     public ControllerIO(IController l) {
         this.listener = l;
         this.openFlowPort = defaultOpenFlowPort;
-        String portString = System.getProperty("port");
+        String portString = System.getProperty("of.listenPort");
         if (portString != null) {
             try {
                 openFlowPort = Short.decode(portString).shortValue();
index 6d94703..8881fb5 100644 (file)
@@ -62,8 +62,7 @@ public class SwitchHandler implements ISwitch {
             .getLogger(SwitchHandler.class);
     private static final int SWITCH_LIVENESS_TIMER = 5000;
     private static final int SWITCH_LIVENESS_TIMEOUT = 2 * SWITCH_LIVENESS_TIMER + 500;
-    private static final int SYNCHRONOUS_FLOW_TIMEOUT = 2000;
-    private static final int STATS_COLLECTION_TIMEOUT = 2000;
+    private int MESSAGE_RESPONSE_TIMER = 2000;
     private static final int bufferSize = 1024 * 1024;
 
     private String instanceName;
@@ -92,6 +91,7 @@ public class SwitchHandler implements ISwitch {
     private ConcurrentHashMap<Integer, Callable<Object>> messageWaitingDone;
     private boolean running;
     private Thread switchHandlerThread;
+    private Integer responseTimerValue;
 
     private enum SwitchState {
         NON_OPERATIONAL(0), WAIT_FEATURES_REPLY(1), WAIT_CONFIG_REPLY(2), OPERATIONAL(
@@ -132,6 +132,16 @@ public class SwitchHandler implements ISwitch {
         this.messageWaitingDone = new ConcurrentHashMap<Integer, Callable<Object>>();
         this.inBuffer = ByteBuffer.allocateDirect(bufferSize);
         this.outBuffer = ByteBuffer.allocateDirect(bufferSize);
+        this.responseTimerValue = MESSAGE_RESPONSE_TIMER;
+        String rTimer = System.getProperty("of.messageResponseTimer");
+        if (rTimer != null) {
+            try {
+                responseTimerValue = Integer.decode(rTimer);
+            } catch (NumberFormatException e) {
+                logger.warn("Invalid of.messageResponseTimer:" + rTimer + ", use default("
+                        + MESSAGE_RESPONSE_TIMER+ ")");
+            }
+        }
     }
 
     public void start() {
@@ -532,7 +542,7 @@ public class SwitchHandler implements ISwitch {
         Object result = null;
         try {
             result = submit
-                    .get(STATS_COLLECTION_TIMEOUT, TimeUnit.MILLISECONDS);
+                    .get(MESSAGE_RESPONSE_TIMER, TimeUnit.MILLISECONDS);
             return result;
         } catch (Exception e) {
             logger.warn("Timeout while waiting for " + req.getType()
@@ -552,7 +562,7 @@ public class SwitchHandler implements ISwitch {
         Future<Object> submit = executor.submit(worker);
         try {
             result = submit
-                    .get(SYNCHRONOUS_FLOW_TIMEOUT, TimeUnit.MILLISECONDS);
+                    .get(responseTimerValue, TimeUnit.MILLISECONDS);
             messageWaitingDone.remove(xid);
             if (result == null) {
                 // if result  is null, then it means the switch can handle this message successfully