[DO NOT MERGE] 91/6991/2
authorFlavio Fernandes <ffernand@redhat.com>
Wed, 14 May 2014 12:53:51 +0000 (08:53 -0400)
committerFlavio Fernandes <ffernand@redhat.com>
Mon, 19 May 2014 16:54:37 +0000 (12:54 -0400)
This is the implementation of the md-sal ping tutorial, from
https://wiki.opendaylight.org/view/Ping

[DO NOT MERGE]

Change-Id: I08272c7f8afbd1a244082a1cb7f173f5b68455bd
Signed-off-by: Flavio Fernandes <ffernand@redhat.com>
17 files changed:
opendaylight/commons/opendaylight/pom.xml
opendaylight/distribution/opendaylight/pom.xml
opendaylight/md-sal/model/model-ping/pom.xml [new file with mode: 0644]
opendaylight/md-sal/model/model-ping/src/main/yang/ping.yang [new file with mode: 0644]
opendaylight/md-sal/model/pom.xml
opendaylight/ping/northbound/enunciate.xml [new file with mode: 0644]
opendaylight/ping/northbound/pom.xml [new file with mode: 0644]
opendaylight/ping/northbound/src/main/java/org/opendaylight/controller/ping/northbound/PingNorthbound.java [new file with mode: 0644]
opendaylight/ping/northbound/src/main/java/org/opendaylight/controller/ping/northbound/PingNorthboundRSApplication.java [new file with mode: 0644]
opendaylight/ping/northbound/src/main/resources/WEB-INF/web.xml [new file with mode: 0644]
opendaylight/ping/plugin/pom.xml [new file with mode: 0644]
opendaylight/ping/plugin/src/main/java/org/opendaylight/controller/ping/plugin/internal/PingImpl.java [new file with mode: 0644]
opendaylight/ping/plugin/src/main/java/org/opendaylight/controller/ping/plugin/internal/PingProvider.java [new file with mode: 0644]
opendaylight/ping/service/pom.xml [new file with mode: 0644]
opendaylight/ping/service/src/main/java/org/opendaylight/controller/ping/service/api/PingServiceAPI.java [new file with mode: 0644]
opendaylight/ping/service/src/main/java/org/opendaylight/controller/ping/service/impl/PingServiceImpl.java [new file with mode: 0644]
pom.xml

index 81cc16da9fc3feb51e9ef02eb379bada33293de7..3573ac964db96e0ef020f41d068e551da2c3c6df 100644 (file)
     <osgi-brandfragment.web.version>0.0.2-SNAPSHOT</osgi-brandfragment.web.version>
     <osgi.compendium.version>5.0.0</osgi.compendium.version>
     <osgi.core.version>5.0.0</osgi.core.version>
+    <ping.northbound.version>1.0-SNAPSHOT</ping.northbound.version>
+    <ping.plugin.version>0.4.0-SNAPSHOT</ping.plugin.version>
+    <ping.service.version>1.1-SNAPSHOT</ping.service.version>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
     <projectinfo>2.6</projectinfo>
         <version>${osgi-brandfragment.web.version}</version>
       </dependency>
 
