<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>
<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>
--- /dev/null
+<?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>
--- /dev/null
+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";
+ }
+ }
+ }
+}
<module>model-flow-statistics</module>
<module>model-flow-management</module>
<module>model-topology</module>
+ <module>model-ping</module>
</modules>
<properties>
--- /dev/null
+<?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>
--- /dev/null
+<?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>
--- /dev/null
+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();
+ }
+}
--- /dev/null
+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;
+ }
+}
--- /dev/null
+<?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>
--- /dev/null
+<?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>
--- /dev/null
+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);
+ }
+ }
+
+}
--- /dev/null
+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) {
+ }
+
+}
+
--- /dev/null
+<?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>
--- /dev/null
+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);
+}
+
--- /dev/null
+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;
+ }
+
+}
<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>