+      <!-- Ping -->
+      <dependency>
+        <groupId>org.opendaylight.controller</groupId>
+        <artifactId>ping.northbound</artifactId>
+        <version>${ping.northbound.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.opendaylight.controller</groupId>
+        <artifactId>ping.plugin</artifactId>
+        <version>${ping.plugin.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.opendaylight.controller</groupId>
+        <artifactId>ping.service</artifactId>
+        <version>${ping.service.version}</version>
+      </dependency>
+
       <dependency>
         <groupId>org.opendaylight.controller</groupId>
         <artifactId>protocol-framework</artifactId>
         <artifactId>model-inventory</artifactId>
         <version>${mdsal.version}</version>
       </dependency>
+      <dependency>
+        <groupId>org.opendaylight.controller.model</groupId>
+        <artifactId>model-ping</artifactId>
+        <version>${mdsal.version}</version>
+      </dependency>
       <dependency>
         <groupId>org.opendaylight.controller.thirdparty</groupId>
         <artifactId>com.sun.jersey.jersey-servlet</artifactId>
index 04818e78c61a10e636a9b5a2ce9fdf42b8ab1910..b489669017e858b4117375ad218e1d5f3d232193 100644 (file)
       <artifactId>osgi-brandfragment.web</artifactId>
     </dependency>
 
+    <!-- Ping -->
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>ping.northbound</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>ping.plugin</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>ping.service</artifactId>
+    </dependency>
+
     <!-- Southbound bundles -->
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
           <groupId>org.opendaylight.controller.model</groupId>
           <artifactId>model-inventory</artifactId>
         </dependency>
+        <dependency>
+          <groupId>org.opendaylight.controller.model</groupId>
+          <artifactId>model-ping</artifactId>
+        </dependency>
         <dependency>
           <groupId>org.opendaylight.controller.model</groupId>
           <artifactId>model-topology</artifactId>
diff --git a/opendaylight/md-sal/model/model-ping/pom.xml b/opendaylight/md-sal/model/model-ping/pom.xml
new file mode 100644 (file)
index 0000000..a305ccc
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0  http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.opendaylight.controller.model</groupId>
+    <artifactId>model-parent</artifactId>
+    <version>1.1-SNAPSHOT</version>
+  </parent>
+  <artifactId>model-ping</artifactId>
+  <packaging>bundle</packaging>
+</project>
diff --git a/opendaylight/md-sal/model/model-ping/src/main/yang/ping.yang b/opendaylight/md-sal/model/model-ping/src/main/yang/ping.yang
new file mode 100644 (file)
index 0000000..f801941
--- /dev/null
@@ -0,0 +1,35 @@
+module ping {
+  namespace "urn:opendaylight:ping";
+  prefix ping;
+  import ietf-inet-types {prefix inet;}
+  revision "2013-09-11" {
+    description "TCP ping module";
+  }
+  rpc send-echo {
+    description "Send TCP ECHO request";
+    input {
+      leaf destination {
+        type inet:ipv4-address;
+      }
+    }
+    output {
+      leaf echo-result {
+        type enumeration {
+          enum "reachable" {
+            value 0;
+            description "Received reply";
+          }
+          enum "unreachable" {
+            value 1;
+            description "No reply during timeout";
+          }
+          enum "error" {
+            value 2;
+            description "Error happened";
+          }
+        }
+        description "Result types";
+      }
+    }
+  }
+}
index 12b5f766254c933221217d0962f399139a436781..c6b7d29a3edafea856c6372091e8dcdd24304c7f 100644 (file)
@@ -19,6 +19,7 @@
     <module>model-flow-statistics</module>
     <module>model-flow-management</module>
     <module>model-topology</module>
+    <module>model-ping</module>
   </modules>
 
   <properties>
diff --git a/opendaylight/ping/northbound/enunciate.xml b/opendaylight/ping/northbound/enunciate.xml
new file mode 100644 (file)
index 0000000..d77989c
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+<enunciate label="full" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:noNamespaceSchemaLocation="http://enunciate.codehaus.org/schemas/enunciate-1.26.xsd">
+
+  <services>
+    <rest defaultRestSubcontext="/controller/nb/v2/ping"/>
+  </services>
+
+  <modules>
+    <docs docsDir="rest" title="Ping REST API" includeExampleXml="true" includeExampleJson="true"/>
+  </modules>
+</enunciate>
diff --git a/opendaylight/ping/northbound/pom.xml b/opendaylight/ping/northbound/pom.xml
new file mode 100644 (file)
index 0000000..d9ec8bf
--- /dev/null
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0  http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.opendaylight.controller</groupId>
+    <artifactId>commons.opendaylight</artifactId>
+    <version>1.4.2-SNAPSHOT</version>
+    <relativePath>../../commons/opendaylight</relativePath>
+  </parent>
+  <artifactId>ping.northbound</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>bundle</packaging>
+  <dependencies>
+    <dependency>
+      <groupId>org.codehaus.enunciate</groupId>
+      <artifactId>enunciate-core-annotations</artifactId>
+      <version>${enunciate.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>commons.northbound</artifactId>
+      <version>0.4.2-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>ping.service</artifactId>
+      <version>1.1-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller.thirdparty</groupId>
+      <artifactId>com.sun.jersey.jersey-servlet</artifactId>
+      <version>1.17</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller.thirdparty</groupId>
+      <artifactId>org.apache.catalina.filters.CorsFilter</artifactId>
+      <version>7.0.42</version>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <version>${bundle.plugin.version}</version>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Import-Package>org.opendaylight.controller.ping.service.api,
+              org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924,
+              org.apache.commons.logging,
+              com.sun.jersey.spi.container.servlet,
+              org.opendaylight.controller.northbound.commons,
+              org.opendaylight.controller.northbound.commons.exception,
+              org.opendaylight.controller.northbound.commons.utils,
+              org.opendaylight.controller.sal.utils,
+              org.opendaylight.controller.sal.authorization,
+              org.opendaylight.controller.sal.packet.address,
+              javax.ws.rs,
+              javax.ws.rs.core,
+              javax.xml.bind.annotation,
+              javax.xml.bind,
+              org.slf4j,
+              org.apache.catalina.filters,
+              com.fasterxml.jackson.jaxrs.base,
+              com.fasterxml.jackson.jaxrs.json,
+              !org.codehaus.enunciate.jaxrs</Import-Package>
+            <Web-ContextPath>/controller/nb/v2</Web-ContextPath>
+          </instructions>
+          <manifestLocation>${project.basedir}/src/main/resources/META-INF</manifestLocation>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.codehaus.enunciate</groupId>
+        <artifactId>maven-enunciate-plugin</artifactId>
+        <version>${enunciate.version}</version>
+        <dependencies>
+          <dependency>
+            <groupId>org.opendaylight.controller</groupId>
+            <artifactId>sal</artifactId>
+            <version>0.7.1-SNAPSHOT</version>
+          </dependency>
+        </dependencies>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git a/opendaylight/ping/northbound/src/main/java/org/opendaylight/controller/ping/northbound/PingNorthbound.java b/opendaylight/ping/northbound/src/main/java/org/opendaylight/controller/ping/northbound/PingNorthbound.java
new file mode 100644 (file)
index 0000000..e1e2134
--- /dev/null
@@ -0,0 +1,39 @@
+package org.opendaylight.controller.ping.northbound;
+
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.core.Response;
+
+import org.codehaus.enunciate.jaxrs.ResponseCode;
+import org.codehaus.enunciate.jaxrs.StatusCodes;
+import org.opendaylight.controller.ping.service.api.PingServiceAPI;
+import org.opendaylight.controller.sal.utils.ServiceHelper;
+
+@Path("/")
+public class PingNorthbound {
+    /**
+     * Ping test
+     */
+    @Path("/ping/{ipAddress}")
+    @PUT
+    @StatusCodes({
+        @ResponseCode(code = 200, condition = "Destination reachable"),
+        @ResponseCode(code = 503, condition = "Internal error"),
+        @ResponseCode(code = 503, condition = "Destination unreachable") })
+    public Response ping(@PathParam(value = "ipAddress") String ipAddress) {
+        PingServiceAPI ping = (PingServiceAPI) ServiceHelper.getGlobalInstance(
+                PingServiceAPI.class, this);
+        if (ping == null) {
+
+            /* Ping service not found. */
+            return Response.ok(new String("No ping service")).status(500)
+                    .build();
+        }
+        if (ping.pingDestination(ipAddress))
+            return Response.ok(new String(ipAddress + " - reachable")).build();
+
+        return Response.ok(new String(ipAddress + " - unreachable")).status(503)
+                .build();
+    }
+}
diff --git a/opendaylight/ping/northbound/src/main/java/org/opendaylight/controller/ping/northbound/PingNorthboundRSApplication.java b/opendaylight/ping/northbound/src/main/java/org/opendaylight/controller/ping/northbound/PingNorthboundRSApplication.java
new file mode 100644 (file)
index 0000000..8b37fb0
--- /dev/null
@@ -0,0 +1,15 @@
+package org.opendaylight.controller.ping.northbound;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.core.Application;
+
+public class PingNorthboundRSApplication extends Application {
+    @Override
+    public Set<Class<?>> getClasses() {
+        Set<Class<?>> classes = new HashSet<Class<?>>();
+        classes.add(PingNorthbound.class);
+        return classes;
+    }
+}
diff --git a/opendaylight/ping/northbound/src/main/resources/WEB-INF/web.xml b/opendaylight/ping/northbound/src/main/resources/WEB-INF/web.xml
new file mode 100644 (file)
index 0000000..e4e8734
--- /dev/null
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<web-app xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+ http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
+  <servlet>
+    <servlet-name>JAXRSPing</servlet-name>
+    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
+    <init-param>
+      <param-name>javax.ws.rs.Application</param-name>
+      <param-value>org.opendaylight.controller.ping.northbound.PingNorthboundRSApplication</param-value>
+    </init-param>
+    <load-on-startup>1</load-on-startup>
+  </servlet>
+
+  <servlet-mapping>
+    <servlet-name>JAXRSPing</servlet-name>
+    <url-pattern>/*</url-pattern>
+  </servlet-mapping>
+
+        <filter>
+          <filter-name>CorsFilter</filter-name>
+          <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
+          <init-param>
+            <param-name>cors.allowed.origins</param-name>
+            <param-value>*</param-value>
+          </init-param>
+          <init-param>
+            <param-name>cors.allowed.methods</param-name>
+            <param-value>GET,POST,HEAD,OPTIONS,PUT</param-value>
+          </init-param>
+          <init-param>
+            <param-name>cors.allowed.headers</param-name>
+            <param-value>Content-Type,X-Requested-With,accept,authorization, origin,Origin,Access-Control-Request-Method,Access-Control-Request-Headers</param-value>
+          </init-param>
+          <init-param>
+            <param-name>cors.exposed.headers</param-name>
+            <param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials</param-value>
+          </init-param>
+          <init-param>
+            <param-name>cors.support.credentials</param-name>
+            <param-value>true</param-value>
+          </init-param>
+          <init-param>
+            <param-name>cors.preflight.maxage</param-name>
+            <param-value>10</param-value>
+          </init-param>
+        </filter>
+        <filter-mapping>
+          <filter-name>CorsFilter</filter-name>
+          <url-pattern>/*</url-pattern>
+        </filter-mapping>
+
+        <security-constraint>
+          <web-resource-collection>
+            <web-resource-name>NB api</web-resource-name>
+            <url-pattern>/*</url-pattern>
+            <http-method>POST</http-method>
+            <http-method>GET</http-method>
+            <http-method>PUT</http-method>
+            <http-method>PATCH</http-method>
+            <http-method>DELETE</http-method>
+            <http-method>HEAD</http-method>
+          </web-resource-collection>
+          <auth-constraint>
+            <role-name>System-Admin</role-name>
+            <role-name>Network-Admin</role-name>
+            <role-name>Network-Operator</role-name>
+            <role-name>Container-User</role-name>
+          </auth-constraint>
+        </security-constraint>
+
+        <security-role>
+                <role-name>System-Admin</role-name>
+        </security-role>
+        <security-role>
+                <role-name>Network-Admin</role-name>
+        </security-role>
+        <security-role>
+                <role-name>Network-Operator</role-name>
+        </security-role>
+        <security-role>
+                <role-name>Container-User</role-name>
+        </security-role>
+
+        <login-config>
+                <auth-method>BASIC</auth-method>
+                <realm-name>opendaylight</realm-name>
+        </login-config>
+</web-app>
diff --git a/opendaylight/ping/plugin/pom.xml b/opendaylight/ping/plugin/pom.xml
new file mode 100644 (file)
index 0000000..9fb6b7d
--- /dev/null
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0  http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.opendaylight.controller</groupId>
+    <artifactId>commons.opendaylight</artifactId>
+    <version>1.4.2-SNAPSHOT</version>
+    <relativePath>../../commons/opendaylight</relativePath>
+  </parent>
+  <artifactId>ping.plugin</artifactId>
+  <version>0.4.0-SNAPSHOT</version>
+  <packaging>bundle</packaging>
+  <dependencies>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>sal-binding-api</artifactId>
+      <version>1.1-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>sal-common-util</artifactId>
+      <version>1.1-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller.model</groupId>
+      <artifactId>model-ping</artifactId>
+      <version>1.1-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.yangtools</groupId>
+      <artifactId>yang-binding</artifactId>
+      <version>${yangtools.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.yangtools</groupId>
+      <artifactId>yang-common</artifactId>
+      <version>${yangtools.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.core</artifactId>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <version>${bundle.plugin.version}</version>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Import-Package>org.opendaylight.yang.gen.v1.urn.opendaylight.ping.rev130911,
+             org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924,
+             org.opendaylight.yangtools.yang.common,
+             org.opendaylight.yangtools.yang.binding,
+             org.opendaylight.controller.sal.binding.api,
+             org.opendaylight.controller.sal.common.util,
+             com.google.common.util.concurrent,
+             org.osgi.framework</Import-Package>
+            <Export-Package>org.opendaylight.controller.ping.plugin.internal</Export-Package>
+            <Bundle-Activator>org.opendaylight.controller.ping.plugin.internal.PingProvider</Bundle-Activator>
+          </instructions>
+          <manifestLocation>${project.basedir}/META-INF</manifestLocation>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git a/opendaylight/ping/plugin/src/main/java/org/opendaylight/controller/ping/plugin/internal/PingImpl.java b/opendaylight/ping/plugin/src/main/java/org/opendaylight/controller/ping/plugin/internal/PingImpl.java
new file mode 100644 (file)
index 0000000..0fe7300
--- /dev/null
@@ -0,0 +1,56 @@
+package org.opendaylight.controller.ping.plugin.internal;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.util.Collections;
+import java.util.concurrent.Future;
+
+import org.opendaylight.controller.sal.common.util.Rpcs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.ping.rev130911.PingService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.ping.rev130911.SendEchoInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.ping.rev130911.SendEchoOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.ping.rev130911.SendEchoOutput.EchoResult;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.ping.rev130911.SendEchoOutputBuilder;
+import org.opendaylight.yangtools.yang.common.RpcError;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+
+import com.google.common.util.concurrent.Futures;
+
+public class PingImpl implements PingService {
+
+    private EchoResult pingHost(InetAddress destination) throws IOException {
+        if (destination.isReachable(5000)) {
+            return EchoResult.Reachable;
+        } else {
+            return EchoResult.Unreachable;
+        }
+    }
+
+    @Override
+    public Future<RpcResult<SendEchoOutput>> sendEcho(SendEchoInput destination) {
+        try {
+            InetAddress dst = InetAddress.getByName(destination
+                    .getDestination().getValue());
+            EchoResult result = this.pingHost(dst);
+
+            /* Build the result and return it. */
+            SendEchoOutputBuilder ob = new SendEchoOutputBuilder();
+            ob.setEchoResult(result);
+            RpcResult<SendEchoOutput> rpcResult =
+                    Rpcs.<SendEchoOutput> getRpcResult(true, ob.build(),
+                            Collections.<RpcError> emptySet());
+
+            return Futures.immediateFuture(rpcResult);
+        } catch (Exception e) {
+
+            /* Return error result. */
+            SendEchoOutputBuilder ob = new SendEchoOutputBuilder();
+            ob.setEchoResult(EchoResult.Error);
+            RpcResult<SendEchoOutput> rpcResult =
+                    Rpcs.<SendEchoOutput> getRpcResult(true, ob.build(),
+                            Collections.<RpcError> emptySet());
+            return Futures.immediateFuture(rpcResult);
+        }
+    }
+
+}
diff --git a/opendaylight/ping/plugin/src/main/java/org/opendaylight/controller/ping/plugin/internal/PingProvider.java b/opendaylight/ping/plugin/src/main/java/org/opendaylight/controller/ping/plugin/internal/PingProvider.java
new file mode 100644 (file)
index 0000000..01087bc
--- /dev/null
@@ -0,0 +1,40 @@
+package org.opendaylight.controller.ping.plugin.internal;
+
+import java.util.Collection;
+
+import org.opendaylight.controller.sal.binding.api.AbstractBindingAwareProvider;
+// import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.ping.rev130911.PingService;
+import org.opendaylight.yangtools.yang.binding.RpcService;
+import org.osgi.framework.BundleContext;
+
+public class PingProvider extends AbstractBindingAwareProvider {
+
+    PingImpl pingImpl;
+
+    public PingProvider() {
+        pingImpl = new PingImpl();
+    }
+
+    @Override
+    public Collection<? extends RpcService> getImplementations() {
+        return null;
+    }
+
+    @Override
+    public Collection<? extends ProviderFunctionality> getFunctionality() {
+        return null;
+    }
+
+    @Override
+    public void onSessionInitiated(ProviderContext session) {
+        session.addRpcImplementation(PingService.class, pingImpl);
+    }
+
+    @Override
+    protected void startImpl(BundleContext context) {
+    }
+
+}
+
diff --git a/opendaylight/ping/service/pom.xml b/opendaylight/ping/service/pom.xml
new file mode 100644 (file)
index 0000000..5d797c8
--- /dev/null
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0   http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.opendaylight.controller</groupId>
+    <artifactId>commons.opendaylight</artifactId>
+    <version>1.4.2-SNAPSHOT</version>
+    <relativePath>../../commons/opendaylight</relativePath>
+  </parent>
+  <artifactId>ping.service</artifactId>
+  <version>1.1-SNAPSHOT</version>
+  <packaging>bundle</packaging>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>sal-binding-api</artifactId>
+      <version>1.1-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller.model</groupId>
+      <artifactId>model-ping</artifactId>
+      <version>1.1-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.yangtools</groupId>
+      <artifactId>yang-binding</artifactId>
+      <version>${yangtools.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.yangtools</groupId>
+      <artifactId>yang-common</artifactId>
+      <version>${yangtools.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.core</artifactId>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <version>${bundle.plugin.version}</version>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Import-Package>org.opendaylight.yang.gen.v1.urn.opendaylight.ping.rev130911,
+              org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924,
+              org.opendaylight.yangtools.yang.common,
+              org.opendaylight.yangtools.yang.binding,
+              org.opendaylight.controller.sal.binding.api,
+              org.osgi.framework</Import-Package>
+            <Export-Package>org.opendaylight.controller.ping.service.api</Export-Package>
+            <Bundle-Activator>org.opendaylight.controller.ping.service.impl.PingServiceImpl</Bundle-Activator>
+          </instructions>
+          <manifestLocation>${project.basedir}/META-INF</manifestLocation>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git a/opendaylight/ping/service/src/main/java/org/opendaylight/controller/ping/service/api/PingServiceAPI.java b/opendaylight/ping/service/src/main/java/org/opendaylight/controller/ping/service/api/PingServiceAPI.java
new file mode 100644 (file)
index 0000000..5dea55a
--- /dev/null
@@ -0,0 +1,15 @@
+package org.opendaylight.controller.ping.service.api;
+
+
+public interface PingServiceAPI {
+
+    /**
+     * pingDestination
+     *
+     * @param address An IPv4 address to be pinged
+     * @return True if address is reachable,
+     * false if address is unreachable or error occurs.
+     */
+    boolean pingDestination(String address);
+}
+
diff --git a/opendaylight/ping/service/src/main/java/org/opendaylight/controller/ping/service/impl/PingServiceImpl.java b/opendaylight/ping/service/src/main/java/org/opendaylight/controller/ping/service/impl/PingServiceImpl.java
new file mode 100644 (file)
index 0000000..08229b7
--- /dev/null
@@ -0,0 +1,66 @@
+package org.opendaylight.controller.ping.service.impl;
+
+import java.util.concurrent.ExecutionException;
+
+import org.opendaylight.controller.ping.service.api.PingServiceAPI;
+import org.opendaylight.controller.sal.binding.api.AbstractBindingAwareConsumer;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
+import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.ping.rev130911.PingService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.ping.rev130911.SendEchoInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.ping.rev130911.SendEchoOutput;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+public class PingServiceImpl extends AbstractBindingAwareConsumer implements
+        BundleActivator, BindingAwareConsumer, PingServiceAPI {
+
+    private PingService ping;
+    private ConsumerContext session;
+
+    @Override
+    public void onSessionInitialized(ConsumerContext session) {
+        this.session = session;
+    }
+
+    @Override
+    protected void startImpl(BundleContext context) {
+        context.registerService(PingServiceAPI.class, this, null);
+    }
+
+    @Override
+    public boolean pingDestination(String address) {
+
+        if (ping == null) {
+            ping = this.session.getRpcService(PingService.class);
+            if (ping == null) {
+
+                /* No ping service found. */
+                return false;
+            }
+        }
+
+        Ipv4Address destination = new Ipv4Address(address);
+
+        SendEchoInputBuilder ib = new SendEchoInputBuilder();
+        ib.setDestination(destination);
+        try {
+            RpcResult<SendEchoOutput> result = ping.sendEcho(ib.build()).get();
+            switch (result.getResult().getEchoResult()) {
+            case Reachable:
+                return true;
+            case Unreachable:
+            case Error:
+            default:
+                return false;
+            }
+        } catch (InterruptedException ie) {
+        } catch (ExecutionException ee) {
+        }
+
+        return false;
+    }
+
+}
diff --git a/pom.xml b/pom.xml
index 3a3c3dcfb462b2d2a56341799760e9074added56..45f281797f80a2884046f6a981d59ee6af363e83 100644 (file)
--- a/pom.xml
+++ b/pom.xml
     <module>opendaylight/samples/loadbalancer</module>
     <module>opendaylight/samples/northbound/loadbalancer</module>
 
+    <!-- Ping -->
+    <module>opendaylight/ping/service</module>
+    <module>opendaylight/ping/plugin</module>
+    <module>opendaylight/ping/northbound</module>
+
     <!-- Parents -->
     <module>opendaylight/commons/concepts</module>
     <module>opendaylight/commons/protocol-framework</module>